From 5becc898723511e03f0f42ef6d1ba5e34ded9622 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 23 Mar 2019 20:37:18 +0000 Subject: [PATCH] Instead of adjusting CS, always relocate NBP to 0x00500 --- nbp.asm | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/nbp.asm b/nbp.asm index 5192e68..ff97f54 100644 --- a/nbp.asm +++ b/nbp.asm @@ -1,38 +1,26 @@ ; assumptions about the starting envionment cpu 8086 org 0x0000 -; dl probable drive number -; ds:si probable pointer to partition structure -; es:bx probable pxeenv+ structure +; es:bx pxeenv+ structure ; ss:sp functional stack -_startup: ; during PXE, CS=0000 and IP=7C00 -; adjust CS so our offsets match org setting above -mov ax, _exit -push ax ; store exit addr on stack so main will return to it -push bx ; backup bx -call near .push_ip -.push_ip: -pop bx -sub bx, .push_ip ; subtract expected value ... -shr bx,1 ; shift it to 4 bits to the right -shr bx,1 -shr bx,1 -shr bx,1 -mov ax,cs -add ax,bx ; so we can add it to cs -pop bx ; restore bx -push ax ; cs -mov ax, main -push ax ; ip -sti -retf ; jump +_startup: + xor ax, ax + mov ss, ax + mov sp, 0x0000 + mov ds, ax + mov es, ax + + mov si, 0x7C00 + mov di, 0x0500 + mov cx, (_reloc_end) + rep movsb + jmp 0x0050:main _exit: mov si, .message call kprintf - int 0x20 .loop: hlt jmp .loop @@ -40,3 +28,5 @@ _exit: db "Halted: Waiting for poweroff...", 0 %include "kernel/main.asm" + +_reloc_end: