diff options
author | Anton Kling <anton@kling.gg> | 2023-10-27 19:39:54 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-30 21:49:48 +0100 |
commit | 715274d3a77c58510b97c3f87cd604dde9de7a4f (patch) | |
tree | f3f71248419f3395badc1b3bd9f64bd63dc3ae8c | |
parent | 8eede5fd642db2c56a1f5185973815fbd2b0afa4 (diff) |
Kernel: Move min, max functions to their own file
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | includes/math.h | 2 | ||||
-rw-r--r-- | kmalloc.c | 5 | ||||
-rw-r--r-- | math.c | 3 |
4 files changed, 8 insertions, 6 deletions
@@ -1,6 +1,6 @@ CC="./sysroot/bin/i686-sb-gcc" AS="./sysroot/bin/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 cpu/int_syscall.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 scalls/ppoll.o scalls/ftruncate.o kubsan.o scalls/mmap.o drivers/serial.o scalls/accept.o scalls/bind.o scalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o scalls/shm.o elf.o ksbrk.o sched/scheduler.o scalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o scalls/msleep.o scalls/uptime.o scalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o scalls/recvfrom.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 cpu/int_syscall.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 scalls/ppoll.o scalls/ftruncate.o kubsan.o scalls/mmap.o drivers/serial.o scalls/accept.o scalls/bind.o scalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o scalls/shm.o elf.o ksbrk.o sched/scheduler.o scalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o scalls/msleep.o scalls/uptime.o scalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o scalls/recvfrom.o math.o CFLAGS = -O2 -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. INCLUDE=-I./includes/ -I./libc/include/ @@ -20,7 +20,7 @@ debug: gdb -x .gdbinit nk: - qemu-system-i386 -d int -no-reboot -no-shutdown -serial file:./serial.log -hda ext2.img -m 1G -cdrom myos.iso -s + qemu-system-i386 -d int -netdev user,id=n0,hostfwd=udp:127.0.0.1:6001-:6000 -device rtl8139,netdev=n0 -no-reboot -no-shutdown -serial file:./serial.log -hda ext2.img -m 1G -cdrom myos.iso -s run: qemu-system-i386 -enable-kvm -netdev user,id=n0,hostfwd=udp:127.0.0.1:6001-:6000 -device rtl8139,netdev=n0 -d int -no-reboot -no-shutdown -chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0 -hda ext2.img -m 1G -cdrom myos.iso -s diff --git a/includes/math.h b/includes/math.h new file mode 100644 index 0000000..19fc595 --- /dev/null +++ b/includes/math.h @@ -0,0 +1,2 @@ +int min(int a, int b); +int max(int a, int b); @@ -1,6 +1,7 @@ #include <assert.h> #include <kmalloc.h> #include <ksbrk.h> +#include <math.h> #define NEW_ALLOC_SIZE 0x30000 #define IS_FREE (1 << 0) @@ -13,10 +14,6 @@ typedef struct MallocHeader { struct MallocHeader *n; } MallocHeader; -size_t max(size_t a, size_t b) { return (a > b) ? a : b; } - -size_t min(size_t a, size_t b) { return (a < b) ? a : b; } - uint64_t delta_page(uint64_t a) { return 0x1000 - (a % 0x1000); } MallocHeader *head = NULL; @@ -0,0 +1,3 @@ +#include <math.h> +int min(int a, int b) { return ((a) > (b) ? b : a); } +int max(int a, int b) { return (a > b) ? a : b; } |