diff options
| author | Alejandro Sior <aho@sior.be> | 2022-06-18 10:39:10 +0200 |
|---|---|---|
| committer | Alejandro Sior <aho@sior.be> | 2022-06-18 10:39:10 +0200 |
| commit | bd98b26786d21ffddb017ffe35ecaa4a9fd0aa4a (patch) | |
| tree | 1b78a43385bf0751abab8dd2423905696fd5baab | |
| parent | 3aefeeb723b8822916fb39b7c32551c35c06e32f (diff) | |
| -rw-r--r-- | .bochsrc | 2 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | bios/boot.ha | 4 | ||||
| -rw-r--r-- | main.ha | 17 | ||||
| -rw-r--r-- | rt/+x86_64/stage0.s | 19 | ||||
| -rw-r--r-- | rt/+x86_64/stage1.S | 24 | ||||
| -rw-r--r-- | rt/hare.sc | 3 | ||||
| -rwxr-xr-x | run.sh | 18 |
8 files changed, 78 insertions, 10 deletions
@@ -7,7 +7,7 @@ romimage: file="/usr/local/share/bochs/BIOS-bochs-latest", address=0x00000000, o vgaromimage: file="/usr/local/share/bochs/VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
-floppya: type=1_44, 1_44="/home/aws/rep/boot/boot.bin", status=inserted, write_protected=0
+floppya: type=1_44, 1_44="/home/aws/rep/boot/boot.img", status=inserted, write_protected=0
# no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=none
@@ -1,4 +1,5 @@ /boot /boot.bin +/boot.img /bx_enh_dbg.ini diff --git a/bios/boot.ha b/bios/boot.ha index e165f5a..e8b4f98 100644 --- a/bios/boot.ha +++ b/bios/boot.ha @@ -10,3 +10,7 @@ export const @symbol("drive_spt") drive_sectors_per_track: u8; // Amount of heads that the boot drive has export const @symbol("drive_heads") drive_heads: u8; + +// Buildup location for the data structures +const @symbol("buildup") _buildup: u8; +export const buildup: *[*]u8 = &_buildup: *[*]u8; @@ -15,8 +15,19 @@ export fn main() void = { }; let dest = 0x100000: uintptr: *[*]u8; - drive::read(0, 512, dest)!; - if (dest[511] == 0xaa) { - term::print(&text, "\nnice!"); + //drive::read(0, 512, dest)!; + //if (dest[511] == 0xaa) { + // term::print(&text, "\nnice!"); + //}; + + let pd: *[512]u64 = (0x1000): uintptr: *[512]u64; + pd[511] = 0x1000 | 0x3 | 1 << 6; + + // let wtf: u64 = 0o777; + + let lvl4: u64 = 0o177777 << 48 | 511 << 39 | 511 << 30 | 511 << 21 | 511 << 12 | 0x0; + let p4: *u64 = lvl4: uintptr: *u64; + if (*p4 >> 12 == 0x2) { + term::print(&text, "poggers\n"); }; }; diff --git a/rt/+x86_64/stage0.s b/rt/+x86_64/stage0.s index 2961a10..e88c3b8 100644 --- a/rt/+x86_64/stage0.s +++ b/rt/+x86_64/stage0.s @@ -56,7 +56,7 @@ a20_ok: # the rest :) load_stage1: # :Start to read at the second sector - mov $0x1, %di + mov entry1_begin, %edi # :Place the result just after us mov $boot_stage1_start, %esi load_stage1_loop: @@ -86,7 +86,24 @@ previous_sector: bios_idtr: .quad 0 +.org 446 + +entry1: +.byte 0x80 +.byte 0x0 +.byte 0x0 +.byte 0x0 +.byte 0x0 # type +.byte 0x0 # last +.byte 0x0 +.byte 0x0 +entry1_begin: +.int 0x0 +.int 512 + .org 510 .word 0xaa55 + + .include "rt/+x86_64/stage1.S" diff --git a/rt/+x86_64/stage1.S b/rt/+x86_64/stage1.S index 4f99d69..a3f35ab 100644 --- a/rt/+x86_64/stage1.S +++ b/rt/+x86_64/stage1.S @@ -74,25 +74,39 @@ pages_fill: or $3, %edi mov %edi, (_p4) + # Recursive map the page 4 + mov $_p4, %edi + or $3, %edi + mov $_p4, %ebx + mov %edi, 4088(%ebx) + mov $_p2, %edi or $3, %edi mov %edi, (_p3) mov $_p1, %edi or $3, %edi - mov %edi, (_p2) - + mov $_p3, %ebx + mov %edi, 8(%ebx) # :Now we are going to fill the first page - mov $0x3, %ebx + mov $(1 << 7| 0x3), %ebx + mov $512, %ecx + mov $_p2, %edi +pages_fill_p2_loop: + mov %ebx, (%edi) + add $0x200000, %ebx + add $8, %edi + loop pages_fill_p2_loop + mov $512, %ecx mov $_p1, %edi pages_fill_p1_loop: mov %ebx, (%edi) - add $0x1000, %ebx + add $0x200000, %ebx add $8, %edi loop pages_fill_p1_loop - + # :Now that the pages are prepared, we must set the %cr3 to point to the level 4 # page table. This register contains the address of the level 4 page mov $_p4, %edi @@ -73,4 +73,7 @@ SECTIONS { boot_end = .; + + . = ALIGN(512); + buildup = .; } @@ -1,5 +1,14 @@ #!/bin/sh -e +print_u32() { + printf "\\$(printf %o $(($1&0xFF)))\\$(printf %o $((($1 >> 8)&0xFF)))\\$(printf %o $((($1 >> 16)&0xFF)))\\$(printf %o $((($1 >> 24)&0xFF)))" +} + + +write_u32() { + print_u32 $1 | dd if=/dev/stdin of=$3 conv=notrunc bs=1 seek=$2 status=none +} + # :Tell hare to use our custom runtime # and linker scripts (this feature is so simple and neat :)) export HAREPATH=. @@ -19,4 +28,13 @@ objcopy \ --binary-architecture=i386:x86-64 \ boot boot.bin +size=$(stat -c %s boot.bin) +sectors=$((size/512 + 1)) +write_u32 1 $((446 + 8)) boot.bin +write_u32 $sectors $((446 + 12)) boot.bin + +[ -f boot.img ] && rm boot.img +../gptman/gptman convert boot.bin boot.img +chmod +rw boot.img + bochs |
