Compile rust

Write a simple rust function, call it from C
This commit is contained in:
greg
2015-09-20 23:57:20 -07:00
parent 82b80dc56c
commit 05dd3ff9e8
3 changed files with 21 additions and 3 deletions

View File

@@ -15,10 +15,11 @@ baremetal_gamarjoba: baremetal_gamarjoba.asm include.c
run_baremetal_gamarjoba: baremetal_gamarjoba
qemu-system-i386 -kernel baremetal_gamarjoba
keyboard: keyboard.asm c_keyboard.c
keyboard: keyboard.asm c_keyboard.c keyboard.rs
gcc -m32 -ffreestanding -o c_keyboard.o -c c_keyboard.c
rustc --emit obj -o rust_keyboard.o --target i686-unknown-linux-gnu keyboard.rs
nasm -f elf32 keyboard.asm
ld -m elf_i386 -nostdlib -T linker.ld keyboard.o c_keyboard.o -o keyboard
ld -m elf_i386 -nostdlib -T linker.ld keyboard.o c_keyboard.o rust_keyboard.o -o keyboard
run_keyboard: keyboard
qemu-system-i386 -kernel keyboard

View File

@@ -1,10 +1,13 @@
extern int write_to_coord(int x, int y, int x86_specifier);
extern int clear(int x86_specifier);
extern int rust_get_int();
void print_int(int, int);
void c_entry() {
write_to_coord(1,1, (0xf0 << 8) | 'm');
print_int(0x73f, 10);
int from_rust = rust_get_int();
print_int(from_rust, 10);
}
void print_int(int input, int coord) {

14
keyboard.rs Normal file
View File

@@ -0,0 +1,14 @@
#![feature(lang_items, start, no_core)]
#![no_core]
#![no_main]
#[no_mangle]
pub extern fn rust_get_int() -> i32 {
return 16;
}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
#[lang = "sized"] trait Sized {}
#[lang = "copy"] trait Copy {}