Make setup generic for both NBP and DOS startup

This commit is contained in:
Nero 2019-03-24 17:59:45 +00:00
parent bcff1efe59
commit 8d12a42442
2 changed files with 44 additions and 21 deletions

View File

@ -2,15 +2,13 @@ main:
mov ax, cs
mov ds, ax
call debug_init
call heap_init
call ivt_backup
call debug_init
mov ax, 18
call malloc
int 0x2E
.endloop:
hlt
jmp .endloop
retf
%include "kernel/heap.asm"
%include "kernel/intr.asm"
@ -19,4 +17,3 @@ main:
align 16
heap:
dw 0

54
nbp.asm
View File

@ -4,29 +4,55 @@ org 0x0000
; es:bx pxeenv+ structure
; ss:sp functional stack
; during PXE, CS=0000 and IP=7C00
_startup:
xor ax, ax
mov ax, cs
cmp ax, 0x0000 ; MBR or NBP, CS=0000 IP=7C00
je .mbr
cmp ax, 0x07C0 ; MBR on weird BIOS, CS=07C0 IP=0000
je .mbr
.dos:
mov ax, cs
push ax ; return CS
mov ax, .dosret
add ax, 0x0100
push ax ; return IP
push cx ; byte counter
push si ; source offset
push di ; destination offset
push es ; destination segment
mov ax, cs
add ax, 0x0010
push ax ; main CS
mov ax, main
push ax ; main IP
retf
.dosret:
int 0x20
int 0x18
.mbr:
mov ax, 0x0050
mov ds, ax
mov es, ax
mov [0xFFFE], ss ; save current stack configuration onto new stack
mov [0xFFFC], sp
mov ss, ax
mov sp, 0xFFFC
push dx
push bx ; possible far ptr to pxeenv+ struct
push es
mov es, ax ; 0x0050
mov di, 0x0000
xor ax, ax
mov ds, ax
mov si, 0x7C00
mov di, 0x0500
mov cx, _reloc_end
rep movsb
pop es
pop di
pop si
pop cx
jmp 0x0050:main
call 0x0050:main
.halt:
hlt
jmp .halt
%include "kernel/main.asm"