summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-20 14:15:32 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-05-20 14:15:32 +0200
commit6ca6c71e87d348e69167f2cd97547b76ccd12f0d (patch)
tree06f8091e2add4935ec3dd761a3d5a528d2ba5510
parent4c59f7360514aa6c67ba2fbaa09d4cc9e3139957 (diff)
downloadabaos-6ca6c71e87d348e69167f2cd97547b76ccd12f0d.tar.gz
abaos-6ca6c71e87d348e69167f2cd97547b76ccd12f0d.tar.bz2
added simple stdio stub
-rw-r--r--DESIGN3
-rw-r--r--src/Makefile7
-rw-r--r--src/console.c11
-rw-r--r--src/console.h3
-rw-r--r--src/interrupts.asm2
-rw-r--r--src/interrupts.c10
-rw-r--r--src/interrupts.h5
-rw-r--r--src/kernel.c14
-rw-r--r--src/serial.c9
-rw-r--r--src/serial.h3
-rw-r--r--src/stddef.h2
-rw-r--r--src/string.c10
-rw-r--r--src/vga.c9
-rw-r--r--src/vga.h3
14 files changed, 43 insertions, 48 deletions
diff --git a/DESIGN b/DESIGN
index b9a899b..55bd28c 100644
--- a/DESIGN
+++ b/DESIGN
@@ -25,3 +25,6 @@ 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.
+Use standard C functions early on, even if they have to be glued
+funnilly to early functions as in VGA text console, etc.
+
diff --git a/src/Makefile b/src/Makefile
index 8507c72..e46db57 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -28,10 +28,10 @@ kernel.bin: kernel.elf
kernel.sym: kernel.elf
$(OBJCOPY) --only-keep-debug kernel.elf kernel.sym
-kernel.elf: kernel.o console.o vga.o serial.o port.o port_asm.o interrupts.o interrupts_asm.o string.o stdlib.o
+kernel.elf: kernel.o console.o vga.o serial.o port.o port_asm.o interrupts.o interrupts_asm.o string.o stdlib.o stdio.o
$(LD) -o kernel.elf -N -n -Ttext 0x8400 --oformat elf32-i386 \
kernel.o console.o vga.o serial.o port.o port_asm.o \
- interrupts.o interrupts_asm.o string.o stdlib.o
+ interrupts.o interrupts_asm.o string.o stdlib.o stdio.o
magic.bin: magic.asm
$(NASM) magic.asm -DMAGIC='"$(MAGIC)"' -f bin -o magic.bin
@@ -66,6 +66,9 @@ string.o: string.c string.h
stdlib.o: stdlib.c stdlib.h
$(CC) $(CFLAGS) -c -o stdlib.o stdlib.c
+stdio.o: stdio.c stdio.h
+ $(CC) $(CFLAGS) -c -o stdio.o stdio.c
+
clean:
-rm -f boot.bin kernel.bin kernel.sym kernel.elf image.bin magic.bin *.o boot.map image.tmp
diff --git a/src/console.c b/src/console.c
index ea57d07..ef4c36f 100644
--- a/src/console.c
+++ b/src/console.c
@@ -43,17 +43,6 @@ void console_put_string( console_t *console, const char *s )
}
}
-void console_put_hex( console_t *console, const uint32_t v )
-{
- if( console->vga != NULL ) {
- vga_put_hex( console->vga, v );
- }
-
- if( console->serial != NULL ) {
- serial_put_hex( console->serial, v );
- }
-}
-
void console_put_newline( console_t *console )
{
if( console->vga != NULL ) {
diff --git a/src/console.h b/src/console.h
index b87eed4..f8eccff 100644
--- a/src/console.h
+++ b/src/console.h
@@ -1,8 +1,6 @@
#ifndef CONSOLE_H
#define CONSOLE_H
-#include <stdint.h>
-
#include "vga.h"
#include "serial.h"
@@ -16,7 +14,6 @@ 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_hex( console_t *console, const uint32_t v );
void console_put_newline( console_t *console );
#endif // CONSOLE_H
diff --git a/src/interrupts.asm b/src/interrupts.asm
index d5d67c9..2a09783 100644
--- a/src/interrupts.asm
+++ b/src/interrupts.asm
@@ -16,3 +16,5 @@ interrupts_disable:
cli
leave
ret
+
+; uint32_t interrpts_handle_interrupt( uint8_t interrupt_no, uint32_t esp );
diff --git a/src/interrupts.c b/src/interrupts.c
index a3eea59..c456774 100644
--- a/src/interrupts.c
+++ b/src/interrupts.c
@@ -1,8 +1,18 @@
#include "interrupts.h"
#include "string.h"
+#include "stdio.h"
void interrupts_init( interrupt_t *interrupts )
{
memset( interrupts, 0, sizeof( interrupt_t ) );
}
+
+uint32_t interrupts_handle_interrupt( uint8_t interrupt_no, uint32_t esp )
+{
+ puts( "interrupt" );
+
+ // for now, we are using the same stack for kernel and interrupt
+ // handlers (n task switching)
+ return esp;
+}
diff --git a/src/interrupts.h b/src/interrupts.h
index 01406e3..d4ceab6 100644
--- a/src/interrupts.h
+++ b/src/interrupts.h
@@ -1,11 +1,14 @@
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
+#include <stdint.h>
+
typedef struct {
} interrupt_gate_descriptor_t;
typedef struct {
+
} interrupt_t;
void interrupts_enable( void );
@@ -13,6 +16,8 @@ void interrupts_disable( void );
void interrupts_init( interrupt_t *interrupt );
+uint32_t interrupts_handle_interrupt( uint8_t interrupt_no, uint32_t esp );
+
// initialize IDT
// handle gates
// assembly trampolines calling C (static) functions
diff --git a/src/kernel.c b/src/kernel.c
index 5080156..a3ff1d7 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -4,6 +4,7 @@
#include "serial.h"
#include "console.h"
#include "stdlib.h"
+#include "stdio.h"
#include "interrupts.h"
void entry( void )
@@ -20,16 +21,22 @@ void entry( void )
console_init( &console );
console_add_vga_output( &console, &vga );
console_add_serial_output( &console, &serial );
+
+ // initialize the early console of the kernel
+ stdio_set_console( &console );
+ puts( "Started early kernel console" );
+ printf( "Kernel code and data is at 0x%X, kernel stack at 0x%X\n", 0x8400, 0x90000 );
+ puts( "Initializing interrupts" );
interrupt_t interrupt;
interrupts_init( &interrupt );
//~ interrupts_enable( );
int y = 1;
int x = 12 / y;
- console_put_hex( &console, x );
+ printf( "Hex number is 0x%X and string is '%s'\n", x, "abaos" );
- console_put_string( &console, "Initializing hardware" );
+ console_put_string( &console, "Running.." );
const char bar[] = "\\|/-";
int y_pos = vga_get_cursor_y( &vga );
@@ -50,6 +57,5 @@ void entry( void )
console_put_newline( &console );
- console_put_string( &console, "Terminating" );
- console_put_newline( &console );
+ puts( "Terminating" );
}
diff --git a/src/serial.c b/src/serial.c
index 409b024..aba329c 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -27,15 +27,6 @@ void serial_put_string( serial_t *serial, const char *s )
}
}
-void serial_put_hex( serial_t *serial, const uint32_t v )
-{
- char buf[19];
-
- serial_put_string( serial, "0x" );
- itoa( v, (char *)buf, 16 );
- serial_put_string( serial, (const char *)buf );
-}
-
void serial_put_newline( serial_t *serial )
{
serial_put_char( serial, '\n' );
diff --git a/src/serial.h b/src/serial.h
index 15eca00..2fd66e5 100644
--- a/src/serial.h
+++ b/src/serial.h
@@ -1,8 +1,6 @@
#ifndef SERIAL_H
#define SERIAL_H
-#include <stdint.h>
-
#include "port.h"
typedef struct {
@@ -13,7 +11,6 @@ typedef struct {
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_hex( serial_t *serial, const uint32_t v );
void serial_put_newline( serial_t *serial );
#endif // SERIAL_H
diff --git a/src/stddef.h b/src/stddef.h
index 962e1aa..57a0297 100644
--- a/src/stddef.h
+++ b/src/stddef.h
@@ -3,4 +3,6 @@
#define NULL ( (void *)0 )
+#define size_t uint32_t
+
#endif /* STDDEF_H */
diff --git a/src/string.c b/src/string.c
index a229739..3de194a 100644
--- a/src/string.c
+++ b/src/string.c
@@ -17,13 +17,15 @@ void *memmove( void *d, const void *s, size_t n )
if( dd == ss ) return d;
if( dd <= ss ) {
- while( n-- ) {
+ n--;
+ while( n > 0 ) {
*dd++ = *ss++;
}
} else {
dd += n;
ss += n;
- while( n-- ) {
+ n--;
+ while( n > 0 ) {
*--dd = *--ss;
}
}
@@ -55,13 +57,13 @@ size_t strlcpy( char *d, const char *s, size_t n )
{
size_t len = 0;
- while( len < n && s[len] ) {
+ while( len < n && s[len] != '\0' ) {
d[len] = s[len];
len++;
}
d[len] = '\0';
- while( s[len] ) {
+ while( s[len] != '\0' ) {
len++;
}
diff --git a/src/vga.c b/src/vga.c
index 609b831..1b8dde4 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -186,15 +186,6 @@ void vga_put_string( vga_t *vga, const char *s )
}
}
-void vga_put_hex( vga_t *vga, const uint32_t v )
-{
- char buf[19];
-
- vga_put_string( vga, "0x" );
- itoa( v, (char *)buf, 16 );
- vga_put_string( vga, (const char *)buf );
-}
-
void vga_put_newline( vga_t *vga )
{
vga->cursor_x = 0;
diff --git a/src/vga.h b/src/vga.h
index 47cc96f..ebe402c 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -1,8 +1,6 @@
#ifndef VGA_H
#define VGA_H
-#include <stdint.h>
-
#include "port.h"
enum {
@@ -54,7 +52,6 @@ void vga_put_char_at( vga_t *vga, const int x, const int y, const char c );
void vga_put_string_at( vga_t *vga, const int x, const int y, const char *s );
void vga_put_char( vga_t *vga, const char c );
void vga_put_string( vga_t *vga, const char *s );
-void vga_put_hex( vga_t *vga, const uint32_t v );
void vga_put_newline( vga_t *vga );
#endif /* VGA_H */