80
基本輸入/輸出系統(BIOS)研究 指導老師: 陳德生 學生 : 楊逸翔 曾成濱 班級 : 資訊四甲

基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

基本輸入輸出系統(BIOS)研究

指導老師 陳德生

學生 楊逸翔 曾成濱

班級 資訊四甲

目錄

目錄 I

摘要 III

致謝 IV

第一部份 x86 基本硬體架構 1

Chapter 1 基本輸入輸出系統(BIOS) -Introduction 1

11 什麼是 BIOS 2

12 BIOS in ROM 3

13 執行 BIOS 的目的與基本流程 3

Chapter 2 重要之硬體介紹 5

21 主要的集成電路(IC) 6

211 中央處理器(CPU) 6

212 晶片組(Chip-set) 8

213 整合中低速率介面(Super IO) 9

214 鍵盤控制器(Keyboard Controller) 9

215 CMOS(RTCCMOS 計時參數晶片) 11

216 其它一般 IC 11

22 匯流排系統(BUS System) 12

221 週邊元件介面匯流排 PCI (Peripheral Component Interface Bus)12

222 系統管理匯流排 SMBus (System Management Bus) 13

223 低針腳數 LPC (Low pin count) 14

224 GP IO(General Purpose IO) 14

23 電源管理(Power management) 14

231 系統管理模式 SMM (System Management Mode) 14

232 進階電源管理 APM (Advanced Power Management) 15

I

233 進階設定與電源介面 ACPI (Advanced Configuration and Power

Interface) 15

Chapter 3 BIOS 實際在硬體上位置 16

amp運作機制 16

31 當開機時(Power-ON) 16

32 晶片組(Chipset) 定址空間分配 16

33 映射記憶體 Shadow Ram 17

34 Flat mode amp Big real mode 18

第二部份 Trace BIOS 流程helliphellip 20

Chapter 4 Trace BIOS 所需資源helliphellip 21

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可與 無壓縮程序) helliphellip 23

51 簡述此階段的工作helliphellip 23

52 選寫此皆段程序需注意之特點helliphellip 24

53 BIOS 流程helliphellip 24

Chapter 6 第二階段(記憶體可用 POSTamp解壓縮) helliphellip 33

Chapter 7 第三階段

(CMOS 設定之後 POST 續) helliphellip 50

第三部份(附錄) 59

附錄 1 診斷碼 59

附錄 2 縮寫名詞對照表 66

附錄 3 參考資料 72

心得 74

II

摘要

這個專題是藉由研究 BIOS 了解電腦的硬體架構進而對未來踏入嵌入式系

統的研究能有更進一步的幫助主要內容包括

BIOS 簡介

電腦硬體簡介

TRACE BIOS 的 BOOTING 流程

BIOS 燒入實作

III

致謝

首先感謝 陳德生指導教授長期以來給予我們的協助與讓我們有機會作這個

專題雖然面對這個專題有時會感覺像茫然大海可是陳德生老師會給我們一

些提示方向不論專題成果是否與目標一致我們都很慶幸參與這個專題最

後再謝謝老師 老師辛苦了

接著我們還要感謝在作專題的過程中曾經提供我們方向與意見的 王益文老

師 以及 林志敏老師還有待在實驗室期間 曾提供我們協助的吳季穎吳維揚

學長

IV

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 2: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

目錄

目錄 I

摘要 III

致謝 IV

第一部份 x86 基本硬體架構 1

Chapter 1 基本輸入輸出系統(BIOS) -Introduction 1

11 什麼是 BIOS 2

12 BIOS in ROM 3

13 執行 BIOS 的目的與基本流程 3

Chapter 2 重要之硬體介紹 5

21 主要的集成電路(IC) 6

211 中央處理器(CPU) 6

212 晶片組(Chip-set) 8

213 整合中低速率介面(Super IO) 9

214 鍵盤控制器(Keyboard Controller) 9

215 CMOS(RTCCMOS 計時參數晶片) 11

216 其它一般 IC 11

22 匯流排系統(BUS System) 12

221 週邊元件介面匯流排 PCI (Peripheral Component Interface Bus)12

222 系統管理匯流排 SMBus (System Management Bus) 13

223 低針腳數 LPC (Low pin count) 14

224 GP IO(General Purpose IO) 14

23 電源管理(Power management) 14

231 系統管理模式 SMM (System Management Mode) 14

232 進階電源管理 APM (Advanced Power Management) 15

I

233 進階設定與電源介面 ACPI (Advanced Configuration and Power

Interface) 15

Chapter 3 BIOS 實際在硬體上位置 16

amp運作機制 16

31 當開機時(Power-ON) 16

32 晶片組(Chipset) 定址空間分配 16

33 映射記憶體 Shadow Ram 17

34 Flat mode amp Big real mode 18

第二部份 Trace BIOS 流程helliphellip 20

Chapter 4 Trace BIOS 所需資源helliphellip 21

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可與 無壓縮程序) helliphellip 23

51 簡述此階段的工作helliphellip 23

52 選寫此皆段程序需注意之特點helliphellip 24

53 BIOS 流程helliphellip 24

Chapter 6 第二階段(記憶體可用 POSTamp解壓縮) helliphellip 33

Chapter 7 第三階段

(CMOS 設定之後 POST 續) helliphellip 50

第三部份(附錄) 59

附錄 1 診斷碼 59

附錄 2 縮寫名詞對照表 66

附錄 3 參考資料 72

心得 74

II

摘要

這個專題是藉由研究 BIOS 了解電腦的硬體架構進而對未來踏入嵌入式系

統的研究能有更進一步的幫助主要內容包括

BIOS 簡介

電腦硬體簡介

TRACE BIOS 的 BOOTING 流程

BIOS 燒入實作

III

致謝

首先感謝 陳德生指導教授長期以來給予我們的協助與讓我們有機會作這個

專題雖然面對這個專題有時會感覺像茫然大海可是陳德生老師會給我們一

些提示方向不論專題成果是否與目標一致我們都很慶幸參與這個專題最

後再謝謝老師 老師辛苦了

接著我們還要感謝在作專題的過程中曾經提供我們方向與意見的 王益文老

師 以及 林志敏老師還有待在實驗室期間 曾提供我們協助的吳季穎吳維揚

學長

IV

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 3: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

233 進階設定與電源介面 ACPI (Advanced Configuration and Power

Interface) 15

Chapter 3 BIOS 實際在硬體上位置 16

amp運作機制 16

31 當開機時(Power-ON) 16

32 晶片組(Chipset) 定址空間分配 16

33 映射記憶體 Shadow Ram 17

34 Flat mode amp Big real mode 18

第二部份 Trace BIOS 流程helliphellip 20

Chapter 4 Trace BIOS 所需資源helliphellip 21

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可與 無壓縮程序) helliphellip 23

51 簡述此階段的工作helliphellip 23

52 選寫此皆段程序需注意之特點helliphellip 24

53 BIOS 流程helliphellip 24

Chapter 6 第二階段(記憶體可用 POSTamp解壓縮) helliphellip 33

Chapter 7 第三階段

(CMOS 設定之後 POST 續) helliphellip 50

第三部份(附錄) 59

附錄 1 診斷碼 59

附錄 2 縮寫名詞對照表 66

附錄 3 參考資料 72

心得 74

II

摘要

這個專題是藉由研究 BIOS 了解電腦的硬體架構進而對未來踏入嵌入式系

統的研究能有更進一步的幫助主要內容包括

BIOS 簡介

電腦硬體簡介

TRACE BIOS 的 BOOTING 流程

BIOS 燒入實作

III

致謝

首先感謝 陳德生指導教授長期以來給予我們的協助與讓我們有機會作這個

專題雖然面對這個專題有時會感覺像茫然大海可是陳德生老師會給我們一

些提示方向不論專題成果是否與目標一致我們都很慶幸參與這個專題最

後再謝謝老師 老師辛苦了

接著我們還要感謝在作專題的過程中曾經提供我們方向與意見的 王益文老

師 以及 林志敏老師還有待在實驗室期間 曾提供我們協助的吳季穎吳維揚

學長

IV

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 4: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

摘要

這個專題是藉由研究 BIOS 了解電腦的硬體架構進而對未來踏入嵌入式系

統的研究能有更進一步的幫助主要內容包括

BIOS 簡介

電腦硬體簡介

TRACE BIOS 的 BOOTING 流程

BIOS 燒入實作

III

致謝

首先感謝 陳德生指導教授長期以來給予我們的協助與讓我們有機會作這個

專題雖然面對這個專題有時會感覺像茫然大海可是陳德生老師會給我們一

些提示方向不論專題成果是否與目標一致我們都很慶幸參與這個專題最

後再謝謝老師 老師辛苦了

接著我們還要感謝在作專題的過程中曾經提供我們方向與意見的 王益文老

師 以及 林志敏老師還有待在實驗室期間 曾提供我們協助的吳季穎吳維揚

學長

IV

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 5: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

致謝

首先感謝 陳德生指導教授長期以來給予我們的協助與讓我們有機會作這個

專題雖然面對這個專題有時會感覺像茫然大海可是陳德生老師會給我們一

些提示方向不論專題成果是否與目標一致我們都很慶幸參與這個專題最

後再謝謝老師 老師辛苦了

接著我們還要感謝在作專題的過程中曾經提供我們方向與意見的 王益文老

師 以及 林志敏老師還有待在實驗室期間 曾提供我們協助的吳季穎吳維揚

學長

IV

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 6: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

第一部份 x86 基本硬體架構

Chapter 1 基本輸入輸出系統(BIOS) ndashIntroduction

概述 BIOS 的目的和存放的實體位置

Chapter 2 重要之硬體介紹

X86 系統的硬體與特殊執行機制

Chapter 3 BIOS 實際在硬體上位置amp運作機制

Chapter 1 基本輸入輸出系統(BIOS)

-Introduction

1

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 7: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

11 什麼是 BIOS

民航機在起飛前機長必需先按 Check-list 啟動amp檢查 電門機身控制面

板等而 x86 電腦就如同民航機CPU 在開機時會像機長一樣按 BIOS(Che

ck-list) 指示依序初amp檢查電腦待電腦可正常運作後(起飛)再把電腦交給 OS (自

動駕駛系統)

下面清楚定義了 BIOS

一個韌體程式( Firmware program)儲存在惟讀記憶體(ROM

Memory)提供最基本的硬體初始化(initialize)周邊控制的必要程

式碼(通常由組合語言寫成)

2

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 8: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

12 BIOS in ROM

BIOS 就存放在主機板上的一顆 Rom

裡而 x86 硬體特性就是設計成在開機的

一瞬間CPU 從主機板上的 BIOS 晶片內取

得程式碼也就是由 BIOS 內部的程式碼掌

控電腦的初始動作

而 BIOS Rom 平時是設定成唯讀狀態必需藉由特定工具才可以加以修改

抹除

注意 其它的週邊也有自已的 BIOS Rom 像是顯示卡(video-card)高階網路卡

(NIC)等因為較複雜的外接週邊硬體設計差異很大各自有其獨特初始動作

所以廠商會另外加上 BIOS Rom

13 執行 BIOS 的目的與基本流程

一般 BIOS 最重要的工作有下列幾點

開機自我檢測 POST(Power On Self Test)

一開機時系統將控制權交給 BIOS 時它會先檢查 CPU 暫存器

(Registers)旗標(Flags)是否運作正常接著檢查像是 8254 計時器

(timer)8259A 可程式中斷控制器(Programmable Interrupt Controller)8237

直接記憶體存取控制器(DMA controller)

初使化amp測試(InitialampTest)

初使化晶片組(Chipset)記憶體(RAM)Video-card 還有相關周邊的

暫存器並測試是否可正常工作

3

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 9: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

初使化(Initialize)

依照該晶片組的技術文件的規定對暫存器填值改位元或旗

標的動作使其可正常工作

記錄系統的設定值

把系統設定值像是日期時間硬體設定等存入 CMOS

將常駐程式(Runtime Program) 常駐於記憶體(Memory)

以提供作業系統(OS)或應用程式呼叫

-基本 BIOS 流程圖-

4

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 10: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 2 重要之硬體介紹

5

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 11: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

21 主要的集成電路(IC)

211 中央處理器(CPU)

中央處理器(CPU)有兩種主要模式 分別如下

真實模式(Real-Mode)

保護模式(Protect-Mode)

真實模式(Real mode)

在最初的 8086 處理器被釋出時它只有一種記憶體定址模式而它使用了

節區暫存器(segment register)和位移暫存器(offset register)作定址其定址方式如下

記憶體定址(Memory Addressing) segment offset

CS ltlt 4 + IP = 指令的線性位址(Linear Address Of

Instruction)

位址線(Address-Lines) 20 條(1024KB)

這種定址模式稱為真實模式定址(Real mode addressing)而它允許 8x86 定址至

1MB 的記憶體

接著說明真實模式的特性

1 捲繞(8086 記憶體特性)

當記憶體位址超過 0FFFFFh 時會捲繞回 00000h

6

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 12: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

2 A20 開關(switch)

X86 CPU 在 268 時位址線增加至 24 條(16MB 超過 1024KB)為了相容性

在位址線 A20~A23 設計了一個開關(A20 switch)它可切換兩種定址方式

強制歸零 (Real-Mode)模擬 8086 的記憶體捲繞特性

可進位 (Protect-Mode)可以在 0FFFFFh 進位

最後明確定義真實模式

當 IA-32 CPU 在使用真實模式定址狀態下執行時稱為真實模式(Real Mode)

保護模式(Protect mode) 它允許 8x86 定址至 4 GB(32 條位址線)的記憶體

但從保護模式切回真實模式時必需重置(Reset)那麼不就等於又重新開

機也就使得之前所執行的部份又得重新執行一遍這樣將會永無止境的執行下

7

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 13: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

去為了解決這個問題發展出了一個機制下面詳細說明其步驟

解決從保護模式切回真實模式必須 重置(Reset) 的問題

8042 鍵盤控制器(近似一顆簡單小型的 CPU也有自已的韌體負責

keyboardA20 開關 和 重置)

Step1 把關機(shutdown) 返回指示位元組 amp 返回位址寫入 CMOS

Step2 然後下令打開 A20 切到保護模式

------------- 切到保護模式 -----------------------

------------- 回到真實模式 -----------------------

Step3 重置鍵盤控制器(KBC)因為鍵盤控制器有自已的韌體不受系統重置

影嚮

Step4 CPU-gt 0FFFFF00000h 做簡單 CPU 測試

Step5 從 CMOS 讀入關機返回指示位元判斷此次為何種關機

硬體正常開機(power-onreset)

重保護模式返回(軟體重置(Soft reset)) -gt 讀取返回位址

注意至 386 以後以設計可直接從保護模式返回真實模式但還是保留 A20 開

關軟體重置(為了向下相容性)

212 晶片組(Chip-set)

早期主機板上焊滿大量電阻電容IC 和複雜電路 這樣才能達成一個功

能 不但成本高 也很難完成很多功能或除錯 所以借由半導體技術將這些

