예제 #1
0
void			bootloader_paging_init(void)
{
  t_uint32		limit;
  t_uint32		addr;
  t_uint16		i;
  t_ia32_page		pg;

  /*
   * 1)
   */

  if (pd_build(bootloader_init_alloc(PD_MAX_ENTRIES * sizeof(t_ia32_pde),
				     NULL), &pd, 1) != ERROR_NONE)
    {
      printf("cannot build a page-directory\n");
      bootloader_error();
    }

  /*
   * 2)
   */

  init->machdep.pd = pd;

  /*
   * 3)
   */

  if (pt_build(bootloader_init_alloc(PT_MAX_ENTRIES * sizeof(t_ia32_pte),
				     NULL), &pt0, 1) != ERROR_NONE)
    {
      printf("cannot build a page-table\n");
      bootloader_error();
    }

  pt0.present = 1;
  pt0.rw = PT_WRITABLE;
  pt0.user = PT_PRIVILEGED;
  pt0.cached = PT_CACHED;
  pt0.writeback = PT_WRITEBACK;

  pd_add_table(&pd, 0, pt0);

  pg.present = 1;
  pg.rw = PG_WRITABLE;
  pg.user = PG_PRIVILEGED;
  pg.cached = PG_CACHED;
  pg.writeback = PG_WRITEBACK;

  for (i = 0, addr = PAGESZ;  i < PT_MAX_ENTRIES - 1; i++, addr += PAGESZ)
    {
      pg.addr = addr;
      pt_add_page(&pt0, PTE_ENTRY(addr), pg);
    }

  /*
   * 4)
   */

  limit = bootloader_init_alloc(0, NULL);

  for (addr = init->kcode; addr < limit; addr += PAGESZ)
    {
      if (pd_get_table(&pd, PDE_ENTRY(addr), &pt) != ERROR_NONE)
	{
	  if (pt_build(bootloader_init_alloc(PT_MAX_ENTRIES *
					     sizeof(t_ia32_pte),
					     NULL), &pt, 1) != ERROR_NONE)
	    {
	      printf("cannot build a page-table\n");
	      bootloader_error();
	    }

	  pt.present = 1;
	  pt.rw = PT_WRITABLE;
	  pt.user = PT_PRIVILEGED;
	  pt.cached = PT_CACHED;
	  pt.writeback = PT_WRITEBACK;

	  pd_add_table(&pd, PDE_ENTRY(addr), pt);
	  limit += PAGESZ;
	}
      pg.addr = addr;
      pt_add_page(&pt, PTE_ENTRY(addr), pg);
    }

  /*
   * 5)
   */

  pd_activate(pd, PD_CACHED, PD_WRITEBACK);

  /*
   * 6)
   */

  paging_enable();
}
예제 #2
0
파일: interrupt.c 프로젝트: fenollp/kaneton
void			bootloader_interrupt_init(void)
{
  t_ia32_idt		idt;
  t_ia32_gate		gate;
  int			i;

  /*
   * 1)
   */

  if (idt_build(256,
		bootloader_init_alloc(256 *
				      sizeof(t_ia32_idte), NULL),
		1, &idt) != STATUS_OK)
    {
      bootloader_cons_msg('!', "interrupt: error creating idt.\n");
      bootloader_error();
    }

  /*
   * 2)
   */

  if (idt_activate(&idt) != STATUS_OK)
    {
      bootloader_cons_msg('!', "interrupt: error activating idt.\n");
      bootloader_error();
    }

  /*
   * 3)
   */

  for (i = 0; i < 256; i++)
    {
      gate.offset = (t_uint32)bootloader_interrupt_dummy;
      gate.segsel = IA32_PMODE_BOOTLOADER_CS << 3;
      gate.privilege = 0;
      gate.type = ia32_type_gate_interrupt;

      if (idt_add_gate(NULL, i, gate) != STATUS_OK)
	{
	  bootloader_cons_msg('!', "interrupt: error adding gate.\n");
	  bootloader_error();
	}
    }

  /*
   * 4)
   */

  if (pic_init() != STATUS_OK)
    {
      bootloader_cons_msg('!', "interrupt: error activating PIC.\n");
      bootloader_error();
    }

  asm volatile("sti");

  memcpy(&init->machine.idt, &idt, sizeof (t_ia32_idt));
}