#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <DOS.h>
#define CMOS_ADDR (0x70) /* address port of CMOS */
#define CMOS_DATA (0x71) /* data port for CMOS */
typedef unsigned long DWORD;
/*
static DWORD inpd(int portnum)
{
static DWORD value ;
asm mov dx,portnum ;
asm lea bx,value ;
#if defined(__BORLANDC__)
__emit__(0x66,0x50, // push EAX
0x66,0xED, // in EAX,DX
0x66,0x89,0x07, // mov [BX],EAX
0x66,0x58) ; // pop EAX
#else
asm push eax
asm in eax,dx ;
asm mov [bx],eax ;
asm pop eax
#endif
return value ;
}
static void outpd(int portnum, DWORD val)
{
static DWORD value = 0 ;
value = val ;
asm mov dx,portnum ;
asm lea bx,value ;
#if defined(__BORLANDC__)
__emit__(0x66,0x50, // push EAX
0x66,0x8B,0x07, // mov EAX,[BX]
0x66,0xEF, // out DX,EAX
0x66,0x58) ; // pop EAX
#else
asm push eax
asm mov eax,[bx] ;
asm out dx,eax ;
asm pop eax
#endif
/*
asm mov dx,0xED;
#if defined(__BORLANDC__)
__emit__(
0x66,0x50,
0x66,0xEF,
0x66,0x58);
#else
asm push eax
asm out dx,eax ;
asm pop eax
#endif
return ;
}
*/
int main( void )
{
DWORD offset,data;
struct CMOS
{
unsigned char current_second;
unsigned char alarm_second;
unsigned char current_minute;
unsigned char alarm_minute;
unsigned char current_hour;
unsigned char alarm_hour;
unsigned char current_day_of_week;
unsigned char current_day;
unsigned char current_month;
unsigned char current_year;
unsigned char status_registers[4];
unsigned char diagnostic_status;
unsigned char shutdown_code;
unsigned char drive_types;
unsigned char reserved_x;
unsigned char disk_1_type;
unsigned char reserved;
unsigned char equipment;
unsigned char lo_mem_base;
unsigned char hi_mem_base;
unsigned char hi_exp_base;
unsigned char lo_exp_base;
unsigned char fdisk_0_type;
unsigned char fdisk_1_type;
unsigned char reserved_2[19];
unsigned char hi_check_sum;
unsigned char lo_check_sum;
unsigned char lo_actual_exp;
unsigned char hi_actual_exp;
unsigned char century;
unsigned char information;
unsigned char reserved3[12];
} cmos;
char *pointer;
pointer = (char *) &cmos;
clrscr();
printf(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
const int size = 128; /* or 64 depending upon your system */
for ( offset=0; offset<size ; offset++ )
{
disable( );
outportb( 0x70, offset );
data = inportb( 0x71 );
*pointer++=data;
enable( );
printf( " 0x%.2X", data );
// *pointer++=data;
}
// clrscr();
//printf(" This program is to get the CMOS information.\n");
//printf(" Some of twhe CMOS information is as follows.\n");
printf(" Current date: %d/%x/%x", cmos.current_month,
cmos.current_day, cmos.century);
if(cmos.current_year<10)
printf("0%d\n",cmos.current_year);
else
printf("%x\n",cmos.current_year);
printf(" Current time: %x:%x:%.2x\n", cmos.current_hour,
cmos.current_minute, cmos.current_second);
//printf("Shutdown type: %d.\n", cmos.shutdown_code);
//printf("Hard disk type %d\n", cmos.fdisk_0_type);
getch();
return(0);
}
/*
void main(void)
{
DWORD Dev;
int Fun;
DWORD Bus;
DWORD Val;
DWORD Address;
DWORD VendorID;
DWORD DeviceID;
clrscr();
// printf(" Bus Dev Fun Val Device \n");
// printf("=== === === ======== ========\n");
for(Bus=0;Bus<5;Bus++)
{
for(Dev=0;Dev<32;Dev++)
{
for(Fun=0;Fun<8;Fun++)
{
Address=0x80000000L+(Bus<<16)+(Dev<<11)+(Fun<<8);
outpd(0x71,Address);
Val=inpd(0x70);
VendorID=Val;
DeviceID=Val>>16;
if(Val!=0xffffffffL)
{
printf(" %02x",Bus);
printf(" %02X",Dev);
printf(" %02d",Fun);
printf(" %4X",VendorID);
printf(" %04X \n",DeviceID);
}
}
}
}
getch();
}
*/
评论1