diff options
author | Marvin Borner | 2020-08-05 21:33:48 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-05 21:33:48 +0200 |
commit | 835960fd85989ee961b5a932f467e6e4f545d201 (patch) | |
tree | d93c67e51189eec12fb43ef860deba92e9017329 /src | |
parent | 4af62bb53676b7f721b46cabee78cac3a557e924 (diff) |
Added some cpu function wrappers
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/cpu.c | 21 | ||||
-rw-r--r-- | src/drivers/interrupts.c | 4 | ||||
-rw-r--r-- | src/features/proc.c | 5 | ||||
-rw-r--r-- | src/features/syscall.c | 1 | ||||
-rw-r--r-- | src/inc/cpu.h | 4 | ||||
-rw-r--r-- | src/main.c | 6 |
6 files changed, 33 insertions, 8 deletions
diff --git a/src/drivers/cpu.c b/src/drivers/cpu.c index ba8c66f..5c27c51 100644 --- a/src/drivers/cpu.c +++ b/src/drivers/cpu.c @@ -46,3 +46,24 @@ void outl(u16 port, u32 data) { __asm__ volatile("outl %0, %1" ::"a"(data), "Nd"(port)); } + +void cli() +{ + __asm__ volatile("cli"); +} + +void sti() +{ + __asm__ volatile("sti"); +} + +void hlt() +{ + __asm__ volatile("hlt"); +} + +void idle() +{ + while (1) + hlt(); +} diff --git a/src/drivers/interrupts.c b/src/drivers/interrupts.c index 9ad2529..0b94208 100644 --- a/src/drivers/interrupts.c +++ b/src/drivers/interrupts.c @@ -173,7 +173,7 @@ void isr_handler(struct regs *r) if (handler) { handler(r); } else if (r->int_no <= 32) { - __asm__("cli"); + cli(); printf("\n%s Exception, halting!\n", isr_exceptions[r->int_no]); printf("Error code: %d\n", r->err_code); while (1) { @@ -218,8 +218,6 @@ void isr_install() idt_set_gate(29, (u32)isr29, 0x08, 0x8E); idt_set_gate(30, (u32)isr30, 0x08, 0x8E); idt_set_gate(31, (u32)isr31, 0x08, 0x8E); - - idt_set_gate(0x80, (u32)isr128, 0x08, 0x8E); } /** diff --git a/src/features/proc.c b/src/features/proc.c index 7acbf03..d0fd66c 100644 --- a/src/features/proc.c +++ b/src/features/proc.c @@ -1,5 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include <cpu.h> #include <interrupts.h> #include <load.h> #include <mem.h> @@ -70,7 +71,7 @@ struct proc *proc_make() void proc_init() { - __asm__ volatile("cli"); + cli(); current = root = proc_make(); bin_load("/init", root); irq_install_handler(0, scheduler); @@ -81,6 +82,6 @@ void proc_init() *(void **)(&entry) = (u32 *)root->regs.eip; __asm__ volatile("movl %%eax, %%ebp" ::"a"(root->regs.ebp)); __asm__ volatile("movl %%eax, %%esp" ::"a"(root->regs.esp)); - __asm__ volatile("sti"); + sti(); entry(); } diff --git a/src/features/syscall.c b/src/features/syscall.c index c3a758a..50963b7 100644 --- a/src/features/syscall.c +++ b/src/features/syscall.c @@ -15,5 +15,6 @@ void syscall_handler(struct regs *r) void syscall_init() { + idt_set_gate(0x80, (u32)isr128, 0x08, 0x8E); isr_install_handler(0x80, syscall_handler); } diff --git a/src/inc/cpu.h b/src/inc/cpu.h index 092fd3f..eb09291 100644 --- a/src/inc/cpu.h +++ b/src/inc/cpu.h @@ -13,6 +13,10 @@ void insl(u16 port, void *addr, int n); void outb(u16 port, u8 data); void outw(u16 port, u16 data); void outl(u16 port, u32 data); +void cli(); +void sti(); +void hlt(); +void idle(); static inline void spinlock(int *ptr) { @@ -2,6 +2,7 @@ #include "config.h" #include <boot.h> +#include <cpu.h> #include <def.h> #include <fs.h> #include <gui.h> @@ -35,7 +36,7 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info) keyboard_install(); // Enable drivers - __asm__("sti"); + sti(); mem_info++; // TODO: Use the mmap (or remove)! @@ -47,6 +48,5 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info) syscall_init(); proc_init(); - while (1) { - }; + idle(); } |