x86 NASM Indirect Far Jump In Real Mode -


i have been messing around multi-stage bootloader , have got of code work, except last part: the jump. have gotten code work out before wanted make more modular replacing line:

jmp 0x7e0:0 

with one:

jmp far [stage2read + sectorreadparam.bufoff] 

instead of hard coding code load in, wanted indirect jump it. here's rest of code:

; stage 1 of multi-stage bootloader  bits 16                       org 0x7c00              jmp 0:boot_main     %include "io16.inc"  boot_main:     ; setup new stack     cli                    mov ax, 0x100            mov ss, ax               mov bp, 0x4000            mov sp, bp               sti       ; setup data segment     xor ax, ax     mov ds, ax      ; save drive booted     mov [stage2read + sectorreadparam.drive], dl          ; home-made bios wrapper read sectors memory     mov si, stage2read     call readsectors                                     ; change new data segment     mov ax, [stage2read + sectorreadparam.bufseg]     mov ds, ax                   ;jmp 0x7e0:0                                    ; works     jmp far [stage2read + sectorreadparam.bufoff]   ; not  ; used parameters readsectors stage2read: istruc sectorreadparam          @ sectorreadparam.bufoff,  dd 0     @ sectorreadparam.bufseg,  dw 0x07e0     @ sectorreadparam.numsecs, db 1     @ sectorreadparam.track,   db 0     @ sectorreadparam.sector,  db 2     @ sectorreadparam.head,    db 0     @ sectorreadparam.drive,   db 0        ; needs initialized! iend  ; ending times 510-($-$$) db 0     dw 0xaa55               

remember code has been tested , works except indirect far jump work. that's need work. wondering if maybe indirect far jump implicitly using example ds address stage2read + sectorreadparam.bufoff incorrect. bugging me because seemingly simple. help!

you had couple of bugs in original code. first fact had offset using dd (32-bit dword) instead of 16-bit word. line:

at sectorreadparam.bufoff, dd 0 

should have been:

at sectorreadparam.bufoff, dw 0 

when specify memory operand far jmp default (in case) relative ds (data segment). before far jmp set ds new value, jmp memory operand read memory address wrong segment (0x07e0 instead of 0x0000).

you can either set ds after jmp or can change memory operand relative cs (which still segment data) using override. this:

jmp far [cs:stage2read + sectorreadparam.bufoff] 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -