LMARV-1 reboot part 6: About CSRs and interrupts

  Рет қаралды 3,826

Robert Baruch

Robert Baruch

Күн бұрын

This part explains a bit about CSRs (Control and Status Registers) and how interrupts get handled.
nMigen exercises: github.com/RobertBaruch/nmige...
github repo for code: github.com/RobertBaruch/riscv...
RISC-V specs: riscv.org/technical/specifica...
nMigen tutorial: github.com/RobertBaruch/nmige...

Пікірлер: 21
@douggale5962
@douggale5962 3 жыл бұрын
Little psychology tip: when giving people a set of alternatives, always give them the choice that you want to encourage them to pick as the last option. If they are indifferent, and don't care which one, they will tend to pick the last one, because it is easiest to remember. Should be more like, "upvote if you thought it was useful", and just omit the not up-voting, the "if" covers it!
@TomStorey96
@TomStorey96 3 жыл бұрын
Im already feeling the anxiety of this becoming a huge project 😋
@der.Schtefan
@der.Schtefan 3 жыл бұрын
If ECALL, context switches, etc. seem to be too problematic, you can opt for not supporting interrupts in V1 of your hardware or only support it in a limited fashion (Machine level external interrupt routine for IO), especially if you have a microcontroler-like machinelevel-only hardware. V2 of your hardware (or nMigen simulation) then can add more and more. It is easy to lose oneself in the vast space of Interrupts, context switches, and the dozens and dozens of CSRs Risc-v can support. But since right now you are also in control of the software that will run on your hardware, you can limit the support as far as needed to have a minimum-viable-hardware, and add more later. Helps preventing frustration :)
@AmitsLife
@AmitsLife 3 жыл бұрын
Thank you
@maikmerten
@maikmerten 3 жыл бұрын
17:10 I think that ecall from machine mode in that table is Interrupt=0, ExceptionCode=11 and ebreak is Interrupt=0, ExceptionCode=3.
@xavierthomas1980
@xavierthomas1980 3 жыл бұрын
Yes I think too. The machine software interrupt (Interrupt=1, ExceptionCode=3) is for IPI (inter-processor interrupts) and happens when writing to a specific memory-mapped CSR of the HART's interrupt controller.
@der.Schtefan
@der.Schtefan 3 жыл бұрын
ECALL vs INT: x86 has a similar situation with the SYSCALL and INT 80h semantic. SYSCALL on x86 is newer/faster, vs the old method of setting up registers and then calling INT 80h (which is simply a random convention in software like MS-DOS or old windows, etc). RISC-V maps ECALL to various interrupts, depending on wether the ECALL happened in User/Supervisor/Machine mode. This is the way how RISC-V performs kernel calls (setup registers in user mode, then call ECALL, which is handled by a handler running in Supervisor / machine mode). If you only want to run privileged machine level code like in a microcontroller without an operating system, ECALL would always hit INT 0/11. You can also skip calling ECALL in such a case, since you'd anyway just call whatever code you want. RISC-V also supports interrupt handling, and software can setup and trigger interrupts. Google For the SiFive Interrupt Cookbook: sifive.cdn.prismic.io/sifive/0d163928-2128-42be-a75a-464df65e04e0_sifive-interrupt-cookbook.pdf SiFive is the company that is driving RISC-V software and hardware development the most prominent, and their interrupt overview is quite nice.
@paco3447
@paco3447 3 жыл бұрын
Amazing. As a matter of curiosity, did the previous ttl tangible version were built using bit slices? Let’s say amd 4bit or whatever. I remember some Apollo workstation emulating a 68k10 Instruction Set out of amd bit slices.
@RobertBaruch
@RobertBaruch 3 жыл бұрын
Nope, no bit slices.
@paco3447
@paco3447 3 жыл бұрын
@@RobertBaruch Awesome. Thank you.
@costa_marco
@costa_marco 3 жыл бұрын
I am concerned about conditional jump. PC+4 at interrupt return might not work. But I didn't read the RISCV documentation about it.
@RobertBaruch
@RobertBaruch 3 жыл бұрын
Me too, I'm not completely sure how it's supposed to work. We know what PC we're targeting once the branch instruction is done, but why wouldn't we store that in MEPC? Unless it's different between interrupts (store the return address) vs exceptions (store the exception-causing instruction address)?
@costa_marco
@costa_marco 3 жыл бұрын
Unless you just keep the next PC as it is in the PC register and stores the current executing PC into the CSR. When you return, the PC is already pointing to the right address. That is my interpretation of the document. You said you will have a switchable register bank, that would work just fine, as all registers are swapped at interrupt service.
@maikmerten
@maikmerten 3 жыл бұрын
@@RobertBaruch From section 3.2.1 of the Priv Spec: "ECALL and EBREAK cause the receiving privilege mode’s epc register to be set to the address of the ECALL or EBREAK instruction itself, not the address of the following instruction." In general, it appears that if an instruction causes a trap/interrupt, then MEPC will contain the address of that instruction. To resume, one would read MEPC, increment it by the instruction length, write back MEPC, then return from the service routine. For external interrupts MEPC contains the return address. A few years back I filed an issue for a clarification in the spec: github.com/riscv/riscv-isa-manual/issues/106
@der.Schtefan
@der.Schtefan 3 жыл бұрын
Before serving an interrupt, you might need to compute the next instruction (PC+4 or target instruction in case of a jump (even unconditional jump)), store that on stack, and jump there afterwards. Storing the registers during a context switch might be imperative anyway. See section 5.2 Context Switch Overhead for a quick overview in case of an ECALL instruction of the SiFive interrupt cookbook. sifive.cdn.prismic.io/sifive/0d163928-2128-42be-a75a-464df65e04e0_sifive-interrupt-cookbook.pdf
@TomStorey96
@TomStorey96 3 жыл бұрын
@@RobertBaruch I think that sounds logical. In an exception you want to know what broke, but in an interrupt you want to know where you should go back to. An exception handler can try and recover from the error and could then return to the application that caused it by doing it's own calculation on the return PC (or go back to the original PC and retry), or it could simply trash it and restart it.
LMARV-1 reboot part 7: Interrupts and exceptions, code complete???!
30:28
LMARV-1 reboot part 4: the sequencer
1:05:46
Robert Baruch
Рет қаралды 3,2 М.
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 10 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
LMARV-1 reboot part 2: the register card.
58:02
Robert Baruch
Рет қаралды 5 М.
LMARV-1 reboot part 5: formal verification of the CPU
54:35
Robert Baruch
Рет қаралды 2,9 М.
Can You Forge Tungsten?
16:14
Alec Steele
Рет қаралды 566 М.
LMARV-1 reboot part 8: Exploring layout for multiplexed registers
1:22:01
How I mastered Leetcode the unfair way
8:02
Sahil & Sarra
Рет қаралды 22 М.
LMARV-1 reboot part 14: Chips that don't exist
37:37
Robert Baruch
Рет қаралды 6 М.
Live programming 2: LMARV-1 RISCV
2:55:26
Robert Baruch
Рет қаралды 4,6 М.
PCB Reverse Engineering
50:36
ScanCAD International, Inc
Рет қаралды 10 М.
LMARV-1 reboot part 3: the shifter and ALU
38:56
Robert Baruch
Рет қаралды 3,1 М.
Частая ошибка геймеров? 😐 Dareu A710X
1:00
Вэйми
Рет қаралды 6 МЛН
ноутбуки от 7.900 в тг laptopshoptop
0:14
Ноутбуковая лавка
Рет қаралды 3,7 МЛН
разбил телефон из-за видео
0:15
STANISLAVSKIY Hi
Рет қаралды 953 М.