切换至保护模式时QEMU异常重启的技术求助
实模式切换保护模式异常问题
我在实模式下完成操作后尝试切换到保护模式,但出现异常情况。实模式中我制作了简单欢迎界面,要求用户输入姓名,之后本该切换至保护模式,但实际表现为:按下Enter键后,某个字符背景开始变化,随后我使用的QEMU模拟器重启并重新显示欢迎界面。
以下是相关代码:
section startUp vstart=0x7f00 ; clearing the screen mov ah,0x00 mov al,0x03 int 0x10 ; disabling the cursor mov ah,0x01 mov ch,0x3f int 0x10 ; using Bios to print character mov ah,0x0e mov al,'C' mov cx,0x01 int 0x10 ; printing a string mov ax,msg mov bx,0x00 mov cl,0x0f mov dx,0x00 call printMsg ; print warning mov ax,warning mov bx,0x00 mov cl,0x04 mov dx,0x3a call printMsg ; print message mov ax,msg2 mov bx,0x00 mov cl,0x0f mov dx,0x0140 call printMsg ; input mov si,keypress mov bx,0x00 call input ; switching to protected mode cli ; disabling interrupts lgdt [GDT_Descriptor] mov eax,cr0 or eax,0x01 mov cr0,eax ; here we are in 32 bit protected mode jmp protectedMode ; printing a string function printMsg: pusha ; ax ==> offset , bx ==> segment , dl ==> Line a0*lineNumber - 1, cl ==> color mov es,bx mov bx,0xB000 mov ds,bx mov si,ax mov di,0x8000 add di,dx mov byte[es:0x7e00],0x00 jmp loopThrough loopThrough: mov al,byte[es:si] mov byte[ds:di], al add di,0x01 mov byte[ds:di],cl sub di,0x01 add si,0x01 mov bl,byte[es:si] cmp bl,0x00 je quit add di,0x02 jmp loopThrough quit : popa ret ; input function kjjj input: pusha ; si ==> offset , bx ==> segment mov di,si mov es,bx jmp loopinterupt loopinterupt : mov ah,0x00 int 0x16 cmp al,0x20 je quitInput mov byte[es:si],al add si,0x01 mov byte[es:si],0x00 mov ax,di mov dx,0x172 mov cl,0x0f call printMsg jmp loopinterupt quitInput : popa ret ; Data ; Setting Up the GDT GDT : times 8 db 0x00 ; base : 0x100000 ; Limit : 0x00700 dw 0x0700 ; limit 1 dw 0x0000 ; base 1 db 0x10 ; base 2 db 0x9a ; access Byte db 0xc0 ; limit + flags db 0x00d ; base 3 ; base : 0x800000 ; limit : 0x00700 dw 0x0700 ; limit 1 dw 0x0000 ; base 1 db 0x80 ; base 2 db 0x96 ; access Byte db 0xc0 ; limit + flags db 0x00 ; base 3 GDT_Descriptor : dw GDT_Descriptor - GDT - 1 dd GDT msg db 'Welcome to the OS fdffdfgd',0x00 msg2 db 'Please write your name : ',0x00 keypress db 'K',0x00 warning db "" [bits 32] protectedMode: jmp $ times 1024-($-$$) db 0
代码在执行到jmp protectedMode语句前均正常运行。
内容的提问来源于stack exchange,提问作者Djebbar Abderrahmene
相关产品推荐
相关产品推荐

