i use following code by nasm,but when enter pmode it has reboot:
;nasmw -o boot.com boot.asm
;copyboot boot.com 0 1
;i in real mode,it is right

bit 16
org 0
.....
a20msg db 'Setting A20 address line',13,10,0
pmodemsg db 'Setting CR0 -> Entering PMode',13,10,0

; Here's the locations of my IDT and GDT. Remember, Intel's are
; little endian processors, therefore, these are in reversed order.
; Also note that lidt and lgdt accept a 32-bit address and 16-bit
; limit, therefore, these are 48-bit variables.
pIDT dw 7FFh ; limit of 256 IDT slots
dd 0000h ; starting at 0000

pGDT dw 17FFh ; limit of 768 GDT slots
dd 0800h ; starting at 0800h (after IDT)

....
;reading kernel file
read_me:
xor ax, ax
int 0x13

mov eax,0x9000 ;
mov es,eax
xor bx,bx
mov ax,0x0204 ;
mov ch,0 ;
mov cl,2 ;
mov dh,0 ;
mov dl, ;
int 0x13 ;
jc read_me ;
;seting a20
mov si, a20msg ;
call message

call enable_A20

; the A20 line is on now. Let's load in our ITD and GDT tables...
; Ideally, there will actually be data in their locations (by loading
; the kernel)
lidt
lgdt

; now let's enter pmode...
mov si, pmodemsg
call message
call getkey

mov eax, cr0 ; load the control register in
or al, 1 ; set bit 1: pmode bit
mov cr0, eax ; copy it back to the control register
jmp $+2 ; and clear the prefetch queue
nop
nop
;!!!!!!!!!!!!!!!now go here,the machine is reboot?why??????????
mov si, pmodemsg
call message
call getkey

enable_A20:
cli

call a20wait
mov al,0xAD
out 0x64,al

call a20wait
mov al,0xD0
out 0x64,al

call a20wait2
in al,0x60
push eax

call a20wait
mov al,0xD1
out 0x64,al

call a20wait
pop eax
or al,2
out 0x60,al

call a20wait
mov al,0xAE
out 0x64,al

call a20wait


ret

a20wait:
.l0: mov ecx,65536
.l1: in al,0x64
test al,2
jz .l2
loop .l1
jmp .l0
.l2: ret


a20wait2:
.l0: mov ecx,65536
.l1: in al,0x64
test al,1
jnz .l2
loop .l1
jmp .l0
.l2: ret

times 510-($-$$) db 0
dw 0xAA55
Posted on 2003-05-23 11:22:44 by bgcq
Go to the Search Forum and seek there. Find MenuetOS (.org) for working sourcecode. Read the rules of the forum, pls. :alright:
Posted on 2003-05-24 08:55:04 by Ultrano
Me too. I dont know whats wrong with it. I think the GDT point to the wrong value. Where should GDT pointed to ? I have pointed it to where my Program loaded. It always error when executing LMSW ax or mov cr0,eax. Whats wrong with our preparation?
Posted on 2003-05-24 19:55:56 by realvampire
Hi,


pIDT dw 7FFh ; limit of 256 IDT slots
dd 0000h ; starting at 0000

pGDT dw 17FFh ; limit of 768 GDT slots
dd 0800h ; starting at 0800h (after IDT)


IMHO, both lidt and lgdt will fail. Your code said there is a IDT at address 0 with many entries (last byte at 7FFh)
Sure? What did you initialise at address 0. Just to enter PMode you don't need setup IDT at this point. Just comment out.
Your code for GDT said there is a GDT at 0800h. What is there? Have you stored the segment info there?

Entering the PMode consists of three important parts:
- enabling A20 gate
- set LSB in cr0
- do the jump right into with the selector to your code segment
this should be jmp 0008:00011000 if the second entry in your GDT is the code segment and the code is placed at 11000h

Check out this thread

Bye Miracle
Posted on 2003-05-26 07:13:49 by miracle

Hi,



IMHO, both lidt and lgdt will fail. Your code said there is a IDT at address 0 with many entries (last byte at 7FFh)
Sure? What did you initialise at address 0. Just to enter PMode you don't need setup IDT at this point. Just comment out.
Your code for GDT said there is a GDT at 0800h. What is there? Have you stored the segment info there?

Entering the PMode consists of three important parts:
- enabling A20 gate
- set LSB in cr0
- do the jump right into with the selector to your code segment
this should be jmp 0008:00011000 if the second entry in your GDT is the code segment and the code is placed at 11000h

Check out this thread

Bye Miracle


If my GDT located at CS:109 and for example CS is 8000, what value I should put at it? (CS:IP == 8000:0109 ).



MyGdt dw 001f
dd 80000109 << segment
or this ?
MyGDT dw 001f
dd 00080109 << Linier

Thanks for that thread, now I know I must point the LGDT to a real offset, not flat.
I load it before switching.
Posted on 2003-05-27 02:22:24 by realvampire
the never ending story :tongue:

I say its linear.

BTW sandpile.org said the 66h prefix for lgdt and lidt is slightly ignored.
Posted on 2003-05-27 04:31:59 by miracle