blob: 6022f8db83407beab5accd6f874eee533d7f1d4b [file] [log] [blame]
swissChilid8137922021-02-17 15:34:07 -08001#pragma once
2
3#include "kint.h"
4
5struct gdt_entry
6{
7 ushort limit_low;
8 ushort base_low;
9 uchar base_middle;
10
swissChili825d46b2021-02-21 10:14:16 -080011 union {
swissChilid8137922021-02-17 15:34:07 -080012 struct
13 {
swissChili825d46b2021-02-21 10:14:16 -080014 uint a_p : 1;
15 uint a_dpl : 2;
16 uint a_dt : 1;
swissChilid8137922021-02-17 15:34:07 -080017 uint a_type : 4;
swissChili0b35bf22021-02-18 12:49:40 -080018 } __attribute__((packed));
swissChilid8137922021-02-17 15:34:07 -080019
20 uchar access;
21 };
22
swissChili825d46b2021-02-21 10:14:16 -080023 union {
swissChilid8137922021-02-17 15:34:07 -080024 struct
25 {
swissChili825d46b2021-02-21 10:14:16 -080026 uint g_g : 1;
27 uint g_d : 1;
swissChilid8137922021-02-17 15:34:07 -080028 uint g_zero : 2; /* includes A */
swissChili825d46b2021-02-21 10:14:16 -080029 uint g_len : 4;
swissChili0b35bf22021-02-18 12:49:40 -080030 } __attribute__((packed));
swissChili825d46b2021-02-21 10:14:16 -080031
swissChilid8137922021-02-17 15:34:07 -080032 uchar granularity;
33 };
34
35 uchar base_high;
36} __attribute__((packed));
37
swissChilid8137922021-02-17 15:34:07 -080038struct 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
46struct idt_entry
47{
48 ushort base_low;
49 ushort selector;
50 uchar zero;
51
swissChili825d46b2021-02-21 10:14:16 -080052 union {
swissChilid8137922021-02-17 15:34:07 -080053 struct
54 {
swissChili825d46b2021-02-21 10:14:16 -080055 uchar f_p : 1;
56 uchar f_dpl : 2;
swissChilid8137922021-02-17 15:34:07 -080057 uchar f_const : 5;
swissChili0b35bf22021-02-18 12:49:40 -080058 } __attribute__((packed));
swissChili825d46b2021-02-21 10:14:16 -080059
swissChilid8137922021-02-17 15:34:07 -080060 uchar flags;
61 };
swissChili825d46b2021-02-21 10:14:16 -080062
swissChilid8137922021-02-17 15:34:07 -080063 ushort base_high;
64} __attribute__((packed));
65
66#define IDT_F_CONST 0b00110
67
68struct idt_pointer
69{
70 ushort limit;
71 uint base;
72} __attribute__((packed));
73
swissChili1e8b7562021-12-22 21:22:57 -080074// We don't use hardware task switching, but we need a TSS entry
75// anyway.
76struct __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
swissChilid8137922021-02-17 15:34:07 -0800118extern void isr0();
119extern void isr1();
120extern void isr2();
121extern void isr3();
122extern void isr4();
123extern void isr5();
124extern void isr6();
125extern void isr7();
126extern void isr8();
127extern void isr9();
128extern void isr10();
129extern void isr11();
130extern void isr12();
131extern void isr13();
132extern void isr14();
133extern void isr15();
134extern void isr16();
135extern void isr17();
136extern void isr18();
137extern void isr19();
138extern void isr20();
139extern void isr21();
140extern void isr22();
141extern void isr23();
142extern void isr24();
143extern void isr25();
144extern void isr26();
145extern void isr27();
146extern void isr28();
147extern void isr29();
148extern void isr30();
149extern void isr31();
150
swissChiliee6d10d2021-05-29 18:05:16 -0700151// Syscall
152extern void isr128();
153// Tasking setup
154extern void isr129();
155
swissChili9b3584b2021-02-18 13:57:27 -0800156extern void irq0();
157extern void irq1();
158extern void irq2();
159extern void irq3();
160extern void irq4();
161extern void irq5();
162extern void irq6();
163extern void irq7();
164extern void irq8();
165extern void irq9();
166extern void irq10();
167extern void irq11();
168extern void irq12();
169extern void irq13();
170extern void irq14();
171extern void irq15();
172
swissChilid8137922021-02-17 15:34:07 -0800173void init_descriptor_tables();
174void init_idt();
175void init_gdt();
swissChili1e8b7562021-12-22 21:22:57 -0800176
177/// Set the stack to be used for Kernel-mode interrupt routines
178void set_kernel_interrupt_stack(void *stack);
179
180extern struct tss_entry tss_entry;