Fork me on GitHub

root/kernel/idt.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. set_idt_entry
  2. idt_init

   1 /*
   2  * fiwix/kernel/idt.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/asm.h>
   9 #include <fiwix/const.h>
  10 #include <fiwix/types.h>
  11 #include <fiwix/segments.h>
  12 #include <fiwix/string.h>
  13 
  14 struct gate_desc idt[NR_IDT_ENTRIES];
  15 
  16 struct desc_r idtr = {
  17         sizeof(idt) - 1,
  18         (unsigned int)idt
  19 };
  20 
  21 static void set_idt_entry(int num, __off_t handler, unsigned int flags)
  22 {
  23         idt[num].gd_looffset = handler & 0x0000FFFF;
  24         idt[num].gd_selector = KERNEL_CS;
  25         idt[num].gd_flags = flags << 8;
  26         idt[num].gd_hioffset = handler >> 16;
  27 }
  28 
  29 void idt_init(void)
  30 {
  31         int n;
  32 
  33         memset_b(idt, NULL, sizeof(idt));
  34         for(n = 0; n < NR_IDT_ENTRIES; n++) {
  35                 set_idt_entry(n, (__off_t)&unknown_irq, SD_32INTRGATE | SD_PRESENT);
  36         }
  37 
  38         /* FIXME: must be SD_32TRAPGATE for true multitasking */
  39         set_idt_entry(0x00, (__off_t)&except0, SD_32INTRGATE | SD_PRESENT);
  40         set_idt_entry(0x01, (__off_t)&except1, SD_32INTRGATE | SD_PRESENT);
  41         set_idt_entry(0x02, (__off_t)&except2, SD_32INTRGATE | SD_PRESENT);
  42         set_idt_entry(0x03, (__off_t)&except3, SD_32INTRGATE | SD_PRESENT);
  43         set_idt_entry(0x04, (__off_t)&except4, SD_32INTRGATE | SD_PRESENT);
  44         set_idt_entry(0x05, (__off_t)&except5, SD_32INTRGATE | SD_PRESENT);
  45         set_idt_entry(0x06, (__off_t)&except6, SD_32INTRGATE | SD_PRESENT);
  46         set_idt_entry(0x07, (__off_t)&except7, SD_32INTRGATE | SD_PRESENT);
  47         set_idt_entry(0x08, (__off_t)&except8, SD_32INTRGATE | SD_PRESENT);
  48         set_idt_entry(0x09, (__off_t)&except9, SD_32INTRGATE | SD_PRESENT);
  49         set_idt_entry(0x0A, (__off_t)&exceptA, SD_32INTRGATE | SD_PRESENT);
  50         set_idt_entry(0x0B, (__off_t)&exceptB, SD_32INTRGATE | SD_PRESENT);
  51         set_idt_entry(0x0C, (__off_t)&exceptC, SD_32INTRGATE | SD_PRESENT);
  52         set_idt_entry(0x0D, (__off_t)&exceptD, SD_32INTRGATE | SD_PRESENT);
  53         set_idt_entry(0x0E, (__off_t)&exceptE, SD_32INTRGATE | SD_PRESENT);
  54         set_idt_entry(0x0F, (__off_t)&exceptF, SD_32INTRGATE | SD_PRESENT);
  55         set_idt_entry(0x10, (__off_t)&except10, SD_32INTRGATE | SD_PRESENT);
  56         set_idt_entry(0x11, (__off_t)&except11, SD_32INTRGATE | SD_PRESENT);
  57         set_idt_entry(0x12, (__off_t)&except12, SD_32INTRGATE | SD_PRESENT);
  58         set_idt_entry(0x13, (__off_t)&except13, SD_32INTRGATE | SD_PRESENT);
  59         set_idt_entry(0x14, (__off_t)&except14, SD_32INTRGATE | SD_PRESENT);
  60         set_idt_entry(0x15, (__off_t)&except15, SD_32INTRGATE | SD_PRESENT);
  61         set_idt_entry(0x16, (__off_t)&except16, SD_32INTRGATE | SD_PRESENT);
  62         set_idt_entry(0x17, (__off_t)&except17, SD_32INTRGATE | SD_PRESENT);
  63         set_idt_entry(0x18, (__off_t)&except18, SD_32INTRGATE | SD_PRESENT);
  64         set_idt_entry(0x19, (__off_t)&except19, SD_32INTRGATE | SD_PRESENT);
  65         set_idt_entry(0x1A, (__off_t)&except1A, SD_32INTRGATE | SD_PRESENT);
  66         set_idt_entry(0x1B, (__off_t)&except1B, SD_32INTRGATE | SD_PRESENT);
  67         set_idt_entry(0x1C, (__off_t)&except1C, SD_32INTRGATE | SD_PRESENT);
  68         set_idt_entry(0x1D, (__off_t)&except1D, SD_32INTRGATE | SD_PRESENT);
  69         set_idt_entry(0x1E, (__off_t)&except1E, SD_32INTRGATE | SD_PRESENT);
  70         set_idt_entry(0x1F, (__off_t)&except1F, SD_32INTRGATE | SD_PRESENT);
  71 
  72         set_idt_entry(0x20, (__off_t)&irq0, SD_32INTRGATE | SD_PRESENT);
  73         set_idt_entry(0x21, (__off_t)&irq1, SD_32INTRGATE | SD_PRESENT);
  74         set_idt_entry(0x22, (__off_t)&irq2, SD_32INTRGATE | SD_PRESENT);
  75         set_idt_entry(0x23, (__off_t)&irq3, SD_32INTRGATE | SD_PRESENT);
  76         set_idt_entry(0x24, (__off_t)&irq4, SD_32INTRGATE | SD_PRESENT);
  77         set_idt_entry(0x25, (__off_t)&irq5, SD_32INTRGATE | SD_PRESENT);
  78         set_idt_entry(0x26, (__off_t)&irq6, SD_32INTRGATE | SD_PRESENT);
  79         set_idt_entry(0x27, (__off_t)&irq7, SD_32INTRGATE | SD_PRESENT);
  80         set_idt_entry(0x28, (__off_t)&irq8, SD_32INTRGATE | SD_PRESENT);
  81         set_idt_entry(0x29, (__off_t)&irq9, SD_32INTRGATE | SD_PRESENT);
  82         set_idt_entry(0x2A, (__off_t)&irq10, SD_32INTRGATE | SD_PRESENT);
  83         set_idt_entry(0x2B, (__off_t)&irq11, SD_32INTRGATE | SD_PRESENT);
  84         set_idt_entry(0x2C, (__off_t)&irq12, SD_32INTRGATE | SD_PRESENT);
  85         set_idt_entry(0x2D, (__off_t)&irq13, SD_32INTRGATE | SD_PRESENT);
  86         set_idt_entry(0x2E, (__off_t)&irq14, SD_32INTRGATE | SD_PRESENT);
  87         set_idt_entry(0x2F, (__off_t)&irq15, SD_32INTRGATE | SD_PRESENT);
  88 
  89         /* FIXME: must be SD_32TRAPGATE for true multitasking */
  90         set_idt_entry(0x80, (__off_t)&syscall, SD_32INTRGATE | SD_DPL3 | SD_PRESENT);
  91 
  92         load_idt((unsigned int)&idtr);
  93 }

/* [previous][next][first][last][top][bottom][index][help] */