diff --git a/.clangd b/.clangd index 4ad4a3d..7427527 100644 --- a/.clangd +++ b/.clangd @@ -5,6 +5,11 @@ CompileFlags: - "-ffreestanding" - "-fno-builtin" - "-fno-common" + - "-Wall" + - "-Wextra" + - "-Wshadow" - "-fno-strict-aliasing" + - "-nostdinc" - "-nostdlib" - - "-Istdlib" + - "-I" + - "/home/oliste/repos/nub-os/src/stdlib" diff --git a/makefile b/makefile index b6183f1..0a8b3ca 100644 --- a/makefile +++ b/makefile @@ -2,13 +2,12 @@ CC = x86_64-elf-gcc LD = x86_64-elf-ld AS = nasm -TARGET_PATH = src/arch/x86_64 -CFLAGS = -m64 -ffreestanding -nostdlib -fno-builtin -Wall -Wextra -Wshadow -std=c11 -I src/stdlib -g +CFLAGS = -m64 -ffreestanding -nostdinc -nostdlib -fno-builtin -Wall -Wextra -Wshadow -std=c11 -I src/stdlib -g LDFLAGS = -g ASFLAGS = -f elf64 -g -F dwarf -SRC_C := $(shell find src -name '*.c' ) -SRC_ASM := $(shell find src -name '*.asm' ) +SRC_C := $(shell find src -name '*.c') +SRC_ASM := $(shell find src -name '*.asm') OBJS := $(patsubst src/%.c, .build/%.o, $(SRC_C)) $(patsubst src/%.asm, .build/%.o, $(SRC_ASM)) diff --git a/src/arch/mmap.h b/src/arch/mmap.h index 3278d65..93f6958 100644 --- a/src/arch/mmap.h +++ b/src/arch/mmap.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "stdint.h" typedef struct { diff --git a/src/arch/x86_64/interrupts.c b/src/arch/x86_64/interrupts.c index f699efc..6d28858 100644 --- a/src/arch/x86_64/interrupts.c +++ b/src/arch/x86_64/interrupts.c @@ -1,7 +1,7 @@ #include "interrupts.h" #include "../arch.h" +#include "stdio.h" #include "util.h" -#include #define PIC1_COMMAND 0x20 #define PIC1_DATA 0x21 diff --git a/src/arch/x86_64/interrupts.h b/src/arch/x86_64/interrupts.h index 5cfbd2d..f5886d9 100644 --- a/src/arch/x86_64/interrupts.h +++ b/src/arch/x86_64/interrupts.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include "stdbool.h" +#include "stdint.h" typedef struct { diff --git a/src/arch/x86_64/keyboard.c b/src/arch/x86_64/keyboard.c index 8bd5d88..bc17da1 100644 --- a/src/arch/x86_64/keyboard.c +++ b/src/arch/x86_64/keyboard.c @@ -1,7 +1,7 @@ // #include "keyboard.h" // #include "interrupts.h" // #include "util.h" -// #include +// #include "stddef.h" // #define SCANCODE_LEFT_SHIFT 42 // #define SCANCODE_RIGHT_SHIFT 54 diff --git a/src/arch/x86_64/keyboard.h b/src/arch/x86_64/keyboard.h index eac0d16..dc7d058 100644 --- a/src/arch/x86_64/keyboard.h +++ b/src/arch/x86_64/keyboard.h @@ -1,7 +1,7 @@ // #pragma once -// #include -// #include +// #include "stdbool.h" +// #include "stdint.h" // typedef struct // { diff --git a/src/arch/x86_64/mmap.c b/src/arch/x86_64/mmap.c index f2e701d..5c7885d 100644 --- a/src/arch/x86_64/mmap.c +++ b/src/arch/x86_64/mmap.c @@ -1,7 +1,7 @@ #include "mmap.h" #include "../mmap.h" -#include -#include +#include "stddef.h" +#include "stdio.h" #define USABLE_REGION_SIZE 32 diff --git a/src/arch/x86_64/util.h b/src/arch/x86_64/util.h index a843e64..6cf15fb 100644 --- a/src/arch/x86_64/util.h +++ b/src/arch/x86_64/util.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "stdint.h" enum { diff --git a/src/arch/x86_64/vga.c b/src/arch/x86_64/vga.c index 580276c..3f00227 100644 --- a/src/arch/x86_64/vga.c +++ b/src/arch/x86_64/vga.c @@ -1,5 +1,5 @@ #include "vga.h" -#include +#include "stddef.h" #define ROWS 25 #define COLUMNS 80 diff --git a/src/arch/x86_64/vga.h b/src/arch/x86_64/vga.h index da55117..918c6c3 100644 --- a/src/arch/x86_64/vga.h +++ b/src/arch/x86_64/vga.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "stdint.h" #define VGA_BLACK 0 #define VGA_BLUE 1 diff --git a/src/arch/x86_64/x86_64.c b/src/arch/x86_64/x86_64.c index b2d381c..ead4bdd 100644 --- a/src/arch/x86_64/x86_64.c +++ b/src/arch/x86_64/x86_64.c @@ -3,10 +3,10 @@ #include "interrupts.h" #include "mmap.h" #include "multiboot.h" +#include "stddef.h" +#include "stdio.h" #include "util.h" #include "vga.h" -#include -#include void entry(multiboot_info_t* mbd) { diff --git a/src/kernel.c b/src/kernel.c index d88e7fd..1dd0faa 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,6 +1,6 @@ #include "kernel.h" #include "pmm.h" -#include +#include "stdio.h" void kmain() { diff --git a/src/pmm.c b/src/pmm.c index b3856e1..7bd4572 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -1,9 +1,8 @@ #include "pmm.h" #include "arch/mmap.h" -#include -#include -#include -#include +#include "mem.h" +#include "stddef.h" +#include "stdio.h" #define BITMAP_SIZE 32768 // Supports up to 1GB of RAM #define USABLE_REGION_SIZE 32 diff --git a/src/pmm.h b/src/pmm.h index 421f758..49d133e 100644 --- a/src/pmm.h +++ b/src/pmm.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "stdint.h" #define PAGE_SIZE 4096 diff --git a/src/stdlib/mem.c b/src/stdlib/mem.c index a440849..4151265 100644 --- a/src/stdlib/mem.c +++ b/src/stdlib/mem.c @@ -1,5 +1,5 @@ #include "mem.h" -#include +#include "stdint.h" void memset(void* destination, uint8_t value, size_t length) { diff --git a/src/stdlib/mem.h b/src/stdlib/mem.h index 9f3ddc4..c6ecbb1 100644 --- a/src/stdlib/mem.h +++ b/src/stdlib/mem.h @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include "stddef.h" +#include "stdint.h" void memset(void* destination, uint8_t value, size_t length); \ No newline at end of file diff --git a/src/stdlib/stdarg.h b/src/stdlib/stdarg.h new file mode 100644 index 0000000..536ccb1 --- /dev/null +++ b/src/stdlib/stdarg.h @@ -0,0 +1,8 @@ +#pragma once + +typedef __builtin_va_list va_list; + +#define va_start(ap, last) __builtin_va_start(ap, last) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) +#define va_copy(dest, src) __builtin_va_copy(dest, src) diff --git a/src/stdlib/stdbool.h b/src/stdlib/stdbool.h new file mode 100644 index 0000000..20c1842 --- /dev/null +++ b/src/stdlib/stdbool.h @@ -0,0 +1,7 @@ +#pragma once + +#define bool _Bool +#define true 1 +#define false 0 + +#define __bool_true_false_are_defined 1 diff --git a/src/stdlib/stddef.h b/src/stdlib/stddef.h new file mode 100644 index 0000000..2b35097 --- /dev/null +++ b/src/stdlib/stddef.h @@ -0,0 +1,12 @@ +#pragma once + +#ifndef NULL +#define NULL ((void*)0) +#endif + +typedef unsigned long size_t; +typedef long ptrdiff_t; +typedef long intptr_t; +typedef unsigned long uintptr_t; + +#define offsetof(type, member) __builtin_offsetof(type, member) diff --git a/src/stdlib/stdint.h b/src/stdlib/stdint.h new file mode 100644 index 0000000..96ad566 --- /dev/null +++ b/src/stdlib/stdint.h @@ -0,0 +1,50 @@ +#pragma once + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; + +typedef uint8_t u8; +typedef int8_t i8; +typedef uint16_t u16; +typedef int16_t i16; +typedef uint32_t u32; +typedef int32_t i32; +typedef uint64_t u64; +typedef int64_t i64; + +#define INT8_MIN (-128) +#define INT8_MAX 127 +#define UINT8_MAX 0xff + +#define INT16_MIN (-32768) +#define INT16_MAX 32767 +#define UINT16_MAX 0xffff + +#define INT32_MIN (-2147483647 - 1) +#define INT32_MAX 2147483647 +#define UINT32_MAX 0xffffffffU + +#define INT64_MIN (-9223372036854775807LL - 1) +#define INT64_MAX 9223372036854775807LL +#define UINT64_MAX 0xffffffffffffffffULL + +#define INT8_C(x) x +#define UINT8_C(x) x##U + +#define INT16_C(x) x +#define UINT16_C(x) x##U + +#define INT32_C(x) x +#define UINT32_C(x) x##U + +#define INT64_C(x) x##LL +#define UINT64_C(x) x##ULL + +#define INTMAX_C(x) x##LL +#define UINTMAX_C(x) x##ULL diff --git a/src/stdlib/stdio.c b/src/stdlib/stdio.c index f23cd1d..8fdbfb4 100644 --- a/src/stdlib/stdio.c +++ b/src/stdlib/stdio.c @@ -1,9 +1,9 @@ #include "stdio.h" #include "../arch/arch.h" +#include "stdarg.h" +#include "stdbool.h" +#include "stddef.h" #include "string.h" -#include -#include -#include void printf(const char* fmt, ...) {