Please help me!I don't know where error in!It always restart! :sad: :sad: :sad:

;----------------------------------------------------------------------
; Processor Initialization
;----------------------------------------------------------------------
bits 16
org 0x7c00
;----------------------------------------------------------------------
GDT_CodeSegment_Selector    equ 0x08
Processor_Interrupt_Procedure_Sector_Total  equ 10
Processor_Interrupt_Procedure_Sector_Situation  equ 8
Processor_Interrupt_Procedure_Memory_Location  equ 0x100000
Processor_Interrupt_Procedure_Sector_Word_Total  equ Processor_Interrupt_Procedure_Sector_Total*256
;----------------------------------------------------------------------
jmp Initializate_Processor

GDT_Tables:
  GDT_Null:
Null_Discriptor1 dd 0x00
Null_Discriptor2 dd 0x00

  GDT_CodeSegment_Address equ $-GDT_Tables
  GDT_CodeSegment:
  dw 0xffff
  dw 0x0000
  db 0x00
  db 10011010b;0x9a
  db 11001111b;0xcf
  db 0x00

  GDT_DataSegment_Address equ $-GDT_Tables
  GDT_DataSegment:
  dw 0xffff
  dw 0x0000
  db 0x00
  db 10010010b;0x92
  db 11001111b
  db 0x00

  GDT64_CodeSegment_Address equ $-GDT_Tables
  GDT64_CodeSegment:
  dd 0x0000
  db 0x00
  db 10000000b;10011000b
  dw 0

GDT_End:
GDT_Address:
  dw GDT_End-GDT_Tables-1
  dd GDT_Tables
;----------------------------------------------------------------------
IDT_Address:
IDT_Address_Limit dw IDT_End-IDT_Tables-1
IDT_Address_Base  dd IDT_Tables

IDT_Tables:

IDT_Discriptor_00:
Target_Code_Segment_Offset1_00  dw 0x0000 ;Low bit
Target_Code_Segment_Selector_00 dw GDT_CodeSegment_Selector
Attribute_00  dw 0x8e00
Target_Code_Segment_Offset2_00 dw 0x0010 ;High bit

IDT_Discriptor_01:
Target_Code_Segment_Offset1_01  dw 0x0100
Target_Code_Segment_Selector_01 dw GDT_CodeSegment_Selector
Attribute_01  dw 0x8e00
Target_Code_Segment_Offset2_01 dw 0x0010

IDT_Discriptor_02:
Target_Code_Segment_Offset1_02  dw 0x0200
Target_Code_Segment_Selector_02 dw GDT_CodeSegment_Selector
Attribute_02  dw 0x8e00
Target_Code_Segment_Offset2_02 dw 0x0010

IDT_Discriptor_03:
Target_Code_Segment_Offset1_03  dw 0x0300
Target_Code_Segment_Selector_03 dw GDT_CodeSegment_Selector
Attribute_03  dw 0x8e00
Target_Code_Segment_Offset2_03 dw 0x0010

IDT_Discriptor_04:
Target_Code_Segment_Offset1_04  dw 0x0400
Target_Code_Segment_Selector_04 dw GDT_CodeSegment_Selector
Attribute_04  dw 0x8e00
Target_Code_Segment_Offset2_04 dw 0x0010

IDT_Discriptor_05:
Target_Code_Segment_Offset1_05  dw 0x0500
Target_Code_Segment_Selector_05 dw GDT_CodeSegment_Selector
Attribute_05  dw 0x8e00
Target_Code_Segment_Offset2_05 dw 0x0010

IDT_Discriptor_06:
Target_Code_Segment_Offset1_06  dw 0x0600
Target_Code_Segment_Selector_06 dw GDT_CodeSegment_Selector
Attribute_06  dw 0x8e00
Target_Code_Segment_Offset2_06 dw 0x0010

IDT_Discriptor_07:
Target_Code_Segment_Offset1_07  dw 0x0700
Target_Code_Segment_Selector_07 dw GDT_CodeSegment_Selector
Attribute_07  dw 0x8e00
Target_Code_Segment_Offset2_07 dw 0x0010

IDT_Discriptor_08:
Target_Code_Segment_Offset1_08  dw 0x0800
Target_Code_Segment_Selector_08 dw GDT_CodeSegment_Selector
Attribute_08  dw 0x8e00
Target_Code_Segment_Offset2_08 dw 0x0010

IDT_Discriptor_09:
Target_Code_Segment_Offset1_09  dw 0x0900
Target_Code_Segment_Selector_09 dw GDT_CodeSegment_Selector
Attribute_09  dw 0x8e00
Target_Code_Segment_Offset2_09 dw 0x0010

IDT_Discriptor_10:
Target_Code_Segment_Offset1_10  dw 0x0a00
Target_Code_Segment_Selector_10 dw GDT_CodeSegment_Selector
Attribute_10  dw 0x8e00
Target_Code_Segment_Offset2_10 dw 0x0010

IDT_Discriptor_11:
Target_Code_Segment_Offset1_11  dw 0x0b00
Target_Code_Segment_Selector_11 dw GDT_CodeSegment_Selector
Attribute_11  dw 0x8e00
Target_Code_Segment_Offset2_11 dw 0x0010

