Bran's OS tutorial Exception handling

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
Chocrates
Posts: 5
Joined: Thu Aug 11, 2011 10:39 pm

Bran's OS tutorial Exception handling

Post by Chocrates »

Hey All,

Im going through the Bran Os tutorials and i cannot seem to get the idt set up to handle the exceptions.

Im a bit at a loss as to why its not working. The question is, what are some good ways to debug this early boot code, and are there any "normal" mistakes people usually make when trying to install these?

I can post the source, but for the most part its straight from the tutorials.

I am running this in qemu, and my physical cpu is an amd, which from what i can find doesn't seem like it has a GDT, which could be an issue.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Bran's OS tutorial Exception handling

Post by Nessphoro »

Eh, all x86 CPU have GDT,
and you're running QEMU which simulates the CPU, and in turn GDT,
Plus if you're booting via GRUB, it sets up a GDT for you.

But yeah, check if you're loading the LIDT with proper values.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bran's OS tutorial Exception handling

Post by gerryg400 »

and my physical cpu is an amd, which from what i can find doesn't seem like it has a GDT, which could be an issue.
What do you mean by this ? All 386 compatible CPUs need a GDT. Remember you must build the GDT.
If a trainstation is where trains stop, what is a workstation ?
Chocrates
Posts: 5
Joined: Thu Aug 11, 2011 10:39 pm

Re: Bran's OS tutorial Exception handling

Post by Chocrates »

gerryg400 wrote:
and my physical cpu is an amd, which from what i can find doesn't seem like it has a GDT, which could be an issue.
What do you mean by this ? All 386 compatible CPUs need a GDT. Remember you must build the GDT.
Wiki and a few other places say that GDT is intel specific.
Nessphoro wrote: Plus if you're booting via GRUB, it sets up a GDT for you.

But yeah, check if you're loading the LIDT with proper values.
Not using grub, letting qemu boot the kernel for me....

i will go back through the LIDT code
thanks!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bran's OS tutorial Exception handling

Post by gerryg400 »

Plus if you're booting via GRUB, it sets up a GDT for you.
Grub tells you not to rely on its GDT. It does load some values into the segment regs but you must not try to reload them without your own GDT.
If a trainstation is where trains stop, what is a workstation ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bran's OS tutorial Exception handling

Post by gerryg400 »

Chocrates wrote:Wiki and a few other places say that GDT is intel specific.
And your AMD is an Intel clone. Rest assured it needs a GDT.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Bran's OS tutorial Exception handling

Post by Nessphoro »

gerryg400 wrote:
Plus if you're booting via GRUB, it sets up a GDT for you.
Grub tells you not to rely on its GDT. It does load some values into the segment regs but you must not try to reload them without your own GDT.
Nevertheless it works,

And by GRUB I meant Multiboot compliant bootloader - aka QEMU's
Chocrates
Posts: 5
Joined: Thu Aug 11, 2011 10:39 pm

Re: Bran's OS tutorial Exception handling

Post by Chocrates »

No dice.

in the link.ld file i had to change phys = 0x00100000; to phys = 0x00001000; to allow qemu to load the kernel image

when compiling the the source from the tutorial, with the only modifcations being removing the underscores from function names in the asm file, and the link.ld file change, the exception handlers dont work.

Any ideas as to why the link.ld change is presumably causing this?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Bran's OS tutorial Exception handling

Post by Nessphoro »

Can we see your LD script.
Chocrates
Posts: 5
Joined: Thu Aug 11, 2011 10:39 pm

Re: Bran's OS tutorial Exception handling

Post by Chocrates »

OUTPUT_FORMAT("binary")
ENTRY(_start)
phys = 0x00001000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Bran's OS tutorial Exception handling

Post by Bietje »

Can you give us some more information of the errors you get..

The only thing I can think of right now is that you are overwriting you own code at some point.
Chocrates
Posts: 5
Joined: Thu Aug 11, 2011 10:39 pm

Re: Bran's OS tutorial Exception handling

Post by Chocrates »

Aha!

turns out it was working flawlessly, except that my puts function doesn't like strings, but instead likes an array of chars....

I will look into that and post here if i fix it, for completeness.

I appologize for wasiting your time!

Edit:

apparently i should have looked harder as well:

http://wiki.osdev.org/Bran%27s_Known_Bugs
Post Reply