Link to home
Start Free TrialLog in
Avatar of laeuchli
laeuchli

asked on

Os com loader.

Hey, I am writing a os, and I have a question. How does one go about writing a com loader? I think I know how to read in a sector of the disk, but what do you do after that? Thanks
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of laeuchli
laeuchli

ASKER

yes but how do you jump to beginning? Do you use a jmp, and jump to the mem address.
There are several ways.  Let's say this is a 32-bit machine and your image load address is 0x00001000.  If you've written this in ASM, just do a JMP 0x00001000 or whater the syntax is for an absolute jump on that machine.  Another method is to push the address you want to jump to onto the stack and do a return.

In C, it might be something like this:

main()
{
      void (*fn)(void) = (void (*)(void))0x00001000;
      fn();
}

In this case, the first line declares a function pointer, fn, that takes no arguments and returns nothing.  It also initializes it to point to the load address of 0x00001000.  The second line calls the function at fn.  In this case, when the called app is finished, if it ends with a return, control will return to the loader.
ok thanks, that doesn't sound so bad.