IDT_Discriptor_12:
Target_Code_Segment_Offset1_12  dw 0x0c00
Target_Code_Segment_Selector_12 dw GDT_CodeSegment_Selector
Attribute_12  dw 0x8e00
Target_Code_Segment_Offset2_12 dw 0x0010

IDT_Discriptor_13:
Target_Code_Segment_Offset1_13  dw 0x0d00
Target_Code_Segment_Selector_13 dw GDT_CodeSegment_Selector
Attribute_13  dw 0x8e00
Target_Code_Segment_Offset2_13 dw 0x0010

IDT_Discriptor_14:
Target_Code_Segment_Offset1_14  dw 0x0e00
Target_Code_Segment_Selector_14 dw GDT_CodeSegment_Selector
Attribute_14  dw 0x8e00
Target_Code_Segment_Offset2_14 dw 0x0010

IDT_Discriptor_15:
Target_Code_Segment_Offset1_15  dw 0x0f00
Target_Code_Segment_Selector_15 dw GDT_CodeSegment_Selector
Attribute_15  dw 0x8e00
Target_Code_Segment_Offset2_15 dw 0x0010

IDT_Discriptor_16:
Target_Code_Segment_Offset1_16  dw 0x1000
Target_Code_Segment_Selector_16 dw GDT_CodeSegment_Selector
Attribute_16  dw 0x8e00
Target_Code_Segment_Offset2_16 dw 0x0010

IDT_Discriptor_17:
Target_Code_Segment_Offset1_17  dw 0x1100
Target_Code_Segment_Selector_17 dw GDT_CodeSegment_Selector
Attribute_17  dw 0x8e00
Target_Code_Segment_Offset2_17 dw 0x0010

IDT_Discriptor_18:
Target_Code_Segment_Offset1_18  dw 0x1200
Target_Code_Segment_Selector_18 dw GDT_CodeSegment_Selector
Attribute_18  dw 0x8e00
Target_Code_Segment_Offset2_18 dw 0x0010

IDT_Discriptor_19:
Target_Code_Segment_Offset1_19  dw 0x1300
Target_Code_Segment_Selector_19 dw GDT_CodeSegment_Selector
Attribute_19  dw 0x8e00
Target_Code_Segment_Offset2_19 dw 0x0010

IDT_Discriptor_20:
Target_Code_Segment_Offset1_20  dw 0x1400
Target_Code_Segment_Selector_20 dw GDT_CodeSegment_Selector
Attribute_20  dw 0x8e00
Target_Code_Segment_Offset2_20 dw 0x0010

IDT_Discriptor_21:
Target_Code_Segment_Offset1_21  dw 0x1500
Target_Code_Segment_Selector_21 dw GDT_CodeSegment_Selector
Attribute_21  dw 0x8e00
Target_Code_Segment_Offset2_21 dw 0x0010

IDT_Discriptor_22:
Target_Code_Segment_Offset1_22  dw 0x1600
Target_Code_Segment_Selector_22 dw GDT_CodeSegment_Selector
Attribute_22  dw 0x8e00
Target_Code_Segment_Offset2_22 dw 0x0010

IDT_Discriptor_23:
Target_Code_Segment_Offset1_23  dw 0x1700
Target_Code_Segment_Selector_23 dw GDT_CodeSegment_Selector
Attribute_23  dw 0x8e00
Target_Code_Segment_Offset2_23 dw 0x0010

IDT_Discriptor_24:
Target_Code_Segment_Offset1_24  dw 0x1800
Target_Code_Segment_Selector_24 dw GDT_CodeSegment_Selector
Attribute_24  dw 0x8e00
Target_Code_Segment_Offset2_24 dw 0x0010

IDT_Discriptor_25:
Target_Code_Segment_Offset1_25  dw 0x1900
Target_Code_Segment_Selector_25 dw GDT_CodeSegment_Selector
Attribute_25  dw 0x8e00
Target_Code_Segment_Offset2_25 dw 0x0010

IDT_Discriptor_26:
Target_Code_Segment_Offset1_26  dw 0x1a00
Target_Code_Segment_Selector_26 dw GDT_CodeSegment_Selector
Attribute_26  dw 0x8e00
Target_Code_Segment_Offset2_26 dw 0x0010

IDT_Discriptor_27:
Target_Code_Segment_Offset1_27  dw 0x1b00
Target_Code_Segment_Selector_27 dw GDT_CodeSegment_Selector
Attribute_27  dw 0x8e00
Target_Code_Segment_Offset2_27 dw 0x0010

IDT_Discriptor_28:
Target_Code_Segment_Offset1_28  dw 0x1c00
Target_Code_Segment_Selector_28 dw GDT_CodeSegment_Selector
Attribute_28  dw 0x8e00
Target_Code_Segment_Offset2_28 dw 0x0010

IDT_Discriptor_29:
Target_Code_Segment_Offset1_29  dw 0x1d00
Target_Code_Segment_Selector_29 dw GDT_CodeSegment_Selector
Attribute_29  dw 0x8e00
Target_Code_Segment_Offset2_29 dw 0x0010

