diff options
Diffstat (limited to 'usr.sbin/acpi/acpidb')
| -rw-r--r-- | usr.sbin/acpi/acpidb/Makefile | 94 | ||||
| -rw-r--r-- | usr.sbin/acpi/acpidb/Makefile.depend | 16 | ||||
| -rw-r--r-- | usr.sbin/acpi/acpidb/acpidb.8 | 165 | ||||
| -rw-r--r-- | usr.sbin/acpi/acpidb/acpidb.c | 540 | 
4 files changed, 815 insertions, 0 deletions
diff --git a/usr.sbin/acpi/acpidb/Makefile b/usr.sbin/acpi/acpidb/Makefile new file mode 100644 index 000000000000..377846a016ae --- /dev/null +++ b/usr.sbin/acpi/acpidb/Makefile @@ -0,0 +1,94 @@ +PROG=	acpidb +SRCS=	acpidb.c + +# common +SRCS+=	acfileio.c acgetline.c ahids.c ahuuids.c cmfsize.c + +# components/debugger +SRCS+=	dbcmds.c dbconvert.c dbdisply.c dbexec.c dbfileio.c	\ +	dbhistry.c dbinput.c dbmethod.c dbnames.c dbobject.c	\ +	dbstats.c dbtest.c dbutils.c dbxface.c + +# components/disassembler +SRCS+=	dmbuffer.c dmcstyle.c dmdeferred.c dmnames.c dmopcode.c	\ +	dmresrc.c dmresrcl.c dmresrcl2.c dmresrcs.c dmutils.c	\ +	dmwalk.c + +# components/dispatcher +SRCS+=	dsargs.c dscontrol.c dsdebug.c dsfield.c dsinit.c	\ +	dsmethod.c dsmthdat.c dsobject.c dsopcode.c dspkginit.c	\ +	dsutils.c dswexec.c dswload.c dswload2.c dswscope.c	\ +	dswstate.c + +# components/events +SRCS+=	evevent.c evglock.c evgpe.c evgpeblk.c evgpeinit.c	\ +	evgpeutil.c evhandler.c evmisc.c evregion.c evrgnini.c	\ +	evsci.c evxface.c evxfevnt.c evxfregn.c + +# components/executer +SRCS+=	exconcat.c exconfig.c exconvrt.c excreate.c exdebug.c	\ +	exdump.c exfield.c exfldio.c exmisc.c exmutex.c		\ +	exnames.c exoparg1.c exoparg2.c exoparg3.c exoparg6.c	\ +	exprep.c exregion.c exresnte.c exresolv.c exresop.c	\ +	exserial.c exstore.c exstoren.c exstorob.c exsystem.c	\ +	extrace.c exutils.c + +# components/hardware +SRCS+=	hwacpi.c hwesleep.c hwgpe.c hwpci.c hwregs.c hwsleep.c	\ +	hwvalid.c hwxface.c hwxfsleep.c + +# components/namespace +SRCS+=	nsaccess.c nsalloc.c nsarguments.c nsconvert.c nsdump.c	\ +	nseval.c nsinit.c nsload.c nsnames.c nsobject.c		\ +	nsparse.c nspredef.c nsprepkg.c nsrepair.c nsrepair2.c	\ +	nssearch.c nsutils.c nswalk.c nsxfeval.c nsxfname.c	\ +	nsxfobj.c + +# components/parser +SRCS+=	psargs.c psloop.c psobject.c psopcode.c psopinfo.c	\ +	psparse.c psscope.c pstree.c psutils.c pswalk.c		\ +	psxface.c + +# components/resources +SRCS+=	rsaddr.c rscalc.c rscreate.c rsdump.c rsdumpinfo.c	\ +	rsinfo.c rsio.c rsirq.c rslist.c rsmemory.c rsmisc.c	\ +	rsserial.c rsutils.c rsxface.c + +# components/tables +SRCS+=	tbdata.c tbfadt.c tbfind.c tbinstal.c tbprint.c		\ +	tbutils.c tbxface.c tbxfload.c + +# components/utilities +SRCS+=	utaddress.c utalloc.c utascii.c utbuffer.c utcache.c	\ +	utcksum.c utcopy.c utdebug.c utdecode.c utdelete.c	\ +	uterror.c uteval.c utexcep.c utglobal.c uthex.c utids.c	\ +	utinit.c utlock.c utmath.c utmisc.c utmutex.c		\ +	utnonansi.c utobject.c utosi.c utownerid.c utpredef.c	\ +	utresdecode.c utresrc.c utstate.c utstring.c		\ +	utstrsuppt.c utstrtoul64.c uttrack.c utuuid.c utxface.c	\ +	utxferror.c utxfinit.c + +# os_specific/service_layers +SRCS+=	osgendbg.c osunixxf.c + +MAN=	acpidb.8 +WARNS?=	3 + +CFLAGS+= -DACPI_DB_APP -DACPI_EXEC_APP -fno-strict-aliasing +LIBADD=	pthread + +.include <bsd.prog.mk> + +# clang 6.0.0 and higher warn about the ACPI_ROOT_OBJECT and +# ACPI_TO_POINTER macros from sys/contrib/dev/acpica/include/actypes.h, +# that they use arithmetic on a null pointer treated as a cast from +# integer to pointer, which is a GNU extension. +# +# Turn off the warning, because this is in contributed code. +.if ${COMPILER_TYPE} == "clang" +CWARNFLAGS+=	-Wno-null-pointer-arithmetic +.endif + +# AcpiUtInitStackPtrTrace intentionally leaks a pointer to an +# on-stack variable. +CWARNFLAGS.utdebug.c+= ${NO_WDANGLING_POINTER} diff --git a/usr.sbin/acpi/acpidb/Makefile.depend b/usr.sbin/acpi/acpidb/Makefile.depend new file mode 100644 index 000000000000..577dc5747f1e --- /dev/null +++ b/usr.sbin/acpi/acpidb/Makefile.depend @@ -0,0 +1,16 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ +	include \ +	include/xlocale \ +	lib/${CSU_DIR} \ +	lib/libc \ +	lib/libcompiler_rt \ +	lib/libthr \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/usr.sbin/acpi/acpidb/acpidb.8 b/usr.sbin/acpi/acpidb/acpidb.8 new file mode 100644 index 000000000000..0b9163c5a010 --- /dev/null +++ b/usr.sbin/acpi/acpidb/acpidb.8 @@ -0,0 +1,165 @@ +.\"- +.\" Copyright (c) 2003 Nate Lawson +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\"    notice, this list of conditions and the following disclaimer +.\"    in this position and unchanged. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\"    notice, this list of conditions and the following disclaimer in the +.\"    documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote products +.\"    derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd August 7, 2003 +.Dt ACPIDB 8 +.Os +.Sh NAME +.Nm acpidb +.Nd ACPI DSDT debugger +.Sh SYNOPSIS +.Nm +.Ar input-file +.Sh DESCRIPTION +The +.Nm +utility is a debugger for the ACPI DSDT. +It can parse and execute various +AML methods and display the result. +.Sh COMMANDS +.Ss General-Purpose Commands +.Bl -tag -width indent +.It Ic Allocations +Display list of current memory allocations +.It Ic Dump Ar Address | Namepath Op Cm Byte | Word | Dword | Qword +Display ACPI objects or memory +.It Ic EnableAcpi +Enable ACPI (hardware) mode +.It Ic Help +Show various help screens +.It Ic History +Display command history buffer +.It Ic Level Ar DebugLevel Op Cm console +Get/Set debug level for file or console +.It Ic Locks +Current status of internal mutexes +.It Ic Quit No or Ic Exit +Exit the debugger +.It Ic Stats Op Cm Allocations | Memory | Misc | Objects | Tables +Display namespace and memory statistics +.It Ic Tables +Display info about loaded ACPI tables +.It Ic Unload Ar TableSig Op Ar Instance +Unload an ACPI table +.It Ic !\& Ar CommandNumber +Execute command from history buffer +.It Ic !! +Execute last command again +.El +.Ss Namespace Access Commands +.Bl -tag -width indent +.It Ic Event Cm F | G Ar Value +Generate AcpiEvent (Fixed/GPE) +.It Ic Find Ar Name +Find ACPI name(s) with wildcards +.Ql ( ?\& +is wildcard) +.It Ic Method +Display list of loaded control methods +.It Ic Namespace Oo Ar Addr | Path Oc Op Ar Depth +Display loaded namespace tree/subtree +.It Ic Notify Ar NamePath Value +Send a notification +.It Ic Objects Ar ObjectType +Display all objects of the given type +.It Ic Owner Ar OwnerId Op Ar Depth +Display loaded namespace by object owner +.It Ic Prefix Op Ar NamePath +Set or Get current execution prefix +.It Ic References Ar Addr +Find all references to object at addr +.It Ic Resources +Get and display resources +.It Ic Terminate +Delete namespace and all internal objects +.It Ic Thread Ar Threads Loops NamePath +Spawn threads to execute method(s) +.El +.Ss Control Method Execution Commands +.Bl -tag -width indent +.It Ic Arguments +.Pq Ic Args +Display method arguments +.It Ic Breakpoint Ar AmlOffset +Set an AML execution breakpoint +.It Ic Call +Run to next control method invocation +.It Ic Debug Ar Namepath Op Ar Arguments +Single Step a control method +.It Ic Execute Ar Namepath Op Arguments +Execute control method +.It Ic Go +Allow method to run to completion +.It Ic Information +Display info about the current method +.It Ic Into +Step into (not over) a method call +.It Ic List Op OpcodeCount +Display method ASL statements +.It Ic Locals +Display method local variables +.It Ic Results +Display method result stack +.It Ic Set Cm A | L Ar # Value +Set method data (Arguments/Locals) +.It Ic Stop +Terminate control method +.It Ic Tree +Display control method calling tree +.It Ic <Enter> +Single step next AML opcode (over calls) +.El +.Ss File I/O Commands +.Bl -tag -width indent +.It Ic Close +Close debug output file +.It Ic Open Ar Filename +Open a file for debug output +.It Ic Load Ar Filename +Load ACPI table from a file +.El +.Sh SEE ALSO +.Xr acpi 4 , +.Xr acpidump 8 , +.Xr iasl 8 +.Sh HISTORY +The +.Nm +utility first appeared in the +.Nm acpicatools +port. +It was imported for +.Fx 5.2 . +.Sh AUTHORS +.An -nosplit +The +.Nm +utility was written by +.An Mitsuru Iwasaki Aq Mt iwasaki@FreeBSD.org +and uses Intel ACPI-CA for the backend. +This manual page was written by +.An Nate Lawson . diff --git a/usr.sbin/acpi/acpidb/acpidb.c b/usr.sbin/acpi/acpidb/acpidb.c new file mode 100644 index 000000000000..efd8099f467e --- /dev/null +++ b/usr.sbin/acpi/acpidb/acpidb.c @@ -0,0 +1,540 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2000-2002 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *    notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *    notice, this list of conditions and the following disclaimer in the + *    documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/queue.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/stdint.h> +#include <sys/types.h> + +#include <assert.h> +#include <ctype.h> +#include <err.h> +#include <fcntl.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <contrib/dev/acpica/include/acpi.h> +#include <contrib/dev/acpica/include/accommon.h> +#include <contrib/dev/acpica/include/acapps.h> +#include <contrib/dev/acpica/include/acdebug.h> +#include <contrib/dev/acpica/include/amlresrc.h> + +/* + * Dummy DSDT Table Header + */ + +static ACPI_TABLE_HEADER dummy_dsdt_table = { +	"DSDT", 123, 1, 123, "OEMID", "OEMTBLID", 1, "CRID", 1 +}; + +/* + * Region space I/O routines on virtual machine + */ + +static int	aml_debug_prompt = 1; + +struct ACPIRegionContent { +	TAILQ_ENTRY(ACPIRegionContent) links; +	int			regtype; +	ACPI_PHYSICAL_ADDRESS	addr; +	UINT8			value; +}; + +TAILQ_HEAD(ACPIRegionContentList, ACPIRegionContent); +static struct	ACPIRegionContentList RegionContentList; + +static int		 aml_simulation_initialized = 0; + +ACPI_PHYSICAL_ADDRESS	 AeLocalGetRootPointer(void); +void			 AeDoObjectOverrides(void); +void			 AeTableOverride(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER **); + +static void		 aml_simulation_init(void); +static int		 aml_simulate_regcontent_add(int regtype, +			     ACPI_PHYSICAL_ADDRESS addr, +			     UINT8 value); +static int		 aml_simulate_regcontent_read(int regtype, +			     ACPI_PHYSICAL_ADDRESS addr, +			     UINT8 *valuep);  +static int		 aml_simulate_regcontent_write(int regtype, +			     ACPI_PHYSICAL_ADDRESS addr, +			     UINT8 *valuep); +static UINT64		 aml_simulate_prompt(char *msg, UINT64 def_val); +static void		 aml_simulation_regload(const char *dumpfile); +static void		 aml_simulation_regdump(const char *dumpfile); + +/* Stubs to simplify linkage to the ACPICA core subsystem. */ +ACPI_PHYSICAL_ADDRESS +AcpiOsGetRootPointer(void) +{ + +	return (0); +} + +void +AeDoObjectOverrides(void) +{ +} + +void +AeTableOverride(ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) +{ +} + +void +MpSaveGpioInfo(ACPI_PARSE_OBJECT *Op, AML_RESOURCE *Resource, +    UINT32 PinCount, UINT16 *PinList, char *DeviceName) +{ +} + +void +MpSaveSerialInfo(ACPI_PARSE_OBJECT *Op, AML_RESOURCE *Resource, +    char *DeviceName) +{ +} + +static void +aml_simulation_init(void) +{ + +	aml_simulation_initialized = 1; +	TAILQ_INIT(&RegionContentList); +	aml_simulation_regload("region.ini"); +} + +static int +aml_simulate_regcontent_add(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 value) +{ +	struct	ACPIRegionContent *rc; + +	rc = malloc(sizeof(struct ACPIRegionContent)); +	if (rc == NULL) { +		return (-1);	/* malloc fail */ +	} +	rc->regtype = regtype; +	rc->addr = addr; +	rc->value = value; + +	TAILQ_INSERT_TAIL(&RegionContentList, rc, links); +	return (0); +} + +static int +aml_simulate_regcontent_read(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) +{ +	struct	ACPIRegionContent *rc; + +	if (!aml_simulation_initialized) { +		aml_simulation_init(); +	} +	TAILQ_FOREACH(rc, &RegionContentList, links) { +		if (rc->regtype == regtype && rc->addr == addr) { +			*valuep = rc->value; +			return (1);	/* found */ +		} +	} + +	*valuep = 0; +	return (aml_simulate_regcontent_add(regtype, addr, *valuep)); +} + +static int +aml_simulate_regcontent_write(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) +{ +	struct	ACPIRegionContent *rc; + +	if (!aml_simulation_initialized) { +		aml_simulation_init(); +	} +	TAILQ_FOREACH(rc, &RegionContentList, links) { +		if (rc->regtype == regtype && rc->addr == addr) { +			rc->value = *valuep; +			return (1);	/* exists */ +		} +	} + +	return (aml_simulate_regcontent_add(regtype, addr, *valuep)); +} + +static UINT64 +aml_simulate_prompt(char *msg, UINT64 def_val) +{ +	char		buf[16], *ep; +	UINT64		val; + +	val = def_val; +	printf("DEBUG"); +	if (msg != NULL) { +		printf("%s", msg); +	} +	printf("(default: 0x%jx ", (uintmax_t)val); +	printf(" / %ju) >>", (uintmax_t)val); +	fflush(stdout); + +	bzero(buf, sizeof buf); +	while (1) { +		if (read(0, buf, sizeof buf) == 0) { +			continue; +		} +		if (buf[0] == '\n') { +			break;	/* use default value */ +		} +		if (buf[0] == '0' && buf[1] == 'x') { +			val = strtoq(buf, &ep, 16); +		} else { +			val = strtoq(buf, &ep, 10); +		} +		break; +	} +	return (val); +} + +static void +aml_simulation_regload(const char *dumpfile) +{ +	char	buf[256], *np, *ep; +	struct	ACPIRegionContent rc; +	FILE	*fp; + +	if (!aml_simulation_initialized) { +		return; +	} + +	if ((fp = fopen(dumpfile, "r")) == NULL) { +		return; +	} + +	while (fgets(buf, sizeof buf, fp) != NULL) { +		np = buf; +		/* reading region type */ +		rc.regtype = strtoq(np, &ep, 10); +		if (np == ep) { +			continue; +		} +		np = ep; + +		/* reading address */ +		rc.addr = strtoq(np, &ep, 16); +		if (np == ep) { +			continue; +		} +		np = ep; + +		/* reading value */ +		rc.value = strtoq(np, &ep, 16); +		if (np == ep) { +			continue; +		} +		aml_simulate_regcontent_write(rc.regtype, rc.addr, &rc.value); +	} + +	fclose(fp); +} + +static void +aml_simulation_regdump(const char *dumpfile) +{ +	struct	ACPIRegionContent *rc; +	FILE	*fp; + +	if (!aml_simulation_initialized) { +		return; +	} +	if ((fp = fopen(dumpfile, "w")) == NULL) { +		warn("%s", dumpfile); +		return; +	} +	while (!TAILQ_EMPTY(&RegionContentList)) { +		rc = TAILQ_FIRST(&RegionContentList); +		fprintf(fp, "%d	0x%jx	0x%x\n", +		    rc->regtype, (uintmax_t)rc->addr, rc->value); +		TAILQ_REMOVE(&RegionContentList, rc, links); +		free(rc); +	} + +	fclose(fp); +	TAILQ_INIT(&RegionContentList); +} + +/* + * Space handlers on virtual machine + */ + +static ACPI_STATUS +aml_vm_space_handler( +	UINT32			SpaceID, +	UINT32			Function, +	ACPI_PHYSICAL_ADDRESS	Address, +	UINT32			BitWidth, +	UINT64			*Value, +	int			Prompt) +{ +	int			state; +	UINT8			val; +	UINT64			value, i; +	char			msg[256]; +	static const char	*space_names[] = { +		"SYSTEM_MEMORY", "SYSTEM_IO", "PCI_CONFIG", +		"EC", "SMBUS", "CMOS", "PCI_BAR_TARGET"}; + +	switch (Function) { +	case ACPI_READ: +		value = 0; +		for (i = 0; (i * 8) < BitWidth; i++) { +			state = aml_simulate_regcontent_read(SpaceID, +							     Address + i, &val); +			if (state == -1) { +				return (AE_NO_MEMORY); +			} +			value |= val << (i * 8); +		} +		*Value = value; +		if (Prompt) { +			sprintf(msg, "[read (%s, %2d, 0x%jx)]", +				space_names[SpaceID], BitWidth, +				(uintmax_t)Address); +			*Value = aml_simulate_prompt(msg, value); +			if (*Value != value) { +				return(aml_vm_space_handler(SpaceID, +						ACPI_WRITE, +						Address, BitWidth, Value, 0)); +			} +		} +		break; + +	case ACPI_WRITE: +		value = *Value; +		if (Prompt) { +			sprintf(msg, "[write(%s, %2d, 0x%jx)]", +				space_names[SpaceID], BitWidth, +				(uintmax_t)Address); +			value = aml_simulate_prompt(msg, *Value); +		} +		*Value = value; +		for (i = 0; (i * 8) < BitWidth; i++) { +			val = value & 0xff; +			state = aml_simulate_regcontent_write(SpaceID, +							      Address + i, &val); +			if (state == -1) { +				return (AE_NO_MEMORY); +			} +			value = value >> 8; +		} +	} + +	return (AE_OK); +} + +#define DECLARE_VM_SPACE_HANDLER(name, id);			\ +static ACPI_STATUS						\ +aml_vm_space_handler_##name (					\ +	UINT32			Function,			\ +	ACPI_PHYSICAL_ADDRESS	Address,			\ +	UINT32			BitWidth,			\ +	UINT64			*Value)				\ +{								\ +	return (aml_vm_space_handler(id, Function, Address,	\ +		BitWidth, Value, aml_debug_prompt));		\ +} + +DECLARE_VM_SPACE_HANDLER(system_memory,	ACPI_ADR_SPACE_SYSTEM_MEMORY); +DECLARE_VM_SPACE_HANDLER(system_io,	ACPI_ADR_SPACE_SYSTEM_IO); +DECLARE_VM_SPACE_HANDLER(pci_config,	ACPI_ADR_SPACE_PCI_CONFIG); +DECLARE_VM_SPACE_HANDLER(ec,		ACPI_ADR_SPACE_EC); +DECLARE_VM_SPACE_HANDLER(smbus,		ACPI_ADR_SPACE_SMBUS); +DECLARE_VM_SPACE_HANDLER(cmos,		ACPI_ADR_SPACE_CMOS); +DECLARE_VM_SPACE_HANDLER(pci_bar_target,ACPI_ADR_SPACE_PCI_BAR_TARGET); + +/* + * Load DSDT data file and invoke debugger + */ + +static int +load_dsdt(const char *dsdtfile) +{ +	char			filetmp[PATH_MAX]; +	ACPI_NEW_TABLE_DESC	*list; +	u_int8_t		*code; +	struct stat		sb; +	int			dounlink, error, fd; + +	fd = open(dsdtfile, O_RDONLY, 0); +	if (fd == -1) { +		perror("open"); +		return (-1); +	} +	if (fstat(fd, &sb) == -1) { +		perror("fstat"); +		close(fd); +		return (-1); +	} +	code = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0); +	close(fd); +	if (code == NULL) { +		perror("mmap"); +		return (-1); +	} +	if ((error = AcpiInitializeSubsystem()) != AE_OK) { +		munmap(code, (size_t)sb.st_size); +		return (-1); +	} + +	/* +	 * make sure DSDT data contains table header or not. +	 */ +	if (strncmp((char *)code, "DSDT", 4) == 0) { +		dounlink = 0; +		strlcpy(filetmp, dsdtfile, sizeof(filetmp)); +	} else { +		dounlink = 1; +		mode_t	mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); +		dummy_dsdt_table.Length = sizeof(ACPI_TABLE_HEADER) + sb.st_size; +		if ((size_t)snprintf(filetmp, sizeof(filetmp), "%s.tmp", +		    dsdtfile) > sizeof(filetmp) - 1) { +			fprintf(stderr, "file name too long\n"); +			munmap(code, (size_t)sb.st_size); +			return (-1); +		} +		fd = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode); +		if (fd == -1) { +			perror("open"); +			munmap(code, (size_t)sb.st_size); +			return (-1); +		} +		write(fd, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER)); + +		write(fd, code, sb.st_size); +		close(fd); +	} +	munmap(code, (size_t)sb.st_size); + +	/* +	 * Install the virtual machine version of address space handlers. +	 */ +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_SYSTEM_MEMORY, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_memory, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise SystemMemory handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_SYSTEM_IO, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_io, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise SystemIO handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_PCI_CONFIG, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_config, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise PciConfig handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_EC, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_ec, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise EC handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_SMBUS, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_smbus, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise SMBUS handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_CMOS, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_cmos, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise CMOS handler: %d\n", error); +		return (-1); +	} +	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, +			ACPI_ADR_SPACE_PCI_BAR_TARGET, +			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_bar_target, +			NULL, NULL)) != AE_OK) { +		fprintf(stderr, "could not initialise PCI BAR TARGET handler: %d\n", error); +		return (-1); +	} + +	list = NULL; +	AcGetAllTablesFromFile(filetmp, TRUE, &list); + +	AcpiInitializeDebugger(); +	AcpiGbl_DebuggerConfiguration = 0; +	AcpiDbUserCommands(); + +	if (dounlink) { +		unlink(filetmp); +	} + +	return (0); +} + +static void +usage(const char *progname) +{ + +	printf("usage: %s dsdt_file\n", progname); +	exit(1); +} + +int +main(int argc, char *argv[]) +{ +	char	*progname; + +	progname = argv[0]; + +	if (argc == 1) { +		usage(progname); +	} + +	AcpiDbgLevel = ACPI_DEBUG_DEFAULT; + +	/* +	 * Match kernel options for the interpreter.  Global variable names +	 * can be found in acglobal.h. +	 */ +	AcpiGbl_EnableInterpreterSlack = TRUE; + +	aml_simulation_regload("region.ini"); +	if (load_dsdt(argv[1]) == 0) { +		aml_simulation_regdump("region.dmp"); +	} + +	return (0); +}  | 
