Skip to content

Commit

Permalink
refactor: use uefi-amd64.json instead of modify target.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Nov 21, 2023
1 parent f0311a6 commit 76bb5c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
39 changes: 1 addition & 38 deletions compileopts/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,43 +375,6 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
"--no-insert-timestamp",
"--no-dynamicbase",
)
} else if goos == "uefi" {
spec.Triple = strings.ReplaceAll(triple, "-unknown-uefi", "-unknown-windows-gnu")
spec.GOOS = "linux"
spec.Linker = "ld.lld"
spec.Libc = "picolibc"
spec.BuildTags = append(spec.BuildTags, "baremetal")
spec.CFlags = append(spec.CFlags,
"-ffreestanding",
"-fshort-wchar",
"-fshort-enums",
"-mno-red-zone",
)
switch goarch {
case "amd64", "i386":
spec.LDFlags = append(spec.LDFlags,
"-m", "i386pep",
"--image-base", "0x400000",
)
spec.ExtraFiles = append(spec.ExtraFiles,
"src/device/x86/cpu_"+goarch+".S",
)
case "arm64":
spec.LDFlags = append(spec.LDFlags,
"-m", "arm64pe",
)
}
spec.LDFlags = append(spec.LDFlags,
"--entry", "efi_main",
"--subsystem", "efi_application",
"-Bdynamic",
"--gc-sections",
"--no-insert-timestamp",
"--no-dynamicbase",
)
spec.ExtraFiles = append(spec.ExtraFiles,
"src/machine/uefi/asm_"+goarch+".S",
)
} else if goos == "wasip1" {
spec.GC = "" // use default GC
spec.Scheduler = "asyncify"
Expand All @@ -433,7 +396,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
}
if goarch != "wasm" {
suffix := ""
if (goos == "windows" || goos == "uefi") && goarch == "amd64" {
if goos == "windows" && goarch == "amd64" {
// Windows uses a different calling convention on amd64 from other
// operating systems so we need separate assembly files.
suffix = "_windows"
Expand Down
40 changes: 40 additions & 0 deletions targets/uefi-amd64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"build-tags": ["uefi", "baremetal", "linux", "amd64"],
"llvm-target": "x86_64-unknown-windows-gnu",
"goos": "linux",
"goarch": "amd64",
"gc": "precise",
"linker": "ld.lld",
"libc": "picolibc",
"scheduler": "tasks",
"automatic-stack-size": false,
"default-stack-size": 65536,
"cflags": [
"-Werror",
"-fshort-enums",
"-fomit-frame-pointer",
"-mfloat-abi=soft",
"-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables",
"-ffunction-sections", "-fdata-sections",
"-ffreestanding",
"-fshort-wchar",
"-mno-red-zone"
],
"ldflags": [
"-m", "i386pep",
"--image-base", "0x400000",
"--entry", "efi_main",
"--subsystem", "efi_application",
"-Bdynamic",
"--gc-sections",
"--no-insert-timestamp",
"--no-dynamicbase"
],
"extra-files": [
"src/device/x86/cpu_amd64.S",
"src/machine/uefi/asm_amd64.S",
"src/internal/task/task_stack_amd64_windows.S",
"src/runtime/asm_amd64_windows.S"
],
"gdb": ["gdb-multiarch", "gdb"]
}

0 comments on commit 76bb5c2

Please sign in to comment.