Example #1
0
File: init.c Project: Quest-V/quest
/* Create an address space for boot modules */
static uint16
load_module (multiboot_module * pmm, int mod_num)
{

  uint32 *plPageDirectory = get_phys_addr (pg_dir[mod_num]);
  uint32 *plPageTable = get_phys_addr (pg_table[mod_num]);
  void *pStack = get_phys_addr (ul_stack[mod_num]);
  /* temporarily map pmm->pe in order to read pph->p_memsz */
  Elf32_Ehdr *pe, *pe0 = map_virtual_page ((uint) pmm->pe | 3);
  Elf32_Phdr *pph = (void *) pe0 + pe0->e_phoff;
  void *pEntry = (void *) pe0->e_entry;
  int i, c, j;
  uint32 *stack_virt_addr;
  uint32 page_count = 1;

  /* find out how many pages for the module */
  for (i = 0; i < pe0->e_phnum; i++) {
    if (pph->p_type == PT_LOAD)
      page_count += (pph->p_memsz >> 12);
    pph = (void *) pph + pe0->e_phentsize;
  }

  /* now map the entire module */
  pe = map_contiguous_virtual_pages ((uint) pmm->pe | 3, page_count);

  unmap_virtual_page (pe0);

  pph = (void *) pe + pe->e_phoff;

  /* Populate ring 3 page directory with kernel mappings */
  memcpy (&plPageDirectory[1023], (void *) (((uint32) get_pdbr ()) + 4092),
          4);
  /* LAPIC/IOAPIC mappings */
  memcpy (&plPageDirectory[1019], (void *) (((uint32) get_pdbr ()) + 4076),
          4);

  /* Populate ring 3 page directory with entries for its private address
     space */
  plPageDirectory[0] = (uint32) plPageTable | 7;

  plPageDirectory[1022] = (uint32) get_phys_addr (kls_pg_table[mod_num]) | 3;
  kls_pg_table[mod_num][0] = (uint32) get_phys_addr (kl_stack[mod_num]) | 3;

  /* Walk ELF header */
  for (i = 0; i < pe->e_phnum; i++) {

    if (pph->p_type == PT_LOAD) {
      /* map pages loaded from file */
      c = (pph->p_filesz + 0xFFF) >> 12;        /* #pages to load for module */

      for (j = 0; j < c; j++)
        plPageTable[((uint32) pph->p_vaddr >> 12) + j] =
          (uint32) pmm->pe + (pph->p_offset & 0xFFFFF000) + (j << 12) + 7;

      /* zero remainder of final page */
      memset ((void *) pe + pph->p_offset + pph->p_filesz,
              0, (pph->p_memsz - pph->p_filesz) & 0x0FFF);

      /* map additional zeroed pages */
      c = (pph->p_memsz + 0xFFF) >> 12;

      /* Allocate space for bss section.  Use temporary virtual memory for
       * memset call to clear physical frame(s)
       */
      for (; j <= c; j++) {
        uint32 page_frame = (uint32) alloc_phys_frame ();
        void *virt_addr = map_virtual_page (page_frame | 3);
        memset (virt_addr, 0, 0x1000);
        plPageTable[((uint32) pph->p_vaddr >> 12) + j] = page_frame + 7;
        unmap_virtual_page (virt_addr);
      }
    }

    pph = (void *) pph + pe->e_phentsize;
  }
Example #2
0
int
sfi_early_init(sfi_info_t *sfi_info)
{
  int i;
  size_t syst_num;
  phys_addr_t low_frame;
  phys_addr_t high_frame;
  phys_addr_t syst_phys;

  memset(sfi_info, 0, sizeof(*sfi_info));

  syst_phys = sfi_syst_phys();
  if(syst_phys == -1) {
    return 0;
  }

  low_frame = high_frame = syst_phys;

  sfi_info->system_table = (sfi_system_table_t*)
    (((char*)map_virtual_page((syst_phys & 0xFFFFF000) | 3))
    + (syst_phys & 0xFFF));

  syst_num = SFI_NUM_SYST_ENTRIES(sfi_info->system_table);

  for(i = 0; i < syst_num; i++) {
    if(sfi_info->system_table->entries[i] > 0xFFFFFFFF) {
      panic("SFI table above 4G region");
    }
    if(sfi_info->system_table->entries[i] < low_frame) {
      low_frame = sfi_info->system_table->entries[i];
    }
    if(sfi_info->system_table->entries[i] > high_frame) {
      high_frame = sfi_info->system_table->entries[i];
    }
  }

  sfi_info->low_frame = low_frame = low_frame & 0xFFFFF000;
  high_frame &= 0xFFFFF000;

  unmap_virtual_page(sfi_info->system_table);

  sfi_info->num_frames = ((high_frame - low_frame) / 0x1000) + 1;
  sfi_info->start_addr =
    map_contiguous_virtual_pages(low_frame | 3,
                                 sfi_info->num_frames);

  if(sfi_info->start_addr == NULL) {
    panic("Failed to map STI");
  }

  sfi_info->system_table = (sfi_system_table_t*)
    SFI_PHYS_TO_VIRT(sfi_info, syst_phys);

  print_syst_table(sfi_info);

  sfi_info->cpus_table = get_sfi_table(sfi_info, SFI_SIG_CPUS);
  print_cpus_table(sfi_info);

  sfi_info->apic_table = get_sfi_table(sfi_info, SFI_SIG_APIC);
  print_apic_table(sfi_info);

  sfi_info->mmap_table = get_sfi_table(sfi_info, SFI_SIG_MMAP);
  print_mmap_table(sfi_info);

  sfi_info->freq_table = get_sfi_table(sfi_info, SFI_SIG_FREQ);
  print_freq_table(sfi_info);

  sfi_info->mtmr_table = get_sfi_table(sfi_info, SFI_SIG_MTMR);
  print_mtmr_table(sfi_info);

  sfi_info->mrtc_table = get_sfi_table(sfi_info, SFI_SIG_MRTC);
  print_mrtc_table(sfi_info);

  sfi_info->wake_table = get_sfi_table(sfi_info, SFI_SIG_WAKE);
  print_wake_table(sfi_info);

  sfi_info->devs_table = get_sfi_table(sfi_info, SFI_SIG_DEVS);
  print_devs_table(sfi_info);

  sfi_info->gpio_table = get_sfi_table(sfi_info, SFI_SIG_GPIO);
  print_gpio_table(sfi_info);

  sfi_info->xsdt_table = get_sfi_table(sfi_info, SFI_SIG_XSDT);
  print_xsdt_table(sfi_info);

  return 0;
}