From 1905f3babdc33ad3a684cca4dc35265799a14285 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Tue, 31 Aug 2021 22:50:10 +0100 Subject: [PATCH] kernel32.bin is now written in C, make necessary modifications to Makefile, .gitignore, boot32.asm, etc to get this working --- .gitignore | 1 + Makefile | 14 +++++++++++-- boot32.asm | 2 +- kernel32.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel32.ld | 9 +++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 kernel32.c create mode 100644 kernel32.ld diff --git a/.gitignore b/.gitignore index ce571f9..d6a02df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.bin *.img *.sector +*.o img.d/ \ No newline at end of file diff --git a/Makefile b/Makefile index 9c3113a..2855285 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ -disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin + +CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie +LDFLAGS = + +disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel32.bin dd if=/dev/zero of=disk.img count=43 bs=100k dd if=boot.sector of=disk.img conv=notrunc mount disk.img img.d @@ -20,4 +24,10 @@ print.bin: print.asm nasm $< -o $@ boot32.bin: boot32.asm - nasm $< -o $@ \ No newline at end of file + nasm $< -o $@ + +kernel32.bin: kernel32.ld kernel32.o + ld $(LDFLAGS) -T $< -o $@ kernel32.o + +kernel32.o: kernel32.c + gcc $(CFLAGS) -o $@ -c $< \ No newline at end of file diff --git a/boot32.asm b/boot32.asm index 548537e..b85382d 100644 --- a/boot32.asm +++ b/boot32.asm @@ -80,7 +80,7 @@ gdt_code: gdt_data: dw 0xffff dw 0x0 - db 0x8 + db 0x0 db 10010010b db 01001111b db 0 diff --git a/kernel32.c b/kernel32.c new file mode 100644 index 0000000..67d6fba --- /dev/null +++ b/kernel32.c @@ -0,0 +1,58 @@ +void clear_screen(); +void set_curpos(int x, int y); +void print(const char* string); + +unsigned char* VMEM_ADDR = (unsigned char*)0xb8000; +const int TERM_WIDTH = 80; +const int TERM_HEIGHT = 25; + +int cursor_x = 0; +int cursor_y = 0; + +int main() { + asm( + "mov $0x10, %ax\n" + "mov %ax, %ds\n" + "mov %ax, %ss\n" + "mov $0x90000, %esp" + ); + + clear_screen(); + set_curpos(0, 0); + + print("Hello, World!\n\nWe are running XnoeOS Code in C now, Protected Mode has been achieved and everything is working super nicely!\n\nHow wonderful!\n\nNow I just need to hope my print function works properly too~~"); + + while (1) {} +} + +void clear_screen() { + for (int i=0; i