swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "kint.h" |
| 4 | |
| 5 | struct gdt_entry |
| 6 | { |
| 7 | ushort limit_low; |
| 8 | ushort base_low; |
| 9 | uchar base_middle; |
| 10 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 11 | union { |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 12 | struct |
| 13 | { |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 14 | uint a_p : 1; |
| 15 | uint a_dpl : 2; |
| 16 | uint a_dt : 1; |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 17 | uint a_type : 4; |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 18 | } __attribute__((packed)); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 19 | |
| 20 | uchar access; |
| 21 | }; |
| 22 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 23 | union { |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 24 | struct |
| 25 | { |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 26 | uint g_g : 1; |
| 27 | uint g_d : 1; |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 28 | uint g_zero : 2; /* includes A */ |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 29 | uint g_len : 4; |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 30 | } __attribute__((packed)); |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 31 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 32 | uchar granularity; |
| 33 | }; |
| 34 | |
| 35 | uchar base_high; |
| 36 | } __attribute__((packed)); |
| 37 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 38 | struct gdt_pointer |
| 39 | { |
| 40 | /* Upper 16 bits of selector limits */ |
| 41 | ushort limit; |
| 42 | /* first struct gdt_entry */ |
| 43 | uint base; |
| 44 | } __attribute__((packed)); |
| 45 | |
| 46 | struct idt_entry |
| 47 | { |
| 48 | ushort base_low; |
| 49 | ushort selector; |
| 50 | uchar zero; |
| 51 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 52 | union { |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 53 | struct |
| 54 | { |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 55 | uchar f_p : 1; |
| 56 | uchar f_dpl : 2; |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 57 | uchar f_const : 5; |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 58 | } __attribute__((packed)); |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 59 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 60 | uchar flags; |
| 61 | }; |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 62 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 63 | ushort base_high; |
| 64 | } __attribute__((packed)); |
| 65 | |
| 66 | #define IDT_F_CONST 0b00110 |
| 67 | |
| 68 | struct idt_pointer |
| 69 | { |
| 70 | ushort limit; |
| 71 | uint base; |
| 72 | } __attribute__((packed)); |
| 73 | |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 74 | // We don't use hardware task switching, but we need a TSS entry |
| 75 | // anyway. |
| 76 | struct __attribute__((packed)) tss_entry |
| 77 | { |
| 78 | // Previous TSS. Unused. |
| 79 | uint prev_tss; |
| 80 | // Kernel stack pointer. |
| 81 | uint esp0; |
| 82 | // Kernel stack segment. |
| 83 | uint ss0; |
| 84 | // Unused |
| 85 | uint esp1; |
| 86 | uint ss1; |
| 87 | uint esp2; |
| 88 | uint ss2; |
| 89 | uint cr3; |
| 90 | uint eip; |
| 91 | uint eflags; |
| 92 | uint eax; |
| 93 | uint ecx; |
| 94 | uint edx; |
| 95 | uint ebx; |
| 96 | uint esp; |
| 97 | uint ebp; |
| 98 | uint esi; |
| 99 | uint edi; |
| 100 | // The value to load into ES when we change to kernel mode. |
| 101 | uint es; |
| 102 | // The value to load into CS when we change to kernel mode. |
| 103 | uint cs; |
| 104 | // The value to load into SS when we change to kernel mode. |
| 105 | uint ss; |
| 106 | // The value to load into DS when we change to kernel mode. |
| 107 | uint ds; |
| 108 | // The value to load into FS when we change to kernel mode. |
| 109 | uint fs; |
| 110 | // The value to load into GS when we change to kernel mode. |
| 111 | uint gs; |
| 112 | // Unused... |
| 113 | uint ldt; |
| 114 | ushort trap; |
| 115 | ushort iomap_base; |
| 116 | }; |
| 117 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 118 | extern void isr0(); |
| 119 | extern void isr1(); |
| 120 | extern void isr2(); |
| 121 | extern void isr3(); |
| 122 | extern void isr4(); |
| 123 | extern void isr5(); |
| 124 | extern void isr6(); |
| 125 | extern void isr7(); |
| 126 | extern void isr8(); |
| 127 | extern void isr9(); |
| 128 | extern void isr10(); |
| 129 | extern void isr11(); |
| 130 | extern void isr12(); |
| 131 | extern void isr13(); |
| 132 | extern void isr14(); |
| 133 | extern void isr15(); |
| 134 | extern void isr16(); |
| 135 | extern void isr17(); |
| 136 | extern void isr18(); |
| 137 | extern void isr19(); |
| 138 | extern void isr20(); |
| 139 | extern void isr21(); |
| 140 | extern void isr22(); |
| 141 | extern void isr23(); |
| 142 | extern void isr24(); |
| 143 | extern void isr25(); |
| 144 | extern void isr26(); |
| 145 | extern void isr27(); |
| 146 | extern void isr28(); |
| 147 | extern void isr29(); |
| 148 | extern void isr30(); |
| 149 | extern void isr31(); |
| 150 | |
swissChili | ee6d10d | 2021-05-29 18:05:16 -0700 | [diff] [blame] | 151 | // Syscall |
| 152 | extern void isr128(); |
| 153 | // Tasking setup |
| 154 | extern void isr129(); |
| 155 | |
swissChili | 9b3584b | 2021-02-18 13:57:27 -0800 | [diff] [blame] | 156 | extern void irq0(); |
| 157 | extern void irq1(); |
| 158 | extern void irq2(); |
| 159 | extern void irq3(); |
| 160 | extern void irq4(); |
| 161 | extern void irq5(); |
| 162 | extern void irq6(); |
| 163 | extern void irq7(); |
| 164 | extern void irq8(); |
| 165 | extern void irq9(); |
| 166 | extern void irq10(); |
| 167 | extern void irq11(); |
| 168 | extern void irq12(); |
| 169 | extern void irq13(); |
| 170 | extern void irq14(); |
| 171 | extern void irq15(); |
| 172 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 173 | void init_descriptor_tables(); |
| 174 | void init_idt(); |
| 175 | void init_gdt(); |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 176 | |
| 177 | /// Set the stack to be used for Kernel-mode interrupt routines |
| 178 | void set_kernel_interrupt_stack(void *stack); |
| 179 | |
| 180 | extern struct tss_entry tss_entry; |