1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

acpi: define AML opcode jumptable and populate with placeholder function

Due to the large number of opcodes that the AML VM needs to support,
using a long switch statement will not be as performant as setting up a
jump table due to the way that the go compiler generates code for long
switch statements on integer values (asm code indicates that binary
search is used to select the switch target).

For the time being, the populateJumpTable method will assign a
placeholder function to each jump table entry that just returns a
"opcode X not implemented error".
This commit is contained in:
Achilleas Anagnostopoulos 2017-10-16 06:58:05 +01:00
parent 1d5d1dc3ec
commit 718006f4e4
3 changed files with 26 additions and 1 deletions

View File

@ -119,6 +119,8 @@ const (
opIndexField = opcode(0xff + 0x86)
opBankField = opcode(0xff + 0x87)
opDataRegion = opcode(0xff + 0x88)
//
numOpcodes = 0xff + 0x89
)
// The opcode table contains all opcode-related information that the parser knows.

View File

@ -24,7 +24,7 @@ const (
ctrlFlowTypeFnReturn
)
// execContext encapsulates
// execContext holds the AML interpreter state while an AML method executes.
type execContext struct {
localArg [maxLocalArgs]interface{}
methodArg [maxMethodArgs]interface{}
@ -65,6 +65,8 @@ type VM struct {
// whether integers are treated as 32 or 64-bits. The VM memoizes this
// value so that it can be used by the data conversion helpers.
sizeOfIntInBits int
jumpTable [numOpcodes]opHandler
}
// NewVM creates a new AML VM and initializes it with the default scope
@ -101,6 +103,7 @@ func (vm *VM) Init() *Error {
}
}
vm.populateJumpTable()
return nil
}

View File

@ -0,0 +1,20 @@
package aml
// opHandler is a function that implements an AML opcode.
type opHandler func(*execContext, Entity) *Error
// populateJumpTable assigns the functions that implement the various AML
// opcodes to the VM's jump table.
func (vm *VM) populateJumpTable() {
for i := 0; i < len(vm.jumpTable); i++ {
vm.jumpTable[i] = opExecNotImplemented
}
}
// opExecNotImplemented is a placeholder handler that returns a non-implemented
// opcode error.
func opExecNotImplemented(_ *execContext, ent Entity) *Error {
return &Error{
message: "opcode " + ent.getOpcode().String() + " not implemented",
}
}