2009年3月31日 星期二

●First Instruction Executed




剖析First Instruction Executed
一、Processor 寄存器初始狀態,如上圖。
1、CR0.PE = 0,處理器處於真實模式
2、RIP = FFF0h
3、CS.Base = FFFF_0000h
4、由於在真實模式下,第一條指令的物理位址就在:CS.Base + RIP = FFFF_FFF0h。

二、MCH(NorthBridge)的處理
FFFF_FFF0h位址由Processor送到MCH進行解析,這個位址落在MCH固定為High BIOS 分配的區域中,MCH直接通過DMI介面送到ICH進行處理。MCH相當於一個派發者角色,根據定義的位址映射分派到不同的介面。

三、ICH(SouthBridge)的處理
1、ICH對MCH提交過來的位址進行解碼。
2、ICH的位址映射機制中:FFFF_FFF0地址落 FFF8_0000 ~ FFFF_FFFFh這個範圍中,這個範圍的位址將直接分派到LPC介面的Frimware Hub進行處理,LPC 介面相當於一個PCI-to-ISA 橋,BIOS寄居在LPC bus上,從而訪問BIOS區域。
3、在物理器件上,ICH Firmware Hub的IDSEL選擇固定位址設為FFF8_0000 ~ FFFF_FFFF範圍,LPC介面寄存器(B#0, D#30,F#0)中的,Firmware Hub Decode Enable寄存器的bit15固定為1,允許FFF8_0000 ~ FFFF_FFFF位址提交到Firmware Hub。這樣確保FFFF_FFF0提交到LPC bus。
ICH相當於一個解碼器角色,解碼後分配任務給設備執行。

四、第一條指令執行
經典地在FFFF_FFF0絕大多數是一條far jmp指令:jmp far ptr 0F000h:0E05Bh,不同的BIOS跳轉的位址或許不同。這條指令跳轉到FE05B這個位址上執行。同時刷新CS.Selector、CS.Base以及EIP寄存器。引一段 Intel 的話:

The first instruction that is fetched and executed following a hardware reset is
located at physical address FFFFFFF0H. This address is 16 bytes below the
processor’s uppermost physical address. The EPROM containing the software initialization
code must be located at this address.
The address FFFFFFF0H is beyond the 1-MByte addressable range of the processor
while in real-address mode. The processor is initialized to this starting address as
follows. The CS register has two parts: the visible segment selector part and the
hidden base address part. In real-address mode, the base address is normally
formed by shifting the 16-bit segment selector value 4 bits to the left to produce a
20-bit base address. However, during a hardware reset, the segment selector in the
CS register is loaded with F000H and the base address is loaded with FFFF0000H. The
starting address is thus formed by adding the base address to the value in the EIP
register (that is, FFFF0000 + FFF0H = FFFFFFF0H).

以上這段文字表明,Intel從架構上規定了,processor復位後,FFFFFFF0H地址上必須包含一些初始化程式,BIOS必須在定位在這段位址區域上。
MCH與ICH的配合從物理上通過位址映射機制保證了這一點的實施。

五、驗證一下FFFF_FFF0位址上是否是一條far jmp指令,可以簡單地打開cmd視窗執行debug命令。
C:>debug
-d F000:FFF0
F000:FFF0 EA 5B E0 00 F0 30 32 2F 32 37 2F 30 38 00 FC
EA 5B E0 00 F0 就是 jmp far ptr F000:E05B 指令,這條指令跳轉到FE05B的物理位址上,這將是 BIOS 的 BOOTBLOCK。

六、BIOS位址空間高端與低端的別名機制

1、在整個位址空間中 FFE0_0000 ~ FFFF_FFFF 這段2M 區域真正地被固定分配給 BIOS 使用,包括基本的 BIOS 區以及一些設備擴展的 BIOS 區。這段空間是不能提交至 DRAM 的。

2、實際上,BIOS的低端地址C_0000 ~ F_FFFF 屬於PAM區 (即:Programmed Attibute Memory) ,這段區域可被賦為4個訪問屬性:disable,read-only,write-only 以及 read/write。根據訪問屬性的不同可被提交到ICH,也可以提交DRAM,但初始化的屬性是Disable,為DRAM不可用,初始狀態是通過DMI提交到ICH處理的,但是可以在 BIOS 代碼修改的,從而提交至DRAM。

3、C_0000 ~ F_FFFF 與 FFFC_0000 ~ FFFF_FFFF 指向同一個區域,被冠以別名稱呼,即C_0000 ~ F_FFFF 被映射到 FFFC_0000 ~ FFFF_FFFF。

AMD 如是說:參閱圖4
Accesses to BIOS space in the low megabyte (between 000C_0000h and 000F_FFFFh) are mapped to the top megabyte (between FFFC_0000h and FFFF_FFFFh) on the LPC bus; the OAR locks for these apply to these accesses based on the remapped address at the top megabyte.

●無論是C_0000 ~ F_FFFF,還是 FFFC_0000 ~ FFFF_FFFF 最終結果都將送到LPC bus上的FFFC_0000 ~ FFFF_FFFF 地址上。參閱圖5

沒有留言:

張貼留言