kernel entry address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ezome
Posts: 20
Joined: Thu Aug 30, 2007 3:09 pm
Location: Germany

kernel entry address

Post by ezome »

how does my bootloader find the entry address of my c kernel?


i link with

Code: Select all

LDFLAGS = -nostdlib -e _main -Ttext 0x100000 -L$(LIB_PATH) -Map kernel.map
but the mapfile says this

Code: Select all

Address of section .text set to 0x100000
LOAD kernel32.o
LOAD main.o
LOAD ..\..\lib\/libos.a
LOAD ..\..\lib\/libc.a

.text           0x00100000      0x670
 *(.text)
 .text          0x00100000       0x90 kernel32.o
                0x00100034                kernel32
 .text          0x00100090       0x20 main.o
                0x00100090                main
so the main function is placed at 0x00100090 which is pretty useless
and it moves from time to time when the code changes

how do i make sure the main function stays at 0x00100000?
here it is:

Code: Select all

void kernel32();

int main()
{
  kernel32();
  while(1);
}
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

I would use a small stub written in ASM that calls the main function.
Something like:

Code: Select all

bit 32

global start
extern main

start:
call main
And set the entry point to "start" (with ld -> "ENTRY(start)")
User avatar
ezome
Posts: 20
Joined: Thu Aug 30, 2007 3:09 pm
Location: Germany

Post by ezome »

and how do i link a nasm binary to a c binary?
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post by jerryleecooper »

Why do you want main to return a value? What is a map file? :?:
My advice is, make a main.c file with your main entry function, that will be called by your bootloader, don't put any function before your main function, and link your main.o object first. It's not only an advice, but the thing to do. Don't play with your main function a lot, or else it will break often.
User avatar
ezome
Posts: 20
Joined: Thu Aug 30, 2007 3:09 pm
Location: Germany

Post by ezome »

yeah you are right. the return value of main is pretty useless
just an old habbit after years of c++

a mapfile just shows you where the functions are placed in your executable

i think the problem is that i link kernel32.c before main.c
as you can see here

Code: Select all

.text           0x00100000      0x670
 *(.text)
 .text          0x00100000       0x90 kernel32.o
                0x00100034                kernel32
 .text          0x00100090       0x20 main.o
                0x00100090                main
User avatar
ezome
Posts: 20
Joined: Thu Aug 30, 2007 3:09 pm
Location: Germany

Post by ezome »

ok it's fixed

it was just about the linking order
after i renamed main.c my makefile linked it first

Code: Select all

.text           0x00100000      0x670
 *(.text)
 .text          0x00100000       0x20 _main.o
                0x00100000                main
 .text          0x00100020       0x90 kernel32.o
                0x00100054                kernel32
Post Reply