From 61ae70c4c39ee792420f54549fe9987dc20a26a0 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sun, 15 Aug 2021 21:31:21 +0200 Subject: [PATCH 1/9] TODO list --- TODO.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..94694f8 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +# TO DO + - Multiboot support (for grub etc) + - Expand os-image so there is no error 0x8b00! From ba5590850eaf2fa7997230a3f3f658ca5bd4c2da Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 18:29:11 +0200 Subject: [PATCH 2/9] Minor refactor --- Makefile | 1 - src/kernel/lib/vga.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4a99e2c..d381f62 100644 --- a/Makefile +++ b/Makefile @@ -32,4 +32,3 @@ clean: kernel.dis : kernel.bin ndisasm -b 32 $< > $@ - diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index e3948e9..f0d9f02 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -3,20 +3,44 @@ // VGA base address: 0xb8000 // Charpos = 0xb8000 + 2(row*80 + col) +// Screen Dimensions +#define WIDTH 640 +#define HEIGHT 480 + +// Memory #define VIDEO_MEM (char*)0xb8000 -#define GET_INDEX(s, c) (int)(c-s) -static int cursor_y = 0; -char* get_cursor_pos(unsigned int col, unsigned int row) { +// Global +static int cursor_row = 0; + +/* + VGA & Memory Functions +*/ +char* get_vga_memory_pointer(unsigned int col, unsigned int row) { return (char*)(VIDEO_MEM + 2*((row*80) + col)); } +void putc(char c, unsigned int col, unsigned int row) { + *get_vga_memory_pointer(col, row) = c; +} + +/* + Graphics Functions +*/ +void clear_screen(unsigned int width = 640, unsigned int height = 480) { + +} + + +/* + General Printing Functions +*/ void print(char* str, unsigned int str_len) { for( char* c = str; *c != '\0'; c++ ) - *get_cursor_pos( GET_INDEX(str, c), cursor_y ) = *c; + putc(*c, (int)(c - str), cursor_row); } void println(char* str, unsigned int str_len) { print(str, str_len); - cursor_y++; // Increment to next y-pos (newline) + cursor_row++; // Increment to next y-pos (newline) } From 566516ca3cb1cf7401b77aa02ae31e7c0f13307e Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:11:38 +0200 Subject: [PATCH 3/9] Created clear_screen --- src/kernel/kernel.c | 6 +++--- src/kernel/lib/vga.c | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 8629a26..93da93f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -4,7 +4,7 @@ void main() { // Do kernel stuff char* vidmem = (char*)0xb8000; *vidmem = 'X'; - for( int i = 0; i < 16; i++ ) { - println("C-Printing test!", 16); - } + + clear_screen(); + println("Kernel loaded.", 14); } diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index f0d9f02..7e89353 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -8,7 +8,8 @@ #define HEIGHT 480 // Memory -#define VIDEO_MEM (char*)0xb8000 +#define VIDEO_MEM (char*)0xb8000 +#define VIDEO_MEM_MAX (char*)0xb8fa0 // Global static int cursor_row = 0; @@ -27,8 +28,10 @@ void putc(char c, unsigned int col, unsigned int row) { /* Graphics Functions */ -void clear_screen(unsigned int width = 640, unsigned int height = 480) { - +void clear_screen() { + for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) { + *c = 0x20; + } } From 1aef6760667736d83b9a32c4bed57d4ae08c91b9 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:18:12 +0200 Subject: [PATCH 4/9] Color codes --- src/kernel/kernel.c | 2 +- src/kernel/lib/vga.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 93da93f..398e90c 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -6,5 +6,5 @@ void main() { *vidmem = 'X'; clear_screen(); - println("Kernel loaded.", 14); + println("eOS Version 0.0 2021", 0x0f); } diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index 7e89353..4ba02d1 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -17,12 +17,15 @@ static int cursor_row = 0; /* VGA & Memory Functions */ -char* get_vga_memory_pointer(unsigned int col, unsigned int row) { +char* get_vga_charpos_pointer(unsigned int col, unsigned int row) { return (char*)(VIDEO_MEM + 2*((row*80) + col)); } -void putc(char c, unsigned int col, unsigned int row) { - *get_vga_memory_pointer(col, row) = c; +void putc(char c, unsigned int col, unsigned int row, int colorcode) { + char* mem = get_vga_charpos_pointer(col, row); + *mem = c; + *(mem+1) = colorcode; + } /* @@ -38,12 +41,12 @@ void clear_screen() { /* General Printing Functions */ -void print(char* str, unsigned int str_len) { +void print(char* str, int colorcode) { for( char* c = str; *c != '\0'; c++ ) - putc(*c, (int)(c - str), cursor_row); + putc(*c, (int)(c - str), cursor_row, colorcode); } -void println(char* str, unsigned int str_len) { - print(str, str_len); +void println(char* str, int colorcode) { + print(str, colorcode); cursor_row++; // Increment to next y-pos (newline) } From 159ab0e1a24425f368af9f37e98747f93d62d8b9 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:28:53 +0200 Subject: [PATCH 5/9] set_cursor_pos --- src/kernel/kernel.c | 3 ++- src/kernel/lib/vga.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 398e90c..e5db7da 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -6,5 +6,6 @@ void main() { *vidmem = 'X'; clear_screen(); - println("eOS Version 0.0 2021", 0x0f); + set_cursor_pos(0, 5); + println("\t eOS Version 0.0 2021", 0xf0); } diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index 4ba02d1..7de8f48 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -12,7 +12,8 @@ #define VIDEO_MEM_MAX (char*)0xb8fa0 // Global -static int cursor_row = 0; +static unsigned int cursor_row = 0; +static unsigned int cursor_col = 0; /* VGA & Memory Functions @@ -23,8 +24,8 @@ char* get_vga_charpos_pointer(unsigned int col, unsigned int row) { void putc(char c, unsigned int col, unsigned int row, int colorcode) { char* mem = get_vga_charpos_pointer(col, row); - *mem = c; - *(mem+1) = colorcode; + *mem = c; // Write the character + *(mem+1) = colorcode; // Write the colorcode } @@ -32,18 +33,22 @@ void putc(char c, unsigned int col, unsigned int row, int colorcode) { Graphics Functions */ void clear_screen() { - for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) { + // Make all the characters spaces + for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) *c = 0x20; - } } /* General Printing Functions */ +void set_cursor_pos(unsigned int x, unsigned int y) { + cursor_col, cursor_row = x, y; +} + void print(char* str, int colorcode) { for( char* c = str; *c != '\0'; c++ ) - putc(*c, (int)(c - str), cursor_row, colorcode); + putc(*c, (unsigned int)(c - str + cursor_col), cursor_row, colorcode); } void println(char* str, int colorcode) { From c990061920d6d0f9ce08297b1cb43bdfe0ebea16 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:32:01 +0200 Subject: [PATCH 6/9] Makefile update & VGA lib stuff --- Makefile | 2 ++ src/kernel/lib/vga.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d381f62..0eea523 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ all: os-image run: all qemu-system-x86_64 os-image +drun: clean run + grub: eOS.iso qemu-system-x86_64 eOS.iso diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index 7de8f48..3cbb4ae 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -48,7 +48,7 @@ void set_cursor_pos(unsigned int x, unsigned int y) { void print(char* str, int colorcode) { for( char* c = str; *c != '\0'; c++ ) - putc(*c, (unsigned int)(c - str + cursor_col), cursor_row, colorcode); + putc(*c, (unsigned int)(c - str) + cursor_col, cursor_row, colorcode); } void println(char* str, int colorcode) { From 83560782374bd7ff60415e3720d3e698ddf39015 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:33:53 +0200 Subject: [PATCH 7/9] Minor set_cursor_pos bug fix --- src/kernel/kernel.c | 2 +- src/kernel/lib/vga.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e5db7da..ce6a1ec 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -6,6 +6,6 @@ void main() { *vidmem = 'X'; clear_screen(); - set_cursor_pos(0, 5); + set_cursor_pos(24, 0); println("\t eOS Version 0.0 2021", 0xf0); } diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index 3cbb4ae..e869fe2 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -43,7 +43,8 @@ void clear_screen() { General Printing Functions */ void set_cursor_pos(unsigned int x, unsigned int y) { - cursor_col, cursor_row = x, y; + cursor_col = x; + cursor_row = y; } void print(char* str, int colorcode) { From 1c76279e1e31ef6406d5336c61d0294b63eafcd1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:39:44 +0200 Subject: [PATCH 8/9] String library --- src/kernel/lib/string.c | 2 ++ src/kernel/lib/vga.c | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 src/kernel/lib/string.c diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c new file mode 100644 index 0000000..f9501ae --- /dev/null +++ b/src/kernel/lib/string.c @@ -0,0 +1,2 @@ +// Generic String Library +#define INDEX(s, c) (int)(c-s) diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index e869fe2..9d5d7cd 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -3,10 +3,6 @@ // VGA base address: 0xb8000 // Charpos = 0xb8000 + 2(row*80 + col) -// Screen Dimensions -#define WIDTH 640 -#define HEIGHT 480 - // Memory #define VIDEO_MEM (char*)0xb8000 #define VIDEO_MEM_MAX (char*)0xb8fa0 From 828b7c1321758d4fea22f4e2bab32c1f768d2e5d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 16 Aug 2021 19:44:49 +0200 Subject: [PATCH 9/9] String library --- src/kernel/lib/string.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c index f9501ae..7b9dcd4 100644 --- a/src/kernel/lib/string.c +++ b/src/kernel/lib/string.c @@ -1,2 +1,8 @@ // Generic String Library #define INDEX(s, c) (int)(c-s) + +unsigned int length(char* str) { + char* p; + for( p = str; *p != '\0'; p++ ) {} + return (unsigned int)(p-str); +}