From 8dd26c5239acb4150c5c6d7336447d0d43b0caf5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 9 Sep 2016 17:13:16 -0600 Subject: [PATCH] Compile init as executable using libstd --- .gitmodules | 6 +++ Makefile | 19 ++++---- init/Cargo.toml | 6 +-- init/src/lib.rs | 99 --------------------------------------- init/src/main.rs | 3 ++ libstd | 1 + ralloc | 1 + rust | 2 +- rustc.sh | 2 +- x86_64-unknown-redox.json | 4 +- 10 files changed, 27 insertions(+), 116 deletions(-) delete mode 100644 init/src/lib.rs create mode 100644 init/src/main.rs create mode 160000 libstd create mode 160000 ralloc diff --git a/.gitmodules b/.gitmodules index c38b4a5..e033dc2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 9101b60..232fd4e 100644 --- a/Makefile +++ b/Makefile @@ -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/* diff --git a/init/Cargo.toml b/init/Cargo.toml index 1aeb3c2..cc77b50 100644 --- a/init/Cargo.toml +++ b/init/Cargo.toml @@ -2,9 +2,5 @@ name = "init" version = "0.1.0" -[lib] +[[bin]] name = "init" -crate-type = ["staticlib"] - -[dependencies] -syscall = { path = "../syscall/" } diff --git a/init/src/lib.rs b/init/src/lib.rs deleted file mode 100644 index 47c6e5f..0000000 --- a/init/src/lib.rs +++ /dev/null @@ -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 -} diff --git a/init/src/main.rs b/init/src/main.rs new file mode 100644 index 0000000..0912780 --- /dev/null +++ b/init/src/main.rs @@ -0,0 +1,3 @@ +pub fn main() { + println!("Hello, World!"); +} diff --git a/libstd b/libstd new file mode 160000 index 0000000..c6d6f70 --- /dev/null +++ b/libstd @@ -0,0 +1 @@ +Subproject commit c6d6f70869b435a6c0940d9eb8b0dd6f2ec03663 diff --git a/ralloc b/ralloc new file mode 160000 index 0000000..65495da --- /dev/null +++ b/ralloc @@ -0,0 +1 @@ +Subproject commit 65495da00fc74e40b0047749a5d498547a07dfaa diff --git a/rust b/rust index 46a90c6..f1f40f8 160000 --- a/rust +++ b/rust @@ -1 +1 @@ -Subproject commit 46a90c60ab79d65a09330448becd01c78511ea77 +Subproject commit f1f40f850e2546c2c187514e3d61d17544ba433f diff --git a/rustc.sh b/rustc.sh index 4278e41..9121ff0 100755 --- a/rustc.sh +++ b/rustc.sh @@ -1,2 +1,2 @@ #!/bin/bash -RUST_BACKTRACE=1 rustc -L build $* +RUST_BACKTRACE=1 rustc -L build --cfg redox $* diff --git a/x86_64-unknown-redox.json b/x86_64-unknown-redox.json index 34400b2..49e840b 100644 --- a/x86_64-unknown-redox.json +++ b/x86_64-unknown-redox.json @@ -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 }