/* viengoos.c - Main file for viengoos. Copyright (C) 2007, 2008 Free Software Foundation, Inc. Written by Neal H. Walfield . This file is part of the GNU Hurd. The GNU Hurd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The GNU Hurd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #if HAVE_CONFIG_H #include #endif #include "mutex.h" #ifndef NDEBUG struct ss_lock_trace ss_lock_trace[SS_LOCK_TRACE_COUNT]; int ss_lock_trace_count; #endif #include #include #include #include #include #include #include #include #include #include #include "arch.h" #include "viengoos.h" #include "memory.h" #include "boot-modules.h" #include "cap.h" #include "object.h" #include "activity.h" #include "thread.h" #include "server.h" #include "shutdown.h" #include "output.h" #include "zalloc.h" #include "ager.h" #include "scheduler.h" #define BUG_ADDRESS "" /* The program name. */ char *program_name = "viengoos"; /* The following must be defined and are used to calculate the extents of the laden binary itself. _END is one more than the address of the last byte. */ extern char _start; extern char _end; static struct output_driver output_device; static void parse_args (int argc, char *argv[]) { int i = 1; while (i < argc) { if (!strcmp (argv[i], "--usage")) { i++; printf ("Usage %s [OPTION...]\n", argv[0]); printf ("Try `%s --help' for more information\n", program_name); shutdown_machine (); } else if (!strcmp (argv[i], "--help")) { struct output_driver **drv = output_drivers; i++; printf ("Usage: %s [OPTION...]\n" "\n" "Boot the Hurd system and wrap the L4 privileged system " "calls.\n" "\n" " -o, --output DRV use output driver DRV\n" " -D, --debug LEVEL enable debug output (1-5)" #ifdef DEBUG_ELIDE " (disabled)" #endif "\n" " -h, --halt halt the system at error (default)\n" " -r, --reboot reboot the system at error\n" "\n" " --usage print out some usage information and " "exit\n" " --help display this help and exit\n" " --version output version information and exit\n" "\n", argv[0]); printf ("Valid output drivers are: "); while (*drv) { printf ("%s", (*drv)->name); if (drv == output_drivers) printf (" (default)"); drv++; if (*drv && (*drv)->name) printf (", "); else printf (".\n\n"); } printf ("Report bugs to " BUG_ADDRESS ".\n"); shutdown_machine (); } else if (!strcmp (argv[i], "--version")) { i++; printf ("%s " PACKAGE_VERSION "\n", program_name); shutdown_machine (); } else if (!strcmp (argv[i], "-o") || !strcmp (argv[i], "--output")) { i++; if (!output_init (&output_device, argv[i], true)) panic ("Unknown output driver %s", argv[i]); i++; } else if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--halt")) { i++; shutdown_reset = 0; } else if (!strcmp (argv[i], "-r") || !strcmp (argv[i], "--reset")) { i++; shutdown_reset = 1; } else if (!strcmp (argv[i], "-D") || !strcmp (argv[i], "--debug")) { i++; if (! ('0' <= argv[i][0] && argv[i][0] <= '9')) panic ("Option -D expects an integer argument"); #ifndef DEBUG_ELIDE output_debug = strtol (argv[i], (char **) NULL, 10); #endif i++; } else if (argv[i][0] == '-') panic ("Unsupported option %s", argv[i]); else panic ("Invalid non-option argument %s", argv[i]); } } #include "page-tables.h" struct thread * system_task_load (void) { const char *const argv[] = { boot_modules[0].command_line, NULL }; struct thread *thread; thread = process_spawn (VG_ADDR_VOID, (void *) boot_modules[0].start, (void *) boot_modules[0].end, argv, NULL, true); /* Free the associated memory. */ memory_reservation_clear (memory_reservation_system_executable); return thread; } static void bootstrap (void) __attribute__ ((noinline)); static void bootstrap (void) { object_init (); /* Load the system task. */ struct thread *thread = system_task_load (); /* MEMORY_TOTAL is the total number of frames in the system. We need to know the number of frames that are available to user tasks. This is the sum of the free memory plus that which is already allocated to activities. So far, there is only the root activity. */ memory_total = zalloc_memory + root_activity->frames_total; timer_bootstrap (); scheduler_bootstrap (); thread_bootstrap (); server_bootstrap (); ager_bootstrap (); } int main (int argc, char *argv[]) { printf ("In main\n"); parse_args (argc, argv); debug (1, "%s " PACKAGE_VERSION, program_name); /* print hello message */ arch_bootstrap (); /* Bootstrap the system. */ bootstrap (); schedule (NULL); thread_resume (); }