diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index c761e9b..275d1fa 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,10 +1,10 @@ -#include <_stdio.h> #include #include +#include MemoryBlock *firstBlock; -void initMemoryAllocation(uint32_t kernelEnd) { +void initMemoryAllocation(uintptr_t kernelEnd) { firstBlock = (MemoryBlock *)kernelEnd; firstBlock->next = NULL; firstBlock->last = NULL; @@ -13,9 +13,10 @@ } #define getOffset() \ - (alignment ? alignmentBit - ((uint32_t)(current + 1) & (alignmentMask)) : 0) + (alignment ? alignmentBit - ((uintptr_t)(current + 1) & (alignmentMask)) \ + : 0) -void memmove(uint8_t *to, uint8_t *from, uint32_t count) { +void memmove(uint8_t *to, uint8_t *from, uintptr_t count) { if (from > to) { for (; count > 0; count--) { *(to++) = *(from++); @@ -27,11 +28,11 @@ } } -void *mallocTaskAligned(uint32_t size, uint8_t alignment, Task *task) { +void *mallocTaskAligned(uintptr_t size, uint8_t alignment, Task *task) { MemoryBlock *current = firstBlock; uint32_t alignmentBit = 1 << alignment; uint32_t alignmentMask = alignmentBit - 1; - uint32_t additionalOffset = getOffset(); + uintptr_t additionalOffset = getOffset(); while (current->task || current->size < size + additionalOffset) { current = current->next; additionalOffset = getOffset(); @@ -65,15 +66,15 @@ return (void *)(current + 1); } -void *mallocTask(uint32_t size, Task *task) { +void *mallocTask(uintptr_t size, Task *task) { return mallocTaskAligned(size, 0, task); } -void *malloc(uint32_t size) { +void *malloc(uintptr_t size) { return mallocTaskAligned(size, 0, getCurrentTask()); } -void *mallocAligned(uint32_t size, uint8_t alignment) { +void *mallocAligned(uintptr_t size, uint8_t alignment) { return mallocTaskAligned(size, alignment, getCurrentTask()); } diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index c761e9b..275d1fa 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,10 +1,10 @@ -#include <_stdio.h> #include #include +#include MemoryBlock *firstBlock; -void initMemoryAllocation(uint32_t kernelEnd) { +void initMemoryAllocation(uintptr_t kernelEnd) { firstBlock = (MemoryBlock *)kernelEnd; firstBlock->next = NULL; firstBlock->last = NULL; @@ -13,9 +13,10 @@ } #define getOffset() \ - (alignment ? alignmentBit - ((uint32_t)(current + 1) & (alignmentMask)) : 0) + (alignment ? alignmentBit - ((uintptr_t)(current + 1) & (alignmentMask)) \ + : 0) -void memmove(uint8_t *to, uint8_t *from, uint32_t count) { +void memmove(uint8_t *to, uint8_t *from, uintptr_t count) { if (from > to) { for (; count > 0; count--) { *(to++) = *(from++); @@ -27,11 +28,11 @@ } } -void *mallocTaskAligned(uint32_t size, uint8_t alignment, Task *task) { +void *mallocTaskAligned(uintptr_t size, uint8_t alignment, Task *task) { MemoryBlock *current = firstBlock; uint32_t alignmentBit = 1 << alignment; uint32_t alignmentMask = alignmentBit - 1; - uint32_t additionalOffset = getOffset(); + uintptr_t additionalOffset = getOffset(); while (current->task || current->size < size + additionalOffset) { current = current->next; additionalOffset = getOffset(); @@ -65,15 +66,15 @@ return (void *)(current + 1); } -void *mallocTask(uint32_t size, Task *task) { +void *mallocTask(uintptr_t size, Task *task) { return mallocTaskAligned(size, 0, task); } -void *malloc(uint32_t size) { +void *malloc(uintptr_t size) { return mallocTaskAligned(size, 0, getCurrentTask()); } -void *mallocAligned(uint32_t size, uint8_t alignment) { +void *mallocAligned(uintptr_t size, uint8_t alignment) { return mallocTaskAligned(size, alignment, getCurrentTask()); } diff --git a/src/kernel/memory/fileSystem.c b/src/kernel/memory/fileSystem.c index 3c6c0f3..b88b4ff 100644 --- a/src/kernel/memory/fileSystem.c +++ b/src/kernel/memory/fileSystem.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include FileSystemFolder rootFolder = { diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index c761e9b..275d1fa 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,10 +1,10 @@ -#include <_stdio.h> #include #include +#include MemoryBlock *firstBlock; -void initMemoryAllocation(uint32_t kernelEnd) { +void initMemoryAllocation(uintptr_t kernelEnd) { firstBlock = (MemoryBlock *)kernelEnd; firstBlock->next = NULL; firstBlock->last = NULL; @@ -13,9 +13,10 @@ } #define getOffset() \ - (alignment ? alignmentBit - ((uint32_t)(current + 1) & (alignmentMask)) : 0) + (alignment ? alignmentBit - ((uintptr_t)(current + 1) & (alignmentMask)) \ + : 0) -void memmove(uint8_t *to, uint8_t *from, uint32_t count) { +void memmove(uint8_t *to, uint8_t *from, uintptr_t count) { if (from > to) { for (; count > 0; count--) { *(to++) = *(from++); @@ -27,11 +28,11 @@ } } -void *mallocTaskAligned(uint32_t size, uint8_t alignment, Task *task) { +void *mallocTaskAligned(uintptr_t size, uint8_t alignment, Task *task) { MemoryBlock *current = firstBlock; uint32_t alignmentBit = 1 << alignment; uint32_t alignmentMask = alignmentBit - 1; - uint32_t additionalOffset = getOffset(); + uintptr_t additionalOffset = getOffset(); while (current->task || current->size < size + additionalOffset) { current = current->next; additionalOffset = getOffset(); @@ -65,15 +66,15 @@ return (void *)(current + 1); } -void *mallocTask(uint32_t size, Task *task) { +void *mallocTask(uintptr_t size, Task *task) { return mallocTaskAligned(size, 0, task); } -void *malloc(uint32_t size) { +void *malloc(uintptr_t size) { return mallocTaskAligned(size, 0, getCurrentTask()); } -void *mallocAligned(uint32_t size, uint8_t alignment) { +void *mallocAligned(uintptr_t size, uint8_t alignment) { return mallocTaskAligned(size, alignment, getCurrentTask()); } diff --git a/src/kernel/memory/fileSystem.c b/src/kernel/memory/fileSystem.c index 3c6c0f3..b88b4ff 100644 --- a/src/kernel/memory/fileSystem.c +++ b/src/kernel/memory/fileSystem.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include FileSystemFolder rootFolder = { diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 7b0d6c9..c6ba9bf 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index c761e9b..275d1fa 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,10 +1,10 @@ -#include <_stdio.h> #include #include +#include MemoryBlock *firstBlock; -void initMemoryAllocation(uint32_t kernelEnd) { +void initMemoryAllocation(uintptr_t kernelEnd) { firstBlock = (MemoryBlock *)kernelEnd; firstBlock->next = NULL; firstBlock->last = NULL; @@ -13,9 +13,10 @@ } #define getOffset() \ - (alignment ? alignmentBit - ((uint32_t)(current + 1) & (alignmentMask)) : 0) + (alignment ? alignmentBit - ((uintptr_t)(current + 1) & (alignmentMask)) \ + : 0) -void memmove(uint8_t *to, uint8_t *from, uint32_t count) { +void memmove(uint8_t *to, uint8_t *from, uintptr_t count) { if (from > to) { for (; count > 0; count--) { *(to++) = *(from++); @@ -27,11 +28,11 @@ } } -void *mallocTaskAligned(uint32_t size, uint8_t alignment, Task *task) { +void *mallocTaskAligned(uintptr_t size, uint8_t alignment, Task *task) { MemoryBlock *current = firstBlock; uint32_t alignmentBit = 1 << alignment; uint32_t alignmentMask = alignmentBit - 1; - uint32_t additionalOffset = getOffset(); + uintptr_t additionalOffset = getOffset(); while (current->task || current->size < size + additionalOffset) { current = current->next; additionalOffset = getOffset(); @@ -65,15 +66,15 @@ return (void *)(current + 1); } -void *mallocTask(uint32_t size, Task *task) { +void *mallocTask(uintptr_t size, Task *task) { return mallocTaskAligned(size, 0, task); } -void *malloc(uint32_t size) { +void *malloc(uintptr_t size) { return mallocTaskAligned(size, 0, getCurrentTask()); } -void *mallocAligned(uint32_t size, uint8_t alignment) { +void *mallocAligned(uintptr_t size, uint8_t alignment) { return mallocTaskAligned(size, alignment, getCurrentTask()); } diff --git a/src/kernel/memory/fileSystem.c b/src/kernel/memory/fileSystem.c index 3c6c0f3..b88b4ff 100644 --- a/src/kernel/memory/fileSystem.c +++ b/src/kernel/memory/fileSystem.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include FileSystemFolder rootFolder = { diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 7b0d6c9..c6ba9bf 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 7ccbcb7..67e3ffa 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include #define STACK_SIZE 0x100000 @@ -22,8 +22,8 @@ task->registers.edi = 0; task->registers.eflags = flags; task->registers.eip = mainFunction; - task->registers.cr3 = (uint32_t)pagedir; - task->registers.esp = STACK_SIZE + (uint32_t)stack; + task->registers.cr3 = (uintptr_t)pagedir; + task->registers.esp = STACK_SIZE + (uintptr_t)stack; task->stack = stack; task->messages = NULL; task->ticksLeft = -1; @@ -34,7 +34,7 @@ Task *last = currentTask; currentTask = popBeginning(&scheduledTasks); while (currentTask == 0) { - currentTask = INTERRUPT_TASK; + currentTask = (void *)(uintptr_t)INTERRUPT_TASK; asm("sti"); asm("hlt"); currentTask = popBeginning(&scheduledTasks); diff --git a/Makefile b/Makefile index 3a9dada..2b35f61 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/compile_flags.txt b/compile_flags.txt index f16cf85..30140a7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,3 +2,4 @@ -I./src/include -fms-extensions -Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/include/_stdio.h b/src/include/_stdio.h deleted file mode 100644 index 81d2663..0000000 --- a/src/include/_stdio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -extern void printf(const char *format, ...); - -extern void setTextStyle(uint8_t newFormat); - -#endif diff --git a/src/include/alloc.h b/src/include/alloc.h index 93229c1..9aa86ba 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -4,20 +4,17 @@ #include #include -typedef enum MemoryState { FREE = 0, IN_USE = 1 } MemoryState; - typedef struct MemoryBlock { struct MemoryBlock *last; struct MemoryBlock *next; - MemoryState state; uint32_t size; Task *task; } MemoryBlock; -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void *malloc(uint32_t size); -extern void *mallocAligned(uint32_t size, uint8_t alignment); -extern void *mallocTask(uint32_t size, Task *task); +extern void initMemoryAllocation(uintptr_t kernelEnd); +extern void *malloc(uintptr_t size); +extern void *mallocAligned(uintptr_t size, uint8_t alignment); +extern void *mallocTask(uintptr_t size, Task *task); extern void free(void *location); extern void printMemoryStack(); extern void freeTaskAllocations(Task *task); diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..4dfd065 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,9 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +extern void printf(const char *format, ...); +extern void setTextStyle(uint8_t newFormat); + +#endif diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 436aa2e..234e1dc 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include extern void getVendorId(char *string); diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c index 8c1e7f7..f443dfa 100644 --- a/src/kernel/drivers/interrupts/exceptions.c +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include char *EXCEPTION_MESSAGES[] = {"DIVIDE BY ZERO", diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c index f9959de..6d8eefd 100644 --- a/src/kernel/drivers/interrupts/interrupts.c +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include @@ -13,10 +13,10 @@ void setInterrupt(uint8_t vector, void *callback) { IDTEntry *descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->isr_low = (uintptr_t)callback & 0xFFFF; descriptor->codeSegment = 0x08; descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->isr_high = (uintptr_t)callback >> 16; descriptor->reserved = 0; } @@ -24,7 +24,7 @@ buffer = malloc(sizeof(IDTEntry) * 257); entries = (IDTEntry *)(((int)buffer + sizeof(IDTEntry) >> 3) << 3); idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t)entries; + idtr.base = (uint32_t)(uintptr_t)entries; setupExceptions(); setupIRQs(); __asm__ volatile("lidt %0" : : "memory"(idtr)); diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c index 7e4b85c..12e7979 100644 --- a/src/kernel/drivers/interrupts/irqs.c +++ b/src/kernel/drivers/interrupts/irqs.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 99fdd04..cc4bad5 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -1,4 +1,3 @@ -#include <_stdio.h> #include #include #include @@ -7,7 +6,9 @@ #include #include #include +#include #include +#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -73,7 +74,7 @@ return; } Message *message = malloc(sizeof(Message)); - message->data = altKeycodes[scancode]; + message->data = (void *)(uintptr_t)altKeycodes[scancode]; message->type = KEYBOARD_STRING; message->size = strlen(message->data); listAdd(&(getKeyboardConsumer()->messages), message); @@ -97,9 +98,9 @@ } void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = (void *)(uint32_t)capitalKeycodes[scancode]; + data = (void *)(uintptr_t)capitalKeycodes[scancode]; } else { - data = (void *)(uint32_t)keycodes[scancode]; + data = (void *)(uintptr_t)keycodes[scancode]; } Message *message = malloc(sizeof(Message)); message->data = data; diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c index 35addee..ef60189 100644 --- a/src/kernel/drivers/interrupts/timer/timer.c +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #define PIT_A 0x40 @@ -40,7 +40,7 @@ outb(PIT_A, (uint8_t)(divisor >> 8)); } -uint32_t timerMillis = 0; +uintptr_t timerMillis = 0; void timerHandler() { timerMillis++; diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 6ff03fd..a9c7a4e 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include void scanHardDrives() { ListElement *drives = NULL; diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index e2f65be..e5ac6df 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #define IDE_DATA_REGISTER 0 #define IDE_ERROR_REGISTER 1 diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c index b65e27b..13008e3 100644 --- a/src/kernel/drivers/pci/hardDrive/sataController.c +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include // information source: // https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf @@ -103,7 +103,7 @@ } FisToDevice; void *getPointer(uint32_t lower, uint32_t upper) { - return (void *)(lower | (uint64_t)upper << 32); + return (void *)(uintptr_t)(lower | (uintptr_t)upper << 32); } uint32_t getType(PortControlRegisters *registers) { @@ -185,8 +185,8 @@ memset(commandTable, 0, sizeof(CommandTable) + (commandHeader->regionDescriptorCount - 1) * sizeof(PhysicalRegionDescriptor)); - commandTable->regionDescriptor[0].dataBaseLower = (uint64_t)buffer; - commandTable->regionDescriptor[0].dataBaseUpper = (uint64_t)buffer >> 32; + commandTable->regionDescriptor[0].dataBaseLower = (uintptr_t)buffer; + commandTable->regionDescriptor[0].dataBaseUpper = (uintptr_t)buffer >> 32; commandTable->regionDescriptor[0].byteCount = 511; commandTable->regionDescriptor[0].interrupt = 1; FisToDevice *fis = (void *)&(commandTable->fis); @@ -223,16 +223,16 @@ disableCommands(port); CommandListStructure *commandList = mallocAligned(sizeof(CommandListStructure), 10); - port->commandListLower = commandList; - port->commandListUpper = (uint64_t)commandList >> 32; - uint64_t fis = (uint64_t)mallocAligned(sizeof(CommandListStructure), 10); + port->commandListLower = (uintptr_t)commandList; + port->commandListUpper = (uintptr_t)commandList >> 32; + uintptr_t fis = (uintptr_t)mallocAligned(sizeof(CommandListStructure), 10); port->fisLower = fis; - port->fisUpper = (uint64_t)commandList >> 32; + port->fisUpper = (uintptr_t)commandList >> 32; memset(commandList, 0, sizeof(CommandListStructure)); for (uint8_t i = 0; i < 32; i++) { uint16_t size = 256; // sizeof(CommandTable) commandList->commandHeaders[i].regionDescriptorCount = 8; - uint64_t commandTable = (uint64_t)mallocAligned(size, 8); + uintptr_t commandTable = (uintptr_t)mallocAligned(size, 8); commandList->commandHeaders[i].commandTableLower = commandTable; commandList->commandHeaders[i].commandTableUpper = commandTable >> 32; memset((void *)commandTable, 0, size); @@ -268,7 +268,7 @@ // todo return; } - HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + HbaMemoryRegisters *registers = (void *)(uintptr_t)pciDevice->bar5; for (uint8_t i = 0; i < 32; i++) { if (!(registers->implementedPorts & (1 << i))) { continue; diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index 8068f5d..8a9e0c5 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -1,9 +1,9 @@ -#include <_stdio.h> #include #include #include #include #include +#include #include #include diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c deleted file mode 100644 index 240870a..0000000 --- a/src/kernel/drivers/textMode/_stdio.c +++ /dev/null @@ -1,161 +0,0 @@ -#include <_stdio.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char HEX_CHARS[] = "0123456789ABCDEF"; - -void putHex(char **write, uint32_t x) { - if (x == 0) { - **write = HEX_CHARS[x]; - (*write)++; - **write = HEX_CHARS[x]; - (*write)++; - return; - } - bool alreadyWriting = false; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - **write = HEX_CHARS[byte >> 4]; - (*write)++; - **write = HEX_CHARS[byte & 0x0F]; - (*write)++; - } - } -} - -uint8_t hexLength(uint32_t x) { - bool alreadyWriting = false; - uint8_t size = 0; - for (int position = 3; position >= 0; position--) { - uint8_t byte = (x >> (position * 8)) & 0xFF; - if (byte != 0x00 && !alreadyWriting) { - alreadyWriting = true; - } - if (alreadyWriting) { - size += 2; - } - } - return max(size, 2); -} - -uint32_t power(uint32_t x, uint32_t y) { - uint32_t result = 1; - for (int i = 0; i < y; i++) { - result *= x; - } - return result; -} - -uint32_t intLength(uint32_t x) { - if (x == 0) { - return 1; - } - for (int i = 10; i >= 0; i--) { - if (x / power(10, i) > 0) { - return i + 1; - } - } - return 1; -} - -void addChar(char **write, char c) { - **write = c; - (*write)++; -} - -void putInt(char **write, uint32_t x) { - if (x == 0) { - addChar(write, '0'); - return; - } - for (int i = 10; i >= 0; i--) { - uint32_t n = x / power(10, i); - if (n) { - addChar(write, HEX_CHARS[n % 10]); - } - } -} - -uint32_t getInsertLength(char insertType, uint32_t x) { - switch (insertType) { - case 's': - return strlen((char *)x); - case 'x': - return hexLength(x); - case 'c': - return 1; - case 'i': - return intLength(x); - } - return 0; -} - -void stringInsert(char **write, uint32_t x) { - char *string = (char *)x; - uint32_t length = strlen(string); - for (uint32_t position = 0; position < length; position++) { - **write = string[position]; - (*write)++; - } -} - -void handleInsert(char **write, char insertType, uint32_t x) { - switch (insertType) { - case 's': - stringInsert(write, x); - return; - case 'x': - putHex(write, x); - return; - case 'c': - **write = x; - return; - case 'i': - putInt(write, x); - } -} - -void printf(const char *format, ...) { - uint32_t size = 0; - va_list valist; - va_start(valist, format); - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - size += getInsertLength(format[++i], va_arg(valist, uint32_t)); - continue; - } - size++; - } - va_start(valist, format); - - char *data = malloc(size); - char *write = data; - for (int i = 0; format[i] != 0; i++) { - if (format[i] == '%') { - handleInsert(&write, format[++i], va_arg(valist, uint32_t)); - continue; - } - *write = format[i]; - write++; - } - va_end(valist); - - Message *message = malloc(sizeof(Message)); - message->data = data; - message->size = size; - message->type = -1; - listAdd(&getPrinterTask()->messages, message); - schedule(getPrinterTask()); -} diff --git a/src/kernel/drivers/textMode/cursor.c b/src/kernel/drivers/textMode/cursor.c index ed5603e..0805ebd 100644 --- a/src/kernel/drivers/textMode/cursor.c +++ b/src/kernel/drivers/textMode/cursor.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include void setCursorOffset(uint16_t offset) { outb(0x3D4, 0x0F); diff --git a/src/kernel/drivers/textMode/stdio.c b/src/kernel/drivers/textMode/stdio.c new file mode 100644 index 0000000..b311ed2 --- /dev/null +++ b/src/kernel/drivers/textMode/stdio.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char HEX_CHARS[] = "0123456789ABCDEF"; + +void putHex(char **write, uintptr_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } + bool alreadyWriting = false; + for (int position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + **write = HEX_CHARS[byte >> 4]; + (*write)++; + **write = HEX_CHARS[byte & 0x0F]; + (*write)++; + } + } +} + +uint8_t hexLength(uintptr_t x) { + bool alreadyWriting = false; + uint8_t size = 0; + for (int position = sizeof(uintptr_t); position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00 && !alreadyWriting) { + alreadyWriting = true; + } + if (alreadyWriting) { + size += 2; + } + } + return max(size, 2); +} + +uint32_t power(uintptr_t x, uintptr_t y) { + uintptr_t result = 1; + for (uintptr_t i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(intptr_t x) { + if (x == 0) { + return 1; + } + for (intptr_t i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uintptr_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (intptr_t i = 10; i >= 0; i--) { + uintptr_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + +uint32_t getInsertLength(char insertType, uintptr_t x) { + switch (insertType) { + case 's': + return strlen((char *)x); + case 'x': + return hexLength(x); + case 'c': + return 1; + case 'i': + return intLength(x); + } + return 0; +} + +void stringInsert(char **write, uintptr_t x) { + char *string = (char *)x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + (*write)++; + } +} + +void handleInsert(char **write, char insertType, uintptr_t x) { + switch (insertType) { + case 's': + stringInsert(write, x); + return; + case 'x': + putHex(write, x); + return; + case 'c': + **write = x; + return; + case 'i': + putInt(write, x); + } +} + +void printf(const char *format, ...) { + uintptr_t size = 0; + va_list valist; + va_start(valist, format); + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + size += getInsertLength(format[++i], va_arg(valist, uintptr_t)); + continue; + } + size++; + } + va_start(valist, format); + + char *data = malloc(size); + char *write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uintptr_t)); + continue; + } + *write = format[i]; + write++; + } + va_end(valist); + + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = size; + message->type = -1; + listAdd(&getPrinterTask()->messages, message); + schedule(getPrinterTask()); +} diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 46071c6..a10993d 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -25,8 +25,8 @@ void shiftUp() { for (int y = 1; y < VIDEO_HEIGHT; y++) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y - 1), old, old >> 8); } } @@ -38,8 +38,8 @@ void shiftDown() { for (int y = VIDEO_HEIGHT - 1; y >= 0; y--) { for (int x = 0; x < VIDEO_WIDTH; x++) { - uint16_t old = - *(uint16_t *)(FRAMEBUFFER_LOCATION + getOffset(x, y) * 2); + uint16_t old = *(uint16_t *)(uintptr_t)(FRAMEBUFFER_LOCATION + + getOffset(x, y) * 2); setCharAtOffset(getOffset(x, y + 1), old, old >> 8); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 444e498..a341d2f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,14 +1,11 @@ -#include <_stdio.h> #include #include #include #include -#include -#include #include #include -#include #include +#include #include #include diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index c761e9b..275d1fa 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,10 +1,10 @@ -#include <_stdio.h> #include #include +#include MemoryBlock *firstBlock; -void initMemoryAllocation(uint32_t kernelEnd) { +void initMemoryAllocation(uintptr_t kernelEnd) { firstBlock = (MemoryBlock *)kernelEnd; firstBlock->next = NULL; firstBlock->last = NULL; @@ -13,9 +13,10 @@ } #define getOffset() \ - (alignment ? alignmentBit - ((uint32_t)(current + 1) & (alignmentMask)) : 0) + (alignment ? alignmentBit - ((uintptr_t)(current + 1) & (alignmentMask)) \ + : 0) -void memmove(uint8_t *to, uint8_t *from, uint32_t count) { +void memmove(uint8_t *to, uint8_t *from, uintptr_t count) { if (from > to) { for (; count > 0; count--) { *(to++) = *(from++); @@ -27,11 +28,11 @@ } } -void *mallocTaskAligned(uint32_t size, uint8_t alignment, Task *task) { +void *mallocTaskAligned(uintptr_t size, uint8_t alignment, Task *task) { MemoryBlock *current = firstBlock; uint32_t alignmentBit = 1 << alignment; uint32_t alignmentMask = alignmentBit - 1; - uint32_t additionalOffset = getOffset(); + uintptr_t additionalOffset = getOffset(); while (current->task || current->size < size + additionalOffset) { current = current->next; additionalOffset = getOffset(); @@ -65,15 +66,15 @@ return (void *)(current + 1); } -void *mallocTask(uint32_t size, Task *task) { +void *mallocTask(uintptr_t size, Task *task) { return mallocTaskAligned(size, 0, task); } -void *malloc(uint32_t size) { +void *malloc(uintptr_t size) { return mallocTaskAligned(size, 0, getCurrentTask()); } -void *mallocAligned(uint32_t size, uint8_t alignment) { +void *mallocAligned(uintptr_t size, uint8_t alignment) { return mallocTaskAligned(size, alignment, getCurrentTask()); } diff --git a/src/kernel/memory/fileSystem.c b/src/kernel/memory/fileSystem.c index 3c6c0f3..b88b4ff 100644 --- a/src/kernel/memory/fileSystem.c +++ b/src/kernel/memory/fileSystem.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include FileSystemFolder rootFolder = { diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 7b0d6c9..c6ba9bf 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -1,7 +1,7 @@ -#include <_stdio.h> #include #include #include +#include #include #include diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 7ccbcb7..67e3ffa 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -1,6 +1,6 @@ -#include <_stdio.h> #include #include +#include #include #define STACK_SIZE 0x100000 @@ -22,8 +22,8 @@ task->registers.edi = 0; task->registers.eflags = flags; task->registers.eip = mainFunction; - task->registers.cr3 = (uint32_t)pagedir; - task->registers.esp = STACK_SIZE + (uint32_t)stack; + task->registers.cr3 = (uintptr_t)pagedir; + task->registers.esp = STACK_SIZE + (uintptr_t)stack; task->stack = stack; task->messages = NULL; task->ticksLeft = -1; @@ -34,7 +34,7 @@ Task *last = currentTask; currentTask = popBeginning(&scheduledTasks); while (currentTask == 0) { - currentTask = INTERRUPT_TASK; + currentTask = (void *)(uintptr_t)INTERRUPT_TASK; asm("sti"); asm("hlt"); currentTask = popBeginning(&scheduledTasks); diff --git a/src/kernel/util/tree-os.c b/src/kernel/util/tree-os.c index 9e73134..41111e5 100644 --- a/src/kernel/util/tree-os.c +++ b/src/kernel/util/tree-os.c @@ -1,4 +1,4 @@ -#include <_stdio.h> +#include #include #include