電子元件線路微縮至幾個大型晶片內以化簡主機板設計稱為系統晶片組

到現在主要分為兩大晶片

8

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 14: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

北橋晶片(North-Bridge) intel 稱之為記憶體控制集線器 MCH(Memory

Control Hub)集線器(Hub)也就是把其它裝置集中連線到北橋晶片

上而北橋是靠近 CPU 的一端所以它主要連接高速的裝置 像是

CPUMemory顯示卡並且它也包含了記憶體控制器(Memory

Controller)所以顧名思義命名為記憶體控制集線器(Memory Control

Hub)

南橋晶片(South-Bridge) 輸入輸出控制集線器 ICH(IO Control Hub)

不同於 MCH 主導高速裝置它相業負責較低速的 IO 週邊像是鍵

盤PrinterUSB等並集成了部份 IO 週邊的控制晶片(super IO

USB 控制器鍵盤控制器等)CMOS

213 整合中低速率介面(Super IO)

它提供了下列介面

Serial Port Com1 amp Com2

Parallel Port LPT

GameJoystick IO

FDC Controller(軟碟機)

InfraRed(IR)需佔用一個 com port

除了標準介面以外廠商也會增加額外功能例如 溫度偵測CPU 風扇轉

速控制(fan control)控制工作電壓(work voltage)等

214 鍵盤控制器(Keyboard Controller)

跟鍵盤做溝通的就是 KBC每當你按一個按鍵鍵盤就會送出一個掃描碼

(scancode)給鍵盤控制器經由鍵盤控制器翻譯後在發出中斷給 CPU由 CPU 接

9

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 15: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

收處裡而且鍵盤控制器的中斷優先權相當高僅次於 8253 計時中斷器

鍵盤控制器有 8 個暫存器是跟 CPU 溝通兩個 8-bit IO port 跟鍵盤溝通

輸入是 P1從鍵盤接收輸入

輸出是 P2發出輸出給鍵盤

P1

bit 7 Keyboard lock 0 locked 1 not locked

bit 6 Display 0 CGA 1 MDA

bit 5 Manufacturing jumper 0 installed 1 not installed

with jumper the BIOS runs an infinite diagnostic loop

bit 4 RAM on motherboard 0 512 KB 1 256 KB

bit 3 Unused in ISA EISA PS2 systems

Can be configured for clock switching

bit 2 Unused in ISA EISA PS2 systems

Can be configured for clock switching

Keyboard power PS2 MCA 0 keyboard power normal 1 no power

bit 1 Mouse data in Unused in ISA

bit 0 Keyboard data in Unused in ISA

P2

bit 7 Keyboard data data to keyboard

bit 6 Keyboard clock

bit 5 IRQ12 0 IRQ12 not active 1 active

10

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 16: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

bit 4 IRQ1 0 IRQ1 not active 1 active

bit 3 Mouse clock Unused in ISA

bit 2 Mouse data Unused in ISA Data to mouse

bit 1 A20 0 A20 line is forced 0 1 A20 enabled

bit 0 Reset 0 reset CPU 1 normal

215 CMOS(RTCCMOS 計時參數晶片)

RTC(Real Time Clock) 計時器 負責維持電腦時間

CMOS 為一存儲資料的空間用來記錄日期時間和 BiOS 設定

具備低秏電特性當電腦關閉時會改由電池供電以維持電腦設定值

216 其它一般 IC

IC 編號 功能

8042 KeyBoard Control

8237 DMA Controller

82538254 PIT(Programmable Interval Timer)

8255 PPI(Programmable Peripheral Interface)

8259 PIC(Programmable Interrupt Controller)

8284 Impulse Producer(序產生器)

11

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 17: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

22 匯流排系統(BUS System)

221 週邊元件介面匯流排 PCI (Peripheral Component Interface

Bus)

週邊元件匯流排 PCI 可以說是 x86 系統中最重要的一個匯流排系統因為

它連接大多數主機板上的裝置

在一個基本的 PCI 匯流排系統中(無其它 PCI 匯流排橋接控制晶片)最多可

以有 32 個 PCI 裝置(北橋晶片南橋晶片網路卡USB 控制晶片)互相連接

在一般主機板中晶片組本身最少就佔一組(PCI 控制器)有時侯會佔用到兩組

或更多

12

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 18: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

222 系統管理匯流排 SMBus (System Management Bus)

系統管理匯流排由兩條訊號線構成而經由它的可使小型系統和電源管理相

關晶片得以和其它的系統溝通它提供符合SMBus的裝制偵測定位讀寫參

數等設定之用例如 可用系統管理匯流排去偵測DRAM插了幾排並抓取該排

SPD參數或是讀取硬體監控晶片的參數值(CPU溫度風扇轉速電源)把不

用裝置關掉

Ps (此兩條系統管理匯流排訊號線為 SMBCLK 和 SMBDAT工作在100KHz)

13

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 19: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

223 低針腳數 LPC (Low pin count)

是用來取代傳統工業標準架構 ISA(Industry Standard Architecture) 匯流排的介

面規格因為以往 ISA 匯流排的位置資料 是分離解碼而 LPC 是採用類似週

邊元件匯流排 PCI 位置資料 共用解碼方式所以 以 LPC 介面設計的 Super IO

晶片等可以大幅降低訊號線數量(腳位)主機板也可以簡化設計

ISA LPC

Data width 16bit 4bit

Workfreq 833MHz 333MHz

Addressing space 24 條(16MB) 32 條(4GB)

Max Transfer width 16MBs 16MBs

224 GP IO(General Purpose IO)

Chipset 提供的通用 IO 控制訊號線也可稱為使用者可規畫

(User-Programmable) GP IO也就是可以依照需求將 GPIO 當成 IO Input 或是 IO

Output 或是 Input+Output(雙向)它的使用範圍很廣泛不過還是得參照使用 Chip

的規範來使用而它主要作為主機板上元件的特殊控制(運用 GP IO 設計相關硬

體線路然後配合 BIOS)例如鍵盤 power-on網路喚醒(wake on Lan)超頻

(overclocking)

23 電源管理(Power management)

231 系統管理模式 SMM (System Management Mode)

這個模式是由特殊目的中斷 一系統管理中斷 SMI(System Management

Interrupt)組成它被視為硬體介面和安全的記憶體位址空間作為存放處理器狀

態和 SMI 處理程序(SMI handler)SMI 處理者為一種特殊的軟體程序用以執行

14

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 20: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

不同的系統管理功能(例如電源控制)當 SMI 被觸發時CPU 會將它的狀態儲存

至記憶體然後開始執行 SMI 處理程序最後在最後一道指令執行從記憶體

讀回處理器狀態然後解除中斷並交回控制權至先前程序它執行的主要程序

為休眠模式而處理器為電腦系統裡功率相對較高的元件因此時眽控制在系統

管理模式下(使用休眠時)可以省下很多處理器的電源消秏

232 進階電源管理 APM (Advanced Power Management)

BIOS 提供作業系統一個呼叫表(call-table)用以控制硬體電源狀態但由於

APM 定義的功能較侷限(BIOS 本身的限制)並且只能做簡單的監控所以省電

效率並不高所以另外發展出 ACPI 進階設定與電源介面(在下面另作說明)

233 進階設定與電源介面 ACPI (Advanced Configuration and

Power Interface)

不同於進階電源管理 APM 由 BIOS 主導電源管理進階設定與電源介面 ACPI

是由 OS 主導著電源管理因為最後掌控電腦的是 OS可以做的變化相對多了

所以把電源管理由 BIOS 轉移至 OS才能真正發揮出電源管理的效率

15

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 21: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 3 BiOS 實際在硬體上位置

amp運作機制

