diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9528492 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +*.rs text eol=lf +*.S text eol=lf +*.a binary +*.h text eol=lf +*.s text eol=lf +*.S text eol=lf +README.* text eol=lf +LICENSE text eol=lf +*.md text eol=lf +*.sh text eol=lf +*.ps1 text eol=crlf +.gitignore text eol=lf +.gitattributes text eol=lf +*.yml text eol=lf +*.toml text eol=lf diff --git a/Cargo.toml b/Cargo.toml index 4fd056c..efebf7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "riscv" -version = "0.5.4" -repository = "https://github.com/rust-embedded/riscv" -authors = ["The RISC-V Team "] -categories = ["embedded", "hardware-support", "no-std"] -description = "Low level access to RISC-V processors" -keywords = ["riscv", "register", "peripheral"] +name = "vexriscv" +version = "0.0.1" +repository = "https://github.com/xobs/vexriscv-rust" +authors = ["Sean Cross ", "The RISC-V Team "] +categories = ["embedded", "hardware-support", "no-std", "vexriscv"] +description = "Low level access to the VexRiscv processor" +keywords = ["riscv", "register", "peripheral", "vexriscv"] license = "ISC" [dependencies] @@ -13,4 +13,4 @@ bare-metal = ">=0.2.0,<0.2.5" bit_field = "0.9.0" [features] -inline-asm = [] \ No newline at end of file +inline-asm = [] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..74a54e2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,6 @@ +Copyright (c) 2020, Sean Cross \ +Copyright (c) 2019, RISC-V team https://github.com/rust-embedded/wg#the-riscv-team + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md index 807bd15..262f27e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ -[![crates.io](https://img.shields.io/crates/d/riscv.svg)](https://crates.io/crates/riscv) -[![crates.io](https://img.shields.io/crates/v/riscv.svg)](https://crates.io/crates/riscv) -[![Build Status](https://travis-ci.org/rust-embedded/riscv.svg?branch=master)](https://travis-ci.org/rust-embedded/riscv) +[![crates.io](https://img.shields.io/crates/d/riscv.svg)](https://crates.io/crates/vexriscv) +[![crates.io](https://img.shields.io/crates/v/riscv.svg)](https://crates.io/crates/vexriscv) +[![Build Status](https://travis-ci.org/rust-embedded/riscv.svg?branch=master)](https://travis-ci.org/xobs/vexriscv) -# `riscv` +# `veriscv` -> Low level access to RISC-V processors +> Low level access to parts of the VexRiscv RISC-V processor -This project is developed and maintained by the [RISC-V team][team]. +This project is derived from [riscv](https://github.com/rust-embedded/riscv), developed and maintained by the [RISC-V team][team]. -## [Documentation](https://docs.rs/crate/riscv) +## [Documentation](https://docs.rs/crate/vexriscv) ## License +Copyright 2020 Sean "xobs" Cross Copyright 2019 [RISC-V team][team] Permission to use, copy, modify, and/or distribute this software for any purpose diff --git a/asm.S b/asm.S index c6c293b..e42d90c 100644 --- a/asm.S +++ b/asm.S @@ -1,4 +1,46 @@ -#include "asm.h" +#define REG_READ(name, offset) \ +.section .text.__read_ ## name; \ +.global __read_ ## name; \ +__read_ ## name: \ + csrrs a0, offset, x0; \ + ret + +#define REG_WRITE(name, offset) \ +.section .text.__write_ ## name; \ +.global __write_ ## name; \ +__write_ ## name: \ + csrrw x0, offset, a0; \ + ret + +#define REG_SET(name, offset) \ +.section .text.__set_ ## name; \ +.global __set_ ## name; \ +__set_ ## name: \ + csrrs x0, offset, a0; \ + ret + +#define REG_CLEAR(name, offset) \ +.section .text.__clear_ ## name; \ +.global __clear_ ## name; \ +__clear_ ## name: \ + csrrc x0, offset, a0; \ + ret + + +#define REG_READ_WRITE(name, offset) REG_READ(name, offset); REG_WRITE(name, offset) +#define REG_SET_CLEAR(name, offset) REG_SET(name, offset); REG_CLEAR(name, offset) + +#define RW(offset, name) REG_READ_WRITE(name, offset); REG_SET_CLEAR(name, offset) +#define RO(offset, name) REG_READ(name, offset) + +#if __riscv_xlen == 32 +#define RW32(offset, name) RW(offset, name) +#define RO32(offset, name) RO(offset, name) +#else +#define RW32(offset, name) +#define RO32(offset, name) +#endif +// ----------------------- // .section .text.__ebreak .global __ebreak @@ -273,3 +315,10 @@ RW(0x7A3, tdata3) // Third Debug/Trace trigger data register RW(0x7B0, dcsr) // Debug control and status register RW(0x7B1, dpc) // Debug PC RW(0x7B2, dscratch) // Debug scratch register + +// VexRiscv custom registers +RW(0xBC0, vmim) // Machine IRQ Mask +RW(0xFC0, vmip) // Machine IRQ Pending +RW(0x9C0, vsim) // Supervisor IRQ Mask +RW(0xDC0, vsip) // Supervisor IRQ Pending +RW(0xCC0, vdci) // DCache Info diff --git a/asm.h b/asm.h deleted file mode 100644 index 2b675e7..0000000 --- a/asm.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __ASM_H -#define __ASM_H - -#define REG_READ(name, offset) \ -.section .text.__read_ ## name; \ -.global __read_ ## name; \ -__read_ ## name: \ - csrrs a0, offset, x0; \ - ret - -#define REG_WRITE(name, offset) \ -.section .text.__write_ ## name; \ -.global __write_ ## name; \ -__write_ ## name: \ - csrrw x0, offset, a0; \ - ret - -#define REG_SET(name, offset) \ -.section .text.__set_ ## name; \ -.global __set_ ## name; \ -__set_ ## name: \ - csrrs x0, offset, a0; \ - ret - -#define REG_CLEAR(name, offset) \ -.section .text.__clear_ ## name; \ -.global __clear_ ## name; \ -__clear_ ## name: \ - csrrc x0, offset, a0; \ - ret - - -#define REG_READ_WRITE(name, offset) REG_READ(name, offset); REG_WRITE(name, offset) -#define REG_SET_CLEAR(name, offset) REG_SET(name, offset); REG_CLEAR(name, offset) - -#define RW(offset, name) REG_READ_WRITE(name, offset); REG_SET_CLEAR(name, offset) -#define RO(offset, name) REG_READ(name, offset) - -#if __riscv_xlen == 32 -#define RW32(offset, name) RW(offset, name) -#define RO32(offset, name) RO(offset, name) -#else -#define RW32(offset, name) -#define RO32(offset, name) -#endif - -#endif /* __ASM_H */ - diff --git a/assemble.ps1 b/assemble.ps1 new file mode 100644 index 0000000..079eae1 --- /dev/null +++ b/assemble.ps1 @@ -0,0 +1,19 @@ +New-Item -Force -Name bin -Type Directory + +# remove existing blobs because otherwise this will append object files to the old blobs +Remove-Item -Force bin/*.a + +$crate = "xous-riscv" + +riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imac asm.S -o bin/$crate.o +riscv64-unknown-elf-ar crs bin/riscv32imac-unknown-none-elf.a bin/$crate.o +riscv64-unknown-elf-ar crs bin/riscv32imc-unknown-none-elf.a bin/$crate.o + +riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32i asm.S -DSKIP_MULTICORE -o bin/$crate.o +riscv64-unknown-elf-ar crs bin/riscv32i-unknown-none-elf.a bin/$crate.o + +riscv64-unknown-elf-gcc -c -mabi=lp64 -march=rv64imac asm.S -o bin/$crate.o +riscv64-unknown-elf-ar crs bin/riscv64imac-unknown-none-elf.a bin/$crate.o +riscv64-unknown-elf-ar crs bin/riscv64gc-unknown-none-elf.a bin/$crate.o + +Remove-Item bin/$crate.o diff --git a/assemble.sh b/assemble.sh index d8c9457..8994b7e 100755 --- a/assemble.sh +++ b/assemble.sh @@ -2,18 +2,18 @@ set -euxo pipefail -crate=riscv +crate=riscv-rt # remove existing blobs because otherwise this will append object files to the old blobs rm -f bin/*.a -riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32i asm.S -o bin/$crate.o -ar crs bin/riscv32i-unknown-none-elf.a bin/$crate.o - -riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imc asm.S -o bin/$crate.o +riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imac asm.S -o bin/$crate.o ar crs bin/riscv32imac-unknown-none-elf.a bin/$crate.o ar crs bin/riscv32imc-unknown-none-elf.a bin/$crate.o +riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32i asm.S -DSKIP_MULTICORE -o bin/$crate.o +ar crs bin/riscv32i-unknown-none-elf.a bin/$crate.o + riscv64-unknown-elf-gcc -c -mabi=lp64 -march=rv64imac asm.S -o bin/$crate.o ar crs bin/riscv64imac-unknown-none-elf.a bin/$crate.o ar crs bin/riscv64gc-unknown-none-elf.a bin/$crate.o