failed to jmp from real mode to protect mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
speller
Posts: 1
Joined: Sat Oct 22, 2011 5:35 am

failed to jmp from real mode to protect mode

Post by speller »

I use nasm to make binaray file, then dd it to a floopy image, but when I run this code in bochs, it failed and I don not kown why.
Poor English ;p If you can understand me, give me a hand please.

org 0x7c00
jmp BEGIN

NULL_DESC:
dd 0
dd 0

CODE_DESC:
dw 0xffff
dw 0
db 0
db 0x98
db 0x40
db 0

VIDEO_DESC:
dw 0xffff
dw 0x8000
db 0x0b
db 0x92
db 0
db 0

; 这个结构会加载到寄存器 gdtr
GDT_LEN equ $-NULL_DESC
GDT_PTR dw GDT_LEN-1
dd 0

; Selector of GDT
Selector_CODE equ CODE_DESC-NULL_DESC
Selector_VIDEO equ VIDEO_DESC-NULL_DESC

[BITS 16]
BEGIN:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x100

; 设定CODE_DESC的段基址
xor eax, eax
mov ax, cs
shl eax, 4
add eax, CODE_SEG
mov word [CODE_DESC+2], ax
shr eax, 16
mov byte [CODE_DESC+4], al
mov byte [CODE_DESC+7], ah

; 设定GDT_PTR中的GDT基址
xor eax, eax
mov ax, ds
shl eax, 4
add eax, NULL_DESC
mov dword [GDT_PTR+2], eax

; 加载GDTR
lgdt [GDT_PTR]

; 进入保护模式
cli

in al, 0x92
or al, 0x02
out 92h, al

mov eax, cr0
or eax, 1
mov cr0, eax

jmp dword Selector_CODE:0

[BITS 32]
CODE_SEG:

mov ax, Selector_VIDEO
mov gs, ax
mov edi, 1
mov al, 'a'
mov ah, 0x0f
mov [gs:edi], ax
jmp $

CODE_SEG_LEN equ $-CODE_SEG
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: failed to jmp from real mode to protect mode

Post by Chandra »

Use code tags.

Lots of issues. You've better start with basics.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: failed to jmp from real mode to protect mode

Post by Combuster »

And try not to randomly copy DOS applications without knowing how they work
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply