summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-14 18:41:09 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-05-14 18:41:09 +0200
commite47f8666ec59b9726cc0daee98872bdc4ea6fe3e (patch)
tree376644302801d6972e457431d573f564f2d87c4c
parent5bebcc939adc868110a91b9bd0c013208f6f1779 (diff)
downloadabaos-e47f8666ec59b9726cc0daee98872bdc4ea6fe3e.tar.gz
abaos-e47f8666ec59b9726cc0daee98872bdc4ea6fe3e.tar.bz2
added a simple kernel console which can use VGA and the first serial port for output
(no terminal emulation, only sequential output) shows how to intermix VGA animations and line-orinented console output
-rw-r--r--src/Makefile8
-rw-r--r--src/console.c51
-rw-r--r--src/console.h19
-rw-r--r--src/kernel.c20
-rw-r--r--src/serial.c12
-rw-r--r--src/serial.h2
6 files changed, 103 insertions, 9 deletions
diff --git a/src/Makefile b/src/Makefile
index fed5c71..52a628b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,9 +18,10 @@ image.bin: boot.bin kernel.bin magic.bin
boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm
nasm boot.asm -f bin -o boot.bin
-kernel.bin: kernel.o vga.o serial.o port.o port_asm.o string.o stdlib.o
+kernel.bin: kernel.o console.o vga.o serial.o port.o port_asm.o string.o stdlib.o
$(LD) -o kernel.bin -N -n -Ttext 0x8400 --oformat binary \
- kernel.o vga.o serial.o port.o port_asm.o string.o stdlib.o
+ kernel.o console.o vga.o serial.o port.o port_asm.o \
+ string.o stdlib.o
magic.bin: magic.asm
nasm magic.asm -f bin -o magic.bin
@@ -31,6 +32,9 @@ kernel.o: kernel.c
port.o: port.c port.h
$(CC) $(CFLAGS) -c -o port.o port.c
+console.o: console.c console.h vga.h serial.h
+ $(CC) $(CFLAGS) -c -o console.o console.c
+
vga.o: vga.c vga.h
$(CC) $(CFLAGS) -c -o vga.o vga.c
diff --git a/src/console.c b/src/console.c
new file mode 100644
index 0000000..d9ae941
--- /dev/null
+++ b/src/console.c
@@ -0,0 +1,51 @@
+#include "console.h"
+
+#include "string.h"
+
+void console_init( console_t *console )
+{
+ memset( console, 0, sizeof( console_t ) );
+}
+
+void console_add_vga_output( console_t *console, vga_t *vga )
+{
+ console->vga = vga;
+}
+
+void console_add_serial_output( console_t *console, serial_t *serial )
+{
+ console->serial = serial;
+}
+
+void console_put_char( console_t *console, const char c )
+{
+ if( console->vga ) {
+ vga_put_char( console->vga, c );
+ }
+
+ if( console->serial ) {
+ serial_put_char( console->serial, c );
+ }
+}
+
+void console_put_string( console_t *console, const char *s )
+{
+ if( console->vga ) {
+ vga_put_string( console->vga, s );
+ }
+
+ if( console->serial ) {
+ serial_put_string( console->serial, s );
+ }
+}
+
+void console_put_newline( console_t *console )
+{
+ if( console->vga ) {
+ vga_put_newline( console->vga );
+ }
+
+ if( console->serial ) {
+ serial_put_newline( console->serial );
+ }
+}
diff --git a/src/console.h b/src/console.h
new file mode 100644
index 0000000..a792e0d
--- /dev/null
+++ b/src/console.h
@@ -0,0 +1,19 @@
+#ifndef CONSOLE_H
+#define CONSOLE_H
+
+#include "vga.h"
+#include "serial.h"
+
+typedef struct console_t {
+ vga_t *vga;
+ serial_t *serial;
+} console_t;
+
+void console_init( console_t *console );
+void console_add_vga_output( console_t *console, vga_t *vga );
+void console_add_serial_output( console_t *console, serial_t *serial );
+void console_put_char( console_t *console, const char c );
+void console_put_string( console_t *console, const char *s );
+void console_put_newline( console_t *console );
+
+#endif // CONSOLE_H
diff --git a/src/kernel.c b/src/kernel.c
index 5021813..91546a6 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -2,21 +2,25 @@
#include "vga.h"
#include "serial.h"
+#include "console.h"
void entry( void )
-{
+{
serial_t serial;
serial_init( &serial );
- serial_put_char( &serial, 'A' );
- serial_put_char( &serial, '\n' );
vga_t vga;
vga_init( &vga );
-
+
+ console_t console;
+ console_init( &console );
+ console_add_vga_output( &console, &vga );
+ console_add_serial_output( &console, &serial );
+
vga_set_color( &vga, VGA_COLOR_LIGHT_GREY );
vga_set_background_color( &vga, VGA_COLOR_BLACK );
- vga_put_string( &vga, "ABAOS 0.0.1 STARTING" );
+ console_put_string( &console, "Initializing hardware" );
const char bar[] = "\\|/-";
int y_pos = vga_get_cursor_y( &vga );
@@ -26,14 +30,16 @@ void entry( void )
if( i % 1000 == 0 ) {
vga_put_char_at( &vga, x_pos, y_pos, '.' );
x_pos++;
+ serial_put_char( &serial, '.' );
}
vga_put_char_at( &vga, x_pos, y_pos, bar[i%4] );
for( int j = 0; j < 150; j++ ) {
}
}
vga_put_char_at( &vga, x_pos, y_pos, '.' );
- vga_put_newline( &vga );
-
+ serial_put_char( &serial, '.' );
+ 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/serial.c b/src/serial.c
index 3ef1a43..c67f765 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -19,6 +19,18 @@ void serial_put_char( serial_t *serial, const char c )
port8_write( &serial->port_3F8, c );
}
+void serial_put_string( serial_t *serial, const char *s )
+{
+ for( size_t i = 0; i < strlen( s ); i++ ) {
+ serial_put_char( serial, s[i] );
+ }
+}
+
+void serial_put_newline( serial_t *serial )
+{
+ serial_put_char( serial, '\n' );
+}
+
//~ outb(0x3FB, 0x83); /* DLAB = 1 */
//~ outb(0x3F8, 0x0C); /* 9600 Baud */
//~ outb(0x3F9, 0x00);
diff --git a/src/serial.h b/src/serial.h
index f302b93..4f665b2 100644
--- a/src/serial.h
+++ b/src/serial.h
@@ -10,5 +10,7 @@ typedef struct serial_t {
void serial_init( serial_t *serial );
void serial_put_char( serial_t *serial, const char c );
+void serial_put_string( serial_t *serial, const char *s );
+void serial_put_newline( serial_t *serial );
#endif // SERIAL_H