• C

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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.