以下為轉帖
完整的文件可以參考
http://www.phoenix.com/NR/rdonlyres/56E38DE2-3E6F-4743-835F-B4A53726ABED/0/specsbbs101.pdf
以下為一些重點整理
BBS (BIOS Boot Specification) 是用來規範 BIOS 如何選擇啟動裝置。它包含了
1. 辨識系統中的 IPL (Initial Program Load) 裝置
2. 根據使用者的選擇,尋訪每個裝置並檢視它是否能夠啟動系統
IPL (Initial Program Load) Device:
IPL Devie 指的是可以啟動載入並執行作業系統的裝置。他包含了像是 Floppy, Hard drives, CD-ROM, PCMCIA conrtollers/cards, PnP Cards, Legacy cards 甚至像是 Network, Serial port, Parallel port 等等可開機的實體或虛擬裝置。
所有的 IPL 可以被歸類成下列三種
1. BAID
2. PnP Card (可再細分為 BCV 和 BEV 兩種裝置)
3. Legacy IPL Device
BAID (BIOS Aware IPL Device):
此類 IPL 需要 BIOS 的程式碼支援,來提供它啟動系統的能力。通常啟動的程式碼內建於 INT 19h (BIOS Bootstrap loader) 的服務之中。常見的裝置如下:
First floppy drive, First ATA Hard drive, PCI ATA card drive, ATAPI CD-ROM drive, PCMCIA controller bootable card, Ethernet controller code embedded in BIOS
PnP Cards:
此類 IPL 裝置,必須附加 option ROM 於 C0000h-EFFFFh (2K boundary)。而且在 Option ROM 中必須有 PnP Option ROM Header (Table 2)。另外,開機相關資訊會被記錄在 PnP Expansion Header (Table 3),在此表格中,包含了 BCV 或 BEV 的指標。
BCV (Boot Connection Vector):
BCV 是一個指標,指向 Option ROM 中的某一段程式碼。這段程式碼負責執行裝置的初始化、偵測硬體 (例如是否有 SCSI 裝置連接到系統) 或者在必要時 Hook INT 13h 的服務 (Disk I/O)。常見的有:
PnP SCSI card drive, NoN-PnP card PnP Expansion HeaderBEV (Bootstrap Entry Vector):
BEV 是一個指標,指向 Option ROM 中負責載入作業系統的一段程式碼,並在必要時 Hook INT 18h 或 INT 19h 的服務。通常於網路卡裝置的 Network Remote Boot 時使用。常見的有:
PnP Token Ring card, PnP Ethernet card, NoN-PnP card PnP Expansion Header
Legacy IPL Devices:
此類裝置為標準的 ISA Card,其包含了一個 Option ROM 於 C0000h-EFFFFh (2K boundary)。此類型的裝置於 Option ROM 並沒有 PnP Expansion Header 的相關資訊。在它的 Option ROM 被 BIOS 找到時,會先執行一段初始化的程式。這段程式執行期間,會根據需要來 Hook INT 19h, INT 18h 以及 INT 13h。
IPL Table
每個 BAID 以及 BEV 裝置必須在 IPL Table 中有一個相對應的欄位
範例
0: Floppy A:
1: Hard Drive C:
2: CD-ROM
3: BEV #1
4: BEV #2
IPL Priority
IPL Priority 決定 IPL 開機的順序。它存在於非揮發性記憶體中,並且可以讓使用者修改。在 INT 19h (載入作業系統) 呼叫中,它必須能夠被取用,並且根據表格中的順序來進行開機的程序。
範例
0: 3 (BEV #1)
1: 4 (BEV #2)
2: 1 (Hard Drive C:)
3: 2 (CD-ROM)
4: 0 (Floppy A:)
IPL Priority Pseudocode
Created at BIOS build time:
First few IPL Table entries are filled in by the BAIDs.
maxIPLCount = Number of entries in IPL Table.
baidCount = Number of BAIDs in the system.
maxBEVCount = (maxIPLCount - baidCount).
The NV memory space for the IPL Priority is reserved.
Assumptions:
· The default for the IPL Priority will automatically be
created during POST in case the NV memory gets corrupted.
· nvBEVCount = number of BEV devices found last time -
stored in NV memory.
· postBEVCount = number of BEV devices found this time.
Execution at POST time:
· All option ROMs with a PnP Expansion Header are identified
and their initialization entry points are called.
· Additional IPL Table entries are filled in with the BEV
devices found.
· IF (NV memory is corrupted)
· Set default IPL Priority by first placing the BAIDs,
and then adding in the BEVs in the order they were found.
· ELSE
· The IPL Priority is retrieved from NV memory.
· deltaBEVCount = (nvBEVCount - postBEVCount).
· IF (deltaBEVCount != 0)
· IF (deltaBEVCount > 0)
· FOR (i = 0; i != deltaBEVCount; ++i)
· Add a new BEV device to the end of IPL Priority.
· ELSE
· For (i = 0; i != deltaBEVCount; --i)
· Delete the BEV device nearest the end of IPL Priority.
· ENDIF
· Save the postBEVCount in NV memory as nvBEVCount.
· Save the new IPL Priority in NV memory.
· (Optional) - Display a message that the IPL Priority
changed and allow the user to enter Setup to reconfigure
the IPL Priority.
· ENDIF
· ENDIF
· Invoke INT 19h.
BCV Priority
在 BIOS INT 13h (Disk I/O) 的服務之中,磁碟機代號 00-7Fh 為 Floppy Disk, 而 80-FFh 為 Fixed Disk。而這些代號和實體磁碟的對應必須在 BIOS 中完成。另外值得注意的一點就是,由於只有第一台 Floppy 和第一台 Fixed Disk 可以用來啟動 (代號 00h 以及 80h),所以根據不同的啟動設定,也必須將 INT 13h Hook 的順序作調整才能夠順利開機。
舉例來說,如果 ATA 硬碟佔用掉 80h,而 SCSI 只能佔用 81h 之後的磁碟機代號的話,那麼 SCSI 硬碟就不能作為開機的硬碟了。
範例
BCV Table
0: ATA Drives
1: Legacy Cards
2: BCV #1
3: BCV #2
BCV Priority
0: 2 (BCV #1)
1: 0 (ATA Drives)
2: 1 (Legacy Cards)
3: 3 (BCV #2)
INT 13h 支援的裝置有下列幾種
1. ATA Drive
2. PnP Cards with BCVs
3. Legacy Cards with Option ROMs
4. Hard Drive BAID
關於 INT 13h 的幾個重點
1. 當 INT 13h 被 Hook 時,舊的 INT 13h Vector 必須被保存
2. 已經安裝的硬碟數目必須被保存在 BDA 0040:0075
3. 第一個安裝的硬碟會得到 80h 的代號,這也代表著它是開機硬碟
4. 一旦安裝到 INT 13h 之後,就不能被解除安裝
BCV Post Pseudocode
Created at BIOS build time:
· First two BCV Table entries are filled in by ATA support and
Legacy option ROM
support.
· The NV memory space for the IPL Priority is reserved.
Assumptions:
· The default for the BCV Priority will automatically be
created during POST in case the NV memory gets corrupted.
1. Call the video option ROM.
2. Initialize the first two BCV Table entries with ATA Support
and Legacy Cards respectively. These two entries will always
exist in the BCV Table and will always be in that order.
3. Identify all option ROMs with BCVs and add any that are
found to the BCV Table.
4. Call all the BCV option ROMs in the order they reside in
the BCV Table and store their return value in AX upon return.
5. If NV memory is corrupted, set defaults for BCV Priority
and BCVCount.
6. Check if the number of BCV devices found this time matches
the number found last time. If not, update the BCV Priority
and BCVCount accordingly.
7. FOR (i = 0; i < index =" BCV">INT 19h
在這個服務呼叫時,所有的 IPL 已經被辨識,並且 INT 13h 的裝置也都已安裝完成。在呼叫之後,它會根據 IPL Priority 中的裝置,呼叫其 Boot handler。第一個呼叫成功的裝置會負責載入作業系統。如果全部的裝置都已呼叫過後還沒有成功載入作業系統,它會顯示一個錯誤訊息,並且等待重新開 始。
以下為 INT 19h 的 Pseudocode
· IPLcount = current number of BAIDs and BEV devices at this boot.
· FOR (i = 0; i < currentipl =" IPL">INT 18h
原本的 INT 18h 的動作是將控制權交給 BIOS,顯示一個錯誤訊息並且等待使用者按下按鍵後進行下一個動作。而在 BBS 中重新定義 INT 18h 的功能為錯誤回覆的中斷向量。這裡要注意的是 INT 18h 並不會返回至呼叫它的程序,並且在一開始就將堆疊重新設定。
以下為 INT 18h 的 Pseudocode
· Reset stack.
· IF (all IPL devices have been attempted)
· Print an error message that no O/S was found.
· Wait for a key stroke.
· Execute the INT 19h instruction.
· ELSE
· Determine which IPL device failed to boot.
· Jump to a label in the INT 19h handler to try the next
IPL device.
· ENDIFBoot Menu (Optional)
在 POST 期間,部份 BIOS 充許使用者使用一個特定的 Hot Key 來呼叫 Boot Menu,並用它來改變 INT 19h 所使用的啟動裝置。這裡要注意的是,這個動作並不會改變 IPL Priority 的內容,它只是單純地選擇啟動的裝置。
以下為 Pseudocode
IF (A Boot Menu selection was made)
currentIPL = IPL Priority[Boot Menu selection].
Use currentIPL to select the BAID or BEV table entry.
Do a far call to the boot handler, if successful we never return.
IF (we get control back via RETF, or an INT 18h):
Clean up the stack if necessary.
ENDIF
ENDIF
一些相關的表格Table 1 - IPL Table and BCV Table Entry Data Structure
Name Offset Size Description
deviceType 00h WORD See definitions below
statusFlags 02h WORD See bit definitions below
bootHandler 04h FAR PTR Far pointer to address of boot handler
descString 08h FAR PTR Far pointer to ASCIIZ description string
expansion 0Ch DWORD Reserved for future expansion
deviceType:
00h = Reserved
01h = Floppy
02h = Hard disk
03h = CD-ROM
04h = PCMCIA
05h = USB device
06h = Embedded network
07h..7Fh = Reserved
80h = BEV device
81h..FEh = Reserved
FFh = Unknown
Table 2 - PnP Option ROM Header
Offset Size Value Description
00h BYTE 55h Signature byte 1
01h BYTE AAh Signature byte 2
02h BYTE Varies Option ROM length in 512-byte blocks
03h DWORD Varies Initialization entry point
07h 17BYTES Varies Reserved.
18h WORD Varies Offset to PCI data structure
1Ah WORD Varies Offset to expansion header structure
Table 3 - PnP Expansion Header
0ffset Size Value Description
00h BYTE '$' Signature byte 1
01h BYTE 'P' Signature byte 2
02h BYTE 'n' Signature byte 3
03h BYTE 'P' Signature byte 4
04h BYTE 01h Structure revision
05h BYTE Varies Length (in 16 byte increments)
06h WORD Varies Offset of next header (0000h if none).
08h BYTE 00h Reserved
09h BYTE Varies Checksum
0Ah DWORD Varies Device identifier
0Eh WORD Varies Pointer to manufacturer string (Optional)
10h WORD Varies Pointer to product name string (Optional)
12h 3BYTES Varies Device type code
15h BYTE Varies Device indicators
16h WORD Varies Boot Connection Vector (BCV), 0000h if none
18h WORD Varies Disconnect Vector (DV), 0000h if none
1Ah WORD Varies Bootstrap Entry Vector (BEV), 0000h if none
1Ch WORD 0000h Reserved
1Eh WORD Varies Static resource information vector, 0000h if none
Table 4 - PCI Data Structure
00h BYTE 'P' Signature byte 1
01h BYTE 'C' Signature byte 2
02h BYTE 'I' Signature byte 3
03h BYTE 'R' Signature byte 4
04h WORD Varies Vendor Identification
06h WORD Varies Device Identification
08h WORD Varies Pointer to Vital Product Data
0Ah WORD Varies PCI Data Structure Length
0Ch BYTE Varies PCI Data Structure Revision
0Dh 3BYTES Varies Class Code
10h WORD Varies Image Length
12h WORD Varies Revision Level of Code/Data
14h BYTE Varies Code type
15h BYTE Varies Indicator
16h WORD Reserved
沒有留言:
張貼留言