[Stage1] Fix linker to force main() at base address
[Stage1] Add basic write-to-screen utilities for VGA mode 3
This commit is contained in:
parent
3f7e02533f
commit
5b17b79264
5 changed files with 58 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
7
stage1/include/screen.h
Normal file
7
stage1/include/screen.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef __OS3_ST1_SCREEN_H
|
||||
#define __OS3_ST1_SCREEN_H
|
||||
|
||||
extern void write_string(const char*, int);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -3,6 +3,9 @@ SECTIONS
|
|||
{
|
||||
. = 0x10000;
|
||||
.text : AT(0x10000){
|
||||
stage1/CMakeFiles/stage1.dir/stage1.c.obj(.text);
|
||||
}
|
||||
.othertext : {
|
||||
*(.text);
|
||||
}
|
||||
.data : {
|
||||
|
|
|
|||
39
stage1/screen.c
Normal file
39
stage1/screen.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue