Page 2 of 2
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Thu Apr 21, 2005 7:40 am
by distantvoices
<me>
hands over a buncha hankies to Pype
Here, have a good snort and let it go lad. *chuckle*
</me>
@kofrad: honestly, align your kernel at 0x10000 and get it out of the bootloaders way. I'm sure this will save you quite some troubles later on. Believe me, your kernel gonna grow faster than you 'll believe once you've got a certain knack.
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Thu Apr 21, 2005 5:13 pm
by kofrad
I changed my linker script and my bootloader code to load the kernel at 0x10000, but when I run make, I get this
Code: Select all
bootsect.asm:23: warning: word value exceeds bounds
If I try to run it anyway, bochs will panic. I'm sorry if I dont seem to get it, but I'm still really new to this. Maybe it'll be easier and better if I was to convert my kernel to use the multiboot spec and just use grub?
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Thu Apr 21, 2005 8:48 pm
by Brendan
Hi,
kofrad wrote:
Code: Select all
bootsect.asm:23: warning: word value exceeds bounds
If I try to run it anyway, bochs will panic. I'm sorry if I dont seem to get it, but I'm still really new to this. Maybe it'll be easier and better if I was to convert my kernel to use the multiboot spec and just use grub?
If you're having trouble with something like this, then trying to find bugs in a full blown kernel is going to give you nightmares. My advice is to make the boot code work perfectly (just for experience) and then use GRUB (if you still feel like it) after that.
Take a look at line number 23 in "bootsect.asm", and see if you can find a word value that is exceeding it's bounds (ie. one that doesn't fit in 16 bits)...
Cheers,
Brendan
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Fri Apr 22, 2005 1:57 am
by kofrad
OK, a word's maximum integer value is 65,535 and the hex number 0x10000 = 65,536. The register that I am placing the hex value into is only 16 bits. How am I able to tell it to use a 32 bit number, or can I?
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Fri Apr 22, 2005 5:15 am
by Pype.Clicker
you could make it a 32bits register, but the BIOS would discard the highest bits.
Most likely, you need to set the segment register at 0x1000 and the offset at 0. That'll make you 0x1000*16 + 0 = 65536
That question confirms my first impression that you definitely need more assembly skillz. Ever tried "the Art Of Assembly programming" tutorials ?
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Fri Apr 22, 2005 8:57 pm
by kofrad
I'm real sorry to still be bothering you with this problem, I have my linker script set to align everything at 0x10000 and I wasnt exactly sure of how to set the segment register, so I used this code in the part where I tell the BIOS where to load my kernel data
Code: Select all
mov ax,0x1000
mov es,ax
mov bx,0x0
and for the jmp instruction to jump to the kernel I used this
When I enable tracing for bochs, it runs through and then freezes on the jmp instruction. I'm pretty sure I messed something up here because I know bochs will clear all memory to zero when it starts and it might be freezing trying to execute all zeros. I'm not even entirely sure my link.ld is correct, this might be because the link.ld is aligning everything at 0x10000. Here is my link.ld
Code: Select all
SECTIONS
{
. = 0x10000;
.text :
{
stub.o(asmstub);
*(.text)
}
.rodata ALIGN (0x10000) :
{
*(.rodata)
}
.data ALIGN (0x10000) :
{
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
Also, I found the art of assembly tutorials and I'm going through them right now. Thanks for the tip

Re:Computer crashes once bootloader tries to jump to kernel
Posted: Sat Apr 23, 2005 7:41 am
by Pype.Clicker
erhm. Since you're enabling pmode in your bootloader, you should rather have
The parameters for loading and the linker script seems both fine.
btw, you should try to gather more information from bochs than just "it crashes".
It might have told you "running in bogus memory" or "tripple fault". Those things are explained in the
TroubleShooting category of the FAQ
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Sat Apr 23, 2005 12:48 pm
by kofrad
Now I have my kernel working at 0x10000, but I still have the problem with my print() function. Bochs seems to freeze right after it leaves the function and the function dosent print anything.

Here is my print() function if you could possibly help me out:
Code: Select all
void print(const char *_message)
{
unsigned short offset;
unsigned long i;
unsigned char *vidmem = (unsigned char *)0xB8000;
// Read cursor position
out(0x3D4, 14);
offset = in(0x3D5) << 8;
out(0x3D4, 15);
offset |= in(0x3D5);
// Start at writing at cursor position
vidmem += offset*2;
// Continue until we reach null character
i = 0;
while (_message[i] != 0) {
*vidmem = _message[i++];
_message++;
vidmem++;
*vidmem = 0x0F;
//*vidmem = foreground + (background << 4) + (blink << 7);
vidmem++;
}
// Set new cursor position
offset += i;
out(0x3D5, (unsigned char)(offset));
out(0x3D4, 14);
out(0x3D5, (unsigned char)(offset >> 8));
}
Re:Computer crashes once bootloader tries to jump to kernel
Posted: Sun Apr 24, 2005 3:44 pm
by Pype.Clicker
there are hint for that too in the TroubleShooting category. I'd guess either non-zero-based datasegment or .rodata section missing in the image.