1 /* biossums.c --- written by Eike W. for the Bochs BIOS */
2 /* adapted for the LGPL'd VGABIOS by vruppert */
7 typedef unsigned char byte;
9 void check( int value, char* message );
11 #define LEN_BIOS_DATA 0x8000
12 #define MAX_OFFSET (LEN_BIOS_DATA - 1)
15 #define BIOS_OFFSET 0x7FFF
17 long chksum_bios_get_offset( byte* data, long offset );
18 byte chksum_bios_calc_value( byte* data, long offset );
19 byte chksum_bios_get_value( byte* data, long offset );
20 void chksum_bios_set_value( byte* data, long offset, byte value );
24 #define PMID_CHKSUM 19
26 long chksum_pmid_get_offset( byte* data, long offset );
27 byte chksum_pmid_calc_value( byte* data, long offset );
28 byte chksum_pmid_get_value( byte* data, long offset );
29 void chksum_pmid_set_value( byte* data, long offset, byte value );
32 byte bios_data[LEN_BIOS_DATA];
35 int main( int argc, char* argv[] ) {
38 long offset, tmp_offset;
39 byte cur_val = 0, new_val = 0;
44 printf( "Error. Need a file-name as an argument.\n" );
48 if(( stream = fopen( argv[1], "rb" )) == NULL ) {
49 printf( "Error opening %s for reading.\n", argv[1] );
52 if( fread( bios_data, 1, LEN_BIOS_DATA, stream ) >= LEN_BIOS_DATA ) {
53 printf( "Error reading max. 32767 Bytes from %s.\n", argv[1] );
61 while( (tmp_offset = chksum_pmid_get_offset( bios_data, offset )) != -1L ) {
63 cur_val = chksum_pmid_get_value( bios_data, offset );
64 new_val = chksum_pmid_calc_value( bios_data, offset );
65 printf( "\nPMID entry at: 0x%4lX\n", offset );
66 printf( "Current checksum: 0x%02X\n", cur_val );
67 printf( "Calculated checksum: 0x%02X ", new_val );
70 if( hits == 1 && cur_val != new_val ) {
71 printf( "Setting checksum." );
72 chksum_pmid_set_value( bios_data, offset, new_val );
75 printf( "Multiple PMID entries! No checksum set." );
83 offset = chksum_bios_get_offset( bios_data, offset );
84 cur_val = chksum_bios_get_value( bios_data, offset );
85 new_val = chksum_bios_calc_value( bios_data, offset );
86 printf( "\nBios checksum at: 0x%4lX\n", offset );
87 printf( "Current checksum: 0x%02X\n", cur_val );
88 printf( "Calculated checksum: 0x%02X ", new_val );
89 if( cur_val != new_val ) {
90 printf( "Setting checksum." );
91 chksum_bios_set_value( bios_data, offset, new_val );
96 if(( stream = fopen( argv[1], "wb" )) == NULL ) {
97 printf( "Error opening %s for writing.\n", argv[1] );
100 if( fwrite( bios_data, 1, LEN_BIOS_DATA, stream ) < LEN_BIOS_DATA ) {
101 printf( "Error writing 32KBytes to %s.\n", argv[1] );
103 exit( EXIT_FAILURE );
107 return( EXIT_SUCCESS );
111 void check( int okay, char* message ) {
114 printf( "\n\nError. %s.\n", message );
115 exit( EXIT_FAILURE );
120 long chksum_bios_get_offset( byte* data, long offset ) {
122 return( BIOS_OFFSET );
126 byte chksum_bios_calc_value( byte* data, long offset ) {
132 for( i = 0; i < MAX_OFFSET; i++ ) {
133 sum = sum + *( data + i );
135 sum = -sum; /* iso ensures -s + s == 0 on unsigned types */
140 byte chksum_bios_get_value( byte* data, long offset ) {
142 return( *( data + BIOS_OFFSET ) );
146 void chksum_bios_set_value( byte* data, long offset, byte value ) {
148 *( data + BIOS_OFFSET ) = value;
152 byte chksum_pmid_calc_value( byte* data, long offset ) {
159 check( offset + len <= MAX_OFFSET, "PMID entry length out of bounds" );
161 for( i = 0; i < len; i++ ) {
162 if( i != PMID_CHKSUM ) {
163 sum = sum + *( data + offset + i );
171 long chksum_pmid_get_offset( byte* data, long offset ) {
175 while( offset + PMID_LEN < MAX_OFFSET ) {
177 if( *( data + offset + 0 ) == 'P' && \
178 *( data + offset + 1 ) == 'M' && \
179 *( data + offset + 2 ) == 'I' && \
180 *( data + offset + 3 ) == 'D' ) {
189 byte chksum_pmid_get_value( byte* data, long offset ) {
191 check( offset + PMID_CHKSUM <= MAX_OFFSET, "PMID checksum out of bounds" );
192 return( *( data + offset + PMID_CHKSUM ) );
196 void chksum_pmid_set_value( byte* data, long offset, byte value ) {
198 check( offset + PMID_CHKSUM <= MAX_OFFSET, "PMID checksum out of bounds" );
199 *( data + offset + PMID_CHKSUM ) = value;