Skip to content

Commit 0560f65

Browse files
committed
add userland target
1 parent 05d6bcd commit 0560f65

3 files changed

Lines changed: 76 additions & 2 deletions

File tree

build/linker-scripts/userland.ld

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Tell the linker that we want an x86_64 ELF64 output file */
2+
OUTPUT_FORMAT(elf64-x86-64)
3+
OUTPUT_ARCH(i386:x86-64)
4+
5+
/* We want the symbol `_start` to be our entry point */
6+
ENTRY(_start)
7+
8+
/* Define the program headers we want so the bootloader gives us the right */
9+
/* MMU permissions */
10+
PHDRS
11+
{
12+
null PT_NULL FLAGS(0) ; /* Null segment */
13+
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
14+
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */
15+
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
16+
}
17+
18+
SECTIONS
19+
{
20+
. = 0x40000;
21+
22+
.text : {
23+
*(.text .text.*)
24+
} :text
25+
26+
/* Move to the next memory page for .rodata */
27+
. += CONSTANT(MAXPAGESIZE);
28+
29+
.rodata : {
30+
*(.rodata .rodata.*)
31+
} :rodata
32+
33+
/* Move to the next memory page for .data */
34+
. += CONSTANT(MAXPAGESIZE);
35+
36+
.data : {
37+
*(.data .data.*)
38+
} :data
39+
40+
.bss : {
41+
*(COMMON)
42+
*(.bss .bss.*)
43+
} :data
44+
45+
.got : {
46+
*(.got)
47+
} :data
48+
49+
. += CONSTANT(MAXPAGESIZE);
50+
51+
}

build/targets/x86_64-userland.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"llvm-target": "x86_64-unknown-none",
3+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
4+
"arch": "x86_64",
5+
"target-endian": "little",
6+
"target-pointer-width": 64,
7+
"target-c-int-width": 32,
8+
"os": "none",
9+
"executables": true,
10+
"linker-flavor": "ld.lld",
11+
"linker": "rust-lld",
12+
"disable-redzone": true,
13+
"panic-strategy": "abort",
14+
"features": "-mmx,-sse,+soft-float",
15+
"rustc-abi": "x86-softfloat",
16+
"code-model": "small",
17+
"pre-link-args": {
18+
"ld.lld": [
19+
"--gc-sections",
20+
"--script=./build/linker-scripts/userland.ld"
21+
]
22+
}
23+
}

build/xtask/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn build(sh: &Shell, rl: bool, mut args: Arguments) -> Result<()> {
128128
"cargo build
129129
{release...}
130130
-p init
131-
--target ./build/targets/{target}.json
131+
--target ./build/targets/{target}-userland.json
132132
-Z build-std=core,alloc,compiler_builtins
133133
-Z build-std-features=compiler-builtins-mem"
134134
)
@@ -138,7 +138,7 @@ fn build(sh: &Shell, rl: bool, mut args: Arguments) -> Result<()> {
138138

139139
cmd!(
140140
sh,
141-
"cp {xernel_dir}/target/x86_64/{build_dir}/init {xernel_dir}/target/"
141+
"cp {xernel_dir}/target/x86_64-userland/{build_dir}/init {xernel_dir}/target/"
142142
)
143143
.run()?;
144144

0 commit comments

Comments
 (0)