Kaynağa Gözat

add c defs of hlt cli sti

greatbridf 4 yıl önce
ebeveyn
işleme
e2cabea44b
3 değiştirilmiş dosya ile 33 ekleme ve 3 silme
  1. 11 0
      include/asm/port_io.h
  2. 18 0
      src/asm/port_io.s
  3. 4 3
      src/kernel_main.c

+ 11 - 0
include/asm/port_io.h

@@ -2,7 +2,18 @@
 
 #include <types/types.h>
 
+#define PORT_PIC1 (0x20)
+#define PORT_PIC2 (0xa0)
+#define PORT_PIC1_COMMAND (PORT_PIC1)
+#define PORT_PIC1_DATA ((PORT_PIC1) + 1)
+#define PORT_PIC2_COMMAND (PORT_PIC2)
+#define PORT_PIC2_DATA ((PORT_PIC2) + 1)
+
 #define PORT_KEYDATA 0x0060u
 
 extern void asm_outb(uint16_t port_number, uint8_t data);
 extern uint8_t asm_inb(uint16_t port_number);
+
+extern void asm_hlt(void);
+extern void asm_cli(void);
+extern void asm_sti(void);

+ 18 - 0
src/asm/port_io.s

@@ -22,3 +22,21 @@ asm_inb:
     inb %dx, %al
     popl %edx
     ret
+
+.globl asm_hlt
+.type  asm_hlt @function
+asm_hlt:
+    hlt
+    ret
+
+.globl asm_cli
+.type  asm_cli @function
+asm_cli:
+    cli
+    ret
+
+.globl asm_sti
+.type  asm_sti @function
+asm_sti:
+    sti
+    ret

+ 4 - 3
src/kernel_main.c

@@ -1,6 +1,7 @@
 #include <kernel_main.h>
 
 #include <asm/boot.h>
+#include <asm/port_io.h>
 #include <kernel/interrupt.h>
 #include <kernel/mem.h>
 #include <kernel/stdio.h>
@@ -36,7 +37,7 @@ void kernel_main(void)
 
     vga_printk("No work to do, halting...\n", 0x0fU);
 
-_loop:
-    asm("hlt");
-    goto _loop;
+    while (1) {
+        asm_hlt();
+    }
 }