Page 1 of 2
Not linking
Posted: Wed Mar 30, 2016 4:00 am
by moondeck
Hi,
i am compiling my "operating system" thingie, but it stops at linking, it says
Code: Select all
kloaderasm.o: In function `irq_common_stub':
kernelld.asm:(.data+0xbb): undefined reference to `ihandler'
The code is for IRQ handling, ihandler() is in the kernelio directory.
The code for the OS is on GitHub
https://github.com/m00nd3ck/hydrogen
What did i do wrong?
Re: Not linking
Posted: Wed Mar 30, 2016 4:13 am
by gerryg400
The ihandler function is defined in irq.c. According to your Makefile you aren't compiling or linking that file.
Re: Not linking
Posted: Wed Mar 30, 2016 4:14 am
by moondeck
gerryg400 wrote:The ihandler function is defined in irq.c. According to your Makefile you aren't compiling or linking that file.
Oh ****, thanks
Derp me
Re: Not linking
Posted: Wed Mar 30, 2016 4:16 am
by Octocontrabass
In addition, the options you're passing to gcc don't look quite right (
you don't need -m32 but you do need -lgcc) and you're directly calling ld to link your kernel instead of using gcc.
Re: Not linking
Posted: Wed Mar 30, 2016 4:23 am
by moondeck
Octocontrabass wrote:In addition, the options you're passing to gcc don't look quite right (
you don't need -m32 but you do need -lgcc) and you're directly calling ld to link your kernel instead of using gcc.
Thanks,what is wrong with calling ld?
Re: Not linking
Posted: Wed Mar 30, 2016 4:47 am
by Octocontrabass
There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use the same options for both compiling and linking.
Re: Not linking
Posted: Wed Mar 30, 2016 4:52 am
by moondeck
Octocontrabass wrote:There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use the same options for both compiling and linking.
Thanks, now i am getting another error
Code: Select all
kernelio/irq.c:66:5: error: too many arguments to function 'init_irq_handler'
init_irq_handler(47, (unsigned)irq15, 0x08, 0x8E);
I have commited the new code to the repo
Re: Not linking
Posted: Wed Mar 30, 2016 5:08 am
by gerryg400
Let me fill in the gaps.
Your made an error in the file "kernelio/irq.c:" on line "66" at the ":5":th character. The "error:" is that you passed "too many arguments to" the "function 'init_irq_handler'".
Re: Not linking
Posted: Wed Mar 30, 2016 5:13 am
by moondeck
gerryg400 wrote:Let me fill in the gaps.
Your made an error in the file "kernelio/irq.c:" on line "66" at the ":5":th character. The "error:" is that you passed "too many arguments to" the "function 'init_irq_handler'".
yes, but i have used code from Bran's tutorial, and i thought it would work.
The definition of init_irq_handler is
Code: Select all
void init_irq_handler(int irq, void (*handler)(struct regs *r))
{
irqrout[irq] = handler;
}
but for some reason its usage is
Code: Select all
init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
Re: Not linking
Posted: Wed Mar 30, 2016 5:20 am
by iansjack
moondeck wrote:yes, but i have used code from xxxx's tutorial, and i thought it would work.
A classic beginner's mistake. Never just copy code from somewhere else, without understanding it, and then complain that it doesn't work.
Re: Not linking
Posted: Wed Mar 30, 2016 5:26 am
by moondeck
iansjack wrote:moondeck wrote:yes, but i have used code from xxxx's tutorial, and i thought it would work.
A classic beginner's mistake. Never just copy code from somewhere else, without understanding it, and then complain that it doesn't work.
Yeah, i understood what it does, but there were some unexplained things there.
For example:
Code: Select all
init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
what are the 0x08, 0x8E there for? i have removed them, and it compiles normally, without triple faulting. i will try to make it actually do something
Re: Not linking
Posted: Wed Mar 30, 2016 10:45 am
by BrightLight
moondeck wrote:Code: Select all
init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
what are the 0x08, 0x8E there for? i have removed them, and it compiles normally, without triple faulting. i will try to make it actually do something
0x08 is probably your code segment. 0x8E tells the CPU this IDT entry is present, requires a descriptor priviledge 0, and is an i386 interrupt gate.
Re: Not linking
Posted: Wed Mar 30, 2016 12:52 pm
by mikegonta
moondeck wrote:Octocontrabass wrote:In addition, the options you're passing to gcc don't look quite right (
you don't need -m32 but you do need -lgcc) and you're
directly calling ld to link your kernel instead of using gcc.
Thanks,what is wrong with calling ld?
Octocontrabass wrote:There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use
the same options for both compiling and linking.
Personally, I prefer to link separately during development. That way I can concentrate on getting it to compile without concern for
getting it to link just yet. I use a Windows command script, I know a make file is better, however the script allows me more control
(and easier for me to customize). For example (coming from an asm background) I option gcc to output a listing which the script
opens in a text editor. After linking, the binary is then copied to a live USB flash drive which is emulated by Qemu.
Re: Not linking
Posted: Wed Mar 30, 2016 5:34 pm
by Octocontrabass
mikegonta wrote:Personally, I prefer to link separately during development.
You can still link separately even when using GCC to link.
Re: Not linking
Posted: Thu Mar 31, 2016 12:43 am
by FusT
moondeck wrote:Yeah, i understood what it does, but there were some unexplained things there.
You are contradicting yourself there.
I'm not trying to offend you but I think you haven't got the faintest idea what that code is
actually doing or how the C language and compiler work.
GCC is actually your friend when it comes to errors, it usually is pretty clear about what mistakes you made and where you made them, you just need to understand them..
What omarrx024 said should have been clear to you before you started writing/copy-pasting code.
I strongly suggest you read
http://wiki.osdev.org/Beginner_Mistakes and catch up on some theory so you understand
why and
how things are the way they are.
OSdev is hard but doable. just don't give up