minor edits and optimizations

This commit is contained in:
stnolting 2020-07-21 20:46:28 +02:00
parent 0338f9f00e
commit b0d0287773
3 changed files with 95 additions and 91 deletions

View file

@ -196,7 +196,7 @@ begin
mem_i => rdata, -- memory read data
alu_i => alu_res, -- ALU result
csr_i => csr_rdata, -- CSR read data
pc_i => next_pc, -- next pc
pc_i => next_pc, -- next pc (for linking)
-- data output --
rs1_o => rs1, -- operand 1
rs2_o => rs2 -- operand 2

View file

@ -552,7 +552,7 @@ begin
execute_engine.i_reg_nxt <= execute_engine.i_reg;
execute_engine.is_jump_nxt <= '0';
execute_engine.is_ci_nxt <= execute_engine.is_ci;
execute_engine.pc_nxt <= execute_engine.pc(data_width_c-1 downto 1) & '0';
execute_engine.pc_nxt <= execute_engine.pc;
execute_engine.sleep_nxt <= execute_engine.sleep;
-- instruction dispatch --
@ -638,7 +638,7 @@ begin
else
execute_engine.is_ci_nxt <= ipb.rdata(32); -- flag to indicate this is a compressed instruction beeing executed
execute_engine.i_reg_nxt <= ipb.rdata(31 downto 0);
execute_engine.pc_nxt <= ipb.raddr(data_width_c-1 downto 1) & '0'; -- the PC according to the current instruction
execute_engine.pc_nxt <= ipb.raddr; -- the PC according to the current instruction
if (execute_engine.sleep = '1') then
execute_engine.state_nxt <= TRAP;
else
@ -652,7 +652,7 @@ begin
fetch_engine.reset <= '1';
if (trap_ctrl.env_start = '1') then -- check here again if we came directly from DISPATCH
trap_ctrl.env_start_ack <= '1';
execute_engine.pc_nxt <= csr.mtvec(data_width_c-1 downto 2) & "00";
execute_engine.pc_nxt <= csr.mtvec;
execute_engine.sleep_nxt <= '0'; -- waky waky
execute_engine.state_nxt <= SYS_WAIT;
end if;
@ -724,7 +724,7 @@ begin
end if;
ctrl_nxt(ctrl_alu_opb_mux_lsb_c) <= '1'; -- use IMM as ALU.OPB
-- save return address --
ctrl_nxt(ctrl_rf_in_mux_msb_c downto ctrl_rf_in_mux_lsb_c) <= "10"; -- RF input = current PC
ctrl_nxt(ctrl_rf_in_mux_msb_c downto ctrl_rf_in_mux_lsb_c) <= "10"; -- RF input = next PC (save return address)
ctrl_nxt(ctrl_rf_wb_en_c) <= '1'; -- valid RF write-back
--
execute_engine.is_jump_nxt <= '1'; -- this is a jump operation
@ -732,7 +732,7 @@ begin
when opcode_fence_c => -- fence operations
-- ------------------------------------------------------------
execute_engine.pc_nxt <= execute_engine.next_pc(data_width_c-1 downto 1) & '0'; -- "refetch" next instruction (only relevant for fencei)
execute_engine.pc_nxt <= execute_engine.next_pc; -- "refetch" next instruction (only relevant for fencei)
if (execute_engine.i_reg(instr_funct3_msb_c downto instr_funct3_lsb_c) = funct3_fencei_c) and (CPU_EXTENSION_RISCV_Zifencei = true) then -- FENCEI
fetch_engine.reset <= '1';
ctrl_nxt(ctrl_bus_fencei_c) <= '1';
@ -753,7 +753,7 @@ begin
trap_ctrl.break_point <= '1';
when funct12_mret_c => -- MRET
trap_ctrl.env_end <= '1';
execute_engine.pc_nxt <= csr.mepc(data_width_c-1 downto 1) & '0';
execute_engine.pc_nxt <= csr.mepc;
fetch_engine.reset <= '1';
when funct12_wfi_c => -- WFI = "CPU sleep"
execute_engine.sleep_nxt <= '1'; -- good night
@ -761,12 +761,8 @@ begin
NULL;
end case;
execute_engine.state_nxt <= SYS_WAIT;
else
if (CPU_EXTENSION_RISCV_Zicsr = true) then -- CSR access
execute_engine.state_nxt <= CSR_ACCESS;
else -- undefined
execute_engine.state_nxt <= DISPATCH;
end if;
else -- CSR access
execute_engine.state_nxt <= CSR_ACCESS;
end if;
when others => -- undefined
@ -836,9 +832,9 @@ begin
when BRANCH => -- update PC for taken branches and jumps
-- ------------------------------------------------------------
execute_engine.pc_nxt <= alu_add_i; -- branch/jump destination
if (execute_engine.is_jump = '1') or (execute_engine.branch_taken = '1') then
fetch_engine.reset <= '1';
execute_engine.pc_nxt <= alu_add_i(data_width_c-1 downto 1) & '0'; -- branch/jump destination
fetch_engine.reset <= '1'; -- trigger new instruction fetch from modified PC
execute_engine.state_nxt <= SYS_WAIT;
else
execute_engine.state_nxt <= DISPATCH;

