Page 1 of 1

jmp to C kernel

Posted: Wed Jan 22, 2003 10:25 am
by pini
I used int 13h to load my kernel in real space memory and int 15h to move it above 1MB. There is no error here (all the interrupts returned with successfully results).
Then I go to protected mode :

Code: Select all

mov eax,cr0
or eax,0x1
mov cr0,eax
jmp .next
.next:
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0x9F000
jmp dword 0x8:0x100000
My GDT contains three entries : dummy, Code & Data and IS correct.
I get this with bochs :
[CPU] BxError: instruction with op1=0xff
[CPU] nnn was 7
[CPU] WARNING: Encountered an unknown instruction (signalling illegal instruction) :
[CPU] >>PANIC<< exception(): 3rd exception with no resolution
Seems to be a "simple" triple fault, but when I put a hlt before the jump to the kernel, everything works fine => The problem is within the jump, but I couldn't find it out.

Can anyone help ?

Re:jmp to C kernel

Posted: Wed Jan 22, 2003 4:36 pm
by Pype.Clicker
the code you execute is invalid. Check the first bytes of your kernel are an entry point. And also check you properly loaded the kernel

Re:jmp to C kernel

Posted: Thu Jan 23, 2003 12:40 pm
by distantvoices
this kind of error i have got, when i have forgotten to build the kernel a plain binary file with the entrypoint at the very beginning.

this is because the bootloader i have stuffed to gether with various sources does just load a plain binary file into memory, activates protected mode with a very general gdt and after that jumps to the kernel. I just keep it simple to get things running first, before i start playing with the trickses.

regarding the C-Kernel: this part of the Kernel I do not jump to with the bootloader-jump. I first jump to asm-routine which does some little initialization, and after that, i go to the c kernel. f. ex. i set a stack large enough in this asm-file. Just call it the asm-layer.

Hope this is not too confusing.

Re:jmp to C kernel

Posted: Thu Jan 23, 2003 6:10 pm
by noodles
I have seen a few articles which suggest this is probably something to do with the data section appearing first in the binary. This means you are trying to execute data as instructions. The two ways round this are:

Do as previously suggested and use an assembly routine to call the main function in the kernel.

Or write a linker script so that the linker knows what order they go in. Personally the first option sounds way the easiest.

HTH
Chris

Re:jmp to C kernel

Posted: Fri Jan 24, 2003 1:14 am
by Pype.Clicker
my personal approach was to translate the flat binary and pre-pend it a small (16bytes) header carrying:
- a magic id (KERN) proving this is a kernel binary file
- load_size : how much bytes from the file should be read in memory (.text + .data)
- alloc_size : how much bytes should be available in RAM for that file (.text+.data+.bss). bytes from load_size to alloc_size will be wiped-out to zeroes by the loader.
- entry_point: this is the place where the EIP should be jumped to.

Re:jmp to C kernel

Posted: Fri Jan 24, 2003 11:27 am
by pini
At last, I can explain a little what my problem is.
Between the setup of the segment registers to to good GDT descriptor and the jump to the kernel, I put this :

Code: Select all

mov eax,0xFFFF
And bochs give me the same value for its EAX registers (nothing wrong here ;))
But when I use

Code: Select all

mov eax,0x10000
instead, bochs says that EAX contains 0x00000000 ! And this is true for every value above 0xFFFF

Second point :
I am using this syntax for my "jump-to-the-kernel" instruction :

Code: Select all

jmp dword KERNEL_ADDRESS
where KERNEL_ADDRESS contains 0x100000 (1 Meg).
But when I disassemble the bootloader, nasm produce this code instead :

Code: Select all

66E961F7 : jmp dword 0xF800
Which is totally incorrect !

I know that these problems don't come from the A20 gate, opened before this. So where may them come from ?

Re:jmp to C kernel

Posted: Fri Jan 24, 2003 5:33 pm
by Curufir
Shot in the dark, but are you still in 16-bit mode when you try to load eax? Specifically I mean the before a [bits 32] assembler instruction.

Re:jmp to C kernel

Posted: Sun Jan 26, 2003 3:45 am
by Pype.Clicker
it looks like you miss some "db 66" and "db 67" (32bits operands and 32bits addresses opcodes) in your code ...