Example #1
0
void _main()
{
    mem_extent_t *ramext;
    u8 sn[6];
    u32 cpu_clk_hz = 0;
    rtc_time_t tm;
    s32 ret;

    /*
        This section runs with interrupts disabled.  The boot console is not available in this
        section.
    */
    preempt_disable();

    /* Copy kernel read/write data areas into kernel RAM */
    memcpy(&_sdata, &_etext, &_edata - &_sdata);        /* Copy .data section to kernel RAM */
    bzero(&_sbss, &_ebss - &_sbss);                     /* Initialise .bss section          */

    /* Begin platform initialisation */
    if(plat_init() != SUCCESS)
        boot_early_fail(1);

    if(plat_mem_detect() != SUCCESS)    /* Detect installed RAM, initialise memory extents  */
        boot_early_fail(2);

    /* Initialise kernel slabs */
    slab_init(&_ebss);                  /* Slabs sit after the .bss section */

    /* Initialise kernel heap */
    kmeminit(g_slab_end, mem_get_highest_addr(MEM_EXTENT_KERN | MEM_EXTENT_RAM) - KERNEL_STACK_LEN);

    /* Initialise user heap.  Place it in the largest user RAM extent. */
    ramext = mem_get_largest_extent(MEM_EXTENT_USER | MEM_EXTENT_RAM);
    umeminit(ramext->base, ramext->base + ramext->len);

	/* By default, all exceptions cause a context-dump followed by a halt. */
	cpu_irq_init_table();

    /* Initialise device tree */
	if(dev_init() != SUCCESS)
        boot_early_fail(3);

	/*
        It's not yet possible to initialise the real (platform) console because devices haven't
        been enumerated and interrupts are disabled.  In the meantime, create a temporary in-memory
        kernel console device to capture output from the boot process.
    */

    if(early_boot_console_init() != SUCCESS)
        boot_early_fail(4);

    printf("%s\nplatform: %s\n", g_warmup_message, plat_get_name());

    printf("%uMB RAM detected\n", (mem_get_total_size(MEM_EXTENT_USER | MEM_EXTENT_RAM)
            + mem_get_total_size(MEM_EXTENT_KERN | MEM_EXTENT_RAM)) >> 20);

    /* === Initialise peripherals - phase 2 === */
    if(dev_enumerate() != SUCCESS)
        boot_early_fail(5);

    /* Initialise the console */
    if(plat_console_init() != SUCCESS)
        boot_early_fail(6);

    ret = sched_init("[sys]");      /* Init scheduler and create system process */

    /*
        Enable interrupts and continue booting
    */
    preempt_enable();

    /* Copy the contents of the temporary console to the real console; close the temp console. */
    early_boot_console_close();

    /* Activate red LED while the boot process continues */
	plat_led_off(LED_ALL);
	plat_led_on(LED_RED);

    /*
        Device enumeration is done; interrupts are enabled, and the console should be functional.
        Booting continues...
    */

    /* Zero any user RAM extents.  This happens after init'ing the DUART, because beeper. */
/*
    put("Clearing user RAM: ");
    mem_zero_extents(MEM_EXTENT_USER | MEM_EXTENT_RAM);
    puts("done");
*/

    /* Initialise the block cache, then scan mass-storage devices for partitions */
    block_cache_init(2039);
    partition_init();

    boot_list_mass_storage();
    boot_list_partitions();

    /* ret is set by the call to sched_init(), above */
    if(ret != SUCCESS)
        printf("sched: init failed: %s\n", kstrerror(ret));

    ret = vfs_init();
	if(ret != SUCCESS)
		printf("vfs: init failed: %s\n", kstrerror(ret));

    /* Display approximate CPU clock speed */
    if(plat_get_cpu_clock(&cpu_clk_hz) == SUCCESS)
        printf("\nCPU fclk ~%2u.%uMHz\n", cpu_clk_hz / 1000000, (cpu_clk_hz % 1000000) / 100000);

    /* Initialise tick handler */
    tick_init();

    /* Display memory information */
	printf("%u bytes of kernel heap memory available\n"
           "%u bytes of user memory available\n", kfreemem(), ufreemem());

    /* Display platform serial number */
    if(plat_get_serial_number(sn) == SUCCESS)
    {
        printf("Hardware serial number %02X%02X%02X%02X%02X%02X\n",
                sn[0], sn[1], sn[2], sn[3], sn[4], sn[5]);
    }

    /* Display the current date and time */
    if(get_time(&tm) == SUCCESS)
    {
        char timebuf[12], datebuf[32];

        if((time_iso8601(&tm, timebuf, sizeof(timebuf)) == SUCCESS) &&
            (date_long(&tm, datebuf, sizeof(datebuf)) == SUCCESS))
            printf("%s %s\n", timebuf, datebuf);
        else
            puts("Date/time invalid - please set clock");
    }

    /* Create housekeeper process */
//    proc_create(0, 0, "[hk]", NULL, housekeeper, 0, 0, PROC_TYPE_KERNEL, NULL, NULL);

    /* Initialise networking system */
    ret = net_init();
    if(ret != SUCCESS)
        printf("net: init failed: %s\n", kstrerror(ret));

    /* Startup complete - activate green LED */
	plat_led_off(LED_RED);
	plat_led_on(LED_GREEN);

	monitor();      /* start interactive "shell" thing */

	cpu_halt();		/* should never be reached */
}
Example #2
0
int
main (int argc, char *argv[])
{
    GError *error = NULL;
    gboolean config_migrated = FALSE;
    char *config_migrate_msg;
    int exit_code = EXIT_FAILURE;

    /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
#ifdef HAVE_SETLOCALE
    (void) setlocale (LC_ALL, "");
#endif
    (void) bindtextdomain (PACKAGE, LOCALEDIR);
    (void) textdomain (PACKAGE);

    /* do this before args parsing */
    str_init_strings (NULL);

    if (!mc_args_parse (&argc, &argv, "mc", &error))
    {
      startup_exit_falure:
        fprintf (stderr, _("Failed to run:\n%s\n"), error->message);
        g_error_free (error);
        g_free (mc_global.tty.shell);
      startup_exit_ok:
        str_uninit_strings ();
        return exit_code;
    }

    /* do this before mc_args_show_info () to view paths in the --datadir-info output */
    OS_Setup ();

    if (!g_path_is_absolute (mc_config_get_home_dir ()))
    {
        error = g_error_new (MC_ERROR, 0, "%s: %s", _("Home directory path is not absolute"),
                             mc_config_get_home_dir ());
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    if (!mc_args_show_info ())
    {
        exit_code = EXIT_SUCCESS;
        goto startup_exit_ok;
    }

    if (!events_init (&error))
        goto startup_exit_falure;

    mc_config_init_config_paths (&error);
    if (error == NULL)
        config_migrated = mc_config_migrate_from_old_place (&error, &config_migrate_msg);
    if (error != NULL)
    {
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    vfs_init ();
    vfs_plugins_init ();
    vfs_setup_work_dir ();

    /* Set up temporary directory after VFS initialization */
    mc_tmpdir ();

    /* do this after vfs initialization due to mc_setctl() call in mc_setup_by_args() */
    if (!mc_setup_by_args (argc, argv, &error))
    {
        vfs_shut ();
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    /* check terminal type
     * $TEMR must be set and not empty
     * mc_global.tty.xterm_flag is used in init_key() and tty_init()
     * Do this after mc_args_handle() where mc_args__force_xterm is set up.
     */
    mc_global.tty.xterm_flag = tty_check_term (mc_args__force_xterm);

    /* NOTE: This has to be called before tty_init or whatever routine
       calls any define_sequence */
    init_key ();

    /* Must be done before installing the SIGCHLD handler [[FIXME]] */
    handle_console (CONSOLE_INIT);

#ifdef ENABLE_SUBSHELL
    /* Don't use subshell when invoked as viewer or editor */
    if (mc_global.mc_run_mode != MC_RUN_FULL)
        mc_global.tty.use_subshell = FALSE;

    if (mc_global.tty.use_subshell)
        subshell_get_console_attributes ();
#endif /* ENABLE_SUBSHELL */

    /* Install the SIGCHLD handler; must be done before init_subshell() */
    init_sigchld ();

    /* We need this, since ncurses endwin () doesn't restore the signals */
    save_stop_handler ();

    /* Must be done before init_subshell, to set up the terminal size: */
    /* FIXME: Should be removed and LINES and COLS computed on subshell */
    tty_init (!mc_args__nomouse, mc_global.tty.xterm_flag);

    load_setup ();

    /* start check mc_global.display_codepage and mc_global.source_codepage */
    check_codeset ();

    /* Removing this from the X code let's us type C-c */
    load_key_defs ();

    load_keymap_defs (!mc_args__nokeymap);

    macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t));

    tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors);

    mc_skin_init (&error);
    if (error != NULL)
    {
        message (D_ERROR, _("Warning"), "%s", error->message);
        g_error_free (error);
        error = NULL;
    }

    dlg_set_default_colors ();

#ifdef ENABLE_SUBSHELL
    /* Done here to ensure that the subshell doesn't  */
    /* inherit the file descriptors opened below, etc */
    if (mc_global.tty.use_subshell)
        init_subshell ();
#endif /* ENABLE_SUBSHELL */

    /* Also done after init_subshell, to save any shell init file messages */
    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_SAVE);

    if (mc_global.tty.alternate_plus_minus)
        application_keypad_mode ();

    /* Done after subshell initialization to allow select and paste text by mouse
       w/o Shift button in subshell in the native console */
    init_mouse ();

    /* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is
       separate for the normal and alternate screens */
    enable_bracketed_paste ();

    /* subshell_prompt is NULL here */
    mc_prompt = (geteuid () == 0) ? "# " : "$ ";

    if (config_migrated)
    {
        message (D_ERROR, _("Warning"), "%s", config_migrate_msg);
        g_free (config_migrate_msg);
    }

    /* Program main loop */
    if (mc_global.midnight_shutdown)
        exit_code = EXIT_SUCCESS;
    else
        exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE;

    /* Save the tree store */
    (void) tree_store_save ();

    free_keymap_defs ();

    /* Virtual File System shutdown */
    vfs_shut ();

    flush_extension_file ();    /* does only free memory */

    mc_skin_deinit ();
    tty_colors_done ();

    tty_shutdown ();

    done_setup ();

    if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0)
        handle_console (CONSOLE_RESTORE);
    if (mc_global.tty.alternate_plus_minus)
        numeric_keypad_mode ();

    (void) signal (SIGCHLD, SIG_DFL);   /* Disable the SIGCHLD handler */

    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_DONE);

    if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL
        && last_wd_string != NULL && !print_last_revert)
    {
        int last_wd_fd;

        last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
                           S_IRUSR | S_IWUSR);
        if (last_wd_fd != -1)
        {
            ssize_t ret1;
            int ret2;
            ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string));
            ret2 = close (last_wd_fd);
            (void) ret1;
            (void) ret2;
        }
    }
    g_free (last_wd_string);

    g_free (mc_global.tty.shell);

    done_key ();

    if (macros_list != NULL)
    {
        guint i;
        for (i = 0; i < macros_list->len; i++)
        {
            macros_t *macros;

            macros = &g_array_index (macros_list, struct macros_t, i);
            if (macros != NULL && macros->macro != NULL)
                (void) g_array_free (macros->macro, FALSE);
        }
        (void) g_array_free (macros_list, TRUE);
    }
