flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Easy way to get any OS to load a .EXE file.

Author
Thread Post new topic Reply to topic
mbr_tsr



Joined: 03 Apr 2011
Posts: 4903
mbr_tsr
Code:

;LOADEXE.ASM
;Easy Way to get Any OS to Load a .EXE File
;By Shawn T. Cook
;Version 1.0

;simply reads the .EXE to 8000:0 using int 21h
;then does some stuff and runs the .EXE

;Shows a 'E' if not a MZ header...
;change filename.exe to the name of your .EXE file!

Org 0x0100


RunEXE:        

push cs
push cs
pop  ds
pop  es

mov  ah, 0x3d
mov  al, 0
mov  dx, ExeName
int  21h

mov  bx, ax
mov  ax, 0x8000
mov  ds, ax

mov  dx, 0
KeepLoading:
mov  cx, 0x10
mov  ah, 0x3f      ;read
int  21h
jc   NotKeepLoading
cmp  ax, 0
je   NotKeepLoading
mov  ax, ds
add  ax, 1
mov  ds, ax
jmp  KeepLoading
NotKeepLoading:

mov  ah, 0x3e      ;close
int  21h


ReadEXEFile:

        mov     ax, 0x8000
        mov     ds, ax

        cmp     word [ds:0], 5A4Dh         ; "MZ" signature?

        jne     NotEXE


RelocateEXE:

        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, [bx]                ; di = item ofs
        mov     dx, [bx+2]              ; dx = item seg (rel)
        add     dx, ax                  ; dx = item seg (abs)

        push    ds
        mov     ds, dx                  ; ds = dx
        add     [di], ax                ; fixup
        pop     ds

        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:
        ; set the magic number so the program knows who has loaded it:
        mov     si, 16381 ; prime number 2**14-3
        mov     di, 32749 ; prime number 2**15-19
        mov     bp, 65521 ; prime number 2**16-15

        retf

NotEXE:
        mov ah, 0x0e
        mov al, 'E'
        int 0x10
        ret


ExeName db 'filename.exe',0



    
Post 14 Nov 2014, 02:15
View user's profile Send private message Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop
except your os will also have to provide int 21h 3d 3e & 3f functions Wink
Post 14 Nov 2014, 04:38
View user's profile Send private message Reply with quote
mbr_tsr



Joined: 03 Apr 2011
Posts: 4903
mbr_tsr
my OS provides int 21h function 40h even, big problem haunted my whole day was getting this to load command line parameters, i set 80h to the command line text and passed the PSP segment as DS to the .EXE but still the command line parameter is full of trash, i tried everything, no luck. i know 80h is the # of bytes and 81h is just a blank space the rest is the text followed by a CR but it is NOT working, so when you enter the .EXE and type shit after it just sees trash, DAMN.
Post 18 Nov 2014, 22:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.