This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add Rust example. Closes #73

  • Loading branch information...
IanSeyler committed Nov 12, 2014
1 parent 069bbb2 commit 740d2b2359f51283cc269c26a6121a156b3db285
Showing with 74 additions and 0 deletions.
  1. +74 −0 programs/rust.rs
View
@@ -0,0 +1,74 @@
// Rust on BareMetal - Tested with Rust 0.13.0-nightly
// rustc -O --crate-type lib -o rust.o --emit obj rust.rs
// ld -T app.ld -o rust.app rust.o
#![no_std]
#![allow(ctypes)]
#![feature(lang_items)]
#[lang="sized"]

This comment has been minimized.

Show comment
Hide comment
@edef1c

edef1c Nov 12, 2014

Why not link to libcore instead? libcore provides everything from the Rust stdlib that works in a freestanding environment.

@edef1c

edef1c Nov 12, 2014

Why not link to libcore instead? libcore provides everything from the Rust stdlib that works in a freestanding environment.

This comment has been minimized.

Show comment
Hide comment
@IanSeyler

IanSeyler Nov 12, 2014

Member

This was just a quick port of ragingSloth/rustboot@0a55ab5

I don't know much about Rust myself but this is open for updates.

@IanSeyler

IanSeyler Nov 12, 2014

Member

This was just a quick port of ragingSloth/rustboot@0a55ab5

I don't know much about Rust myself but this is open for updates.

trait Sized {}
enum Color {
Black = 0,
Red = 1,
Green = 2,
Blue = 3,
Yellow = 4,
Purple = 5,
Cyan = 6,
LightGray = 7,
DarkGray = 8,
LightRed = 9,
LightGreen = 10,
LightBlue = 11,
LightYellow = 12,
LightPurple = 13,
LightCyan = 14,
White = 15,
}
enum Option<T> {
None,
Some(T)
}
struct IntRange {
cur: int,
max: int
}
impl IntRange {
fn next(&mut self) -> Option<int> {
if self.cur < self.max {
self.cur += 1;
Some(self.cur - 1)
} else {
None
}
}
}
fn range(lo: int, hi: int) -> IntRange {
IntRange { cur: lo, max: hi }
}
fn clear_screen(background: Color) {
let mut r = range(0, 80 * 25);
loop {
match r.next() {
Some(x) => {
unsafe {
*((0xb8000 + x * 2) as *mut u16) = (background as u16) << 12;
}
},
None => {break}
}
}
}
#[no_mangle]
#[no_split_stack]
pub fn main() {
clear_screen(LightRed);
}

0 comments on commit 740d2b2

Please sign in to comment.