http://www.wretch.cc/blog/hyper0672/9867131
以下为转帖

完整的文件可以参考
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 Header

BEV (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.
· ENDIF

Boot 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

 

阅读全文
类别:Bios 查看评论
posted on 2010-12-18 17:51  sinbad_li  阅读(1447)  评论(0编辑  收藏  举报