31 當開機時(Power-ON)

intel 設計 80x86 CPU 開機後(Real Mode)的第一個動作就是指向記憶體的

最高位址

CS=DS=ES=SS=0FFFFh IP=0000h

=gt segment offset = FFFF0000h(000FFFF0h)

然後開始抓取(fetch) 指令(instruction)並 執行(execute)

所以 BIOS 儲存的 Rom chip必須在可以解碼的記憶體最高位置否則

在開機時CPU 將無法抓取 BIOS 的第一道指令當然也就繼續開機的動作

32 晶片組(Chipset) 定址空間分配

晶片組(Chipset) 定址空間分配

一般晶片組的定址能力為 32bit(4GB)而從最高位址往下依序分配

0FFFFFFFFh

- BIOS (包含主機板 外加擴充卡 等)

- 主機板資源

- 記憶體對應 IO

16

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 22: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

- AGPPCI-ExPCI 的設定

- 其它 PCI 裝置的記憶體(例如 內建 128MB 的 video-card至少就佔用了

128MB 的定址空間)

~

=Memory(剩於的定址空間)

000000000h

所以主機板內建元件和外接擴充卡不同最後剩下記憶體可用的定址範圍也不

同(通常還要視 OS 而定)

而在剛關機還處在真實模式(Real-Mode)的情況下(1MB limit)在不進入到保

護模式(Protect-Mode)下無法讀到位於 4GB 的 BIOS Rom

128K(1M bits)的部分可以透過 E0000~F0000 的映射記憶體(shadows ram)的切

換來讀取倒真的 ROM 的資料不過這個控制法用的晶片組不同切換的方法也不

如果 ROM 超過 128K 的部分那真的要切到 Big FLAT Mode(稍後說明)不一定

要用保護模式Big FLAT Mode 可直接去存取 4G 的頂端因為所有的晶片組一定

要把這部分的位址解到 ROM 上面

33 映射記憶體 Shadow Ram

因為動態記憶體(RAM)的執行速度比 Rom 快所以將部份 Rom 記憶體映射

到傳統 640KB~1MB 之間未使用的記憶體區域也就是把 C~F(C0000h~FFFFFh)四

個節區(segments)依需要設定成 Read-onlyRead-Write 的記憶體區域(Memory

Section)每一個對映的記憶頁大小最小為 16KB(4000h)這種特性稱為映射記憶

17

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 23: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

體(Shadow Ram)

映射記憶體步驟

Step1 複制 ROM 的內容至相同位址的延伸記憶體內

Step2 把原來的 ROS 設為無作用(diable)

Step3 對於映射後的位址設為寫入保護(write-protected)

34 Flat mode amp Big real mode

Flat mode(是最簡單的 32bits protect mode)

18

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 24: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

先切到 Virtual Protected Mode選一個 Data Selector(DSESFSGS) 把

segment 設成 以 0 為 base 以 4G 為 segment-limit 的 selector接下來再切回

Real-Mode此時使用這個 segment 可以用 32bit 的 index register 來定址使得程

式員可以忽略 CS DS ES FS GS 這些 segment純粹把

vitual address = physical address

Big real mode(是 real mode)

只是把 DS ES FS GS 這些 segment 設定成 以 0 為 base 以 4G 為 limit

的 selector程式員可以利用 32 bits memory access(prefix code 67h)去 access

19

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 25: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

第二部份 Trace BIOS 流程

BIOS 所面對的是 x86 系統上的各種複雜的匯流排系統與裝置而它們

各自都有不同的特性所以在開始 Trace BIOS 前需深入認識各種架構還有

在 Trace 時手上也要掌握相關資源(中斷表CMOS Ram 配置表晶片組暫

存器配置表等)

Chapter 4 Trace BIOS 所需背景知識資源(進階)

因為整個 BIOS 執行流程很繁雜所以必需將它分成幾個部分來看這樣

會比較容易了解而我們使用的區分方式主要以無壓縮程序有壓縮程序

CMOS 設定後的 POST 共分為三部份會如此區分的原因是主機板廠商為了節

省 BIOS Flash ROM 的成本會將原本的 BIOS 程式壓縮過(只留下少部份未壓

縮)但電腦在剛啟動時並無解壓縮能力所以初期所執行的皆為無壓縮程序

去做初使化的工作待載入解壓縮程序後才解壓縮 POST 程式並開始 POST

主體以此做為區分而後會有使用者是否中斷 POST而進入 CMOS 設定所

以將這之後再另外區分為一階段

Chapter 5 第一階段(開機啟動區塊與無壓縮程序)

Chapter 6 第二階段(解壓縮 POST 程序)

Chapter 7 第三階段(CMOS 設定之後的流程)

20 20

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 26: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 4 Trace BIOS 所需資源

要正確初始化設定任何裝置除了知道它的存取位址外還必需有一

份完整的晶片組 datasheet其內容最重要的就是各裝置的組態控制暫存器

的配置與詳細的設定值對應關係下面就此次目標板的南北橋組態暫

存器分部作初步的說明

一首先為北橋晶片依 PCI 規範分為三部份

1 主控端(Host)至 PCI 端之間的橋接與連接在此橋接上的週邊裝置

組態空間(HOST-TO-PCI BRIDGE CONFIGURATION SPACE)

橋接上各元件組態表配置如下

HOST 至 PCI 的橋接組態空間標頭

HOST L2 CACHEDRAM

現用訊號驅動電流(DRAMPCI)

電源管理

影射記憶體(SHADOW RAM) amp 不可快取區域

HOST 橋接 amp PCI 仲裁者(ARBITER)

時脈控制

顯示狀態(VGA)

GART 和分頁表快取(PAGE TABLE CACHE)

DRAM 優先權計時器

AGP和 HOST 橋接

2 裝置 2 虛擬 PCI 至 PCI 橋接

3 PCI IDE 裝置

21

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 27: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

4 進階組態電源介面(ACPI) 組態暫存器

5 系統管理匯流排(SMBUS) IO 暫存器

6 USB OPENHCI HOST 控制器組態空間

USB 組態空間 (函數 2)

HOST 控制器(選擇性暫存器)

7 自動電源控制(APC)暫存器

RTC 暫存器

8 資料獲得模組(DAM) 中斷暫存器

Ps更詳細資料請參考 sis5305595 datasheet

三IO Port 位址表

四CMOS 索引資料

五中斷向量表

22 22

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 28: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 5 第一階段

