diff --git a/.cargo/config.toml b/.cargo/config.toml index a249dee7760fa57e76ea6ae3481949363b460d81..1f583ac657521bf7c98c1500a0ca30b20878413f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -8,7 +8,8 @@ # runner = "arm-none-eabi-gdb -q -x openocd.gdb" # runner = "gdb-multiarch -q -x openocd.gdb" # runner = "gdb -q -x openocd.gdb" - runner = "qemu-system-gnuarmeclipse --verbose --verbose --board STM32F4-Discovery --mcu STM32F407VG -d unimp,guest_errors --nographic --semihosting-config enable=on,target=native --image " + # runner = "qemu-system-gnuarmeclipse --verbose --verbose --board STM32F4-Discovery --mcu STM32F407VG -d unimp,guest_errors --nographic --semihosting-config enable=on,target=native --image " +runner = "qemu-system-arm -M raspi2 -serial stdio -chardev socket,id=monitor,path=monitor.sock,server,nowait -monitor chardev:monitor -D ./qemu.log -d in_asm -d cpu_reset -d in_asm,int,mmu -kernel " rustflags = [ # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x @@ -16,7 +17,8 @@ rustflags = [ #"-C", "link-arg=--nmagic", # LLD (shipped with the Rust toolchain) is used as the default linker - "-C", "link-arg=-Tboards/stm32f4xx/link.x", + # "-C", "link-arg=-Tboards/stm32f4xx/link.x", + "-C", "link-arg=-Tboards/raspberrypi/link.x", # if you run into problems with LLD switch to the GNU linker by commenting out # this line @@ -34,8 +36,9 @@ rustflags = [ # Pick ONE of these compilation targets # target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ #target = "thumbv7m-none-eabi" # Cortex-M3 -target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) +# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) # target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) # target = "thumbv8m.base-none-eabi" # Cortex-M23 # target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU) # target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) +target = "armv7a-none-eabi" diff --git a/Cargo.lock b/Cargo.lock index 0e915a71a65ee4586825e705cfb64923544329fd..483ee6da345eb4aba099e9dbcd7f3145d9e4c09c 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,10 @@ checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" name = "cmsis" version = "0.1.0" +[[package]] +name = "cortex-a7" +version = "0.1.0" + [[package]] name = "cortex-m" version = "0.6.7" @@ -220,6 +224,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" +[[package]] +name = "raspberrypi" +version = "0.1.0" +dependencies = [ + "kernel", + "panic-halt", + "utils", +] + [[package]] name = "riscv" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2e49d115c6ed627a59406458065b53e70c323421..55a52e1db2cf33c0ecd449a293f5f52cbce6832e 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,11 +4,14 @@ members = [ "kal/posix", "kernel/source", "kernel/arch/arm/cortex-m4", + "kernel/arch/arm/cortex-a7", "kernel/arch/riscv", "boards/stm32f4xx", + "boards/raspberrypi", "components/exchook", "utils", ] + exclude = [ ] @@ -19,6 +22,7 @@ lto = false opt-level = "z" debug = true + [profile.release] panic = "abort" lto = true diff --git a/README.md b/README.md index f36b86fea863b2a6b8484761211dc1d7093210e5..d092095756a104d91582363001993eaca38ea5f2 100755 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ rust stable安装 rust nightly安装(使用嵌入式汇编时,需切换到nightly版本) 1. rustup install nightly 2. rustup default nightly -3. rustup target add thumbv7em-none-eabi +3. rustup target add thumbv7em-none-eabi armv7a-none-eabi #### 使用说明 diff --git a/boards/raspberrypi/Cargo.toml b/boards/raspberrypi/Cargo.toml new file mode 100755 index 0000000000000000000000000000000000000000..43440b01ce808f1ebe4ce961a57f0fe4991d2d5b --- /dev/null +++ b/boards/raspberrypi/Cargo.toml @@ -0,0 +1,12 @@ +[package] +edition = "2018" +readme = "README.md" +name = "raspberrypi" +version = "0.1.0" +authors = ["evilbinary "] + +[dependencies] +panic-halt = "0.2.0" +# utils = {path = "../../utils/"} +# kernel = {path = "../../kernel/source"} + diff --git a/boards/raspberrypi/link.x b/boards/raspberrypi/link.x new file mode 100644 index 0000000000000000000000000000000000000000..abc9ed25695f2505b79302c9bed0cb7eb255f57b --- /dev/null +++ b/boards/raspberrypi/link.x @@ -0,0 +1,37 @@ +ENTRY(_start) +K_VIR_ADDR = 0x00000; +K_PHY_ADDR = 0x00000; +PAGE_SIZE = 0x100; +SECTIONS +{ + /* Code. */ + .text K_VIR_ADDR : AT(K_PHY_ADDR) + { + . = ALIGN(PAGE_SIZE); + *(.text._start) + } + + /* Read-only data. */ + .rodata : ALIGN(4K) + { + *(.rodata) + } + + /* Read-write data (initialized) */ + .data : ALIGN(4K) + { + *(.data ) + _stack_top = . ; + } + + /* Read-write data (uninitialized) and stack */ + .bss : ALIGN(4K) + { + *(COMMON) + *(.bss) + } + .ARM.exidx :{ + *(.ARM) + } + _end = .; +} diff --git a/boards/raspberrypi/src/main.rs b/boards/raspberrypi/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..17c2251d6d4f903697dc33c1761ad90f5cabea38 --- /dev/null +++ b/boards/raspberrypi/src/main.rs @@ -0,0 +1,112 @@ +#![no_main] +#![no_std] +#![feature(asm)] +use panic_halt as _; + + +extern "C" { + static mut _stack_top: u32; +} + + +fn io_write(reg: u32, val: u32) { + unsafe { *(reg as *mut u32)= val; } +} + +fn io_read(reg: u32) -> u32 { + unsafe { *(reg as *const u32) } +} + +pub fn uart_init(){ + unsafe { + const BASE:u32=0x3F000000; + // turn off + *((BASE+0x00201030) as *mut u32) |= 0 as u32; + + //clear int + *((BASE+0x00201044) as *mut u32) = 0x7FF as u32; + //115200 + *((BASE+0x00201024) as *mut u32) = 0x7FF as u32; + + //fbrd + *((BASE+0x00201028) as *mut u32) = 0xB as u32; + //8n1 + *((BASE+0x0020102C) as *mut u32) = 0b11 << 5 as u32; + + //enable tx rx + *((BASE+0x00201030) as *mut u32) = 0x301 as u32; + } +} + + +pub fn uart_send(byte: u8) { + unsafe { + const BASE:u32 = 0x3F000000; + while (*((BASE+0x00201018) as *mut u32) & 0x20!=0) { + } + *((BASE +0x00201000) as *mut u32)= byte as u32; + } +} + +fn write_string(msg: &str) { + for c in msg.chars() { + uart_send(c as u8) + } +} + + +#[no_mangle] +pub unsafe fn _start() { + asm!(" + mrc p15, #0, r1, c0, c0, #5 + and r1, r1, #3 + cmp r1, #0 + bne halt + + mrs r0, cpsr + ldr sp, = _stack_top + ldr fp, = _stack_top + + // set sp in abt mode. + bic r1, r0, #0x1F + orr r1, r1, #0x17 + msr cpsr_c,r1 + mov sp, #0x1000 + + // set sp in undf mode. + bic r1, r0, #0x1F + orr r1, r1, #0x1B + msr cpsr_c,r1 + mov sp, #0x1000 + + // set sp in irq mode. + bic r1, r0, #0x1F + orr r1, r1, #0x12 + msr cpsr_c,r1 + mov sp, #0x2000 + //ldr sp,= stack_irq + + // set sp in svc mode. + bic r1, r0, #0x1F + orr r1, r1, #0x13 + msr cpsr_c, r0 + mov sp, #0x3000 + //ldr sp,= stack_svc + bl main + + halt: + wfe + b halt + " +); + main(); +} + +#[no_mangle] +fn main() { + uart_init(); + write_string("Hello,liteos cortex-a7!\n"); + + loop{ + } +} diff --git a/boards/stm32f4xx/Cargo.toml b/boards/stm32f4xx/Cargo.toml index 68c6374daef51ecd00b5dbce744a5bb49392c0ce..76b689a5afd29dd4cc2b72b9cb269408f6d0a6b7 100755 --- a/boards/stm32f4xx/Cargo.toml +++ b/boards/stm32f4xx/Cargo.toml @@ -4,6 +4,7 @@ edition = "2018" readme = "README.md" name = "stm32f4xx" version = "0.1.0" +default-run ="stm32f4xx" [dependencies] cortex-m = "0.6.0" diff --git a/kernel/arch/arm/cortex-a7/Cargo.toml b/kernel/arch/arm/cortex-a7/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..45f22cec913fabad16c675fb950e304349df504b --- /dev/null +++ b/kernel/arch/arm/cortex-a7/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cortex-a7" +version = "0.1.0" +edition = "2018" +authors = ["evilbinary "] +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/kernel/arch/arm/cortex-a7/src/lib.rs b/kernel/arch/arm/cortex-a7/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..2e67b25f743b271db154fe7e6bf09153ad0363f4 --- /dev/null +++ b/kernel/arch/arm/cortex-a7/src/lib.rs @@ -0,0 +1,8 @@ +#![no_std] +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}