1 /* biossums.c --- written by Eike W. for the Bochs BIOS */
2 /* adapted for the LGPL'd VGABIOS by vruppert */
4 /* This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 typedef unsigned char byte
;
23 void check( int value
, char* message
);
25 #define LEN_BIOS_DATA 0x8000
26 #define MAX_OFFSET (LEN_BIOS_DATA - 1)
29 #define BIOS_OFFSET 0x7FFF
31 long chksum_bios_get_offset( byte
* data
, long offset
);
32 byte
chksum_bios_calc_value( byte
* data
, long offset
);
33 byte
chksum_bios_get_value( byte
* data
, long offset
);
34 void chksum_bios_set_value( byte
* data
, long offset
, byte value
);
38 #define PMID_CHKSUM 19
40 long chksum_pmid_get_offset( byte
* data
, long offset
);
41 byte
chksum_pmid_calc_value( byte
* data
, long offset
);
42 byte
chksum_pmid_get_value( byte
* data
, long offset
);
43 void chksum_pmid_set_value( byte
* data
, long offset
, byte value
);
46 byte bios_data
[LEN_BIOS_DATA
];
49 int main( int argc
, char* argv
[] ) {
52 long offset
, tmp_offset
;
53 byte cur_val
= 0, new_val
= 0;
58 printf( "Error. Need a file-name as an argument.\n" );
62 if(( stream
= fopen( argv
[1], "rb" )) == NULL
) {
63 printf( "Error opening %s for reading.\n", argv
[1] );
66 if( fread( bios_data
, 1, LEN_BIOS_DATA
, stream
) >= LEN_BIOS_DATA
) {
67 printf( "Error reading max. 32767 Bytes from %s.\n", argv
[1] );
75 while( (tmp_offset
= chksum_pmid_get_offset( bios_data
, offset
)) != -1L ) {
77 cur_val
= chksum_pmid_get_value( bios_data
, offset
);
78 new_val
= chksum_pmid_calc_value( bios_data
, offset
);
79 printf( "\nPMID entry at: 0x%4lX\n", offset
);
80 printf( "Current checksum: 0x%02X\n", cur_val
);
81 printf( "Calculated checksum: 0x%02X ", new_val
);
84 if( hits
== 1 && cur_val
!= new_val
) {
85 printf( "Setting checksum." );
86 chksum_pmid_set_value( bios_data
, offset
, new_val
);
89 printf( "Multiple PMID entries! No checksum set." );
97 offset
= chksum_bios_get_offset( bios_data
, offset
);
98 cur_val
= chksum_bios_get_value( bios_data
, offset
);
99 new_val
= chksum_bios_calc_value( bios_data
, offset
);
100 printf( "\nBios checksum at: 0x%4lX\n", offset
);
101 printf( "Current checksum: 0x%02X\n", cur_val
);
102 printf( "Calculated checksum: 0x%02X ", new_val
);
103 if( cur_val
!= new_val
) {
104 printf( "Setting checksum." );
105 chksum_bios_set_value( bios_data
, offset
, new_val
);
110 if(( stream
= fopen( argv
[1], "wb" )) == NULL
) {
111 printf( "Error opening %s for writing.\n", argv
[1] );
112 exit( EXIT_FAILURE
);
114 if( fwrite( bios_data
, 1, LEN_BIOS_DATA
, stream
) < LEN_BIOS_DATA
) {
115 printf( "Error writing 32KBytes to %s.\n", argv
[1] );
117 exit( EXIT_FAILURE
);
121 return( EXIT_SUCCESS
);
125 void check( int okay
, char* message
) {
128 printf( "\n\nError. %s.\n", message
);
129 exit( EXIT_FAILURE
);
134 long chksum_bios_get_offset( byte
* data
, long offset
) {
136 return( BIOS_OFFSET
);
140 byte
chksum_bios_calc_value( byte
* data
, long offset
) {
146 for( i
= 0; i
< MAX_OFFSET
; i
++ ) {
147 sum
= sum
+ *( data
+ i
);
149 sum
= -sum
; /* iso ensures -s + s == 0 on unsigned types */
154 byte
chksum_bios_get_value( byte
* data
, long offset
) {
156 return( *( data
+ BIOS_OFFSET
) );
160 void chksum_bios_set_value( byte
* data
, long offset
, byte value
) {
162 *( data
+ BIOS_OFFSET
) = value
;
166 byte
chksum_pmid_calc_value( byte
* data
, long offset
) {
173 check( offset
+ len
<= MAX_OFFSET
, "PMID entry length out of bounds" );
175 for( i
= 0; i
< len
; i
++ ) {
176 if( i
!= PMID_CHKSUM
) {
177 sum
= sum
+ *( data
+ offset
+ i
);
185 long chksum_pmid_get_offset( byte
* data
, long offset
) {
189 while( offset
+ PMID_LEN
< MAX_OFFSET
) {
191 if( *( data
+ offset
+ 0 ) == 'P' && \
192 *( data
+ offset
+ 1 ) == 'M' && \
193 *( data
+ offset
+ 2 ) == 'I' && \
194 *( data
+ offset
+ 3 ) == 'D' ) {
203 byte
chksum_pmid_get_value( byte
* data
, long offset
) {
205 check( offset
+ PMID_CHKSUM
<= MAX_OFFSET
, "PMID checksum out of bounds" );
206 return( *( data
+ offset
+ PMID_CHKSUM
) );
210 void chksum_pmid_set_value( byte
* data
, long offset
, byte value
) {
212 check( offset
+ PMID_CHKSUM
<= MAX_OFFSET
, "PMID checksum out of bounds" );
213 *( data
+ offset
+ PMID_CHKSUM
) = value
;