Page 1 of 1

Setting up custom gdt after paging is enabled...

Posted: Sun Mar 20, 2005 11:57 am
by Silverhawk
Hello guys !

After kernel 0xc0000000 linking epsiod, I've enabled paging, mapping the first 4Mb as identity and at 0xc0000000. (I use grub to boot, and without trying to define my proper gdt, it seems to work well)
Since my gdt worked well before trying to test 0xc0000000 kernel linking (before, I was in identity mapping mode), I wouldn't think this can pose a problem !
Well, here is what bochs tells me :
00003641152e[CPU ] load_seg_reg: GDT: DS: index(0002) > limit(000000)
00003641152e[CPU ] exception(): 3rd (13) exception with no resolution, shutdown
And here is the code :

Code: Select all

.text
... 
; just after paging is enabled

lgdt [gdt_ptr] 
   
   mov ax,KERNEL_DATA_SEL
   mov ds,ax
   mov es,ax
   mov ss,ax
   mov fs,ax
   mov gs,ax

   jmp KERNEL_CODE_SEL:.continue
.continue :

...

.data

gdt:

; NULL descriptor
   dw 0         ; limit 15:0
   dw 0         ; base 15:0
   db 0         ; base 23:16
   db 0         ; type
   db 0         ; limit 19:16, flags
   db 0         ; base 31:24

KERNEL_CODE_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 9Ah         ; present,ring 0,code,non-conforming,readable
   db 0CFh         ; page-granular (4 gig limit), 32-bit
   db 0
   
KERNEL_DATA_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 92h         ; present, ring 0, data, expand-up, writable
   db 0CFh         ; page-granular (4 gig limit), 32-bit
   db 0
   
USER_CODE_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 0FAh         ; present,ring 3,code,non-conforming,readable
   db 0DFh         ; page-granular (4 gig limit), 32-bit
   db 0
   
USER_DATA_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 0F2h         ; present, ring 3, data, expand-up, writable
   db 0DFh         ; page-granular (4 gig limit), 32-bit
   db 0
   
; unused descriptor
   dw 0
   dw 0
   db 0
   db 0
   db 0
   db 0

gdt_end:

gdt_ptr:
   dw gdt_end - gdt - 1
   dd (gdt - 0xc0000000 + 0x100000)

...
Does someone know where this error comes from ?

thanks.

Re:Setting up custom gdt after paging is enabled...

Posted: Sun Mar 20, 2005 12:59 pm
by Candy
you might've mispaged the page with gdt_ptr on it. Are you sure it's mapped to the place it's linked to be?

Re:Setting up custom gdt after paging is enabled...

Posted: Sun Mar 20, 2005 1:20 pm
by Silverhawk
Yes, I'm sure...
I map from 0x0 and 0xc0000000 the first 4 mb of physical memory... and my kernel which starts at 0xc0000000 is less than 4 Mb size...
When I keep using grub implicit gdt, it works well.
Moreover, bochs should tells me exception 14 insted of exeption 13 if there is a mispaging, no ?

Re:Setting up custom gdt after paging is enabled...

Posted: Sun Mar 20, 2005 2:43 pm
by Candy
if you don't page it gives exception 14

if you mispage (place a different page at the right spot) it doesn't say anything but loads the GDT as you request, using false data. If you then use it you get the wrong output.

Got a bootable disk image for bochs testing?

Re:Setting up custom gdt after paging is enabled...

Posted: Sun Mar 20, 2005 3:22 pm
by Silverhawk
OK, thanks for these explainations !

Yes, I've got a bochs floppy disk image for testing purpose...

I use gdb to debug in bochs. Till I was in identity mapping, it was really convenient to debug ! But now my small kernel is linked at 0xC0000000, gdb doesn't seem to stop on break points !!!! (so, it's hard to debug...)

I would like to add that for testing purpose, I've transformed my small kernel to a very simple one : it does nothing more than displaying black '1' characters on a blue screen...

Here is the the asm code that call c kernel entry routine...
(my floppy disk image is too big to be attached : 1.44 Mb)

Re:Setting up custom gdt after paging is enabled...

Posted: Mon Mar 21, 2005 1:34 am
by Candy
place breakpoints on physical addresses, and if you REALLY need it to stop (say, just before a crash) place a few consecutive. It occasionally misses one.

The point of the floppy disk image is that I can boot it in bochsdbg and run my own checkpoints & stuff... worked for two others this weekend alone, so I figured... :)

Re:Setting up custom gdt after paging is enabled...

Posted: Mon Mar 21, 2005 2:11 pm
by Silverhawk
Well, even compressed, my floppy bochs image take more than 30 kb...
I'm still trying to fix the bug...
I hope it will be fixed some day ! ;D
By the way, even establishing breakpoint at physical memory (without using symbols, but hexadecimal addresses instead) gdb keeps on its way without stopping !!! Really weird and unconvenient !!!
so long !