diff --git a/stage1/CMakeLists.txt b/stage1/CMakeLists.txt index 2328fd7..f780ac4 100644 --- a/stage1/CMakeLists.txt +++ b/stage1/CMakeLists.txt @@ -1,4 +1,4 @@ -add_executable(stage1 stage1.c) +add_executable(stage1 stage1.c screen.c) target_compile_options(stage1 PUBLIC -ffreestanding) set_target_properties(stage1 PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) target_link_options(stage1 PRIVATE -T${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) diff --git a/stage1/include/screen.h b/stage1/include/screen.h new file mode 100644 index 0000000..09edd43 --- /dev/null +++ b/stage1/include/screen.h @@ -0,0 +1,7 @@ +#ifndef __OS3_ST1_SCREEN_H +#define __OS3_ST1_SCREEN_H + +extern void write_string(const char*, int); + + +#endif \ No newline at end of file diff --git a/stage1/linker.ld b/stage1/linker.ld index dec9633..214e869 100644 --- a/stage1/linker.ld +++ b/stage1/linker.ld @@ -3,6 +3,9 @@ SECTIONS { . = 0x10000; .text : AT(0x10000){ + stage1/CMakeFiles/stage1.dir/stage1.c.obj(.text); + } + .othertext : { *(.text); } .data : { diff --git a/stage1/screen.c b/stage1/screen.c new file mode 100644 index 0000000..718e404 --- /dev/null +++ b/stage1/screen.c @@ -0,0 +1,39 @@ +#include "include/screen.h" +#include "../os3_common/datatypes.h" +#include "../os3_common/packing.h" + +int x = 0; +int y = 0; + +void write_character(char c) { + os_u16 color_byte = 0x0A; + os_u16* vram = (os_u16*) 0xB8000; + os_u16* cursor_pos = vram + ((y * 80) + x); + *cursor_pos = c | (color_byte << 8); +} + +void write_string(const char* str, int max_len) { + int i = 0; + do { + char c = *str; + if (c == 0) { + return; + } + + if (c == '\n') { + y = (y + 1) % 25; + x = 0; + str++; + continue; + } + + write_character(c); + x++; + if (x >= 80) { + y = (y + 1) % 25; + x = 0; + } + str++; + i++; + } while(i < max_len || max_len == 0); +} diff --git a/stage1/stage1.c b/stage1/stage1.c index 9d5fae3..56089d2 100644 --- a/stage1/stage1.c +++ b/stage1/stage1.c @@ -2,10 +2,16 @@ // Created by barba on 06/10/2022. // +#include "../os3_common/datatypes.h" +#include "../os3_common/packing.h" +#include "include/screen.h" + int main() { + write_string("OS3 Booted into stage 1!\n", 0); + write_string("Looking for stage 2....", 0); while(1) { }; - return 0; -} \ No newline at end of file + return 0; +}