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
LVL 5
laeuchliAsked:
Who is Participating?
 
jhanceConnect With a Mentor Commented:
It's always great fun writing your own OS.  It's too bad not many people do this anymore.  I remember......

Anyway, a loader generally does 4 things:

1) Find the image of the executable file that has been requested to run.

2) Loads the image from the disk into the memory.

3) Fixes up any absolute addresses to correspond to the load address.  Note that this step is not necessary if this is an absolute loader.

4) Jumps to the beginning (or other specified place) in the loaded image.
0
 
laeuchliAuthor Commented:
yes but how do you jump to beginning? Do you use a jmp, and jump to the mem address.
0
 
jhanceCommented:
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.
0
 
laeuchliAuthor Commented:
ok thanks, that doesn't sound so bad.
0
All Courses

From novice to tech pro — start learning today.