summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile22
-rw-r--r--src/kernel.c10
-rw-r--r--src/port.h5
-rw-r--r--src/stage1_functions.asm7
-rw-r--r--src/string.c11
-rw-r--r--src/string.h8
-rw-r--r--src/sys/types.h8
-rw-r--r--src/vga.c31
-rw-r--r--src/vga.h4
9 files changed, 92 insertions, 14 deletions
diff --git a/src/Makefile b/src/Makefile
index 94fb3f1..fcde58d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
CC := gcc
-CFLAGS := -std=c99 -m32 -ffreestanding -Os -g -Wall -Werror
+CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror
LD := ld
all: image.bin
@@ -7,26 +7,30 @@ all: image.bin
image.bin: boot.bin kernel.bin
cat boot.bin kernel.bin > image.bin
# truncate to correct number of sectors, we have
- # 512 (boot) + N * 1024 (N currenty is 2)
- truncate -s 2560 image.bin
+ # 512 (boot, first stage) + N * 512 (N currenty is 3) + M * 512 (M is currently 2)
+ truncate -s 3072 image.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
- $(LD) -o kernel.bin -Ttext 0x8000 kernel.o --oformat binary
+kernel.bin: kernel.o vga.o string.o
+ $(LD) -o kernel.bin -Ttext 0x8000 -m elf_i386 --oformat binary \
+ kernel.o vga.o string.o
kernel.o: kernel.c
$(CC) $(CFLAGS) -O0 -c -o kernel.o kernel.c
+vga.o: vga.c
+ $(CC) $(CFLAGS) -O0 -c -o vga.o vga.c
+
+string.o: string.c
+ $(CC) $(CFLAGS) -O0 -c -o string.o string.c
+
clean:
-rm -f boot.bin kernel.bin image.bin *.o
run-qemu: image.bin
- qemu-system-i386 -m 16 -drive "file=image.bin,if=ide,format=raw"
+ qemu-system-i386 -m 32 -drive "file=image.bin,if=ide,format=raw"
run-bochs:
bochs -q -f bochs.config 'boot:floppy' 'floppya: 1_44=image.bin, status=inserted'
-
-functions.o: functions.c
- $(CC) $(CFLAGS) -c -o functions.o functions.c
diff --git a/src/kernel.c b/src/kernel.c
index 2531c03..70c2b79 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1,5 +1,7 @@
#include <stdint.h>
+#include "vga.h"
+
void entry( void )
{
volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xb8000;
@@ -14,7 +16,7 @@ void entry( void )
volatile uint8_t bar[] = "\\|/-";
int pos = 10;
int i = 0;
- for( i = 0; i < 20000; i++ ) {
+ for( i = 0; i < 10000; i++ ) {
if( i % 1000 == 0 ) {
*(VIDEO_MEMORY+pos) = '.';
*(VIDEO_MEMORY+pos+1) = 0x07;
@@ -22,7 +24,11 @@ void entry( void )
}
*(VIDEO_MEMORY+pos) = bar[i%4];
*(VIDEO_MEMORY+pos+1) = 0x07;
- for( int j = 0; j < 10000; j++ ) {
+ for( int j = 0; j < 1000; j++ ) {
}
}
+
+ vga_t vga;
+ vga_init( &vga );
+ vga_clear_screen( &vga );
}
diff --git a/src/port.h b/src/port.h
new file mode 100644
index 0000000..a4621de
--- /dev/null
+++ b/src/port.h
@@ -0,0 +1,5 @@
+#ifndef PORT_H
+#define PORT_H
+
+
+#endif /* PORT_H */
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm
index 859ee66..35a0dbb 100644
--- a/src/stage1_functions.asm
+++ b/src/stage1_functions.asm
@@ -1,8 +1,9 @@
; number of sectors to be read
; this is 512 (the bootloader stage1) +
-; N * 1024 for bootloader stage2 and the kernel code
-; (note: the first sector gets loaded by the BIOS)
-NOF_LOAD_SECTORS equ 4
+; 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 5
; IN bx: begin of memory area to dump
; IN ax: number of words to dump
diff --git a/src/string.c b/src/string.c
new file mode 100644
index 0000000..30ccba6
--- /dev/null
+++ b/src/string.c
@@ -0,0 +1,11 @@
+#include "string.h"
+
+void *memset( void *s, int c, size_t n )
+{
+ for( size_t i = 0; i < n; i++ ) {
+ ((uint8_t *)s)[i] = c;
+ }
+
+ return s;
+}
+
diff --git a/src/string.h b/src/string.h
new file mode 100644
index 0000000..c380155
--- /dev/null
+++ b/src/string.h
@@ -0,0 +1,8 @@
+#ifndef STRING_H
+#define STRING_H
+
+#include "sys/types.h"
+
+void *memset( void *s, int c, size_t n );
+
+#endif /* STRING_H */
diff --git a/src/sys/types.h b/src/sys/types.h
new file mode 100644
index 0000000..1ec9642
--- /dev/null
+++ b/src/sys/types.h
@@ -0,0 +1,8 @@
+#ifndef SYS_TYPES_H
+#define SYS_TYPES_H
+
+#include <stdint.h>
+
+typedef uint32_t size_t;
+
+#endif /* SYS_TYPES_H */
diff --git a/src/vga.c b/src/vga.c
index 26208a0..77ef043 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -1 +1,32 @@
#include "vga.h"
+
+#include "string.h"
+
+void vga_init( vga_t *vga )
+{
+ memset( vga, 0, sizeof( vga_t ) );
+
+ vga->res_x = VGA_DEFAULT_RES_X;
+ vga->res_y = VGA_DEFAULT_RES_Y;
+
+ // TODO: get current position from VGA hardware
+ //~ vga_set_cursor( vga, 0, 0 );
+};
+
+void vga_clear_screen( vga_t *vga )
+{
+ volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xb8000;
+
+ for( int i = 0; i < 2 * ( vga->res_x * vga->res_y ); i += 2 ) {
+ *(VIDEO_MEMORY+i) = ' ';
+ *(VIDEO_MEMORY+i+1) = 0x4f;
+ }
+
+ //~ vga_set_cursor( vga, 0, 0 );
+}
+
+void vga_set_cursor( vga_t *vga, int x, int y )
+{
+ vga->cursor_x = x;
+ vga->cursor_y = y;
+}
diff --git a/src/vga.h b/src/vga.h
index 49fe8f2..a13c148 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -15,4 +15,8 @@ typedef struct vga_t {
int cursor_y; // current cursor position Y
} vga_t;
+void vga_init( vga_t *vga );
+void vga_clear_screen( vga_t *vga );
+void vga_set_cursor( vga_t *vga, int x, int y );
+
#endif /* VGA_H */