39 typedef void (*
exec_entry)(
char *args,
char *envs,
unsigned long kpma);
52 extern unsigned long end;
56 static inline void tree_vfs(
void)
72 printf(
"Root ninfo: %p\n", ninfo);
74 for (i = 0; i < depth; i ++) {
79 ninfo->
name ? ninfo->
name :
"(root)");
83 item =
malloc(
sizeof(*item));
90 list_add_tail(&item->head, &stack);
103 if (stack.prev == &stack) {
108 item =
list_entry(stack.prev,
struct stack, head);
109 list_del(&item->head);
122 static inline int vfs_build_dev(
void)
143 int fill_env(
struct env_t *envt,
int idx,
char *env,
int *aidx)
180 static inline int fill_map(
struct memmap *map,
int idx,
char *env)
219 void parse_env(
char *env,
struct env_t *envt,
struct memmap *map)
263 while (*env && idx <
MAX_IDX) {
264 if (label[token_idx][0]) {
265 if (label[token_idx][i] != *env) {
276 if (label[token_idx][i] !=
'\0' || *env !=
'=') {
284 if (fill_env(envt, token_idx, env, &array_idx) == 0) {
288 if (fill_map(map, token_idx, env) == 0) {
293 envt->
envp[idx++] = env - i;
309 static inline void parse_arg(
char *arg,
struct arg_t *argt)
334 static inline void setup_default_thread(
struct memmap *map)
341 dbg_printf(
"Failed to initialize the attribute\n");
356 dbg_printf(
"Failed to initialize a thread\n");
368 dbg_printf(
"Failed to destroy the attribute\n");
372 static inline void test_thread(
void)
378 printf(
"THID: %p\n", thid);
380 printf(
"Failed to find a THID\n");
385 static inline void dump_map(
struct memmap *map)
397 static inline void transfer_to_vma(
struct memmap *map,
void *vma_kernel)
406 map->
tcb = (
char *)(0xFFFFFFFF - map->
tcb_size - (0x01 << 20) + 1);
422 static inline void frame_init(
void)
428 register int pgt_idx;
429 register int page_idx;
434 assert(tcb &&
"thread is not valid");
437 assert(arch_data &&
"arch_data is not valid");
440 assert(pgd &&
"Failed to do onetime mapping");
444 for (pgt_idx = 0; pgt_idx <
NR_TABLES; pgt_idx++) {
445 if (!pgd[pgt_idx].p) {
449 pgt = (
struct pgte *)(pgd[pgt_idx].pt_base * pagesize);
450 assert(pgt &&
"page table is not valid");
454 assert(pgt &&
"onetime map failed");
456 for (page_idx = 0; page_idx <
NR_PAGES; page_idx++) {
457 if (!pgt[page_idx].p) {
461 page = (
void *)(pgt[page_idx].
page_base * pagesize);
466 assert(pgt &&
"onetime unmap");
470 static inline void vfs_attach_root(
void)
473 struct ninfo *fat_root;
481 fat_root =
fat_load(root,
"/dev/fda");
487 static void _start_on_vma(
char *args,
char *envs,
unsigned long kpma)
495 panic(
"Paging is not enabled");
499 parse_arg(args, &argt);
500 parse_env(envs, &envt, &map);
508 transfer_to_vma(&map, (
void *)envs);
518 if (vfs_build_dev() < 0) {
526 setup_default_thread(&map);
529 (
void *)(0xFFFFFFFF - (0x01 << 20) + 1),
545 panic(
"End of a function (ret:%d)", ret);
563 parse_env(env, &envt, &map);
594 :
"m"(esp),
"m"(vma_start)