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

271 Commits

Author SHA1 Message Date
Achilleas Anagnostopoulos
bb81bb3550 ci: run matrix build with go 1.7.x - 1.x
The .travis.yml file has been updated so that CI will also attempt to
build the kernel using the latest go branches from 1.7, 1.8, 1.9, 1.10,
1.x.

The tests will only be run once against the latest go version.
2018-03-23 07:26:20 +00:00
Achilleas Anagnostopoulos
c0f92f4454 makefile: tweak build script to compile kernel using go 1.10 2018-03-23 07:26:20 +00:00
Achilleas Anagnostopoulos
ce9a397008 bootstrap: add extra cgo stub symbols for go 1.8 2018-03-23 07:22:32 +00:00
Achilleas Anagnostopoulos
8d0c44921b goruntime: split bootstrap symbols into conditionally compiled files
Due to some changes in the runtime init functions between go 1.7 and
later versions (e.g. runtime.modulesInit() defined after go 1.7), the
kernel code that bootstraps the go runtime had to be split into separate
files which are conditionally compiled using +build flags.
2018-03-23 07:22:32 +00:00
Achilleas Anagnostopoulos
4e3567f8a1 tools: update offsets tool to work with go versions 1.7 - 1.10
Older go versions (1.7.x) specify a fixed page size (_PageSize const) as
part of their runtime whereas newer go versions populate the page size at
runtime.

The kernel asm bootstrap code was written with go 1.8 in mind. As a
result it attempts to populate the page size manually which obviously
breaks compilation in go 1.7.

The offsets tool has been updated to emit the special def
"SKIP_PAGESIZE_SETUP" when running under go 1.7 which allows us to
perform conditional compilation of the page setup code inside the
bootstrap asm code.

fixup
2018-03-23 07:21:02 +00:00
Achilleas Anagnostopoulos
c0b9f62f78
Merge pull request #65 from achilleasa/fix-kernel-elf-section-mapping-bug
Fix kernel elf section mapping bug
2018-03-22 19:17:34 +00:00
Achilleas Anagnostopoulos
76f7869f57 vmm: fix some lint warnings (error not checked) 2018-03-22 18:56:28 +00:00
Achilleas Anagnostopoulos
d082a7473a vmm: handle mapping of kernel ELF sections that are not page aligned
The code responsible for mapping the kernel sections worked under the
assumption that the linker would align all sections on a page boundary.
To figure out the page extents for a particular section, the
implementation would round the section VMA down to the nearest page and
add to that the section length rounded up to the nearest page size.

However, some sections (e.g. noptrbss) use 32 byte alignment. Depending
on the section length, the original implementation could in some cases
skip mapping of the last page in the section which would cause a page
fault when its contents were accessed.

The fix for this issue is quite simple: calculate the end page by
rounding up (section start addr + section length) to the next page.
2018-03-22 18:56:13 +00:00
Achilleas Anagnostopoulos
cc699b3d15
Update STATUS.md 2018-03-12 06:42:30 +00:00
Achilleas Anagnostopoulos
972cf64bca lint: fix lint warnings 2018-03-11 17:38:41 +00:00
Achilleas Anagnostopoulos
3bfbf6389e lint: add "gofmt -s" to the linter list 2018-03-11 17:38:20 +00:00
Achilleas Anagnostopoulos
b46598cb67
Merge pull request #63 from achilleasa/reimplement-aml-parser
Reimplement AML parser
2018-03-11 15:39:42 +00:00
Achilleas Anagnostopoulos
f57aa9433d acpi: fix bugs discovered by fuzzing 2018-03-09 07:14:12 +00:00
Achilleas Anagnostopoulos
ddbddd2ea2 acpi: add Makefile target for fuzzing and AML parser fuzzer
The fuzzer can be invoked by running: "make test-fuzz". The AML parser
test suite has been augmented with a special "TestParserCrashers"
function that can be used to replay corpuses identified by go-fuzz as
causing parser crashes.

The test can be invoked as:

go test -v -run TestParserCrashers -aml-replace-crashers-from
$BUILD/fuzz/corpus/src_gopheros_device_acpi_aml/crashers

where $BUILD is the output directory (default: build/) defined in the
Makefile.
2018-03-09 07:14:12 +00:00
Achilleas Anagnostopoulos
d7028ed73d acpi: test the parser against actual AML dumps
All dumps are located in the tabletest package. The DSDT/SSDT dumps were
obtained by running an aml dump tool inside a virtualbox instance. The
dumps were disassembled using the iasl tool (version 20180105) from
Intel's reference ACPICA implementation.

The parser-testsuite dumps were written by hand to ensure that all
possible happy-paths in the parser were followed and then compiled into
AML using the same iasl tool.

The added TestParser function attempts to parse various sets of AML
dumps and then uses the object tree pretty-printer to obtain a dump of
the tree. The dump is then compared to an expected value (.exp files are
also placed in the tabletest package). The test code supports passing
the "-aml-regenerate-parser-exp-files" flag to update the exp files:

go test -run TestParser -aml-regenerate-parser-exp-files
2018-03-09 07:14:09 +00:00
Achilleas Anagnostopoulos
9dd9ab9add acpi: add helper method to pretty-print AML object trees 2018-03-09 07:08:36 +00:00
Achilleas Anagnostopoulos
fe6c8f7293 acpi: implement AML multi-pass parser 2018-03-09 07:08:36 +00:00
Achilleas Anagnostopoulos
98fe98bc83 acpi: implement reader abstraction for AML in-memory byte-streams 2018-03-09 07:08:36 +00:00
Achilleas Anagnostopoulos
b00fff0e39 acpi: define tree-based structure for storing parsed AML entities
ACPI entity definitions form a tree whose roots are a sequence of
pre-defined namespace objects. The parser stores all AML entities using
a space-optimized structure (Object). These objects are organized into a
tree via the ObjectTree structure.

Instead of storing pointers to other objects (i.e. siblings, children or
parent), objects use uint32 indices to objects managed by the
ObjectTree. This has the nice advantage of reducing the memory
requirements for our tree in half when running on 64-bits (4-bytes per
index vs 8-bytes per pointer) while also allowing us to recycle objects
that are explicitly freed by the parser.
2018-03-09 07:08:31 +00:00
Achilleas Anagnostopoulos
851011f957 acpi: define parser tables for decoding AML opcodes
The opcode tables establish a 2-level mapping between AML opcodes (regular
or extended) and a secondary table that allows the parser to decode each
opcode. This information includes:
 - the opcode name
 - the opcode flags (e.g. specifies a named object or parsing must be
 deferred to a later pass)
 - the expected arguments for each opcode and their types.
2018-02-28 19:41:51 +00:00
Achilleas Anagnostopoulos
ca1682c431 acpi: define helper functions for working with opcode groups 2018-02-27 08:37:55 +00:00
Achilleas Anagnostopoulos
b1e959ec4d acpi: define list of AML opcodes
The list provides a uniform mapping for regular (one byte), extended
(0x1b + one byte) opcodes as well as some "internal" opcodes that will be
used by the parser to represent method calls, named fields and resolved
named object references.
2018-02-27 08:14:42 +00:00
Achilleas Anagnostopoulos
a06b1aa21f
Merge pull request #62 from achilleasa/remove-broken-aml-parser-impl
acpi: remove broken AML parser implementation
2018-02-25 08:35:42 +00:00
Achilleas Anagnostopoulos
80bd263fc9 acpi: remove broken AML parser implementation
The existing parser implementation has several issues and will, in many
cases incorrectly parse AML bytestreams that contain (among other
things):
- ambiguous method calls (same method name defined in multiple scopes)
- bank fields
- buffer fields where the length arg contains a method call
- named objects containing one or more '^' prefixes when defined inside
nested Scope elements (e.g. Scope(_SBRG){ Device(^PCIE){...} })

Unfortunately, these issues were discovered quite late while working on
the AML interpreter and while an attempt was made to correct some of
these (see previous commits), it turns out that the current codebase
cannot be refactored to fix all issues.

I have therefore decided to get rid of the current implementation and
replace it with a new one which will be created from scratch to address
all the above issues.

This commit just cleans up the codebase so the new parser can be added
via a future PR.
2018-02-25 08:32:33 +00:00
Achilleas Anagnostopoulos
3396b997e7
Merge pull request #61 from achilleasa/refactor-aml-parser-into-multiple-packages
Refactor AML parser into multiple packages and fix parser bugs
2018-01-06 10:53:44 +00:00
Achilleas Anagnostopoulos
c09798622b acpi: provide more robust implementation for parsing AML method bodies
The previous implementation used brute-force approach where the parser
made an initial pass scanning the AML bytestream and looking for method
declaration opcodes. It then parsed out the method name and arg count
and populated a map which was used to detect the number of arguments to
be parsed upon encountering a method invocation. This approach proved to
be error-prone and would lead to an incorrect parse tree in the
following ASL example:

  Method (FOOF, 1, NotSerialized)
  {
    Return ("bar")
  }

  Method (TST0, 0, NotSerialized)
  {
    FOOF(0)
    \_SB.FOOF(2, 3)
  }

  Scope(\_SB){
    // Another FOOF method in \_SB which takes a different arg count
    Method (FOOF, 2, NotSerialized)
    {
      Return ("something")
    }
  }

In the above example the parser would correctly parse the first FOOF
call in TST0 but fail to parse the second invocation since the method
name contains a scope. The second invocation would actually yield the
following incorrect entity list (arguments appear as sibling entities):

Ref(\_SB.FOOF), Const(2), Const(3)

The new approach gets rid of the brute-force method and instead modifies
the initial parse of the tree not to parse the entities in the AML
method bodies but to instead track the start and end offset in the
AML stream for the body contents. In the second pass (where the parser
normally resolves symbol references), the parser can properly parse the
contents of method bodies since the entire AML tree is now known and the
parser can use the regular scope lookup rules to find the correct method
declaration for the invocation and figure out the argument count it
needs to parse.
2018-01-06 10:44:19 +00:00
Achilleas Anagnostopoulos
10ba4f7ad6 acpi: implement LazyRefResolver for entities that use lazy symbol references 2018-01-03 20:59:49 +00:00
Achilleas Anagnostopoulos
41eae61c9f acpi: update AML parser to use the new entities 2018-01-03 20:59:44 +00:00
Achilleas Anagnostopoulos
e7f203f06a acpi: move stream reader implementation into parser pkg 2018-01-03 20:55:37 +00:00
Achilleas Anagnostopoulos
d1eb0b6d4d acpi: move parser opcode table into the parser pkg 2018-01-03 20:55:37 +00:00
Achilleas Anagnostopoulos
7e419ae20e acpi: move entity visitor code to the entity pkg 2018-01-03 20:55:37 +00:00
Achilleas Anagnostopoulos
38143ab510 acpi: refactor scope lookup code and move it into the entity pkg 2018-01-03 20:55:37 +00:00
Achilleas Anagnostopoulos
17842763e9 acpi: move entities to the entity pkg, export them and add missing entities
This commit moves the AML entity definitions into the entity package and
makes them exportable so we can reference them from other packages.

In addition, the commit adds some missing entity structs that were
previously treated as generic entities (e.g. Processor, PowerResource
and ThermalZone).

Finally, this commit cleans the definitions and adds missing struct
attributes for the various field types (Field, IndexField, BankField)
2018-01-03 20:55:31 +00:00
Achilleas Anagnostopoulos
89923eb481 acpi: move AML opcode definitions into the entity pkg 2017-12-17 21:26:39 +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