From a03bb42790cd7374606b1760de9443890314b020 Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:26:14 +0200 Subject: [PATCH] Switch: to freestanding stdint and stdbool headers --- makefile | 2 +- src/drivers/ata.c | 2 +- src/drivers/ata.h | 2 ++ src/drivers/framebuffer.c | 2 +- src/drivers/framebuffer.h | 3 ++- src/kernel/io.h | 2 +- src/kernel/kheap.c | 2 +- src/kernel/kheap.h | 2 +- src/kernel/kmain.c | 2 +- src/kernel/paging.c | 2 +- src/kernel/paging.h | 2 +- src/kernel/shell.c | 2 +- src/kernel/system.c | 2 +- src/kernel/system.h | 3 ++- src/libc/crypto.c | 2 +- src/libc/crypto.h | 2 +- src/libc/ctype.c | 3 ++- src/libc/ctype.h | 2 +- src/libc/stdint.h | 24 ------------------------ src/libc/stdio.c | 2 +- src/libc/stdio.h | 3 ++- src/libc/string.c | 3 ++- src/programs/ciphers.c | 2 +- src/programs/conway.c | 2 +- src/programs/math.c | 2 +- src/programs/primes.c | 2 +- 26 files changed, 31 insertions(+), 48 deletions(-) delete mode 100644 src/libc/stdint.h diff --git a/makefile b/makefile index 918e65e..c4b4871 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc -CFLAGS = -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/ +CFLAGS = -ffreestanding -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/ LDFLAGS = -T link.ld -melf_i386 AS = nasm ASFLAGS = -f elf diff --git a/src/drivers/ata.c b/src/drivers/ata.c index 4582d6a..8df5997 100644 --- a/src/drivers/ata.c +++ b/src/drivers/ata.c @@ -1,4 +1,4 @@ -#include "../libc/stdint.h" +#include #include "../kernel/io.h" #include "../libc/stdio.h" diff --git a/src/drivers/ata.h b/src/drivers/ata.h index 550645c..08c1f7d 100644 --- a/src/drivers/ata.h +++ b/src/drivers/ata.h @@ -1,6 +1,8 @@ #ifndef ATA_H #define ATA_H +#include + void ata_read_sector(uint32_t lba, uint8_t* buffer); void test_read_sector(); diff --git a/src/drivers/framebuffer.c b/src/drivers/framebuffer.c index 528b0dd..bc684f7 100644 --- a/src/drivers/framebuffer.c +++ b/src/drivers/framebuffer.c @@ -1,4 +1,4 @@ -#include "../libc/stdint.h" +#include #include "framebuffer.h" #include "serial.h" #include "../kernel/system.h" diff --git a/src/drivers/framebuffer.h b/src/drivers/framebuffer.h index 5a2a8ff..7ec9029 100644 --- a/src/drivers/framebuffer.h +++ b/src/drivers/framebuffer.h @@ -1,6 +1,8 @@ #ifndef FRAMEBUFFER_H #define FRAMEBUFFER_H +#include + #define PSF1_FONT_MAGIC 0x0436 typedef struct { @@ -9,7 +11,6 @@ typedef struct { uint8_t characterSize; // PSF character size. } PSF1_Header; - #define PSF_FONT_MAGIC 0x864ab572 typedef struct { diff --git a/src/kernel/io.h b/src/kernel/io.h index 6480303..4a5553f 100644 --- a/src/kernel/io.h +++ b/src/kernel/io.h @@ -1,7 +1,7 @@ #ifndef INCLUDE_IO_H #define INCLUDE_IO_H -#include "../libc/stdint.h" +#include void outb(unsigned short port, unsigned char data); unsigned char inb(unsigned short port); diff --git a/src/kernel/kheap.c b/src/kernel/kheap.c index 439a081..3076a97 100644 --- a/src/kernel/kheap.c +++ b/src/kernel/kheap.c @@ -1,6 +1,6 @@ #include "kheap.h" -#include "../libc/stdint.h" +#include extern uint32_t end; uint32_t placement_address = (uint32_t)&end; diff --git a/src/kernel/kheap.h b/src/kernel/kheap.h index 7e16d91..0e0e130 100644 --- a/src/kernel/kheap.h +++ b/src/kernel/kheap.h @@ -1,7 +1,7 @@ #ifndef KHEAP_H #define KHEAP_H -#include "../libc/stdint.h" +#include uint32_t kmalloc_a(uint32_t sz); uint32_t kmalloc_p(uint32_t sz, uint32_t *phys); diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index 5f1a11d..135eef7 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -5,7 +5,7 @@ #include "system.h" #include "paging.h" #include "../drivers/ata.h" -#include "../libc/stdint.h" +#include #include "../drivers/framebuffer.h" typedef struct { diff --git a/src/kernel/paging.c b/src/kernel/paging.c index c49efa4..c4fad18 100644 --- a/src/kernel/paging.c +++ b/src/kernel/paging.c @@ -1,4 +1,4 @@ -#include "../libc/stdint.h" +#include #include "paging.h" #include "../libc/stdio.h" #include "system.h" diff --git a/src/kernel/paging.h b/src/kernel/paging.h index ee485ad..2b6474d 100644 --- a/src/kernel/paging.h +++ b/src/kernel/paging.h @@ -2,7 +2,7 @@ #define PAGING_H #include "system.h" -#include "../libc/stdint.h" +#include typedef struct { uint32_t present : 1; diff --git a/src/kernel/shell.c b/src/kernel/shell.c index fe3973e..46f6fc4 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -2,7 +2,7 @@ #include "../libc/stdio.h" #include "../libc/string.h" #include "../programs/programs.h" -#include "../libc/stdint.h" +#include #define BUFFER_SIZE 256 #define MAX_COMMANDS 16 diff --git a/src/kernel/system.c b/src/kernel/system.c index 36594da..0b02871 100644 --- a/src/kernel/system.c +++ b/src/kernel/system.c @@ -1,5 +1,5 @@ #include "system.h" -#include "../libc/stdint.h" +#include void *memset(void *dest, char val, size_t count) { diff --git a/src/kernel/system.h b/src/kernel/system.h index 874cf19..b9b650c 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -1,9 +1,10 @@ #ifndef SYSTEM_H #define SYSTEM_H -#include "../libc/stdint.h" +#include typedef int size_t; +#define NULL ((void*)0) void *memset(void *dest, char val, size_t count); void *memmove(void* dest, const void* src, size_t n); diff --git a/src/libc/crypto.c b/src/libc/crypto.c index b9c261e..c0ba0b3 100644 --- a/src/libc/crypto.c +++ b/src/libc/crypto.c @@ -1,5 +1,5 @@ #include "crypto.h" -#include "../libc/stdint.h" +#include int lcg(int seed) { diff --git a/src/libc/crypto.h b/src/libc/crypto.h index 04a54b1..c5aafbd 100644 --- a/src/libc/crypto.h +++ b/src/libc/crypto.h @@ -3,7 +3,7 @@ #define RAND_MAX 1024 -#include "../libc/stdint.h" +#include int lcg(int seed); int randint(int seed); diff --git a/src/libc/ctype.c b/src/libc/ctype.c index 49e4545..862028a 100644 --- a/src/libc/ctype.c +++ b/src/libc/ctype.c @@ -1,5 +1,6 @@ -#include "stdint.h" +#include +#include bool isdigit(char c) { diff --git a/src/libc/ctype.h b/src/libc/ctype.h index 10ace98..a93d394 100644 --- a/src/libc/ctype.h +++ b/src/libc/ctype.h @@ -1,7 +1,7 @@ #ifndef CTYPE_H #define CTYPE_H -#include "stdint.h" +#include bool isdigit(char c); bool isspace(char c); diff --git a/src/libc/stdint.h b/src/libc/stdint.h deleted file mode 100644 index fffbd7d..0000000 --- a/src/libc/stdint.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef INCLUDE_STDINT_H -#define INCLUDE_STDINT_H - -typedef signed char int8_t; -typedef unsigned char uint8_t; - -typedef signed short int16_t; -typedef unsigned short uint16_t; - -typedef signed long int int32_t; -typedef unsigned long int uint32_t; - -typedef signed long long int int64_t; -typedef unsigned long long int uint64_t; - -typedef uint8_t bool; -#define true 1 -#define false 0 - -#define NULL ((void*)0) - -typedef unsigned int uintptr_t; - -#endif diff --git a/src/libc/stdio.c b/src/libc/stdio.c index 3ea1076..7c06d03 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -1,7 +1,7 @@ #include "../kernel/io.h" #include "stdio.h" #include "string.h" -#include "stdint.h" +#include #include "../kernel/system.h" #include "../drivers/framebuffer.h" #include "../drivers/serial.h" diff --git a/src/libc/stdio.h b/src/libc/stdio.h index 731eb87..a4490f0 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -1,7 +1,8 @@ #ifndef INCLUDE_STDIO_H #define INCLUDE_STDIO_H -#include "stdint.h" +#include +#include #define FB_GREEN 2 #define FB_DARK_GREY 8 diff --git a/src/libc/string.c b/src/libc/string.c index 5c79755..6f5bd54 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -1,4 +1,5 @@ -#include "stdint.h" +#include +#include "../kernel/system.h" int strlen(const char* str) { diff --git a/src/programs/ciphers.c b/src/programs/ciphers.c index 9193989..a4eeb14 100644 --- a/src/programs/ciphers.c +++ b/src/programs/ciphers.c @@ -33,7 +33,7 @@ void program_rot13() } #include "../libc/string.h" -#include "../libc/stdint.h" +#include const char* morse_alphabet[] = { ".-", // A diff --git a/src/programs/conway.c b/src/programs/conway.c index 93de491..a1e63a2 100644 --- a/src/programs/conway.c +++ b/src/programs/conway.c @@ -2,7 +2,7 @@ #include "../libc/stdio.h" #include "../kernel/system.h" #include "../libc/crypto.h" -#include "../libc/stdint.h" +#include #include "../drivers/serial.h" #include "../libc/string.h" diff --git a/src/programs/math.c b/src/programs/math.c index 9f96c9e..e91362c 100644 --- a/src/programs/math.c +++ b/src/programs/math.c @@ -1,6 +1,6 @@ // Math expression lexer and parser -#include "../libc/stdint.h" +#include #include "../kernel/system.h" #include "../libc/stdio.h" #include "../libc/ctype.h" diff --git a/src/programs/primes.c b/src/programs/primes.c index 10a179f..e6f42f8 100644 --- a/src/programs/primes.c +++ b/src/programs/primes.c @@ -1,4 +1,4 @@ -#include "../libc/stdint.h" +#include #include "../libc/stdio.h" #include "../kernel/system.h"