Skip to content
Snippets Groups Projects
Verified Commit ab2aaa9c authored by Jeremy Soller's avatar Jeremy Soller
Browse files

WIP: convert to rust

parent c96eb83d
No related branches found
No related tags found
No related merge requests found
[build]
rustflags = [
# Kernel should preserve floating-point registers
"-Csoft-float",
]
[unstable]
build-std = ["core", "alloc", "compiler_builtins"]
build-std-features = ["panic-unwind"]
/build
/target
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "redox_bootloader"
version = "0.1.0"
[package]
name = "redox_bootloader"
version = "0.1.0"
edition = "2018"
[lib]
name = "bootloader"
path = "src/lib.rs"
crate-type = ["staticlib"]
[dependencies]
Makefile 0 → 100644
ARCH=x86
TARGET=$(ARCH)-unknown-none
export LD=ld -m elf_i386
export OBJCOPY=objcopy
export PARTED=parted
export QEMU=qemu-system-i386
export RUST_TARGET_PATH=$(CURDIR)/targets
all: build/bootloader.bin
clean:
rm -rf build
build/libbootloader.a: Cargo.lock Cargo.toml src/**
mkdir -p build
cargo rustc --lib --target $(TARGET) --release -- -C soft-float -C debuginfo=2 --emit link=$@
build/bootloader.elf: linkers/$(ARCH).ld build/libbootloader.a
mkdir -p build
$(LD) --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libbootloader.a && \
$(OBJCOPY) --only-keep-debug $@ $@.sym && \
$(OBJCOPY) --strip-debug $@
build/bootloader.bin: build/bootloader.elf $(ARCH)/**
mkdir -p build
nasm -f bin -o $@ -l $@.lst -D ARCH_$(ARCH) -D KERNEL=$< -i$(ARCH) $(ARCH)/disk.asm
build/harddrive.bin: build/bootloader.bin
mkdir -p build
rm -f $@.partial
fallocate -l 256MiB $@.partial
$(PARTED) -s -a minimal $@.partial mklabel msdos
$(PARTED) -s -a minimal $@.partial mkpart primary 1MiB 100%
dd if=$< of=$@.partial bs=1 count=446 conv=notrunc
dd if=$< of=$@.partial bs=512 skip=1 seek=1 conv=notrunc
mv $@.partial $@
qemu: build/harddrive.bin
$(QEMU) \
-d cpu_reset \
-d guest_errors \
-smp 4 -m 2048 \
-chardev stdio,id=debug,signal=off,mux=on \
-serial chardev:debug \
-mon chardev=debug \
-machine q35 \
-net none \
-enable-kvm \
-cpu host \
-drive file=$<,format=raw
ENTRY(kstart)
OUTPUT_FORMAT(elf32-i386)
SECTIONS {
. = 0x100000;
. += SIZEOF_HEADERS;
. = ALIGN(4096);
.text : {
__text_start = .;
*(.text*)
. = ALIGN(4096);
__text_end = .;
}
.rodata : {
__rodata_start = .;
*(.rodata*)
. = ALIGN(4096);
__rodata_end = .;
}
.data : {
__data_start = .;
*(.data*)
. = ALIGN(4096);
__data_end = .;
__bss_start = .;
*(.bss*)
. = ALIGN(4096);
__bss_end = .;
}
.tdata : {
__tdata_start = .;
*(.tdata*)
. = ALIGN(4096);
__tdata_end = .;
__tbss_start = .;
*(.tbss*)
. += 8;
. = ALIGN(4096);
__tbss_end = .;
}
__end = .;
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note*)
*(.rel.eh_frame*)
}
}
nightly-2021-06-15
#![no_std]
#![feature(lang_items)]
#![feature(llvm_asm)]
mod panic;
#[no_mangle]
pub unsafe extern "C" fn kstart() -> ! {
loop {}
}
//! Intrinsics for panic handling
use core::alloc::Layout;
use core::panic::PanicInfo;
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
/// Required to handle panics
#[panic_handler]
#[no_mangle]
pub extern "C" fn rust_begin_unwind(info: &PanicInfo) -> ! {
//println!("BOOTLOADER PANIC: {}", info);
loop {
unsafe {
llvm_asm!("hlt" : : : : "intel", "volatile");
}
}
}
#[lang = "oom"]
#[no_mangle]
#[allow(improper_ctypes_definitions)] // Layout is not repr(C)
pub extern fn rust_oom(_layout: Layout) -> ! {
panic!("kernel memory allocation failed");
}
#[allow(non_snake_case)]
#[no_mangle]
/// Required to handle panics
pub extern "C" fn _Unwind_Resume() -> ! {
loop {
unsafe {
llvm_asm!("hlt" : : : : "intel", "volatile");
}
}
}
{
"llvm-target": "i686-unknown-none",
"target-endian": "little",
"target-pointer-width": "32",
"target-c-int-width": "32",
"data-layout": "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128",
"arch": "x86",
"os": "none",
"env": "",
"vendor": "unknown",
"linker-flavor": "gcc",
"target-family": "redox",
"pre-link-args": {
"gcc": ["-m32", "-nostdlib", "-static"]
},
"features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float",
"dynamic-linking": false,
"executables": false,
"relocation-model": "pic",
"code-model": "kernel",
"disable-redzone": true,
"eliminate-frame-pointer": false,
"exe-suffix": "",
"has-rpath": false,
"no-compiler-rt": true,
"no-default-libraries": true,
"position-independent-executables": false,
"has-elf-tls": true
}
File moved
File moved
File moved
File moved
File moved
......@@ -3,8 +3,8 @@ sectalign off
%include "bootsector.asm"
startup_start:
%ifdef ARCH_i386
%include "startup-i386.asm"
%ifdef ARCH_x86
%include "startup-x86.asm"
%endif
%ifdef ARCH_x86_64
......
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment