Page 1 of 2
[SOLVED]Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 1:21 pm
by bashcommando
Well, I tried to link my two binaries together and...
Code: Select all
boot.o: In function `skip':
boot.asm:(.sfbootloader+0x1e): relocation truncated to fit: R_386_16 against `.sfbootloader'
boot.asm:(.sfbootloader+0x29): relocation truncated to fit: R_386_16 against `.sfbootloader'
The code in question is:
Code: Select all
skip:
cli
lgdt [gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp 08h:pmode
BITS 32
pmode:
extern kmain
call kmain
jmp $
Maybe it has to do with the gdt or protected bit?
Here is my GDT:
Code: Select all
gdt: dw 0, 0, 0, 0
codesel: dw 207, 39424, 0, 65535
datasel: dw 207, 37376, 0, 65535
gdt_end:
gdtr: dw gdt_end - gdt - 1
dd gdt
Also I added my own text section called .sfbootloader but that didn't seem to effect anything. Help?
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 1:57 pm
by BrightLight
Actually, a boot loader loads and executes a kernel. A kernel is not usually linked to a boot loader. Try parsing a file system instead, load your kernel to memory and jump/call its entry point.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:08 pm
by bashcommando
omarrx024 wrote:Actually, a boot loader loads and executes a kernel. A kernel is not usually linked to a boot loader. Try parsing a file system instead, load your kernel to memory and jump/call its entry point.
Noted for future reference.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:09 pm
by no92
omarrx024 basically told you what you have to do. I'm a little bit worried about the fact that you have to ask this question - do you have to knowledge you have to have to be able to program such a thing?
omarrx024 wrote:A kernel is not usually linked to a boot loader.
I'd even say that a kernel is never linked against the bootloader.
Typically, for a bootloader (assuming a BIOS environment), the first stage (which is 512 bytes big) gets loaded first. It only reads the second one from the disk and sets ip accordingly. The second stage does all the fancy stuff - like reading the file system, loading the kernel into memory and passing execution to it.
A bootloader is a little OS of its own. Many OSdevers here once wanted to create their own bootloader, but stopped it in order to be able to do the more exciting kernel development instead. Maybe that's something to think about for you - relying on GRUB sounds scary for a lot of newbies (for a reason I haven't understood yet), but it's not as bad as you think it is. Having Linux or a BSD is crucial for that (GRUB doesn't run on Windows).
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:13 pm
by psychobeagle12
I had an issue like this once myself. If you google it you should find the solution. Here is the code that caused my problem:
Notice what I did wrong? The 'byte' specifier was trying to truncate the 32-bit address to 8 bits. The linker was complaining because I was creating an 8 bit value from the 32-bit value. Don't be surprised if you find your issue somewhere other than the code you posted, because I don't see any such problem in what you have there. I'll say again that you should not be trying to link your kernel to your bootloader, but I don't believe that this is why you were getting this particular warning. I think it has to do with the truncation of a 32-bit address to a smaller size, specifically a 16-bit value.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:38 pm
by iansjack
Having Linux or a BSD is crucial for that (GRUB doesn't run on Windows).
That is incorrect.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:41 pm
by BrightLight
bashcommando wrote:Noted for future reference.
Take a look at
Required Knowledge in the wiki. And what I told you is not even needed for reference; it is just part of the standard boot process.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 2:41 pm
by BrightLight
no92 wrote:Having Linux or a BSD is crucial for that (GRUB doesn't run on Windows).
GRUB can chain load Windows and other non-multiboot compliant OSes.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 3:03 pm
by iansjack
Of course Grub can chainload Windows, but that's not what no92 was talking about. He said that it doesn't run on Windows; it does.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 4:12 pm
by bashcommando
no92 wrote:Maybe that's something to think about for you - relying on GRUB sounds scary for a lot of newbies (for a reason I haven't understood yet), but it's not as bad as you think it is.
Unfortunatly I have already used grub enough times to know that I don't want it packaged in my OS(because seriously who wants a bootloader bigger than thier own OS?). I have had to recover linux a bunch of times after messing around with the kernel. So I am interested mostly in the bootloader.
omarrx024 wrote:Actually, a boot loader loads and executes a kernel. A kernel is not usually linked to a boot loader.
Let's just call it a unusual OS then, it's only temporary.
psychobeagle12 wrote:If you google it you should find the solution.
No solution which is why I am posting it here.
omarrx024 wrote:
Take a look at
Required Knowledge in the wiki. And what I told you is not even needed for reference; it is just part of the standard boot process.
How many times do I have to look at that page because somebody didn't understand that I want something different than a "Normal OS". I do have knowledge of that, but you don't get what I am doing.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 5:00 pm
by iansjack
https://www.technovelty.org/c/relocatio ... t-wtf.html
(This is talking about 64-bit code, but the principles are the same.) Use objdump to inspect your object files and the problem should be obvious. The lesson is that if something isn't working right you should use the tools provided to inspect the generated code, or if it's at runtime use a debugger to inspect what is actually happening. That way you will learn a lot more than you will by running to the forums every time you have a silly error. Try to research and work out explanations for yourself rather than always asking others to provide them; if you don't understand the processor you are going to have bigger problems down the line.
you don't get what I am doing
I'm not really convinced that you get what you are doing. It's nothing out of the ordinary; in fact it seems to be based on some standard tutorials.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 6:04 pm
by psychobeagle12
So my guess is that the solution I posted was NOT found on google? Cuz' like I said, I had this same problem and googled it, and solved it WITH MY POSTED SOLUTION! Not only did I tell you how to find the solution, I posted it for you!
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 10:37 pm
by bashcommando
psychobeagle12 wrote:So my guess is that the solution I posted was NOT found on google? Cuz' like I said, I had this same problem and googled it, and solved it WITH MY POSTED SOLUTION! Not only did I tell you how to find the solution, I posted it for you!
Umm, you realize that...
1. I am using nasm
2. Google produces certain results for different people
iansjack wrote:Use objdump to inspect your object files and the problem should be obvious. The lesson is that if something isn't working right you should use the tools provided to inspect the generated code, or if it's at runtime use a debugger to inspect what is actually happening.
Thank you, I will try that next time.
Re: Problem when linking bootloader and kernel.
Posted: Thu Jan 29, 2015 11:30 pm
by Roman
Re: Problem when linking bootloader and kernel.
Posted: Fri Jan 30, 2015 6:49 am
by bashcommando
Appearently I was "Geek loading".
I am guessing that is bad?