Raspi asm stub for loading kernel

Not quite working yet
This commit is contained in:
greg
2017-03-26 23:09:42 -07:00
parent d56c93dc4f
commit aa420a6c57
5 changed files with 97 additions and 34 deletions

View File

@@ -6,7 +6,18 @@ process:
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
clean:
rm -f main.o
rm -f output.elf
rm -f *.o
rm -f *.elf
rm -f *.a
rm -f kernel.img
rm -f kernel.map

View File

@@ -1,32 +0,0 @@
Discarded input sections
.bss 0x0000000000000000 0x0 main.o
.ARM.attributes
0x0000000000000000 0x14 main.o
Memory Configuration
Name Origin Length Attributes
*default* 0x0000000000000000 0xffffffffffffffff
Linker script and memory map
LOAD main.o
.init 0x0000000000008000 0x50
*(.init)
.init 0x0000000000008000 0x50 main.o
0x0000000000008000 _start
.text 0x0000000000008050 0x0
*(.text)
.text 0x0000000000008050 0x0 main.o
.data 0x0000000000008050 0x0
*(.data)
.data 0x0000000000008050 0x0 main.o
/DISCARD/
*(*)
OUTPUT(output.elf elf32-littlearm)

View File

@@ -0,0 +1,54 @@
#![feature(lang_items, asm)]
#![crate_type = "staticlib"]
#![no_std]
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!("") }
}
}
#[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 {}
}
*/

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