View file

@ -70,6 +70,13 @@ volatile uint32_t exception_handler_answer;
// Prototypes
void global_trap_handler(void);
void test_ok(void);
void test_fail(void);
// Global variables (also test initialization of global vars here)
int cnt_fail = 0;
int cnt_ok = 0;
int cnt_test = 0;
/**********************************************************************//**
@ -91,10 +98,6 @@ int main() {
register uint32_t tmp_a;
volatile uint32_t dummy_dst __attribute__((unused));
int cnt_fail = 0;
int cnt_ok = 0;
int cnt_test = 0;
union {
uint64_t uint64;
uint32_t uint32[sizeof(uint64_t)/2];
@ -204,12 +207,10 @@ int main() {
neorv32_uart_printf("%u bytes (should be %u bytes) ", dmem_probe_cnt, neorv32_cpu_csr_read(CSR_MISPACESIZE));
neorv32_uart_printf("@ 0x%x ", neorv32_cpu_csr_read(CSR_MISPACEBASE));
if (dmem_probe_cnt == neorv32_cpu_csr_read(CSR_MISPACESIZE)) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#else
neorv32_uart_printf("skipped (disabled)\n");
@ -238,12 +239,10 @@ int main() {
neorv32_uart_printf("%u bytes (should be %u bytes) ", imem_probe_cnt, neorv32_cpu_csr_read(CSR_MDSPACESIZE));
neorv32_uart_printf("@ 0x%x ", neorv32_cpu_csr_read(CSR_MDSPACEBASE));
if (imem_probe_cnt == neorv32_cpu_csr_read(CSR_MDSPACESIZE)) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#else
neorv32_uart_printf("skipped (disabled)\n");
@ -261,12 +260,10 @@ int main() {
if (((neorv32_cpu_csr_read(CSR_MCYCLE) & 0xffff0000L) == 0x1BCD0000) &&
(neorv32_cpu_csr_read(CSR_MCYCLEH) == 0x00034455)) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
@ -281,12 +278,10 @@ int main() {
if (((neorv32_cpu_csr_read(CSR_MINSTRET) & 0xffff0000L) == 0x11220000) &&
(neorv32_cpu_csr_read(CSR_MINSTRETH) == 0x00090011)) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
@ -303,12 +298,10 @@ int main() {
uint64_t mtime_systime = neorv32_mtime_get_time() & 0xFFFFFFFFFFFF0000LL;
if (cpu_systime.uint64 == mtime_systime) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
@ -323,15 +316,33 @@ int main() {
asm volatile ("fence.i");
if (exception_handler_answer != 0xFFFFFFFF) {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
else {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
// ----------------------------------------------------------
// Illegal CSR access
// ----------------------------------------------------------
exception_handler_answer = 0xFFFFFFFF;
neorv32_uart_printf("ILLEGAL CSR: ");
cnt_test++;
neorv32_cpu_csr_read(0xfff); // CSR 0xfff not implemented
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_I_ILLEGAL) {
test_ok();
}
else {
test_fail();
}
#endif
// ----------------------------------------------------------
// Unaligned instruction address
// ----------------------------------------------------------
@ -374,12 +385,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_I_ACCESS) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -402,12 +411,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_I_ILLEGAL) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -434,12 +441,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_I_ILLEGAL) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
}
@ -459,12 +464,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_BREAKPOINT) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -481,12 +484,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_L_MISALIGNED) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -503,12 +504,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_L_ACCESS) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -525,12 +524,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_S_MISALIGNED) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -547,12 +544,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_S_ACCESS) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -568,12 +563,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_MENV_CALL) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -596,12 +589,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_MTI) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -627,12 +618,10 @@ int main() {
#if (DETAILED_EXCEPTION_DEBUG==0)
if (exception_handler_answer == EXCCODE_MEI) {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
else {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
#endif
@ -651,12 +640,10 @@ int main() {
asm volatile ("wfi");
if (exception_handler_answer != EXCCODE_MTI) {
neorv32_uart_printf("fail\n");
cnt_fail++;
test_fail();
}
else {
neorv32_uart_printf("ok\n");
cnt_ok++;
test_ok();
}
@ -680,5 +667,26 @@ int main() {
* Trap handler for ALL exceptions/interrupts.
**************************************************************************/
void global_trap_handler(void) {
exception_handler_answer = neorv32_cpu_csr_read(CSR_MCAUSE);
}
/**********************************************************************//**
* Test results helper function: Shows "ok" and increments global cnt_ok
**************************************************************************/
void test_ok(void) {
neorv32_uart_printf("ok\n");
cnt_ok++;
}
/**********************************************************************//**
* Test results helper function: Shows "fail" and increments global cnt_fail
**************************************************************************/
void test_fail(void) {
neorv32_uart_printf("fail\n");
cnt_fail++;
}