summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bochsrc2
-rw-r--r--.gitignore1
-rw-r--r--bios/boot.ha4
-rw-r--r--main.ha17
-rw-r--r--rt/+x86_64/stage0.s19
-rw-r--r--rt/+x86_64/stage1.S24
-rw-r--r--rt/hare.sc3
-rwxr-xr-xrun.sh18
8 files changed, 78 insertions, 10 deletions
diff --git a/.bochsrc b/.bochsrc
index 394d356..997af86 100644
--- a/.bochsrc
+++ b/.bochsrc
@@ -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
diff --git a/.gitignore b/.gitignore
index 7e2ef1d..dbfbee0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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;
diff --git a/main.ha b/main.ha
index e640d04..d13242a 100644
--- a/main.ha
+++ b/main.ha
@@ -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
diff --git a/rt/hare.sc b/rt/hare.sc
index ac8c4c5..343f585 100644
--- a/rt/hare.sc
+++ b/rt/hare.sc
@@ -73,4 +73,7 @@ SECTIONS {
boot_end = .;
+
+ . = ALIGN(512);
+ buildup = .;
}
diff --git a/run.sh b/run.sh
index 6b28de9..346267c 100755
--- a/run.sh
+++ b/run.sh
@@ -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