Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / user / hello_world / hello_world.c
1 /* Copyright (c) 2008, Sandia National Laboratories */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <limits.h>
7 #include <lwk/liblwk.h>
8
9 static void pmem_api_test(void);
10 static void aspace_api_test(void);
11
12 int
13 main(int argc, char *argv[], char *envp[])
14 {
15         int i;
16         id_t aspace_id;
17
18         printf("Hello, world!\n");
19
20         printf("Arguments:\n");
21         for (i = 0; i < argc; i++)
22                 printf("  argv[%d] = %s\n", i, argv[i]);
23
24         printf("Environment Variables:\n");
25         for (i = 0; envp[i] != NULL; i++)
26                 printf("  envp[%d] = %s\n", i, envp[i]);
27
28         pmem_api_test();
29         aspace_api_test();
30
31         printf("Spinning forever...\n");
32         while (1) {}
33 }
34
35 static void
36 pmem_api_test(void)
37 {
38         struct pmem_region query, result;
39         unsigned long bytes_umem = 0;
40         int status;
41
42         printf("TEST BEGIN: Physical Memory Management\n");
43
44         query.start = 0;
45         query.end = ULONG_MAX;
46         pmem_region_unset_all(&query);
47
48         printf("  Physical Memory Map:\n");
49         while ((status = pmem_query(&query, &result)) == 0) {
50                 printf("    [%#016lx, %#016lx) %-11s\n",
51                         result.start,
52                         result.end,
53                         (result.type_is_set)
54                                 ? pmem_type_to_string(result.type)
55                                 : "UNSET"
56                 );
57
58                 if (result.type == PMEM_TYPE_UMEM)
59                         bytes_umem += (result.end - result.start);
60
61                 query.start = result.end;
62         }
63
64         if (status != -ENOENT) {
65                 printf("ERROR: pmem_query() status=%d\n", status);
66         }
67
68         printf("  Total User-Level Managed Memory: %lu bytes\n", bytes_umem);
69
70         printf("TEST END: Physical Memory Management\n");
71 }
72
73 static void
74 aspace_api_test(void)
75 {
76         int status;
77         id_t my_id, new_id;
78
79         printf("TEST BEGIN: Address Space Management\n");
80
81         if ((status = aspace_get_myid(&my_id)) != 0)
82                 printf("ERROR: aspace_get_myid() status=%d\n", status);
83         else
84                 printf("  My address space ID is %u\n", my_id);
85
86         printf("  Creating a new aspace: ");
87
88         status = aspace_create(ANY_ID, "TEST-ASPACE", &new_id);
89         if (status)
90                 printf("\nERROR: aspace_create() status=%d\n", status);
91         else
92                 printf("id=%u\n", new_id);
93
94         printf("  Using SMARTMAP to map myself into aspace %u\n", new_id);
95         status = aspace_smartmap(my_id, new_id, SMARTMAP_ALIGN, SMARTMAP_ALIGN);
96         if (status) printf("ERROR: aspace_smartmap() status=%d\n", status);
97
98         aspace_dump2console(new_id);
99
100         status = aspace_unsmartmap(my_id, new_id);
101         if (status) printf("ERROR: aspace_unsmartmap() status=%d\n", status);
102
103         printf("  Destroying a aspace %u: ", new_id);
104         status = aspace_destroy(new_id);
105         if (status)
106                 printf("ERROR: aspace_destroy() status=%d\n", status);
107         else
108                 printf("OK\n");
109
110         printf("TEST END: Address Space Management\n");
111 }