flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > exe in pm |
Author |
|
revolution 13 Dec 2008, 06:24
You can't simply load an exe into memory and start executing. Each section needs to be properly located into memory. The Imports table needs to be properly linked and bound to the DLLs. If it has a TLS defined then you need to initialise that. Perhaps some other things to initialise also before you can jump/call to the code start offset. Basically you need to do all the things that the Windows exe loader would do.
|
|||
13 Dec 2008, 06:24 |
|
dosin 13 Dec 2008, 17:21
I think your looking at what I am trying to do wrong...
were the .exe is does not matter - if its on a disk or a mem location.. it should be able to execute from either.. its just in mem not on a disk.. its just a matter of setting up the stack and executing it.. I have done this with code compiled into the program.. its the same concept.. The OS is not crashing because of the loading an .exe to the mem... its crashing when I try to execute it... Each section needs to be properly located into memory - right but this can be done from it being stored in mem.. think of this mem location were its stored -like you would from a disk.. just no need to read the floppy... |
|||
13 Dec 2008, 17:21 |
|
kas 13 Dec 2008, 17:31
Are you trying to use fasm to create a RAM disk?
Kas |
|||
13 Dec 2008, 17:31 |
|
dosin 13 Dec 2008, 17:44
The best way to explain is :
The os is loaded from a floppy.. The test.exe would be a user app executed by the OS... The user app is just loaded into the main kernel..instead of loaded from a disk |
|||
13 Dec 2008, 17:44 |
|
Dex4u 13 Dec 2008, 18:16
Now you first problem is MZ are useally for realmode and even than you need to set stuff up, before running.
Example of loading a com or MZ (realmode) Code: ;;;;;;;;;;;;;;;;;;; ;; Type checking ;; ;;;;;;;;;;;;;;;;;;; cli ; for stack adjustments mov ax, ImageLoadSeg mov es, ax cmp word [es:0], 5A4Dh ; "MZ" signature? je RelocateEXE ; yes, it's an EXE program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup and Run COM program ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov ax, es sub ax, 10h ; "org 100h" stuff mov es, ax mov ds, ax mov ss, ax xor sp, sp push es push word 100h jmp Run ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Relocate, setup and run EXE program ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RelocateEXE: 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) push ds mov ds, dx ; ds = dx add [ds: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: mov dl, [cs:bsDriveNumber] ; let program know boot drive mov dh, 0xff ; let DexOS know it booted from bootprog sti retf But it would be best if you tell us what you want to do, eg: do you need to be able to compile it with a C compiler ?, so you need a certain file format ?. Does it need to be reloctable ? etc. |
|||
13 Dec 2008, 18:16 |
|
dosin 13 Dec 2008, 19:14
I am trying to:
align 8 exefile: file 'test.exe' rb 8 lea ebx,[exefile] call load_exe load_exe: loading data goes here..... ret I have a good idea on how to do it now... I will try later and if works will post how I did it! Thanks again for the help... |
|||
13 Dec 2008, 19:14 |
|
Dex4u 14 Dec 2008, 15:23
Unless you use a reloctable file format and fix the offset's, you will need to do something like this:
Remember EBX is the base address you need to add this to all vars Example of needing base add Code: mov eax,[TestVar+ebx] ;TestVar is a var call [WriteHex32+ebx] ;WriteHex32 is stored in a var mov esi,msgService2 ; Move offset to string add esi,ebx ; We add the base address Example of not needing base add Code: call PrintTest ; call proc jmp next ; jump to address |
|||
14 Dec 2008, 15:23 |
|
dosin 14 Dec 2008, 17:41
Thanks - I think I am getting closer... or at leist its not crashing now... lol
or it may be working .. I just have nothing to base it on - it could be the C program still needs work or the loading... in the loadexe I am adding the base to it... I have been going over the isr int to make sure I did not miss anything and the nasm/gcc .. looks okay,, the program should fill the screen white .. so far its not doing that... There are some diff in nasm versus .. Fasm.. this could be an issue also like with the rw rb (are not in Nasm) ... maybe I will try without the int. or in txt mode... |
|||
14 Dec 2008, 17:41 |
|
dosin 15 Dec 2008, 13:14
just if anyone was wondernig if
align 8 binfile: file 'test.bin' ;was .exe rb 8 lea ebx,[binfile] call run_bin_file run_bin_file: ;execute the code here works.. Yes - it does - you can store an excutable/binary file in mem and can run it this way! I tried with a simpler format with fasm and it worked... The prob with the gcc - is all the junk it adds to the exe... I may be stuck with compile a binary format - like how they make kernels... no libs freestanding... but this would be okay if it works for what I am trying to do... or possible another format... |
|||
15 Dec 2008, 13:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.