Skip to content

Commit

Permalink
Refactored linker script and boot to be more architecture agnostic.
Browse files Browse the repository at this point in the history
Moved the linker script dependency to a dependency of i386. Added
--spawn_strategy=standalone to the qemu.sh script. Unfortunately, there
is a bug in bazel seen here,
bazelbuild/bazel#716, that requires sandboxing
to be disabled to allow the linker script dependency to persist to the
main kernel dependency. It's not ideal but if they ever fix this bug,
the code as is should function with sandboxing.
  • Loading branch information
RyRose committed Nov 20, 2017
1 parent 129c6d1 commit a5f1ee2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
4 changes: 0 additions & 4 deletions kernel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ cc_binary (
"//kernel/arch:gdt",
"//kernel/arch:tty",
"//kernel/arch:memory_detection",
"//kernel/arch/i386:linker.ld",
":crt"
],
linkopts = [
"-T kernel/arch/i386/linker.ld"
],
visibility = ["//visibility:public"],
)

Expand Down
8 changes: 2 additions & 6 deletions kernel/arch/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ arch_library(name = "gdt")

arch_library(name = "memory_detection")

cc_library(
name = "boot",
deps = select({
"//tools:i386" : ["//kernel/arch/i386/boot"],
}),
)
arch_library(name = "boot")

4 changes: 4 additions & 0 deletions kernel/arch/boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef KERNEL_ARCH_BOOT_H
#define KERNEL_ARCH_BOOT_H

#endif // KERNEL_ARCH_BOOT_H
3 changes: 0 additions & 3 deletions kernel/arch/i386/BUILD

This file was deleted.

9 changes: 6 additions & 3 deletions kernel/arch/i386/boot/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ cc_library(
srcs = [
"boot.S",
"crti.S",
"crtn.S"
"crtn.S",
],
deps = [
":multiboot",
"linker.ld"
],
linkopts = [
"-T $(location linker.ld)"
],
alwayslink = 1,
)
Expand All @@ -21,6 +25,5 @@ cc_library(
hdrs = [
"meminfo.h",
"multiboot.h"
],
alwayslink = 1,
]
)
12 changes: 6 additions & 6 deletions kernel/arch/i386/linker.ld → kernel/arch/i386/boot/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ SECTIONS
/* Begin putting sections at 1 MiB, a conventional place for kernels to be
loaded at by the bootloader. */
. = 1M;
kernel_start = .;

/* First put the multiboot header, as it is required to be put very early
early in the image or the bootloader won't recognize the file format.
Next we'll put the .text section. */
.text BLOCK(4K) : ALIGN(4K)
.text ALIGN(4K) :
{
*(.multiboot)
*(.text)
}

/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
.rodata ALIGN(4K) :
{
*(.rodata)
}

/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
.data ALIGN(4K) :
{
*(.data)
}

/* Read-write data (uninitialized) and stack */
.bss BLOCK(4K) : ALIGN(4K)
.bss ALIGN(4K) :
{
*(COMMON)
*(.bss)
}

/* The compiler may produce other sections, put them in the proper place in
in this file, if you'd like to include them in the final kernel. */
kernel_end = .;
}
2 changes: 1 addition & 1 deletion qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ if [ ! -d "tools/compilers/$TARGET" ]; then
./tools/install.sh $TARGET || exit $?;
fi

bazel build :iso --crosstool_top=//tools:toolchain --cpu=$1 --host_cpu=$1 --strip=never || exit $?
bazel build :iso --spawn_strategy=standalone --crosstool_top=//tools:toolchain --cpu=$1 --host_cpu=$1 --strip=never --verbose_failures || exit $?
qemu-system-$1 -cdrom bazel-genfiles/os.iso -monitor stdio -s

0 comments on commit a5f1ee2

Please sign in to comment.