您的位置:首页 > 其它

自己编写操作系统的笔记5

2009-03-27 14:21 239 查看
对于保护模式和boot sector理解还是不够深。今天仅仅打算在昨天的基础上打出hello protect mode,发现不能输出……一个字都没输出,仅仅看出jmp $的样子。还是寻址没有弄明白啊。

先上代码,继续研究:

Title	protect.asm

include	protect.inc

.386p
;-------------------------------------------------------
code	segment	use16
assume cs:code
org		07c00h
Start:
xor		eax,eax							;设置GDT基址
mov		ax,code
mov		ds,ax
shl		eax,4
add		eax,offset GDT
mov		dword	ptr	GDTPTR.base,eax
xor		eax,eax							;设置代码段基址
mov		ax,code
shl		eax,4
mov		codes.Basel,ax
shr		eax,16
mov		codes.Basem,AL
mov		codes.Baseh,AH
xor		eax,eax							;设置数据段基址
mov		ax,code
shl		eax,4
add		eax,offset msg
mov		datas.Basel,ax
shr		eax,16
mov		datas.Basem,al
mov		datas.Baseh,ah
lgdt		Fword PTR GDTPTR
cli
OpenA20
SetCR0ToProtect
Jump16 	<code_sel>,<OFFSET begin>	;不了解
begin:
SetCR0ToReal
JUMP16	<seg real>,<offset real>
real:
CloseA20
sti
mov		ax,code
mov		ds,ax
mov		cs,ax
mov		es,ax
call		dispstr
jmp		$							;循环
dispstr:
mov		ax,msg					;以下几行参见原书注释
mov		bp,ax
mov		cx,19
mov		ax,01301h
mov		bx,000ch
mov		dl,0
int		10h
ret
GDT		Label	Byte
space	Descriptor<>
codes	Descriptor<0FFFFh,,,DA_C,0>
code_sel=codes-GDT
datas	Descriptor<0FFFFh,,,DA_DRW,0>
data_sel=datas-GDT
GDTLEN=$-GDT
GDTPTR		fdesc<GDTLEN-1,>
msg:
db	"Hello,Protect Mode!"			;所要打印字符串
MSGLEN=$-msg
db	510-($-offset Start)	dup(0)
dw	0AA55h
code	ends
end	start


运行到jmp $处我想调试一下,所以就暂停(我用的是vmware),然后用ultra Edit打开内存文件,发现hello这句话在7cc4处。然后看到mov ax,msg的跳转指向的正是这里,可是没有输出,实在是太奇怪了。大概还是不了解这些跳转的详细内容吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: