1,105,208 Community Members

Assembly Bootloader with a C/C++ Kernel

Member Avatar
Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have written a bootloader in ASM (I can post code if you like) and I plan to write a kernel in C /c++ because I don't want to have to deal with a Kernel written ENTIRELY in ASM. Is there any way (Got to keep this under or at 512 bytes) to allow the bootloader, written in ASM, to pass control (like call a method or something) to the C kernel?

I'm a newbie to this kind of thing, and I thought I would ask the pros.
Please be nice, this is my first post! :icon_cheesygrin:

Member Avatar
Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

bump!
I'm sure some one out there knows the answer!!!

Member Avatar
steventaal
Newbie Poster
23 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I WISH it was so simple as to call a function and give control to another program. *sigh* I suppose you'll just have to execute the loader for the c kernel, or if the kernel is one file, then call the file and exit or return your bootloader.

Member Avatar
Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I WISH it was so simple as to call a function and give control to another program. *sigh* I suppose you'll just have to execute the loader for the c kernel, or if the kernel is one file, then call the file and exit or return your bootloader.

Thanks so much for the reply! Yeah, I really wish it was too...
do you know if you could provide code of sorts that could do as you described? I mean, I'm not sure if I could write some ASM code to do that, because I am kind of a noob.

Member Avatar
felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

heres a basic way
.........................................

**call kernel**

put this into your bootload.asm
.........................................

**void kernel(void) 
{
 /* code */
}**

this would be kernel.c
.........................................
hope this helps

Member Avatar
Schol-R-LEA
Nearly a Posting Virtuoso
1,384 posts since Oct 2010
Reputation Points: 635 [?]
Q&As Helped to Solve: 225 [?]
Skill Endorsements: 28 [?]
 
0
 

I would strongly recommend not responding to threads that have been dead for over two years, especially when the answer you're giving is unquestionably incorrect.

Why is your answer wrong? Well, first off, it does not address the matter of loading the compiled code into memory, and more importantly, of loading it correctly. Unlike with assembly language, there really isn't any option with most compilers to generate raw binary image files which can be loaded directly into memory; rather the generated code is going to be in an 'executable' format that contains relocation tables and other information that needs to be handled before the actual binary can be computed.

Worse, on the x86 and x86-64 platforms, your answer pre-supposes 16-bit C/C++ code, which few modern compilers will generate. In order to run the 32-bit or 64-bit code which are the mainstays of modern operating systems, you would need to switch into protected mode (or long protected mode) before running the C code, which means that the page tables, interrupt descriptors, and so forth would have to be in place before calling the compiled code.

Member Avatar
felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

he's q was how to get to the kernel and this does work yeah in 16 bit but he didnt let us know what bits and this worked for me when i built a small kernel.

Member Avatar
Schol-R-LEA
Nearly a Posting Virtuoso
1,384 posts since Oct 2010
Reputation Points: 635 [?]
Q&As Helped to Solve: 225 [?]
Skill Endorsements: 28 [?]
 
-1
 

Oh? What compiler were you using, and how did you coax it to produce raw binaries?

(On a guess, it was Turbo C, correct? And you simply created a .COM file? That would work, but it would be quite limited.)

Member Avatar
felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

No it wasnt Turbo C it was gcc on Linux using ld to Link them together and it didnt produce .COM it produced .BIN

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: