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

251 Commits

Author SHA1 Message Date
Achilleas Anagnostopoulos
ef88921fb9 acpi: refactor block exec code and add support for stack traces
The VM.execBlock method has been converted to a standalone function.
Access to the vm is facilitated via the ctx argument.

The VM will calculate the start and end instruction pointer offsets for
all scoped blocks in a pre-processing pass which is initiated by the
VM.checkEntities call when it encounters a Method entity. As opcodes
may trigger the execution of multiple opcodes (e.g. if/else) or even
mutate the execution flow (e.g. a break inside a while loop) we need
to keep track of the IP offsets in all scoped blocks so the VM can
provide accurate IP values for stack traces.

The stack trace is included as part of the *Error struct and is
populated automatically by execBlock whenever an error occurs. A
convenience Error.StackTrace() method is provided for obtaining
a formatted version of the stack trace as a string.

Each stack trace entry contains information about the method name inside
which an error executed, the table name where the method was defined as
well as the opcode type and IP offset (relative to the method start) where the
error occured. Stack traces are also preserved across method
invocations. An example flow that generates a fatal error is included in
the vm-testsuite-DSDT.dsl file (method \NST2). Calling this method with
the appropriate arguments generates a stack trace that looks like this:

Stack trace:
[000] [DSDT] [NST2():0x2] opcode: Store
[001] [DSDT] [NST3():0x1] opcode: Add
[002] [DSDT] [NST4():0x8] opcode: If
[003] [DSDT] [NST4():0x9] opcode: Fatal
2017-12-08 08:47:15 +00:00
Achilleas Anagnostopoulos
540986cb0b acpi: add VM-support for method invocations
The getOpcode() method of methodInvocationEntity has been patched so
that a non-AML opcode is returned (selected to be lastOpcode + 1). The
jumpTable at position [lastOpcode+1] is populated with a method that
handles the method invocation logic.

Whenever a method invocation is encountered, the interpreter will try to
lazilly resolve the invoked method definition. Then, a new execution
context will be allocated on the stack and the method args will be
automatically populated by resolving (via a vmLoad call) all arguments
of the methodInvocationEntity instance. The interpreter will then invoke
the method using the new context, fetch the result value (new ctx
retVal) and resolve it (via vmLoad) back to value that can be stored in
the original context that triggered the method invocation.
2017-12-04 08:46:43 +00:00
Achilleas Anagnostopoulos
ad6c7ee991 acpi: add VM-support for while/if/elseif/else blocks 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
2be5b9d224 acpi: add VM-support for AML bitwise opcodes 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
38b2a3e4e2 acpi: add VM-support for AML arithmetic opcodes 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
a172621af7 acpi: implement string <=> int converter
The converter is pretty basic at the moment and it only supports
converting to/from Integer and String types. This commit also includes
some argument => uint64 conversion helpers that will serve as the basis
for implementing the ALU opcodes.
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
d6a825fc02 acpi: implement AML helpers for detecting argument types
The list of AML types is described on $p. 876 of ACPI 6.2 standard
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
dfaf068735 acpi: implement vmStore/Copy for local/method args and references
The vmStore implementation does not support storing data to other AML
entities such as Buffers, Fields or Regions. Support for these entities
will be included in a separate commit.

The current vmCopyObject implementation is as simple as possible for
now; only copying of strings and uint64 values is supported. This
matches the behavior of vmLoad.

Both vmLoad/Store functions support reading/writing to/from object
references following the ACPI spec rules about automatic dereferencing.
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
1a2d075aa2 acpi: implement minimal helper for reading AML operand values
The helper only supports reading a subset of the available AML operands:
- constants (uint64, strings and bools; bools are auto-casted to uint64)
- local and method args

The implementation will recursively drill down into the operand values
till it reaches a value that can be mapped to a Go uint64 or string
type. For example, if arg0 contains a constant with the value "foo",
vmRead will recurse into the arg0 value and return "foo"
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
fd2f4a72ad acpi: instanciate AML interpreter when the ACPI driver is initialized 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
63c69fe8d3 acpi: implement internal VM method for executing AML blocks
The execBlock method supports the various control flows defined by the
ACPI standard (next instr, continue, break and return). It is designed
so that it can be recursively invoked both AML methods and various
flow-altering opcodes (e.g. opIf, opWhile e.t.c.)
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
718006f4e4 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".
2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
1d5d1dc3ec acpi: implement VM entity lookup and visit wrappers 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
64f3dae485 acpi: define VM type and structs to maintain execution state 2017-12-04 06:35:26 +00:00
Achilleas Anagnostopoulos
61597cff56
Merge pull request #60 from achilleasa/improve-handling-of-fwd-decls-in-aml-parser
Improve handling of forward declarations in AML parser
2017-12-03 11:14:48 +00:00
Achilleas Anagnostopoulos
692155b44b acpi: refine post-parse entity processing rules
This commit updates the post-parse step so that:
- the visitor not longer recurses into method bodies. Since code inside
  methods may potentially generate dynamic/scoped entities or even use
  conditional invocations (if CondRefOf(X) { X(...) }), symbol resolution
  will be deferred to the AML interpreter.
- parent-child relationships between entities are checked and updated if
  not properly specified
