Skip to content

Instantly share code, notes, and snippets.

@alilee
Created November 17, 2015 10:16
Show Gist options
  • Save alilee/d7030b2901c564427a97 to your computer and use it in GitHub Desktop.
Save alilee/d7030b2901c564427a97 to your computer and use it in GitHub Desktop.
{
"arch": "arm",
"cpu": "cortex-a8",
"data-layout": "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:64-v128:64:128-a:0:32-n32-S64",
"disable-redzone": true,
"executables": true,
"llvm-target": "arm-none-eabi",
"morestack": false,
"os": "none",
"relocation-model": "static",
"target-endian": "little",
"target-word-size": "32",
"target-pointer-width": "32",
"no-compiler-rt" : true
}
#![feature(no_std, lang_items)]
#![no_std]
#[no_mangle]
pub extern fn rust_main() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! {loop{}}
ENTRY(_reset)
SECTIONS
{
. = 0x10000;
.startup . : { build/startup.o(.text) }
.text : { *(.text.rust_main) }
. = ALIGN(0x1000);
stack = .;
. = . + 0x1000; /* 4kB of stack memory */
stack_top = .;
}
CPU=arm926ej-s
TARGET=arm-none-eabi
AS=arm-none-eabi-as
CC=arm-none-eabi-gcc
RC=rustc
LD=arm-none-eabi-ld
OBJCOPY=arm-none-eabi-objcopy
OBJDUMP=arm-none-eabi-objdump
OBJS=$(patsubst %,%.o,$(basename $(wildcard *.[cs] *.rs)))
ASFLAGS = -mcpu=cortex-a8
CFLAGS = -Og
build/%.o: src/%.s
@mkdir -p $(shell dirname $@)
$(AS) $(ASFLAGS) -g $< -o $@
%.elf: %.ld $(OBJS)
$(LD) -T $^ -o $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
$(OBJDUMP) -dS $< > $*.code
kernel := build/kernel
rust_os := target/$(TARGET)/debug/libarm.a
linker_script := src/linker.ld
assembly_source_files := $(wildcard src/*.s)
assembly_object_files := $(patsubst src/%.s, build/%.o, $(assembly_source_files))
.PHONY: all clean run iso cargo
all: $(kernel)
clean:
@cargo clean
@rm -rf build
$(kernel).elf: cargo $(rust_os) $(assembly_object_files) $(linker_script)
$(LD) -n --gc-sections -T $(linker_script) -o $@ $(assembly_object_files) $(rust_os)
$(kernel): $(kernel).elf
$(OBJCOPY) -O binary $< $@
$(OBJDUMP) -dS $< > $(kernel).code
cargo:
@cargo rustc --target $(TARGET) -- -Z no-landing-pads
.global _reset
.global rust_main
_reset:
LDR sp, =stack_top
BL rust_main
B .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment