From d6b64c65a0d09dba96a65edd2959bd58fe781fcc Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 14 May 2017 19:20:38 +0200 Subject: some small fixes, clang image overload (magic doesn't work, most likely because memory is not wiped between qemu invocations) --- DESIGN | 12 ++++++++++++ doc/README.Tyndur | 2 ++ src/Makefile | 4 ++-- src/console.c | 16 ++++++++++------ src/kernel.c | 6 +++++- src/stage1_functions.asm | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/DESIGN b/DESIGN index b7ba1e2..b9a899b 100644 --- a/DESIGN +++ b/DESIGN @@ -1,11 +1,22 @@ design principles ----------------- +The final goal is a self-hosting, self-compiling system, so we will +have to implement or port the assember, the C compiler, a linker and +a make program into the new operating system. So featuritis and +non-standards will kill the project fast! + Use strict ANSI C99. This means no inline-assembly. This means we have to write assembly routines if we need things not available in C (lgdt, in, out, etc.). +Use the cdecl calling convetion when calling assembly from C. +Stick to NASM assembly bare features (equ, org). Use only the absolute +minimum. Make sure it compiles with every ANSI C99 compiler (gcc, clang, tcc, ...). +Use only what is needed, nothing fancy. +Try to compile as often as possible with different compilers on different +host systems. Use only very simple makefile rules. Make sure we could also just use a simple shell script to compile the kernel. @@ -13,3 +24,4 @@ use a simple shell script to compile the kernel. Avoid implementation and using of unsafe C functions. Provide safe counterparts wherever possible. There are of course exceptions like scrolling the VGA buffer with a memmove. + diff --git a/doc/README.Tyndur b/doc/README.Tyndur index 26fd0a3..6e9b644 100644 --- a/doc/README.Tyndur +++ b/doc/README.Tyndur @@ -1,2 +1,4 @@ http://www.lowlevel.eu/wiki/Týndur/Entwicklung git clone git://git.tyndur.org/tyndur.git + +inspired by console.c: especially the idea of having output to VGA and serial diff --git a/src/Makefile b/src/Makefile index 52a628b..c2b91fa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,8 +11,8 @@ image.bin: boot.bin kernel.bin magic.bin # + M * 512 (M is currently 7) = 3144 for kernel.bin # + 1 * 512 = 512 for magic.bin # (M + N + 1 is the number of sectors to be read in stage 2, as stage 1 - # loads only the first sector, so adapt NOF_LOAD_SECTORS to 10) - truncate -s 5632 image.tmp + # loads only the first sector, so adapt NOF_LOAD_SECTORS to 12) + truncate -s 6656 image.tmp cat image.tmp magic.bin > image.bin boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm diff --git a/src/console.c b/src/console.c index d9ae941..ef4c36f 100644 --- a/src/console.c +++ b/src/console.c @@ -1,10 +1,14 @@ #include "console.h" #include "string.h" +#include "stddef.h" void console_init( console_t *console ) { memset( console, 0, sizeof( console_t ) ); + + console->vga = NULL; + console->serial = NULL; } void console_add_vga_output( console_t *console, vga_t *vga ) @@ -19,33 +23,33 @@ void console_add_serial_output( console_t *console, serial_t *serial ) void console_put_char( console_t *console, const char c ) { - if( console->vga ) { + if( console->vga != NULL ) { vga_put_char( console->vga, c ); } - if( console->serial ) { + if( console->serial != NULL ) { serial_put_char( console->serial, c ); } } void console_put_string( console_t *console, const char *s ) { - if( console->vga ) { + if( console->vga != NULL ) { vga_put_string( console->vga, s ); } - if( console->serial ) { + if( console->serial != NULL ) { serial_put_string( console->serial, s ); } } void console_put_newline( console_t *console ) { - if( console->vga ) { + if( console->vga != NULL ) { vga_put_newline( console->vga ); } - if( console->serial ) { + if( console->serial != NULL ) { serial_put_newline( console->serial ); } } diff --git a/src/kernel.c b/src/kernel.c index 91546a6..2cbe40a 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -38,8 +38,12 @@ void entry( void ) } vga_put_char_at( &vga, x_pos, y_pos, '.' ); serial_put_char( &serial, '.' ); - console_put_newline( &console ); + console_put_newline( &console ); + + console_put_string( &console, "Terminating" ); + console_put_newline( &console ); + //~ vga_set_color( &vga, VGA_COLOR_WHITE ); //~ vga_set_background_color( &vga, VGA_COLOR_RED ); //~ vga_clear_screen( &vga ); diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm index c43da4d..854b3b4 100644 --- a/src/stage1_functions.asm +++ b/src/stage1_functions.asm @@ -2,7 +2,7 @@ ; 3 * 512 for bootloader stage2 and the kernel code ; (note: the first sector gets loaded by the BIOS, so ; subtract 1 here!) -NOF_LOAD_SECTORS equ 11 +NOF_LOAD_SECTORS equ 13 ; IN bx: begin of memory area to dump ; IN ax: number of words to dump -- cgit v1.2.3-54-g00ecf