2019-03-24 19:24:25 +01:00
|
|
|
; assumptions about the starting envionment
|
|
|
|
cpu 8086
|
|
|
|
org 0x0000
|
|
|
|
|
|
|
|
_startup:
|
|
|
|
xor ax, ax ; trash 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:
|
|
|
|
; ROP because call only works on immediate or memory
|
|
|
|
mov ax, cs
|
|
|
|
push ax ; return CS
|
|
|
|
mov ax, .dosret
|
|
|
|
add ax, 0x0100
|
|
|
|
push ax ; return IP
|
|
|
|
mov ax, cs
|
|
|
|
add ax, 0x0010
|
|
|
|
push ax ; main CS
|
|
|
|
mov ax, main
|
|
|
|
push ax ; main IP
|
|
|
|
retf
|
|
|
|
.dosret:
|
|
|
|
int 0x20
|
|
|
|
jmp .halt
|
|
|
|
.mbr:
|
|
|
|
push si ; index of partition table entry
|
|
|
|
push ds ; segment for ^
|
|
|
|
push dx ; dl might contain drive number
|
|
|
|
push bx ; possible offset for pxeenv+ struct
|
|
|
|
push es ; segment for ^
|
|
|
|
|
|
|
|
mov ax, 0x0050
|
|
|
|
mov es, ax
|
|
|
|
mov di, 0x0000
|
|
|
|
|
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov si, 0x7C00
|
|
|
|
|
|
|
|
mov cx, _reloc_end
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
call 0x0050:main
|
|
|
|
.halt:
|
|
|
|
hlt
|
|
|
|
jmp .halt
|
|
|
|
|
2019-03-23 21:23:17 +01:00
|
|
|
main:
|
|
|
|
mov ax, cs
|
|
|
|
mov ds, ax
|
|
|
|
|
|
|
|
call heap_init
|
2019-03-24 18:59:45 +01:00
|
|
|
call ivt_backup
|
|
|
|
call debug_init
|
2019-03-23 22:26:46 +01:00
|
|
|
|
2019-03-24 18:59:45 +01:00
|
|
|
int 0x2E
|
2019-03-23 21:23:17 +01:00
|
|
|
|
2019-03-24 18:59:45 +01:00
|
|
|
retf
|
2019-03-23 21:23:17 +01:00
|
|
|
|
2019-03-24 19:24:25 +01:00
|
|
|
%include "heap.asm"
|
|
|
|
%include "intr.asm"
|
|
|
|
%include "debug.asm"
|
|
|
|
%include "kprintf.asm"
|
|
|
|
|
|
|
|
_reloc_end:
|
2019-03-23 21:23:17 +01:00
|
|
|
|
|
|
|
align 16
|
|
|
|
heap:
|