EXE execution

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

EXE execution

Post 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
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: EXE execution

Post by Gigasoft »

You have to add to the old values, not just overwrite them.
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Re: EXE execution

Post by me239 »

Thanks, I've got it working now :D
Post Reply