From 4a589f9c51ee4592e4ad134e9c9359016767e93b Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 26 Aug 2021 08:57:41 +0200 Subject: [PATCH 01/10] TODO.md update --- TODO.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index bba626c..e2c313d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # TO DO - - Refactor the VGA driver - - Finish the book! + - Scrolling - Multiboot support (for grub etc) - Rendering (VGA) - User input (Keyboard) From 8a9937997e91e199c0e4c1d584c72df25bef4482 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 26 Aug 2021 09:00:57 +0200 Subject: [PATCH 02/10] Stuff --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index e2c313d..de50dd2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ # TO DO + - String formating - Scrolling - Multiboot support (for grub etc) - Rendering (VGA) From 0c3728863e502e141e9413a0528e36e320f78d4d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 26 Aug 2021 21:21:19 +0200 Subject: [PATCH 03/10] Prototypes etc --- kernel/kernel.c | 6 ------ lib/strf.c | 9 +++++++++ lib/strf.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 lib/strf.c create mode 100644 lib/strf.h diff --git a/kernel/kernel.c b/kernel/kernel.c index 290d9e5..2d24fd9 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -6,10 +6,4 @@ void main() { set_cursor_pos(28, 2); print("eOS Version 0.1 2021", 0xf0); - - /* - set_cursor_pos(0, 0); - for( int i = 0; i < 255; i++ ) - println("X", i); - */ } diff --git a/lib/strf.c b/lib/strf.c new file mode 100644 index 0000000..c273e1b --- /dev/null +++ b/lib/strf.c @@ -0,0 +1,9 @@ +#include "lib/strf.h" + +#define int_offset 48 +// 0:48 - 9:57 + +char* int_to_str(int i) { + char* strbuf; + double num = (double)i; +} diff --git a/lib/strf.h b/lib/strf.h new file mode 100644 index 0000000..2046d91 --- /dev/null +++ b/lib/strf.h @@ -0,0 +1 @@ +char* int_to_str(int i); From e429ac610279a7e30450f2372e907e2d0f73f735 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 27 Aug 2021 23:42:30 +0200 Subject: [PATCH 04/10] Borked int_to_str --- Makefile | 4 ++-- kernel/kernel.c | 5 +++++ lib/strf.c | 12 +++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5b13a7e..4c23ad8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -C_SOURCES = $(wildcard kernel/*.c drivers/*.c) -HEADERS = $(wildcard kernel/*.h drivers/*.h) +C_SOURCES = $(wildcard kernel/*.c drivers/*.c lib/*.c) +HEADERS = $(wildcard kernel/*.h drivers/*.h lib/*.h) OBJ = $(C_SOURCES:.c=.o) all: os-image diff --git a/kernel/kernel.c b/kernel/kernel.c index 2d24fd9..7fbcba1 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,9 +1,14 @@ #include "../drivers/vga.h" +#include "../lib/strf.h" void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. + int test = 1234; + char* teststr = int_to_str(test); + println(teststr, 0xf0); + set_cursor_pos(28, 2); print("eOS Version 0.1 2021", 0xf0); } diff --git a/lib/strf.c b/lib/strf.c index c273e1b..5259262 100644 --- a/lib/strf.c +++ b/lib/strf.c @@ -1,9 +1,15 @@ -#include "lib/strf.h" +#include "strf.h" #define int_offset 48 // 0:48 - 9:57 char* int_to_str(int i) { - char* strbuf; - double num = (double)i; + char* strbuf = "XXXXXX"; + + while( i > 0 ) { + *(strbuf + 1) = (i % 10) + int_offset; + i /= 10; + } + + return strbuf; } From 4d6c6fd8dd6b552f650e1e5d58ff3cad4fc2b5ee Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:19:21 +0200 Subject: [PATCH 05/10] str stuff --- kernel/kernel.c | 3 ++- lib/str.c | 21 +++++++++++++++++++++ lib/str.h | 2 ++ lib/strf.c | 16 ++++++++-------- lib/strf.h | 2 +- 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 lib/str.c create mode 100644 lib/str.h diff --git a/kernel/kernel.c b/kernel/kernel.c index 7fbcba1..f7ea26c 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -6,7 +6,8 @@ void main() { // i.e. clear the screen et cetera. int test = 1234; - char* teststr = int_to_str(test); + char* teststr; + teststr = int_to_str(test, teststr); println(teststr, 0xf0); set_cursor_pos(28, 2); diff --git a/lib/str.c b/lib/str.c new file mode 100644 index 0000000..a0a7ef7 --- /dev/null +++ b/lib/str.c @@ -0,0 +1,21 @@ +#include "str.h" + +unsigned int strlen(char* str) { + char* c; + for( c = str; *c != '\0'; c++ ) // search for end-of-string + + return (unsigned int)(c - str); // get size by delta-address + +} + +char* strcat(char* buf, char* str) { + unsigned int bufferlen = strlen(buf); + + // remove the 0x0 char from the buffer + *(buf + bufferlen) = 0x3f; // placeholder + + // concat the str to buf + for( char* c = str; *c != '\0'; c++ ) { + + } +} diff --git a/lib/str.h b/lib/str.h new file mode 100644 index 0000000..f50e596 --- /dev/null +++ b/lib/str.h @@ -0,0 +1,2 @@ +unsigned int strlen(char* str); +char* strcat(char* buf, char* str); diff --git a/lib/strf.c b/lib/strf.c index 5259262..65dddc7 100644 --- a/lib/strf.c +++ b/lib/strf.c @@ -3,13 +3,13 @@ #define int_offset 48 // 0:48 - 9:57 -char* int_to_str(int i) { - char* strbuf = "XXXXXX"; - - while( i > 0 ) { - *(strbuf + 1) = (i % 10) + int_offset; - i /= 10; +char* int_to_str(int i, char* strbuf) { + if( i == 0 ) { + return (char*)(int_offset); + } else { + char cbuf; + cbuf = (char)((i % 10) + int_offset); + + return int_to_str(i / 10, strbuf + cbuf); } - - return strbuf; } diff --git a/lib/strf.h b/lib/strf.h index 2046d91..29649bc 100644 --- a/lib/strf.h +++ b/lib/strf.h @@ -1 +1 @@ -char* int_to_str(int i); +char* int_to_str(int i, char* strbuf); From d7b97a830be0a9a3c7a596edcbe3854598172b49 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:28:16 +0200 Subject: [PATCH 06/10] Borked strcat --- kernel/kernel.c | 9 +++++---- lib/str.c | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/kernel.c b/kernel/kernel.c index f7ea26c..0333a43 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,14 +1,15 @@ #include "../drivers/vga.h" +#include "../lib/str.h" #include "../lib/strf.h" void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. - int test = 1234; - char* teststr; - teststr = int_to_str(test, teststr); - println(teststr, 0xf0); + char* strbuf = "HEJ"; + char* str2 = "xD"; + strbuf = strcat(strbuf, str2); + println(strbuf, 0xf0); set_cursor_pos(28, 2); print("eOS Version 0.1 2021", 0xf0); diff --git a/lib/str.c b/lib/str.c index a0a7ef7..0153b87 100644 --- a/lib/str.c +++ b/lib/str.c @@ -5,7 +5,6 @@ unsigned int strlen(char* str) { for( c = str; *c != '\0'; c++ ) // search for end-of-string return (unsigned int)(c - str); // get size by delta-address - } char* strcat(char* buf, char* str) { @@ -15,7 +14,11 @@ char* strcat(char* buf, char* str) { *(buf + bufferlen) = 0x3f; // placeholder // concat the str to buf + int cc = 0; for( char* c = str; *c != '\0'; c++ ) { - + *(buf + bufferlen + cc) = *c; + cc++; } + + return buf; } From b671216aa9b6fd15b6f53f5f0cb8566f2456ffe6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:33:28 +0200 Subject: [PATCH 07/10] Refactor --- lib/str.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/str.c b/lib/str.c index 0153b87..b95af7b 100644 --- a/lib/str.c +++ b/lib/str.c @@ -1,10 +1,11 @@ #include "str.h" unsigned int strlen(char* str) { - char* c; - for( c = str; *c != '\0'; c++ ) // search for end-of-string - - return (unsigned int)(c - str); // get size by delta-address + unsigned int len = 0; + for( char* c = str; *c != '\0'; c++ ) // search for end-of-string + len++; + + return len; } char* strcat(char* buf, char* str) { @@ -20,5 +21,7 @@ char* strcat(char* buf, char* str) { cc++; } + *(buf + bufferlen + cc) = '\0'; // add end-of-string + return buf; } From ce864a724ea44f90badf4db46aefd7f6d4237502 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:42:10 +0200 Subject: [PATCH 08/10] TODO & String library --- TODO.md | 7 ++++++- kernel/kernel.c | 4 ++-- lib/str.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index de50dd2..32bdb54 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,10 @@ # TO DO - - String formating + - Malloc + - String Library + + - Concat + - Format + - Scrolling - Multiboot support (for grub etc) - Rendering (VGA) diff --git a/kernel/kernel.c b/kernel/kernel.c index 0333a43..8ea9e47 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -6,8 +6,8 @@ void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. - char* strbuf = "HEJ"; - char* str2 = "xD"; + char* strbuf = "Hello"; + char* str2 = "World!"; strbuf = strcat(strbuf, str2); println(strbuf, 0xf0); diff --git a/lib/str.c b/lib/str.c index b95af7b..d9345e1 100644 --- a/lib/str.c +++ b/lib/str.c @@ -12,7 +12,8 @@ char* strcat(char* buf, char* str) { unsigned int bufferlen = strlen(buf); // remove the 0x0 char from the buffer - *(buf + bufferlen) = 0x3f; // placeholder + *(buf + bufferlen) = 0x3f; // replace end-of-string + // with a placeholder // concat the str to buf int cc = 0; From d65c73fc9edd46f312f7ab61b64e7df2dc95d0bc Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:51:07 +0200 Subject: [PATCH 09/10] Memory alloc --- kernel/memory.c | 1 + kernel/memory.h | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 kernel/memory.c create mode 100644 kernel/memory.h diff --git a/kernel/memory.c b/kernel/memory.c new file mode 100644 index 0000000..b31569d --- /dev/null +++ b/kernel/memory.c @@ -0,0 +1 @@ +#include "memory.h" diff --git a/kernel/memory.h b/kernel/memory.h new file mode 100644 index 0000000..b2b140d --- /dev/null +++ b/kernel/memory.h @@ -0,0 +1,2 @@ +char* malloc(unsigned int size); +void mfree(char* p); From 02faf041ffdd13b925f443262a0a537088f1e847 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:54:25 +0200 Subject: [PATCH 10/10] Refactor & darkmode --- drivers/vga.c | 2 +- kernel/kernel.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index c53692b..2138ab7 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -50,7 +50,7 @@ void set_cursor_pos(unsigned int col, unsigned int row) { void clear_screen() { for( int c = 0; c < MAX_COLS; c++ ) for( int r = 0; r < MAX_ROWS; r++ ) - writechar(0x20, c, r, 0xf0); + writechar(0x20, c, r, 0x0f); } /* diff --git a/kernel/kernel.c b/kernel/kernel.c index 8ea9e47..13aacf8 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -6,11 +6,13 @@ void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. + set_cursor_pos(28, 2); + print("eOS Version 0.1 2021", 0x0f); + + char* strbuf = "Hello"; char* str2 = "World!"; strbuf = strcat(strbuf, str2); - println(strbuf, 0xf0); - - set_cursor_pos(28, 2); - print("eOS Version 0.1 2021", 0xf0); + set_cursor_pos(0, 0); + println(strbuf, 0x0f); }