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
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.
laeuchliAuthor Commented:
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:

      void (*fn)(void) = (void (*)(void))0x00001000;

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.
laeuchliAuthor Commented:
ok thanks, that doesn't sound so bad.
All Courses

From novice to tech pro — start learning today.