Page 1 of 1

Code  re-write problem

Posted: Sat Aug 30, 2003 11:00 pm
by Sentient
I am in the process of rewriting some code to tidy it up a bit, and I have run into a major brick wall causing more problems than when I originally figured out how to do this.

As usual, its in the switch from real mode to protected mode.

Bochs dumpped:

00000525302e[CPU  ] jump_protected: S=1: descriptor not executable
00000525302p[CPU  ] >>PANIC<< exception(): 3rd (13) exception with no resolution
00000525302i[SYS  ] Last time is 1062374731
00000525302i[CPU  ] protected mode
00000525302i[CPU  ] CS.d_b = 16 bit
00000525302i[CPU  ] SS.d_b = 16 bit
00000525302i[CPU  ] | EAX=60000011  EBX=00000004  ECX=000c0fff  EDX=00000100
00000525302i[CPU  ] | ESP=00001000  EBP=00000000  ESI=0000010c  EDI=0000000c
00000525302i[CPU  ] | IOPL=0 NV UP DI PL NZ NA PE NC
00000525302i[CPU  ] | SEG selector     base    limit G D
00000525302i[CPU  ] | SEG sltr(index|ti|rpl)     base    limit G D
00000525302i[CPU  ] |  DS:1000( 0000| 0|  0) 00010000 0000ffff 0 0
00000525302i[CPU  ] |  ES:8000( 0000| 0|  0) 00080000 0000ffff 0 0
00000525302i[CPU  ] |  FS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00000525302i[CPU  ] |  GS:ffff( 0000| 0|  0) 000ffff0 0000ffff 0 0
00000525302i[CPU  ] |  SS:9000( 0000| 0|  0) 00090000 0000ffff 0 0
00000525302i[CPU  ] |  CS:1000( 0000| 0|  0) 00010000 0000ffff 0 0
00000525302i[CPU  ] | EIP=000000a3 (000000a3)
00000525302i[CPU  ] | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000525302i[CPU  ] | CR3=0x00000000 CR4=0x00000000

From what I can figure, it is trying to jump to protected mode, but the selector is not valid for a code segment???

This is the code that set's up protected mode (A20 is also enabled earlier)

CLI

DB 066h
LGDT [FWORD PTR GDT_48]

MOV EAX, CR0
OR AL, 1
MOV CR0, EAX

JMP $+2
NOP

;-------------------------------------------------------------------------------
; CPU is now in Protected Mode
; JMP FAR to Selector1:System32 to clear pipeline
;-------------------------------------------------------------------------------
DB 67h
DB 66h
DB 0EAh
DD 30000h
DW 0008

And the GDT...


GDT_48:
DW 4*8-1 ; GDT = 4 Entries
DD BIG_GDT ; GDT Base

BIG_GDT:
;-------------------------------------------------------------------------------
; #0 Segment Descriptor - DUMMY
; Intel Specification
;-------------------------------------------------------------------------------
DB 0,0,0,0
DB 0,0,0,0

;-------------------------------------------------------------------------------
; #1 Segment Descriptor - CODE SEGMENT (All 4Gb)
; Index=0x08H
;-------------------------------------------------------------------------------
DW 0FFFFh
DW 00000h
DB 00h
DB 09Ah
DB 0CFh
DB 00h

As I said, this is a rewrite of existing code and all this code is unchanged (and worked before). Can anyone see anything obvious, or make some other suggestions?

Cheers

RE:Code  re-write problem

Posted: Sat Aug 30, 2003 11:00 pm
by Sentient
I did notice one overlooked problem which just didnt appear before.
The GDT was not aligned, so I set it to Align 16.

Now Bochs seems to die with:

00000525302e[CPU  ] jump_protected: dpl > CPL
00000525302p[CPU  ] >>PANIC<< exception(): 3rd (13) exception with no resolution

RE:Code  re-write problem

Posted: Sat Aug 30, 2003 11:00 pm
by Sentient
Hmmm.. I don't know how I avoided this in my original code, but the GDTR was loading the wrong value

GDT_48:
DW 4*8-1 ; GDT = 4 Entries
DD BIG_GDT ; GDT Base

should have been:

GDT_48:
DW 4*8-1 ; GDT = 4 Entries
DD SEG<<4 + BIG_GDT ; GDT Base

I have no idea how that actually worked in my original code, but oh well, all is good now.