Page 1 of 1

Locating a Kernel

Posted: Sat Aug 23, 2003 12:31 am
by K.J.
to a address it's not really at without using paging(in PMode).

As described by Tim, you can do it via modifying the base of the GDT entries so that when "fake" addresses are added, they wrap around to physical addresses.

I've not quite gotten that far though yet, I'm just currently using the default GDT that GRUB hands me, compare a value in my data segment to a known good value, and trying to jump to a function within my kernel.

My kernel is linked so everything is offsetted to 0xC0000000. GRUB loads the kernel to 0x100000. So when I jump to a location, I need to somehow subtract 0xBFF00000 from the final location's address(as the GDT base isn't setup yet so that stuff will wrap around).

My current code for this is:

Code: Select all

[bits 32]
[section .text]
start:
   ; first test
   mov eax, [magic-0xBFF00000]
   cmp eax, 0x1234ABCD
   je fine-0xBFF00000 ; this a second test too actually

   ; comparing didn't end up correct, display a blinking "D"
    mov   word [0B8000h],9F44h
    cli
    hlt

fine:
    cli
    hlt

[section .data]
magic:
    dd 0x1234ABCD
NASM gags and says:

boiler.asm:7: error: short jump is out of range


Changing je fine-0xBFF00000 too je FAR fine-0xBFF00000 simply makes NASM complain of an incorrect use of the FAR operator.

I'm sure the solution to this is obvious, but I've not touched ASM for about 5 months, so I'm kinda rusty.

Any help is appreciated,
K.J.

Re:Locating a Kernel

Posted: Sat Aug 23, 2003 2:08 am
by Soap_
Try using "je NEAR your_address". If I recall correctly it will force nasm to generate the long version of the jmp opcode

Re:Locating a Kernel

Posted: Sat Aug 23, 2003 2:36 am
by Nairou
All conditional jumps are relative to the current location, so theres no need to modify the jump offset. Just use it as-is and it will work fine.

Re:Locating a Kernel

Posted: Sun Aug 24, 2003 9:56 pm
by K.J.
Thanks a ton Nairou, it works without a problem now. :)

K.J.