Read BIOS
Satya Prakash Prasad
satyaprakash.prasad at gmail.com
Sun Jun 9 10:24:31 EDT 2013
I am trying to write a code to read BIOS details. Below is the program but
I believe that I am not reading BIOS details. Can anyone please correct me
in my understanding:
Note I found that /proc/ioports gives the I/O ports details like:
[root at ioport]# cat /proc/ioports
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
........and so on..................
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <ctype.h>
#include <string.h>
main(int argc, char *argv[])
{
unsigned char c;
if(argc != 2) {
printf("-1. Invalid args : usage %s start-end address\n",
argv[0]);
exit(-1);
}
char * temp = argv[1];
while(*temp != '\0' && (isxdigit(*temp) || *temp=='-'))
temp++;
char * delim = strchr(argv[1], '-');
if(*temp != '\0' || !delim ) {
printf("-2. Invalid args : usage %s start-end address\n",
argv[0]);
exit(-2);
}
*delim = '\0';
int start = (int)strtol(argv[1], '\0', 16), end =
(int)strtol(delim+1, '\0', 16), index = 0;
if(start < 0 || end <= 0 ) {
printf("-3. Invalid args : usage %s start-end address\n",
argv[0]);
exit(-3);
}
if(iopl(3) == -1) {
printf("-4. Unable to set privilege level\n");
exit(-4);
}
if(ioperm(start, end - start, 1) == -1) {
printf("-5. Unable to set access permission bits\n");
exit(-5);
}
for(index = start ; index <= end ; index ++)
{
c = inb(index);
printf("%X", c);
}
ioperm(start, end - start, 0);
printf("\n");
}
So my program dumps the data in-between the ports assigned for devices:
[root at ioport]# ./a.out 0000-001f
01000007D0FFFFFFFFFFFFF0100000
7D0FFFFFFFFFFFFF
Please let me know if I am in the right path or not and guide me
appropriately.
Regards,
Prakash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130609/acf91120/attachment.html
More information about the Kernelnewbies
mailing list