Change kernel blob format to be option rom compatible

This commit is contained in:
Nero 2019-04-20 21:02:35 +00:00
parent 3b3fa349d4
commit d8fe1b211c
4 changed files with 152 additions and 52 deletions

View File

@ -2,18 +2,18 @@ FD_CYLINDERS = 40
FD_HEADS = 2
FD_SECTORS = 9
default: kernel.com
default: kernel.rom
kernel.bin: kernel/*.asm
nasm -s -o $@ -I kernel kernel/main.asm
kernel.rom: kernel/*.asm
nasm -s -o $@ -I kernel kernel/main.asm && ./fix-rom.sh $@
boot/%.bin: boot/%.asm
nasm -s -o $@ -I lib $<
fdimage.img: boot/floppy.bin kernel.bin
fdimage.img: boot/floppy.bin kernel.rom
dd if=/dev/zero bs=512 count=$$(( $(FD_CYLINDERS) * $(FD_HEADS) * $(FD_SECTORS) )) of=$@
mformat -i $@ -t $(FD_CYLINDERS) -h $(FD_HEADS) -n $(FD_SECTORS) -B boot/floppy.bin ::
mcopy -i $@ kernel.bin ::boot.bin
mcopy -i $@ kernel.rom ::kernel.rom
clean:
rm -f *.com *.bin *.img boot/*.bin
rm -f *.com *.bin *.rom *.img boot/*.bin

View File

@ -48,10 +48,6 @@ _startup:
; setup stack area growing down from 0x10000
mov ss, ax
mov sp, ax
; backup important values
push bx
push cx
push dx
; adjust CS
jmp 0x07C0:main
@ -63,6 +59,11 @@ rootdir:
dw 0
main:
; backup important values
push bx
push cx
push dx
; setup buffer area directly at 4k
mov ax, 0x0100
mov ds, ax
@ -78,13 +79,16 @@ main:
; restore important variables
xor ax, ax
mov bp, ax
mov si, ax
mov di, ax
pop dx
pop cx
pop bx
jmp 0x0100:0000
mov di, [0x001A]
mov ax, [di+0x1A]
push ds
push ax
retf
call error
db "ROM ERROR", 0
; Write AX, a string and bail out
; Return pointer is the string start
@ -228,9 +232,9 @@ loadblk:
times (0x1F0 - ($-$$)) db 0
bootfilename:
db "BOOT"
db "KERNEL"
times (0x1F8 - ($-$$)) db " "
db "BIN"
db "ROM"
times (0x1FE - ($-$$)) db 0

13
fix-rom.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
setbyte() {
printf "\x$3"|dd status=none seek="$2" bs=1 count=1 conv=notrunc of="$1"
}
[ -n "$1" ] || exit 1
setbyte "$1" 2 $(stat -c "%s" "$1"|awk '{printf("%02x",$1/512)}')
setbyte "$1" 41 00
checksum=$(xxd -p -c 1 "$1"|sed 's/^/0x/'|awk '{s+=$1} END {printf("%02x\n",256-s%256)}')
setbyte "$1" 41 "$checksum"

View File

@ -1,30 +1,114 @@
; assumptions about the starting envionment
cpu 8086
org 0x0000
db 0x55, 0xAA, 0x00
jmp optrom_init
_startup:
times (0x1A - ($-$$)) db 0
dw pnp
align 16
pnp:
db "$PnP"
db 1 ; version 1
db 2 ; 2 * 16 length
dw 0 ; offset of next header
db 0
db 0 ; checksum (filled by fix-rom)
dd 0 ; device identifier
dw .vendor ; manufacturer string
dw .product ; product name string
db 0,0,0 ; device type string
db 0x20 ; device indicator, bit for "read cacheable" set
dw 0 ; boot connection vector
dw 0 ; boot disconnect vector
dw start ; bootstrap entry point
dw 0 ; reserved
dw 0
.vendor:
db "Nero", 0
.product:
db "2B", 0
align 16
optrom_init:
push di
push es
xor ax, ax
mov es, ax
mov di, 0x0060 ; vector (0x18 * 4 bytes)
mov ax, start
stosw
mov ax, cs
mov ss, ax
mov sp, 0x0000
; <0x0010 is BIOS segment when relocated to HMA
; so we need a nop sled
times (0x10 - ($-$$)) nop
main:
stosw
pop es
pop di
retf
start:
call intr_init
int 3
sti
mov si, 0x0000
mov ds, si
.loop:
push bx
mov dx, 0x0000
mov ah, 0x02
mov bx, 0x0000
int 0x10
pop bx
call dump
mov ah, 0x01
int 0x21
mov dl, al
mov ah, 0x02
int 0x21
sti
cmp al, 0x30
jne .notup
sub bx, 0x0100
.notup:
cmp al, 0x31
jne .notdown
add bx, 0x0100
.notdown:
jmp .loop
.halt:
hlt
jmp .halt
dump:
mov si, bx
mov cx, 0x10
.nextline:
mov ax, si
call kprint16
mov al, 0x3A
call kputc
mov al, 0x20
call kputc
push cx
mov cx, 0x0020
.bytes:
lodsb
call kprint8
loop .bytes
pop cx
mov al,0x20
call kputc
mov al,0x0A
call kputc
mov al,0x0D
call kputc
loop .nextline
ret
%include "intr.asm"
%include "debug.asm"
%include "kprintf.asm"
@ -32,5 +116,4 @@ main:
_reloc_end:
align 16
heap:
align 512