笔记

来源:互联网 发布:imap4 端口 编辑:程序博客网 时间:2024/05/26 15:59

------------------------------

8086模式下寻址:

CS段寄存器*16+IP

DS段寄存器*16+OFFSET

-------------------------------

------------------------------

8086模式下IO寻址:

IN:input form port

OUT:output to port


mov data between EAX or AX or AL and port(DX或一个8bit数字)

-----------------------



设置断点 b *0x7c00


CLI  清除中断标志,如果当前的特权级别为IOPL;EFLAGS寄存器 IF (external maskable ininterrupt)外部可屏蔽请求中断

CLD 清除方向标志,字符串操作指令会 ++ SI 或 DI。 EFLAGS寄存器  DF=0

xor %ax,%ax  ax=0

mov %ax,%ds  ds=0

mov %ax,%es es=0

mov %ax,%ss ss=0

in $0x64,%al    读64端口(KB 控制器)

test $0x02,%al  执行and操作  bit 1= input buffer full

jne 0x7c0a

mov %dl,%al  dl=0x80

out %al,$0x64

in %0x64,%al

test $0x02,%al

jne 0x7c14

mov %df,%al

out %al,%0x60    df:11011111

lgdtw 0x7c64   :0x7c64: 0x17 0x000x4c 0x7c0x00 0x000x66 0x90

//Limit 0x17

//base:0x7c4c

-------------------

GDTR  全局描述符表寄存器


-------------------



mov %cr0,%eax eax=0x10  ET=1 coprocessor 存在 80237

or $0x1,%eax  PE=1  protection enable,保护模式

mov %eax,%cr0  //设置PE=1,进入保护模式

ljmp $0x8,$0x7c32  //设置cs=0x8  ip=0x7c32, 将cpu预存指令全部清除

//cs段指定的段描述符为GDT[1] 其中base=0x00000000

mov $0x10,%al

mov %al,%ds  //设置ds=0x10, ds段指定的段描述符为GDT[2],其中base=0x00000000

mov %al,%es 

mov %al,%fs 

mov %al,%gs 

mov %al,%ss 


mov  $0x7c00,%esp //建立栈


call 0x7d0d  //call bootmain


bootmain:装载第一个扇区到内存

//最后一条命令

call ELFHDR->e_entry


//inc/memlayout.h 内存布局