We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,680 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Assembly Bootloader with a C/C++ Kernel

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:

4
Contributors
8
Replies
2 Years
Discussion Span
1 Week Ago
Last Updated
26
Views
Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

steventaal
Newbie Poster
23 posts since Mar 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

Hazardous_Byte
Newbie Poster
9 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

Schol-R-LEA
Veteran Poster
1,089 posts since Oct 2010
Reputation Points: 495
Solved Threads: 174
Skill Endorsements: 13

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.

felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.)

Schol-R-LEA
Veteran Poster
1,089 posts since Oct 2010
Reputation Points: 495
Solved Threads: 174
Skill Endorsements: 13

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

felceyboy
Newbie Poster
12 posts since May 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.3047 seconds using 2.7MB