[99] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Functions for accessing DPT data. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
[150] | 8 | ; AccessDPT_GetDriveSelectByteToAL |
---|
| 9 | ; Parameters: |
---|
| 10 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 11 | ; Returns: |
---|
| 12 | ; AL: Drive Select Byte |
---|
| 13 | ; Corrupts registers: |
---|
| 14 | ; Nothing |
---|
| 15 | ;-------------------------------------------------------------------- |
---|
| 16 | ALIGN JUMP_ALIGN |
---|
| 17 | AccessDPT_GetDriveSelectByteToAL: |
---|
| 18 | mov al, [di+DPT.wFlags] |
---|
| 19 | and al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV |
---|
| 20 | or al, MASK_DRVNHEAD_SET ; Bits set to 1 for old drives |
---|
| 21 | ret |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | ;-------------------------------------------------------------------- |
---|
| 25 | ; AccessDPT_GetDeviceControlByteToAL |
---|
| 26 | ; Parameters: |
---|
| 27 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 28 | ; Returns: |
---|
| 29 | ; AL: Device Control Byte |
---|
| 30 | ; Corrupts registers: |
---|
| 31 | ; Nothing |
---|
| 32 | ;-------------------------------------------------------------------- |
---|
| 33 | ALIGN JUMP_ALIGN |
---|
| 34 | AccessDPT_GetDeviceControlByteToAL: |
---|
| 35 | xor al, al |
---|
[158] | 36 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ |
---|
[150] | 37 | jnz SHORT .EnableDeviceIrq |
---|
| 38 | or al, FLG_DEVCONTROL_nIEN ; Disable IRQ |
---|
| 39 | .EnableDeviceIrq: |
---|
| 40 | ret |
---|
| 41 | |
---|
[227] | 42 | |
---|
[150] | 43 | ;-------------------------------------------------------------------- |
---|
[227] | 44 | ; AccessDPT_GetLCHStoAXBLBH |
---|
[3] | 45 | ; Parameters: |
---|
| 46 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 47 | ; Returns: |
---|
[227] | 48 | ; AX: Number of L-CHS cylinders |
---|
| 49 | ; BL: Number of L-CHS heads |
---|
| 50 | ; BH: Number of L-CHS sectors per track |
---|
[3] | 51 | ; Corrupts registers: |
---|
[227] | 52 | ; CX, DX |
---|
[3] | 53 | ;-------------------------------------------------------------------- |
---|
[227] | 54 | AccessDPT_GetLCHStoAXBLBH: |
---|
| 55 | ; Return LBA-assisted CHS if LBA addressing used |
---|
[173] | 56 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA |
---|
[227] | 57 | jz SHORT .ConvertPchsToLchs |
---|
[173] | 58 | |
---|
[227] | 59 | call AccessDPT_GetLbaSectorCountToBXDXAX |
---|
| 60 | call AtaID_GetLbaAssistedCHStoDXAXBLBH |
---|
| 61 | test dx, dx |
---|
| 62 | jnz SHORT .LimitAXtoMaxLCHScylinders |
---|
| 63 | cmp ax, MAX_LCHS_CYLINDERS |
---|
| 64 | jbe SHORT .returnLCHS |
---|
| 65 | .LimitAXtoMaxLCHScylinders: |
---|
| 66 | mov ax, MAX_LCHS_CYLINDERS |
---|
| 67 | .returnLCHS: |
---|
| 68 | ret |
---|
[173] | 69 | |
---|
[227] | 70 | .ConvertPchsToLchs: |
---|
| 71 | mov ax, [di+DPT.wPchsCylinders] |
---|
| 72 | mov bx, [di+DPT.wPchsHeadsAndSectors] |
---|
| 73 | jmp SHORT AccessDPT_ShiftPCHinAXBLtoLCH |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | ;-------------------------------------------------------------------- |
---|
| 77 | ; AccessDPT_GetLbaSectorCountToBXDXAX |
---|
| 78 | ; Parameters: |
---|
| 79 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 80 | ; Returns: |
---|
| 81 | ; BX:DX:AX: 48-bit sector count |
---|
| 82 | ; Corrupts registers: |
---|
| 83 | ; Nothing |
---|
| 84 | ;-------------------------------------------------------------------- |
---|
| 85 | AccessDPT_GetLbaSectorCountToBXDXAX: |
---|
| 86 | mov ax, [di+DPT.twLbaSectors] |
---|
| 87 | mov dx, [di+DPT.twLbaSectors+2] |
---|
| 88 | mov bx, [di+DPT.twLbaSectors+4] |
---|
[3] | 89 | ret |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | ;-------------------------------------------------------------------- |
---|
[227] | 93 | ; AccessDPT_ShiftPCHinAXBLtoLCH |
---|
[173] | 94 | ; Parameters: |
---|
[227] | 95 | ; AX: P-CHS cylinders (1...16383) |
---|
| 96 | ; BL: P-CHS heads (1...16) |
---|
[173] | 97 | ; Returns: |
---|
[227] | 98 | ; AX: Number of L-CHS cylinders (1...1024) |
---|
| 99 | ; BL: Number of L-CHS heads (1...255) |
---|
[173] | 100 | ; CX: Number of bits shifted |
---|
| 101 | ; Corrupts registers: |
---|
| 102 | ; Nothing |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
[227] | 104 | AccessDPT_ShiftPCHinAXBLtoLCH: |
---|
[173] | 105 | xor cx, cx |
---|
| 106 | .ShiftLoop: |
---|
[227] | 107 | cmp ax, MAX_LCHS_CYLINDERS ; Need to shift? |
---|
[173] | 108 | jbe SHORT .LimitHeadsTo255 ; If not, return |
---|
| 109 | inc cx ; Increment shift count |
---|
[227] | 110 | shr ax, 1 ; Halve cylinders |
---|
| 111 | shl bl, 1 ; Double heads |
---|
[173] | 112 | jmp SHORT .ShiftLoop |
---|
| 113 | .LimitHeadsTo255: ; DOS does not support drives with 256 heads |
---|
[227] | 114 | cmp bl, cl ; Set CF if BL is zero |
---|
| 115 | sbb bl, ch ; If BL=0 then BL=255 |
---|
[173] | 116 | ret |
---|
| 117 | |
---|
[227] | 118 | |
---|
[173] | 119 | ;-------------------------------------------------------------------- |
---|
[3] | 120 | ; Returns pointer to DRVPARAMS for master or slave drive. |
---|
| 121 | ; |
---|
| 122 | ; AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 123 | ; Parameters: |
---|
| 124 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 125 | ; Returns: |
---|
| 126 | ; CS:BX: Ptr to DRVPARAMS |
---|
| 127 | ; Corrupts registers: |
---|
| 128 | ; Nothing |
---|
| 129 | ;-------------------------------------------------------------------- |
---|
| 130 | ALIGN JUMP_ALIGN |
---|
| 131 | AccessDPT_GetPointerToDRVPARAMStoCSBX: |
---|
[150] | 132 | eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS |
---|
| 133 | add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS |
---|
[158] | 134 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE |
---|
[150] | 135 | jz SHORT .ReturnPointerToDRVPARAMS |
---|
| 136 | add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS |
---|
| 137 | .ReturnPointerToDRVPARAMS: |
---|
[3] | 138 | ret |
---|
[200] | 139 | |
---|
| 140 | ;-------------------------------------------------------------------- |
---|
| 141 | ; AccessDPT_GetUnshiftedAddressModeToALZF |
---|
| 142 | ; Parameters: |
---|
| 143 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 144 | ; Returns: |
---|
| 145 | ; AL: Addressing Mode (L-CHS, P-CHS, LBA28, LBA48) |
---|
| 146 | ; unshifted (still shifted where it is in bFlagsLow) |
---|
| 147 | ; ZF: Set based on value in AL |
---|
| 148 | ; Corrupts registers: |
---|
| 149 | ; AL |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
| 151 | ; |
---|
| 152 | ; Converted to a macro since only called in two places, and the call/ret overhead |
---|
| 153 | ; is not worth it for these two instructions (4 bytes total) |
---|
| 154 | ; |
---|
| 155 | %macro AccessDPT_GetUnshiftedAddressModeToALZF 0 |
---|
| 156 | mov al, [di+DPT.bFlagsLow] |
---|
| 157 | and al, MASKL_DPT_ADDRESSING_MODE |
---|
| 158 | %endmacro |
---|