• T0_806675
  • 7.6KB
  • rar
  • 0
  • VIP专享
  • 0
  • 2022-05-01 09:52
  • CMOS校验和算法
  • Debug
  • cmos.plg
  • cmos.opt
  • cmos.cpp
  • cmos.dsw
  • cmos.ncb
  • cmos.dsp
// Filename CMOS.CPP // (C) Copyright CAD Center, HUST. All Rights Reserved // Compile with SMALL model Tel:7543973 /************************************************************ function : Show your CMOS programmer: Jesse date : 1994 11 11 Modify : 1996 3 2 ************************************************************/ #ifndef __SMALL__ #error complile with small model #endif #include<stdio.h> #include<conio.h> #include<bios.h> #include<dos.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #define INDEX 0x70 #define VALUE 0x71 #define BYTE unsigned char #define WORD unsigned int void help(); void display(); void wbyte(int port, unsigned value); BYTE rbyte(int port); void cal_checksum( int checklen); int write_mrsum(); int write_amisum(); void change_bios(int port, int value); int test_biostype(void); struct { char *name; int (*sum) () ; } biosdesc[]={ "AMMMMI", write_amisum, "MR BIOS", write_mrsum, "DECpc", NULL, "Phoenix", NULL } ; #define cprintf printf void help(void) { cprintf("\nCMOS Untity (Version 1.00) Mar 1996 Tel:7543973\n"); cprintf("(C) Copyright Jesse CAD Center, HUST. All Rights Reserve \r\n\n"); cprintf(" can deal with AMI,MR,Phoenix bios,not include AMI 1994 version! n"); cprintf("Usage : CMOS --display cmos value directly\n"); cprintf(" or CMOS [port newvalue] --change cmos unit\n"); cprintf("\r\n"); return; } int biostype=0; /*main function of cmos*/ void main(int argc, char *argv[]) { int port, value; clrscr(); help(); biostype=test_biostype(); if(biostype==0 ) { printf("Your Computer is not AMI/MR/Phoenix BIOS!\n"); return; } printf("BIOS type: %s\n",biosdesc[biostype-1].name ); if ( argc==2 ) return ; if (argc>=3) { sscanf(argv[1],"%x",&port); sscanf(argv[2],"%x",&value); change_bios(port,value); } display(); } /* print CMOS element */ void display() { int i; for (i=0x0 ;i<0x10 ;i++) printf("%-5x",i); for (i=0x10 ;i<0x80 ;i++) printf("%-5x",rbyte(i)); printf("\n"); } BYTE rbyte(int port) { outp(INDEX,port); outp(0xed, port); return inp(VALUE); } void wbyte(int port, unsigned value) { disable(); outp(INDEX,port); outp(0xed, port); outp(VALUE, value&0xff); enable(); } void outw(int port, unsigned value) { wbyte(port, value&0xff); wbyte(port+1, value>>8); } WORD inw(int port) { WORD value; outp(INDEX,port); outp(0xed, port); value=inp(VALUE); outp(INDEX,port+1); outp(0xed, port+1); value= value+( inp(VALUE)<<8 ); return value; } /*cal checksum of ami bios, From addr 34 to 3d and 40 to ...,save to 3e*/ int write_amisum() { { WORD i=0,num; WORD sum=0; BYTE movsi[]={0xbe,0x40,0xe0,0};//code of MOV si, e040 BYTE far *pkey=(BYTE far*)movsi; WORD far *p; BYTE far *ROM=(BYTE far*)MK_FP(0xf000,0); for(i=0;i<0xa;i++) sum+=rbyte( 0x34+i); for (i=0;i<0xfff0;i++) //search 'MOV SI,E040' if (_fstrncmp(ROM+i,pkey,3)==0) break; if (i<0xfff0) { ROM+=i; p=(WORD far*)ROM+3; p=(WORD far*)MK_FP(0xf000, *p); num= *p; p=(WORD far*)ROM+5; num=num- *p; for(i=0;i sum+=rbyte(0x40+i); } wbyte(0x3f, sum&0xff); wbyte(0x3e, sum>>8); return sum; } //calculate checksum of mrbios, part addr of 10 to 3e, save to 3f int write_mrsum() { BYTE mask[6]={ 0x7f,0xf8,0x3f,0xff,0xf8,0x0a } ; BYTE v,cx; register unsigned char sum=0x1f; int i,addr; addr=0x10; for (i=5;i>=0;i--) { v=mask[i]; for (cx=0;cx<8;cx++) { { if (v&1) sum+= rbyte(addr); addr++; v >>=1; } } sum=sum&0x1f; wbyte(0x3f,sum); return sum; } /*cal checksum of any bios , from addr 10 ot 2d ,save to 2e */ void cal_checksum( int checklen) { WORD value, sum =0,i; for (i=0x10 ;i sum+= rbyte(i); value=inw(0x3e); printf("\nSUM (2e)=%-5x (3e)=%-5x\n", sum,value); wbyte(checklen+1, sum&0xff); wbyte(checklen, sum>>8); } //change bios setup void change_bios( int port,int value) { wbyte(port, value); if (biosdesc[biostype-1].sum ) (*biosdesc[biostype-1].sum)(); cal_checksum(0x2e); } /* Test your MotherBoard BIOS type */ int test_biostype(void) { char far *ROM; WORD i,type; ROM = (char far *) MK_FP(0xf000, 0); for(i=0; i<0xfff0; i++) { for(type=0 ;type if(! _fstrncmp(ROM+i, biosdesc[type].name, 5)) return type+1; } return 0; }