23 |
#include <config.h> |
#include <config.h> |
24 |
#endif |
#endif |
25 |
|
|
26 |
|
#include <stdlib.h> |
27 |
|
|
28 |
#include "physmem.h" |
#include "physmem.h" |
29 |
#include "zalloc.h" |
#include "zalloc.h" |
30 |
|
|
31 |
|
|
32 |
/* The program name. */ |
/* The program name. */ |
33 |
char *program_name = "physmem"; |
char program_name[] = "physmem"; |
34 |
|
|
35 |
|
|
36 |
|
#define WORTEL_MSG_PUTCHAR 1 |
37 |
|
#define WORTEL_MSG_PANIC 2 |
38 |
|
#define WORTEL_MSG_GET_MEM 3 |
39 |
|
#define WORTEL_MSG_GET_CAP_REQUEST 4 |
40 |
|
#define WORTEL_MSG_GET_CAP_REPLY 5 |
41 |
|
|
42 |
void |
void |
43 |
get_all_memory (void) |
get_all_memory (void) |
44 |
{ |
{ |
45 |
l4_fpage_t fpage; |
l4_fpage_t fpage; |
46 |
|
|
47 |
|
l4_accept (l4_map_grant_items (l4_complete_address_space)); |
48 |
|
|
49 |
do |
do |
50 |
{ |
{ |
51 |
l4_msg_t msg; |
l4_msg_t msg; |
52 |
l4_msg_tag_t msg_tag; |
l4_msg_tag_t tag; |
53 |
l4_grant_item_t grant_item; |
l4_grant_item_t grant_item; |
54 |
|
|
|
l4_accept (l4_map_grant_items (l4_complete_address_space)); |
|
55 |
l4_msg_clear (&msg); |
l4_msg_clear (&msg); |
56 |
/* FIXME: 2 is WORTEL_MSG_GET_MEM. */ |
l4_set_msg_label (&msg, WORTEL_MSG_GET_MEM); |
57 |
l4_set_msg_label (&msg, 2); |
/* FIXME: Use real cap_id. */ |
|
/* FIXME: cap_id */ |
|
58 |
l4_msg_append_word (&msg, 0); |
l4_msg_append_word (&msg, 0); |
59 |
l4_msg_load (&msg); |
l4_msg_load (&msg); |
60 |
/* FIXME: Hard coded wortel thread. */ |
/* FIXME: Hard coded wortel thread. */ |
61 |
msg_tag = l4_call (l4_global_id (l4_thread_user_base () + 2, 1)); |
tag = l4_call (l4_global_id (l4_thread_user_base () + 2, 1)); |
62 |
if (l4_ipc_failed (msg_tag)) |
if (l4_ipc_failed (tag)) |
63 |
{ |
panic ("get_mem request failed during %s: %u", |
64 |
debug ("get_mem request failed during %s: %u", |
l4_error_code () & 1 ? "receive" : "send", |
65 |
l4_error_code () & 1 ? "receive" : "send", |
(l4_error_code () >> 1) & 0x7); |
66 |
(l4_error_code () >> 1) & 0x7); |
|
67 |
l4_sleep (l4_never); |
if (l4_untyped_words (tag) != 0 |
68 |
} |
|| l4_typed_words (tag) != 2) |
69 |
if (l4_untyped_words (msg_tag) != 0 |
panic ("Invalid format of wortel get_mem reply"); |
70 |
|| l4_typed_words (msg_tag) != 2) |
|
71 |
{ |
l4_msg_store (tag, &msg); |
|
debug ("Invalid format of wortel get_mem reply"); |
|
|
l4_sleep (l4_never); |
|
|
} |
|
|
l4_msg_store (msg_tag, &msg); |
|
72 |
l4_msg_get_grant_item (&msg, 0, &grant_item); |
l4_msg_get_grant_item (&msg, 0, &grant_item); |
73 |
fpage = grant_item.send_fpage; |
fpage = grant_item.send_fpage; |
74 |
|
|
78 |
while (fpage.raw != l4_nilpage.raw); |
while (fpage.raw != l4_nilpage.raw); |
79 |
} |
} |
80 |
|
|
81 |
|
|
82 |
|
void |
83 |
|
create_bootstrap_caps (void) |
84 |
|
{ |
85 |
|
l4_accept (l4_map_grant_items (l4_complete_address_space)); |
86 |
|
|
87 |
|
while (1) |
88 |
|
{ |
89 |
|
l4_msg_t msg; |
90 |
|
l4_msg_tag_t tag; |
91 |
|
unsigned int i; |
92 |
|
|
93 |
|
l4_msg_clear (&msg); |
94 |
|
l4_set_msg_label (&msg, WORTEL_MSG_GET_CAP_REQUEST); |
95 |
|
/* FIXME: Use real cap_id. */ |
96 |
|
l4_msg_append_word (&msg, 0); |
97 |
|
l4_msg_load (&msg); |
98 |
|
/* FIXME: Hard coded wortel thread. */ |
99 |
|
tag = l4_call (l4_global_id (l4_thread_user_base () + 2, 1)); |
100 |
|
|
101 |
|
if (l4_ipc_failed (tag)) |
102 |
|
panic ("get cap request failed during %s: %u", |
103 |
|
l4_error_code () & 1 ? "receive" : "send", |
104 |
|
(l4_error_code () >> 1) & 0x7); |
105 |
|
|
106 |
|
l4_msg_store (tag, &msg); |
107 |
|
|
108 |
|
if (l4_untyped_words (tag) == 1) |
109 |
|
{ |
110 |
|
/* This requests the master control capability. */ |
111 |
|
if (l4_typed_words (tag)) |
112 |
|
panic ("Invalid format of wortel get cap request reply " |
113 |
|
"for master control"); |
114 |
|
|
115 |
|
/* FIXME: Create capability. */ |
116 |
|
l4_msg_clear (&msg); |
117 |
|
l4_set_msg_label (&msg, WORTEL_MSG_GET_CAP_REPLY); |
118 |
|
/* FIXME: Use our wortel cap here. */ |
119 |
|
l4_msg_append_word (&msg, 0); |
120 |
|
/* FIXME: Use our control cap for this task here. */ |
121 |
|
l4_msg_append_word (&msg, 0xf00); |
122 |
|
l4_msg_load (&msg); |
123 |
|
/* FIXME: Hard coded thread ID. */ |
124 |
|
l4_send (l4_global_id (l4_thread_user_base () + 2, 1)); |
125 |
|
|
126 |
|
/* This is the last request made. */ |
127 |
|
return; |
128 |
|
} |
129 |
|
else if (l4_untyped_words (tag) != 3 |
130 |
|
|| l4_typed_words (tag) == 0) |
131 |
|
panic ("Invalid format of wortel get cap request reply"); |
132 |
|
|
133 |
|
debug ("Creating cap for 0x%x covering 0x%x to 0x%x:", |
134 |
|
l4_msg_word (&msg, 0), l4_msg_word (&msg, 1), |
135 |
|
l4_msg_word (&msg, 2)); |
136 |
|
|
137 |
|
for (i = 0; i < l4_typed_words (tag); i += 2) |
138 |
|
{ |
139 |
|
l4_fpage_t fpage; |
140 |
|
l4_grant_item_t grant_item; |
141 |
|
l4_msg_get_grant_item (&msg, i, &grant_item); |
142 |
|
|
143 |
|
fpage = grant_item.send_fpage; |
144 |
|
if (l4_nilpage.raw == fpage.raw) |
145 |
|
{ |
146 |
|
if (l4_typed_words (tag) == 2) |
147 |
|
{ |
148 |
|
/* FIXME: Create control capability for this one |
149 |
|
task. */ |
150 |
|
debug ("Can't create task control capability yet"); |
151 |
|
} |
152 |
|
else |
153 |
|
panic ("Invalid fpage in create bootstrap cap call"); |
154 |
|
} |
155 |
|
debug ("0x%x ", fpage.raw); |
156 |
|
} |
157 |
|
debug ("\n"); |
158 |
|
|
159 |
|
l4_msg_clear (&msg); |
160 |
|
l4_set_msg_label (&msg, WORTEL_MSG_GET_CAP_REPLY); |
161 |
|
|
162 |
|
/* FIXME: Use our wortel cap here. */ |
163 |
|
l4_msg_append_word (&msg, 0); |
164 |
|
/* FIXME: This must return the real capability ID. */ |
165 |
|
l4_msg_append_word (&msg, 0xa00); |
166 |
|
l4_msg_load (&msg); |
167 |
|
/* FIXME: Hard coded thread ID. */ |
168 |
|
l4_send (l4_global_id (l4_thread_user_base () + 2, 1)); |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
int |
int |
174 |
main (int argc, char *argv[]) |
main (int argc, char *argv[]) |
179 |
|
|
180 |
get_all_memory (); |
get_all_memory (); |
181 |
|
|
182 |
zalloc_dump_zones (program_name); |
create_bootstrap_caps (); |
183 |
|
|
184 |
while (1) |
while (1) |
185 |
l4_sleep (l4_never); |
l4_sleep (l4_never); |