康磊++楊朝輝
摘要:在計(jì)算機(jī)組成原理的教學(xué)中,CPU設(shè)計(jì)實(shí)驗(yàn)?zāi)軌蚴箤W(xué)生深入理解和掌握計(jì)算機(jī)的運(yùn)行和控制機(jī)制。該文提出了一種基于FPGA的CPU開放式實(shí)驗(yàn)平臺的設(shè)計(jì)思想,該平臺由上位機(jī)和硬件開發(fā)平臺組成。通過開放式實(shí)驗(yàn)平臺,學(xué)生可以根據(jù)自行選取的MIPS指令集修改模型機(jī)的數(shù)據(jù)通路和控制通路并設(shè)計(jì)控制器,通過實(shí)驗(yàn)平臺觀察運(yùn)行過程和結(jié)果以確定設(shè)計(jì)的正確性。
關(guān)鍵詞:CPU實(shí)驗(yàn)?zāi)P?;?shù)據(jù)通路;控制通路;MIPS指令集;FPGA
中國分類號:TP302 文獻(xiàn)標(biāo)識碼:A 文章編號:1009-3044(2017)30-0235-03
Design of Open CPU Experiment Model Based on FPGA
KANG Lei,YANG Zhao-hui
(School of Computer, Xi'an University of Petroleum, Xi'an 710065, China)
Abstract: CPU design experiment in the teaching of computer composing principle can make student understand and master the mechanism of computer operation and control deeply. This paper presents a design idea of an open CPU experiment platform Based on FPGA, which is composed of the host computer and the hardware development platform. Through the open experiment platform, the students can modify the data path and control path of the model machine and design the control unit according to their own MIPS instruction set, and observe the running process and the result to ensure the correctness of the design through the experimental platform.
Key words: CPU experimental model; Datapath; Controlpath; The MIPS instruction set; FPGA
由于中央處理器(CPU Central Processing Unit)在現(xiàn)代計(jì)算機(jī)系統(tǒng)中占有核心功能,對于計(jì)算機(jī)專業(yè)的課程體系,CPU的設(shè)計(jì)開發(fā)是一個(gè)重點(diǎn)和難點(diǎn)。完成CPU的設(shè)計(jì)需要學(xué)生學(xué)習(xí)計(jì)算機(jī)的組成原理,系統(tǒng)結(jié)構(gòu)等,并以此設(shè)計(jì)出CPU系統(tǒng)。而在計(jì)算機(jī)組成原理的CPU設(shè)計(jì)試驗(yàn)中,目前國內(nèi)高校普遍使用的是教學(xué)系統(tǒng)或者小規(guī)模集成電路和手工布線方式,這樣只能進(jìn)行驗(yàn)證性實(shí)驗(yàn),或者實(shí)驗(yàn)的規(guī)模有限,過于瑣碎的操作耗費(fèi)設(shè)計(jì)人員的精力,無法提供自住設(shè)計(jì)和發(fā)揮的平臺。
本文通過研究和設(shè)計(jì)基于FPGA的32位開放式CPU試驗(yàn)?zāi)P?,同時(shí)設(shè)計(jì)開發(fā)出相關(guān)的驗(yàn)證調(diào)試系統(tǒng),為設(shè)計(jì)人員提供了一套開放式,可自主設(shè)計(jì)的CPU設(shè)計(jì)實(shí)驗(yàn)環(huán)境。設(shè)計(jì)人員通過該開放式CPU模型能直觀感受CPU的工作原理和各部件的功能,根據(jù)自己的設(shè)計(jì)更新該實(shí)驗(yàn)?zāi)P偷南嚓P(guān)部件,并設(shè)計(jì)自己的數(shù)據(jù)通路和控制通路來實(shí)現(xiàn)自己的設(shè)計(jì)。通過調(diào)試系統(tǒng)設(shè)計(jì)人員可以監(jiān)控CPU內(nèi)部運(yùn)行情況,對設(shè)計(jì)的CPU進(jìn)行運(yùn)行調(diào)試驗(yàn)證,完成CPU的設(shè)計(jì)和實(shí)現(xiàn)驗(yàn)證。
1 CPU功能和結(jié)構(gòu)設(shè)計(jì)
1.1. CPU的指令系統(tǒng)
指令系統(tǒng)作為CPU的對上接口,定義了CPU的功能,并直接影響了CPU的實(shí)現(xiàn)。MIPS作為精簡指令集(RISC Reduced Instruction Set Computer)的代表,有著指令定長,結(jié)構(gòu)簡單的特點(diǎn)。選擇MIPS指令集可以減少指令設(shè)計(jì)難度。本文的指令基于MIPS指令集進(jìn)行設(shè)計(jì),存儲系統(tǒng)采用哈佛結(jié)構(gòu)。
MIPS指令分為立即數(shù)類型(I類型),跳轉(zhuǎn)類型(J類型),和寄存器類型(R類型)三種。本文設(shè)計(jì)的模型機(jī)選取了如表1所示的10條指令。這10條指令分別屬于算術(shù)邏輯運(yùn)算類,訪存類和跳轉(zhuǎn)類,可以滿足程序設(shè)計(jì)的基本要求。
表1 選取的10條指令
[類別\&指令助記符\&描述\&運(yùn)算類\&addu rd, rs, rt\&GPR[rd]<-GPR[rs]+ GPR[rt]\&subu rd, rs, rt\&GPR[rd]<-GPR[rs]- GPR[rt]\&and rd, rs, rt\&GPR[rd]<-GPR[rs] AND GPR[rt]\&ori rt, rs, imm\&GPR[rt]<-GPR[rs] OR imm\&訪存類\&lw rt, offset(base)\&GPR[rt]<-mem[GPR[base]+offset]\&sw rt, offset(base)\&mem[GPR[base]+offset]<-GPR[rt]\&跳轉(zhuǎn)類\&beq rs, rt, offset\&if(GPR[rs]==GPR[rt]) then轉(zhuǎn)移\&bne rs, rt, offset\&if(GPR[rs] ≠GPR[rt]) then轉(zhuǎn)移\&jr rs \&PC <- GPR[rs]\&jal target\&PC <- PC31..28||instr_index||02
GPR[31]<-PC + 4\&]endprint