summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/boot.asm31
-rw-r--r--src/kernel.c36
2 files changed, 67 insertions, 0 deletions
diff --git a/src/boot.asm b/src/boot.asm
new file mode 100644
index 0000000..cbf57d6
--- /dev/null
+++ b/src/boot.asm
@@ -0,0 +1,31 @@
+;> The Multiboot header must be contained completely within the first 8192 bytes of the OS
+;> image, and must be longword (32-bit) aligned.
+MULTIBOOT_ALIGN_TO_PAGE: equ 1 << 0
+MULTIBOOT_MEMORY_DESCRIBE: equ 1 << 2
+MULTIBOOT_MAGIC: equ 0x1BADB002
+MULTIBOOT_FLAGS: equ (MULTIBOOT_ALIGN_TO_PAGE | MULTIBOOT_MEMORY_DESCRIBE)
+MULTIBOOT_CHECKSUM: equ -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)
+section .multiboot_header
+align 4
+ dd MULTIBOOT_MAGIC
+ dd MULTIBOOT_FLAGS
+ dd MULTIBOOT_CHECKSUM
+
+STACK_SIZE: equ (1 << 14)
+section .bss
+align 16
+stack_bottom:
+ resb STACK_SIZE
+stack_top:
+
+section .text
+global _start:function (_start.end - _start)
+_start:
+ mov esp, stack_top
+ extern cmain
+ call cmain
+ cli
+
+jmp $
+
+.end:
diff --git a/src/kernel.c b/src/kernel.c
new file mode 100644
index 0000000..1459f73
--- /dev/null
+++ b/src/kernel.c
@@ -0,0 +1,36 @@
+#include <stddef.h>
+#include <stdint.h>
+
+#define WIDTH 80
+#define HEIGHT 25
+
+#define BLACK 0
+#define BLUE 1
+#define GREEN 2
+#define RED 4
+#define MAGENTA 13
+#define WHITE 15
+
+int strlen(char* s) {
+ int n = 0;
+ char* s_ptr = s;
+ while (*(s_ptr++)) {
+ n++;
+ }
+ return n;
+}
+
+void cmain(void) {
+ uint16_t* vgamem = (uint16_t*) 0xB8000;
+ uint16_t vgacolors[6] = {WHITE | RED << 4, WHITE | GREEN << 4, WHITE | BLUE << 4, BLACK | RED << 4, BLACK | GREEN << 4, BLACK | BLUE << 4};
+ char* s = "Hello world!";
+ int i,j,k;
+ for (k = 0; k >= 0; ++k) {
+ k = (k % 5);
+ j = 0;
+ while (j < 100000000) { j++; } // Since we don't have an interrupt descriptor table we can't use the PIC; this emulates "sleeping"
+ for (i = 0; i < WIDTH*HEIGHT; i++) {
+ vgamem[i] = s[i % strlen(s)] | vgacolors[(i+k) % 6] << 8;
+ }
+ }
+} \ No newline at end of file