I am trying to switch to protected mode after playing around a little bit with real mode, but something weird occurs. In real mode I have created a simple welcome screen asking the user to enter their name. After that, the switch to protected mode should occur, but this is what happens instead:
As you can see I press Enter and the background of a character starts changing, and then QEMU (the emulator I am using) restarts and re-displays the welcome screen.
Here is the code :
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
So as you saw the code executes just fine until the jmp protectedMode
is executed.