-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.c
53 lines (45 loc) · 1.31 KB
/
kernel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include"screen.h"
#include "ps2.h"
#include "tables.h"
#include "interrupt.h"
#include "interrupt_handlers.h"
/* This is a dummy function that sits around for the TSS to hop to if that ever happens.
* It probably shouldn't happen, but if it does at least you'll know what's up.
*/
void new_main(void) {
terminal_writestring("\nYou probably shouldn't have gotten here\n");
}
/* Kernel execution starts here! */
void kernel_main(void) {
/* Set up various tables so interrupts will work */
create_tss((uintptr_t) &new_main);
create_gdt();
/* Set up the PIC:
* IRQs from the master chip show up as interrupts 0x20-0x27;
* IRQs from the slave chip show up as interrupts 0x28-0x2F.
*/
PIC_remap(0x20,0x28);
/* Disable IRQs for all PIC devices
* (so we don't try to jump to 0x0 when an IRQ
* we don't want to handle fires)
*/
IRQ_mask_all();
/* Add an interrupt for the PS/2 keyboard (on PIC IRQ 0x1)
* and enable that IRQ
*/
add_idt_entry(0x21, (uintptr_t) &keypress);
IRQ_clear_mask(0x1);
/* Interrupt 0x42 prints 'hi'! */
add_idt_entry(0x42, (uintptr_t) &hi);
/* Enable interrupts */
enable_interrupts();
/* Initialize terminal interface */
terminal_initialize();
/* Hang forever */
for(;;) {
asm("hlt");
}
}