1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for generating and accessing drive
|
---|
3 | ; information to be displayed on boot menu.
|
---|
4 |
|
---|
5 | ; Section containing code
|
---|
6 | SECTION .text
|
---|
7 |
|
---|
8 | ;--------------------------------------------------------------------
|
---|
9 | ; Creates new BOOTMENUINFO struct for detected hard disk.
|
---|
10 | ;
|
---|
11 | ; BootMenuInfo_CreateForHardDisk
|
---|
12 | ; Parameters:
|
---|
13 | ; DL: Drive number
|
---|
14 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
15 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
16 | ; Returns:
|
---|
17 | ; ES:BX: Ptr to BOOTMENUINFO (if successful)
|
---|
18 | ; Corrupts registers:
|
---|
19 | ; AX, CX, DX, DI
|
---|
20 | ;--------------------------------------------------------------------
|
---|
21 | BootMenuInfo_CreateForHardDisk:
|
---|
22 | call BootMenuInfo_ConvertDPTtoBX ; ES:BX now points to new BOOTMENUINFO
|
---|
23 | push ds ; Preserve RAMVARS...
|
---|
24 | push si ; ...and SI
|
---|
25 |
|
---|
26 | push es ; ES to be copied to DS
|
---|
27 |
|
---|
28 | %ifdef MODULE_ADVANCED_ATA
|
---|
29 | ; Copy DPT_ADVANCED_ATA to BOOTMENUINFO to keep DPTs small.
|
---|
30 | ; DPT_ADVANCED_ATA has variables that are only needed during initialization.
|
---|
31 | mov ax, [di+DPT_ADVANCED_ATA.wIdeBasePort]
|
---|
32 | mov [es:bx+BOOTMENUINFO.wIdeBasePort], ax
|
---|
33 | mov dx, [di+DPT_ADVANCED_ATA.wMinPioActiveTimeNs]
|
---|
34 | mov [es:bx+BOOTMENUINFO.wMinPioActiveTimeNs], dx
|
---|
35 |
|
---|
36 | mov ax, [di+DPT_ADVANCED_ATA.wMinPioRecoveryTimeNs]
|
---|
37 | mov cx, [di+DPT_ADVANCED_ATA.wControllerID]
|
---|
38 | mov dx, [di+DPT_ADVANCED_ATA.wControllerBasePort]
|
---|
39 | pop ds ; ES copied to DS
|
---|
40 | mov [bx+BOOTMENUINFO.wMinPioRecoveryTimeNs], ax
|
---|
41 | mov [bx+BOOTMENUINFO.wControllerID], cx
|
---|
42 | mov [bx+BOOTMENUINFO.wControllerBasePort], dx
|
---|
43 |
|
---|
44 | %else
|
---|
45 | pop ds ; ES copied to DS
|
---|
46 | %endif
|
---|
47 |
|
---|
48 | ; Store Drive Name
|
---|
49 | add si, BYTE ATA1.strModel ; DS:SI now points drive name
|
---|
50 | lea di, [bx+BOOTMENUINFO.szDrvName] ; ES:DI now points to name destination
|
---|
51 | mov cx, MAX_HARD_DISK_NAME_LENGTH / 2 ; Max number of WORDs allowed
|
---|
52 | .CopyNextWord:
|
---|
53 | lodsw
|
---|
54 | xchg al, ah ; Change endianness
|
---|
55 | stosw
|
---|
56 | loop .CopyNextWord
|
---|
57 | xor ax, ax ; Zero AX and clear CF
|
---|
58 | stosw ; Terminate with NULL
|
---|
59 |
|
---|
60 | pop si
|
---|
61 | pop ds
|
---|
62 | ret
|
---|
63 |
|
---|
64 |
|
---|
65 | ;--------------------------------------------------------------------
|
---|
66 | ; BootMenuInfo_GetTotalSectorCount
|
---|
67 | ; Parameters:
|
---|
68 | ; DS:DI: DPT Pointer
|
---|
69 | ; Returns:
|
---|
70 | ; BX:DX:AX: 48-bit sector count
|
---|
71 | ; Corrupts registers:
|
---|
72 | ; CX
|
---|
73 | ;--------------------------------------------------------------------
|
---|
74 | BootMenuInfo_GetTotalSectorCount:
|
---|
75 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
|
---|
76 | jnz SHORT .ReturnFullCapacity
|
---|
77 | jmp AH15h_GetSectorCountToBXDXAX
|
---|
78 | .ReturnFullCapacity:
|
---|
79 | jmp AccessDPT_GetLbaSectorCountToBXDXAX
|
---|
80 |
|
---|
81 |
|
---|
82 | ;--------------------------------------------------------------------
|
---|
83 | ; BootMenuInfo_IsAvailable
|
---|
84 | ; Parameters:
|
---|
85 | ; Nothing
|
---|
86 | ; Returns:
|
---|
87 | ; ES: Segment to BOOTVARS with BOOTMENUINFOs
|
---|
88 | ; ZF: Set if BOOTVARS with BOOTMENUINFOs is available
|
---|
89 | ; Cleared if not available (no longer initializing)
|
---|
90 | ; Corrupts registers:
|
---|
91 | ; BX
|
---|
92 | ;--------------------------------------------------------------------
|
---|
93 | BootMenuInfo_IsAvailable:
|
---|
94 | LOAD_BDA_SEGMENT_TO es, bx
|
---|
95 | cmp WORD [es:BOOTVARS.wMagicWord], BOOTVARS_MAGIC_WORD
|
---|
96 | ret
|
---|
97 |
|
---|
98 |
|
---|
99 | ;--------------------------------------------------------------------
|
---|
100 | ; Returns offset to BOOTMENUINFO based on DPT pointer.
|
---|
101 | ;
|
---|
102 | ; BootMenuInfo_ConvertDPTtoBX
|
---|
103 | ; Parameters:
|
---|
104 | ; DS:DI: DPT Pointer
|
---|
105 | ; Returns:
|
---|
106 | ; BX: Offset to BOOTMENUINFO struct
|
---|
107 | ; Corrupts registers:
|
---|
108 | ; Nothing
|
---|
109 | ;--------------------------------------------------------------------
|
---|
110 | BootMenuInfo_ConvertDPTtoBX:
|
---|
111 | push ax
|
---|
112 | mov ax, di
|
---|
113 | sub ax, BYTE RAMVARS_size ; subtract off base of DPTs
|
---|
114 | mov bl, DPT_BOOTMENUINFO_SIZE_MULTIPLIER ; BOOTMENUINFO's are a whole number multiple of DPT size
|
---|
115 | mul bl
|
---|
116 | add ax, BOOTVARS.rgBootNfo ; add base of BOOTMENUINFO
|
---|
117 | xchg ax, bx
|
---|
118 | pop ax
|
---|
119 | ret
|
---|