diff options
-rw-r--r-- | doc/internal/gdt.txt | 3 | ||||
-rw-r--r-- | doc/internal/mem.txt | 4 | ||||
-rw-r--r-- | makefile | 21 | ||||
-rw-r--r-- | src/boot.asm | 55 | ||||
-rw-r--r-- | src/kernel/link.ld | 15 | ||||
-rw-r--r-- | src/kernel/main.c | 7 | ||||
-rw-r--r-- | src/kernel/vga.c | 14 | ||||
-rw-r--r-- | src/kernel/vga.h | 3 |
8 files changed, 122 insertions, 0 deletions
diff --git a/doc/internal/gdt.txt b/doc/internal/gdt.txt new file mode 100644 index 0000000..f260cfe --- /dev/null +++ b/doc/internal/gdt.txt @@ -0,0 +1,3 @@ +0x08: 0x0000.0000 - 0x0007.ffff (code) +0x10: 0x0000.0000 - 0x0007.ffff (data) +0x18: 0x0003.8000 - 0x0003.ffff (stack)
\ No newline at end of file diff --git a/doc/internal/mem.txt b/doc/internal/mem.txt new file mode 100644 index 0000000..d3b7696 --- /dev/null +++ b/doc/internal/mem.txt @@ -0,0 +1,4 @@ +0x0001.0000 - 0x0002.ffff: unused +0x0003.0000 - 0x0003.7fff: kernel +0x0003.8000 - 0x0003.ffff: stack +0x0004.0000 - 0x0007.ffff: unused
\ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..efb5cf8 --- /dev/null +++ b/makefile @@ -0,0 +1,21 @@ +floppy: kernel boot + mkdir -p obj out + /sbin/mkfs.fat -C -R 17 -n "PORTLAND OS" obj/shadow.img 1440 + echo -n -e '\xeb\x3c' > obj/jmp.bin + dd if=obj/jmp.bin of=obj/shadow.img obs=2 conv=notrunc + dd if=out/boot.bin of=obj/shadow.img obs=1 seek=62 conv=notrunc + dd if=out/kernel.bin of=obj/shadow.img seek=1 conv=notrunc + mv obj/shadow.img out/floppy.img + +kernel: + mkdir -p obj/kernel out + gcc -m32 -ffreestanding -c src/kernel/main.c -o obj/kernel/main.o + gcc -m32 -ffreestanding -c src/kernel/vga.c -o obj/kernel/vga.o + ld -T src/kernel/link.ld obj/kernel/main.o obj/kernel/vga.o -o out/kernel.bin + +boot: + mkdir -p out + nasm src/boot.asm -o out/boot.bin + +clean: + rm -r obj out
\ No newline at end of file diff --git a/src/boot.asm b/src/boot.asm new file mode 100644 index 0000000..b476581 --- /dev/null +++ b/src/boot.asm @@ -0,0 +1,55 @@ +bits 16 +org 0x7c3e + +kernel_sectors equ 16 +kernel_segment equ 0x3000 + + in al, 0x92 + or al, 0x02 + out 0x92, al + + xor ax, ax + mov ss, ax + mov sp, 0x7ffc + + mov ax, kernel_segment + mov es, ax + mov ax, 0x0200 + kernel_sectors + xor bx, bx + mov cx, 0x0002 + xor dh, dh + int 0x13 + + cli + + lgdt [gdt] + + mov eax, cr0 + or al, 0x01 + mov cr0, eax + + jmp 0x08:pmode + +bits 32 + +pmode: + mov ax, 0x10 + mov ds, ax + mov ax, 0x18 + mov ss, ax + mov sp, 0x7ffc + + jmp kernel_segment * 16 + +gdt: + dw .e - .t + dd .t +.t: + dq 0x0000_0000_0000_0000 + dq 0x00c0_9a00_0000_007f + dq 0x00c0_9200_0000_007f + dq 0x0040_9203_8000_7fff +.e: + +times $$ + 448 - $ db 0 +dw 0xaa55
\ No newline at end of file diff --git a/src/kernel/link.ld b/src/kernel/link.ld new file mode 100644 index 0000000..1fcff40 --- /dev/null +++ b/src/kernel/link.ld @@ -0,0 +1,15 @@ +OUTPUT_FORMAT(binary) +OUTPUT_ARCH(i386) + +SECTIONS { + . = 0x00030000; + .entry : { + */main.o(.text) + } + .bin : { + *(.text) + *(.rodata) + *(.data) + *(.bss) + } +}
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c new file mode 100644 index 0000000..1a8b2f4 --- /dev/null +++ b/src/kernel/main.c @@ -0,0 +1,7 @@ +#include <stdint.h> +#include "vga.h" + +void main() { + while (1) + vga_printsz("Hello! "); +}
\ No newline at end of file diff --git a/src/kernel/vga.c b/src/kernel/vga.c new file mode 100644 index 0000000..d0170c0 --- /dev/null +++ b/src/kernel/vga.c @@ -0,0 +1,14 @@ +#include <stdint.h> + +#define VGA_START (uint16_t *)0x000b8000 +#define VGA_END (VGA_START + 80 * 25) +uint16_t *cursor = VGA_START; +uint16_t color = 0x1f00; + +void vga_printsz(uint8_t *sz) { + while (*sz) { + *(cursor++) = color | *(sz++); + if (cursor == VGA_END) + cursor = VGA_START; + } +}
\ No newline at end of file diff --git a/src/kernel/vga.h b/src/kernel/vga.h new file mode 100644 index 0000000..47ac1fb --- /dev/null +++ b/src/kernel/vga.h @@ -0,0 +1,3 @@ +#include <stdint.h> + +void vga_printsz(uint8_t *sz);
\ No newline at end of file |