[CS61C FA20] Lecture 20.1 - Single-Cycle CPU Control: Control and Status Registers — Transcript
Full transcript
- 0:01[Music]
- 0:08hello
- 0:10welcome back to the module in which we
- 0:12design a risk pipe cpu
- 0:14we have made an enormous progress so far
- 0:16we have designed a data path that can
- 0:18execute
- 0:20every single instruction from the rb32i
- 0:23based instruction set that we need to
- 0:26run any compiled c program so that's
- 0:30great
- 0:30but we are not quite done yet
- 0:34we need just a few more things
- 0:38so just to recap how we got to
- 0:41how we got this far we started fairly
- 0:44simple
- 0:45we designed the data product and execute
- 0:48r-type instructions then we added i type
- 0:50instructions
- 0:51then s-types b types u types and j-types
- 0:54ending up with a data path that is
- 0:58configurable
- 0:59and can be configured to execute any
- 1:01instruction
- 1:02from our base instruction set for that
- 1:06we outlined what does the control logic
- 1:09need to do
- 1:10but we haven't designed that control
- 1:12logic yet
- 1:13that's what we're going to do next but
- 1:15before then
- 1:17let's take a look at a few other
- 1:19components that
- 1:21pretty much every computer needs to have
- 1:24one of those components
- 1:26is a set of so-called
- 1:29control and status registers or csrs for
- 1:33short
- 1:35control and status registers
- 1:38are separate from our base instruction
- 1:41set
- 1:41our base general purpose 32 registers
- 1:46that we have
- 1:47in our instruction set architecture
- 1:52they are close to the processor but not
- 1:55as
- 1:55close and close to the execution unit
- 1:58but not as close as our
- 2:01general purpose integer registers
- 2:05they're used for different kinds of
- 2:06purposes they're used for monitoring
- 2:11the status and performance and also for
- 2:13communication
- 2:14with other devices like peripherals or
- 2:17other units on the same chip
- 2:23risk five isa um allows space for
- 2:26addressing up to 4096 csrs although
- 2:29in most cases we are not going to have
- 2:31that many of them
- 2:33um so what are these csrs what are they
- 2:36used for
- 2:37well when we talk about monitoring the
- 2:39performance we often
- 2:40care about how well are the
- 2:43programs executing so in that sense um
- 2:48csrs
- 2:50may count the number of cycles that we
- 2:53have executed
- 2:54or the number of instructions that have
- 2:56been retired they can be used for
- 2:58communication with co-processors like a
- 3:00floating point unit
- 3:01or with peripherals things like
- 3:05printers if you like
- 3:08and often that communication is done by
- 3:12placing some kind of a
- 3:14control word into that register
- 3:17that the peripheral unit is supposed to
- 3:19pick up and do something with it
- 3:21and then when it is done it would put
- 3:23its status in there
- 3:25ready or waiting or done
- 3:28and the processor will know that that
- 3:31action
- 3:32has been completed in some cases that
- 3:35communication is just a single bit
- 3:37or a flag and that
- 3:40draws parallels with how we work or at
- 3:43some point used to work with a
- 3:44postal service so in
- 3:48old-fashioned mailboxes somebody would
- 3:50put
- 3:51a piece of mail in the mailbox and raise
- 3:53a flag
- 3:54and then when the mail carrier comes and
- 3:56picks up that
- 3:57piece of mail they will lower the flag
- 4:00or clear the flag that's why we
- 4:04that's the reason why we call some of
- 4:07these single bit
- 4:09pieces of information in processors as
- 4:11flags
- 4:13and we set them and clear them
- 4:16csrs are in pretty much every processor
- 4:19that is out there
- 4:21but they're not part
- 4:24of the base i say they used to be in the
- 4:28base isa but they've been taken out
- 4:30for modularity reasons so there is a
- 4:33standard extension
- 4:34that covers these csrs in risk five
- 4:39so how do the these csr instructions
- 4:41look like well they share
- 4:43the well familiar i format
- 4:46there are two types of csr instructions
- 4:48ones
- 4:49that have source register the other ones
- 4:52that use immediates
- 4:54so a half of them have a register
- 4:57operand
- 4:58the other one have the immediate operand
- 5:02so similar to i format
- 5:06we have the upper 12 bits reserved for
- 5:10addresses instead of the immediate here
- 5:12the upper 12 bits are used for
- 5:14for addressing the
- 5:18csrs control and status registers
- 5:22so since we have 12 bits over there that
- 5:24we are using
- 5:25we can have up to 4096 csrs
- 5:28then we have a field for the source
- 5:31register or the immediate
- 5:33functory field designates which
- 5:36instruction
- 5:36are we executing rd is the destination
- 5:40register
- 5:41and the opcode
- 5:45is of a system type shared with some
- 5:47other instructions
- 5:49so the way how these csrs work is
- 5:52they generally work or with the
- 5:56with our general purpose registers so
- 5:58what we'll be doing
- 6:00will be swapping the values in csrs with
- 6:03the values that are
- 6:04in our general purpose registers so
- 6:08general and a good example is a
- 6:11basic instruction csr read write csr
- 6:14rw that
- 6:18copies or take the copies what is in
- 6:21the csr in a particular csr that you are
- 6:24addressing
- 6:25and stores that result in destination
- 6:27register and at the same time
- 6:30or concurrently takes the value from the
- 6:32source register rs1
- 6:34and copies it to the csr
- 6:41that is done when the destination
- 6:44register is any register other than x0
- 6:46if it is x0
- 6:48then we are not reading the csr because
- 6:50we cannot
- 6:51change the value that is in x0
- 6:54there are two other variants csr read
- 6:57and then set or clear those are
- 7:00basically
- 7:01setting or clearing the flag
- 7:04that the csr has been read
- 7:08then we have the immediate variants
- 7:10which work exactly the same
- 7:12except that in the source
- 7:15field we are not storing the address of
- 7:18the
- 7:18source register we are storing the
- 7:20immediate value and
- 7:22this immediate value is five bits that
- 7:24needs to be extended
- 7:25to write a 32-bit csr
- 7:29and keep in mind that it is always zero
- 7:31extended
- 7:32um it doesn't make sense to sign extend
- 7:35things that are
- 7:36just status bits we're not really doing
- 7:39any arithmetic with them
- 7:41so as an example of a csr extraction
- 7:43i've mentioned csr
- 7:44rw which is the atomic read write csr
- 7:48we'll see later in the course much
- 7:50better definition of what
- 7:51atomic means but in this case it means
- 7:54that we would like to swap the values
- 7:56in csrs and integer registers
- 8:00so in this case csrrw reads the previous
- 8:03value of the csr
- 8:05and writes it to integer register rt
- 8:08and then writes what is in rs1
- 8:12to the csr doesn't change the value
- 8:15of the source register
- 8:19this is a bit trickier to implement
- 8:22what we will do in our project we'll
- 8:24implement the pseudo instruction
- 8:27csr write which only writes
- 8:30the status control and status register
- 8:34so its format is csr w
- 8:38csr rs1 and what it does
- 8:41it's essentially a short for the csrw
- 8:44where the destination register is x0 it
- 8:47just writes
- 8:48the value from rs1 to the csr
- 8:53conversely the pseudo instructional csr
- 8:56wi writes the immediate value
- 8:59you immediate to the csr and when
- 9:03implementing this there is not much of a
- 9:05magic
- 9:06it's just the block of registers
- 9:08whatever the number of registers
- 9:10we need and remember since you would
- 9:13like to write to them
- 9:14don't forget clocks and write enable
- 9:17signals
- 9:18you don't want to scribble over your
- 9:20controlling status registers
- 9:22accidentally that's it
- 9:26but for controlling status registers
- 9:29there are a few more instructions in the
- 9:31base instruction set that we will not
- 9:33implement in this course but sometimes
- 9:35they pop up in our assembly code so it's
- 9:37a good
- 9:38good idea to know uh what they are so
- 9:40we're not so surprised when we see them
- 9:43we have equals and e-brakes
- 9:46both of them are of i format and share
- 9:49the same
- 9:50system up code and equal
- 9:54makes requests to the supporting
- 9:56execution environment
- 9:57namely the operating system
- 10:00such as system calls which would be
- 10:02linux
- 10:04syscalls and then
- 10:08e-brake is used to transfer the control
- 10:12to the debugger
- 10:17that's what we have of those and one
- 10:19more instruction that we
- 10:21sometimes may encounter is the fence
- 10:24much more rarely in this class this is
- 10:26the one that
- 10:27separates the memory and
- 10:30io accesses as viewed by other threads
- 10:34and processes and that is it
- 10:38will continue building the control after
- 10:40a break
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 20.1 - Single-Cycle CPU Control: Control and Status Registers by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,357 words across 253 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.