Page 1 of 1
Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 9:05 am
by nake
Hi all, this is my first post here ^^
I'm starting to develop my kernel, but I get those
start.o:(.text+0x2d): undefined reference to `_kmain'
As I'm quite new on compiling on linux I think I did something wrong while ./configure or so...
On the wiki there is a tutorial on how compiling gcc an binutils, but nothing for nasm (or at least i couldn find it...)
This is what I did:
I downloaded the nasm source code, untared it and cd into it's folder, then
Code: Select all
export PREFIX=/usr/cross
export TARGET=i586-elf
./configure --prefix=$PREFIX --target=$TARGET
make all
make install
export PATH=$PATH:$PREFIX/bin
$TARGET-nasm -f elf -o start.o start.asm
It says:
i586-elf-nasm: no se encontrĂ³ la orden (which means that couldn't find the order)
If I assembly it using
I get the _kmain error while linking... yagh
Thanks in advance
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 9:25 am
by Combuster
Obviously, "_kmain" and "kmain" are not the same thing... Fix your spelling
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 9:44 am
by nake
... It fixed it, however in the wiki says:
I get unresolved references to kmain, or others because of missing / superfluous underscores in the object files !?
As an immediate resolve, you can use -fno-leading-underscores or -fleading-underscores to get the object file variant you need; in the long run, you might want to set up a GCC Cross-Compiler with the correct default behavior.
I want to do it the good way, not the fast one...
Thanks for the fast reply
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 9:53 am
by Combuster
As quoted, if you have the
GCC Cross-Compiler built according to those instructions, it has the correct behaviour by default. Which means there are no leading underscores.
Note that the default depends on the host you are compiling for - on DOS and Windows leading underscores are customary, while on practically all others they are not. Which is one of the reasons why you should use a cross-compiler: to get rid of the host platform-specific features the compiler throws into your OS.
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 12:04 pm
by nake
mmm....still having trouble.
I couldnt find anything on the forums nor wiki.
If I try to call a function made in asm i get an
undefined reference error while linking. And this time is not a spelling error.
The assembly code:
Code: Select all
global gdt_flush
extern gp
gdt_flush:
lgdt [gp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2
flush2:
ret
and the C code:
Code: Select all
struct gdt_entry gdt[3];
struct gdt_ptr gp;
extern void gdt_flush(void);
void gdt_install(void)
{
/* Setup the GDT pointer and limit */
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
gp.base = (int)&gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_flush();
}
Then I just assembly, compile everything, and then link it:
Code: Select all
nasm -f elf -o start.o start.asm
$TARGET-gcc -Wall -Wextra -Werror -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -fno-leading-underscore -I./include -c -o gdt.o gdt.c
$TARGET-ld -T link.ld -o kernel.bin start.o kernel.o gdt.o display.o
I've really no clue why it fails, I even tried adding
'_' everywhere xD
Code: Select all
gdt.o: In function `gdt_install':
gdt.c:(.text+0xb2): undefined reference to `gdt_flush'
Thanks
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 12:22 pm
by Combuster
did you use sections?
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 12:32 pm
by nake
Only the .bss for the stack... Do I have to define all of them?
However I think I'm going to start again following another tutorial.
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 12:38 pm
by nake
My .ld looks like this:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
And I think in the assembly everything is .text except the part that says:
Code: Select all
SECTION .bss
resb 8192 ; This reserves 8KBytes of memory here
sys_stack:
And thats the last thing I have on my assembly file. I feel like a big noob xD
I dont really know too much about assembly, apart from microcontroler's asm.
Re: Cross-compile nasm linux problem
Posted: Tue Mar 30, 2010 12:52 pm
by Combuster
nake wrote:I think
Don't think, know. Especially when you have already proven yourself wrong somewhere