2017-12-03 10:54:21 +00:00
Achilleas Anagnostopoulos
70c798f40a acpi: add pre-process step to capture arg counts for all function decls
Since the ACPI standard allows forward function declarations this step
is required so we can properly parse the argument list for function
invocations. Contrary to other AML entities, method invocations do not
include any sort of pkgLength information so unless we track the
expected argument count for each function, our parser will not be able
to figure out where the argument list ends.
2017-12-03 10:21:40 +00:00
Achilleas Anagnostopoulos
7983394390 acpi: implement resolver interface for methodInvocation entities 2017-12-03 10:17:41 +00:00
Achilleas Anagnostopoulos
0a05164703 acpi: change scopeVisit to visit entities in a visited entity's arglist 2017-12-01 08:01:17 +00:00
Achilleas Anagnostopoulos
d9bd6f104e acpi: fix linter warnings for unhandled errors in AML parser 2017-11-27 07:15:11 +00:00
Achilleas Anagnostopoulos
61449a15a1 lint: enable check for proper handling of return values 2017-11-22 07:03:56 +00:00
Achilleas Anagnostopoulos
4aa2600b65 Merge pull request #59 from achilleasa/place-linter-deps-in-build-folder
Prepend build folder to GOPATH before building/testing/linting
2017-10-25 07:43:05 +01:00
Achilleas Anagnostopoulos
11baa1e8f5 Prepend build folder to GOPATH before building/testing/linting 2017-10-25 07:33:24 +01:00
Achilleas Anagnostopoulos
0f85d4be53 Merge pull request #53 from achilleasa/implement-aml-parser
Implement AML parser
2017-09-30 16:44:09 +01:00
Achilleas Anagnostopoulos
61a033e2ad acpi: tweak parser and add tests for parser errors 2017-09-30 16:40:53 +01:00
Achilleas Anagnostopoulos
d020045887 acpi: tag entities with the handle of the table that defines them
This allows us to implement the Unload opcode which given a handle,
removes all entities that are tagged by it.
2017-09-30 16:36:26 +01:00
Achilleas Anagnostopoulos
2a84c75d8e acpi: implement AML parser for all AML opcodes in the ACPI 6.2 spec 2017-09-30 16:36:22 +01:00
Achilleas Anagnostopoulos
4dd7c0b077 acpi: implement functions for working with AML scopes
The scope resolution rules are specified in page 252 of the ACPI 6.2
spec.
2017-09-30 16:25:34 +01:00
Achilleas Anagnostopoulos
130e11507c acpi: define structs for basic AML entities 2017-09-30 16:25:29 +01:00
Achilleas Anagnostopoulos
5171822ba6 acpi: define mappings and helpers for AML opcodes 2017-09-30 14:08:55 +01:00
Achilleas Anagnostopoulos
93125caa8a acpi: implement memory-based reader for AML byte-code streams 2017-09-30 13:45:30 +01:00
Achilleas Anagnostopoulos
4e985c91c6 Merge pull request #56 from achilleasa/update-vagrantfile
vagrantfile: include gcc and binutils in the list of installed packages
2017-09-24 10:12:48 +01:00
Achilleas Anagnostopoulos
41d245d331 vagrantfile: include gcc and binutils in the list of installed packages 2017-09-24 10:06:35 +01:00
Achilleas Anagnostopoulos
52be87b67f Merge pull request #54 from dvrkps/patch-1
travis: update go version
2017-09-19 19:08:46 +01:00
Davor Kapsa
04a097bf4f travis: update go version 2017-09-18 09:45:41 +02:00
Achilleas Anagnostopoulos
14aef16459 Merge pull request #52 from achilleasa/detect-acpi-support-and-enumerate-acpi-tables
Detect ACPI support and enumerate ACPI tables
2017-08-28 07:49:00 +01:00
Achilleas Anagnostopoulos
7d959af0a9 acpi: import and register ACPI driver with hal 2017-08-28 07:28:31 +01:00
Achilleas Anagnostopoulos
78d5fac550 acpi: probe for RSDT and enumerate/map other ACPI tables (inc. DSDT) 2017-08-28 07:28:31 +01:00
Achilleas Anagnostopoulos
49dfc5c9de acpi: define structs for standard header and various ACPI tables 2017-08-28 07:28:27 +01:00
Achilleas Anagnostopoulos
7bcaf0ee8d vmm: implement identity mapping function for contiguous physical mem regions
vmm.IdentityMapRegion can be used by device drivers that want to
establish an identity mapping for a contiguous physical memory block in
order to access some hardware or table.
2017-08-28 07:28:04 +01:00
Achilleas Anagnostopoulos
0a271b206b pmm: implement FrameFromAddress
This is equivalent to vmm.PageFromAddress but returns back a pmm.Frame
2017-08-28 07:28:04 +01:00
Achilleas Anagnostopoulos
324022187d Merge pull request #51 from achilleasa/fix-vga-text-palette-mapping
Map EGA color indices to correct DAC entries for VGA HW
2017-08-19 11:07:28 +01:00
Achilleas Anagnostopoulos
d17298acaa vga_text: Map EGA color indices to correct DAC entries for the VGA hw 2017-08-19 10:33:38 +01:00
Achilleas Anagnostopoulos
08c845a9ac Use the correct CI env name 2017-08-08 23:57:54 +01:00
Achilleas Anagnostopoulos
9838f468a7 Fix minor typo in BUILD.md 2017-08-08 23:42:25 +01:00
Achilleas Anagnostopoulos
301024eb89 Merge pull request #49 from achilleasa/improve-readme
Improve documentation
2017-08-08 23:38:27 +01:00
Achilleas Anagnostopoulos
b5bd7da046 Update readme 2017-08-08 23:34:24 +01:00
Achilleas Anagnostopoulos
63e9f40d47 Add build guide 2017-08-08 23:34:19 +01:00
Achilleas Anagnostopoulos
c778693de0 Merge pull request #48 from achilleasa/vbox-make-target
Add Makefile target for running gopher-os ISO using vbox
2017-08-08 23:24:15 +01:00
Achilleas Anagnostopoulos
cb0f7312cf Add vbox run target to the Makefile and rename run target to run-qemu 2017-08-08 23:11:59 +01:00