Skip to content

Commit 70969f4

Browse files
committed
initial commit
0 parents  commit 70969f4

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

boards/realview-eb-mpcore/board.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
This contains the board code for the ARM realview-eb-mpcore. It
3+
contains everything specific to the board that is abstracted
4+
away from the kernel code.
5+
6+
It is produced at this time as a Rust library which is then used by
7+
the kernel when it is built.
8+
*/

build

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rustc main.rs --opt-level 3 --emit=obj --target=arm-unknown-linux-gnueabi
2+
arm-ld main.o -o rustk.elf
3+
arm-objcopy -j .text -O binary rustk.elf rustk.bin

core.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
struct Global {
2+
heapoffset: uint,
3+
curheapndx: uint
4+
}
5+
6+
static mut GLOBAL: Global = Global {
7+
heapoffset: 0,
8+
curheapndx: 0
9+
};
10+
11+
#[lang="exchange_malloc"]
12+
#[inline]
13+
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
14+
// The most simple heap possible!
15+
let ptr: uint;
16+
ptr = GLOBAL.heapoffset + GLOBAL.curheapndx;
17+
GLOBAL.curheapndx += size;
18+
19+
ptr as *mut u8
20+
}
21+
22+
#[lang="exchange_free"]
23+
#[inline]
24+
unsafe fn exchange_free(ptr: *mut u8, old_size: uint, align: uint) {
25+
// The most simple heap possible. It does not support
26+
// deallocation!
27+
}

main.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#![feature(lang_items)]
2+
#![no_std]
3+
#![allow(unused_variables)]
4+
#![allow(dead_code)]
5+
#![feature(asm)]
6+
7+
mod core;
8+
9+
#[lang="sized"]
10+
trait Sized {}
11+
#[lang="sync"]
12+
trait Sync {}
13+
14+
static GDT: [u32, ..5] = [0, 1, 2, 3, 4];
15+
16+
#[lang = "exchange_heap"]
17+
#[experimental = "may be renamed; uncertain about custom allocator design"]
18+
pub static HEAP: () = ();
19+
20+
/// A type that represents a uniquely-owned value.
21+
#[lang = "owned_box"]
22+
#[unstable = "custom allocators will add an additional type parameter (with default)"]
23+
pub struct Box<T>(*mut T);
24+
25+
#[start]
26+
fn main(argc: int, argv: *const *const u8) -> int {
27+
unsafe {
28+
asm!("mov sp, $0" : : "i"(0x2000u));
29+
}
30+
31+
kstart();
32+
33+
unsafe {
34+
asm!("b kstart");
35+
/*
36+
These are things that I really do not want to implement
37+
at the moment. Also my `as` implementation has broken
38+
and I do not want to use `gas`, also my goal was to get
39+
everything in Rust - does this not count!!
40+
*/
41+
asm!("__morestack:");
42+
asm!("__aeabi_unwind_cpp_pr0:");
43+
}
44+
45+
0
46+
}
47+
48+
const SERIAL_BASE: u32 = 0x10009000;
49+
const SERIAL_FLAG_REGISTER: u32 = 0x18;
50+
const SERIAL_BUFFER_FULL: u32 = 1 << 15;
51+
52+
fn kserdbg_putc(c: u8) {
53+
unsafe {
54+
let mem: *mut u32 = (SERIAL_BASE + SERIAL_FLAG_REGISTER) as *mut u32;
55+
56+
while (*mem & SERIAL_BUFFER_FULL) == 0 {}
57+
58+
let mem: *mut u32 = SERIAL_BASE as *mut u32;
59+
60+
*mem = c as u32;
61+
}
62+
}
63+
64+
#[no_mangle]
65+
extern fn kstart() {
66+
/*
67+
Print A then B then C to the serial h/w port.
68+
*/
69+
let x: Box<uint> = box 3u;
70+
71+
kserdbg_putc(65);
72+
kserdbg_putc(66);
73+
kserdbg_putc(67);
74+
loop { }
75+
}

qemurun

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qemu-system-arm -m 8 -kernel rustk.bin -serial stdio -machine realview-eb-mpcore

0 commit comments

Comments
 (0)