Example #3
0
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;
}
Example #4
0
void vfs_setup(CallChain next) {
	char *res_path, *storage_path, *cache_path;
	get_core_paths(&res_path, &storage_path, &cache_path);

	char *local_res_path = strfmt("%s%cresources", storage_path, vfs_get_syspath_separator());
	vfs_syspath_normalize_inplace(local_res_path);

	log_info("Resource path: %s", res_path);
	log_info("Storage path: %s", storage_path);
	log_info("Local resource path: %s", local_res_path);
	log_info("Cache path: %s", cache_path);

	struct mpoint_t {
		const char *dest;    const char *syspath; bool loadpaks; uint flags;
	} mpts[] = {
		// per-user directory, where configs, replays, screenshots, etc. get stored
		{ "storage",         storage_path,        false,         VFS_SYSPATH_MOUNT_MKDIR },

		// system-wide directory, contains all of the game assets
		{ "resdirs",         res_path,            true,          VFS_SYSPATH_MOUNT_READONLY },

		// subpath of storage, files here override the global assets
		{ "resdirs",         local_res_path,      true,          VFS_SYSPATH_MOUNT_MKDIR | VFS_SYSPATH_MOUNT_READONLY },

		// per-user directory, to contain various cached resources to speed up loading times
		{ "cache",           cache_path,          false,         VFS_SYSPATH_MOUNT_MKDIR },

		{NULL}
	};

	vfs_init();

	// temporary union of the "real" directories
	vfs_create_union_mountpoint("resdirs");

	// temporary union of the packages (e.g. zip files)
	vfs_create_union_mountpoint("respkgs");

	// permanent union of respkgs and resdirs
	// this way, files in any of the "real" directories always have priority over anything in packages
	vfs_create_union_mountpoint("res");

	for(struct mpoint_t *mp = mpts; mp->dest; ++mp) {
		if(mp->loadpaks) {
			// mount it to a temporary mountpoint to get a list of packages from this directory
			if(!vfs_mount_syspath("tmp", mp->syspath, mp->flags)) {
				log_fatal("Failed to mount '%s': %s", mp->syspath, vfs_get_error());
			}

			if(!vfs_query("tmp").is_dir) {
				log_error("'%s' is not a directory", mp->syspath);
				vfs_unmount("tmp");
				continue;
			}

			// load all packages from this directory into the respkgs union
			load_packages("tmp", "respkgs");

			// now mount it to the intended destination, and remove the temporary mountpoint
			vfs_mount_alias(mp->dest, "tmp");
			vfs_unmount("tmp");
		} else if(!vfs_mount_syspath(mp->dest, mp->syspath, mp->flags)) {
			log_fatal("Failed to mount '%s': %s", mp->syspath, vfs_get_error());
		}
	}

	vfs_mkdir_required("storage/replays");
	vfs_mkdir_required("storage/screenshots");

	free(local_res_path);
	free(res_path);
	free(storage_path);
	free(cache_path);

	// set up the final "res" union and get rid of the temporaries

	vfs_mount_alias("res", "respkgs");
	vfs_mount_alias("res", "resdirs");
	// vfs_make_readonly("res");

	vfs_unmount("resdirs");
	vfs_unmount("respkgs");

	run_call_chain(&next, NULL);
}
Example #5
0
extern "C" int
main(stage2_args *args)
{
	TRACE(("boot(): enter\n"));

	if (heap_init(args) < B_OK)
		panic("Could not initialize heap!\n");

	TRACE(("boot(): heap initialized...\n"));

	// set debug syslog default
#if KDEBUG_ENABLE_DEBUG_SYSLOG
	gKernelArgs.keep_debug_output_buffer = true;
#endif

	add_stage2_driver_settings(args);

	platform_init_video();

	// the main platform dependent initialisation
	// has already taken place at this point.

	if (vfs_init(args) < B_OK)
		panic("Could not initialize VFS!\n");

	dprintf("Welcome to the Haiku boot loader!\n");

	bool mountedAllVolumes = false;

	BootVolume bootVolume;
	PathBlacklist pathBlacklist;

	if (get_boot_file_system(args, bootVolume) != B_OK
		|| (platform_boot_options() & BOOT_OPTION_MENU) != 0) {
		if (!bootVolume.IsValid())
			puts("\tno boot path found, scan for all partitions...\n");

		if (mount_file_systems(args) < B_OK) {
			// That's unfortunate, but we still give the user the possibility
			// to insert a CD-ROM or just rescan the available devices
			puts("Could not locate any supported boot devices!\n");
		}

		// ToDo: check if there is only one bootable volume!

		mountedAllVolumes = true;

		if (user_menu(bootVolume, pathBlacklist) < B_OK) {
			// user requested to quit the loader
			goto out;
		}
	}

	if (bootVolume.IsValid()) {
		// we got a volume to boot from!
		status_t status;
		while ((status = load_kernel(args, bootVolume)) < B_OK) {
			// loading the kernel failed, so let the user choose another
			// volume to boot from until it works
			bootVolume.Unset();

			if (!mountedAllVolumes) {
				// mount all other file systems, if not already happened
				if (mount_file_systems(args) < B_OK)
					panic("Could not locate any supported boot devices!\n");

				mountedAllVolumes = true;
			}

			if (user_menu(bootVolume, pathBlacklist) != B_OK
				|| !bootVolume.IsValid()) {
				// user requested to quit the loader
				goto out;
			}
		}

		// if everything is okay, continue booting; the kernel
		// is already loaded at this point and we definitely
		// know our boot volume, too
		if (status == B_OK) {
			if (bootVolume.IsPackaged()) {
				packagefs_apply_path_blacklist(bootVolume.SystemDirectory(),
					pathBlacklist);
			}

			register_boot_file_system(bootVolume);

			if ((platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT) == 0)
				platform_switch_to_logo();

			load_modules(args, bootVolume);
			load_driver_settings(args, bootVolume.RootDirectory());

			// apply boot settings
			apply_boot_settings();

			// set up kernel args version info
			gKernelArgs.kernel_args_size = sizeof(kernel_args);
			gKernelArgs.version = CURRENT_KERNEL_ARGS_VERSION;

			// clone the boot_volume KMessage into kernel accessible memory
			// note, that we need to 4 byte align the buffer and thus allocate
			// 3 more bytes
			void* buffer = kernel_args_malloc(gBootVolume.ContentSize() + 3);
			if (!buffer) {
				panic("Could not allocate memory for the boot volume kernel "
					"arguments");
			}

			buffer = (void*)(((addr_t)buffer + 3) & ~(addr_t)0x3);
			memcpy(buffer, gBootVolume.Buffer(), gBootVolume.ContentSize());
			gKernelArgs.boot_volume = buffer;
			gKernelArgs.boot_volume_size = gBootVolume.ContentSize();

			// ToDo: cleanup, heap_release() etc.
			heap_print_statistics();
			platform_start_kernel();
		}
	}

out:
	heap_release(args);
	return 0;
}
Example #6
0
void kernel_init(multiboot_info_t *mboot_info)
{
	extern char __start_bss[], __stop_bss[];

	memset(__start_bss, 0, __stop_bss - __start_bss);
	/* mboot_info is a physical address.  while some arches currently have the
	 * lower memory mapped, everyone should have it mapped at kernbase by now.
	 * also, it might be in 'free' memory, so once we start dynamically using
	 * memory, we may clobber it. */
	multiboot_kaddr = (struct multiboot_info*)((physaddr_t)mboot_info
                                               + KERNBASE);
	extract_multiboot_cmdline(multiboot_kaddr);

	cons_init();
	print_cpuinfo();

	printk("Boot Command Line: '%s'\n", boot_cmdline);

	exception_table_init();
	cache_init();					// Determine systems's cache properties
	pmem_init(multiboot_kaddr);
	kmem_cache_init();              // Sets up slab allocator
	kmalloc_init();
	hashtable_init();
	radix_init();
	cache_color_alloc_init();       // Inits data structs
	colored_page_alloc_init();      // Allocates colors for agnostic processes
	acpiinit();
	topology_init();
	kthread_init();					/* might need to tweak when this happens */
	vmr_init();
	file_init();
	page_check();
	idt_init();
	kernel_msg_init();
	timer_init();
	vfs_init();
	devfs_init();
	train_timing();
	kb_buf_init(&cons_buf);
	arch_init();
	block_init();
	enable_irq();
	run_linker_funcs();
	/* reset/init devtab after linker funcs 3 and 4.  these run NIC and medium
	 * pre-inits, which need to happen before devether. */
	devtabreset();
	devtabinit();

#ifdef CONFIG_EXT2FS
	mount_fs(&ext2_fs_type, "/dev/ramdisk", "/mnt", 0);
#endif /* CONFIG_EXT2FS */
#ifdef CONFIG_ETH_AUDIO
	eth_audio_init();
#endif /* CONFIG_ETH_AUDIO */
	get_coreboot_info(&sysinfo);
	booting = 0;

#ifdef CONFIG_RUN_INIT_SCRIPT
	if (run_init_script()) {
		printk("Configured to run init script, but no script specified!\n");
		manager();
	}
#else
	manager();
#endif
}
Example #7
0
int main_loop(struct multiboot_info *boot_info)
{
    _kclear();
    syscall_init();
    module_start = (char*) *((unsigned int*)boot_info->mods_addr);
	module_end = *((unsigned int*)(boot_info->mods_addr+4));
    _kcolor(BRIGHT_GREEN);
    _kputs(DREAMOS_VER);
    _kcolor(WHITE);
    _kputs(LNG_SITE);
    _kcolor(BRIGHT_BLUE);
    _kputs(SITEURL);
    _kputs("\n");
    _kcolor(WHITE);
    _kputs("\n");    
    _kputs(LNG_GDT);
    init_gdt();
    _kprintOK();

    outportb(0xFF, MASTER_PORT_1);
    outportb(0xFF, SLAVE_PORT_1);
    _kputs(LNG_IDT);        
    asm("cli");   
    init_idt();
    _kprintOK();  
    _kputs(LNG_PIC8259);
    init_IRQ();   
    _kprintOK();            	    
    set_memorysize((boot_info->mem_upper+boot_info->mem_lower)*1024);
    init_mem();       
    asm("sti");
    _kprintOK();   
    init_paging();    
    _kprintOK();
    printf("Memory (upper) amount-> %d Mb \n", boot_info->mem_upper/1024);
    printf("Memory (lower) amount-> %d kb \n", boot_info->mem_lower);	
    /** Alloc and fill CPUID structure */
    sinfo = kmalloc(sizeof(struct cpuinfo_generic));    
    get_cpuid (sinfo);        
    vfs_init();
    initfs_init();      
	if(boot_info->mods_count > 0) printf("Found n. %d Modules\n", boot_info->mods_count);				
    printf("\n");
    tasks_init();
    init_scheduler();
    _kprintOK();
    printf(LNG_PIT8253);    
    printf("----\n");    
    printf(LNG_SHELL);    
    _kprintOK();
		printf("[+] Address: 0x%x\n", &end);		   	        
		printf("\n");
		dbg_bochs_print((const unsigned char*)"DreamOS Debug String for Bochs\n");
#ifdef BOCHS_DEBUG
		dbg_bochs_print((const unsigned char*)"DreamOS Debug String for Bochs\n");
#endif
		configure_PIT ();   
		new_task("idle", idle);		
		new_task("dreamshell", shell);
    return 0;
}
Example #8
0
File: fs.c Project: spinlock/ucore
void
fs_init(void) {
    vfs_init();
    dev_init();
    pipe_init();
}
Example #9
0
File: init.c Project: fixos/fixos
// Real entry point of the OS :
void init() {
	unsigned int freq;

	interrupt_init();

	earlyterm_init();
	earlyterm_clear();

	kbd_init();
	rtc_init();
	time_init();

	earlyterm_write("Kernel initialization...\n");

	set_kernel_print(&earlyterm_write);
	printk(LOG_INFO, "cmd args: '%s'\n", &cmdargs_begin);

	cmdline_parse(&cmdargs_begin, 1024);

	mmu_init();
	pm_init_pages();

	stimer_init();
	hwkbd_start_periodic_update();

	DBG_WAIT;

	interrupt_inhibit_all(0);


	// console initialisation as soon as possible
	dev_init();
	// add TTY device (on major 4)
	ttydev_device.init();
	dev_register_device(&ttydev_device, 4);

	// add virtual terminal TTYs
	vt_init();

	// USB initialisation
	usb_init();
	// add usb-acm TTY
	acm_usb_init();

	DBG_WAIT;

	// will be the last message displayed on early console
	printk(LOG_INFO, "Switching screen to tty1...\n  The display will be cleared.\n");
	console_make_active();

	// in all cases, Virtual Terminals should be made active (tty1)
	DBG_WAIT;
	vt_set_active(0);


	// need to be changed for "overclocking" :
	//freq_change(FREQ_STC_4, FREQ_DIV_1, FREQ_DIV_4);
	
	freq_time_calibrate();

	freq = freq_get_internal_hz();
	printk(LOG_INFO, "CPU freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	freq = freq_get_peripheral_hz();
	printk(LOG_INFO, "Peripheral freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	// initialize sysctl tables
	ctl_init();

	//test_keyboard_int();

	//test_virtual_mem();

	//asm volatile ("trapa #50");

	//DBG_WAIT;
	

	// Initializing VFS and device sub-sytems, mount platform filesystems,
	// register platform devices...
	
	vfs_init();
	vfs_file_init();

	vfs_register_fs(&smemfs_file_system, VFS_REGISTER_STATIC);
	vfs_register_fs(&protofs_file_system, VFS_REGISTER_STATIC);
	vfs_mount("protofs", NULL, VFS_MOUNT_ROOT);

	vfs_create("/", "dev", INODE_TYPE_PARENT, INODE_FLAG_READ | INODE_FLAG_EXEC, 0);
	vfs_create("/dev", "tty1", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040000);
	vfs_create("/dev", "tty2", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040001);
	vfs_create("/dev", "serial", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00030000);

	vfs_create("/dev", "console", INODE_TYPE_DEV, INODE_FLAG_WRITE, 
			console_get_device());

	DBG_WAIT;

	// keyboard input for virtual terminals
	kbd_set_kstroke_handler(&vt_key_stroke);


	// mount additional filesystems
	vfs_create("/", "mnt", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);
	vfs_create("/mnt", "smem", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);

	vfs_mount("smemfs", "/mnt/smem", VFS_MOUNT_NORMAL);
	
	DBG_WAIT;

	// set /dev/display device
	_display_device.init();
	dev_register_device(&_display_device, 0x20);
	vfs_create("/dev", "display", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00200001);


	// direct keyboard device on major 0x21
	fxkeyboard_device.init();
	dev_register_device(&fxkeyboard_device, 0x21);
	vfs_create("/dev", "keyboard", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00210000);


	DBG_WAIT;

	//test_keymatrix();
//	test_keyboard();
	/*while(1) {
		char c;
		if(vfs_read(console, &c, 1) == 1) {
			vfs_write(console, &c, 1);
		}
	}*/

	DBG_WAIT;

	//test_vfs();

	//test_sdcard();

	//test_sleep_funcs();


	// EEPROM-related code commented to avoid useless write cycles ;)
	//test_eeprom();
	
	/*char mybuf[128];
	int len;

	len = usb_receive(USB_EP_ADDR_EP1OUT, mybuf, 10, 0);
	printk(LOG_DEBUG, "usb_receive ret=%d\n", len);
	if(len > 0) {
		mybuf[len] = '\0';
		printk(LOG_DEBUG, "content = '%s'\n", mybuf);
	}
	

	while(!_magic_lock);
	set_kernel_print(&print_usb_ep2);

	test_vfs();
*/

	// memory area subsystem
	mem_area_init();
	

	process_init();
	sched_init();
	test_process();
	

	printk(LOG_WARNING, "End of init job, sleeping...\n");
	while(1)
		printk(LOG_WARNING, "IER: 0x%x 0x%x\n", USB.IFR0.BYTE, USB.IFR1.BYTE);
}
Example #10
0
void main()
{
	log_init();
	fork_init();
	/* fork_init() will directly jump to restored thread context if we are a fork child */

	mm_init();
	install_syscall_handler();
	heap_init();
	signal_init();
	process_init();
	tls_init();
	vfs_init();
	dbt_init();

	/* Parse command line */
	const char *cmdline = GetCommandLineA();
	int len = strlen(cmdline);
	if (len > BLOCK_SIZE) /* TODO: Test if there is sufficient space for argv[] array */
	{
		kprintf("Command line too long.\n");
		process_exit(1, 0);
	}

	startup = mm_mmap(NULL, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS,
		INTERNAL_MAP_TOPDOWN | INTERNAL_MAP_NORESET, NULL, 0);
	*(uintptr_t*) startup = 1;
	char *current_startup_base = startup + sizeof(uintptr_t);
	memcpy(current_startup_base, cmdline, len + 1);
	char *envbuf = (char *)ALIGN_TO(current_startup_base + len + 1, sizeof(void*));
	char *env0 = envbuf;
	ENV("TERM=xterm");
	char *env1 = envbuf;
	ENV("HOME=/root");
	char *env2 = envbuf;
	ENV("DISPLAY=127.0.0.1:0");
	char *env3 = envbuf;
	ENV("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin");
	int argc = 0;
	char **argv = (char **)ALIGN_TO(envbuf, sizeof(void*));

	/* Parse command line */
	int in_quote = 0;
	char *j = current_startup_base;
	for (char *i = current_startup_base; i <= current_startup_base + len; i++)
		if (!in_quote && (*i == ' ' || *i == '\t' || *i == '\r' || *i == '\n' || *i == 0))
		{
			*i = 0;
			if (i > j)
				argv[argc++] = j;
			j = i + 1;
		}
		else if (*i == '"')
		{
			*i = 0;
			if (in_quote)
				argv[argc++] = j;
			in_quote = !in_quote;
			j = i + 1;
		}
	argv[argc] = NULL;
	char **envp = argv + argc + 1;
	int env_size = 4;
	envp[0] = env0;
	envp[1] = env1;
	envp[2] = env2;
	envp[3] = env3;
	envp[4] = NULL;
	char *buffer_base = (char*)(envp + env_size + 1);

	const char *filename = NULL;
	for (int i = 1; i < argc; i++)
	{
		if (argv[i][0] == '-')
		{
		}
		else if (!filename)
			filename = argv[i];
	}
	if (filename)
		do_execve(filename, argc - 1, argv + 1, env_size, envp, buffer_base, NULL);
	kprintf("Usage: flinux <executable> [arguments]\n");
	process_exit(1, 0);
}
Example #11
0
File: main.c Project: Jkirstejn/OSM
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 processing 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.");
}