I have a strange problem with the long jump after enabling protected mode. The jump instruction seems to get truncated if I try to jump, for example to 0x10000 in a linear code segment (this is where my kernel is).
My GDT looks like this:
Code: Select all
gdt_ptr:
.word gdt_end - gdt - 1 /* GDT Limit */
gdt_b: .long gdt /* GDT base, set by the code */
gdt:
.word 0, 0
.byte 0, 0, 0, 0
/* Linear Code segment */
.word 0xFFFF, 0x0000
.byte 0x0, 0x9A, 0xCF, 0 /* Code, Ring-0, Page-granular */
/* Linear Data segment */
.word 0xFFFF, 0x0000
.byte 0x0, 0x92, 0xCF, 0 /* Data, Ring-0, Page-granular */
/* Video data */
.word 4000, 0x8000
.byte 0xb, 0x92, 0, 0
/* Minikernel segment */
.word 0x1000, 0x0000
.byte 0x1, 0x9A, 0, 0
gdt_end:
Code: Select all
/* Load the GDT */
lgdt gdt_ptr
/* Enter Protected Mode */
movl %cr0, %eax
orb $1, %al
movl %eax, %cr0
.code32
/* We're in! */
/* Far jump in order to flush the prefetch queue */
ljmp $0x8, $0x10000
Code: Select all
00001154704i[CPU ] protected mode
00001154704i[CPU ] CS.d_b = 16 bit
00001154704i[CPU ] SS.d_b = 16 bit
00001154704i[CPU ] | EAX=00000011 EBX=00000000 ECX=00070002 EDX=00000000
00001154704i[CPU ] | ESP=0000fffc EBP=00000000 ESI=00007343 EDI=0000ffde
00001154704i[CPU ] | IOPL=0 vm RF ac nt of df if tf sf zf af PF cf
00001154704i[CPU ] | SEG selector base limit G D
00001154704i[CPU ] | SEG sltr(index|ti|rpl) base limit G D
00001154704i[CPU ] | CS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001154704i[CPU ] | DS:07c0( 0000| 0| 0) 00007c00 0000ffff 0 0
00001154704i[CPU ] | SS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001154704i[CPU ] | ES:1000( 0000| 0| 0) 00010000 0000ffff 0 0
00001154704i[CPU ] | FS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001154704i[CPU ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001154704i[CPU ] | EIP=00007c5c (00007c5c)
00001154704i[CPU ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00001154704i[CPU ] | CR3=0x00000000 CR4=0x00000000
00001154704i[CPU ] >> ea
00001154704i[CPU ] >> 00
00001154704i[CPU ] >> 00
00001154704i[CPU ] >> 10
00001154704i[CPU ] >> 00
00001154704i[CPU ] >> : jmp far 0010:0000
00001154704i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called
00001154704i[ ] Ctrl-C detected in signal handler.
00001154704i[ ] dbg: Quit