《信息安全系統設計基礎》家庭做業

《信息安全系統設計基礎》家庭做業

4.49

在seq-full.hcl中,修改實現leave指令的控制邏輯塊的HCL描述。緩存

首先,leave等價的Y86代碼序列爲:安全

rrmovl %ebp,%esp
popl %ebp

相應棧幀如圖所示:
fetch

則實現這個指令所須要執行的計算爲:
ui

因此,在對seq-full.hcl的修改中,要將leave指令寫入instr_valid,代表該指令爲合法指令;在譯碼與寫回階段,對srcA添加leave指令對應於%ebp,對srcB添加leave指令對應於%ebp,dstE添加leave指令寫回於%esp,dstM添加leave指令寫回於%ebp;在執行階段,須要對操做數A賦值爲4,即對aluA添加leave指令對應+4,aluB添加leave指令對應valB(即%ebp);在訪存階段,只讀控制信號men_read添加leave指令,地址men_addr添加leave指令對應於valA(即%ebp);在更新PC階段無變化設計

seq-full.hcl的修改後:
3d

代碼:code

################ Fetch Stage     ###################################

# Determine instruction code
int icode = [
    imem_error: INOP;
    1: imem_icode;      # Default: get from instruction memory
];

# Determine instruction function
int ifun = [
    imem_error: FNONE;
    1: imem_ifun;       # Default: get from instruction memory
];

bool instr_valid = icode in 
    { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL,
           IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL ,ILEAVE };

# Does fetched instruction require a regid byte?
bool need_regids =
    icode in { IRRMOVL, IOPL, IPUSHL, IPOPL, 
             IIRMOVL, IRMMOVL, IMRMOVL  };

# Does fetched instruction require a constant word?
bool need_valC =
    icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL  };

################ Decode Stage    ###################################

## What register should be used as the A source?
int srcA = [
    icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL  } : rA;
    icode in { IPOPL, IRET } : RESP;
    icode in { ILEAVE } : REBP;
    1 : RNONE; # Don't need register
];

## What register should be used as the B source?
int srcB = [
    icode in { IOPL, IRMMOVL, IMRMOVL  } : rB;
    icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP;
    icode in { ILEAVE } : REBP;
    1 : RNONE;  # Don't need register
];

## What register should be used as the E destination?
int dstE = [
    icode in { IRRMOVL } && Cnd : rB;
    icode in { IIRMOVL, IOPL} : rB;
    icode in { IPUSHL, IPOPL, ICALL, IRET ,ILEAVE} : RESP;
    1 : RNONE;  # Don't write any register
];

## What register should be used as the M destination?
int dstM = [
    icode in { IMRMOVL, IPOPL } : rA;
    icode in { ILEAVE } : REBP;
    1 : RNONE;  # Don't write any register
];

################ Execute Stage   ###################################

## Select input A to ALU
int aluA = [
    icode in { IRRMOVL, IOPL } : valA;
    icode in { IIRMOVL, IRMMOVL, IMRMOVL } : valC;
    icode in { ICALL, IPUSHL } : -4;
    icode in { IRET, IPOPL ,ILEAVE} : 4;
    # Other instructions don't need ALU
];

## Select input B to ALU
int aluB = [
    icode in { IRMMOVL, IMRMOVL, IOPL, ICALL, 
              IPUSHL, IRET, IPOPL ,ILEAVE} : valB;  
    icode in { IRRMOVL, IIRMOVL } : 0;
    # Other instructions don't need ALU
];

## Set the ALU function
int alufun = [
    icode == IOPL : ifun;
    1 : ALUADD;
];

## Should the condition codes be updated?
bool set_cc = icode in { IOPL };

################ Memory Stage    ###################################

## Set read control signal
bool mem_read = icode in { IMRMOVL, IPOPL, IRET ,ILEAVE };

## Set write control signal
bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };

## Select memory address
int mem_addr = [
    icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL } : valE;
    icode in { IPOPL, IRET ,ILEAVE} : valA;
    # Other instructions don't need address
];

## Select memory input data
int mem_data = [
    # Value from register
    icode in { IRMMOVL, IPUSHL } : valA;
    # Return PC
    icode == ICALL : valP;
    # Default: Don't write anything
];

## Determine instruction status
int Stat = [
    imem_error || dmem_error : SADR;
    !instr_valid: SINS;
    icode == IHALT : SHLT;
    1 : SAOK;
];

################ Program Counter Update ############################

## What address should instruction be fetched at

int new_pc = [
    # Call.  Use instruction constant
    icode == ICALL : valC;
    # Taken branch.  Use instruction constant
    icode == IJXX && Cnd : valC;
    # Completion of RET instruction.  Use value from stack
    icode == IRET : valM;
    # Default: Use incremented PC
    1 : valP;
];

6.33

先計算出s、b、t,將地址解析成指引高速緩存的位置
blog

6.34

組5意味着地址第4到第2位爲「101」,觀察4路組相聯高速緩存索引5中 V 表示爲「1」的行,裏面的數據塊便是可能命中的數據,8個存儲器地址爲 0x1314 0x1315 0x1316 0x1317 0x1794 0x1795 0x1796 0x1797索引

相關文章
相關標籤/搜索