IDT_Discriptor_30:
Target_Code_Segment_Offset1_30  dw 0x1e00
Target_Code_Segment_Selector_30 dw GDT_CodeSegment_Selector
Attribute_30  dw 0x8e00
Target_Code_Segment_Offset2_30 dw 0x0010

IDT_Discriptor_31:
Target_Code_Segment_Offset1_31  dw 0x1f00
Target_Code_Segment_Selector_31 dw GDT_CodeSegment_Selector
Attribute_31  dw 0x8e00
Target_Code_Segment_Offset2_31 dw 0x0010

IDT_Discriptor_32:
Target_Code_Segment_Offset1_32  dw 0x2000
Target_Code_Segment_Selector_32 dw GDT_CodeSegment_Selector
Attribute_32  dw 0x8e00
Target_Code_Segment_Offset2_32 dw 0x0010

IDT_End:
; --------------------------------------------------------------------------------------

Initializate_Processor:

Mask_All_IRQ:
mov al,255
out 0xa1,al
out 0x21,al

Enable_A20:

Enable_A20_First:
  in al,0x64
  test al,2
  jnz Enable_A20_First
  mov al,0xd1
  out 0x64,al
Enable_A20_Second:
  in al,0x64
  test al,2
  jnz Enable_A20_Second
  mov al,0xdf
  out 0x60,al

Disable_Interrupt:
cli

Load_GDT:   
        lgdt
;lidt

Enable_ProtectedMode:
                                       
mov eax,0x11                                                                     
        mov cr0,eax   

        jmp GDT_CodeSegment_Address:Code_32 

Bits 32
Code_32:

mov ax,GDT_DataSegment_Address
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
mov esp,0xffff 

Load_Processor_Interrupt_Procedure:
mov dx,0x1f6
mov al,0xa0
out dx,al

mov dx,0x1f2
mov al,Processor_Interrupt_Procedure_Sector_Total  ;Read sector count=10
out dx,al

mov dx,0x1f3
mov al,Processor_Interrupt_Procedure_Sector_Situation
out dx,al

mov dx,0x1f4
mov al,0
out dx,al

mov dx,0x1f5
mov al,0
out dx,al

mov dx,0x1f7
mov al,0x20
out dx,al

Load_Processor_Interrupt_Procedure_Test_DRQ:
  in  al,dx
  test al,8
  jz  Load_Processor_Interrupt_Procedure_Test_DRQ
Load_Processor_Interrupt_Procedure_Read_Sector:
  mov dx,0x1f0
  mov edi,Processor_Interrupt_Procedure_Memory_Location
  mov ecx,Processor_Interrupt_Procedure_Sector_Word_Total
  rep insw


PAE:
  mov edi,0x600000
mov eax,0x610000
add eax,0x01
stosd

mov edi,0x610000
mov eax,0x620000
add eax,0x01
stosd

mov edi,0x620000
mov eax,0x630000
add eax,0x01
stosd

mov edi,0x630000
mov eax,0x000001
mov ecx,0x200
STOSE_PTE:
stosd
add eax,0x1000
add edi,4
loop STOSE_PTE

mov eax,cr4
bts eax,5
mov cr4,eax

      mov  eax,0x600000        ; page directory location
      mov  cr3,eax
      mov  eax,cr0

mov ecx,0xc0000080
rdmsr
bts eax,8
wrmsr

mov al,0x34
mov [0xb8000],al

mov eax,cr0
bts eax,31
mov cr0,eax

mov al,0x37
mov [0xb8000],al

db 0x66
db 0xea
dd Start64
dw 0x18
bits 64
Start64:


jmp $
Posted on 2005-07-19 02:05:07 by Wei.Jian
Hi Wei Jian

Do u know how many days I spent debugging such a program ? I do not remember... too much probably.

What helped me is : TINY steps. Make as many steps as u can. The smallest as u can.

I would suggest, as part of my experience:

- enter PM 32-bit from DOS, come back to DOS. DOS... is it a joke ? No. Write your program below 0a0000, handle its useful tool "debug"

- write basic routines for displaying hexa/decimal values to 0b8000h.

- target a simple 32-bit IDT that works. It is great for avoiding 90 % or more of those insane "triple fault" that reboot your test machine. When your program comes back to DOS with an error code and its location, you are in the right way.

=> write a 32-bit IDT, test it with the kbd and/or timer and/or monitor. Alexei Frounze's tutorial helped me to do so. It won't be long and difficult to convert your 32-bit IDT to 64-bit IDT.

- check your PDE/PTE... compare with others' code, is it different and in what way ? What is really in memory ?

- the real nightmare is the jump from one mode to another: mimic other's code, and try and fully understand how the processor should behave... "fully" is quite a challenge. Many tries and errors help checking your assumptions.

- backup, backup, backup. Get the docs, understand them. Do inline debugging. With that kind of development: nothing's slower than rushing

Hope it helps...

Regards
valy
Posted on 2005-07-19 04:05:57 by valy