📄 biosdecode.c
字号:
}
static int pir_decode(const u8 *p, size_t len)
{
int i;
if (len < 32 || !checksum(p, WORD(p + 6)))
return 0;
printf("PCI Interrupt Routing %u.%u present.\n",
p[5], p[4]);
printf("\tRouter ID: %02x:%02x.%1x\n",
p[8], p[9]>>3, p[9] & 0x07);
printf("\tExclusive IRQs:");
pir_irqs(WORD(p + 10));
printf("\n");
if (DWORD(p + 12) != 0)
printf("\tCompatible Router: %04x:%04x\n",
WORD(p + 12), WORD(p + 14));
if (DWORD(p + 16) != 0)
printf("\tMiniport Data: 0x%08X\n",
DWORD(p + 16));
for (i = 1; i <= (WORD(p + 6) - 32) / 16; i++)
{
printf("\tSlot Entry %u: ID %02x:%02x,",
i, p[(i + 1) * 16], p[(i + 1) * 16 + 1] >> 3);
pir_slot_number(p[(i + 1) * 16 + 14]);
printf("\n");
/* printf("\tSlot Entry %u\n", i);
printf("\t\tID: %02x:%02x\n",
p[(i + 1) * 16], p[(i + 1) * 16 + 1] >> 3);
printf("\t\tLink Value for INTA#: %u\n",
p[(i + 1) * 16 + 2]);
printf("\t\tIRQ Bitmap for INTA#:");
pir_irqs(WORD(p + (i + 1) * 16 + 3));
printf("\n");
printf("\t\tLink Value for INTB#: %u\n",
p[(i + 1) * 16 + 5]);
printf("\t\tIRQ Bitmap for INTB#:");
pir_irqs(WORD(p + (i + 1) * 16 + 6));
printf("\n");
printf("\t\tLink Value for INTC#: %u\n",
p[(i + 1) * 16 + 8]);
printf("\t\tIRQ Bitmap for INTC#:");
pir_irqs(WORD(p + (i + 1) * 16 + 9));
printf("\n");
printf("\t\tLink Value for INTD#: %u\n",
p[(i + 1) * 16 + 11]);
printf("\t\tIRQ Bitmap for INTD#:");
pir_irqs(WORD(p + (i + 1) * 16 + 12));
printf("\n");
printf("\t\tSlot Number:");
pir_slot_number(p[(i + 1) * 16 + 14]);
printf("\n");*/
}
return 1;
}
/*
* Compaq-specific entries
*/
static size_t compaq_length(const u8 *p)
{
return p[4] * 10 + 5;
}
static int compaq_decode(const u8 *p, size_t len)
{
unsigned int i;
(void) len;
printf("Compaq-specific entries present.\n");
/* integrity checking (lack of checksum) */
for (i = 0; i < p[4]; i++)
{
/*
* We do not check for truncated entries, because the length
* was computed from the number of records in compaq_length
* right above, so it can't be wrong.
*/
if (p[5 + i * 10] != '$'
|| !(p[6 + i * 10] >= 'A' && p[6 + i * 10] <= 'Z')
|| !(p[7 + i * 10] >= 'A' && p[7 + i * 10] <= 'Z')
|| !(p[8 + i * 10] >= 'A' && p[8 + i * 10] <= 'Z'))
{
printf("\t Abnormal entry! Please report. [%02X %02X "
"%02X %02X]\n", p[5 + i * 10], p[6 + i * 10],
p[7 + i * 10], p[8 + i * 10]);
return 0;
}
}
for (i = 0; i < p[4]; i++)
{
printf("\tEntry %u: %c%c%c%c at 0x%08X (%u bytes)\n",
i + 1, p[5 + i * 10], p[6 + i * 10], p[7 + i * 10],
p[8 + i * 10], DWORD(p + 9 + i * 10),
WORD(p + 13 + i * 10));
}
return 1;
}
/*
* VPD (vital product data, IBM-specific)
*/
static void vpd_print_entry(const char *name, const u8 *p, size_t len)
{
size_t i;
printf("\t%s: ", name);
for (i = 0; i < len; i++)
if (p[i] >= 32 && p[i] < 127)
printf("%c", p[i]);
printf("\n");
}
static size_t vpd_length(const u8 *p)
{
return p[5];
}
static int vpd_decode(const u8 *p, size_t len)
{
if (len < 0x30)
return 0;
/* XSeries have longer records. */
if (!(len >= 0x45 && checksum(p, len))
/* Some Netvista seem to work with this. */
&& !checksum(p, 0x30)
/* The Thinkpad checksum does *not* include the first 13 bytes. */
&& !checksum(p + 0x0D, 0x30 - 0x0D))
return 0;
printf("VPD present.\n");
vpd_print_entry("BIOS Build ID", p + 0x0D, 9);
vpd_print_entry("Box Serial Number", p + 0x16, 7);
vpd_print_entry("Motherboard Serial Number", p + 0x1D, 11);
vpd_print_entry("Machine Type/Model", p + 0x28, 7);
if (len < 0x45)
return 1;
vpd_print_entry("BIOS Release Date", p + 0x30, 8);
return 1;
}
/*
* Fujitsu application panel
*/
static size_t fjkeyinf_length(const u8 *p)
{
(void) p;
/*
* We don't know at this point, it's somewhere between 12 and 32.
* So we return the max, it shouldn't hurt.
*/
return 32;
}
static int fjkeyinf_decode(const u8 *p, size_t len)
{
int i;
(void) len;
printf("Fujitsu application panel present.\n");
for (i = 0; i < 6; i++)
{
if (*(p + 8 + i * 4) == 0)
return 1;
printf("\tDevice %d: type %u, chip %u", i + 1,
*(p + 8 + i * 4), *(p + 8 + i * 4 + 2));
if (*(p+8+i*4+1)) /* Access method */
printf(", SMBus address 0x%x",
*(p + 8 + i * 4 + 3) >> 1);
printf("\n");
}
return 1;
}
/*
* Main
*/
static struct bios_entry bios_entries[] = {
{ "_SM_", 0, 0xF0000, 0xFFFFF, smbios_length, smbios_decode },
{ "_DMI_", 0, 0xF0000, 0xFFFFF, dmi_length, dmi_decode },
{ "_SYSID_", 0, 0xE0000, 0xFFFFF, sysid_length, sysid_decode },
{ "$PnP", 0, 0xF0000, 0xFFFFF, pnp_length, pnp_decode },
{ "RSD PTR ", 0, 0xE0000, 0xFFFFF, acpi_length, acpi_decode },
{ "$SNY", 0, 0xE0000, 0xFFFFF, sony_length, sony_decode },
{ "_32_", 0, 0xE0000, 0xFFFFF, bios32_length, bios32_decode },
{ "$PIR", 0, 0xF0000, 0xFFFFF, pir_length, pir_decode },
{ "32OS", 0, 0xE0000, 0xFFFFF, compaq_length, compaq_decode },
{ "\252\125VPD", 0, 0xF0000, 0xFFFFF, vpd_length, vpd_decode },
{ "FJKEYINF", 0, 0xF0000, 0xFFFFF, fjkeyinf_length, fjkeyinf_decode },
{ NULL, 0, 0, 0, NULL, NULL }
};
/* Believe it or not, this is significantly faster than memcmp and strncmp */
static int anchor_match(const struct bios_entry *entry, const char *p)
{
size_t i;
for (i = 0; i < entry->anchor_len; i++)
if (entry->anchor[i] != p[i])
return 0;
return 1;
}
/* Return -1 on error, 0 on success */
static int parse_command_line(int argc, char * const argv[])
{
#if 0
int option;
const char *optstring = "d:hV";
struct option longopts[] = {
{ "dev-mem", required_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ 0, 0, 0, 0 }
};
while ((option = getopt_long(argc, argv, optstring, longopts, NULL)) != -1)
switch (option)
{
case 'd':
opt.devmem = optarg;
break;
case 'h':
opt.flags |= FLAG_HELP;
break;
case 'V':
opt.flags |= FLAG_VERSION;
break;
case '?':
return -1;
}
#endif
return 0;
}
static void print_help(void)
{
static const char *help =
"Usage: biosdecode [OPTIONS]\n"
"Options are:\n"
" -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
" -h, --help Display this help text and exit\n"
" -V, --version Display the version and exit\n";
printf("%s", help);
}
int main(int argc, char * const argv[])
{
u8 *buf;
off_t fp;
int i;
if (sizeof(u8) != 1 || sizeof(u16) != 2 || sizeof(u32) != 4)
{
fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
exit(255);
}
/* Set default option values */
opt.devmem = DEFAULT_MEM_DEV;
opt.flags = 0;
if (parse_command_line(argc, argv) < 0)
exit(2);
if (opt.flags & FLAG_HELP)
{
print_help();
return 0;
}
if (opt.flags & FLAG_VERSION)
{
printf("%s\n", VERSION);
return 0;
}
printf("# biosdecode %s\n", VERSION);
if ((buf = mem_chunk(0xE0000, 0x20000, opt.devmem)) == NULL)
exit(1);
/* Compute anchor lengths once and for all */
for (i = 0; bios_entries[i].anchor != NULL; i++)
bios_entries[i].anchor_len = strlen(bios_entries[i].anchor);
for (fp = 0xE0000; fp <= 0xFFFF0; fp += 16)
{
u8 *p = buf + fp - 0xE0000;
for (i = 0; bios_entries[i].anchor != NULL; i++)
{
if (anchor_match(&bios_entries[i], (char *)p)
&& fp >= bios_entries[i].low_address
&& fp < bios_entries[i].high_address)
{
off_t len = bios_entries[i].length(p);
if (fp + len - 1 <= bios_entries[i].high_address)
{
if (bios_entries[i].decode(p, len))
{
fp += (((len - 1) >> 4) << 4);
break;
}
}
}
}
}
free(buf);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -