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_HEADS = 2
FD_SECTORS = 9 FD_SECTORS = 9
default: kernel.com default: kernel.rom
kernel.bin: kernel/*.asm kernel.rom: kernel/*.asm
nasm -s -o $@ -I kernel kernel/main.asm nasm -s -o $@ -I kernel kernel/main.asm && ./fix-rom.sh $@
boot/%.bin: boot/%.asm boot/%.bin: boot/%.asm
nasm -s -o $@ -I lib $< 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=$@ 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 :: 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: 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 ; setup stack area growing down from 0x10000
mov ss, ax mov ss, ax
mov sp, ax mov sp, ax
; backup important values
push bx
push cx
push dx
; adjust CS ; adjust CS
jmp 0x07C0:main jmp 0x07C0:main
@ -63,6 +59,11 @@ rootdir:
dw 0 dw 0
main: main:
; backup important values
push bx
push cx
push dx
; setup buffer area directly at 4k ; setup buffer area directly at 4k
mov ax, 0x0100 mov ax, 0x0100
mov ds, ax mov ds, ax
@ -78,13 +79,16 @@ main:
; restore important variables ; restore important variables
xor ax, ax xor ax, ax
mov bp, ax
mov si, ax
mov di, ax
pop dx pop dx
pop cx pop cx
pop bx 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 ; Write AX, a string and bail out
; Return pointer is the string start ; Return pointer is the string start
@ -228,9 +232,9 @@ loadblk:
times (0x1F0 - ($-$$)) db 0 times (0x1F0 - ($-$$)) db 0
bootfilename: bootfilename:
db "BOOT" db "KERNEL"
times (0x1F8 - ($-$$)) db " " times (0x1F8 - ($-$$)) db " "
db "BIN" db "ROM"
times (0x1FE - ($-$$)) db 0 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,36 +1,119 @@
; assumptions about the starting envionment cpu 8086
cpu 8086 org 0x0000
org 0x0000 db 0x55, 0xAA, 0x00
jmp optrom_init
_startup:
mov ax, cs times (0x1A - ($-$$)) db 0
mov ss, ax dw pnp
mov sp, 0x0000
; <0x0010 is BIOS segment when relocated to HMA align 16
; so we need a nop sled pnp:
times (0x10 - ($-$$)) nop db "$PnP"
main: db 1 ; version 1
call intr_init db 2 ; 2 * 16 length
dw 0 ; offset of next header
int 3 db 0
db 0 ; checksum (filled by fix-rom)
mov ah, 0x01 dd 0 ; device identifier
int 0x21 dw .vendor ; manufacturer string
mov dl, al dw .product ; product name string
mov ah, 0x02 db 0,0,0 ; device type string
int 0x21 db 0x20 ; device indicator, bit for "read cacheable" set
dw 0 ; boot connection vector
sti dw 0 ; boot disconnect vector
.halt: dw start ; bootstrap entry point
hlt dw 0 ; reserved
jmp .halt dw 0
.vendor:
%include "intr.asm" db "Nero", 0
%include "debug.asm" .product:
%include "kprintf.asm" db "2B", 0
%include "dosapi.asm"
align 16
_reloc_end: optrom_init:
push di
align 16 push es
heap: xor ax, ax
mov es, ax
mov di, 0x0060 ; vector (0x18 * 4 bytes)
mov ax, start
stosw
mov ax, cs
stosw
pop es
pop di
retf
start:
call intr_init
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
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"
%include "dosapi.asm"
_reloc_end:
align 512