Page 1 of 1

bin Load Problem

Posted: Tue Dec 30, 2008 11:46 pm
by System123
I have now been able to load a bin file from my floppy into memory. However because the file uses 16bit registers it does not load properly.
ie: instead of loading different instructions on different lines (dump view) the opcodes all get put on one line and create a new instruction.
So:

Code: Select all

mov ax, 0x2E
int 55
Ends up looking like

Code: Select all

mov eax, 0x2E00DC37
Iss this because my os uses 32bit registers? Because if i change my binm file to use 32bit registers it works fine. Is there away to allow my OS to load and run bin files that use 16 bit register

Re: bin Load Problem

Posted: Wed Dec 31, 2008 1:20 am
by hailstorm
I assume (for the sake of simplicity) that you're in protected mode. I guess you have initialised all your segments
as 32 bit segments. All addressing and code execution will be interpreted as 32 bits by the processor, unregarding
the type of bin file you load. You have to define a 16-bit code segment (the intel manual tells you how) and call or jump
to that segment to execute your bin file properly. Should your bin file also contain a data segment, my advise should be
to create a 16 bit data segment.

Good luck!

Re: bin Load Problem

Posted: Wed Dec 31, 2008 8:27 am
by Combuster
The thing is that you are running 16-bit code in a 32-bit environment. You can as suggested switch to 16-bit protected mode, or you can assemble your code in 32-bit mode (via a bits 32 or bits 16 directive).

Re: bin Load Problem

Posted: Fri Jan 02, 2009 5:43 am
by System123
Thanks I will check it out

Re: bin Load Problem

Posted: Sat Jan 03, 2009 1:00 am
by System123
Ok I have another question but about elf/pe files. I am not sure which ones I am going to use but this question is general.

The file header contains a virtual address of the executable. Does this mean I have to load my exe at this virtual memory address? And if so, what happens if my kernel is at that address?

Re: bin Load Problem

Posted: Sat Jan 03, 2009 1:17 am
by JohnnyTheDon
Yes, elf/pe files must be loaded as the file dictates. The only exception is Position Independent Code. This code can run at any position, but it takes quite a performance hit. I know ELFs support PIC, but I don't believe PE files do (DLLs do not require PIC, they use a different method of running at an arbitrary position).

Your other option is to create segments or page tables to map the elf/pe code where it needs to be. I recommend using paging; its what most OSes use, and it has all kinds of other uses (disk mapping, swapping out parts of programs not being used, etc).