Esempio n. 1
0
static void module_load(multiboot_tag_t *tag)
{
  /* calculate size and phy32 pointer */
  size_t size = tag->module.mod_end - tag->module.mod_start;
  elf64_ehdr_t *elf = (elf64_ehdr_t *) aphy32_to_virt(tag->module.mod_start);

  /* make a new process */
  proc_t *proc = proc_create();
  if (!proc)
    panic("couldn't create process for module");

  /* switch our address space */
  proc_switch(proc);

  /* load the ELF file */
  if (!elf64_load(elf, size))
    panic("couldn't load elf64 file");

  /* make a new thread */
  thread_t *thread = thread_create(proc, 0);
  if (!thread)
    panic("couldn't create thread for module");

  /* set entry point of the thread */
  thread->rip = elf->e_entry;

  /* add thread to the scheduler's ready queue */
  thread_resume(thread);
}
Esempio n. 2
0
File: main.c Progetto: 8l/Hydrogen
void main_bsp(void)
{
    // Print header
    screen_write("Hydrogen v0.2b - http://github.com/farok/H2", 0, 0);
    screen_write("Copyright (c) 2012 by Lukas Heidemann", 0, 1);
    screen_write("-------------------------------------------------", 0, 2);

    // Load the IDT
    idt_load(idt_address, IDT_LENGTH);
    idt_setup_loader();

    // Initialize Hydrogen info tables and parse the multiboot tables
    info_init();
    multiboot_parse();

    // Setup the heap
    heap_init();

    // Now parse the ACPI tables and analyze the IO APICs
    acpi_parse();
    ioapic_analyze();

    // Find, check and load the kernel binary
    kernel_find();
    kernel_check();
    elf64_load(kernel_binary);
    kernel_analyze();

    // Initialize interrupt controllers
    lapic_detect();
    lapic_setup();
    ioapic_setup_loader();
    pic_setup();

    // Calibrate the LAPIC timer
    lapic_timer_calibrate();

    // Boot APs
    info_cpu[lapic_id()].flags |= HY_INFO_CPU_FLAG_BSP;
    smp_setup();

    // Setup IDT and IOAPIC according to kernel header
    idt_setup_kernel();
    ioapic_setup_kernel();

    // Setup fast syscall support
    syscall_init();

    // Setup mapping
    kernel_map_info();
    kernel_map_stack();
    kernel_map_idt();
    kernel_map_gdt();

    // Set free address
    info_root->free_paddr = (heap_top + 0xFFF) & ~0xFFF;

    // Lower main entry barrier and jump to the kernel entry point
    main_entry_barrier = 0;
    kernel_enter_bsp();
}