Video
Đăng bởi Quản trị viên OpenER ·
Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
[MUSIC PLAYING] PROFESSOR: Hello. Welcome back to the module in which we design the RISC-V CPU.
We have made enormous progress so far.
We have designed a data path that can execute every single instruction from the RV32I based instruction set that we need to run any compulsory program.
So that's great. But we are not quite done yet. We need just a few more things.
So just to recap how we got this far, we started fairly simple. We designed the later product and executed R type instructions. Then we added I type instructions.
Then S types, B types, U types, and J types. And ended up with a data path that is configurable and can be configured to execute any instruction from our base instruction set.
For that, we outlined what does the control logic need to do. But we haven't designed that control logic yet. That's what we are going to do next.
But before then, let's take a look at a few other components that pretty much every computer needs to have.
One of those components is a set of so-called control and status registers, or CSRs for short.
Control and status registers are separate from our base instruction set, our base general purpose 32 registers that we have in our instruction set architecture.
They are close to the processor but not as close. Close to the execution unit, but not as close as our general purpose integer registers.
They're used for different kinds of purposes. They're used for monitoring the status and performance and also for communication with other devices like peripherals or other units on the same chip.
RISC-V ISC allows space for addressing up to 4,096 CSRs. Although in most cases, we're not going to have that many of them. So what are these CSRs?
What are they used for? Well, when we talk about monitoring the performance, we often care about how well are the programs executing.
So in that sense, CSRs may count the number of cycles that we have executed or a number of instructions that have been retired.
They can be used for communication with core processors, like a floating point unit, or with peripherals, things like printers if you like.
And often the communication is done by placing some kind of a control word into that register that the peripheral unit is supposed to pick up and do something with it.
And then when it is done, it would put its status in there, ready or waiting or done. And the processor will know that that action has been completed.
In some cases, the communication is just a single bit or a flag. And that draws parallels with how we work or at some point used to work with the Postal Service.
So in old fashioned mailboxes, somebody would put a piece of mail in the mailbox and raise a flag.
And then when the mail carrier comes and picks up that piece of mail, they would lower the flag or clear the flag.
That's the reason why we call some of these single bit pieces of information in processors as flags. And we set them and clear them.
CSRs are in pretty much every processor that is out there. But they're not part of the base ISA. They used to be in the base ISA.
But they've been taken out for modularity reasons. So there is a standard extension that covers these CSRs in RISC-V. So how do these CSR instructions look?
Well, they share the familiar I format. There are two types of CSR instructions, ones that have source registered and the other ones that use immediates.
So half of them have a registered operand. The other ones have the immediate operand.
So similar to I format, we have the upper 12 bits. These are for addresses.
Instead of the immediate here, the upper 12 bits are used for addressing the CSRs, control and status registers.
So since we have 12 bits over there that we are using, we can have up to 4,096 CSRs. Then we have a field for the source register or the immediate.
Funct3 field designates which instruction are we executing. rd is the destination register.
And the opcode is of a system type shared with some other instructions.
So the way how these CSRs work is they generally work with our general purpose registers.
So what we'll be doing, we'll be swapping the values in CSRs with the values that are in our general purpose registers.
So in general, a good example is a basic instruction CSR read write, crsrw, that copies what is in the CSR in a particular CSR that we are addressing and stores that result in destination register.
And at the same time or concurrently, it takes the value from the source register rs1 and copies it to the CSR.
That is done when the destination register is any register other than x zero.
If it is x zero, then we are not reading the CSR because we cannot change the value that is in x zero. There are two other variants, CSR read and then set or clear.
Those are basically setting or clearing the flag that the CSR has been read. Then we have the immediate variants, which work exactly the same.
Except that in the source field, we are not storing the address of the source register. We are storing the immediate value. And this immediate value is five bits.
That needs to be extended to write a 32-bit CSR. And keep in mind that it is always zero extended. It doesn't make sense to sign extend things that are just status bits.
We're not really doing any arithmetic with them. So it's an example of a CSR extraction. I've mentioned csr rw, which is the atomic read write CSR.
We'll see later in the course a much better definition of what atomic means. But in this case, it means that we would like to swap the values in CSRs and integer registers.
So in this case, csr rw reads the previous value of the CSR and writes it to integer register rd. And then writes what is in rs1 to the CSR.
It doesn't change the value of the source register.
This is a bit trickier to implement.
What we will do in our project will implement the pseudoinstruction csr write which only writes the control and status register.
So its format is csr w csr rs1. And what it does it's essentially short for the csr rw where destination register is x zero.
It just writes the value from rs1 to the CSR.
Conversely, the psuedoinstruction csr wi writes the immediate value immediate to the CSR. And when implementing this, there is not much magic.
It's just a block of registers, whatever the number of registers we need. And remember, since we would like to write to them, don't forget clocks and write enabled signals.
You don't want to scribble over your control and status registers accidentally. That's it for control and status registers.
There are a few more instructions in the basic instruction set that we will not implement in this course. But sometimes they pop up in our assembly code.
So it's a good idea to know what they are so we are not surprised when we see them. We have ecalls and ebreaks.
Both of them are I format and share the same system opcode. And ecall makes requests to the supporting execution environment.
Namely, the operating system, such as system calls, which would be Linux assist calls.
And then ebreak is used to transfer the control to the debugger.
That's what we have of those. And one more instruction that we sometimes may encounter is the fence. Much more rarely in this class.
This is the one that separates the memory and IO accesses as viewed by other threads and processes. And that is it.
We'll continue building the control after the break.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.