Moving files to rust-xargo dir

This commit is contained in:
greg
2017-03-30 03:09:29 -07:00
parent c55ff680d4
commit 17466c6547
5 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
all: process
process:
arm-none-eabi-as -I asm -o main.o main.s
arm-none-eabi-ld --no-undefined main.o -Map kernel.map -o output.elf -T kernel.ld
arm-none-eabi-objcopy output.elf -O binary kernel.img
#arm-none-eabi-ld --no-undefined rust_kernel.o -Map kernel.map -o rust_kernel.elf -T kernel.ld
#rust_kernel: rust_kernel.rs
# rustc --target arm-unknown-linux-gnueabihf --emit=obj rust_kernel.rs
# arm-none-eabi-gcc -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles rust_kernel.o -o rust_kernel.elf
# arm-none-eabi-objcopy rust_kernel.elf -O binary kernel.img
rust_loader.o: rust_loader.s
arm-none-eabi-gcc -mcpu=arm1176jzf-s -fpic -ffreestanding -c rust_loader.s -o rust_loader.o
#rust_kernel.o: rust_kernel.rs
# rustc --target ./arm-none-eabihf.json --emit=obj -Cpanic=abort -C lto rust_kernel.rs
kernel.elf: rust_kernel.o rust_loader.o
arm-none-eabi-gcc -T rust_linker_script.ld -o kernel.elf -ffreestanding -nostdlib rust_loader.o rust_kernel.o
clean:
rm -f *.o
rm -f *.elf
rm -f *.a
rm -f kernel.img
rm -f kernel.map

View File

@@ -0,0 +1,15 @@
{
"llvm-target": "arm-none-eabihf",
"target-endian": "little",
"target-pointer-width": "32",
"os": "none",
"env": "eabi",
"vendor": "unknown",
"arch": "arm",
"linker": "arm-none-eabi-gcc",
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"executables": true,
"relocation-model": "static",
"no-compiler-rt": true
}

View File

@@ -0,0 +1,43 @@
ENTRY(_start)
SECTIONS {
. = 0x8000;
_start = .;
_text_start = .;
.text :
{
KEEP(*(.text.boot))
*(.text)
}
. = ALIGN(4096);
_text_end = .;
_rodata_start = .;
.rodata :
{
*(.rodata);
}
. = ALIGN(4096);
_rodata_end = .;
_data_start = .;
.data :
{
*(.data)
}
. = ALIGN(4096);
_data_end = .;
_bss_start = .;
.bss :
{
*(.bss)
}
. = ALIGN(4096);
_bss_end = .;
_end = .;
}

View File

@@ -0,0 +1,30 @@
.section ".text.boot"
.globl _start
_start:
/* r15 (SP) begins execution at 0x8000 */
mov sp, #0x8000
/* zero out bss_start to bss_end */
ldr r4, =_bss_start
ldr r9, =_bss_end
mov r5, #0
mov r6, #0
mov r7, #0
mov r8, #0
b 2f
1:
stmia r4!, {r5-r8}
2:
cmp r4, r9
blo 1b // branch less than
/* call kernel_main */
ldr r3, =kernel_main
blx r3 /* branch and change processor state from thumb -> arm */
halt:
wfe /* wait for event */
b halt

View File

@@ -0,0 +1,56 @@
#![feature(lang_items, asm)]
#![crate_type = "staticlib"]
#![no_std]
#[no_mangle]
pub extern "C" fn __eabi_unwind_cpp_pr0() { }
#[cfg(not(test))]
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn eh_personality() {}
#[cfg(not(test))]
#[lang = "panic_fmt"]
#[no_mangle]
pub extern "C" fn panic_fmt() -> ! { loop {}}
#[cfg(not(test))]
#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern "C" fn eh_unwind_resume() { }
#[allow(non_snake_case)]
#[no_mangle]
pub extern "C" fn _Unwind_Resume() -> ! {
loop {}
}
const GPIO_BASE: u32 = 0x2020000;
#[no_mangle]
pub extern "C" fn kernel_main() {
let gpio = GPIO_BASE as *const u32;
let led_on = unsafe { gpio.offset(8) as *mut u32 };
let led_off = unsafe { gpio.offset(11) as *mut u32 };
loop {
unsafe { *(led_on) = 1 << 15 };
sleep(500_000);
unsafe { *(led_off) = 1 << 15 };
sleep(500_000);
unsafe { *(led_on) = 1 << 15 };
sleep(200_000);
unsafe { *(led_off) = 1 << 15 };
sleep(200_000);
}
}
fn sleep(value: u32) {
for _ in 1..value {
unsafe { asm!("") }
}
}