Compile init as executable using libstd

This commit is contained in:
Jeremy Soller 2016-09-09 17:13:16 -06:00
parent 3cd846a756
commit 8dd26c5239
10 changed files with 27 additions and 116 deletions

6
.gitmodules vendored
View file

@ -1,3 +1,9 @@
[submodule "rust"]
path = rust
url = https://github.com/redox-os/rust.git
[submodule "libstd"]
path = libstd
url = https://github.com/redox-os/libstd.git
[submodule "ralloc"]
path = ralloc
url = https://github.com/redox-os/ralloc

View file

@ -3,8 +3,8 @@ ARCH?=x86_64
QEMU=qemu-system-$(ARCH)
QEMUFLAGS=-serial mon:stdio -d guest_errors
RUSTCFLAGS=--target $(ARCH)-unknown-none.json -O -C soft-float
CARGOFLAGS=--target $(ARCH)-unknown-none.json -- -O -C soft-float
RUSTCFLAGS=--target $(ARCH)-unknown-redox.json -O -C soft-float --cfg redox
CARGOFLAGS=--target $(ARCH)-unknown-redox.json -- -O -C soft-float --cfg redox
ifeq ($(ARCH),arm)
LD=$(ARCH)-none-eabi-ld
@ -39,23 +39,24 @@ build/libcore.rlib: rust/src/libcore/lib.rs
mkdir -p build
./rustc.sh $(RUSTCFLAGS) -o $@ $<
build/librand.rlib: rust/src/librand/lib.rs build/libcore.rlib
./rustc.sh $(RUSTCFLAGS) -o $@ $<
build/liballoc.rlib: rust/src/liballoc/lib.rs build/libcore.rlib
mkdir -p build
./rustc.sh $(RUSTCFLAGS) -o $@ $<
build/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs build/libcore.rlib
mkdir -p build
./rustc.sh $(RUSTCFLAGS) -o $@ $<
build/libcollections.rlib: rust/src/libcollections/lib.rs build/libcore.rlib build/liballoc.rlib build/librustc_unicode.rlib
mkdir -p build
./rustc.sh $(RUSTCFLAGS) -o $@ $<
build/libinit.a: init/Cargo.toml init/src/*.rs
build/libstd.rlib: libstd/Cargo.toml libstd/src/** build/libcore.rlib build/liballoc.rlib build/librustc_unicode.rlib build/libcollections.rlib build/librand.rlib
RUSTC="./rustc.sh" cargo rustc --manifest-path $< $(CARGOFLAGS) -o $@
cp libstd/target/$(ARCH)-unknown-redox/debug/deps/*.rlib build
build/init: build/libinit.a
$(LD) -e _start --gc-sections -o $@ $<
build/init: init/Cargo.toml init/src/*.rs build/libstd.rlib
RUSTC="./rustc.sh" cargo rustc --manifest-path $< $(CARGOFLAGS) -o $@
build/libkernel.a: build/libcore.rlib build/liballoc.rlib build/libcollections.rlib build/init FORCE
mkdir -p build
@ -83,4 +84,6 @@ endif
clean:
cargo clean
cargo clean --manifest-path libstd/Cargo.toml
cargo clean --manifest-path init/Cargo.toml
rm -rf build/*

View file

@ -2,9 +2,5 @@
name = "init"
version = "0.1.0"
[lib]
[[bin]]
name = "init"
crate-type = ["staticlib"]
[dependencies]
syscall = { path = "../syscall/" }

View file

@ -1,99 +0,0 @@
#![feature(asm)]
#![feature(lang_items)]
#![no_std]
#[macro_use]
extern crate syscall;
use syscall::{exit, write};
#[no_mangle]
pub unsafe extern fn _start() {
let string = b"Hello, World!\n";
write(1, string);
exit(0);
}
#[cfg(not(test))]
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[cfg(not(test))]
/// Required to handle panics
#[lang = "panic_fmt"]
extern "C" fn panic_fmt(_fmt: ::core::fmt::Arguments, _file: &str, _line: u32) -> ! {
write(2, b"panic\n");
exit(127);
loop {}
}
/// Memcpy
///
/// Copy N bytes of memory from one location to another.
#[no_mangle]
pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
n: usize) -> *mut u8 {
let mut i = 0;
while i < n {
*dest.offset(i as isize) = *src.offset(i as isize);
i += 1;
}
dest
}
/// Memmove
///
/// Copy N bytes of memory from src to dest. The memory areas may overlap.
#[no_mangle]
pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
n: usize) -> *mut u8 {
if src < dest as *const u8 {
let mut i = n;
while i != 0 {
i -= 1;
*dest.offset(i as isize) = *src.offset(i as isize);
}
} else {
let mut i = 0;
while i < n {
*dest.offset(i as isize) = *src.offset(i as isize);
i += 1;
}
}
dest
}
/// Memset
///
/// Fill a block of memory with a specified value.
#[no_mangle]
pub unsafe extern fn memset(s: *mut u8, c: i32, n: usize) -> *mut u8 {
let mut i = 0;
while i < n {
*s.offset(i as isize) = c as u8;
i += 1;
}
s
}
/// Memcmp
///
/// Compare two blocks of memory.
#[no_mangle]
pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
let mut i = 0;
while i < n {
let a = *s1.offset(i as isize);
let b = *s2.offset(i as isize);
if a != b {
return a as i32 - b as i32
}
i += 1;
}
0
}

3
init/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
pub fn main() {
println!("Hello, World!");
}

1
libstd Submodule

@ -0,0 +1 @@
Subproject commit c6d6f70869b435a6c0940d9eb8b0dd6f2ec03663

1
ralloc Submodule

@ -0,0 +1 @@
Subproject commit 65495da00fc74e40b0047749a5d498547a07dfaa

2
rust

@ -1 +1 @@
Subproject commit 46a90c60ab79d65a09330448becd01c78511ea77
Subproject commit f1f40f850e2546c2c187514e3d61d17544ba433f

View file

@ -1,2 +1,2 @@
#!/bin/bash
RUST_BACKTRACE=1 rustc -L build $*
RUST_BACKTRACE=1 rustc -L build --cfg redox $*

View file

@ -9,7 +9,7 @@
"vendor": "unknown",
"target-family": "redox",
"pre-link-args": ["-m64", "-nostdlib", "-static"],
"features": "-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2",
"features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float",
"dynamic-linking": false,
"executables": true,
"relocation-model": "static",
@ -21,5 +21,5 @@
"no-compiler-rt": true,
"no-default-libraries": true,
"position-independent-executables": false,
"has-elf-tls": false
"has-elf-tls": true
}