create disk image with gpt

main
pantonshire 1 year ago
parent a33a21cde9
commit 87854597a1

@ -3,11 +3,11 @@
; -------------------------------------------------------------------- ; --------------------------------------------------------------------
; R | 0x000000 - 0x000400: real-mode interrupt vector table ; R | 0x000000 - 0x000400: real-mode interrupt vector table
; R | 0x000400 - 0x000500: bios data area ; R | 0x000400 - 0x000500: bios data area
; U | 0x000500 - 0x007000: stack ; U | 0x000500 - 0x007c00: stack
; U | 0x007000 - 0x007c00: globals ; U | 0x007000 - 0x007c00: big stage0 initial stack frame
; | 0x007000 - 0x007001: boot drive number ; | 0x007000 - 0x007001: boot drive number
; | 0x007001 - 0x007002: number of hard disk drives ; | 0x007001 - 0x007002: boot drive sectors per track
; | 0x007002 - 0x007003: ; | 0x007002 - 0x007004: boot drive number of heads
; U | 0x007c00 - 0x007e00: boot sector ; U | 0x007c00 - 0x007e00: boot sector
; U | 0x007e00 - 0x080000: conventional usable memory ; U | 0x007e00 - 0x080000: conventional usable memory
; R | 0x080000 - 0x0a0000: extended bios data area (maximum possible size) ; R | 0x080000 - 0x0a0000: extended bios data area (maximum possible size)
@ -17,7 +17,7 @@
; R | 0x0f0000 - 0x100000: motherboard bios ; R | 0x0f0000 - 0x100000: motherboard bios
; BIOS puts our boot sector at 0000:7c00 ; BIOS puts our boot sector at 0000:7c00
org 0x7c00 org 0x7c00
; We're (probably) in real mode ; We're (probably) in real mode
bits 16 bits 16
@ -29,26 +29,31 @@ bits 16
mov ds, ax mov ds, ax
mov es, ax mov es, ax
; Put stack base at 0x7000. Stack grows high->low, so we'll grow away from our program text at ; We put stack base at 0x7c00 and give ourselves a big stack frame [0x7000,0x7c00) for spilling to.
; 0x7c00. We reserve the range [0x7000,0x7c00) for globals. ; Stack grows high->low, so we'll grow away from our program text at 0x7c00.
mov ss, ax mov ss, ax
mov sp, 0x7000 mov sp, 0x7c00
mov bp, 0x7000
; Segment for VGA (0xb800 * 16 = 0xb8000) ; Segment for VGA (0xb800 * 16 = 0xb8000)
mov ax, 0xb800 mov ax, 0xb800
mov fs, ax mov fs, ax
mov di, 0x7000
; Store boot drive number ; Store boot drive number
mov ds:[di], dl mov [bp], dl
; Get drive geometry ; Get drive geometry
mov di, 0x00 mov di, 0x00
mov ah, 0x08 mov ah, 0x08
int 0x13 int 0x13
jb panic jb panic
mov ds:[di + 1], dl and cl, 0x3f
mov [bp + 1], cl
movzx ax, dh
add ax, 1
mov [bp + 2], ax
; Set VGA mode ; Set VGA mode
; https://mendelson.org/wpdos/videomodes.txt ; https://mendelson.org/wpdos/videomodes.txt
@ -57,16 +62,17 @@ bits 16
mov word fs:[0x0000], 0xc048 mov word fs:[0x0000], 0xc048
mov word fs:[0x0002], 0xc069 mov word fs:[0x0002], 0xc069
mov word fs:[0x0004], 0xc021
hlt hlt
panic: panic:
mov ax, 0x0003 mov ax, 0x0003
int 0x10 int 0x10
mov word fs:[0x0000], 0x4f46 mov ax, 0xb800
mov word fs:[0x0002], 0x4f41 mov ds, ax
mov word fs:[0x0004], 0x4f49 mov word [0x0000], 0x4f46
mov word fs:[0x0006], 0x4f4c mov word [0x0002], 0x4f41
mov word [0x0004], 0x4f49
mov word [0x0006], 0x4f4c
hlt hlt
; TODO: enable A20 ; TODO: enable A20
@ -90,20 +96,3 @@ panic:
%if ($ - $$) > 440 %if ($ - $$) > 440
%error "exceeded mbr bootstrap field size" %error "exceeded mbr bootstrap field size"
%endif %endif
; Pad to the end of the MBR bootstrap field
times 440 - ($ - $$) db 0
; Unique disk ID
dd 0x00000000
; Reserved
dw 0x0000
; Zero the partition fields
; TODO: fill in the field pointing to the GPT table
times 510 - ($ - $$) db 0
; Boot signature
db 0x55
db 0xaa

@ -1,6 +1,16 @@
run: run:
qemu-system-x86_64 -drive format=raw,file=boot0.bin qemu-system-x86_64 -drive format=raw,file=disk.bin
build: build:
nasm -f bin -o boot0.bin boot0.s nasm -f bin -o boot0.bin boot0.s
zero_disk:
dd if=/dev/zero of=disk.bin bs=64K count=16
partition_disk:
parted --script disk.bin mklabel gpt
parted --script disk.bin mkpart test 34s 50%
parted --script disk.bin type 1 0fc63daf-8483-4772-8e79-3d69d8477de4
write_stage0:
dd if=boot0.bin of=disk.bin conv=notrunc

Loading…
Cancel
Save