diff options
author | Benji Dial <benji3.141@gmail.com> | 2020-05-16 14:10:08 -0400 |
---|---|---|
committer | Benji Dial <benji3.141@gmail.com> | 2020-05-16 14:10:08 -0400 |
commit | 31d8ae388a7ded576abd3e3d99c3d9193ea6d704 (patch) | |
tree | 9317308fbf0082924de414ef8416e76e927d79cd | |
parent | 806815e5f2612a45cdce6c47ace56146edfa7abf (diff) | |
download | portland-os-31d8ae388a7ded576abd3e3d99c3d9193ea6d704.tar.gz |
small stub with fat info
-rw-r--r-- | makefile | 3 | ||||
-rw-r--r-- | src/boot.asm | 4 | ||||
-rw-r--r-- | src/kernel/fat.h | 25 | ||||
-rw-r--r-- | src/kernel/main.c | 9 | ||||
-rw-r--r-- | src/kernel/vga.c | 77 | ||||
-rw-r--r-- | src/kernel/vga.h | 9 |
6 files changed, 120 insertions, 7 deletions
@@ -1,3 +1,6 @@ +qemu: floppy + qemu-system-i386 out/floppy.img + floppy: kernel boot mkdir -p obj out /sbin/mkfs.fat -C -R 17 -n "PORTLAND OS" obj/shadow.img 1440 diff --git a/src/boot.asm b/src/boot.asm index f9e3a30..fecf466 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -12,6 +12,10 @@ kernel_segment equ 0x3000 mov ss, ax mov sp, 0x7ffc + mov ah, 0x01 + mov ch, 0x3f + int 0x10 + mov ax, kernel_segment mov es, ax mov ax, 0x0200 + kernel_sectors diff --git a/src/kernel/fat.h b/src/kernel/fat.h new file mode 100644 index 0000000..e7aa956 --- /dev/null +++ b/src/kernel/fat.h @@ -0,0 +1,25 @@ +#include <stdint.h> + +#define FAT_INFO ((struct fat_info *)0x7c03) + +struct fat_info { + uint8_t oem[8]; + uint16_t bytes_per_sector; + uint8_t sectors_per_cluster; + uint16_t reserved_sectors; + uint8_t fats; + uint16_t root_entries; + uint16_t sectors; + uint8_t media_type; + uint16_t sectors_per_fat; + uint16_t sectors_per_track; + uint16_t heads; + uint32_t hidden_sectors; + uint32_t sectors_long; + uint8_t drive_number; + uint8_t reserved; + uint8_t ext_boot_marker; + uint32_t volume_id; + uint8_t label[11]; + uint8_t fs_type[8]; +} __attribute__ ((packed));
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c index 1a8b2f4..dbeb11b 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,14 @@ #include <stdint.h> #include "vga.h" +#include "fat.h" void main() { + vga_blank(); + vga_printsz("In kernel-land\n\nDisk label: "); + vga_printsn(FAT_INFO->label, 11); + vga_printsz("\nDisk size: "); + vga_printu32((FAT_INFO->sectors * FAT_INFO->bytes_per_sector) >> 10); + vga_printsz("k\n\nHalting..."); while (1) - vga_printsz("Hello! "); + asm ("hlt"); }
\ No newline at end of file diff --git a/src/kernel/vga.c b/src/kernel/vga.c index d0170c0..8e438a8 100644 --- a/src/kernel/vga.c +++ b/src/kernel/vga.c @@ -1,14 +1,81 @@ #include <stdint.h> +#include <stdbool.h> +#define VGA_COLUMNS 80 +#define VGA_LINES 25 #define VGA_START (uint16_t *)0x000b8000 -#define VGA_END (VGA_START + 80 * 25) +#define VGA_END (VGA_START + VGA_COLUMNS * VGA_LINES) uint16_t *cursor = VGA_START; uint16_t color = 0x1f00; +void vga_scroll() { + cursor = VGA_START; +} + +void vga_blank() { + uint32_t f = (color << 16) | color | 0x00200020; + uint32_t *p = (uint32_t *)VGA_START; + while (p < (uint32_t *)VGA_END) + *(p++) = f; + cursor = VGA_START; +} + +void vga_printch(uint8_t ch) { + if (ch == '\n') { + if ((cursor = cursor - (cursor - VGA_START) % VGA_COLUMNS + VGA_COLUMNS) == VGA_END) + vga_scroll(); + return; + } + *(cursor++) = color | ch; + if (cursor == VGA_END) + vga_scroll(); +} + void vga_printsz(uint8_t *sz) { - while (*sz) { - *(cursor++) = color | *(sz++); - if (cursor == VGA_END) - cursor = VGA_START; + while (*sz) + vga_printch(*(sz++)); +} + +void vga_printsn(uint8_t *sn, uint8_t n) { + while (n--) + vga_printch(*(sn++)); +} + +void vga_printu32(uint32_t n) { + bool zero = false; + for (uint32_t m = 1000000000; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } + } +} + +void vga_printu16(uint16_t n) { + bool zero = false; + for (uint16_t m = 10000; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } + } +} + +void vga_printu8(uint8_t n) { + bool zero = false; + for (uint8_t m = 100; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } } }
\ No newline at end of file diff --git a/src/kernel/vga.h b/src/kernel/vga.h index 47ac1fb..95c6335 100644 --- a/src/kernel/vga.h +++ b/src/kernel/vga.h @@ -1,3 +1,10 @@ #include <stdint.h> -void vga_printsz(uint8_t *sz);
\ No newline at end of file +void vga_blank(); +void vga_scroll(); +void vga_printch(uint8_t ch); +void vga_printsz(uint8_t *sz); +void vga_printsn(uint8_t *sn, uint8_t n); +void vga_printu32(uint32_t n); +void vga_printu16(uint16_t n); +void vga_printu8(uint8_t n);
\ No newline at end of file |