diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2021-12-13 20:18:32 -0500 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2021-12-13 20:18:32 -0500 |
commit | 24f2cb11c07eaa572cae6f24457699a7ac932f2f (patch) | |
tree | 8db41e252ead2b9607fa115ff7dfe112ec6aa08b | |
parent | fde6404a046a23fde994d1cb256ede919667d5fd (diff) | |
download | modit-kernel-master.tar.gz modit-kernel-master.tar.bz2 modit-kernel-master.zip |
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | arch/x86/64/apic.h (renamed from include/arch_x86/64/apic.h) | 0 | ||||
-rw-r--r-- | arch/x86/64/apic/Makefile (renamed from src/arch_x86/64/apic/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/apic/ioapic.c (renamed from src/arch_x86/64/apic/ioapic.c) | 2 | ||||
-rw-r--r-- | arch/x86/64/apic/lapic.c (renamed from src/arch_x86/64/apic/lapic.c) | 4 | ||||
-rw-r--r-- | arch/x86/64/apic/main.c (renamed from src/arch_x86/64/apic/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/64/desc_tables.h | 48 | ||||
-rw-r--r-- | arch/x86/64/gdt/Makefile (renamed from src/arch_x86/64/gdt/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/gdt/main.c (renamed from src/arch_x86/64/gdt/main.c) | 15 | ||||
-rw-r--r-- | arch/x86/64/gdt/switch.s (renamed from src/arch_x86/64/gdt/switch.s) | 0 | ||||
-rw-r--r-- | arch/x86/64/heap/Makefile (renamed from src/arch_x86/64/heap/Makefile) | 2 | ||||
-rw-r--r-- | arch/x86/64/heap/diheap.c (renamed from src/arch_x86/64/heap/diheap.c) | 12 | ||||
-rw-r--r-- | arch/x86/64/heap/heap.h (renamed from src/arch_x86/64/heap/heap.h) | 14 | ||||
-rw-r--r-- | arch/x86/64/heap/main.c (renamed from src/arch_x86/64/heap/main.c) | 14 | ||||
-rw-r--r-- | arch/x86/64/interrupt.h | 25 | ||||
-rw-r--r-- | arch/x86/64/interrupt/Makefile (renamed from src/arch_x86/64/interrupt/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/interrupt/interrupt.s (renamed from src/arch_x86/64/interrupt/interrupt.s) | 0 | ||||
-rw-r--r-- | arch/x86/64/interrupt/main.c (renamed from src/arch_x86/64/interrupt/main.c) | 31 | ||||
-rw-r--r-- | arch/x86/64/linker.ld (renamed from src/arch_x86/64/linker.ld) | 0 | ||||
-rw-r--r-- | arch/x86/64/page.h (renamed from include/arch_x86/64/page.h) | 0 | ||||
-rw-r--r-- | arch/x86/64/pmmbitmap/Makefile (renamed from src/arch_x86/64/pmmbitmap/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/pmmbitmap/main.c (renamed from src/arch_x86/64/pmmbitmap/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/64/pmmstack/Makefile (renamed from src/arch_x86/64/pmmstack/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/pmmstack/main.c (renamed from src/arch_x86/64/pmmstack/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/64/syscall/Makefile (renamed from src/arch_x86/64/syscall/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/syscall/handler.s (renamed from src/arch_x86/64/syscall/handler.s) | 0 | ||||
-rw-r--r-- | arch/x86/64/syscall/syscall.c (renamed from src/arch_x86/64/syscall/syscall.c) | 2 | ||||
-rw-r--r-- | arch/x86/64/task/Makefile (renamed from src/arch_x86/64/task/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/task/context.c (renamed from src/arch_x86/64/task/context.c) | 9 | ||||
-rw-r--r-- | arch/x86/64/task/load.c (renamed from src/arch_x86/64/task/load.c) | 2 | ||||
-rw-r--r-- | arch/x86/64/task/message.c (renamed from src/arch_x86/64/task/message.c) | 2 | ||||
-rw-r--r-- | arch/x86/64/task/port.c (renamed from src/arch_x86/64/task/port.c) | 2 | ||||
-rw-r--r-- | arch/x86/64/task/rip.s (renamed from src/arch_x86/64/task/rip.s) | 0 | ||||
-rw-r--r-- | arch/x86/64/tlb/Makefile (renamed from src/arch_x86/64/tlb/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/tlb/clone.c (renamed from src/arch_x86/64/tlb/clone.c) | 0 | ||||
-rw-r--r-- | arch/x86/64/tlb/main.c (renamed from src/arch_x86/64/tlb/main.c) | 24 | ||||
-rw-r--r-- | arch/x86/64/user/Makefile (renamed from src/arch_x86/64/user/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/64/user/jump.s (renamed from src/arch_x86/64/user/jump.s) | 0 | ||||
-rw-r--r-- | arch/x86/64/user/user.c (renamed from src/arch_x86/64/user/user.c) | 0 | ||||
-rw-r--r-- | arch/x86/acpi.h (renamed from include/arch_x86/common/acpi.h) | 0 | ||||
-rw-r--r-- | arch/x86/common/acpi/Makefile (renamed from src/arch_x86/common/acpi/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/acpi/madt.c (renamed from src/arch_x86/common/acpi/madt.c) | 4 | ||||
-rw-r--r-- | arch/x86/common/acpi/main.c (renamed from src/arch_x86/common/acpi/main.c) | 3 | ||||
-rw-r--r-- | arch/x86/common/acpi/rsdt.c (renamed from src/arch_x86/common/acpi/rsdt.c) | 3 | ||||
-rw-r--r-- | arch/x86/common/cpu/Makefile (renamed from src/arch_x86/common/cpu/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/cpu/main.c (renamed from src/arch_x86/common/cpu/main.c) | 2 | ||||
-rw-r--r-- | arch/x86/common/klibc/Makefile (renamed from src/arch_common/klibc/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/inb.c (renamed from src/arch_x86/common/klibc/inb.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/io_wait.c (renamed from src/arch_x86/common/klibc/io_wait.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/memcmp.c (renamed from src/arch_x86/common/klibc/memcmp.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/memcpy.c (renamed from src/arch_x86/common/klibc/memcpy.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/memset.c (renamed from src/arch_x86/common/klibc/memset.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/klibc/outb.c (renamed from src/arch_x86/common/klibc/outb.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/main.c (renamed from src/arch_x86/common/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/panic/Makefile (renamed from src/arch_x86/common/panic/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/panic/main.c (renamed from src/arch_x86/common/panic/main.c) | 18 | ||||
-rw-r--r-- | arch/x86/common/pic/Makefile (renamed from src/arch_x86/common/pic/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/pic/main.c (renamed from src/arch_x86/common/pic/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/pit/Makefile (renamed from src/arch_x86/common/pit/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/pit/main.c (renamed from src/arch_x86/common/pit/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/stivale2/Makefile (renamed from src/arch_x86/common/stivale2/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/stivale2/main.c (renamed from src/arch_x86/common/stivale2/main.c) | 0 | ||||
-rw-r--r-- | arch/x86/common/syscall/Makefile (renamed from src/arch_x86/common/syscall/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/syscall/syscall.c (renamed from src/arch_x86/common/syscall/syscall.c) | 2 | ||||
-rw-r--r-- | arch/x86/common/timer/Makefile (renamed from src/arch_x86/common/timer/Makefile) | 0 | ||||
-rw-r--r-- | arch/x86/common/timer/main.c (renamed from src/arch_x86/common/timer/main.c) | 6 | ||||
-rw-r--r-- | arch/x86/cpu.h (renamed from include/arch_x86/common/x86.h) | 0 | ||||
-rw-r--r-- | arch/x86/gdt.h (renamed from include/arch_x86/common/gdt.h) | 0 | ||||
-rw-r--r-- | arch/x86/ipc.h (renamed from include/arch_x86/common/ipc.h) | 0 | ||||
-rw-r--r-- | arch/x86/list.h (renamed from include/arch_x86/common/list.h) | 0 | ||||
-rw-r--r-- | arch/x86/pic.h (renamed from include/arch_x86/common/pic.h) | 0 | ||||
-rw-r--r-- | arch/x86/pit.h (renamed from include/arch_x86/common/pit.h) | 0 | ||||
-rw-r--r-- | arch/x86/syscall.h (renamed from include/arch_x86/common/syscall.h) | 0 | ||||
-rw-r--r-- | arch/x86/task.h (renamed from include/arch_x86/common/task.h) | 0 | ||||
-rw-r--r-- | arch/x86/timer.h (renamed from include/arch_x86/common/timer.h) | 0 | ||||
-rw-r--r-- | arch/x86/user.h (renamed from include/arch_x86/common/user.h) | 0 | ||||
-rw-r--r-- | common/boot.h (renamed from include/arch_common/boot.h) | 0 | ||||
-rw-r--r-- | common/init/Makefile (renamed from src/arch_common/init/Makefile) | 0 | ||||
-rw-r--r-- | common/init/init.c (renamed from src/arch_common/init/init.c) | 2 | ||||
-rw-r--r-- | common/initrd.h (renamed from include/arch_common/initrd.h) | 0 | ||||
-rw-r--r-- | common/initrd/Makefile (renamed from src/arch_common/initrd/Makefile) | 0 | ||||
-rw-r--r-- | common/initrd/initrd.c (renamed from src/arch_common/initrd/initrd.c) | 2 | ||||
-rw-r--r-- | common/initrd/tar.c (renamed from src/arch_common/initrd/tar.c) | 2 | ||||
-rw-r--r-- | common/klibc/Makefile (renamed from src/arch_x86/common/klibc/Makefile) | 0 | ||||
-rw-r--r-- | common/klibc/fprintf.c (renamed from src/arch_common/klibc/fprintf.c) | 0 | ||||
-rw-r--r-- | common/klibc/isnum.c (renamed from src/arch_common/klibc/isnum.c) | 0 | ||||
-rw-r--r-- | common/klibc/itoa.c (renamed from src/arch_common/klibc/itoa.c) | 0 | ||||
-rw-r--r-- | common/klibc/main.c (renamed from src/arch_common/klibc/main.c) | 0 | ||||
-rw-r--r-- | common/klibc/printf.c (renamed from src/arch_common/klibc/printf.c) | 0 | ||||
-rw-r--r-- | common/klibc/printk.c (renamed from src/arch_common/klibc/printk.c) | 0 | ||||
-rw-r--r-- | common/klibc/sllist.c (renamed from src/arch_common/klibc/sllist.c) | 0 | ||||
-rw-r--r-- | common/klibc/sprintf.c (renamed from src/arch_common/klibc/sprintf.c) | 0 | ||||
-rw-r--r-- | common/klibc/strcmp.c (renamed from src/arch_common/klibc/strcmp.c) | 0 | ||||
-rw-r--r-- | common/klibc/strcpy.c (renamed from src/arch_common/klibc/strcpy.c) | 0 | ||||
-rw-r--r-- | common/klibc/strlen.c (renamed from src/arch_common/klibc/strlen.c) | 0 | ||||
-rw-r--r-- | common/klibc/strtol.c (renamed from src/arch_common/klibc/strtol.c) | 0 | ||||
-rw-r--r-- | common/klibc/tolower.c (renamed from src/arch_common/klibc/tolower.c) | 0 | ||||
-rw-r--r-- | common/klibc/toupper.c (renamed from src/arch_common/klibc/toupper.c) | 0 | ||||
-rw-r--r-- | common/klibc/vsnprintf.c (renamed from src/arch_common/klibc/vsnprintf.c) | 0 | ||||
-rw-r--r-- | common/memory.h (renamed from include/arch_common/heap.h) | 0 | ||||
-rw-r--r-- | common/modit.h (renamed from include/arch_common/modit.h) | 7 | ||||
-rw-r--r-- | common/mutex.h (renamed from include/arch_common/mutex.h) | 0 | ||||
-rw-r--r-- | common/panic.h (renamed from include/arch_common/panic.h) | 5 | ||||
-rw-r--r-- | common/pmm.h (renamed from include/arch_common/pmm.h) | 0 | ||||
-rw-r--r-- | common/serialtxt.h (renamed from include/arch_common/serialtxt.h) | 0 | ||||
-rw-r--r-- | common/serialtxt/Makefile (renamed from src/arch_common/serialtxt/Makefile) | 0 | ||||
-rw-r--r-- | common/serialtxt/main.c (renamed from src/arch_common/serialtxt/main.c) | 0 | ||||
-rw-r--r-- | common/stdio.h (renamed from include/arch_common/stdio.h) | 0 | ||||
-rw-r--r-- | common/stivale2.h (renamed from include/arch_common/stivale2.h) | 0 | ||||
-rw-r--r-- | common/string.h (renamed from include/arch_common/string.h) | 0 | ||||
-rw-r--r-- | common/vgatxt.h (renamed from include/arch_common/vgatxt.h) | 0 | ||||
-rw-r--r-- | common/vgatxt/Makefile (renamed from src/arch_common/vgatxt/Makefile) | 0 | ||||
-rw-r--r-- | common/vgatxt/main.c (renamed from src/arch_common/vgatxt/main.c) | 0 | ||||
-rw-r--r-- | common/vmm.h (renamed from include/arch_common/vmm.h) | 0 | ||||
-rw-r--r-- | include/arch_x86/64/idt.h | 69 | ||||
-rw-r--r-- | include/arch_x86/64/registers.h | 37 | ||||
-rw-r--r-- | include/arch_x86/common/interrupt.h | 30 |
117 files changed, 176 insertions, 237 deletions
@@ -12,12 +12,12 @@ endif #Files PWD := $(shell pwd) -CORESRC := src/arch_$(ARCH)/common/main.c +CORESRC := arch/$(ARCH)/common/main.c COREOBJ := $(patsubst %.c,%.o,$(CORESRC)) -SRCPATHS := src/arch_$(ARCH)/$(BITS) -SRCPATHS += src/arch_$(ARCH)/common -SRCPATHS += src/arch_common +SRCPATHS := arch/$(ARCH)/$(BITS) +SRCPATHS += arch/$(ARCH)/common +SRCPATHS += common FINDMOD = $(foreach path,$(SRCPATHS),$(wildcard $(path)/$(mod)/)) @@ -25,14 +25,14 @@ MODDIRS := $(foreach mod,$(MODORDER),$(FINDMOD)) MODS := $(patsubst %/,%.a,$(MODDIRS)) -LINK ?= src/arch_$(ARCH)/$(BITS)/linker.ld +LINK ?= arch/$(ARCH)/$(BITS)/linker.ld #Tools CC ?= gcc LD ?= ld AS ?= as WARNS := -Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wdouble-promotion -Wshadow -Wcast-align -INCLUDE := -I$(PWD)/include/arch_$(ARCH)/common -I$(PWD)/include/arch_$(ARCH)/$(BITS) -I$(PWD)/include/arch_common/ +INCLUDE := -I$(PWD)/arch/$(ARCH)/ -I$(PWD)/arch/$(ARCH)/$(BITS) -I$(PWD)/common/ DEFINES := -DARCH_$(ARCH) -DBITS_$(BITS) -DLOGLEVEL=$(LOGLEVEL) CFLAGS := -ffreestanding -nostdlib -fno-stack-protector $(INCLUDE) $(WARNS) -fno-pic -fpie -fomit-frame-pointer -mno-red-zone -mgeneral-regs-only $(DEFINES) -g LDFLAGS := -T$(LINK) -nostdlib -pie -static-pie -fno-pic -fpie -z max-page-size=0x1000 -Wl,--whole-archive @@ -48,6 +48,7 @@ build: $(COREOBJ) $(MODS) clean: rm $(COREOBJ) rm $(MODS) + for dir in $(MODDIRS) ; do rm $$dir/*.o; done %.o:%.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/include/arch_x86/64/apic.h b/arch/x86/64/apic.h index 858e9d2..858e9d2 100644 --- a/include/arch_x86/64/apic.h +++ b/arch/x86/64/apic.h diff --git a/src/arch_x86/64/apic/Makefile b/arch/x86/64/apic/Makefile index ae18db3..ae18db3 100644 --- a/src/arch_x86/64/apic/Makefile +++ b/arch/x86/64/apic/Makefile diff --git a/src/arch_x86/64/apic/ioapic.c b/arch/x86/64/apic/ioapic.c index eda98d0..ef2fddd 100644 --- a/src/arch_x86/64/apic/ioapic.c +++ b/arch/x86/64/apic/ioapic.c @@ -1,7 +1,7 @@ #include "interrupt.h" #include "stdio.h" #include "vmm.h" -#include "heap.h" +#include "memory.h" #include "acpi.h" #include "apic.h" diff --git a/src/arch_x86/64/apic/lapic.c b/arch/x86/64/apic/lapic.c index e8e131c..771a215 100644 --- a/src/arch_x86/64/apic/lapic.c +++ b/arch/x86/64/apic/lapic.c @@ -2,7 +2,7 @@ #include "stdio.h" #include "acpi.h" #include "apic.h" -#include "x86.h" +#include "cpu.h" #include "pic.h" static uintptr_t lapic_regs = 0; @@ -53,7 +53,7 @@ apic_lapic_setup(void) outb(PIC_DATA(PIC1), 0xFF); outb(PIC_DATA(PIC2), 0xFF); - int_set_handler(7, _interrupt_handler_spurious); + interrupt_handler_set(7, _interrupt_handler_spurious); } void diff --git a/src/arch_x86/64/apic/main.c b/arch/x86/64/apic/main.c index 7370343..7370343 100644 --- a/src/arch_x86/64/apic/main.c +++ b/arch/x86/64/apic/main.c diff --git a/arch/x86/64/desc_tables.h b/arch/x86/64/desc_tables.h new file mode 100644 index 0000000..2806bcf --- /dev/null +++ b/arch/x86/64/desc_tables.h @@ -0,0 +1,48 @@ +#ifndef MODIT_KERNEL_DESC_TABLES_H +#define MODIT_KERNEL_DESC_TABLES_H 1 + +#include <stdint.h> + +#define IDTD_TYPE_INTERRUPT 0b1110 +#define IDTD_TYPE_TRAP 0b1111 + +#define IDTD_DPL_KERNEL 0b00 +#define IDTD_DPL_UNUSED1 0b01 +#define IDTD_DPL_UNUSED2 0b10 +#define IDTD_DPL_USER 0b11 + +struct idt_entry +{ + uint16_t offset_0_16; + uint16_t ssel; + union { + struct { + uint8_t ist : 2; + uint8_t zero : 6; + uint8_t type : 4; + uint8_t zero2 : 1; + uint8_t dpl : 2; + uint8_t present : 1; + }; + uint16_t flags; + }; + uint16_t offset_16_32; + uint32_t offset_32_64; + uint32_t reserved; +}; + +struct gdt_entry { + uint16_t limit_low, base_low; + uint8_t base_mid, type, flag, base_high; +}__attribute__((packed)); + +struct tss{ + uint32_t resv0; + uint64_t rsp[3]; + uint64_t resv1; + uint64_t ist[7]; + uint64_t resv2; + uint16_t resv3, iopbo; +} __attribute__((packed)); + +#endif diff --git a/src/arch_x86/64/gdt/Makefile b/arch/x86/64/gdt/Makefile index ffc986d..ffc986d 100644 --- a/src/arch_x86/64/gdt/Makefile +++ b/arch/x86/64/gdt/Makefile diff --git a/src/arch_x86/64/gdt/main.c b/arch/x86/64/gdt/main.c index f942bda..755e282 100644 --- a/src/arch_x86/64/gdt/main.c +++ b/arch/x86/64/gdt/main.c @@ -1,20 +1,9 @@ #include "modit.h" +#include "desc_tables.h" #include <stdio.h> #include <stdint.h> -struct gdt_entry { - uint16_t limit_low, base_low; - uint8_t base_mid, type, flag, base_high; -}__attribute__((packed)); - -static struct { - uint32_t resv0; - uint64_t rsp[3]; - uint64_t resv1; - uint64_t ist[7]; - uint64_t resv2; - uint16_t resv3, iopbo; -} __attribute__((packed)) tss = { 0 }; +static struct tss tss; __attribute__((aligned(0x1000))) static struct { diff --git a/src/arch_x86/64/gdt/switch.s b/arch/x86/64/gdt/switch.s index a6c022b..a6c022b 100644 --- a/src/arch_x86/64/gdt/switch.s +++ b/arch/x86/64/gdt/switch.s diff --git a/src/arch_x86/64/heap/Makefile b/arch/x86/64/heap/Makefile index fec58e6..6d1bacd 100644 --- a/src/arch_x86/64/heap/Makefile +++ b/arch/x86/64/heap/Makefile @@ -16,7 +16,7 @@ OUT := heap .PHONY: all all: ${OFILES} - $(AR) -rcs ../$(OUT).a *.o */*.o + $(AR) -rcs ../$(OUT).a *.o %.o:%.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/src/arch_x86/64/heap/diheap.c b/arch/x86/64/heap/diheap.c index 59a257b..2b9390d 100644 --- a/src/arch_x86/64/heap/diheap.c +++ b/arch/x86/64/heap/diheap.c @@ -31,7 +31,7 @@ #include <string.h> int -heap_create(struct heap *heap, uintptr_t at, size_t len) +__heap_create(struct heap *heap, uintptr_t at, size_t len) { struct crate *firstcrate = NULL; struct bucket *cratebucket = NULL; @@ -69,12 +69,6 @@ heap_create(struct heap *heap, uintptr_t at, size_t len) return 0; } -void -heap_resize(struct heap *heap, size_t newsize) -{ - heap->size = newsize; -} - struct bucket* __heap_bucket_findbest(struct heap *heap, size_t size) { @@ -231,7 +225,7 @@ __heap_bucket_merge(struct heap *heap, struct bucket *bucket) } void* -heap_alloc(struct heap *heap, size_t size) +__heap_alloc(struct heap *heap, size_t size) { struct bucket *bestfit = NULL; size_t remaining = heap->size - heap->used; @@ -264,7 +258,7 @@ heap_alloc(struct heap *heap, size_t size) } int -heap_free(struct heap *heap, void *ptr) +__heap_free(struct heap *heap, void *ptr) { uintptr_t addr = (uintptr_t)ptr; for(struct bucket *bucket = heap->buckets_tail; diff --git a/src/arch_x86/64/heap/heap.h b/arch/x86/64/heap/heap.h index 5eed7e4..4ec028e 100644 --- a/src/arch_x86/64/heap/heap.h +++ b/arch/x86/64/heap/heap.h @@ -86,8 +86,8 @@ * in the bucket list. The crates' buckets are initialized to link with * eachother and are set as the head of the unused list. */ -#ifndef JSH_HEAP_H -#define JSH_HEAP_H 1 +#ifndef DIH_HEAP_H +#define DIH_HEAP_H 1 #include <stdint.h> #include <stddef.h> @@ -131,19 +131,15 @@ struct heap /* Fills a heap datastructure with passed arguments and populates the first crate * If len is less than MODIT_HEAP_CRATE_SIZE, function fails * */ -int heap_create(struct heap *heap, uintptr_t at, size_t len); - -/* Expands the heap's allocation area. Does not support reallocations - * */ -void heap_resize(struct heap *heap, size_t newsize); +int __heap_create(struct heap *heap, uintptr_t at, size_t len); /* Allocates a block of memory atleast [size] bytes long in heap * */ -void *heap_alloc(struct heap *heap, size_t size); +void *__heap_alloc(struct heap *heap, size_t size); /* Frees the memory pointed at by [ptr] for later allocations. * Returns 0 if memory was found and freed * */ -int heap_free(struct heap *heap, void *ptr); +int __heap_free(struct heap *heap, void *ptr); #endif diff --git a/src/arch_x86/64/heap/main.c b/arch/x86/64/heap/main.c index b9c5eb8..854a91f 100644 --- a/src/arch_x86/64/heap/main.c +++ b/arch/x86/64/heap/main.c @@ -1,5 +1,5 @@ +#include "memory.h" #include "heap.h" -#include "diheap/heap.h" #include <stdint.h> #include "stdio.h" @@ -26,8 +26,8 @@ heap_constructor(void) vmm_alloc(MODIT_HEAP_VL_START, MODIT_HEAP_VL_SIZE, 0, 0); vmm_alloc(MODIT_HEAP_PF_START, MODIT_HEAP_PF_SIZE, 0, 0); - heap_create(&kernel_heap_vl, MODIT_HEAP_VL_START, MODIT_HEAP_VL_SIZE); - heap_create(&kernel_heap_pf, MODIT_HEAP_PF_START, MODIT_HEAP_PF_SIZE); + __heap_create(&kernel_heap_vl, MODIT_HEAP_VL_START, MODIT_HEAP_VL_SIZE); + __heap_create(&kernel_heap_pf, MODIT_HEAP_PF_START, MODIT_HEAP_PF_SIZE); } void * @@ -35,9 +35,9 @@ malloc(size_t size) { void *ret = NULL; if(size % PAGE_SIZE == 0) { - ret = heap_alloc(&kernel_heap_pf, size); + ret = __heap_alloc(&kernel_heap_pf, size); }else{ - ret = heap_alloc(&kernel_heap_vl, size); + ret = __heap_alloc(&kernel_heap_vl, size); } return ret; } @@ -54,9 +54,9 @@ calloc(size_t nmemb, size_t size) void free(void *ptr) { if((uintptr_t)ptr > MODIT_HEAP_PF_START) { - heap_free(&kernel_heap_pf, ptr); + __heap_free(&kernel_heap_pf, ptr); }else if((uintptr_t)ptr > MODIT_HEAP_VL_START){ - heap_free(&kernel_heap_vl, ptr); + __heap_free(&kernel_heap_vl, ptr); } } diff --git a/arch/x86/64/interrupt.h b/arch/x86/64/interrupt.h new file mode 100644 index 0000000..1512aaa --- /dev/null +++ b/arch/x86/64/interrupt.h @@ -0,0 +1,25 @@ +#ifndef MODIT_KERNEL_INTERRUPT_H +#define MODIT_KERNEL_INTERRUPT_H 1 + +#include <stdint.h> + +struct intbase { + uint64_t err; + uint64_t rip, cs, rflag, sp, ss; +}; + +struct intstate { + uint64_t r15, r14, r13, r12, r11, r10, r9, r8; + uint64_t rbp, rsi, rdi; + uint64_t rbx, rdx, rcx, rax; + uint64_t num; + struct intbase base; +}; + +typedef void (*int_vector_t)(struct intbase *); +typedef void (*int_handler_t)(struct intstate *); + +void *interrupt_vector_set(int i, int_vector_t vector); +void *interrupt_handler_set(int i, int_handler_t handler); + +#endif diff --git a/src/arch_x86/64/interrupt/Makefile b/arch/x86/64/interrupt/Makefile index c004376..c004376 100644 --- a/src/arch_x86/64/interrupt/Makefile +++ b/arch/x86/64/interrupt/Makefile diff --git a/src/arch_x86/64/interrupt/interrupt.s b/arch/x86/64/interrupt/interrupt.s index 7f042a9..7f042a9 100644 --- a/src/arch_x86/64/interrupt/interrupt.s +++ b/arch/x86/64/interrupt/interrupt.s diff --git a/src/arch_x86/64/interrupt/main.c b/arch/x86/64/interrupt/main.c index e2d49a5..fe22d63 100644 --- a/src/arch_x86/64/interrupt/main.c +++ b/arch/x86/64/interrupt/main.c @@ -1,4 +1,4 @@ -#include "idt.h" +#include "desc_tables.h" #include "interrupt.h" #include "modit.h" #include "panic.h" @@ -6,7 +6,7 @@ #include "stdio.h" #include "stdlib.h" -static PAGEALIGN struct idtd _idt[256]; +static PAGEALIGN struct idt_entry _idt[256]; static int_handler_t handlers[48]; extern uintptr_t interrupt_vectors; @@ -47,24 +47,24 @@ static const char *exceptstrs[32] = __attribute__((interrupt)) void -_interrupt_handler_null(struct intframe *frame) +_interrupt_handler_null(struct intbase *frame) { (void)frame; panic("Unhandled exception\n"); } void -interrupt_body(struct intregs *regs) +interrupt_body(struct intstate *state) { - if(handlers[regs->num] == NULL) { - panic_except(regs, exceptstrs[regs->num]); + if(handlers[state->num] == NULL) { + panic_except(state, exceptstrs[state->num]); }else{ - handlers[regs->num](regs ); + handlers[state->num](state); } } void* -int_set_vector(int i, int_vector_t vector) +interrupt_vector_set(int i, int_vector_t vector) { uintptr_t old = (_idt[i].offset_0_16 + ((uint64_t)_idt[i].offset_16_32 << 16) + @@ -77,17 +77,28 @@ int_set_vector(int i, int_vector_t vector) } void* -int_set_handler(int i, int_handler_t handler) +interrupt_handler_set(int i, int_handler_t handler) { int_handler_t old = NULL; if(i >= 48) return NULL; - int_set_vector(i, (int_vector_t)((&interrupt_vectors)[i])); + interrupt_vector_set(i, (int_vector_t)((&interrupt_vectors)[i])); old = handlers[i]; handlers[i] = handler; return old; } void + + + + + + + + + + + int_setist(int i, uint8_t s) { _idt[i].ist = i; diff --git a/src/arch_x86/64/linker.ld b/arch/x86/64/linker.ld index a008975..a008975 100644 --- a/src/arch_x86/64/linker.ld +++ b/arch/x86/64/linker.ld diff --git a/include/arch_x86/64/page.h b/arch/x86/64/page.h index dd27e3d..dd27e3d 100644 --- a/include/arch_x86/64/page.h +++ b/arch/x86/64/page.h diff --git a/src/arch_x86/64/pmmbitmap/Makefile b/arch/x86/64/pmmbitmap/Makefile index f010abb..f010abb 100644 --- a/src/arch_x86/64/pmmbitmap/Makefile +++ b/arch/x86/64/pmmbitmap/Makefile diff --git a/src/arch_x86/64/pmmbitmap/main.c b/arch/x86/64/pmmbitmap/main.c index 990c4ea..990c4ea 100644 --- a/src/arch_x86/64/pmmbitmap/main.c +++ b/arch/x86/64/pmmbitmap/main.c diff --git a/src/arch_x86/64/pmmstack/Makefile b/arch/x86/64/pmmstack/Makefile index 6f4f184..6f4f184 100644 --- a/src/arch_x86/64/pmmstack/Makefile +++ b/arch/x86/64/pmmstack/Makefile diff --git a/src/arch_x86/64/pmmstack/main.c b/arch/x86/64/pmmstack/main.c index 1351442..1351442 100644 --- a/src/arch_x86/64/pmmstack/main.c +++ b/arch/x86/64/pmmstack/main.c diff --git a/src/arch_x86/64/syscall/Makefile b/arch/x86/64/syscall/Makefile index 58ac95c..58ac95c 100644 --- a/src/arch_x86/64/syscall/Makefile +++ b/arch/x86/64/syscall/Makefile diff --git a/src/arch_x86/64/syscall/handler.s b/arch/x86/64/syscall/handler.s index fcc870c..fcc870c 100644 --- a/src/arch_x86/64/syscall/handler.s +++ b/arch/x86/64/syscall/handler.s diff --git a/src/arch_x86/64/syscall/syscall.c b/arch/x86/64/syscall/syscall.c index 183e402..06f6904 100644 --- a/src/arch_x86/64/syscall/syscall.c +++ b/arch/x86/64/syscall/syscall.c @@ -1,5 +1,5 @@ #include "modit.h" -#include "x86.h" +#include "cpu.h" #include "stdio.h" #include "syscall.h" diff --git a/src/arch_x86/64/task/Makefile b/arch/x86/64/task/Makefile index b1d7a7e..b1d7a7e 100644 --- a/src/arch_x86/64/task/Makefile +++ b/arch/x86/64/task/Makefile diff --git a/src/arch_x86/64/task/context.c b/arch/x86/64/task/context.c index e4de9d6..5c79bba 100644 --- a/src/arch_x86/64/task/context.c +++ b/arch/x86/64/task/context.c @@ -2,11 +2,11 @@ #include "modit.h" #include "stdio.h" #include "stdlib.h" -#include "heap.h" +#include "memory.h" #include "vmm.h" #include "gdt.h" #include "apic.h" -#include "idt.h" +#include "interrupt.h" //Current execution context THREAD struct execution_context *current_excontext; @@ -23,8 +23,9 @@ static int timer_context_ticks_trigger = 0; static bool in_timer = false; static void -excontext_timer_handler(struct intregs *regs) +excontext_timer_handler(struct intstate *state) { + (void)state; if(timer_context == NULL) { apic_write(APIC_REG_TIMER_IC, 10 * timer_gettpms()); apic_write(0xB0, 0); @@ -134,5 +135,5 @@ task_constructor(void) excontext_switch(current_excontext); tss_setstackpl(0, MODIT_KERNEL_STAST); - int_set_handler(32, excontext_timer_handler); + interrupt_handler_set(32, excontext_timer_handler); } diff --git a/src/arch_x86/64/task/load.c b/arch/x86/64/task/load.c index b04c632..9ee48d6 100644 --- a/src/arch_x86/64/task/load.c +++ b/arch/x86/64/task/load.c @@ -2,7 +2,7 @@ #include "vmm.h" #include "pmm.h" #include "page.h" -#include "heap.h" +#include "memory.h" #include "stdlib.h" #include "stdio.h" #include "modit.h" diff --git a/src/arch_x86/64/task/message.c b/arch/x86/64/task/message.c index ab95ff2..a915488 100644 --- a/src/arch_x86/64/task/message.c +++ b/arch/x86/64/task/message.c @@ -4,7 +4,7 @@ #include "mutex.h" #include "stdio.h" #include "stdlib.h" -#include "heap.h" +#include "memory.h" int message_send(size_t tgt, uint8_t *data, size_t len) diff --git a/src/arch_x86/64/task/port.c b/arch/x86/64/task/port.c index 38be3c7..f06acad 100644 --- a/src/arch_x86/64/task/port.c +++ b/arch/x86/64/task/port.c @@ -1,7 +1,7 @@ #include "ipc.h" #include "modit.h" #include "task.h" -#include "heap.h" +#include "memory.h" #include "stdlib.h" #include "stdio.h" diff --git a/src/arch_x86/64/task/rip.s b/arch/x86/64/task/rip.s index 4713a1d..4713a1d 100644 --- a/src/arch_x86/64/task/rip.s +++ b/arch/x86/64/task/rip.s diff --git a/src/arch_x86/64/tlb/Makefile b/arch/x86/64/tlb/Makefile index ca6221c..ca6221c 100644 --- a/src/arch_x86/64/tlb/Makefile +++ b/arch/x86/64/tlb/Makefile diff --git a/src/arch_x86/64/tlb/clone.c b/arch/x86/64/tlb/clone.c index 125a9c5..125a9c5 100644 --- a/src/arch_x86/64/tlb/clone.c +++ b/arch/x86/64/tlb/clone.c diff --git a/src/arch_x86/64/tlb/main.c b/arch/x86/64/tlb/main.c index 4b64b2f..1172284 100644 --- a/src/arch_x86/64/tlb/main.c +++ b/arch/x86/64/tlb/main.c @@ -1,3 +1,4 @@ +#include "modit.h" #include "boot.h" #include "vmm.h" #include "pmm.h" @@ -5,9 +6,9 @@ #include "panic.h" #include "modit.h" #include "task.h" +#include "string.h" #include "stdio.h" -#include "stdlib.h" static vmptr_t *const pml4 = (vmptr_t*)0xFFFFFF7FBFDFE000ULL; static vmptr_t *const pml3 = (vmptr_t*)0xFFFFFF7FBFC00000ULL; @@ -16,12 +17,12 @@ static vmptr_t *const pml1 = (vmptr_t*)0xFFFFFF0000000000ULL; vmptr_t *const pmls[4] = { pml1, pml2, pml3, pml4 }; -THREAD uintptr_t vcr3; +uintptr_t vcr3; -__attribute__((aligned(4096))) static struct page kernel_pml4[512] = { 0 }; -__attribute__((aligned(4096))) static struct page kernel_pml3[512] = { 0 }; -__attribute__((aligned(4096))) static struct page kernel_pml2[512] = { 0 }; -__attribute__((aligned(4096))) static struct page kernel_pml1[512] = { 0 }; +PAGEALIGN static struct page kernel_pml4[512] = { 0 }; +PAGEALIGN static struct page kernel_pml3[512] = { 0 }; +PAGEALIGN static struct page kernel_pml2[512] = { 0 }; +PAGEALIGN static struct page kernel_pml1[512] = { 0 }; static void vmm_invlpg(vmptr_t addr) @@ -30,12 +31,11 @@ vmm_invlpg(vmptr_t addr) } void -_interrupt_handler_pagefault(struct intregs *regs) +_interrupt_handler_pagefault(struct intstate *state) { uint64_t pa; asm volatile("movq %%cr2, %0": "=a"(pa)); - printk(KERNEL_INFO, "%X PF %X @ %X (%i)\n", vcr3, pa, regs->rip, regs->err); uintptr_t l1 = VMM_PML1_INDEX(pa); uint64_t pg = pml1[l1]; if(pg & (PAGE_OS_LAZY << 9)) { @@ -46,8 +46,10 @@ _interrupt_handler_pagefault(struct intregs *regs) } char mbuffer[128]; - snprintf(mbuffer, 128, "%s Page Fault From %s Page By %s Violation at %l016X\n", regs->err & 4 ? "User" : "Kernel", regs->err & 1 ? "Present" : "Non-Present", regs->err & 2 ? "Write" : "Read", pa); - panic_except(regs, mbuffer); + panic_except(state, "%S Page Fault From %s Page By %s Violation at %l016X\n", + state->base.err & 4 ? "User" : "Kernel", + state->base.err & 1 ? "Present" : "Non-Present", + state->base.err & 2 ? "Write" : "Read"); } pmptr_t @@ -140,7 +142,7 @@ vmm_alloc_force(vmptr_t virt, size_t size, bool user, bool ow) MODULE static void tlb_constructor(void) { - int_set_handler(14, _interrupt_handler_pagefault); + interrupt_handler_set(14, _interrupt_handler_pagefault); pmptr_t kpml4_phys = ((pmptr_t)&kernel_pml4) - MODIT_HIGHER_HALF_X86_64; pmptr_t kpml3_phys = ((pmptr_t)&kernel_pml3) - MODIT_HIGHER_HALF_X86_64; diff --git a/src/arch_x86/64/user/Makefile b/arch/x86/64/user/Makefile index f7dbf77..f7dbf77 100644 --- a/src/arch_x86/64/user/Makefile +++ b/arch/x86/64/user/Makefile diff --git a/src/arch_x86/64/user/jump.s b/arch/x86/64/user/jump.s index 2f6ce62..2f6ce62 100644 --- a/src/arch_x86/64/user/jump.s +++ b/arch/x86/64/user/jump.s diff --git a/src/arch_x86/64/user/user.c b/arch/x86/64/user/user.c index 9c8b388..9c8b388 100644 --- a/src/arch_x86/64/user/user.c +++ b/arch/x86/64/user/user.c diff --git a/include/arch_x86/common/acpi.h b/arch/x86/acpi.h index dd55ee7..dd55ee7 100644 --- a/include/arch_x86/common/acpi.h +++ b/arch/x86/acpi.h diff --git a/src/arch_x86/common/acpi/Makefile b/arch/x86/common/acpi/Makefile index 20e4d68..20e4d68 100644 --- a/src/arch_x86/common/acpi/Makefile +++ b/arch/x86/common/acpi/Makefile diff --git a/src/arch_x86/common/acpi/madt.c b/arch/x86/common/acpi/madt.c index abaf706..ce6a639 100644 --- a/src/arch_x86/common/acpi/madt.c +++ b/arch/x86/common/acpi/madt.c @@ -1,8 +1,8 @@ #include "acpi.h" -#include "x86.h" +#include "cpu.h" #include "boot.h" #include "stdio.h" -#include "heap.h" +#include "memory.h" #include "vmm.h" #define MADT_ENTRY_LAPIC 0 diff --git a/src/arch_x86/common/acpi/main.c b/arch/x86/common/acpi/main.c index d221dbc..b958041 100644 --- a/src/arch_x86/common/acpi/main.c +++ b/arch/x86/common/acpi/main.c @@ -1,6 +1,6 @@ #include "acpi.h" #include "boot.h" -#include "heap.h" +#include "memory.h" #include "panic.h" #include "stdio.h" #include "vmm.h" @@ -36,7 +36,6 @@ rsdp_find_rsdt(struct rsdp1 *rsdp) vmm_mappg(rsdtphys, rsdtaddr, 0, 3); rsdtaddr += (rsdtphys % PAGE_SIZE); - printk(KERNEL_INFO, "RSDT %lX\n", rsdtaddr); rsdt_parse(rsdp, (struct acpisdthdr*)rsdtaddr); } diff --git a/src/arch_x86/common/acpi/rsdt.c b/arch/x86/common/acpi/rsdt.c index 6c918b3..9abdff0 100644 --- a/src/arch_x86/common/acpi/rsdt.c +++ b/arch/x86/common/acpi/rsdt.c @@ -3,7 +3,7 @@ #include "vmm.h" #include "stdio.h" #include "string.h" -#include "heap.h" +#include "memory.h" void rsdt_parse_table(struct acpisdthdr *table) @@ -36,7 +36,6 @@ rsdt_parse(struct rsdp1 *rsdp, struct acpisdthdr *rsdthdr) for(size_t i = 0; i < (rsdt->header.len - sizeof(struct acpisdthdr)) / sizeof(uint32_t); i++) { pmptr_t table_phys = (pmptr_t)rsdt->sdtptrs[i]; vmptr_t table_virt = (vmptr_t)malloc(PAGE_SIZE); - printk(KERNEL_INFO, "TAB %lX %lX\n", table_phys, table_virt); if(table_phys == 0) break; struct acpisdthdr *table = NULL; vmm_mappg(table_phys, table_virt, 0, 3); diff --git a/src/arch_x86/common/cpu/Makefile b/arch/x86/common/cpu/Makefile index fdd940e..fdd940e 100644 --- a/src/arch_x86/common/cpu/Makefile +++ b/arch/x86/common/cpu/Makefile diff --git a/src/arch_x86/common/cpu/main.c b/arch/x86/common/cpu/main.c index c235206..580eb73 100644 --- a/src/arch_x86/common/cpu/main.c +++ b/arch/x86/common/cpu/main.c @@ -1,5 +1,5 @@ #include "modit.h" -#include "x86.h" +#include "cpu.h" #include "stdio.h" #include <cpuid.h> diff --git a/src/arch_common/klibc/Makefile b/arch/x86/common/klibc/Makefile index 83aeed7..83aeed7 100644 --- a/src/arch_common/klibc/Makefile +++ b/arch/x86/common/klibc/Makefile diff --git a/src/arch_x86/common/klibc/inb.c b/arch/x86/common/klibc/inb.c index 47151bf..47151bf 100644 --- a/src/arch_x86/common/klibc/inb.c +++ b/arch/x86/common/klibc/inb.c diff --git a/src/arch_x86/common/klibc/io_wait.c b/arch/x86/common/klibc/io_wait.c index 2dd6648..2dd6648 100644 --- a/src/arch_x86/common/klibc/io_wait.c +++ b/arch/x86/common/klibc/io_wait.c diff --git a/src/arch_x86/common/klibc/memcmp.c b/arch/x86/common/klibc/memcmp.c index 0528f4c..0528f4c 100644 --- a/src/arch_x86/common/klibc/memcmp.c +++ b/arch/x86/common/klibc/memcmp.c diff --git a/src/arch_x86/common/klibc/memcpy.c b/arch/x86/common/klibc/memcpy.c index b16fdb7..b16fdb7 100644 --- a/src/arch_x86/common/klibc/memcpy.c +++ b/arch/x86/common/klibc/memcpy.c diff --git a/src/arch_x86/common/klibc/memset.c b/arch/x86/common/klibc/memset.c index bc9ac4a..bc9ac4a 100644 --- a/src/arch_x86/common/klibc/memset.c +++ b/arch/x86/common/klibc/memset.c diff --git a/src/arch_x86/common/klibc/outb.c b/arch/x86/common/klibc/outb.c index e97846f..e97846f 100644 --- a/src/arch_x86/common/klibc/outb.c +++ b/arch/x86/common/klibc/outb.c diff --git a/src/arch_x86/common/main.c b/arch/x86/common/main.c index f1b7249..f1b7249 100644 --- a/src/arch_x86/common/main.c +++ b/arch/x86/common/main.c diff --git a/src/arch_x86/common/panic/Makefile b/arch/x86/common/panic/Makefile index ce10c29..ce10c29 100644 --- a/src/arch_x86/common/panic/Makefile +++ b/arch/x86/common/panic/Makefile diff --git a/src/arch_x86/common/panic/main.c b/arch/x86/common/panic/main.c index b0f5ff9..0ed6b9b 100644 --- a/src/arch_x86/common/panic/main.c +++ b/arch/x86/common/panic/main.c @@ -46,18 +46,22 @@ panic(const char *fmt, ...) } NORETURN void -panic_except(struct intregs *regs, const char *exceptstr) +panic_except(struct intstate *state, const char *fmt, ...) { panic_start(); + + va_list ap; + va_start(ap, fmt); - printf("Unhandled kernel exception\n%s\n", exceptstr); + vprintk(KERNEL_FATAL, fmt, ap); + va_end(ap); #if defined(BITS_64) - if(regs != NULL) { - printf("ERR %i\n", regs->err); - printf("IP %l016X\n", regs->rip); - printf("RAX %l016X RBX %l016X RCX %l016X\nRDX %l016X", regs->rax, regs->rbx, regs->rcx, regs->rdx); - printf("RSI %l016X RDI %l016X\nRSP %l016X RBP %l016X", regs->rsi, regs->rdi, regs->sp, regs->rbp); + if(state != NULL) { + printf("ERR %i\n", state->base.err); + printf("IP %l016X\n", state->base.rip); + printf("RAX %l016X RBX %l016X RCX %l016X\nRDX %l016X", state->rax, state->rbx, state->rcx, state->rdx); + printf("RSI %l016X RDI %l016X\nRSP %l016X RBP %l016X", state->rsi, state->rdi, state->base.sp, state->rbp); } #else diff --git a/src/arch_x86/common/pic/Makefile b/arch/x86/common/pic/Makefile index dca05d7..dca05d7 100644 --- a/src/arch_x86/common/pic/Makefile +++ b/arch/x86/common/pic/Makefile diff --git a/src/arch_x86/common/pic/main.c b/arch/x86/common/pic/main.c index b1fa608..b1fa608 100644 --- a/src/arch_x86/common/pic/main.c +++ b/arch/x86/common/pic/main.c diff --git a/src/arch_x86/common/pit/Makefile b/arch/x86/common/pit/Makefile index 1ce793a..1ce793a 100644 --- a/src/arch_x86/common/pit/Makefile +++ b/arch/x86/common/pit/Makefile diff --git a/src/arch_x86/common/pit/main.c b/arch/x86/common/pit/main.c index c11d4e1..c11d4e1 100644 --- a/src/arch_x86/common/pit/main.c +++ b/arch/x86/common/pit/main.c diff --git a/src/arch_x86/common/stivale2/Makefile b/arch/x86/common/stivale2/Makefile index c74ca9b..c74ca9b 100644 --- a/src/arch_x86/common/stivale2/Makefile +++ b/arch/x86/common/stivale2/Makefile diff --git a/src/arch_x86/common/stivale2/main.c b/arch/x86/common/stivale2/main.c index 44cc01c..44cc01c 100644 --- a/src/arch_x86/common/stivale2/main.c +++ b/arch/x86/common/stivale2/main.c diff --git a/src/arch_x86/common/syscall/Makefile b/arch/x86/common/syscall/Makefile index 58ac95c..58ac95c 100644 --- a/src/arch_x86/common/syscall/Makefile +++ b/arch/x86/common/syscall/Makefile diff --git a/src/arch_x86/common/syscall/syscall.c b/arch/x86/common/syscall/syscall.c index 824b7ee..22c303d 100644 --- a/src/arch_x86/common/syscall/syscall.c +++ b/arch/x86/common/syscall/syscall.c @@ -4,7 +4,7 @@ #include "boot.h" #include "vmm.h" #include "pmm.h" -#include "heap.h" +#include "memory.h" #include "ipc.h" #define POINTER_BOUND_CHECK(ptr) \ diff --git a/src/arch_x86/common/timer/Makefile b/arch/x86/common/timer/Makefile index 1c0643b..1c0643b 100644 --- a/src/arch_x86/common/timer/Makefile +++ b/arch/x86/common/timer/Makefile diff --git a/src/arch_x86/common/timer/main.c b/arch/x86/common/timer/main.c index b166277..72f53cf 100644 --- a/src/arch_x86/common/timer/main.c +++ b/arch/x86/common/timer/main.c @@ -4,7 +4,7 @@ #include "stdio.h" #include "interrupt.h" #include "timer.h" -#include "heap.h" +#include "memory.h" #include <stdbool.h> #include <stddef.h> @@ -36,7 +36,7 @@ _interrupt_timer(struct intregs *regs) static void pit_prepare(uint16_t ms) { - int_set_vector(32, _interrupt_pit); + interrupt_vector_set(32, _interrupt_pit); pit_command(PIT_OM_RATE, PIT_AM_LOHI, PIT_SC_CHANNEL0); pit_write(PIT_SC_CHANNEL0, PIT_FREQ / 1193); pit_ms = ms; @@ -68,7 +68,7 @@ timer_constructor(void) apic_tpms = (0xFFFFFFFF - apic_read(APIC_REG_TIMER_CC)) / 10; printk(KERNEL_INFO, "Clocked timer at %lX clocks per ms\n", apic_tpms); - int_set_handler(32, _interrupt_timer); + interrupt_handler_set(32, _interrupt_timer); apic_write(APIC_REG_LVTTMR, 0x20); apic_write(APIC_REG_TIMER_DC, 0x3); diff --git a/include/arch_x86/common/x86.h b/arch/x86/cpu.h index 95dde22..95dde22 100644 --- a/include/arch_x86/common/x86.h +++ b/arch/x86/cpu.h diff --git a/include/arch_x86/common/gdt.h b/arch/x86/gdt.h index 2fcbc21..2fcbc21 100644 --- a/include/arch_x86/common/gdt.h +++ b/arch/x86/gdt.h diff --git a/include/arch_x86/common/ipc.h b/arch/x86/ipc.h index a319e59..a319e59 100644 --- a/include/arch_x86/common/ipc.h +++ b/arch/x86/ipc.h diff --git a/include/arch_x86/common/list.h b/arch/x86/list.h index 923010c..923010c 100644 --- a/include/arch_x86/common/list.h +++ b/arch/x86/list.h diff --git a/include/arch_x86/common/pic.h b/arch/x86/pic.h index 69110e5..69110e5 100644 --- a/include/arch_x86/common/pic.h +++ b/arch/x86/pic.h diff --git a/include/arch_x86/common/pit.h b/arch/x86/pit.h index c653c44..c653c44 100644 --- a/include/arch_x86/common/pit.h +++ b/arch/x86/pit.h diff --git a/include/arch_x86/common/syscall.h b/arch/x86/syscall.h index f0c42b6..f0c42b6 100644 --- a/include/arch_x86/common/syscall.h +++ b/arch/x86/syscall.h diff --git a/include/arch_x86/common/task.h b/arch/x86/task.h index 6af8036..6af8036 100644 --- a/include/arch_x86/common/task.h +++ b/arch/x86/task.h diff --git a/include/arch_x86/common/timer.h b/arch/x86/timer.h index eee91cf..eee91cf 100644 --- a/include/arch_x86/common/timer.h +++ b/arch/x86/timer.h diff --git a/include/arch_x86/common/user.h b/arch/x86/user.h index 6bf1d95..6bf1d95 100644 --- a/include/arch_x86/common/user.h +++ b/arch/x86/user.h diff --git a/include/arch_common/boot.h b/common/boot.h index 5c2da29..5c2da29 100644 --- a/include/arch_common/boot.h +++ b/common/boot.h diff --git a/src/arch_common/init/Makefile b/common/init/Makefile index 3c00f91..3c00f91 100644 --- a/src/arch_common/init/Makefile +++ b/common/init/Makefile diff --git a/src/arch_common/init/init.c b/common/init/init.c index 939312d..d19b56a 100644 --- a/src/arch_common/init/init.c +++ b/common/init/init.c @@ -5,7 +5,7 @@ #include "list.h" #include "stdio.h" -#include "heap.h" +#include "memory.h" #include "panic.h" #include "string.h" diff --git a/include/arch_common/initrd.h b/common/initrd.h index 06ffd50..06ffd50 100644 --- a/include/arch_common/initrd.h +++ b/common/initrd.h diff --git a/src/arch_common/initrd/Makefile b/common/initrd/Makefile index 0579637..0579637 100644 --- a/src/arch_common/initrd/Makefile +++ b/common/initrd/Makefile diff --git a/src/arch_common/initrd/initrd.c b/common/initrd/initrd.c index ab3a3ab..8bd5a97 100644 --- a/src/arch_common/initrd/initrd.c +++ b/common/initrd/initrd.c @@ -5,7 +5,7 @@ #include "stdio.h" #include "vmm.h" #include "pmm.h" -#include "heap.h" +#include "memory.h" #include "string.h" static pmptr_t strframe = 0; diff --git a/src/arch_common/initrd/tar.c b/common/initrd/tar.c index 9049cfa..bc9e711 100644 --- a/src/arch_common/initrd/tar.c +++ b/common/initrd/tar.c @@ -1,6 +1,6 @@ #include "initrd.h" #include "stdio.h" -#include "heap.h" +#include "memory.h" #include "stdlib.h" static size_t diff --git a/src/arch_x86/common/klibc/Makefile b/common/klibc/Makefile index 83aeed7..83aeed7 100644 --- a/src/arch_x86/common/klibc/Makefile +++ b/common/klibc/Makefile diff --git a/src/arch_common/klibc/fprintf.c b/common/klibc/fprintf.c index 75e0fc2..75e0fc2 100644 --- a/src/arch_common/klibc/fprintf.c +++ b/common/klibc/fprintf.c diff --git a/src/arch_common/klibc/isnum.c b/common/klibc/isnum.c index 0abf3d3..0abf3d3 100644 --- a/src/arch_common/klibc/isnum.c +++ b/common/klibc/isnum.c diff --git a/src/arch_common/klibc/itoa.c b/common/klibc/itoa.c index 565c6fc..565c6fc 100644 --- a/src/arch_common/klibc/itoa.c +++ b/common/klibc/itoa.c diff --git a/src/arch_common/klibc/main.c b/common/klibc/main.c index 6e5f894..6e5f894 100644 --- a/src/arch_common/klibc/main.c +++ b/common/klibc/main.c diff --git a/src/arch_common/klibc/printf.c b/common/klibc/printf.c index 5fd2044..5fd2044 100644 --- a/src/arch_common/klibc/printf.c +++ b/common/klibc/printf.c diff --git a/src/arch_common/klibc/printk.c b/common/klibc/printk.c index ef26f92..ef26f92 100644 --- a/src/arch_common/klibc/printk.c +++ b/common/klibc/printk.c diff --git a/src/arch_common/klibc/sllist.c b/common/klibc/sllist.c index b54c443..b54c443 100644 --- a/src/arch_common/klibc/sllist.c +++ b/common/klibc/sllist.c diff --git a/src/arch_common/klibc/sprintf.c b/common/klibc/sprintf.c index a5cc108..a5cc108 100644 --- a/src/arch_common/klibc/sprintf.c +++ b/common/klibc/sprintf.c diff --git a/src/arch_common/klibc/strcmp.c b/common/klibc/strcmp.c index 807269a..807269a 100644 --- a/src/arch_common/klibc/strcmp.c +++ b/common/klibc/strcmp.c diff --git a/src/arch_common/klibc/strcpy.c b/common/klibc/strcpy.c index 056491b..056491b 100644 --- a/src/arch_common/klibc/strcpy.c +++ b/common/klibc/strcpy.c diff --git a/src/arch_common/klibc/strlen.c b/common/klibc/strlen.c index 48fbbc5..48fbbc5 100644 --- a/src/arch_common/klibc/strlen.c +++ b/common/klibc/strlen.c diff --git a/src/arch_common/klibc/strtol.c b/common/klibc/strtol.c index 538ca60..538ca60 100644 --- a/src/arch_common/klibc/strtol.c +++ b/common/klibc/strtol.c diff --git a/src/arch_common/klibc/tolower.c b/common/klibc/tolower.c index 8b8ac0e..8b8ac0e 100644 --- a/src/arch_common/klibc/tolower.c +++ b/common/klibc/tolower.c diff --git a/src/arch_common/klibc/toupper.c b/common/klibc/toupper.c index 595e854..595e854 100644 --- a/src/arch_common/klibc/toupper.c +++ b/common/klibc/toupper.c diff --git a/src/arch_common/klibc/vsnprintf.c b/common/klibc/vsnprintf.c index abc6338..abc6338 100644 --- a/src/arch_common/klibc/vsnprintf.c +++ b/common/klibc/vsnprintf.c diff --git a/include/arch_common/heap.h b/common/memory.h index 6fc28af..6fc28af 100644 --- a/include/arch_common/heap.h +++ b/common/memory.h diff --git a/include/arch_common/modit.h b/common/modit.h index a573a42..62eeb45 100644 --- a/include/arch_common/modit.h +++ b/common/modit.h @@ -21,6 +21,8 @@ #ifndef KERNEL_MODIT_H #define KERNEL_MODIT_H +#include <stddef.h> + typedef char symbol_t[]; #define NORETURN __attribute__((noreturn)) @@ -31,4 +33,9 @@ typedef char symbol_t[]; #define THREAD +#define ASSERT(condition) \ + if(!condition) panic( ##condition ) + +#define VERIFY(ptr) ASSERT(ptr != NULL) + #endif diff --git a/include/arch_common/mutex.h b/common/mutex.h index 2f3426e..2f3426e 100644 --- a/include/arch_common/mutex.h +++ b/common/mutex.h diff --git a/include/arch_common/panic.h b/common/panic.h index dbebd62..ededf5c 100644 --- a/include/arch_common/panic.h +++ b/common/panic.h @@ -22,13 +22,12 @@ #define MODIT_PANIC_H 1 #include "modit.h" -#include "registers.h" NORETURN void panic(const char *fmt, ...); #if defined(ARCH_x86) -#include "idt.h" -NORETURN void panic_except(struct intregs *regs, const char *exceptstr); +#include "interrupt.h" +NORETURN void panic_except(struct intstate *state, const char *fmt, ...); #endif #endif diff --git a/include/arch_common/pmm.h b/common/pmm.h index 9efeaf2..9efeaf2 100644 --- a/include/arch_common/pmm.h +++ b/common/pmm.h diff --git a/include/arch_common/serialtxt.h b/common/serialtxt.h index 686e0c5..686e0c5 100644 --- a/include/arch_common/serialtxt.h +++ b/common/serialtxt.h diff --git a/src/arch_common/serialtxt/Makefile b/common/serialtxt/Makefile index 84ec13a..84ec13a 100644 --- a/src/arch_common/serialtxt/Makefile +++ b/common/serialtxt/Makefile diff --git a/src/arch_common/serialtxt/main.c b/common/serialtxt/main.c index ee79ff1..ee79ff1 100644 --- a/src/arch_common/serialtxt/main.c +++ b/common/serialtxt/main.c diff --git a/include/arch_common/stdio.h b/common/stdio.h index 91912cc..91912cc 100644 --- a/include/arch_common/stdio.h +++ b/common/stdio.h diff --git a/include/arch_common/stivale2.h b/common/stivale2.h index 9a2a37c..9a2a37c 100644 --- a/include/arch_common/stivale2.h +++ b/common/stivale2.h diff --git a/include/arch_common/string.h b/common/string.h index a881286..a881286 100644 --- a/include/arch_common/string.h +++ b/common/string.h diff --git a/include/arch_common/vgatxt.h b/common/vgatxt.h index e795a52..e795a52 100644 --- a/include/arch_common/vgatxt.h +++ b/common/vgatxt.h diff --git a/src/arch_common/vgatxt/Makefile b/common/vgatxt/Makefile index 0067393..0067393 100644 --- a/src/arch_common/vgatxt/Makefile +++ b/common/vgatxt/Makefile diff --git a/src/arch_common/vgatxt/main.c b/common/vgatxt/main.c index 39d2f9a..39d2f9a 100644 --- a/src/arch_common/vgatxt/main.c +++ b/common/vgatxt/main.c diff --git a/include/arch_common/vmm.h b/common/vmm.h index e4bd9d0..e4bd9d0 100644 --- a/include/arch_common/vmm.h +++ b/common/vmm.h diff --git a/include/arch_x86/64/idt.h b/include/arch_x86/64/idt.h deleted file mode 100644 index 5279d9a..0000000 --- a/include/arch_x86/64/idt.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * include/arch_x86/64/idt.h - * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ -#ifndef MODIT_KERNEL_IDT_H -#define MODIT_KERNEL_IDT_H 1 - -#include <stdint.h> - -#define IDTD_TYPE_INTERRUPT 0b1110 -#define IDTD_TYPE_TRAP 0b1111 - -#define IDTD_DPL_KERNEL 0b00 -#define IDTD_DPL_UNUSED1 0b01 -#define IDTD_DPL_UNUSED2 0b10 -#define IDTD_DPL_USER 0b11 - -struct idtd -{ - uint16_t offset_0_16; - uint16_t ssel; - union { - struct { - uint8_t ist : 2; - uint8_t zero : 6; - uint8_t type : 4; - uint8_t zero2 : 1; - uint8_t dpl : 2; - uint8_t present : 1; - }; - uint16_t flags; - }; - uint16_t offset_16_32; - uint32_t offset_32_64; - uint32_t reserved; -} __attribute__((packed)); - -struct intframe -{ - uint64_t err; - uint64_t rip, cs, rflag, sp, ss; -}; - -struct intregs -{ - uint64_t r15, r14, r13, r12, r11, r10, r9, r8; - uint64_t rbp, rdi, rsi; - uint64_t rbx, rdx, rcx, rax; - uint64_t num, err; - uint64_t rip, cs, rflag, sp, ss; -}; - -void int_setist(int i, uint8_t s); - -#endif diff --git a/include/arch_x86/64/registers.h b/include/arch_x86/64/registers.h deleted file mode 100644 index e9fe81d..0000000 --- a/include/arch_x86/64/registers.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * include/arch_x86/64/registers.h - * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ -#ifndef MODIT_REGISTERS_H -#define MODIT_REGISTERS_H 1 - -#include <stdint.h> - -struct registers -{ - uint64_t r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15; -}; - -struct cpu_state -{ - struct registers regs; - uint64_t ip; - uint64_t flags; - uint64_t s1, s2, s3, s4, s5, s6; -}; - -#endif diff --git a/include/arch_x86/common/interrupt.h b/include/arch_x86/common/interrupt.h deleted file mode 100644 index 8295e84..0000000 --- a/include/arch_x86/common/interrupt.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * include/arch_x86/common/interrupt.h - * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ -#ifndef MODIT_KERNEL_INTERRUPT_H -#define MODIT_KERNEL_INTERRUPT_H 1 - -#include "idt.h" - -typedef void (*int_vector_t)(struct intframe *); -typedef void (*int_handler_t)(struct intregs *); - -void *int_set_vector(int i, int_vector_t vector); -void *int_set_handler(int i, int_handler_t handler); - -#endif |