diff options
author | Anton Kling <anton@kling.gg> | 2024-02-14 17:40:06 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-14 17:40:06 +0100 |
commit | 3922adcdec5bd003b4106ffce79c28553bc40c15 (patch) | |
tree | f1af360cd7ad75d4b5f19bf066bf7e29ce8e3e53 /kernel | |
parent | a8ffc46136eb16adc87fb520c724467d1295a854 (diff) |
Kernel: Update signal handling and IPC
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cpu/idt.c | 39 | ||||
-rw-r--r-- | kernel/cpu/isr.s | 297 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c | 1 | ||||
-rw-r--r-- | kernel/drivers/rtl8139.c | 6 | ||||
-rw-r--r-- | kernel/ipc.c | 5 | ||||
-rw-r--r-- | kernel/ipc.h | 4 | ||||
-rw-r--r-- | kernel/process.s | 2 | ||||
-rw-r--r-- | kernel/sched/scheduler.c | 60 | ||||
-rw-r--r-- | kernel/sched/scheduler.h | 17 | ||||
-rw-r--r-- | kernel/syscalls/install_irq.c | 26 | ||||
-rw-r--r-- | kernel/syscalls/map_frames.c | 6 | ||||
-rw-r--r-- | kernel/syscalls/port.c | 14 | ||||
-rw-r--r-- | kernel/syscalls/virtual_to_physical.c | 6 |
14 files changed, 470 insertions, 15 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index c9fffe6..ea8781c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,6 @@ CC="i686-sb-gcc" AS="i686-sb-as" -OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o switch_task.o arch/i386/interrupts.o cpu/isr.o +OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL #LDFLAGS=-flto -Ofast LDFLAGS= diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 823cc2a..30b6253 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -76,10 +76,9 @@ void page_fault(reg_t *regs) { volatile uint32_t cr2; asm volatile("mov %%cr2, %0" : "=r"(cr2)); kprintf("CR2: %x\n", cr2); - if (0xFFFFDEAD == cr2) { - for (;;) { - switch_task(0); - } + if (0xDEADC0DE == cr2) { + EOI(0xB); + process_pop_restore_context(NULL, regs); return; } klog("Page Fault", LOG_ERROR); @@ -219,16 +218,42 @@ void *isr_list[] = { isr252, isr253, isr254, isr255, }; -void (*list_of_handlers[256])(reg_t *); +typedef int (*interrupt_handler)(reg_t *); + +interrupt_handler list_of_handlers[256]; void int_handler(reg_t *r) { - list_of_handlers[r->int_no](r); + interrupt_handler handler = list_of_handlers[r->int_no]; + if (NULL == handler) { + kprintf("[NOTE] Interrupt(0x%x) called but has no interrupt handler", + r->int_no); + return; + } + + handler(r); + + int is_kernel = (r->cs == 0x08); + if (!is_kernel) { + const signal_t *sig = process_pop_signal(NULL); + if (sig) { + process_push_restore_context(NULL, *r); + r->eip = sig->handler_ip; + kprintf("jumping to: %x\n", r->eip); + // kprintf("esp: %x\n", r->esp); + // kprintf("ebp: %x\n", r->ebp); + + // Add magic value to the stack such that the signal handler + // returns to 0xDEADC0DE + r->useresp -= 4; + *(u32 *)r->useresp = 0xDEADC0DE; + } + } } void install_handler(void (*handler_function)(), u16 type_attribute, u8 entry) { format_descriptor((u32)isr_list[entry], KERNEL_CODE_SEGMENT_OFFSET, type_attribute, &IDT_Entry[entry]); - list_of_handlers[entry] = handler_function; + list_of_handlers[entry] = (interrupt_handler)handler_function; } void idt_init(void) { diff --git a/kernel/cpu/isr.s b/kernel/cpu/isr.s new file mode 100644 index 0000000..1bb2fff --- /dev/null +++ b/kernel/cpu/isr.s @@ -0,0 +1,297 @@ +.intel_syntax noprefix +.section .text +# Due to x86 not giving the interrupt number these isr stubs are +# created. This is to allow a general isr stub for all interrupts. This +# stub will act as a # multiplexer to the correct interrupt. +.macro ISR_NOERRCODE num + .global isr\num + isr\num: + cli + push 0 + push \num + jmp isr_common_stub +.endm + +ISR_NOERRCODE 0 +ISR_NOERRCODE 1 +ISR_NOERRCODE 2 +ISR_NOERRCODE 3 +ISR_NOERRCODE 4 +ISR_NOERRCODE 5 +ISR_NOERRCODE 6 +ISR_NOERRCODE 7 +ISR_NOERRCODE 8 +ISR_NOERRCODE 9 +ISR_NOERRCODE 10 +ISR_NOERRCODE 11 +ISR_NOERRCODE 12 +ISR_NOERRCODE 13 +ISR_NOERRCODE 14 +ISR_NOERRCODE 15 +ISR_NOERRCODE 16 +ISR_NOERRCODE 17 +ISR_NOERRCODE 18 +ISR_NOERRCODE 19 +ISR_NOERRCODE 20 +ISR_NOERRCODE 21 +ISR_NOERRCODE 22 +ISR_NOERRCODE 23 +ISR_NOERRCODE 24 +ISR_NOERRCODE 25 +ISR_NOERRCODE 26 +ISR_NOERRCODE 27 +ISR_NOERRCODE 28 +ISR_NOERRCODE 29 +ISR_NOERRCODE 30 +ISR_NOERRCODE 31 +ISR_NOERRCODE 32 +ISR_NOERRCODE 33 +ISR_NOERRCODE 34 +ISR_NOERRCODE 35 +ISR_NOERRCODE 36 +ISR_NOERRCODE 37 +ISR_NOERRCODE 38 +ISR_NOERRCODE 39 +ISR_NOERRCODE 40 +ISR_NOERRCODE 41 +ISR_NOERRCODE 42 +ISR_NOERRCODE 43 +ISR_NOERRCODE 44 +ISR_NOERRCODE 45 +ISR_NOERRCODE 46 +ISR_NOERRCODE 47 +ISR_NOERRCODE 48 +ISR_NOERRCODE 49 +ISR_NOERRCODE 50 +ISR_NOERRCODE 51 +ISR_NOERRCODE 52 +ISR_NOERRCODE 53 +ISR_NOERRCODE 54 +ISR_NOERRCODE 55 +ISR_NOERRCODE 56 +ISR_NOERRCODE 57 +ISR_NOERRCODE 58 +ISR_NOERRCODE 59 +ISR_NOERRCODE 60 +ISR_NOERRCODE 61 +ISR_NOERRCODE 62 +ISR_NOERRCODE 63 +ISR_NOERRCODE 64 +ISR_NOERRCODE 65 +ISR_NOERRCODE 66 +ISR_NOERRCODE 67 +ISR_NOERRCODE 68 +ISR_NOERRCODE 69 +ISR_NOERRCODE 70 +ISR_NOERRCODE 71 +ISR_NOERRCODE 72 +ISR_NOERRCODE 73 +ISR_NOERRCODE 74 +ISR_NOERRCODE 75 +ISR_NOERRCODE 76 +ISR_NOERRCODE 77 +ISR_NOERRCODE 78 +ISR_NOERRCODE 79 +ISR_NOERRCODE 80 +ISR_NOERRCODE 81 +ISR_NOERRCODE 82 +ISR_NOERRCODE 83 +ISR_NOERRCODE 84 +ISR_NOERRCODE 85 +ISR_NOERRCODE 86 +ISR_NOERRCODE 87 +ISR_NOERRCODE 88 +ISR_NOERRCODE 89 +ISR_NOERRCODE 90 +ISR_NOERRCODE 91 +ISR_NOERRCODE 92 +ISR_NOERRCODE 93 +ISR_NOERRCODE 94 +ISR_NOERRCODE 95 +ISR_NOERRCODE 96 +ISR_NOERRCODE 97 +ISR_NOERRCODE 98 +ISR_NOERRCODE 99 +ISR_NOERRCODE 100 +ISR_NOERRCODE 101 +ISR_NOERRCODE 102 +ISR_NOERRCODE 103 +ISR_NOERRCODE 104 +ISR_NOERRCODE 105 +ISR_NOERRCODE 106 +ISR_NOERRCODE 107 +ISR_NOERRCODE 108 +ISR_NOERRCODE 109 +ISR_NOERRCODE 110 +ISR_NOERRCODE 111 +ISR_NOERRCODE 112 +ISR_NOERRCODE 113 +ISR_NOERRCODE 114 +ISR_NOERRCODE 115 +ISR_NOERRCODE 116 +ISR_NOERRCODE 117 +ISR_NOERRCODE 118 +ISR_NOERRCODE 119 +ISR_NOERRCODE 120 +ISR_NOERRCODE 121 +ISR_NOERRCODE 122 +ISR_NOERRCODE 123 +ISR_NOERRCODE 124 +ISR_NOERRCODE 125 +ISR_NOERRCODE 126 +ISR_NOERRCODE 127 +ISR_NOERRCODE 128 +ISR_NOERRCODE 129 +ISR_NOERRCODE 130 +ISR_NOERRCODE 131 +ISR_NOERRCODE 132 +ISR_NOERRCODE 133 +ISR_NOERRCODE 134 +ISR_NOERRCODE 135 +ISR_NOERRCODE 136 +ISR_NOERRCODE 137 +ISR_NOERRCODE 138 +ISR_NOERRCODE 139 +ISR_NOERRCODE 140 +ISR_NOERRCODE 141 +ISR_NOERRCODE 142 +ISR_NOERRCODE 143 +ISR_NOERRCODE 144 +ISR_NOERRCODE 145 +ISR_NOERRCODE 146 +ISR_NOERRCODE 147 +ISR_NOERRCODE 148 +ISR_NOERRCODE 149 +ISR_NOERRCODE 150 +ISR_NOERRCODE 151 +ISR_NOERRCODE 152 +ISR_NOERRCODE 153 +ISR_NOERRCODE 154 +ISR_NOERRCODE 155 +ISR_NOERRCODE 156 +ISR_NOERRCODE 157 +ISR_NOERRCODE 158 +ISR_NOERRCODE 159 +ISR_NOERRCODE 160 +ISR_NOERRCODE 161 +ISR_NOERRCODE 162 +ISR_NOERRCODE 163 +ISR_NOERRCODE 164 +ISR_NOERRCODE 165 +ISR_NOERRCODE 166 +ISR_NOERRCODE 167 +ISR_NOERRCODE 168 +ISR_NOERRCODE 169 +ISR_NOERRCODE 170 +ISR_NOERRCODE 171 +ISR_NOERRCODE 172 +ISR_NOERRCODE 173 +ISR_NOERRCODE 174 +ISR_NOERRCODE 175 +ISR_NOERRCODE 176 +ISR_NOERRCODE 177 +ISR_NOERRCODE 178 +ISR_NOERRCODE 179 +ISR_NOERRCODE 180 +ISR_NOERRCODE 181 +ISR_NOERRCODE 182 +ISR_NOERRCODE 183 +ISR_NOERRCODE 184 +ISR_NOERRCODE 185 +ISR_NOERRCODE 186 +ISR_NOERRCODE 187 +ISR_NOERRCODE 188 +ISR_NOERRCODE 189 +ISR_NOERRCODE 190 +ISR_NOERRCODE 191 +ISR_NOERRCODE 192 +ISR_NOERRCODE 193 +ISR_NOERRCODE 194 +ISR_NOERRCODE 195 +ISR_NOERRCODE 196 +ISR_NOERRCODE 197 +ISR_NOERRCODE 198 +ISR_NOERRCODE 199 +ISR_NOERRCODE 200 +ISR_NOERRCODE 201 +ISR_NOERRCODE 202 +ISR_NOERRCODE 203 +ISR_NOERRCODE 204 +ISR_NOERRCODE 205 +ISR_NOERRCODE 206 +ISR_NOERRCODE 207 +ISR_NOERRCODE 208 +ISR_NOERRCODE 209 +ISR_NOERRCODE 210 +ISR_NOERRCODE 211 +ISR_NOERRCODE 212 +ISR_NOERRCODE 213 +ISR_NOERRCODE 214 +ISR_NOERRCODE 215 +ISR_NOERRCODE 216 +ISR_NOERRCODE 217 +ISR_NOERRCODE 218 +ISR_NOERRCODE 219 +ISR_NOERRCODE 220 +ISR_NOERRCODE 221 +ISR_NOERRCODE 222 +ISR_NOERRCODE 223 +ISR_NOERRCODE 224 +ISR_NOERRCODE 225 +ISR_NOERRCODE 226 +ISR_NOERRCODE 227 +ISR_NOERRCODE 228 +ISR_NOERRCODE 229 +ISR_NOERRCODE 230 +ISR_NOERRCODE 231 +ISR_NOERRCODE 232 +ISR_NOERRCODE 233 +ISR_NOERRCODE 234 +ISR_NOERRCODE 235 +ISR_NOERRCODE 236 +ISR_NOERRCODE 237 +ISR_NOERRCODE 238 +ISR_NOERRCODE 239 +ISR_NOERRCODE 240 +ISR_NOERRCODE 241 +ISR_NOERRCODE 242 +ISR_NOERRCODE 243 +ISR_NOERRCODE 244 +ISR_NOERRCODE 245 +ISR_NOERRCODE 246 +ISR_NOERRCODE 247 +ISR_NOERRCODE 248 +ISR_NOERRCODE 249 +ISR_NOERRCODE 250 +ISR_NOERRCODE 251 +ISR_NOERRCODE 252 +ISR_NOERRCODE 253 +ISR_NOERRCODE 254 +ISR_NOERRCODE 255 + +isr_common_stub: + pusha # Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax + + mov ax, ds # Lower 16-bits of eax = ds. + push eax # save the data segment descriptor + + mov ax, 0x10 # load the kernel data segment descriptor + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + push esp + call int_handler + add esp, 4 + + pop ebx # reload the original data segment descriptor + mov ds, bx + mov es, bx + mov fs, bx + mov gs, bx + + popa # Pops edi,esi,ebp... + add esp, 8 # Cleans up the pushed error code and pushed ISR number + sti + iret # pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index f59e6a8..da04b1c 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -183,6 +183,7 @@ int keyboard_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { } void add_keyboard(void) { + kprintf("very important"); kb_inode = devfs_add_file("/keyboard", keyboard_read, NULL, NULL, 0, 0, FS_TYPE_CHAR_DEVICE); } diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c index 6e738db..b178078 100644 --- a/kernel/drivers/rtl8139.c +++ b/kernel/drivers/rtl8139.c @@ -105,6 +105,12 @@ void rtl8139_handler(void *regs) { } void rtl8139_send_data(u8 *data, u16 data_size) { + if (data_size > 0x1000) { + rtl8139_send_data(data, 0x1000); + data += 0x1000; + data_size -= 0x1000; + return rtl8139_send_data(data, data_size); + } kprintf("ipc_write\n"); ipc_write(0, data, data_size); /* diff --git a/kernel/ipc.c b/kernel/ipc.c index 6367511..e29b169 100644 --- a/kernel/ipc.c +++ b/kernel/ipc.c @@ -47,10 +47,7 @@ int ipc_read(u8 *buffer, u32 length, u32 *sender_pid) { for (;;) { ipc_message = &handler->data[read_ptr]; if (!ipc_message->is_used) { - return 0; -// kprintf("switch\n"); -// switch_task(); -// continue; + return 0; } kprintf("breaking out\n"); break; diff --git a/kernel/ipc.h b/kernel/ipc.h index cfa9e6d..ae67f71 100644 --- a/kernel/ipc.h +++ b/kernel/ipc.h @@ -3,8 +3,8 @@ #include <stdbool.h> #include <typedefs.h> -#define IPC_BUFFER_SIZE 4096 -#define IPC_NUM_DATA 32 +#define IPC_BUFFER_SIZE 0x2000 +#define IPC_NUM_DATA 400 struct IpcMessage { u8 is_used; diff --git a/kernel/process.s b/kernel/process.s index 9f8ee71..caef941 100644 --- a/kernel/process.s +++ b/kernel/process.s @@ -101,7 +101,7 @@ insert_eip_on_stack: # WARNING: Caller is expected to disable IRQs before calling, and enable IRQs again after function returns switch_to_task: - cli +# cli # Save previous task's state diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c index 8019e5a..505dbd8 100644 --- a/kernel/sched/scheduler.c +++ b/kernel/sched/scheduler.c @@ -26,6 +26,66 @@ process_t *get_current_task(void) { return current_task; } +void process_push_restore_context(process_t *p, reg_t r) { + if (!p) { + p = current_task; + } + reg_t *new_r = kmalloc(sizeof(reg_t)); + memcpy(new_r, &r, sizeof(reg_t)); + stack_push(&p->restore_context_stack, new_r); + return; +} + +void process_pop_restore_context(process_t *p, reg_t *out_r) { + if (!p) { + p = current_task; + } + reg_t *r = stack_pop(&p->restore_context_stack); + if (NULL == r) { + assert(NULL); + } + memcpy(out_r, r, sizeof(reg_t)); + kfree(r); +} + +void process_push_signal(process_t *p, signal_t s) { + if (!p) { + p = current_task; + } + + int index = -1; + for (int i = 0; i < 100; i++) { + const signal_t *s = p->active_signals[i]; + if (!s) { + index = i; + break; + } + } + if (-1 == index) { + assert(0); + return; + } + signal_t *new_signal_entry = kmalloc(sizeof(signal_t)); + memcpy(new_signal_entry, &s, sizeof(signal_t)); + p->active_signals[index] = new_signal_entry; +} + +const signal_t *process_pop_signal(process_t *p) { + if (!p) { + p = current_task; + } + + for (int i = 0; i < 100; i++) { + const signal_t *s = p->active_signals[i]; + if (!s) { + continue; + } + p->active_signals[i] = NULL; + return s; + } + return NULL; +} + bool get_task_from_pid(u32 pid, process_t **out) { for (process_t *tmp = ready_queue; tmp; tmp = tmp->next) { if (tmp->pid == pid) { diff --git a/kernel/sched/scheduler.h b/kernel/sched/scheduler.h index 01276dc..f73d8ef 100644 --- a/kernel/sched/scheduler.h +++ b/kernel/sched/scheduler.h @@ -4,6 +4,7 @@ #include <fs/vfs.h> #include <halts.h> #include <ipc.h> +#include <lib/stack.h> #include <mmu.h> #include <signal.h> #include <stdbool.h> @@ -32,6 +33,10 @@ typedef struct { int fd; } MemoryMap; +typedef struct { + uintptr_t handler_ip; +} signal_t; + typedef struct Process process_t; typedef struct TCB { @@ -40,6 +45,11 @@ typedef struct TCB { uint32_t ESP0; } __attribute__((packed)) TCB; +void process_push_restore_context(process_t *p, reg_t r); +void process_pop_restore_context(process_t *p, reg_t *out_r); +void process_push_signal(process_t *p, signal_t s); +const signal_t *process_pop_signal(process_t *p); + struct Process { u32 pid; char program_name[100]; @@ -57,6 +67,13 @@ struct Process { vfs_inode_t *read_halt_inode[100]; vfs_inode_t *write_halt_inode[100]; vfs_inode_t *disconnect_halt_inode[100]; + + // // FIXME: Make this a array or circular buffer + // reg_t restore_context; + struct stack restore_context_stack; + + signal_t *active_signals[100]; + u32 halts[2]; struct Halt *halt_list; void *data_segment_end; diff --git a/kernel/syscalls/install_irq.c b/kernel/syscalls/install_irq.c new file mode 100644 index 0000000..c50c6e0 --- /dev/null +++ b/kernel/syscalls/install_irq.c @@ -0,0 +1,26 @@ +#include <sched/scheduler.h> +#include <syscalls.h> + +process_t *tmp; +void *handler; + +void jump_signal_handler(void *func, u32 esp); + +void test_handler(reg_t *regs) { + kprintf("IRQ FIRED\n"); + kprintf("handler: %x\n", handler); + tmp->interrupt_handler = handler; + signal_t sig; + sig.handler_ip = (uintptr_t)handler; + process_push_signal(tmp, sig); + return; +} + +int syscall_install_irq(void (*irq_handler)(), u8 irq) { + // TODO: This should be able to fail if the handler is already set + tmp = get_current_task(); + handler = irq_handler; + kprintf("IRQ INSTALLED\n"); + install_handler(test_handler, INT_32_INTERRUPT_GATE(0x0), 0x20 + irq); + return 1; +} diff --git a/kernel/syscalls/map_frames.c b/kernel/syscalls/map_frames.c new file mode 100644 index 0000000..1b0d097 --- /dev/null +++ b/kernel/syscalls/map_frames.c @@ -0,0 +1,6 @@ +#include <mmu.h> +#include <syscalls.h> + +u32 syscall_map_frames(u32 address, u32 size) { + return (u32)mmu_map_user_frames((void *)address, size); +} diff --git a/kernel/syscalls/port.c b/kernel/syscalls/port.c new file mode 100644 index 0000000..0a27a5e --- /dev/null +++ b/kernel/syscalls/port.c @@ -0,0 +1,14 @@ +#include <syscalls.h> + +// FIXME: PERMISSION CHECKS +void syscall_outw(u16 port, u16 word) { + outw(port, word); +} + +void syscall_outl(u16 port, u32 l) { + outl(port, l); +} + +u32 syscall_inl(u16 port) { + return inl(port); +} diff --git a/kernel/syscalls/virtual_to_physical.c b/kernel/syscalls/virtual_to_physical.c new file mode 100644 index 0000000..e5b3eba --- /dev/null +++ b/kernel/syscalls/virtual_to_physical.c @@ -0,0 +1,6 @@ +#include <mmu.h> +#include <syscalls.h> + +u32 syscall_virtual_to_physical(u32 virtual) { + return (u32)virtual_to_physical((void *)virtual, NULL); +} |