osloader!DoGlobalInitialization函数分析之HW_CURSOR--NTLDR源代码分析之设置光标

第一部分:

VOID

DoGlobalInitialization(

IN PBOOT_CONTEXT BootContextRecord

)

{

//

// Turn the cursor off

//

HW_CURSOR(0,127);

D:\srv03rtm\base\boot/inc/bldrx86.h:258:#define HW_CURSOR (*ExternalServicesTable->HardwareCursor)

第二部分:

一、中断显示服务---INT 10H

功能号:

00H ---设置显示器模式

01H ---设置光标形状

02H ---设置光标位置

03H ---读取光标信息

04H ---读取光笔位置

05H ---设置显示页

06H、07H ---初始化或滚屏

08H ---读光标处的字符及其属性

09H ---在光标处按指定属性显示字符

0AH ---在当前光标处显示字符

0BH ---设置调色板、背景色或边框

0CH ---写图形象素

0DH ---读图形象素

0EH ---在Teletype模式下显示字符

0FH ---读取显示器模式

10H ---颜色

11H ---字体

12H ---显示器的配置

13H ---在终端模式下显示字符串

1AH ---读取/设置显示组合编码

1BH ---读取功能/状态信息

1CH ---保存/恢复显示器状态

int 10h中断例程的在光标位置显示字符功能:

mov ah,9 ;在光标位置显示字符

mov al,'a' ;字符

mov bl,7 ;颜色属性

mov bh,0 ;第0页

mov cx,3 ;字符重复个数

int 10h

(ah)=9表示调用的第10h号的中断例程的9号子程序,功能为在光标位置显示字符,可以提供要显示的字符,颜色属性,页号字符重复个数作为参数

一般调用中断例程的某号子程序,存储在ah中

第三部分:

3、 功能02H

功能描述:用文本坐标下设置光标位置

入口参数:AH=02H

BH=显示页码

DH=行(Y坐标)

DL= 列(X坐标)

出口参数:无

第四部分:

//

// Turn the cursor off

//

HW_CURSOR(0,127);

;++

;

; Name:

;

; HardwareCursor

;

; Description:

;

; Positions the hardware cursor and performs other display stuff.

;

; Arguments:

;

; ULONG Y coord (0 based)

; ULONG X coord (0 based)

; TOS -> ULONG Flat return address (must be used with KeCodeSelector)

;

; If X = 0x80000000, then Y contains values that get placed into

; ax (low word of Y) and bx (hi word of y).

; Otherwise X,Y = coors for cursor

;

;

;--

EXPORT_ENTRY_MACRO HardwareCursor

;

; Move the arguments from the caller's 32bit stack to the SU module's

; 16bit stack.

;

MAKE_STACK_FRAME_MACRO <HardwareCursorFrame>, ebx

;

; Go into real mode. We still have the same stack and sp

; but we'll be executing in realmode.

;

ENTER_REALMODE_MACRO

;

; Get the requested sectors. Arguments on realmode stack

; Make (bp) point to the bottom of the argument frame.

;

push bp

mov bp,sp

add bp,2

;

; Put the row (y coord) in dh and the column (x coord) in dl.

;

mov eax,[bp].YCoord

mov edx,[bp].XCoord

cmp edx,80000000h

jne gotxy

mov ebx,eax

shr ebx,16

jmp doint10

gotxy:

mov dh,al DH=行(Y坐标)

mov ah,2 02H ---设置光标位置

mov bh,0

doint10:

int 10h

;

; Restore bp and remove stack-frame from stack

;

pop bp

REMOVE_STACK_FRAME_MACRO <HardwareCursorFrame>

;

; Re-enable protect-mode and paging.

;

RE_ENABLE_PAGING_MACRO

;

; Return to caller and the 32bit universe.

;

EXPORT_EXIT_MACRO

kd> p

osloader!DoGlobalInitialization+0x3b:

004012a8 6a7f push 7Fh

kd> p

osloader!DoGlobalInitialization+0x3d:

004012aa 6a00 push 0

第五部分:

//

// Turn the cursor off

//

HW_CURSOR(0,127);

kd> dv

BootContextRecord = 0x00024538

kd> dx -r1 ((osloader!_BOOT_CONTEXT *)0x24538)

((osloader!_BOOT_CONTEXT *)0x24538) : 0x24538 [Type: _BOOT_CONTEXT *]

+0x000\] FSContextPointer : 0x244e4 \[Type: _FSCONTEXT_RECORD \*

+0x004\] ExternalServicesTable : 0x244ec \[Type: _EXTERNAL_SERVICES_TABLE \*

+0x008\] MemoryDescriptorList : 0x70000 \[Type: _SU_MEMORY_DESCRIPTOR \*

+0x00c\] MachineType : 0x0 \[Type: unsigned long

+0x010\] OsLoaderStart : 0x401000 \[Type: unsigned long

+0x014\] OsLoaderEnd : 0x4894a8 \[Type: unsigned long

+0x018\] ResourceDirectory : 0x487000 \[Type: unsigned long

+0x01c\] ResourceOffset : 0x87000 \[Type: unsigned long

+0x020\] OsLoaderBase : 0x400000 \[Type: unsigned long

+0x024\] OsLoaderExports : 0x443b40 \[Type: unsigned long

+0x028\] BootFlags : 0x0 \[Type: unsigned long

+0x02c\] NtDetectStart : 0x0 \[Type: unsigned long

+0x030\] NtDetectEnd : 0x0 \[Type: unsigned long

+0x034\] SdiAddress : 0x0 \[Type: unsigned long

kd> dx -r1 ((osloader!_FSCONTEXT_RECORD *)0x244e4)

((osloader!_FSCONTEXT_RECORD *)0x244e4) : 0x244e4 [Type: _FSCONTEXT_RECORD *]

+0x000\] BootDrive : 0x80 \[Type: unsigned char

kd> dx -r1 ((osloader!_EXTERNAL_SERVICES_TABLE *)0x244ec)

((osloader!_EXTERNAL_SERVICES_TABLE *)0x244ec) : 0x244ec [Type: _EXTERNAL_SERVICES_TABLE *]

+0x000\] RebootProcessor : 0x22e60 \[Type: void (__cdecl\*)()

+0x004\] DiskIOSystem : 0x22e6c \[Type: long (__cdecl\*)(unsigned char,unsigned char,unsigned short,unsigned short,unsigned char,unsigned char,unsigned char \*)

+0x008\] GetKey : 0x22e84 \[Type: unsigned long (__cdecl\*)()

+0x00c\] GetCounter : 0x22e90 \[Type: unsigned long (__cdecl\*)()

+0x010\] Reboot : 0x22e9c \[Type: void (__cdecl\*)(unsigned long)

+0x014\] DetectHardware : 0x22ec0 \[Type: void (__cdecl\*)(unsigned long,unsigned long,void \*,unsigned long \*,char \*,unsigned long)

+0x018\] HardwareCursor : 0x22ea8 \[Type: void (__cdecl\*)(unsigned long,unsigned long)

+0x01c\] GetDateTime : 0x22eb4 \[Type: void (__cdecl\*)(unsigned long \*,unsigned long \*)

+0x020\] ComPort : 0x22ecc \[Type: void (__cdecl\*)(long,unsigned long,unsigned char)

+0x024\] GetStallCount : 0x22ed8 \[Type: unsigned long (__cdecl\*)()

+0x028\] InitializeDisplayForNt : 0x22ee4 \[Type: void (__cdecl\*)()

+0x02c\] GetMemoryDescriptor : 0x22ef0 \[Type: void (__cdecl\*)()

+0x030\] GetEddsSector : 0x22e78 \[Type: long (__cdecl\*)(unsigned char,unsigned long,unsigned long,unsigned short,unsigned char \*,unsigned char)

+0x034\] GetElToritoStatus : 0x22efc \[Type: long (__cdecl\*)(unsigned char \*,unsigned char)

+0x038\] GetExtendedInt13Params : 0x22f08 \[Type: unsigned char (__cdecl\*)(unsigned char \*,unsigned char)

+0x03c\] NetPcRomServices : 0x0 \[Type: unsigned short (__cdecl\*)(unsigned long,void \*)

+0x040\] ApmAttemptReconnect : 0x22f14 \[Type: void (__cdecl\*)()

+0x044\] BiosRedirectService : 0x0 \[Type: unsigned long (__cdecl\*)(unsigned long)

kd> p

kd> p

osloader!DoGlobalInitialization+0x45:

004012b2 ff5018 call dword ptr [eax+18h] //[eax+18h]

kd> r

eax=000244ec ebx=004013a2 ecx=00000000 edx=00064544 esi=00024538 edi=0048164f

eip=004012b2 esp=00060ec4 ebp=00060ed0 iopl=0 nv up di pl zr na pe nc

cs=0008 ss=0010 ds=0010 es=0010 fs=0030 gs=0000 efl=00000046

osloader!DoGlobalInitialization+0x45:

004012b2 ff5018 call dword ptr [eax+18h] ds:0010:00024504=00022ea8

kd> dd 00060ec4

00060ec4 00000000 0000007f 00024538 00061ff0

kd> ?7f

Evaluate expression: 127 = 0000007f

y=7f x=0