diff options
-rw-r--r-- | src/Makefile | 11 | ||||
-rw-r--r-- | src/boot.asm | 16 | ||||
-rw-r--r-- | src/kernel.c | 26 | ||||
-rw-r--r-- | src/stage1_functions.asm | 10 |
4 files changed, 52 insertions, 11 deletions
diff --git a/src/Makefile b/src/Makefile index 9132a1b..041a029 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,20 +1,23 @@ CC := gcc +CFLAGS := -std=c99 -m32 -ffreestanding LD := ld all: image.bin image.bin: boot.bin kernel.bin cat boot.bin kernel.bin > image.bin - truncate -s 1536 image.bin + # truncate to correct number of sectors, we have + # 512 (boot) + N * 1024 (N currenty is 2) + truncate -s 2560 image.bin boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm nasm boot.asm -f bin -o boot.bin kernel.bin: kernel.o - $(LD) -o kernel.bin -Ttext 0x8000 kernel.o -m elf_i386 --oformat binary + $(LD) -o kernel.bin -Ttext 0x8000 kernel.o --oformat binary kernel.o: kernel.c - $(CC) -m32 -ffreestanding -c -o kernel.o kernel.c + $(CC) $(CFLAGS) -O0 -c -o kernel.o kernel.c clean: -rm -f boot.bin kernel.bin image.bin *.o @@ -26,4 +29,4 @@ run-bochs: bochs -q -f bochs.config 'boot:floppy' 'floppya: 1_44=image.bin, status=inserted' functions.o: functions.c - gcc -m32 -ffreestanding -c -o functions.o functions.c + $(CC) $(CFLAGS) -c -o functions.o functions.c diff --git a/src/boot.asm b/src/boot.asm index f053270..abfa9d5 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -87,6 +87,17 @@ MESSAGE_STAGE_2_LOADED: [bits 32] BEGIN_PROTECTED_MODE: + + mov edx, 1 +_loop_test: + mov si, MESSAGE_INITIALIZING + call pm_print_string + call pm_print_newline + dec edx + cmp edx, 0 + jnz _loop_test +_end_of_test: + mov si, MESSAGE_PROTECTED_MODE call pm_print_string call pm_print_newline @@ -107,6 +118,9 @@ BEGIN_PROTECTED_MODE: MESSAGE_PROTECTED_MODE: db "Switched to 32-bit Protected Mode", 0 +MESSAGE_INITIALIZING: + db "Initializing the Foo machine..", 0 + MESSAGE_CALL_C_ENTRY: db "Calling C entry function", 0 @@ -116,6 +130,6 @@ MESSAGE_HALTED: %include "stage2_functions.asm" ; make sure we have full sectors -times 1024-($-$$) db 0 +times 2048-($-$$) db 0 c_entry: diff --git a/src/kernel.c b/src/kernel.c index d94f960..100fc6d 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,10 +1,28 @@ +#include <inttypes.h> + void entry( ) { - char *VIDEO_MEMORY = (char *)0xb8000; - char *bar = "\\|/-"; + volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xb8000; + + *VIDEO_MEMORY = 'H'; + *(VIDEO_MEMORY+2) = 'E'; + *(VIDEO_MEMORY+4) = 'L'; + *(VIDEO_MEMORY+6) = 'L'; + *(VIDEO_MEMORY+8) = 'O'; + *(VIDEO_MEMORY+10) = '_'; + + uint8_t bar[4] = "\\|/-"; char backup = *VIDEO_MEMORY; - for( int i = 0; i < 20000000; i++ ) { - *VIDEO_MEMORY = bar[i%4]; + int pos = 10; + for( int i = 0; i < 200000; i++ ) { + if( i % 1000 == 0 ) { + *(VIDEO_MEMORY+pos) = '.'; + *(VIDEO_MEMORY+pos+1) = 0x07; + pos += 2; + } + *(VIDEO_MEMORY+pos) = bar[i%4]; + *(VIDEO_MEMORY+pos+1) = 0x07; + for( int j = 0; j < 10000; j++ ); } *VIDEO_MEMORY = backup; } diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm index 2ca3eb2..859ee66 100644 --- a/src/stage1_functions.asm +++ b/src/stage1_functions.asm @@ -1,3 +1,9 @@ +; number of sectors to be read +; this is 512 (the bootloader stage1) + +; N * 1024 for bootloader stage2 and the kernel code +; (note: the first sector gets loaded by the BIOS) +NOF_LOAD_SECTORS equ 4 + ; IN bx: begin of memory area to dump ; IN ax: number of words to dump dump_range: @@ -103,7 +109,7 @@ read_from_disk: mov ah, 0x02 ; read sectors from drive - mov al, 2 ; read 1 sector + mov al, NOF_LOAD_SECTORS ; read 1 sector mov ch, 0 ; select first cylinder mov dh, 0 ; first head mov cl, 2 ; second sector after boot sector @@ -116,7 +122,7 @@ read_from_disk: jc read_error - cmp al, 2 ; 1 sector read? + cmp al, NOF_LOAD_SECTORS ; 1 sector read? jne short_read ; if not, short read ret |