📄 biosdecode.c
字号:
/*
* BIOS Decode
*
* Copyright (C) 2000-2002 Alan Cox <alan@redhat.com>
* Copyright (C) 2002-2007 Jean Delvare <khali@linux-fr.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For the avoidance of doubt the "preferred form" of this code is one which
* is in an open unpatent encumbered format. Where cryptographic key signing
* forms part of the process of creating an executable the information
* including keys needed to generate an equivalently functional executable
* are deemed to be part of the source code.
*
* References:
* - DMTF "System Management BIOS Reference Specification"
* Version 2.3.4
* http://www.dmtf.org/standards/smbios
* - Intel "Preboot Execution Environment (PXE) Specification"
* Version 2.1
* http://www.intel.com/labs/manage/wfm/wfmspecs.htm
* - ACPI "Advanced Configuration and Power Interface Specification"
* Revision 2.0
* http://www.acpi.info/spec20.htm
* - Phoenix "BIOS32 Service Directory"
* Revision 0.4
* http://www.phoenix.com/en/support/white+papers-specs/
* - Microsoft "Plug and Play BIOS Specification"
* Version 1.0A
* http://www.microsoft.com/hwdev/tech/PnP/
* - Microsoft "PCI IRQ Routing Table Specification"
* Version 1.0
* http://www.microsoft.com/hwdev/archive/BUSBIOS/pciirq.asp
* - Compaq "Technical Reference Guide for Compaq Deskpro 4000 and 6000"
* First Edition
* http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html
* - IBM "Using the BIOS Build ID to identify Thinkpad systems"
* Revision 2005-09-19
* http://www-307.ibm.com/pc/support/site.wss/MIGR-45120.html
* - Fujitsu application panel technical details
* As of July 23rd, 2004
* http://apanel.sourceforge.net/tech.php
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "getopt.h"
#include "version.h"
#include "config.h"
#include "types.h"
#include "util.h"
/* Options are global */
struct opt
{
const char *devmem;
unsigned int flags;
};
static struct opt opt;
#define FLAG_VERSION (1 << 0)
#define FLAG_HELP (1 << 1)
struct bios_entry {
const char *anchor;
size_t anchor_len; /* computed */
off_t low_address;
off_t high_address;
size_t (*length)(const u8 *);
int (*decode)(const u8*, size_t);
};
/*
* SMBIOS
*/
static size_t smbios_length(const u8 *p)
{
return p[0x05] == 0x1E ? 0x1F : p[0x05];
}
static int smbios_decode(const u8 *p, size_t len)
{
if (len < 0x1F || !checksum(p, p[0x05])
|| memcmp("_DMI_", p + 0x10, 5) != 0
|| !checksum(p + 0x10, 0x0F))
return 0;
printf("SMBIOS %u.%u present.\n",
p[0x06], p[0x07]);
printf("\tStructure Table Length: %u bytes\n",
WORD(p+0x16));
printf("\tStructure Table Address: 0x%08X\n",
DWORD(p + 0x18));
printf("\tNumber Of Structures: %u\n",
WORD(p + 0x1C));
printf("\tMaximum Structure Size: %u bytes\n",
WORD(p + 0x08));
return 1;
}
static size_t dmi_length(const u8 *p)
{
(void) p;
return 0x0F;
}
static int dmi_decode(const u8 *p, size_t len)
{
if (len < 0x0F || !checksum(p, len))
return 0;
printf("Legacy DMI %u.%u present.\n",
p[0x0E]>>4, p[0x0E] & 0x0F);
printf("\tStructure Table Length: %u bytes\n",
WORD(p + 0x06));
printf("\tStructure Table Address: 0x%08X\n",
DWORD(p + 0x08));
printf("\tNumber Of Structures: %u\n",
WORD(p + 0x0C));
return 1;
}
/*
* SYSID
*/
static size_t sysid_length(const u8 *p)
{
return WORD(p + 0x08);
}
static int sysid_decode(const u8 *p, size_t len)
{
if (len < 0x11 || !checksum(p, WORD(p + 0x08)))
return 0;
printf("SYSID present.\n");
printf("\tRevision: %u\n",
p[0x10]);
printf("\tStructure Table Address: 0x%08X\n",
DWORD(p + 0x0A));
printf("\tNumber Of Structures: %u\n",
WORD(p + 0x0E));
return 1;
}
/*
* PnP
*/
static size_t pnp_length(const u8 *p)
{
return p[0x05];
}
static const char *pnp_event_notification(u8 code)
{
static const char *notification[] = {
"Not Supported", /* 0x0 */
"Polling",
"Asynchronous",
"Unknown" /* 0x3 */
};
return notification[code];
}
static int pnp_decode(const u8 *p, size_t len)
{
if (len < 0x21 || !checksum(p, p[0x05]))
return 0;
printf("PNP BIOS %u.%u present.\n",
p[0x04] >> 4, p[0x04] & 0x0F);
printf("\tEvent Notification: %s\n",
pnp_event_notification(WORD(p + 0x06) & 0x03));
if ((WORD(p + 0x06) & 0x03) == 0x01)
printf("\tEvent Notification Flag Address: 0x%08X\n",
DWORD(p + 0x09));
printf("\tReal Mode 16-bit Code Address: %04X:%04X\n",
WORD(p + 0x0F), WORD(p + 0x0D));
printf("\tReal Mode 16-bit Data Address: %04X:0000\n",
WORD(p + 0x1B));
printf("\t16-bit Protected Mode Code Address: 0x%08X\n",
DWORD(p + 0x13) + WORD(p + 0x11));
printf("\t16-bit Protected Mode Data Address: 0x%08X\n",
DWORD(p + 0x1D));
if (DWORD(p + 0x17) != 0)
printf("\tOEM Device Identifier: %c%c%c%02X%02X\n",
0x40 + ((p[0x17] >> 2) & 0x1F),
0x40 + ((p[0x17] & 0x03) << 3) + ((p[0x18] >> 5) & 0x07),
0x40 + (p[0x18] & 0x1F), p[0x19], p[0x20]);
return 1;
}
/*
* ACPI
*/
static size_t acpi_length(const u8 *p)
{
return p[15] == 2 ? 36 : 20;
}
static const char *acpi_revision(u8 code)
{
switch (code)
{
case 0:
return " 1.0";
case 2:
return " 2.0";
default:
return "";
}
}
static int acpi_decode(const u8 *p, size_t len)
{
if (len < 20 || !checksum(p, 20))
return 0;
printf("ACPI%s present.\n",
acpi_revision(p[15]));
printf("\tOEM Identifier: %c%c%c%c%c%c\n",
p[9], p[10], p[11], p[12], p[13], p[14]);
printf("\tRSD Table 32-bit Address: 0x%08X\n",
DWORD(p + 16));
if (len < 36)
return 1;
if (DWORD(p + 20) > len || !checksum(p, DWORD(p + 20)))
return 0;
if (DWORD(p + 20) < 32) return 1;
printf("\tXSD Table 64-bit Address: 0x%08X%08X\n",
QWORD(p + 24).h, QWORD(p + 24).l);
return 1;
}
/*
* Sony
*/
static size_t sony_length(const u8 *p)
{
return p[0x05];
}
static int sony_decode(const u8 *p, size_t len)
{
if (!checksum(p, len))
return 0;
printf("Sony system detected.\n");
return 1;
}
/*
* BIOS32
*/
static size_t bios32_length(const u8 *p)
{
return p[0x09] << 4;
}
static int bios32_decode(const u8 *p, size_t len)
{
if (len < 0x0A || !checksum(p, p[0x09] << 4))
return 0;
printf("BIOS32 Service Directory present.\n");
printf("\tRevision: %u\n",
p[0x08]);
printf("\tCalling Interface Address: 0x%08X\n",
DWORD(p + 0x04));
return 1;
}
/*
* PIR
*/
static void pir_irqs(u16 code)
{
if (code == 0)
printf(" None");
else
{
u8 i;
for (i = 0; i < 16; i++)
if (code & (1 << i))
printf(" %u", i);
}
}
static void pir_slot_number(u8 code)
{
if (code == 0)
printf(" on-board");
else
printf(" slot number %u", code);
}
static size_t pir_length(const u8 *p)
{
return WORD(p + 6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -