diff --git a/Makefile b/Makefile index 36f61ed1..fe1ee96d 100644 --- a/Makefile +++ b/Makefile @@ -10,14 +10,16 @@ micro_kernel.bin: $(KERNEL_SRC) $(KERNEL_UTILS_SRC) nasm -w+all -f bin -o micro_kernel.bin src/micro_kernel.asm kernel.o: src/kernel.cpp - g++ -Wall -Wextra -O2 -fno-exceptions -fno-rtti -ffreestanding -c src/kernel.cpp -o kernel.o + g++ -O2 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding -c src/kernel.cpp -o kernel.o -kernel.bin: kernel.o - g++ -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o +kernel.bin: kernel.o + g++ -std=c++11 -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o objcopy -R .note -R .comment -S -O binary kernel.bin.o kernel.bin + +filler.bin: kernel.bin bash fill.bash -thor.flp: bootloader.bin micro_kernel.bin kernel.bin +thor.flp: bootloader.bin micro_kernel.bin kernel.bin filler.bin cat bootloader.bin > thor.bin cat micro_kernel.bin >> thor.bin cat kernel.bin >> thor.bin diff --git a/linker.ld b/linker.ld index 6bcd7a10..47dc2e93 100644 --- a/linker.ld +++ b/linker.ld @@ -8,7 +8,7 @@ SECTIONS { /* Begin putting sections at 1 MiB, a conventional place for kernels to be loaded at by the bootloader. */ - . = 0x10000; + . = 0x5000; /* First put the multiboot header, as it is required to be put very early early in the image or the bootloader won't recognize the file format. diff --git a/src/commands.asm b/src/commands.asm index d23e019a..e03c756f 100644 --- a/src/commands.asm +++ b/src/commands.asm @@ -573,6 +573,8 @@ load_command: call 0x5000 + jmp $ + call clear_command ret diff --git a/src/kernel.cpp b/src/kernel.cpp index cf3d751e..bf810e89 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -1,8 +1,66 @@ +void k_print_line(const char* string); +void k_print(const char* string); + extern "C" void kernel_main(){ - unsigned char *vidmem = (unsigned char*) 0x0B8000; + k_print_line("hello, world!"); - *vidmem++ = 'a'; - *vidmem++ = 0; - *vidmem++ = 'b'; + return; +} + +typedef unsigned int uint8_t __attribute__((__mode__(__QI__))); +typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__))); + +enum vga_color { + BLACK = 0, + BLUE = 1, + GREEN = 2, + CYAN = 3, + RED = 4, + MAGENTA = 5, + BROWN = 6, + LIGHT_GREY = 7, + DARK_GREY = 8, + LIGHT_BLUE = 9, + LIGHT_GREEN = 10, + LIGHT_CYAN = 11, + LIGHT_RED = 12, + LIGHT_MAGENTA = 13, + LIGHT_BROWN = 14, + WHITE = 15, +}; + +uint8_t make_color(vga_color fg, vga_color bg){ + return fg | bg << 4; +} + +uint16_t make_vga_entry(char c, uint8_t color){ + uint16_t c16 = c; + uint16_t color16 = color; + return c16 | color16 << 8; +} + +void k_print_line(const char* string){ + long current_line = 0; + long current_column = 0; + + k_print(string); + + current_column = 0; + ++current_line; +} + +void k_print(const char* string){ + long current_line = 0; + long current_column = 0; + + uint16_t* vga_buffer = (uint16_t*) 0x0B8000; + + for(int i = 0; string[i] != 0; ++i){ + vga_buffer[current_line * 80 + current_column] = make_vga_entry(string[i], make_color(WHITE, BLACK)); + + ++current_column; + } + + return; }