valid step function
This commit is contained in:
@@ -152,7 +152,7 @@ int main(int argc, char** argv){
|
||||
|
||||
//program execution
|
||||
tinyriscv_init(&hart);
|
||||
while(hart.pc < file_size + tinyriscv_MEM_OFFSET) tinyriscv_step(&hart);
|
||||
while(tinyriscv_valid_step(&hart)) tinyriscv_step(&hart);
|
||||
|
||||
if(do_regdump) regdump(&hart);
|
||||
if(do_memdump) memdump(&hart, dump_addr);
|
||||
|
||||
@@ -150,6 +150,22 @@ void tinyriscv_r_type(const u8 func3, const u8 func7, u32 x[32], const u8 rd,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void tinyriscv_init(tinyriscv_hart* hart){
|
||||
hart->x[2] = tinyriscv_MEM_OFFSET + hart->mem_size;
|
||||
hart->pc = tinyriscv_MEM_OFFSET;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
u8 tinyriscv_valid_step(const tinyriscv_hart* hart){
|
||||
if(!load32(hart->mem, hart->pc)) return 0;
|
||||
if(hart->pc >= hart->mem_size + tinyriscv_MEM_OFFSET) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void tinyriscv_step(tinyriscv_hart* hart){
|
||||
//fetch
|
||||
const u32 inst = load32(hart->mem, hart->pc);
|
||||
@@ -194,11 +210,4 @@ void tinyriscv_step(tinyriscv_hart* hart){
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void tinyriscv_init(tinyriscv_hart* hart){
|
||||
hart->x[2] = tinyriscv_MEM_OFFSET + hart->mem_size;
|
||||
hart->pc = tinyriscv_MEM_OFFSET;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif //TINYRISCV_H
|
||||
Reference in New Issue
Block a user