免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1561 | 回复: 0
打印 上一主题 下一主题

直接通过 TSS选择子进行任务切换出错,,求助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-22 01:08 |只看该作者 |倒序浏览
本帖最后由 386asm 于 2013-07-22 01:08 编辑

用 nasm编译通过,虚拟机运行出错,我看我的代码和别人的视乎没差别,我查了许久了,都不知哪里错

代码大意是 直接通过 TSS选择子进行任务切换,,,jmp tss_sel:0

代码如下:

%macro descriptor 3
dw %2 & 0ffffh
dw %1 & 0ffffh
db (%1>>16) & 0ffh
dw ((%2>> & 0f00h) | (%3 & 0f0ffh)
db (%1>>24) & 0ffh
%endmacro


org 0100h
jmp start
;**********************************************
[section .gdt]
gdtstart: descriptor 0,0,0
code32: descriptor 0,0ffffh,4098h
code32_sel equ code32 - gdtstart

ldtseg: descriptor 0,0ffffh,82h
ldt_sel equ ldtseg-gdtstart

stack:descriptor 0,stack_top,4093h;存在可读可写,向低扩展数据段,32位,dpl=0,rpl=0
stack_sel equ stack -gdtstart


tssseg:descriptor 0,0ffffh,89h;可用的386tss,dpl=3,rpl=0
tss_sel equ tssseg -gdtstart

tss1seg:descriptor 0,0ffffh,89h;可用的386tss,dpl=3,rpl=0
tss1_sel equ tss1seg -gdtstart

gdtlen equ $-gdtstart
gdtptr dw gdtlen-1
       dd 0
;*****************************************************
[section .ldt]
ldtstart:
code1: descriptor 0,0ffffh,4098h;存在的只执行的非一致代码段dpl=0,rpl=0
code1_sel equ code1 - ldtstart + 4


video: descriptor 0b8000h,0ffffh,92h;存在的可读可写数据段dpl=0,rpl=0
video_sel equ video-ldtstart+4

ldtlen equ $-ldtstart
;********************************************************
[section .stack];;;;;;;;;;;;堆栈区
align 32
[bits 32]
stackstart: times 100 db 0
stack_top equ $-stackstart-1

;;;;;;;;;;;;/////////////////////
; TSS ---------------------------------------------------------------------------------------------
[SECTION .tss]
ALIGN        32
[BITS        32]
tssstart:
                Dw        0,0                           ; Back
                DD        0                        ; 0 级堆栈
                Dw        0,0                ;
                DD        0                        ; 1 级堆栈
                Dw        0,0                        ;
                DD        0                        ; 2 级堆栈
                Dw        0,0                        ;
                DD        0                        ; CR3
                DD        0                        ; EIP
                DD        0                        ; EFLAGS
                DD        0                        ; EAX
                DD        0                        ; ECX
                DD        0                        ; EDX
                DD        0                        ; EBX
                DD        0                        ; ESP
                DD        0                        ; EBP
                DD        0                        ; ESI
                DD        0                        ; EDI
                Dw        0,0                        ; ES
                Dw        0,0                        ; CS
                Dw        0,0                        ; SS
                Dw        0,0                        ; DS
                Dw        0,0                        ; FS
                Dw        0,0                        ; GS
                Dw        0,0                        ; LDT
                Dw        0                        ; 调试陷阱标志
                DW        $ -tssstart + 2                        ; I/O位图基址
                DB        0ffh                        ; I/O位图结束标志
tsslen                equ        $ -tssstart


[SECTION .tss1]
ALIGN        32
[BITS        32]
tss1start:
                Dw        0,0                           ; Back
                DD        stack_top                        ; 0 级堆栈
                Dw        stack_sel,0                ;
                DD        0                        ; 1 级堆栈
                Dw        0,0                        ;
                DD        0                        ; 2 级堆栈
                Dw        0,0                        ;
                DD        0                        ; CR3
                DD        code1start                        ; EIP
                DD        0                        ; EFLAGS
                DD        0                        ; EAX
                DD        0                        ; ECX
                DD        0                        ; EDX
                DD        0                        ; EBX
                DD        stack_top                        ; ESP
                DD        0                        ; EBP
                DD        0                        ; ESI
                DD        (80*12+1)*2                        ; EDI
                Dw        video_sel,0                        ; ES
                Dw        code1_sel,0                        ; CS
                Dw        stack_sel,0                        ; SS
                Dw        video_sel,0                        ; DS
                Dw        video_sel,0                        ; FS
                Dw        video_sel,0                        ; GS
                Dw        ldt_sel,0                        ; LDT
                Dw        0                        ; 调试陷阱标志
                DW        $ -tss1start + 2                        ; I/O位图基址
                DB        0ffh                        ; I/O位图结束标志
tss1len                equ        $ -tss1start


; TSS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


;*********************************************************
[section .code1]
[bits 32]
code1start:

        mov ah,0ch
        mov al,'1'
        mov [gs:edi],ax
        jmp $

       
;*****************************************************
       
;*******************************************
[section .s32]
[bits 32]
protect:mov ax,ds
        shl eax,4
        add eax,stackstart
        mov word [stack+2],ax
        shr eax,16
        mov byte [stack+4],al
        mov byte [stack+7],ah ;初始化全局栈段

        mov ax,stack_sel
        mov ss,ax       
        mov esp,stack_top

        xor eax,eax
        mov ax,ds
        shl eax,4
        add eax,ldtstart
        mov word [ldtseg+2],ax
        shr eax,16
        mov byte [ldtseg+4],al
        mov byte [ldtseg+7],ah ;初始化ldt描述符
       
        xor eax,eax
        mov ax,ds
        shl eax,4
        add eax,code1start
        mov word [code1+2],ax
        shr eax,16
        mov byte [code1+4],al
        mov byte [code1+7],ah;初始化ldt中的code1

        xor eax,eax
        mov ax,ds
        shl eax,4
        add eax,tssstart
        mov word [tssseg+2],ax
        shr eax,16
        mov byte [tssseg+4],al
        mov byte [tssseg+7],ah ;初始化tss描述符

        xor eax,eax
        mov ax,ds
        shl eax,4
        add eax,tss1start
        mov word [tss1seg+2],ax
        shr eax,16
        mov byte [tss1seg+4],al
        mov byte [tss1seg+7],ah ;初始化tss1描述符
       
       
        mov ax,ldt_sel
        lldt ax

        xor eax,eax
        mov ax,tss_sel
        ltr ax

        jmp tss1_sel:0 ;;;;;;;;-***************************出错

;***********************************************
[section .s16];进入保护模式
[bits 16]
start:       
        mov ax,cs
        mov ds,ax
        mov es,ax
        mov ss,ax
        mov sp,0100h

        shl eax,4
        add eax,protect
        mov word [code32+2],ax
        shr eax,16
        mov [code32+4],al
        mov [code32+7],ah
       
        xor eax,eax
        mov ax,ds
        shl eax,4
        add eax,gdtstart
        mov word [gdtptr+2],ax
        shr eax,16
        mov word [gdtptr+4],ax
       
        lgdt [gdtptr]
        cli
        in al,92h
        or al,000000010b
        out 92h,al
       
        mov eax,cr0
        or eax,1
        mov cr0,eax
        jmp dword code32_sel:0


求求了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP