| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("$zx/public/gn/toolchain/environment.gni") |
| import("$zx/public/gn/toolchain/environment_redirect.gni") |
| |
| # The Multiboot trampoline gets its own toolchain to build x86-32 code. |
| if (current_toolchain == default_toolchain) { |
| # Define the special toolchain itself only in the default toolchain. |
| environment("multiboot") { |
| cpu = "x64" |
| configs += standard_fuchsia_configs + [ ":multiboot_config" ] |
| globals = { |
| is_kernel = true |
| } |
| strip = "--strip-sections" |
| } |
| } else if (toolchain.environment == "multiboot") { |
| # This is the top config for all code in the multiboot_toolchain. |
| config("multiboot_config") { |
| configs = [ |
| "$zx/kernel:headers", |
| "$zx/kernel:standalone", |
| "$zx/kernel:warnings", |
| "$zx/kernel/arch/x86:kernel", |
| "$zx/public/gn/config:no_sanitizers", |
| ] |
| compiler_flags = [ |
| "-m32", |
| "-mregparm=3", |
| "-fno-pic", |
| ] |
| asmflags = compiler_flags |
| cflags = compiler_flags |
| ldflags = compiler_flags |
| if (is_gcc) { |
| ldflags += [ "-no-pie" ] |
| } else { |
| ldflags += [ "-Wl,--no-pie" ] |
| } |
| } |
| |
| # We could make a Multiboot image meant to be loaded without ELF headers |
| # and do `objcopy -O binary` here. But there's no reason to, and having |
| # an ELF binary to look at is nicer. To remove the ELF headers instead, |
| # the linker script would need to remove `+ SIZEOF_HEADERS` and then the |
| # multiboot header would be first thing in the raw binary. The toolchain |
| # implicitly strips executables, so `multiboot.bin` is a lean, fully |
| # stripped ELF/Multiboot image. |
| executable("multiboot") { |
| output_extension = "bin" |
| output_dir = root_build_dir |
| output_path = rebase_path("$output_dir/$target_name.$output_extension", |
| root_build_dir) |
| metadata = { |
| # For the //:images build_api_module(). |
| images = [] |
| foreach(name, |
| [ |
| "multiboot-kernel", |
| "qemu-kernel", |
| ]) { |
| images += [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| name = name |
| type = "kernel" |
| path = output_path |
| cpu = current_cpu |
| }, |
| ] |
| } |
| } |
| sources = [ |
| "multiboot-main.c", |
| "multiboot-start.S", |
| "paging.c", |
| "trampoline.c", |
| "util.c", |
| ] |
| deps = [ |
| "$zx/kernel/arch/x86/page_tables:headers", |
| "$zx/kernel/platform/pc:headers", |
| "$zx/system/ulib/libzbi", |
| ] |
| ldflags = [ "-Wl,-T," + rebase_path("multiboot.ld", root_build_dir) ] |
| inputs = [ |
| "multiboot.ld", |
| ] |
| } |
| } else { |
| # In any other toolchain, just redirect to the proper toolchain. |
| environment_redirect("multiboot") { |
| environment_label = ":multiboot" |
| deps = [ |
| ":multiboot", |
| ] |
| } |
| } |