orange's一个操作系统的实现--学习过程 第三章:a代码动态执行
--随着程序执行,查看gdt、GdtPtr内容变化
--原始的gdt内容
--3个gdt(每个8个字节)
00 00 00 00 00 00 00 00
14 00 00 00 00 98 40 00
FF FF 00 80 0B 92 00 00
<bochs:8> x /24bx 0x7c04
[bochs]:
0x0000000000007c04 <bogus+ 0>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x0000000000007c0c <bogus+ 8>: 0x14 0x00 0x00 0x00 0x00 0x98 0x40 0x00
0x0000000000007c14 <bogus+ 16>: 0xff 0xff 0x00 0x80 0x0b 0x92 0x00 0x00
--原始的GdtPtr内容
--文件内容
17 00 00 00 00 00
<bochs:15> x /6bx 0x7c1c
[bochs]:
0x0000000000007c1c <bogus+ 0>: 0x17 0x00 0x00 0x00 0x00 0x00
--源码
GdtLen equ $ - LABEL_GDT ; GDT长度
GdtPtr dw GdtLen - 1 ; GDT界限 ==23
dd 0 ; GDT基地址
--查看反编译代码
<bochs:17> u /20 0x7c2f
00007c2f: ( ): xor eax, eax ; 6631c0
00007c32: ( ): mov ax, cs ; 8cc8
00007c34: ( ): shl eax, 0x04 ; 66c1e004
00007c38: ( ): add eax, 0x00007c80 ; 6605807c0000
00007c3e: ( ): mov word ptr ds:0x7c0e, ax ; a30e7c
00007c41: ( ): shr eax, 0x10 ; 66c1e810
00007c45: ( ): mov byte ptr ds:0x7c10, al ; a2107c
00007c48: ( ): mov byte ptr ds:0x7c13, ah ; 8826137c
00007c4c: ( ): xor eax, eax ; 6631c0
00007c4f: ( ): mov ax, ds ; 8cd8
00007c51: ( ): shl eax, 0x04 ; 66c1e004
00007c55: ( ): add eax, 0x00007c04 ; 6605047c0000
00007c5b: ( ): mov dword ptr ds:0x7c1e, eax ; 66a31e7c
00007c5f: ( ): lgdt ds:0x7c1c ; 0f01161c7c
00007c64: ( ): cli ; fa
--设置断点b 0x7c4c 查看LABEL_DESC_CODE32的gdt发生变化
<bochs:18> b 0x7c4c
<bochs:19> c
(0) Breakpoint 2, 0x0000000000007c4c in ?? ()
Next at t=65538752
(0) [0x000000007c4c] 0000:7c4c (unk. ctxt): xor eax, eax ; 6631c0
<bochs:20> x /24bx 0x7c04
[bochs]:
0x0000000000007c04 <bogus+ 0>: 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00
0x0000000000007c0c <bogus+ 8>: 0x14 0x00 0x80 0x7c 0x00
0x98 0x40 0x00
0x0000000000007c14 <bogus+ 16>: 0xff 0xff 0x00 0x80 0x0b
0x92 0x00 0x00
--设置断点b 0x7c5f 查看GdtPtr发生变化
<bochs:21> b 0x7c5f
<bochs:22> c
(0) Breakpoint 3, 0x0000000000007c5f in ?? ()
Next at t=65538757
(0) [0x000000007c5f] 0000:7c5f (unk. ctxt): lgdt ds:0x7c1c ; 0f01161c
7c
<bochs:23> x /6bx 0x7c1c
[bochs]:
0x0000000000007c1c <bogus+ 0>: 0x17 0x00 0x04 0x7c 0x00 0x00