Example #1
0
/**
 * Function: memoryStage
 * This driver function updates the values in writebackStage
 */
void memoryStage(forwardType * forward, statusType * status, bubbleType * bubble) {
    unsigned int valM;
    unsigned int valE;
    bool memError = FALSE;
    valE = memAddr();
    valM = memCond(valE,&memError);
    if(!memRead())
        valM = 0;
    //Forwarding from memoryStage
    (*forward).m_valM = valM;
    (*forward).M_valE = M.valE;

    (*forward).M_dstE = M.dstE;
    (*forward).M_dstM = M.dstM;
    (*forward).M_Cnd = M.Cnd; 
    (*forward).M_icode = M.icode;
    (*forward).M_valA = M.valA;
    unsigned int mStat;
    mStat = setStat(memError);
    //Updating stat in the statusType struct
    //and the bubbleType struct
    (*status).m_stat = mStat;
    (*bubble).M_icode = M.icode;
    if(!(W_stall(*bubble,*status)))
        updateWStage(mStat,M.icode,M.valE,valM,M.dstE,M.dstM);
}
Example #2
0
/* memoryStage
 *      Controls the main combinational logic of the memory stage
 * Params:   fwdStruct *fwd - contains a bunch of forwarding info 
 * Returns:  void
 * Modifies: Writeback Register
 */
void memoryStage(fwdStruct *fwd) {

    if (M.stat == SINS || M.stat == SADR || M.stat == SHLT)
        canUpdateMem = FALSE;
 
    int valM = M.valA, stat = M.stat;

    bool readC = FALSE, writeC = FALSE, memError = FALSE;
    
    memoryControl(&readC, &writeC);
    
    int memAddr = memoryAddr();
    
    if (readC)
        valM = getWord(memAddr, &memError);
    
    if (writeC && canUpdateMem)
        putWord(memAddr, M.valA, &memError);

    if (memError) {
        stat = SADR;
        canUpdateMem = FALSE;
    }
    
    fwd->M_valE = M.valE;
    fwd->m_valM = valM;
    fwd->M_dstE = M.dstE;
    fwd->M_dstM = M.dstM;
    fwd->M_Cnd = M.Cnd;
    fwd->M_icode = M.icode;
    fwd->M_valA = M.valA;
    fwd->m_stat = stat;

    if (!W_stall(fwd))
        updateWregister(stat, M.icode, M.valE, valM, M.dstE, M.dstM);
    
}