void init_startup_thread(uint32_t arg) { /* Threads have arguments for functions they run, we don't need any. Silence the compiler warning by using the argument. */ arg = arg; kprintf("Mounting filesystems\n"); vfs_mount_all(); kprintf("Initializing networking\n"); network_init(); if(bootargs_get("initprog") == NULL) { kprintf("No initial program (initprog), dropping to fallback\n"); init_startup_fallback(); } kprintf("Starting initial program '%s'\n", bootargs_get("initprog")); /* `process_start` no longer takes an executable as its argument, so we need to start initprog with `process_spawn`. */ process_id_t pid = process_spawn(bootargs_get("initprog")); if (pid < 0) { KERNEL_PANIC("Couldn't fit initial program in process table.\n"); } process_join(pid); /* The current process_start() should never return. */ KERNEL_PANIC("Run out of initprog.\n"); }
void init_startup_thread(uint32_t arg) { /* Threads have arguments for functions they run, we don't need any. Silence the compiler warning by using the argument. */ arg = arg; process_id_t pid; kprintf("Mounting filesystems\n"); vfs_mount_all(); kprintf("Initializing networking\n"); network_init(); if(bootargs_get("initprog") == NULL) { kprintf("No initial program (initprog), dropping to fallback\n"); init_startup_fallback(); } kprintf("Starting initial program '%s'\n", bootargs_get("initprog")); pid = process_spawn(bootargs_get("initprog")); if (pid < 0) KERNEL_PANIC("Couldn't fit initial program in process table.\n"); process_join(pid); halt_kernel(); }
void init_startup_thread(uint32_t arg) { /* Threads have arguments for functions they run, we don't need any. Silence the compiler warning by using the argument. */ arg = arg; kprintf("Mounting filesystems\n"); vfs_mount_all(); if(bootargs_get("initprog") == NULL) { kprintf("No initial program (initprog), dropping to fallback\n"); init_startup_fallback(); } kprintf("Starting initial program '%s'\n", bootargs_get("initprog")); // Run Process-Init for at lave process table process_init(); process_spawn(bootargs_get("initprog"), NULL); }
void init_startup_thread(uint32_t arg) { /* Threads have arguments for functions they run, we don't need any. Silence the compiler warning by using the argument. */ arg = arg; kprintf("Mounting filesystems\n"); vfs_mount_all(); kprintf("Initializing networking\n"); network_init(); if(bootargs_get("initprog") == NULL) { kprintf("No initial program (initprog), dropping to fallback\n"); init_startup_fallback(); } kprintf("Starting initial program '%s'\n", bootargs_get("initprog")); process_run(bootargs_get("initprog")); /* The current process_run() should never return. */ KERNEL_PANIC("Run out of initprog.\n"); }
/** * Fallback function for system startup. This function is executed * if the initial startup program (shell or other userland process given * with initprog boot argument) is not started or specified. * * This is a good place for some kernel test code! * */ void init_startup_fallback(void) { DEBUG("debuginit", "In init_startup_fallback\n"); /* Run console test if "testconsole" was given as boot argument. */ if (bootargs_get("testconsole") != NULL) { device_t *dev; gcd_t *gcd; char buffer[64]; char buffer2[64]; int len; DEBUG("debuginit", "In console test\n"); /* Find system console (first tty) */ dev = device_get(YAMS_TYPECODE_TTY, 0); KERNEL_ASSERT(dev != NULL); gcd = (gcd_t *)dev->generic_device; KERNEL_ASSERT(gcd != NULL); len = snprintf(buffer, 63, "Hello user! Press any key.\n"); gcd->write(gcd, buffer, len); len = gcd->read(gcd, buffer2, 63); KERNEL_ASSERT(len >= 0); buffer2[len] = '\0'; len = snprintf(buffer, 63, "You said: '%s'\n", buffer2); gcd->write(gcd, buffer, len); DEBUG("debuginit", "Console test done, %d bytes written\n", len); } /* Nothing else to do, so we shut the system down. */ kprintf("Startup fallback code ends.\n"); halt_kernel(); }
void init(void) { TID_t startup_thread; int numcpus; /* Initialize polling TTY driver for kprintf() usage. */ polltty_init(); kwrite("BUENOS is a University Educational Nutshell Operating System\n"); kwrite("==========================================================\n"); kwrite("\n"); kwrite("Copyright (C) 2003-2006 Juha Aatrokoski, Timo Lilja,\n"); kwrite(" Leena Salmela, Teemu Takanen, Aleksi Virtanen\n"); kwrite("See the file COPYING for licensing details.\n"); kwrite("\n"); kwrite("Initializing memory allocation system\n"); kmalloc_init(); kwrite("Reading boot arguments\n"); bootargs_init(); /* Seed the random number generator. */ if (bootargs_get("randomseed") == NULL) { _set_rand_seed(0); } else { int seed = atoi(bootargs_get("randomseed")); kprintf("Seeding pseudorandom number generator with %i\n", seed); _set_rand_seed(seed); } numcpus = cpustatus_count(); kprintf("Detected %i CPUs\n", numcpus); KERNEL_ASSERT(numcpus <= CONFIG_MAX_CPUS); kwrite("Initializing interrupt handling\n"); interrupt_init(numcpus); kwrite("Initializing threading system\n"); thread_table_init(); kwrite("Initializing user process system\n"); process_init(); kwrite("Initializing sleep queue\n"); sleepq_init(); kwrite("Initializing semaphores\n"); semaphore_init(); kwrite("Initializing device drivers\n"); device_init(); kprintf("Initializing virtual filesystem\n"); vfs_init(); kwrite("Initializing scheduler\n"); scheduler_init(); kwrite("Initializing virtual memory\n"); vm_init(); kprintf("Creating initialization thread\n"); startup_thread = thread_create(&init_startup_thread, 0); thread_run(startup_thread); kprintf("Starting threading system and SMP\n"); /* Let other CPUs run */ kernel_bootstrap_finished = 1; _interrupt_clear_bootstrap(); _interrupt_enable(); /* Enter context switch, scheduler will be run automatically, since thread_switch() behaviour is identical to timer tick (thread timeslice is over). */ thread_switch(); /* We should never get here */ KERNEL_PANIC("Threading system startup failed."); }
void init(void) { TID_t startup_thread; int numcpus; /* Initialise Static Allocation */ stalloc_init(); /* Initialize polling TTY driver for kprintf() usage. */ polltty_init(); kwrite("Kudos is an educational operating system by the University of Copenhagen\n"); kwrite("========================================================================\n"); kwrite("Based on the Buenos operating system skeleton\n"); kwrite("\n"); kprintf("Copyright (C) 2003-2016 Juha Aatrokoski, Timo Lilja,\n"); kprintf(" Leena Salmela, Teemu Takanen, Aleksi Virtanen, Philip Meulengracht,\n"); kprintf(" Troels Henriksen, Annie Jane Pinder, Niels Gustav Westphal Serup,\n"); kprintf(" Nicklas Warming Jacobsen, Oleksandr Shturmov.\n"); kwrite("See the file COPYING for licensing details.\n"); kwrite("\n"); kwrite("Reading boot arguments\n"); bootargs_init((void*)BOOT_ARGUMENT_AREA); /* Seed the random number generator. */ if (bootargs_get("randomseed") == NULL) { _set_rand_seed(0); } else { int seed = atoi(bootargs_get("randomseed")); kprintf("Seeding pseudorandom number generator with %i\n", seed); _set_rand_seed(seed); } numcpus = cpustatus_count(); kprintf("Detected %i CPUs\n", numcpus); KERNEL_ASSERT(numcpus <= CONFIG_MAX_CPUS); kwrite("Initializing interrupt handling\n"); interrupt_init(numcpus); kwrite("Initializing threading system\n"); thread_table_init(); kwrite("Initializing sleep queue\n"); sleepq_init(); kwrite("Initializing semaphores\n"); semaphore_init(); kwrite("Initializing device drivers\n"); device_init(); kprintf("Initializing virtual filesystem\n"); vfs_init(); kwrite("Initializing scheduler\n"); scheduler_init(); kwrite("Initializing virtual memory\n"); vm_init(); kprintf("Creating initialization thread\n"); startup_thread = thread_create(&init_startup_thread, 0); thread_run(startup_thread); kprintf("Starting threading system and SMP\n"); /* Let other CPUs run */ kernel_bootstrap_finished = 1; _interrupt_clear_bootstrap(); _interrupt_enable(); /* Enter context switch, scheduler will be run automatically, since thread_switch() behaviour is identical to timer tick (thread timeslice is over). */ thread_switch(); /* We should never get here */ KERNEL_PANIC("Threading system startup failed."); }
int init(uint64_t magic, uint8_t *multiboot) { /* Setup Static Allocation System */ multiboot_info_t *mb_info = (multiboot_info_t*)multiboot; TID_t startup_thread; stalloc_init(); /* Setup video printing */ polltty_init(); kwrite("KUDOS - a skeleton OS for exploring OS concepts\n"); kwrite("===============================================\n"); kwrite("\n"); kwrite("KUDOS is heavily based on BUENOS.\n"); kwrite("\n"); kwrite("Copyright (C) 2015-2016 Troels Henriksen, Annie Jane Pinder,\n"); kwrite(" Niels Gustav Westphal Serup, Oleksandr Shturmov,\n"); kwrite(" Nicklas Warming Jacobsen.\n"); kwrite("\n"); kwrite("Copyright (C) 2014 Philip Meulengracht.\n"); kwrite("\n"); kwrite("Copyright (C) 2003-2012 Juha Aatrokoski, Timo Lilja,\n"); kwrite(" Leena Salmela, Teemu Takanen, Aleksi Virtanen.\n"); kwrite("\n"); kwrite("See the file COPYING for licensing details.\n"); kwrite("\n"); /* Setup GDT/IDT/Exceptions */ kprintf("Initializing interrupt handling\n"); interrupt_init(1); /* Read boot args */ kprintf("Reading boot arguments\n"); bootargs_init((void*)(uint64_t)mb_info->cmdline); /* Setup Memory */ kprintf("Initializing memory system\n"); physmem_init(multiboot); vm_init(); /* Seed the random number generator. */ if (bootargs_get("randomseed") == NULL) { _set_rand_seed(0); } else { int seed = atoi((char*)(uint64_t)bootargs_get("randomseed")); kprintf("Seeding pseudorandom number generator with %i\n", seed); _set_rand_seed(seed); } /* Setup Threading */ kprintf("Initializing threading table\n"); thread_table_init(); kprintf("Initializing sleep queue\n"); sleepq_init(); kprintf("Initializing semaphores\n"); semaphore_init(); /* Start scheduler */ kprintf("Initializing scheduler\n"); scheduler_init(); /* Setup Drivers */ kprintf("Initializing device drivers\n"); device_init(); /* Initialize modules */ kprintf("Initializing kernel modules\n"); modules_init(); kprintf("Initializing virtual filesystem\n"); vfs_init(); kprintf("Creating initialization thread\n"); startup_thread = thread_create(init_startup_thread, 0); thread_run(startup_thread); kprintf("Starting threading system and SMP\n"); /* Enter context switch, scheduler will be run automatically, since thread_switch() behaviour is identical to timer tick (thread timeslice is over). */ thread_switch(); return 0xDEADBEEF; }