Page 1 of 1

EXE execution

Posted: Thu Jul 14, 2011 10:31 pm
by me239
Hello everyone! I was wondering if anyone had any code for legacy MZ EXE loading in Real Mode? My current loader is messing up some how on segmentation. Here is my current loader (FASM syntax)

Code: Select all

;ds = location of RAW EXE
;loadseg = 0x1010        
        mov     ax, word[cs:loadseg]
        mov     ds, ax
        add     ax, [ds:08h]            ; ax = image base
        mov     cx, [ds:06h]            ; cx = reloc items
        mov     bx, [ds:18h]            ; bx = reloc table pointer
        jcxz    RelocationDone
ReloCycle:
        mov     di, [ds:bx]             ; di = item ofs
        mov     dx, [ds:bx+2]           ; dx = item seg (rel)
        add     dx, ax                  ; dx = item seg (abs)
        mov     es, dx
        stosw
        add     bx, 4                   ; point to next entry
        loop    ReloCycle
RelocationDone:
        mov     bx, ax
        add     bx, [ds:0Eh]
        mov     ss, bx                  ; ss for EXE
        mov     sp, [ds:10h]            ; sp for EXE
        add     ax, [ds:16h]            ; cs
        push    ax
        push    word [ds:14h]           ; ip
Run:
        sti
        retf

Re: EXE execution

Posted: Fri Jul 15, 2011 3:52 am
by Gigasoft
You have to add to the old values, not just overwrite them.

Re: EXE execution

Posted: Fri Jul 15, 2011 11:11 am
by me239
Thanks, I've got it working now :D