(開機啟動區塊 記憶體使用不可

與 無壓縮程序

初使化 BSP

(Bootstrap

開啟 KBCRTC

Memory

Size

測試 512KB

複製啟動區塊

(BootBlock)至

Main Memory

覆蓋(Flash)BIOS ROM 驗證錯誤(Checksum) ltCtrl-Homegt

跳至 F000FFF0

複製 Main BIOS 與

Runtime Module 至

Main Memory

Fig51 BIOS 最初流程

X86 在開機(重置訊號觸發 reset

signal)後不論是否為多處理器

(Multi-processors)系統皆會指定

BSP(Bootstrap Process)這是主要

掌控整個系統的處理器(Master)而

其它的處理器則稱為應用處理器

(Application Processor)由於我們

所用的系統板並未支援多處理器所

以在往後也將不討論多處理器的部

而 BSP 被初使之後便執行最高

位置的指令 FFFF0h 進而跳躍至啟動

程式區塊(細部待往後說明)開始執

行初使化工作

在這個皆段要注意此時記憶

體尚不能使用這是因為在硬體重

置後所有的裝置(含記憶體)皆尚未

被初使化所以無法使用接著便開

啟鍵盤控制器與 RTC測試記憶體大

小前端 512KB 是否可以使用覆蓋

(Flash)程序與最後覆製主 BIOS 與

常駐模組至主記憶體並跳至

F000FFF0 的記憶體位置這不就等

於又重來一次(在往後會關於這點說

明)

還有因為 x86 並無硬體解壓縮的

能力所以這部份的程序都是無壓縮

51 簡述此階段的工作

23

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 29: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

由於這個階段記憶體無法使用相對的也就無法使用堆疊 Stack

所以需留意下列幾點

不可使用 Call 的方式進入副程序 (取而代之)=gt 用 JMP

的方式進入

在副程序內要留意那些暫存器(Registers)存有之前

程序的運算資料在使用這些暫存器前要先備份並在離

開時回存(restore)

53 BiOS 流程

Fig52 Boot

由於記憶體的最前端 0000h-002Fh

存放中斷向量(Interrupt Vector)無足

夠的空間放置初使程式所以直接 JMP F000E05Bh這個位置機乎每家 BIOS 廠

設計都是一樣的而此時處理器運行在真

實模式(RealMode) Data[16bit] Address[20bit(1MB)] 那麼 BIOS 執行一開始就把中斷關掉為

什麼呢

因為一開始是在做很重要的硬體初

始化所以不希望被中斷而且在剛開機

時大部份 Device 尚未 initial所以

有可能收到的 INT 是無意義的訊號

52 選寫此皆段程序需注意之特點

24

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 30: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

一進入初始程

序就立刻把中

斷關掉

防止不可預期情

況發生

使用 Jmp 取代 Call 進入副程

序因 stack 尚無法使用所以

用 Call 呼叫時會無法儲存回來

的位址在 stack 頂端 BIOS 進入點

Fig53 Code

(Fig 54)詳細描述進入程序時暫存器的使用狀態與無法使用堆

疊最後列出在此程式區塊內存有資料或限用的暫存器另外如果

必需使用這些暫存器則在程式一開始就先作備份

Fig54 Code

25

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 31: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

這部份是對南橋晶片(North-Bridge)內部的

SuperIO 初始化那麼要如何去設定南橋晶片的

值以這裡的作法是把當次步驟所要設定的暫存

器寫成一連續參數資料再把此連續資料的起

始位址傳給專對讀寫此暫存器的 IO 副程序逐

一去設定很可惜的對於關鍵讀寫 IO 的實際

動作AMI 視為保密(隱藏程式碼)所以無法一

探究竟除了這次用到的 sio在往後像是 pci等 IO 程式碼也是被隱藏起來的

Fig56 上圖為設定參數的儲存

區 左圖為 BIOS 控制暫存器

Fig55 初始晶片組

26

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 32: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

可以看到(Fig57)一進入程式就立刻返回這個ldquoOEM 特殊設

定是 BIOS 廠商提供給主機板廠商(簡稱 OEM 廠)作為 OEM 廠可

以彈性的作一些額外設定所以裡面至返回之間的空白就由 OEM

廠自行加入特殊設定當然這些額外的工作必須在 BIOS 原廠設

定後才能去作這也就是 BIOS 廠把 OEM 設定放在返回之前最後

離開程序前檢查那些暫存器必需回存資料

為什麼先初使化 South-Bridge(super IO)

因為剛開機Boot的前端在Flash BIOS amp shutdown 階段需用到

Keyboard而一般Keyboard Controller是內建在South-Bridge的Super IO

裡所以才先初使化(如果在BIOS CheckSum發現BIOS是錯的此時如果沒

有Keyboard提供input控制會無法執行重刷BIOS Rom的動作)

接著把 IRQ 設為邊緣觸發

Fig57 OEM

27

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 33: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig58 檢查 KBCRTC

在檢查主機板晶片組是否內建 RTCKBC(有些主機板會使用一組額外

super IO 晶片)接著送出檢查碼這是 BIOS Debug 的方式因為若是在複

雜的硬體初使化過程中發生錯誤是很難找到錯誤源的不像軟體 debug 可

以使用專門的除錯工具step-by-step 除錯所以就發展出把初使過程分

成很多個小區間而每的區間皆會送出檢查碼(由兩個十六進位數值組成)至

Port80而 BIOS 廠商手上會有對應各檢查碼的 Table如此一但發生錯誤

就可以把發生錯誤的可能區域縮小

接著關閉不可遮蓋中斷(NMI)與優先權(Parity)這道理和先前提到的取

消中斷(cli)相同就不另外說明

然後驗證 BIOS 是否正確如果不

在初始化初期即檢查 BIOS 的正確

性那麼即使有錯也將繼續執行下去

如果只是浪費了時間倒還好要是初始

化發生嚴重錯誤導致損失那就糟了

接著就測試鍵盤控制器(KBC)

Fig59

28

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 34: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

接下來說明如何測試 KBC

在開始測試之前需先把系統旗標存起來(system-flag)它的內含值

指示此次 Reset 是否屬於 Power-On這在以後還需用到首先需先認識

InputBuffer[8bits 暫存器 惟寫] IO port 64h60h(共用)

OutputBuffer[8bits 暫存器 惟讀] IO port 60h

CommandData bit 0 -gt IO port 60h data-type

1 -gt IO port 64h command-byte

另外隨時可以使用 Port 64h 去讀取 KBC 狀態暫存器

Fg 511 KBC 自我測試(self-test)

Fg 510 KBC 狀態暫存器

Fg 512 鍵盤內部 BIOS

29

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 35: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

一開始由 Port 64h 送出 command-byte ldquo0aah這個指令是使 KBC 作

自我測試如果測試成功KBC 便會把 55h 寫入 OutputBuffer接著用

Port64h 去讀 KBC 狀態暫存器查看 OutputBuffer 是否為Fill如果

是 Port60h 讀入結果然後 Port64h 送出 command-byte60h準備把

鍵盤滑鼠使用狀態寫入控制器指令 Byte(當下次用 Port60h 作輸出

便會自動寫入控制器指令 Byte)Port64h 確定 InputBuffer 無資料把

系統旗標和使用狀態一起用 Port60h 寫入控制器指令 Byte

接著檢查 wakeup確認此次是硬體重置或是軟體重置至於為什麼要

做這項檢查留至下一章節再做說明然後把 CPU ID 寫入 CMOS Ram

使用的 IO port 為 70h[Address]與 71h[Data]

Fg513 存取 Cmos Ram

Port 70h寫入位

Port 71h寫入資

接著要執行一項很重要的工作一rdquo測試記憶體rdquo到目前為止執行的指

令皆是從 BIOS ROM 載入途中必需經過 ISA busPCI bus 最後 Host bus然後才到達 CPU所以執行的效率很低藉由儘早初使記憶記進而使用

記憶體執行 BIOS可以提高 POST 的速度那麼為什麼只測試 512KB 呢

因為 BIOS 很少會超過 256KB(廠商的成本考量)所以 512KB 就足夠

了不過原因也有可能是為了早一點到驗證主 BIOS(Main BIOS)的點因

為測試記憶體是很花時間的如果到了驗證主 BIOS 時驗證出錯誤那麼

就平白浪費了測試時間下頁說明測試記憶體的機制

30

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 36: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

在測試記憶體之前必需先

進入 Flat-Mode使定址能力達

到 4GB會先初始北橋內部與記

憶體有關的部份然後做

Memory Sizing接著就開始測試

512KB 記憶體細節在下面說

明在測式完閉後變開始把

BIOS 部份程序複製到記憶體

上然後 Jmp 到記憶體執行接下

來的工作

測試的 Pattern

[esedi]000000h ~ 07ffffh

512kb memory = 64k8 dword

填入 Pattern -gt 比對

Fg515 存取 Cmos Ram

Fg514 測試 Memory

31

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 37: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

進入燒入程序時會從floppy

disk複製至BIOS Chip所以floppy

disk會先被setup

接下透過解壓縮模組將壓縮的程

序解壓縮並複製到映射記憶體

上且存取模式為 取讀shadow ram 寫入 rom 最後Jmp至F000FFF0h

Fg516 從 BIOS ROM 複製程式至

Fg517 Flash 程序解壓縮

32

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 38: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 6 第二階段(記憶體可用

POSTamp解壓縮)

檢查喚醒(wake up)

初始化 Chipset

解壓縮 POST 至 Main Memory

CMOS 診斷(diagnostic)驗證

鍵盤控制器(KBC)

基本測試 BAT(Basic

Assurance Test)

初使化 VGA

初使化 裝置初使管

理員 DIM(Device Initialize Manager)

Fig61 BIOS POST 流程

這部份主要是針對週邊裝置作偵

測初始化 POST而且大多交由裝

置初始管理員 DIM 來主導初使的工

作不過 AIM 也把這個部份隱藏起

來無法看到它實際的程式流程而

到目前為止尚為初始任何顯示裝置

也就是說從開機到現在電腦瑩目還

未顯示任何資訊這必需等到 VGA初始後才會出現 AMI logo

另外在這邊也會測試整個記憶

體與 CMOS 設定

61 簡述此階段的工作

初使化 BUS

初使化 DMA 控制器

更新(Updata)CMOS

Fig62 BIOS POST 流程

記憶體整體測試

33

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 39: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

這邊的進入點為之前程序最後以 Jmp 跳回最高位址 FFFF0h那麼

不就等於重新 Bootup 嗎 雖然都是從最高位址執行但是這和 Power-On重製還是有很大的不同其關鍵就在於rdquowakeuprdquo檢查點還記得之前也曾

出現過同樣的檢查點其實在不同的重置動作會在 CMOS Ram 上的一塊

特定區域留下重置記錄所以即使重新 Bootup 也能在初期即設置檢

查前一次重置記錄的程序如果是非硬體重置便可以略過很多初使化的

動作

接下來的關機邏輯(Shutdown logic)程序是藉由讀取 KBC 狀態暫存器

(STATUS REGISTER)上的系統旗標(system flag)得知上次系的最後執行

的關機模式然後進行相對映的後續處理

[狀態暫存器(STATUS REGISTER) ndashIO SPACE 64H]

其中的系統旗標(bit-2)記錄前次關機模式

Hardreset(Power onreset) =gt 0

Softreset =gt1

在取得 shutdown code 後會依照不同的需求而執行不同的 shutdown 程序

Fig63 軟體重置

34

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 40: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig64 Shutdown 程序

35

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 41: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig65 解壓縮 POST 程序

36

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 42: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

這裡主要是檢查 CMOS 的

電源是否正常記憶區塊內紀

錄的組態是否與目前 POST 的

結果一致記憶區塊大小是否

正確並且更新診斷狀態而

這些診斷狀態值儲存在 CMOS

RAM 內佔用一個 Byte

Fig67 CMOS 診斷

在進行解壓縮模組或程式至 Shadow Ram 時的機制是預先在記憶上規畫

出一個不大的區塊當 Cache然後使用這個區塊作為複制的中介主要有

三個步驟

S1從 FlashROM 上複制(壓縮)模組程式到 Cache

S2再從 Cache 上解壓縮到 Shadow Ram 上

S3最後在清空 Cache

那麼為什麼在解壓縮時不直接解壓縮到 Shadow Ram 上而是先解壓縮後

才複製到目標位置這不是多此一舉 但這個機制會存在 BIOS 中必定

有它的原因猜想是解壓縮時可能會產生一些非目標檔案本體的額外資

料那麼如果直接解壓縮至 Shadow Ram要清除內些額外的資料 相對於

直接清除整個 Cache 將會麻煩很多或是預防解壓縮時意外把原來 Shadow

Ram 上的程序覆寫掉一部份那麼接下來執行可能會使 POST 出錯

Fg66 解壓縮記憶體使用

37

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 43: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig68 KBC

在 KBC 初使化後接著會檢查ltINSgtltENDgt鍵是否有輸入 BAT basic assurance test KBC 自我測試 BCP boot command processor P21 amp P22 為 KBC line

38

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 44: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig69 晶片組

39

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 45: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig610 晶片組(二)

觸發記憶體的 Refresh line 確認 15us ONOFF time(而剛開機時

只用標準 clock 速度)

40

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 46: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

接下來初使顯示裝置分為兩階段

S1 初使 Video ROM(顯示卡自已的 BIOS)

在初使化顯示裝置時裝置初使管理程序無法初使化 Video

ROM那麼便會嘗試使用其它的 ROM一但確定 ROM 可使用時便會把

控制權交給 Video ROM讓它去初使化顯示裝置(顯示卡)

S2 測試顯示記憶體

這會分別作讀寫測試單色(Mono)與彩色(CGA)的顯示記憶體測

完後則會設定顯示模式然後秀出顯示卡的資訊在瑩目上(這就是在

開機時會看到的第一個畫面很難想像 BIOS 執行到這裡才讓電

腦的畫面得以出現)

接著開始初使化顯示裝置

Fig611 顯示卡 VGA

41

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 47: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig612 顯示卡 VGA(二)

42 42

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 48: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig613 顯示卡 VGA(三)

43 43

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 49: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

在接下的這階段待面畫秀出 BIOS 廠的 Logo 後便開始初使化

匯流排系統並把原本可能被 Video ROM 上的初使程序所覆蓋過的

Shadow ROM 區塊的程序(POST)回存回 Shadow 上並且重設為寫入保

護接著顯示是否有匯流排系統上的錯誤最後顯示Hit Del訊息

告知使用者可以進入CMOS Setup

Fig614 顯示 logo

44

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 50: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

在這部份主要是測試基本(lt1MB)和延伸(gt1MB)的記憶體在這之前

未了要在測試記憶體時可以定址到上限 4GB 的位址所以必需切到保護

模式(也可以用 Flat Mode)而測試記憶體的方式是直接對測試記憶

體寫下一組資料樣板(例如2A2A2A2Ah 32 位元組的資料)依此逐一對

記憶體寫入並測試其是否有錯誤並計算出記憶體的大小

如果是用保護模式作記憶體測試則必需重置以回到真實模式所以在

測試完記憶體後程序會檢查是硬體重置還是軟體重置若為軟體重置

則回存 CPU 狀態並且回到真實模式此時可以記憶空間也回覆至 1MB

並清除Hit Del訊息

Fig615 測試 Memory

45

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 51: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig616 測試 Memory(二)

46

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 52: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig617 CMOS Setup

下面處理鍵盤錯誤

一按鍵被一直按住在系統 booted up 時一些系統會發現這特

殊案例但大部份會當作Keyboard error有些系統會顯示兩位

數字來告訴你問題當錯誤發生時這能讓你更容易糾正問題

47

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 53: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig618 Keyboard

48

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 54: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig619 CMOS Setup

接下來就是視使用者是否進入 CMOS Setup

49

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 55: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Chapter 7 第三階段

(CMOS 設定之後 POST 續)

初使 Chipset

匯流排選擇性 ROM(Bus Optional

ROM)

KBD Num-Lock

在載入 OS 之前 初始化 CPU

INT 19 載入 OS

Fig71 BIOS POST-續流程

這裡是 CMOS Setup 之後剩下的

PSOT 工作主要是作一些準備載入

作業系統前的前置工作

71 簡述此階段的工作

50

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 56: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig72 在 Cmos setup 之後

51

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 57: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig73 初始 Bus

52

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 58: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig74 SMRAM

53 53

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 59: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig75 Co-processor

54 54

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 60: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig76 Keyboard

55 55

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 61: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig77 顯示系統結構

56 56

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 62: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig78 DMI

57

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 63: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Fig79 INT19 ndashto OS

58 58

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 64: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

第三部份(附錄)

附錄 1 診斷碼

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

D0 NMI is Disabled CPU ID saved

Init code Checksum verification stating

D1 To do DMA init keyboard controller BAT test start

memory refresh and going to 4GB flat mode

D3 To start memory sizing

D4 To comeback to real mode Execute OEM patch Set

stack

D5 E000 ROM enabled Init code is copied to segment 0 and

control to be transferred to segment 0

D6 Control is in segment 0 to check ltCTRLgtltHOMEgt key

and verify main BIOS check sum

03 NMI is Disabled To check soft resetpower-on

05 BIOS stack set Going to disable cache if any

06 POST code to be uncompressed

07 CPU init and CPU data area init to be done

08 CMOS checksum calculation to be done next

0B Any initialization before keyboard BAT to be done next

0C KB controller IB free To issue the BAT command to

keyboard controller

0E Any initialization after KBC BAT to be done next

0F Keyboard command byte to written

59

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 65: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

10 Going to issue Pin-2324 blockingunblocking command

11 Going to check pressing of ltINSgtltENDgtkey during

power-on

12 To init CMOS if ldquoInit CMOS in every boot is set or

ltENDgt key is pressed Going to disable DMA and

interrupt controllers

13 Video display is disabled and port-B is initialize

14 8254 timer test about to start

19 About to start memory refresh test

1A Memory refresh line is toggling Going to check 15us

ONOFF time

23 To read 8042 input port and disable Megakey GreenPC

feature Make BIOS code segment writeable

診斷碼(HEX) 所進行到的程式碼流程停止或錯誤發生錯誤原因

24 To do any setup before Int vector init

25 Interrupt vector initialization to begin To clear password

if necessary

27 Any initialization before setting video mode to be done

28 Going for monochrome mode and color mode setting

2A Different BUSes init (system static output devices) to

start if present

2B To give control for any setup required before optional

video ROM check

2C To look for optional video ROM and give control

2D To give control to any processing after video ROM return

control

60

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 66: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

2E If EGAVGA not found then do display memory RW

test

2F EGAVGA not found Display memory RW test about to

begin

30 Display memory RW test passed About to look for the

retrace checking

31 Display memory RW test or retrace checking failed To

do alternate display memory RW test

32 Alternate display memory RW test passed To look for

the alternate display retrace checking

34 Video display checking over Display mode to be set next

37 Display mode set Going to display the power-on

message

38 Different BUSes init (input IPL general devices) to start

if present

39 Display different BUSes initialization error messages

3A New cursor position read and saved To display the Hit

ltDELgt message

40 To prepare the descriptor table

42 To enter virtual mode for memory test

43 To enable interrupts for diagnostics mode

44 To initialize data to check memory wrap around at 00

45 Data initialize Going to check for memory wrap around at

00 and finding the total system memory size

46 Memory wrap around test done Memory size calculation

over About to go for writing patterns to test memory

61

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 67: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

47 Pattern to be tested written in extended memory Going to

write patterns in base 640K memory

48 Patterns written in base memory Going to findout amount

of memory below 1M memory

49 Amount of memory below 1M found and verified Going

to findout amount of memory above 1M memory

4B Amount of memory above 1M found and verified Check

for soft reset and going to clear memory below 1M for

soft reset (if power-on go to check point 4eh)

4C Memory below 1M cleared (soft reset) Going to clear

memory above 1M

4D Memory above 1M cleared (soft reset) Going to save the

memory size (go to check point 52h)

4E Memory test start (not soft reset) About to display first

64K memory size

4F Memory size display start This will be updated during

memory test Going for sequential and random memory

size

50 Memory testinginitialization below 1M complete Going

to adjust displayed memory size for relocationshadow

51 Memory size display adjusted due to relocationshadow

Memory test above 1M below

52 Memory testinginitialization above 1M complete

53 Memory size information is saved CPU register is saved

Going to enter in real mode

54 Shutdown successful CPU in real mode Going to disable

62

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 68: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

gate A20 line and disable parityNMI

57 A20 address line parityNMI disable successful Going to

adjust memory size depending on relocationshadow

58 Memory size adjusted for relocationshadow Going to

clear Hit ltDELgt message

59 Hit ltDELgt message cleared ltwaithellipgt message

displayed About to start DMA and interrupt controller

test

60 DMA page register test passed To do DMA1 base

register test

62 DMA1 base register test passed To do DMA2 base

register test

65 DMA2 base register test passed To program DMA unit

1 and 2

66 DMA unit 1 and 2 programming over To initalize8259

interrupt controller

7F Extended NMI sources enable is in progress

80 Keyboard test started Clear output buffer checking for

stuck key to issue keyboard reset command

81 Key board reset errorstuck key found To issue keyboard

controller interface test command

82 Keyboard controller interface test over To write

command byte and init circular buffer

83 Command byte written global data init done To check

for lock-key

84 Lock-key checking over To check for memory size

63

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 69: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

mismatch with CMOS

85 Memory size check done To display soft error and check

for password or bypass setup

86 Password checked About to programming before setup

87 Programming before setup complete To uncompress

SETUP code and execute CMOS setup

88 Returned from CMOS setup program and screen is cleared

about to do programming after setup

89 Programming setup complete Going to display power on

screen message

8B First screen message and ltWAIThellipgt message displayed

PS2 mouse check and extended BIOS data area allocation

to be done

8C Setup options programming after CMOS setup about to

start

8D Going for hard disk controller reset

8F Hard disk controller reset done Floppy setup to be done

next

91 Floppy setup complete Hard disk setup to be done next

95 Init of different BUSes optional ROMs from C800 to

start

96 Going to do any init before C800 optional ROM control

97 Any init before C800 optional ROM control is over

Optional ROM check and control will be done next

98 Optional ROM control is done About to give control to

do any require processing after optional ROM return

64

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 70: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

control and enable external cache

99 Any initialization required after optional ROM test over

Going to setup timer data area and printer base address

9A Return after setting timer and printer base address Going

to do set the RS-232 base address

9B Returning after RS-232 base address Going to do any

initialization before coprocessor test

9C Required initialization before coprocessor is over Going

to initialize coprocessor next

9D Coprocessor initialized Going to do any initialization

after coprocessor test

9E Initialization after coprocessor test is complete Going to

check extended keyboard keyboard ID and num-lock

Keyboard ID command to be

A2 Going to display any soft error

A3 Soft error display complete Going to set keyboard

typematic rate

A4 Keyboard typematic rate set To program memory wait

states

A5 Going to enable parityNMI

A7 NMI and parity enable Going to do any initialization

required before giving control to optional ROM at E000

A8 Initialization before E000 ROM control over E000 ROM

to get control next

A9 Return from E000 ROM control Going to do any

initialization required after E000 optional ROM control

65

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 71: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

AA Initialization after E000 optional ROM control is over

Going to display the system configuration

AB To build MP table if need

AC To uncompress DMI data and execute DMI POST init

B0 System configuration is displayed

B1 Going to copy any code to specific area

00 Copying of code to specific area done Going to give

control to INT-19 boot loader

附錄 2 縮寫名詞對照表

BBS gt BiOS Boot Specification

IPL gt Initial Program Load

(IPL) device is one form of a boot device and is a mainframe term for the loading of

the operating system into the computers main memory

MCA gt Machine Check Architecture

gt Runtime Program(常駐程式常駐於某段記憶體提供 OSAP 呼叫)

===BiOS=========================================

Flash ROM gt (快閃唯讀記憶體(平時與 ROM 一樣但在特殊工具配合相關硬體

設定與特定電壓下=gt 可以被改寫))

POST gt Power On Self Test(開機自我測試)

66

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 72: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

BAT gt Basic Assurance Test

diagnostic self-test (可能是自已內部獨立測試不需外部提供)

----- Module---------

DAM gt DATA ACQUISITION MODULE

DIM gt Device Initialize Manager

DMI gt Desktop Management Interface

is a layer of abstraction between system components and the software that

manage them

ADM gt Avanced Display Management

===Interrupt======================================

NMI gt Not Mask Interrupt

(L)APIC gt (Local)Advanced Programmable Interrupt Controller

SCI gt System Control Interrupt

ISR gt Interrupt Service Routine

===CPU==========================================

BSP gt Bootstrap Processor

(gt Bit-Slice Processor)

MP gt Multi-Process

BCP gt Boot Command Processor

TSC gt Time Stamp Counter(時序記錄器)

67

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 73: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

---Register--------------

MSRs gt Model Specific Register

---Cache-----------------

TLB gt Translation Lookaside Buffer

a small fast-lookup hardware cache [tag value]

---Page-------------------

PTEs gt Page Table Entries

===Memory Map===================================

MTRR gt Memory Type Range Registers

IORR gt IO

MMRs gt Memory Map Registers

MMIO gt Memory Map IO

PAT gt Page Attribute table

SPD ROM gt Serial Presence Detect ROM

DLL gt Digital Looked Loop

SMRAM gt System Management RAM

It provides a safe location for system management code amp data that is not readily

accessible by app

68

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 74: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

-------mem access---------

--descriptor table--

GDT gt Global Descriptor Table

The GDT is a control table for managing addressing in segmented mode

LDT gt Local Descriptor Table

IDT gt Interrupt Descriptor Table

GDTRLDTRIDTR gt xxx Register

===Chipset====================================

SMBA gt Shared Memory Buffer Architecture

(V)UMA gt (VESA)unified memory architecture

----NorthBridge----------------------

SRI gt System Request Interface

XBAR gt Cross Bar

===Bus System====================================

PnP gt Plug amp Play

----PCI----------

(E)ISA gt (Extended) Industry Standard Architecture

===VideoCard=====================================

69

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 75: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

VGA gt Video Graphics Array

VESA gt Video Electronics Standards Association

----video Ram-----

LFB gt Local Frame Buffer (區域顯示記憶體)

UMA gt Unified Memory Area (與主機板共用)

SMA gt Share Memory Architecture

GART gt Graphics Aperture Relocation Table

---DisplayMode----

EGA gt Enhanced Graphics Adapter

===HDD=========================================

LBA gt Logical Block Addressing

A method used with SCSI and IDE disk drives to translate the cylinder head and

sector specifications of the drive into addresses that can be used by an enhanced BIOS

LBA is used with drives that are larger than 528MB

===POWER=======================================

PMU gt Power Management Unit

SMM gt System Management Mode

SM RAM gt System Management RAM

SMI gt System Management Interrupt

SCI gt System Control Interrupt

APM gt Advanced Power Management(先進電源管理介面)

70

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 76: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

ACPI gt Advanced Configuration amp Power Interface(先進電源組控制介面)

APC gt Automatic Power Control

(softhard-ware power updown functions)mainly to support the ACPI power

control functions

PMM gt Power Management Mode

---------ACPI 系統需建立-------------------------

RSDT | Root System(Source) Descriptor Table

FACP | Fixed ACPI Table

DSDT | Differentiated System Description Table

SBST | Smart Battery Specification Table(智慧型電池控制表)

APIC | Advanced Programmable Interrupt Controller(中斷控制設定表格)

ASLAML | ACPI Source Control Language(原始碼控制語言)ACPI Machine Control

Language(機器控制語言)

===CMOS========================================

CMOS Chip gt Complementary Metal Oxide Semiconductor Chip(初稱 RTCCMOS

RAM(計時參數記錄晶片) 原指一種 IC 製程(具備省電低溫))

NVRam gt Non-Volatile RAM(非揮發性記憶體 Ex CMOSFlash Memory(的 ESCD

區域))

GPNV RAM gt General Purpose Non-Volatile RAM

(GPNV) area is a persistent general-purpose storage area managed by the System

Management BIOS For store System Event Log

ESCD gt Extended System Configuration Data

ESCD area is a special part of your BIOSs CMOS memory where BIOS settings are

held

71

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 77: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

================================================

8042 鍵盤控制器(KeyBoard Control)

8237 直接記憶體存取控制器(DMA controller)

8254 計時器(timer)

8255 可程式週邊介面(Programmable Peripheral Interface)

8259A 可程式中斷控制器(Programmable Interrupt Controller)

8284 序產生器(Impulse Producer)

===New Hardware=================================

---ACPI 20-----

XSDT gt Extended System Description Table

附錄 3 參考資料

BIOS Inside ndash BIOS 研發技術剖析 陳文欽 著

IBM80X86 組合語言實務 施威銘 著

Intel 官方網站 httpwwwintelcom

WIKI百科 httpenwikipediaorgwikiMain_Page

IBM 官方網站 httpwwwibmcomus

SiS 0530DS10pdf

SiS5595-20pdf

AMI AMIBIOS-CheckPoint_BeepCodes_listpdf

AMD dwamd_26049_2003_amd_biospdf

24593_Volume 2System Programmingpdf

PCI_v22pdf

pci_bios21pdf

72

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 78: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

Addison Wesley - PCI Express System Architecturechm

73

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 79: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

心得

資訊四甲 曾成濱

當初會選這個專題是應同學邀請然後自已對硬體也很有興趣所以就開始了這

個兩人 group在和同學一起作這專題的一年半之間時常在 meeting 前一天討

論到半夜因為 BiOS 是個範圍含蓋很大的領域而很多部份對廠商來說是機密

的所以資料來源取得不易常常花了很多時間去搜尋資料與用猜想的方法去

接近解答有時自已覺得懂了可過了一陣子之後又發現自已是錯的就這樣慢

慢對電腦有了更深刻的了解雖然這專題最後並沒有達到自已的期許不過已經

讓我成長了很多對於沒有頭緒的未知該如何去面對適應它

最後感謝這段時間一起作專題的楊逸翔同學 與給予我們協助的陳德生老師

74

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75

Page 80: 基本輸入/輸出系統(BIOS)研究 - read.pudn.comread.pudn.com/downloads141/ebook/608635/BIOS研究.pdf · (NIC)..等,因為較複雜的外接週邊硬體設計差異很大,各自有其獨特初始動作,

楊逸翔 資訊四甲

這次的專題研究主要是在研究 BIOS因為當初希望能在研究所研究 SOC所

以希望能藉由 BIOS 來了解電腦的硬體架構使之後能比較容易了解 SOC 的硬體

設計

一開始做這專題還蠻辛苦的因為一直四處碰壁因為 BIOS 和有些電腦的

硬體架構為商業機密因此在找資料上就花了很多功夫另外像是一些名詞的縮

寫也是花了很多功夫才知道他的意思而之後便是開始讀一堆的原文資料做這

次專題真的是讓我讀了很多的原文相信對以後進入研究所研讀論文有相當大的

幫助

最後謝謝一起努力的夥伴 成濱 以及陳德生老師的指導

75