1 | ; Project name : Assembly Library
|
---|
2 | ; Description : Functions for accessing CMOS.
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2018 by XTIDE Universal BIOS Team.
|
---|
7 | ;
|
---|
8 | ; This program is free software; you can redistribute it and/or modify
|
---|
9 | ; it under the terms of the GNU General Public License as published by
|
---|
10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
11 | ; (at your option) any later version.
|
---|
12 | ;
|
---|
13 | ; This program is distributed in the hope that it will be useful,
|
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 |
|
---|
21 | ;--------------------------------------------------------------------
|
---|
22 | ; CMOS_WriteALtoIndexInDL
|
---|
23 | ; Parameters:
|
---|
24 | ; AL: Byte to write
|
---|
25 | ; DL: CMOS address to write to
|
---|
26 | ; Returns:
|
---|
27 | ; Interrupts enabled and NMI disabled
|
---|
28 | ; Corrupts registers:
|
---|
29 | ; Nothing
|
---|
30 | ;--------------------------------------------------------------------
|
---|
31 | CMOS_WriteALtoIndexInDL:
|
---|
32 | push ax
|
---|
33 | call SetDLtoIndexRegister
|
---|
34 | pop ax
|
---|
35 | out CMOS_DATA_REGISTER, al
|
---|
36 | sti
|
---|
37 | ret
|
---|
38 |
|
---|
39 |
|
---|
40 | ;--------------------------------------------------------------------
|
---|
41 | ; CMOS_ReadFromIndexInDLtoAL
|
---|
42 | ; Parameters:
|
---|
43 | ; DL: CMOS address to read from
|
---|
44 | ; Returns:
|
---|
45 | ; AL: Byte read from CMOS
|
---|
46 | ; Interrupts enabled and NMI disabled
|
---|
47 | ; Corrupts registers:
|
---|
48 | ; Nothing
|
---|
49 | ;--------------------------------------------------------------------
|
---|
50 | CMOS_ReadFromIndexInDLtoAL:
|
---|
51 | call SetDLtoIndexRegister
|
---|
52 | in al, CMOS_DATA_REGISTER
|
---|
53 | sti
|
---|
54 | ret
|
---|
55 |
|
---|
56 |
|
---|
57 | ;--------------------------------------------------------------------
|
---|
58 | ; SetDLtoIndexRegister
|
---|
59 | ; Parameters:
|
---|
60 | ; DL: CMOS address to select
|
---|
61 | ; Returns:
|
---|
62 | ; Interrupts disabled and NMI disabled
|
---|
63 | ; Corrupts registers:
|
---|
64 | ; AL
|
---|
65 | ;--------------------------------------------------------------------
|
---|
66 | SetDLtoIndexRegister:
|
---|
67 | mov al, dl
|
---|
68 | or al, FLG_CMOS_INDEX_NMI_DISABLE ; Disable NMI
|
---|
69 | cli
|
---|
70 | out CMOS_INDEX_REGISTER, al
|
---|
71 | ret ; Return works as I/O delay
|
---|
72 |
|
---|
73 |
|
---|
74 | ;--------------------------------------------------------------------
|
---|
75 | ; CMOS_Verify10hTo2Dh
|
---|
76 | ; Parameters:
|
---|
77 | ; Nothing
|
---|
78 | ; Returns:
|
---|
79 | ; ZF: Set if valid checksum
|
---|
80 | ; Interrupts disabled and NMI disabled
|
---|
81 | ; Corrupts registers:
|
---|
82 | ; AX, CX, DX
|
---|
83 | ;--------------------------------------------------------------------
|
---|
84 | CMOS_Verify10hTo2Dh:
|
---|
85 | ; Get checksum WORD from CMOS
|
---|
86 | mov dl, CHECKSUM_OF_BYTES_10hTo2Dh_HIGH
|
---|
87 | call CMOS_ReadFromIndexInDLtoAL
|
---|
88 | xchg ah, al
|
---|
89 | inc dx ; CHECKSUM_OF_BYTES_10hTo2Dh_LOW
|
---|
90 | call CMOS_ReadFromIndexInDLtoAL
|
---|
91 | push ax ; Store checksum word
|
---|
92 |
|
---|
93 | ; Verify checksum
|
---|
94 | call GetSumOfBytes10hto2DhtoCX
|
---|
95 | pop ax
|
---|
96 | cmp ax, cx ; ZF set if checksum verified
|
---|
97 | ret
|
---|
98 |
|
---|
99 |
|
---|
100 | ;--------------------------------------------------------------------
|
---|
101 | ; CMOS_StoreNewChecksumFor10hto2Dh
|
---|
102 | ; Parameters:
|
---|
103 | ; Nothing
|
---|
104 | ; Returns:
|
---|
105 | ; Interrupts disabled and NMI disabled
|
---|
106 | ; Corrupts registers:
|
---|
107 | ; AX, CX, DX
|
---|
108 | ;--------------------------------------------------------------------
|
---|
109 | CMOS_StoreNewChecksumFor10hto2Dh:
|
---|
110 | call GetSumOfBytes10hto2DhtoCX
|
---|
111 |
|
---|
112 | ; Write it to CMOS
|
---|
113 | xchg ax, cx
|
---|
114 | mov dl, CHECKSUM_OF_BYTES_10hTo2Dh_LOW
|
---|
115 | call CMOS_WriteALtoIndexInDL
|
---|
116 | xchg al, ah
|
---|
117 | dec dx ; CHECKSUM_OF_BYTES_10hTo2Dh_HIGH
|
---|
118 | jmp SHORT CMOS_WriteALtoIndexInDL
|
---|
119 |
|
---|
120 |
|
---|
121 | ;--------------------------------------------------------------------
|
---|
122 | ; GetSumOfBytes10hto2DhtoCX
|
---|
123 | ; Parameters:
|
---|
124 | ; Nothing
|
---|
125 | ; Returns:
|
---|
126 | ; CX: Sum of CMOS bytes 10h to 2Dh
|
---|
127 | ; Interrupts disabled and NMI disabled
|
---|
128 | ; Corrupts registers:
|
---|
129 | ; AX, DX
|
---|
130 | ;--------------------------------------------------------------------
|
---|
131 | GetSumOfBytes10hto2DhtoCX:
|
---|
132 | xor cx, cx ; Sum
|
---|
133 | mov dx, 10h ; First index
|
---|
134 |
|
---|
135 | .AddNextByte:
|
---|
136 | call CMOS_ReadFromIndexInDLtoAL
|
---|
137 | xor ah, ah
|
---|
138 | add cx, ax
|
---|
139 | inc dx
|
---|
140 | cmp dl, 2Dh ; Last index
|
---|
141 | jbe .AddNextByte
|
---|
142 | ret
|
---|