EXE execution
Posted: Thu Jul 14, 2011 10:31 pm
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