<div dir="ltr"><div>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:<br><br>Note I found that /proc/ioports gives the I/O ports details like:<br>
<br>[root@ioport]# cat /proc/ioports<br>0000-001f : dma1<br>0020-0021 : pic1<br>0040-0043 : timer0<br>0050-0053 : timer1<br><div>........and so on..................<br></div><div><br></div><br><br>#include <stdio.h><br>
#include <stdlib.h><br>#include <unistd.h><br>#include <sys/io.h><br>#include <ctype.h><br>#include <string.h><br><br>main(int argc, char *argv[])<br>
{<br> unsigned char c;<br> if(argc != 2) {<br> printf("-1. Invalid args : usage %s start-end address\n", argv[0]);<br> exit(-1);<br> }<br> char * temp = argv[1];<br>
while(*temp != '\0' && (isxdigit(*temp) || *temp=='-'))<br> temp++;<br> char * delim = strchr(argv[1], '-');<br> if(*temp != '\0' || !delim ) {<br>
printf("-2. Invalid args : usage %s start-end address\n", argv[0]);<br> exit(-2);<br> }<br> *delim = '\0';<br> int start = (int)strtol(argv[1], '\0', 16), end = (int)strtol(delim+1, '\0', 16), index = 0;<br>
if(start < 0 || end <= 0 ) {<br> printf("-3. Invalid args : usage %s start-end address\n", argv[0]);<br> exit(-3);<br> }<br> if(iopl(3) == -1) {<br> printf("-4. Unable to set privilege level\n");<br>
exit(-4);<br> }<br> if(ioperm(start, end - start, 1) == -1) {<br> printf("-5. Unable to set access permission bits\n");<br> exit(-5);<br> }<br>
for(index = start ; index <= end ; index ++)<br>
{<br> c = inb(index);<br> printf("%X", c);<br> }<br> ioperm(start, end - start, 0);<br> printf("\n");<br>}<br><br><br>So my program dumps the data in-between the ports assigned for devices:<br>
<br>[root@ioport]# ./a.out 0000-001f<br>01000007D0FFFFFFFFFFFFF0100000<div>7D0FFFFFFFFFFFFF<br><br></div>Please let me know if I am in the right path or not and guide me appropriately.<br><br></div>Regards,<br>Prakash<br>
</div>