--- Gnu-Mach/kern/bootstrap.c 2020/09/02 04:42:40 1.1.1.3 +++ Gnu-Mach/kern/bootstrap.c 2020/09/02 04:49:48 1.1.1.6 @@ -29,20 +29,28 @@ /* * Bootstrap the various built-in servers. */ -#include -#include + +#include +#include #include #include -#include "vm_param.h" +#include +#include +#include #include +#include +#include #include +#include +#include #include #include #include #include +#include +#include #include -#include #if MACH_KDB #include @@ -51,7 +59,6 @@ #if OSKIT_MACH #include -#include #include #include #include @@ -59,8 +66,12 @@ #else #include #include -#include +#ifdef MACH_XEN +#include +extern struct start_info boot_info; /* XXX put this in a header! */ +#else /* MACH_XEN */ extern struct multiboot_info boot_info; /* XXX put this in a header! */ +#endif /* MACH_XEN */ #endif #include "boot_script.h" @@ -71,8 +82,8 @@ static mach_port_t boot_host_port; /* l extern char *kernel_cmdline; -static void user_bootstrap(); /* forward */ -static void user_bootstrap_compat(); /* forward */ +static void user_bootstrap(void); /* forward */ +static void user_bootstrap_compat(void); /* forward */ static void bootstrap_exec_compat(void *exec_data); /* forward */ static void get_compat_strings(char *flags_str, char *root_str); /* forward */ @@ -87,7 +98,7 @@ task_insert_send_right( kern_return_t kr; kr = mach_port_insert_right(task->itk_space, name, - (ipc_object_t)port, MACH_MSG_TYPE_PORT_SEND); + port, MACH_MSG_TYPE_PORT_SEND); if (kr == KERN_SUCCESS) break; assert(kr == KERN_NAME_EXISTS); @@ -96,12 +107,26 @@ task_insert_send_right( return name; } -void bootstrap_create() +void bootstrap_create(void) { + int compat; + int n = 0; +#ifdef MACH_XEN + struct multiboot_module *bmods = ((struct multiboot_module *) + boot_info.mod_start); + if (bmods) + for (n = 0; bmods[n].mod_start; n++) { + bmods[n].mod_start = kvtophys(bmods[n].mod_start + (vm_offset_t) bmods); + bmods[n].mod_end = kvtophys(bmods[n].mod_end + (vm_offset_t) bmods); + bmods[n].string = kvtophys(bmods[n].string + (vm_offset_t) bmods); + } + boot_info.mods_count = n; + boot_info.flags |= MULTIBOOT_MODS; +#else /* MACH_XEN */ struct multiboot_module *bmods = ((struct multiboot_module *) phystokv(boot_info.mods_addr)); - int compat; +#endif /* MACH_XEN */ if (!(boot_info.flags & MULTIBOOT_MODS) || (boot_info.mods_count == 0)) panic ("No bootstrap code loaded with the kernel!"); @@ -125,24 +150,24 @@ void bootstrap_create() } else { - int i, losers, maxlen; + int i, losers; /* Initialize boot script variables. We leak these send rights. */ losers = boot_script_set_variable ("host-port", VAL_PORT, - (int)ipc_port_make_send(realhost.host_priv_self)); + (long) realhost.host_priv_self); if (losers) panic ("cannot set boot-script variable host-port: %s", boot_script_error_string (losers)); losers = boot_script_set_variable ("device-port", VAL_PORT, - (int) ipc_port_make_send(master_device_port)); + (long) master_device_port); if (losers) panic ("cannot set boot-script variable device-port: %s", boot_script_error_string (losers)); losers = boot_script_set_variable ("kernel-command-line", VAL_STR, - (int) kernel_cmdline); + (long) kernel_cmdline); if (losers) panic ("cannot set boot-script variable %s: %s", "kernel-command-line", boot_script_error_string (losers)); @@ -161,12 +186,12 @@ void bootstrap_create() get_compat_strings(flag_string, root_string); losers = boot_script_set_variable ("boot-args", VAL_STR, - (int) flag_string); + (long) flag_string); if (losers) panic ("cannot set boot-script variable %s: %s", "boot-args", boot_script_error_string (losers)); losers = boot_script_set_variable ("root-device", VAL_STR, - (int) root_string); + (long) root_string); if (losers) panic ("cannot set boot-script variable %s: %s", "root-device", boot_script_error_string (losers)); @@ -187,7 +212,7 @@ void bootstrap_create() char *var = memcpy (alloca (len), *ep, len); char *val = strchr (var, '='); *val++ = '\0'; - losers = boot_script_set_variable (var, VAL_STR, (int) val); + losers = boot_script_set_variable (var, VAL_STR, (long) val); if (losers) panic ("cannot set boot-script variable %s: %s", var, boot_script_error_string (losers)); @@ -208,7 +233,7 @@ void bootstrap_create() if (eq == 0) continue; *eq++ = '\0'; - losers = boot_script_set_variable (word, VAL_STR, (int) eq); + losers = boot_script_set_variable (word, VAL_STR, (long) eq); if (losers) panic ("cannot set boot-script variable %s: %s", word, boot_script_error_string (losers)); @@ -216,15 +241,11 @@ void bootstrap_create() } #endif - maxlen = 0; for (i = 0; i < boot_info.mods_count; ++i) { int err; char *line = (char*)phystokv(bmods[i].string); - int len = strlen (line) + 1; - if (len > maxlen) - maxlen = len; - printf ("\rmodule %d: %*s", i, -maxlen, line); + printf ("module %d: %s\n", i, line); err = boot_script_parse_line (&bmods[i], line); if (err) { @@ -232,7 +253,7 @@ void bootstrap_create() ++losers; } } - printf ("\r%d multiboot modules %*s", i, -maxlen, ""); + printf ("%d multiboot modules\n", i); if (losers) panic ("%d of %d boot script commands could not be parsed", losers, boot_info.mods_count); @@ -241,8 +262,10 @@ void bootstrap_create() panic ("ERROR in executing boot script: %s", boot_script_error_string (losers)); } - /* XXX at this point, we could free all the memory used - by the boot modules and the boot loader's descriptors and such. */ + /* XXX we could free the memory used + by the boot loader's descriptors and such. */ + for (n = 0; n < boot_info.mods_count; n++) + vm_page_create(bmods[n].mod_start, bmods[n].mod_end); } static void @@ -292,7 +315,7 @@ itoa( vm_size_t num) { char buf[sizeof(vm_size_t)*2+3]; - register char *np; + char *np; np = buf + sizeof(buf); *--np = 0; @@ -312,7 +335,7 @@ itoa( */ static void get_compat_strings(char *flags_str, char *root_str) { - register char *ip, *cp; + char *ip, *cp; strcpy (root_str, "UNKNOWN"); @@ -354,6 +377,7 @@ static void get_compat_strings(char *fla *cp = '\0'; } +#if 0 /* * Copy boot_data (executable) to the user portion of this task. */ @@ -379,6 +403,7 @@ static boolean_t load_bootstrap_symbols #else static boolean_t load_bootstrap_symbols = FALSE; #endif +#endif @@ -432,7 +457,7 @@ read_exec(void *handle, vm_offset_t file if (file_size > 0) { err = copyout((char *)phystokv (mod->mod_start) + file_ofs, - mem_addr, file_size); + (void *)mem_addr, file_size); assert(err == 0); } @@ -447,10 +472,10 @@ read_exec(void *handle, vm_offset_t file static void copy_bootstrap(void *e, exec_info_t *boot_exec_info) { - register vm_map_t user_map = current_task()->map; + //register vm_map_t user_map = current_task()->map; int err; - if (err = exec_load(boot_read, read_exec, e, boot_exec_info)) + if ((err = exec_load(boot_read, read_exec, e, boot_exec_info))) panic("Cannot load user-bootstrap image: error code %d", err); #if MACH_KDB @@ -491,16 +516,12 @@ static void copy_bootstrap(void *e, exec /* * Allocate the stack, and build the argument list. */ -extern vm_offset_t user_stack_low(); -extern vm_offset_t set_user_regs(); - static void build_args_and_stack(struct exec_info *boot_exec_info, char **argv, char **envp) { vm_offset_t stack_base; vm_size_t stack_size; - register char * arg_ptr; int arg_count, envc; int arg_len; @@ -562,7 +583,7 @@ build_args_and_stack(struct exec_info *b /* * first the argument count */ - (void) copyout((char *)&arg_count, + (void) copyout(&arg_count, arg_pos, sizeof(integer_t)); arg_pos += sizeof(integer_t); @@ -575,7 +596,7 @@ build_args_and_stack(struct exec_info *b arg_item_len = strlen(arg_ptr) + 1; /* include trailing 0 */ /* set string pointer */ - (void) copyout((char *)&string_pos, + (void) copyout(&string_pos, arg_pos, sizeof (char *)); arg_pos += sizeof(char *); @@ -588,7 +609,7 @@ build_args_and_stack(struct exec_info *b /* * Null terminator for argv. */ - (void) copyout((char *)&zero, arg_pos, sizeof(char *)); + (void) copyout(&zero, arg_pos, sizeof(char *)); arg_pos += sizeof(char *); /* @@ -599,7 +620,7 @@ build_args_and_stack(struct exec_info *b arg_item_len = strlen(arg_ptr) + 1; /* include trailing 0 */ /* set string pointer */ - (void) copyout((char *)&string_pos, + (void) copyout(&string_pos, arg_pos, sizeof (char *)); arg_pos += sizeof(char *); @@ -612,12 +633,12 @@ build_args_and_stack(struct exec_info *b /* * Null terminator for envp. */ - (void) copyout((char *)&zero, arg_pos, sizeof(char *)); + (void) copyout(&zero, arg_pos, sizeof(char *)); } static void -user_bootstrap_compat() +user_bootstrap_compat(void) { exec_info_t boot_exec_info; @@ -690,9 +711,7 @@ boot_script_exec_cmd (void *hook, task_t char **argv, char *strings, int stringlen) { struct multiboot_module *mod = hook; - exec_info_t boot_exec_info; - register vm_map_t user_map = current_task()->map; int err; if (task != MACH_PORT_NULL) @@ -700,13 +719,14 @@ boot_script_exec_cmd (void *hook, task_t thread_t thread; struct user_bootstrap_info info = { mod, argv, 0, }; simple_lock_init (&info.lock); - simple_lock (&info.lock); err = thread_create ((task_t)task, &thread); assert(err == 0); + simple_lock (&info.lock); thread->saved.other = &info; thread_start (thread, user_bootstrap); - thread_resume (thread); + err = thread_resume (thread); + assert(err == 0); /* We need to synchronize with the new thread and block this main thread until it has finished referring to our local state. */ @@ -715,13 +735,15 @@ boot_script_exec_cmd (void *hook, task_t thread_sleep ((event_t) &info, simple_lock_addr(info.lock), FALSE); simple_lock (&info.lock); } + simple_unlock (&info.lock); + thread_deallocate (thread); printf ("\n"); } return 0; } -static void user_bootstrap() +static void user_bootstrap(void) { struct user_bootstrap_info *info = current_thread()->saved.other; exec_info_t boot_exec_info; @@ -749,6 +771,7 @@ static void user_bootstrap() simple_lock (&info->lock); assert (!info->done); info->done = 1; + simple_unlock (&info->lock); thread_wakeup ((event_t) info); /* @@ -781,6 +804,7 @@ boot_script_task_create (struct cmd *cmd printf("boot_script_task_create failed with %x\n", rc); return BOOT_SCRIPT_MACH_ERROR; } + task_set_name(cmd->task, cmd->path); return 0; } @@ -800,10 +824,18 @@ boot_script_task_resume (struct cmd *cmd int boot_script_prompt_task_resume (struct cmd *cmd) { +#if ! MACH_KDB char xx[5]; +#endif + + printf ("Pausing for %s...\n", cmd->path); - printf ("Hit return to resume %s...", cmd->path); +#if ! MACH_KDB + printf ("Hit to resume bootstrap."); safe_gets (xx, sizeof xx); +#else + SoftDebugger("Hit `c' to resume bootstrap."); +#endif return boot_script_task_resume (cmd); } @@ -813,12 +845,14 @@ boot_script_free_task (task_t task, int { if (aborting) task_terminate (task); + task_deallocate (task); } int boot_script_insert_right (struct cmd *cmd, mach_port_t port, mach_port_t *name) { - *name = task_insert_send_right (cmd->task, (ipc_port_t)port); + *name = task_insert_send_right (cmd->task, + ipc_port_make_send((ipc_port_t) port)); return 0; }