Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. #/* $begin seq-all-hcl */
  2. ####################################################################
  3. # HCL Description of Control for Single Cycle Y86 Processor SEQ #
  4. # Copyright (C) Randal E. Bryant, David R. O'Hallaron, 2010 #
  5. ####################################################################
  6.  
  7. ## Your task is to implement the iaddl and leave instructions
  8. ## The file contains a declaration of the icodes
  9. ## for iaddl (IIADDL) and leave (ILEAVE).
  10. ## Your job is to add the rest of the logic to make it work
  11.  
  12. ####################################################################
  13. # C Include's. Don't alter these #
  14. ####################################################################
  15.  
  16. quote '#include <stdio.h>'
  17. quote '#include "isa.h"'
  18. quote '#include "sim.h"'
  19. quote 'int sim_main(int argc, char *argv[]);'
  20. quote 'int gen_pc(){return 0;}'
  21. quote 'int main(int argc, char *argv[])'
  22. quote ' {plusmode=0;return sim_main(argc,argv);}'
  23.  
  24. ####################################################################
  25. # Declarations. Do not change/remove/delete any of these #
  26. ####################################################################
  27.  
  28. ##### Symbolic representation of Y86 Instruction Codes #############
  29. intsig INOP 'I_NOP'
  30. intsig IHALT 'I_HALT'
  31. intsig IRRMOVL 'I_RRMOVL'
  32. intsig IIRMOVL 'I_IRMOVL'
  33. intsig IRMMOVL 'I_RMMOVL'
  34. intsig IMRMOVL 'I_MRMOVL'
  35. intsig IOPL 'I_ALU'
  36. intsig IJXX 'I_JMP'
  37. intsig ICALL 'I_CALL'
  38. intsig IRET 'I_RET'
  39. intsig IPUSHL 'I_PUSHL'
  40. intsig IPOPL 'I_POPL'
  41. # Instruction code for iaddl instruction
  42. intsig IIADDL 'I_IADDL'
  43. # Instruction code for leave instruction
  44. intsig ILEAVE 'I_LEAVE'
  45.  
  46. ##### Symbolic represenations of Y86 function codes #####
  47. intsig FNONE 'F_NONE' # Default function code
  48.  
  49. ##### Symbolic representation of Y86 Registers referenced explicitly #####
  50. intsig RESP 'REG_ESP' # Stack Pointer
  51. intsig REBP 'REG_EBP' # Frame Pointer
  52. intsig RNONE 'REG_NONE' # Special value indicating "no register"
  53.  
  54. ##### ALU Functions referenced explicitly #####
  55. intsig ALUADD 'A_ADD' # ALU should add its arguments
  56.  
  57. ##### Possible instruction status values #####
  58. intsig SAOK 'STAT_AOK' # Normal execution
  59. intsig SADR 'STAT_ADR' # Invalid memory address
  60. intsig SINS 'STAT_INS' # Invalid instruction
  61. intsig SHLT 'STAT_HLT' # Halt instruction encountered
  62.  
  63. ##### Signals that can be referenced by control logic ####################
  64.  
  65. ##### Fetch stage inputs #####
  66. intsig pc 'pc' # Program counter
  67. ##### Fetch stage computations #####
  68. intsig imem_icode 'imem_icode' # icode field from instruction memory
  69. intsig imem_ifun 'imem_ifun' # ifun field from instruction memory
  70. intsig icode 'icode' # Instruction control code
  71. intsig ifun 'ifun' # Instruction function
  72. intsig rA 'ra' # rA field from instruction
  73. intsig rB 'rb' # rB field from instruction
  74. intsig valC 'valc' # Constant from instruction
  75. intsig valP 'valp' # Address of following instruction
  76. boolsig imem_error 'imem_error' # Error signal from instruction memory
  77. boolsig instr_valid 'instr_valid' # Is fetched instruction valid?
  78.  
  79. ##### Decode stage computations #####
  80. intsig valA 'vala' # Value from register A port
  81. intsig valB 'valb' # Value from register B port
  82.  
  83. ##### Execute stage computations #####
  84. intsig valE 'vale' # Value computed by ALU
  85. boolsig Cnd 'cond' # Branch test
  86.  
  87. ##### Memory stage computations #####
  88. intsig valM 'valm' # Value read from memory
  89. boolsig dmem_error 'dmem_error' # Error signal from data memory
  90.  
  91.  
  92. ####################################################################
  93. # Control Signal Definitions. #
  94. ####################################################################
  95.  
  96. ################ Fetch Stage ###################################
  97.  
  98. # Determine instruction code
  99. int icode = [
  100. imem_error: INOP;
  101. 1: imem_icode; # Default: get from instruction memory
  102. ];
  103.  
  104. # Determine instruction function
  105. int ifun = [
  106. imem_error: FNONE;
  107. 1: imem_ifun; # Default: get from instruction memory
  108. ];
  109.  
  110. bool instr_valid = icode in
  111. { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL,
  112. IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL, IIADDL, ILEAVE };
  113.  
  114. # Does fetched instruction require a regid byte?
  115. bool need_regids =
  116. icode in { IRRMOVL, IOPL, IPUSHL, IPOPL,
  117. IIRMOVL, IRMMOVL, IMRMOVL, IIADDL, ILEAVE };
  118.  
  119. # Does fetched instruction require a constant word?
  120. bool need_valC =
  121. icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL, IIADDL };
  122.  
  123. ################ Decode Stage ###################################
  124.  
  125. ## What register should be used as the A source?
  126. int srcA = [
  127. icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA;
  128. icode in { IPOPL, IRET } : RESP;
  129. 1 : RNONE; # Don't need register
  130. ];
  131.  
  132. ## What register should be used as the B source?
  133. int srcB = [
  134. icode in { IOPL, IRMMOVL, IMRMOVL, IIADDL } : rB;
  135. icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP;
  136. icode in { ILEAVE } : REBP;
  137. 1 : RNONE; # Don't need register
  138. ];
  139.  
  140. ## What register should be used as the E destination?
  141. int dstE = [
  142. icode in { IRRMOVL } && Cnd : rB;
  143. icode in { IIRMOVL, IOPL, IIADDL} : rB;
  144. icode in { IPUSHL, IPOPL, ICALL, IRET, ILEAVE } : RESP;
  145. 1 : RNONE; # Don't write any register
  146. ];
  147.  
  148. ## What register should be used as the M destination?
  149. int dstM = [
  150. icode in { IMRMOVL, IPOPL } : rA;
  151. icode in { ILEAVE } : REBP;
  152. 1 : RNONE; # Don't write any register
  153. ];
  154.  
  155. ################ Execute Stage ###################################
  156.  
  157. ## Select input A to ALU
  158. int aluA = [
  159. icode in { IRRMOVL, IOPL } : valA;
  160. icode in { IIRMOVL, IRMMOVL, IMRMOVL, IIADDL } : valC;
  161. icode in { ICALL, IPUSHL } : -4;
  162. icode in { IRET, IPOPL, ILEAVE } : 4;
  163. # Other instructions don't need ALU
  164. ];
  165.  
  166. ## Select input B to ALU
  167. int aluB = [
  168. icode in { IRMMOVL, IMRMOVL, IOPL, ICALL,
  169. IPUSHL, IRET, IPOPL, IIADDL, ILEAVE } : valB;
  170. icode in { IRRMOVL, IIRMOVL } : 0;
  171. # Other instructions don't need ALU
  172. ];
  173.  
  174. ## Set the ALU function
  175. int alufun = [
  176. icode == IOPL : ifun;
  177. icode == IADDL : ifun;
  178. 1 : ALUADD;
  179. ];
  180.  
  181. ## Should the condition codes be updated?
  182. bool set_cc = icode in { IOPL, IIADDL };
  183.  
  184. ################ Memory Stage ###################################
  185.  
  186. ## Set read control signal
  187. bool mem_read = icode in { IMRMOVL, IPOPL, IRET, ILEAVE };
  188.  
  189. ## Set write control signal
  190. bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };
  191.  
  192. ## Select memory address
  193. int mem_addr = [
  194. icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL } : valE;
  195. icode in { IPOPL, IRET, ILEAVE } : valA;
  196. # Other instructions don't need address
  197. ];
  198.  
  199. ## Select memory input data
  200. int mem_data = [
  201. # Value from register
  202. icode in { IRMMOVL, IPUSHL } : valA;
  203. icode in { ILEAVE } : valB;
  204. # Return PC
  205. icode == ICALL : valP;
  206. # Default: Don't write anything
  207. ];
  208.  
  209. ## Determine instruction status
  210. int Stat = [
  211. imem_error || dmem_error : SADR;
  212. !instr_valid: SINS;
  213. icode == IHALT : SHLT;
  214. 1 : SAOK;
  215. ];
  216.  
  217. ################ Program Counter Update ############################
  218.  
  219. ## What address should instruction be fetched at
  220.  
  221. int new_pc = [
  222. # Call. Use instruction constant
  223. icode == ICALL : valC;
  224. # Taken branch. Use instruction constant
  225. icode == IJXX && Cnd : valC;
  226. # Completion of RET instruction. Use value from stack
  227. icode == IRET : valM;
  228. # Default: Use incremented PC
  229. 1 : valP;
  230. ];
  231. #/* $end seq-all-hcl */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement