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

6 Commits

Author SHA1 Message Date
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
a5c6828fc2 Create tool for converting images to compatible console logo files
The tool processes an image and converts it to a logo.Image struct which
can be assigned to a logo-capable console.
2017-07-13 23:35:20 +01:00
Achilleas Anagnostopoulos
f961270904 Use the new Go workspace paths when building qualified symbol names 2017-07-02 06:39:19 +01:00
Achilleas Anagnostopoulos
ce34763e23 Redirects tool should only consider comments attached to functions 2017-06-30 09:21:05 +01:00
Achilleas Anagnostopoulos
62aca2f2de Implement tool for calculating offsets into g, m and stack structs
The offsets tool is essentially a wrapper around "go build -a -n". It
creates a temporary folder with a dummy go file and runs the above
command using the target OS/ARCH for the kernel and captures the output.
The use of the "-a" flag forces go build to generate a build script for
rebuilding all packages including the runtime ones. As a by-product of
building the runtime package, the compiler emits the "go_asm.h" file
that contains (among other things) the offsets for each element of the
g, m and stack structures (see src/runtime/runtime2.go).

These offsets are used in Go assembly files instead of hardcoded
offsets. For example the following snippet accesses the pointer to m in
the g struct address stored at register CX:

MOVQ TLS, CX
MOVQ g_m(CX), BX

The offsets tool modifies the captured output from the go build command
so it only includes the steps up to building the runtime package,
executes the build script and post-processes the generated go_asm.h file
to retain the entries relevant to g, m and stack and then formats them
so they are compatible with nasm definitions (name equ value).

Depending on the value of the "-out" option, the tool outputs the
generated definitions either to STDOUT (default value for -out) or to a
file.
2017-06-30 09:01:41 +01:00
Achilleas Anagnostopoulos
275664219e Implement tool to detect redirects and to populate the redirect table
The tool scans all go sources (excluding tests) in the "kernel" package
and its subpackages looking for functions with a "go:redirect-from
symbol_name" comment. The go:redirect-from directive implies that a
function serves as a redirect target for s symbol name.  For example,
the following block:

//go:redirect-from runtime.gopanic
func foo(_ interface{}){
	...
}

specifies that calls to "runtime.gopanic" should be redirected to "foo".

The tool provides two commands:
- count: prints the count of redirections
- populate-table: resolve redirect symbols and populate the
  _rt0_rediret_table entries in the kernel image.

As the final virtual addresses for the symbols are only known after
linking, populating this table is a 2-step process. At first, the
"count" command is used to allocate enough space for 2 x NUM_REDIRECTS
pointers. The table itself is placed with the help of the linker script
in a separate section making it easy to find its offset in the ELF
image.

After the kernel is linked, the "populate-table" command use the
debug/elf package to scan the image file and resolve the addresses for
the src and dst redirection symbols. The tool will then open the image
file in RW mode, seek to the location of the table and write the symbol
addresses for each (src, dst) tuple.
2017-06-25 21:39:16 +01:00