Skip to content

Commit

Permalink
Default handlers for first 16 vectors, delay in main
Browse files Browse the repository at this point in the history
The app seems valid, but crashes in the runtime, in reset handler.
  • Loading branch information
0xc0170 committed Dec 12, 2014
1 parent 0bf13a3 commit 9276d25
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*.so
*.rlib
*.dll
*.elf
*.bin
*.map

# Executables
*.exe
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ RUSTFLAGS += -C relocation-model=static
RUSTFLAGS += --opt-level $(OPT) -g -Z no-landing-pads
RUSTFLAGS += -A dead_code -A unused_variables

LDFLAGS = -T kl25z.ld
LDFLAGS += -Map=frdm-kl25z-blinky.map
LDFLAGS += --gc-sections #-print-gc-sections
LDFLAGS = -T kl25z.ld
LDFLAGS += -Map=frdm-kl25z-blinky.map
LDFLAGS += --gc-sections
LDFLAGS += #-print-gc-sections

.SUFFIXES: .o .rs .c

Expand Down
57 changes: 51 additions & 6 deletions init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate core;
// extern crate core;

use kl25z_map::Sim;
use kl25z_map::Port;
Expand All @@ -33,10 +33,23 @@ extern {


#[link_section=".vector_table"]
pub static ISR_VECTOR: [Option<unsafe extern fn()>, .. 3] = [
pub static ISR_VECTOR: [Option<unsafe extern fn()>, .. 16] = [
Option::Some(__StackTop),
Option::Some(reset_handler),
Option::Some(nmi_handler),
Option::Some(hardfault_handler),
Option::None,
Option::None,
Option::None,
Option::None,
Option::None,
Option::None,
Option::None,
Option::Some(svc_handler),
Option::None,
Option::None,
Option::Some(pendsv_handler),
Option::Some(systick_handler),
];

#[link_section=".flash_configuration"]
Expand All @@ -48,8 +61,9 @@ pub static FLASH_CONFIG_FIELD: [u32, ..4] = [
];

#[no_mangle]
#[no_stack_check]
pub unsafe extern "C" fn reset_handler() {
let sim = Sim::get();
sim.copc.set(0x0);

let mut bss = &mut __bss_start__ as *mut u32;
let ebss = &mut __bss_end__ as *mut u32;
Expand All @@ -59,20 +73,45 @@ pub unsafe extern "C" fn reset_handler() {
bss = ((bss as u32) + 4) as *mut u32;
}

let mut data = &mut __data_start__ as *mut u32;
let edata = &mut __data_end__ as *mut u32;
let mut data = &mut __data_start__ as *mut u32;
let edata = &mut __data_end__ as *mut u32;
let mut etext = & __etext as *const u32;

while data < edata {
*data = *etext;
data = ((data as u32) + 4) as *mut u32;
data = ((data as u32) + 4) as *mut u32;
etext = ((etext as u32) + 4) as *const u32;
}

system_init();
::main();
}

#[no_mangle]
pub unsafe extern "C" fn nmi_handler() {
abort();
}

#[no_mangle]
pub unsafe extern "C" fn hardfault_handler() {
abort();
}

#[no_mangle]
pub unsafe extern "C" fn svc_handler() {
abort();
}

#[no_mangle]
pub unsafe extern "C" fn pendsv_handler() {
abort();
}

#[no_mangle]
pub unsafe extern "C" fn systick_handler() {
abort();
}

pub fn system_init()
{
let sim = Sim::get();
Expand Down Expand Up @@ -103,6 +142,12 @@ pub extern fn __aeabi_unwind_cpp_pr0() {
abort();
}

#[doc(hidden)]
#[no_mangle]
pub extern fn __aeabi_unwind_cpp_pr1() {
abort();
}

#[no_mangle]
pub extern fn abort() -> ! {
loop {}
Expand Down
13 changes: 6 additions & 7 deletions io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@

use core::prelude::*;
use core::intrinsics::{volatile_load, volatile_store};
pub use core::cmp;
use core::cell::UnsafeCell;

pub struct VolatileRW<T> {
value: T
value: UnsafeCell<T>,
}

impl<T> VolatileRW<T> {
#[inline]
pub fn get(&self) -> T {
unsafe {
volatile_load(&self.value)
volatile_load(self.value.get() as *const T)
}
}

#[inline]
pub fn set(&self, value: T) {
unsafe {
volatile_store(&self.value as *const T as *mut T, value);
volatile_store(self.value.get(), value);
}
}

}

impl VolatileRW<u32> {
Expand Down Expand Up @@ -65,14 +64,14 @@ impl VolatileRW<u8> {
}

pub struct VolatileR<T> {
value: T
value: UnsafeCell<T>,
}

impl<T> VolatileR<T> {
#[inline]
pub fn get(&self) -> T {
unsafe {
volatile_load(&self.value)
volatile_load(self.value.get() as *const T)
}
}
}
28 changes: 18 additions & 10 deletions kl25z.ld
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,27 @@ SECTIONS

.text :
{
__text = .;
*(.text*)
*(.rodata .rodata.*)
__etext = .;
KEEP(*(.init))
KEEP(*(.fini))
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH

__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;

__etext = .;

.data : AT (__etext)
{
__data_start__ = .;
Expand All @@ -51,13 +66,6 @@ SECTIONS
__bss_end__ = .;
} > RAM

.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > FLASH

.heap :
{
__end__ = .;
Expand Down
15 changes: 14 additions & 1 deletion main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ pub mod kl25z_map;
pub mod io;
pub mod init;

pub fn delay(mut cycles: u32)
{
while cycles > 0 {
unsafe {
asm!("nop" :::: "volatile");
}
cycles -= 1;
}
}

#[no_mangle]
pub fn main()
{
Expand All @@ -40,5 +50,8 @@ pub fn main()

ptb.psor.set(1 << 18);

loop {}
loop {
delay(50000);
ptb.ptor.set(1 << 18);
}
}

0 comments on commit 9276d25

Please sign in to comment.