← RTL Design Interviews · SoC Architecture Interviews

Interview Question · Diagnose a Chip from Evidence

Why Did the Core Enter the Handler?

L0 FresherL2 Mid-Leveldiagnose from evidence

The Question

The interviewer asks

Two runs enter the same machine handler. One executed an illegal instruction. The other received a timer request. How would you tell them apart?

Reveal the Model Answer

Both transfers into the handler are traps. The illegal instruction causes a synchronous exception. The interrupt comes from a request outside the instruction stream. Read mcause for the interrupt bit and cause code, then inspect the saved address in mepc.

Self-Check

Tick each key point you covered in your answer.

What Interviewers Want to Hear (Fresher)

Classify each event by what caused it.

Choose Your Follow-up

I’ve answered the opening question

Choose the route closest to your reasoning. Answer the follow-up aloud, then open the closing question.

I started with the timer.

In machine mode mip shows the timer pending, mie has MTIE set, and mstatus.MIE is zero. An illegal instruction still enters the handler. Why?

Reveal the Model Answer

The interrupt enable gates interrupt delivery. The illegal instruction raises its own synchronous exception regardless of that enable.

Self-Check

Tick each key point you covered in your answer.

Choose the Return Address

A colleague proposes one return address rule for every cause. What evidence would you require before allowing the program to resume?

Reveal the Model Answer

For an interrupt, preserve the saved resume address and service the source. For a repaired fault, retry at the faulting address. Advance past a completed ecall. Only an explicit skip or emulation policy justifies advancing mepc by four after an illegal word. If the fault remains unexplained, stop and report its cause and address.

Self-Check

Tick each key point you covered in your answer.

I called the exception precise.

A store after the illegal word has already written SRAM when the handler starts. Can software treat this as a precise exception?

Reveal the Model Answer

No. Older instructions may finish, but the faulting instruction and younger instructions must leave no normal results. The changed SRAM violates that boundary.

Self-Check

Tick each key point you covered in your answer.

Choose the Return Address

A colleague proposes one return address rule for every cause. What evidence would you require before allowing the program to resume?

Reveal the Model Answer

For an interrupt, preserve the saved resume address and service the source. For a repaired fault, retry at the faulting address. Advance past a completed ecall. Only an explicit skip or emulation policy justifies advancing mepc by four after an illegal word. If the fault remains unexplained, stop and report its cause and address.

Self-Check

Tick each key point you covered in your answer.

I planned to retry.

The cause now identifies an ecall. The handler completed the requested service. What would returning to the saved address do?

Reveal the Model Answer

It would execute ecall again. On ap_rv32 the handler advances mepc by the four-byte instruction length before mret.

Self-Check

Tick each key point you covered in your answer.

Choose the Return Address

A colleague proposes one return address rule for every cause. What evidence would you require before allowing the program to resume?

Reveal the Model Answer

For an interrupt, preserve the saved resume address and service the source. For a repaired fault, retry at the faulting address. Advance past a completed ecall. Only an explicit skip or emulation policy justifies advancing mepc by four after an illegal word. If the fault remains unexplained, stop and report its cause and address.

Self-Check

Tick each key point you covered in your answer.

I allowed interrupts inside the handler.

The handler sets MIE back to one. A second interrupt arrives before the first handler returns. What happens to mepc?

Reveal the Model Answer

Trap entry overwrites mepc with the resume address inside the first handler. Before enabling nesting, save the outer mepc and needed status on the stack. Restore that context before the outer mret.

Self-Check

Tick each key point you covered in your answer.

Choose the Return Address

A colleague proposes one return address rule for every cause. What evidence would you require before allowing the program to resume?

Reveal the Model Answer

For an interrupt, preserve the saved resume address and service the source. For a repaired fault, retry at the faulting address. Advance past a completed ecall. Only an explicit skip or emulation policy justifies advancing mepc by four after an illegal word. If the fault remains unexplained, stop and report its cause and address.

Self-Check

Tick each key point you covered in your answer.

What People Get Wrong

Common wrong answers and why they fail.

Half-Truth

I would identify the cause from the handler address.

Exceptions always share the mtvec base address, and in direct mode interrupts do too.

Half-Truth

I would advance the saved address on every trap.

An interrupt can arrive before an instruction that still needs to run.

Learn It, Then Prove It