Page 1 of 1

LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 5:25 am
by hex
Hello!

I am sorry, if I ask an obvious question here, but I tried searching the forum with no result.

I had some trouble getting Interrupts to work, so I looked into the wiki-section about getting this to work.
When I try to bring the asm-example from http://wiki.osdev.org/I_Cant_Get_Interrupts_Working to compile with nasm, I get an error about the LINEAR_ADRESS thing: "error: comma expected after operand 1".
It refers to this line: "dd LINEAR_ADDRESS(idt)"
Why a comma after this operand and where? And what after it?

Can anybody help me and explain to me, what is wrong there?

Thanks!

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 6:06 am
by Combuster
The idea is that you fill that macro in for yourself :wink:

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 6:09 am
by hex
Aaah!
Okay :D

Then another question comes to my mind: How?
I'am sorry - I'm quite new to this and now I am confused, how to get a linear address?

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 6:54 am
by CodeCat
It depends on how your kernel is linked. If it's supposed to run at 0xC0100000 and the bootloader loads it at 0x00100000, then the macro just has to subtract 0xC0000000 from a pointer to get its physical (linear) address.

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 7:03 am
by hex
thx :)

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 7:17 am
by Combuster
The linear address is the address after segmentation (before is virtual address), but before page translation (which turns it into a physical address). So if your kernel is at 0xC0000000, then the linear address is somewhere in 0xC0000000. If you're in real mode, then you'll need to add the segment offset, i.e. if your code runs at 0x1000:0x0000, then the linear address is idt_offset + 16 * segment, or 0x10000 + idt

@Codecat: time to fix your GDT and IDT code :wink:

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 8:51 am
by hex
I currently have not Paging ;)

By the way: I have no clue, where exactly Grub puts my Kernel in Memory :oops:
I think this information may be obtained using the multiboot-structure?

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 8:55 am
by Combuster
Grub puts you exactly where you told it to.

Assuming that you have an ELF kernel - look at your linker script and see what its puts into the headers for GRUB to find
Amusingly enough, it makes the same changes in the binary, meaning that if you grab the address of something you already have its true address. But having met the required knowledge you should've known that :wink:

Re: LINEAR_ADRESS causes error in nasm

Posted: Sat Nov 01, 2008 9:23 am
by hex
Ah :)
You know - I am really unsure about, what I got right and what I got wrong. But with this, I was right in the first place and then considered it as wrong. Dammit.

Re: LINEAR_ADRESS causes error in nasm

Posted: Sun Nov 02, 2008 5:15 am
by CodeCat
Combuster wrote:@Codecat: time to fix your GDT and IDT code :wink:
Oops, I mixed up linear and physical addresses in that post.