Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a simple c kernel that prints Hello world and an another object file using nasm. my question is how to compile c kernel with gcc and after that create flat binary kernel by linking both object files and put on address 0x7e12. It should be 32bit kernel. I am on Lubuntu 14.04

What I have tried:

i have seen some samples and tired this but this does not give correct thing.

Compile.sh:
gcc -c kernel.c -o kernel.o
<br />nasm base.asm -f elf -o base.o
<br />ld -oformat=binary kernel.o base.o -Ttext=0x7e12


base.asm:
[bits 32]
[extern _start]

call _start


kernel.c:
C++
void start { char *v = (char*) 0xb8000; *v="M";}
Posted
Updated 6-Apr-17 21:44pm

1 solution

The first step is to fix the reported errors and warnings.
# gcc -c kernel.c
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
It must be
void start() { char *v = (char*) 0xb8000; *v="M";}

Next try:
# gcc -c kernel.c
warning: assignment makes integer from pointer without a cast
Understanding this error is a bit tricky. It complains about *v="M" because "M" is a pointer (to a constant string). Your code won't work as expected. You have to use a function that copies a string or assign each character:
void start() 
{ 
    char *v = (char*)0xb8000; 
    v[0] = 'M';
    v[1] = '\0';
}

I have nasm nowhere installed so I can't check it.

Regarding the linking read the documentation. The -T option requires to be followed by a script file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900