Skip to content

Commit 0216e7a

Browse files
committed
IT WORKS (but need review privs')
1 parent b5ded1a commit 0216e7a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mini-rv32ima/mini-rv32ima.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ int StepInstruction( struct InternalCPUState * state, uint8_t * image, uint32_t
301301
// regs[16], regs[17], regs[18], regs[19], regs[20], regs[21], regs[22], regs[23] );
302302

303303
// Force machine mode.
304-
// state->privilege = 3;
305304
//int tprl = 3;
306305
//printf( "TIMER: %08x /// %08x %08x // MS: %08x\n", state->mstatus, state->mip, state->mie,state->mstatus );
307306
//printf( "MSTATUS: %08x\n", state->mstatus );
308307
state->mstatus = (( state->mstatus & 0x08) << 4) | (state->privilege << 11 );
308+
state->privilege = 3; // HMM THERE ARE CONDITION WHERE THIS IS NOT TRUE. XXX CNL XXX ===>>> ACTUALLY IT IS ALWAYS 3 BUT WE SHOULD PUT OLD STATUS IN???
309309
//printf( "MSTATUS: %08x\n", state->mstatus );
310310
state->mepc = state->pc;
311311
state->mtval = 0;
@@ -673,12 +673,13 @@ int StepInstruction( struct InternalCPUState * state, uint8_t * image, uint32_t
673673
// printf( "MRSTAT: %08x\n", state->mstatus );
674674
uint32_t startmstatus = state->mstatus;
675675
//state->privilege = (ir & 0x30000000)>>28; // I thought you could get this from mret/sret, but I guess not?
676-
state->privilege = (state->mstatus >> 11) & 3;
677-
state->mstatus = (( state->mstatus & 0x80) >> 4) | (state->privilege << 11) | 0x80;
678-
printf( "MRSTAT: %08x %08x [[%08x]]\n", state->mstatus, startmstatus, ir );
676+
state->mstatus = (( state->mstatus & 0x80) >> 4) | (0 << 11) | 0x80;
677+
// printf( "MRSTAT: %08x %08x [[%08x]]\n", state->mstatus, startmstatus, ir );
679678
if( ir != 0x30200073 ) printf( "********************************************************\n" );
680679
// alsolog = 10;
681680

681+
state->privilege = (startmstatus >> 11) & 3;
682+
682683
pc = state->mepc-4;
683684
// printf( "<<MRET>> %08x %08x %08x MEPC = %08x THIS PC %08x\n", state->mie, state->mip, state->mstatus, state->mepc, pc);
684685

@@ -722,9 +723,9 @@ int StepInstruction( struct InternalCPUState * state, uint8_t * image, uint32_t
722723
// printf( "TRAPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP %08x %08x -> %08x MEPC=%08x\n", pc, pc, state->mtvec, state->mepc );
723724

724725
// printf( "EBRK: %08x\n", state->mstatus );
725-
state->mstatus = (( state->mstatus & 0x08) << 4) | (state->privilege << 11);
726+
state->mstatus = (( state->mstatus & 0x08) << 4) | (0 << 11);
726727
printf( "EBRK2: %08x [[%08x]]\n", state->mstatus, ir );
727-
728+
state->privilege = 3;
728729
pc = (state->mtvec - 4);
729730
}
730731
break;

0 commit comments

Comments
 (0)