Page 2 of 3

Re:kernel problem (C Pointer)

Posted: Sat Jan 31, 2004 11:56 am
by guest
the cpu crashes if i load the kernel at 0x1000 and jump to 0x1000. but also if jump to 0x10000. then i try to load the kernel to 0x100000 and jump to it. bochs print out:

00000553165i[CPU ] BxError: instruction with op1=0xff
00000553165i[CPU ] nnn was 7
00000553165i[CPU ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00000554946i[CPU ] WARNING: HLT instruction with IF=0!


bootf02 load the kernel to 0x100000, enable paging and map the kernel to FFF80000 linear

Re:kernel problem (C Pointer)

Posted: Sat Jan 31, 2004 12:59 pm
by frank
Looking at your code, it reminds me..
You don't have a far jump after setting cr0 to 1
Do a far jump right after setting cr0.
It's neccessary for the cpu
the cpu crashes if i load the kernel at 0x1000 and jump to 0x1000. but also if jump to 0x10000.
Are you sure it crashes when it jumps?

Re:kernel problem (C Pointer)

Posted: Mon Feb 02, 2004 9:00 am
by guest
Are you sure it crashes when it jumps?
You're right if I load the kernel to 0x100000 the message is print out if I load. But else if I jump.
Looking at your code, it reminds me..
You don't have a far jump after setting cr0 to 1
Do a far jump right after setting cr0.
It's neccessary for the cpu
I try to Change my code to this:

Code: Select all

enter_pmode:
   cli

   lgdt [gdt_desc]

   mov eax, cr0      ; enable pmode
   or eax, 1
   mov cr0, eax

   jmp CODE_SEL:update_registers

update_registers:

   mov eax, DATA_SEL    ; error ????  ???
   mov ds,   eax
   mov es, eax
   mov ss, eax
   mov ds,eax
   mov gs,eax
   mov fs,eax

   mov ax, STACK_SEL
   mov ss,ax
    
   mov esp, 0xFFFF

   jmp 0x1000
but an third exception is happend ( 13 )

Re:kernel problem (C Pointer)

Posted: Mon Feb 02, 2004 10:25 am
by frank
jmp CODE_SEL:update_registers
...
jmp 0x1000
..
It has to be a far jump.
Try jmp dword CODESEL:update_registers and
jmp dword CODESEL:0x1000
lgdt [gdt_desc]
Are you sure this loads the table?
Shoudn't it be lgdt[gdt] ?

Re:kernel problem (C Pointer)

Posted: Mon Feb 02, 2004 10:35 am
by guest
It doesn't work. :'(

before all the changes I enter pmode and all (without the little function) works!!! but just nothing!!!

the gdt_desc is a descriptor:

see gdt.inc

Re:kernel problem (C Pointer)

Posted: Mon Feb 02, 2004 11:02 am
by frank
before all the changes I enter pmode and all (without the little function) works!!! but just nothing!!!
The little function?
You mean mov cr0,eax?


Try this to check it has sucessfully switched to protected mode.

Code: Select all

enter_pmode:
   cli

   lgdt [gdt_desc]

   mov eax, cr0      ; enable pmode
   or eax, 1
   mov cr0, eax

   jmp dword CODE_SEL:update_registers

update_registers:

   mov eax, DATA_SEL    ; error ????  ???
   mov ds,   eax
   mov es, eax
   mov ss, eax
   mov ds,eax
   mov gs,eax
   mov fs,eax

   mov ax, STACK_SEL
   mov ss,ax
   
   mov esp, 0xFFFF

   mov bx,0B800h 
   mov es,bx 
   mov byte [es:0],'F'  
   mov byte [es:1],1Fh

   jmp hang
hang: jmp hang
It doesn't load jump to your kernel, but it should put an F on your screen without crashing and hang.

Re:kernel problem (C Pointer)

Posted: Mon Feb 02, 2004 12:52 pm
by Therx
Don't know if it matters but "jmp dword CODE_SEL:update_registers" doesn't need the dword and the line "mov eax, DATA_SEL" and the ones following it can use just ax rather than eax

Pete

Re:kernel problem (C Pointer)

Posted: Tue Feb 03, 2004 8:35 am
by guest
Try this to check it has sucessfully switched to protected mode. ...
OK I try it and it doesn't work. Is my GDT incorrect???

Re:kernel problem (C Pointer)

Posted: Tue Feb 03, 2004 10:09 am
by guest
OK I have tried some things and the result is that i don't know whats going on with my bootloader. (I know that I know nothing) :P

Code: Select all

enter_pmode:
   cli

   lgdt [gdt_desc]

   mov eax, cr0      ; enable pmode
   or eax, 1
   mov cr0, eax

   jmp dword CODE_SEL:update_registers

update_registers:
   xor eax,eax ; bochs shows that eax is 0x60000000
                   ; after this operation  :-\

;   mov eax, DATA_SEL if I write this the CPU crashes (exception 13)
;   bochs out: write_virtual_checks(): write beyond limit, r/w
   cli
   hlt

Re:kernel problem (C Pointer)

Posted: Tue Feb 03, 2004 10:44 am
by Adek336
try adding [bits 16] and [bits 32] directives in the right places. If you don't, NASM will compile the instructions intended to be ran in pmode- as if they were ran in rmode.

Re:kernel problem (C Pointer)

Posted: Tue Feb 03, 2004 11:43 am
by guest
OK i forgot it. TY

but when I load my kernel to 0x1000 and jump to 0x1000
bochs out: write_virtual_checks(): write beyond limit, r/w

when I load my kernel to 0x100 and jump to 0x1000 all works fine, without the array operations.

OK but when I if create an array of integers all items are zero, too. Where the **** is the problem.
>:( ??? :P :-\

Re:kernel problem (C Pointer)

Posted: Tue Feb 03, 2004 12:59 pm
by Pype.Clicker
if you load starting from 0x100:0x0000 in real mode and jump to ZERO_BASED_CODE_SELECTOR:0x1000, there's no surprise it will work better than if you load at 0x1000:0x0000 and jump at ZBCS:0x1000. Read Perica's tutorial (see BonaFide in .:QuickLinkz:.) about real mode addressing if it doesn't sound straightforward, obvious and a bit insulting to you that i remind it ;D

btw, it's generally unwise to start loading at 0x100:0x0000 as the bootsector itself is located at 0x7C0:0x0000 ... so if your kernel is above 0x6C00 bytes (that's roughly 32KB), you'll find yourself overwriting your preciousss bootloader in the process ... from there anything can occur ...

Re:kernel problem (C Pointer)

Posted: Wed Feb 04, 2004 8:49 am
by guest
TY, now I load my kernel at 0xFFFF:0x0010 not to 0x100000 or something else and jump to 0x100000 and see all works fine :).

Re:kernel problem (C Pointer)

Posted: Wed Feb 04, 2004 9:01 am
by Pype.Clicker
well, it will indeed work fine as long as the A20 gate is enable (remember that BOCHS does this by default, but not all BIOSes do so) and that your kernel is smaller than 65520 bytes ...

Re:kernel problem (C Pointer)

Posted: Wed Feb 04, 2004 2:19 pm
by Neo
does this mean that if my kernel is greater than 64KB i cant load it above the 1MB mark? od i have t load it in the lower 1MB itself then?