- 论坛徽章:
- 59
|
老大,帮我偷偷看一下,真不知什么地方出错。无法Switch
1。能进入PM,
2。能产生中断输出
3。问题出在jmpi tts上...跳不过去啊。头大大大,去掉jmpi 0,0x18,是可以正常运行的)
4。内存:
________________________________
|Base |Locat |
----------------------------------------------------
|0 |sec2的代码,做为一个“小内核" |
_________________________________
|1k |GDT |
----------------------------------------------------
|2k |IDT,size=2k |
----------------------------------------------------
|4k |TSS_0 |
-----------------------------------------------------
|4k+128|LDT_0 |
----------------------------------------------------
|4k+512|Code |
~~~~~~~~~~~~~~~~~~~~~~~~~~
经验证,以上内存的映象是正确的,可以用sec2中的print_char代码段(少改一下就行),输出其内容来证明。
问题了在jmpi 0,0x18(TSS_0的selector,见boot.asm),也就是切换进程上的操作上。
我瞪大眼睛,看intel的manaul,看linus的开机大作,就是找不到什么地方有err.:*( 
1.boot.asm/as86-
- entry start
- .org 0x00
- Seg_Video_Buf =0xb800
- Seg_Boot_Locat =0x07c0
- Seg_GDT_Base =1024
- Seg_Stack =Seg_Boot_Locat+0x400
- start:
- ;Load sec2 to memory 0x00
- ;Read the sector 2 to the 0x0100:0000
- mov ax,#(0x01<<12-512)>>4
- mov es,ax
- mov dx,#0x0000 ;hy=0,disc=0
- mov cx,#0x0002 ;from 2sec
- mov bx,#0x0000 ;base=0
- mov ax,#0x0203 ;Read 3secs(2,3,4)
- int 0x13
- ;mov sector 2 to 0x0000:0000
- mov ax,#(0x01<<12-512)>>4
- mov ds,ax
- mov ax,#0x0000
- mov es,ax
- mov si,#0x0000
- mov di,#0x0000
- cld
- mov cx,#512
- rep
- movsb
- ;move segement descript table to the momery base 1k
- mov ax,#Seg_Boot_Locat
- mov ds,ax
- mov ax,#Seg_GDT_Base>>4
- mov es,ax
- mov si,#GDT
- xor di,di
- cld
- mov cx,#(ENDS_GDT-GDT)
- rep
- movsb
- ;move to Prct_Mode:
- ;load gdt
- mov ax,#Seg_Boot_Locat
- mov ds,ax
- cli
- lgdt gdt_attr
- ;enable A20
- mov ax,#0x0ff0
- mov sp,#0xff00
- call empty_8042
- mov al,#0xd1
- out #0x64,al
- call empty_8042
- mov al,#0xdf
- out #0x60,al
- call empty_8042
- ; start protect mode:
- mov ax,#0x0001
- lmsw ax
- jmpi 0,8
- empty_8042:
- .word 0x00eb,0x00eb
- in al,#0x64
- test al,#2
- jnz empty_8042
- ret
- .align 16
- gdt_attr:
- .word 0x800
- .word Seg_GDT_Base,0x00
- .org 256
- .org 320
- GDT:
-
- .word 0,0,0,0 ;select=%000000
- .word 0x01<<13-1;limit ,2^10*2^2*2^13=2^25=32M;select=%0,1000,0x08
- .word 0x0000 ;base
- .word 0x9a00 ;Code :exec/read
- .word 0x00c0 ;G=4096,386
- .word 0x01<<13-1;selector=%1,0000,0x10
- .word 0x0000
- .word 0x9200 ;data :read/write ,present dpl=0
- .word 0x00c0
-
- .word 128-1 ;TSS1 ,selector 3(%01,1000,0x18)
- .word 0x01<<12 ;base=4k
- .word 0x8900 ;Tss ,not busy,present dpl=00
- .word 0x0000 ;G=1byte,avilable=0
-
- .word 128-1 ;LDT1 ,selector 4(selector=4 %10,0000,0x20)
- .word 0x01<<12+128 ;base=4k+128
- .word 0x9200 ;data :read/write
- .word 0x0040 ;G=1byte
- .word 128-1 ;TSS2 ??use for the system,selector 5,selector=0x28
- .word 0x01<<12+1024 ;base=5k
- .word 0x8900
- .word 0x0000
- .word 0,0,0,0 ;LDT2
- ENDS_GDT:
- .org 510
- .word 0xaa55
复制代码 ____________________________________________________________________________
2.sec2.asm/as86- .text
- entry start
- IDT_Base=1024*2
- start:
- ;.org 0x00
- mov ax,#0x10
- mov ds,ax
- mov ss,ax
- mov ax,#0xff00
- mov [0x000000],ax
- cmp [0x100000],ax
- L6: je L6
- mov edi,#0x0b8000
- mov esi,#msg
- ;mov esi,#(0x01<<12+512)
- mov ah,0x0c
- mov ecx,#(msg_end-msg)
- print_str:
- mov al,[esi]
- mov [edi] ,ax
- inc esi
- inc edi
- inc edi
- loop print_str
- lea edx,[intr_default]
- mov eax,#0x00080000
- mov ax,dx
- mov dx,#0x8e00
- mov edi,#IDT_Base
- ;point to the end of this program.'s next word
- mov ecx,#256
- rp_sidt:
- mov [edi],eax
- mov 4[edi],edx
- add edi,#8
- loop rp_sidt
- mov edi,#(IDT_Base+8*8)
- lea edx,[intr_svr]
- mov eax,#0x00080000
- mov ax,dx
- mov dx,#0x8e00
- mov [edi],eax
- mov 4[edi],edx
- ;mov edi,#(IDT_Base+8*1)
- ;mov [edi],eax
- ;mov 4[edi],edx
- lidt [idt_attr]
- Set_up_Stack:
- mov esp,#0x1000
- mov ax,#0x10
- mov ss,ax
- mov bh,#0x0d
- mov bl,#0x40
- mov edi,#(0x0b8960+160)
- mov dh,#0x00
- sti
- ;Kill floppy monitor:
- mov dx,#0x3f2
- mov al,#0
- outb
- ;mov cl,#0
- ;div cl
- mov ax,#%0101000
- ltr ax
- L_end: jmp L_end
- .align 16
- intr_svr:
- cli
- inc dh
- cmp dh,#0x48
- jne rt_bl
- mov dh,#0x00
- inc bl
- mov [edi],bx
- add edi,#2
- cmp edi,#(0xb8960+160+26)
- jne L1
- mov edi,#(0xb8960+160)
- L1: cmp bl,#0x7f
- jnz rt_bl
- mov bl,#0x40
- rt_bl:
- jmpi 0,0x18
- mov al,#0x20
- out #0x20,al
- sti
- iretd
- .align 16
- intr_default:
- cli
- mov ax,#0x0b48
- mov [0x0b8000+160],ax
- mov al,#0x20
- out #0x20,al
- sti
- iretd
- .align 16
- idt_attr:
- .word 256*8-1
- .long IDT_Base
- .org 480
- msg:
- .ascii "Procted Mode"
- msg_end:
复制代码 ____________________________________________________________________________
3.sec3_4.asm/as86- entry start
- start:
- .org 0x00 ;the TSS_1 locat at 4K
- .long 0x00000000 ;00-No previous Tss
- .long 0x00000000 ;04-No ESP0
- .long 0x00000000 ;08-No SS0
- .long 0x00000000 ;0c-No ESP1
- .long 0x00000000 ;10-No SS1
- .long 0x00000000 ;14-No ESP2
- .long 0x00000000 ;18-No SS2
- .long 0x00000000 ;1c-No CR3
- .long 0x00000000 ;20-EIP=0
- .long 0x00000202 ;24-Eflag IF=1
- .long 0x00000000 ;28-eax=0
- .long 0x00000000 ;2c-ecx=0
- .long 0x00000000 ;30-edx=0
- .long 0x00000000 ;34-ebx=0
- .long 0x00000000 ;38-ESP Not use
- .long 0x00000000 ;3c-EBP=0
- .long 0x00000000 ;40-esi=0
- .long 0x00000000 ;44-edi=0
- .long 0x00000000 ;48-es,not use
- .long 0x00000004 ;4c-cs,item 0 selected,LDT used:(%0100B)
- .long 0x00000000 ;50-ss,not defined(%010100)
- .long 0x00000000 ;54-ds,not defined
- .long 0x00000000 ;58-fs,not defined
- .long 0x00000000 ;5c-gs,not defined
- .long 0x00000020 ;60-ldt selecct from GDT item 4:(10,0100B)
- .long 0x00800000 ;64-no IO Map,No debug
- .org 128 ;start the ldt_1,Locat at 4K+128
- ;Code segment
- .word 512-1 ;Limit selector=%0100
- .word 0x01<<12+512 ;Base=4K+512
- .word 0x9a00 ;Code read/executable
- .word 0x0040 ;G=0 ,1byte
- ;Stack segment
- .word 1024 ;limit selector=%1100
- .word 0x01<<12+512 ;Base=4K+512
- .word 0x9200 ;Data ,read/write
- .word 0x0040 ;G=0 ,1byte
-
- .org 512 ;start the code ,Loacat at 4K+512
- Code_Start:
- ;mov ax,#0x10 ;GDT,item 2
- ;mov ds,ax
- ;mov ax,#0x7a48
- ;mov [0x0b8000+512],ax
- L_app: jmp L_app
复制代码 _________________________________________________________________ |
|