From ef24568fed6f425c130447e8160dd1542459ddc5 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 11 Aug 2024 02:51:35 +0300 Subject: [PATCH] fixed invalid data accesses, due to DS != SS, moved everything into the first 64k instead, should be enough for the kernel. --- kern/Makefile | 3 ++- kern/src/main.c | 12 ------------ kern/src/startup.asm | 9 ++++----- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/kern/Makefile b/kern/Makefile index d097da2..187df0d 100644 --- a/kern/Makefile +++ b/kern/Makefile @@ -14,8 +14,9 @@ LD = ia16-elf-ld warn = -pedantic -Wall inc = -nostdinc -Isrc -Isrc/libc +arch = -march=i8088 -mtune=i8088 -CFLAGS = -march=i8088 -mtune=i8088 $(warn) $(inc) -MMD +CFLAGS = $(arch) -ffreestanding -mcmodel=small $(warn) $(inc) -MMD LDFLAGS = -T kern.ld -Map kern.map $(img): $(bin) diff --git a/kern/src/main.c b/kern/src/main.c index f89cd5d..cc3cd14 100644 --- a/kern/src/main.c +++ b/kern/src/main.c @@ -3,19 +3,7 @@ void kmain(void) { - int i, j; - unsigned short __far *vmem = (void __far*)0xb8000000ul; - unsigned short c; - vid_init(); vid_text(0, 0, "hello!", VID_ATTR(LTRED, BLACK)); init_intr(); - - vmem += 80; - for(i=1; i<25; i++) { - c = ((i & 0xf) << 8) | '@'; - for(j=0; j<80; j++) { - *vmem++ = c; - } - } } diff --git a/kern/src/startup.asm b/kern/src/startup.asm index c64684a..2cd9250 100644 --- a/kern/src/startup.asm +++ b/kern/src/startup.asm @@ -3,7 +3,7 @@ bits 16 section .startup -; memory reserved at the top of RAM for the kernel stack +; memory reserved at the top of the kernel segment for the stack STACKSZ equ 4096 extern kmain @@ -14,10 +14,9 @@ global _start _start: ; TODO floppy off if necessary - ; move stack to the top of RAM (TODO: detect and avoid Ext. BIOS data area) - mov ax, (0xa0000 - STACKSZ) >> 4 - mov ss, ax - mov sp, STACKSZ + ; move stack to the top of the kernel segment + xor ax, ax + mov sp, ax ; zero .bss mov di, _bss_start_off -- 1.7.10.4