// // prototypes.h // // Description: // AD-MIPS Function Prototypes // // Version: // $Id$ // // Revision: // $Log$ // // Author: // Brian J. Alliet // Jonathon W. Donaldson // #ifndef _PROTOTYPES_H #define _PROTOTYPES_H /* * Adder (just adds instead of having to use entire BusALU object) */ class Adder : public Connector { public: Adder(const char *id, int numbits); void connectFrom(OutFlow& op1, OutFlow &op2); ~Adder(); OutFlow& OUT() { return m_output; } virtual long computeValue(); private: OutFlow m_output; OutFlow *m_op1; OutFlow *m_op2; }; /* * Injector (see Injector.C) */ class Injector : public Connector { public: Injector(const char *id, int numbits); ~Injector(); OutFlow& OUT() { return m_output; } virtual long computeValue(); private: OutFlow m_output; public: long m_val; }; /* * Bus for sign-extension and shifting */ class SuperBus : public Bus { public: SuperBus(const char *id, int numbits, long mask=~0, int shift=0); ~SuperBus(); virtual long computeValue(); private: long m_mask; int m_shift; }; /* * Creates logical hardware connections for the AD-MIPS CPU */ void make_connections(); /* * Performs all forwarding for AD-MIPS pipeline */ extern StorageObject* forward(long reg_num, StorageObject* fallback, int from); /* * Pipeline stage functions. */ extern void fetch(); extern void decode(); extern bool branch(); extern void execute(); extern void memory(); extern void writeback(); extern long mips_syscall(long nr, long a0, long a1, long a2); static inline long OP(StorageObject& ir) { return ir(31,26); } static inline long RS(StorageObject& ir) { return ir(25,21); } static inline long RT(StorageObject& ir) { return ir(20,16); } static inline long RD(StorageObject& ir) { return ir(15,11); } static inline long SHAMT(StorageObject& ir) { return ir(10,6); } static inline long FUNC(StorageObject& ir) { return ir(5,0); } // test if instruction loads memory static inline bool loadsMem(StorageObject& ir) { return ir(29,29) == 0 && ir(31,31) == 1; } // test if instrux writes to memory static inline bool storesMem(StorageObject& ir) { return ir(29,29) == 1 && ir(31,31) == 1; } static inline bool writesRD(StorageObject& ir) { return OP(ir) == 0x0 && FUNC(ir) != 0x8 /* JAL */ && FUNC(ir) != 0x9 /* JALR */ && FUNC(ir) != 0xc /* SYSCALL */; } static inline bool writesRT(StorageObject& ir) { return (ir(29,29) == 1 && ir(31,31) == 0) || loadsMem(ir); } static inline bool writesRA(StorageObject& ir) { return OP(ir) == 0x03 /* JAL */ || (OP(ir) == 0x00 && FUNC(ir) == 0x09 /* JALR */) || (OP(ir) == 0x01 && ir(20,20) == 1 /* B*AL */) ; } static inline bool writesV0(StorageObject &ir) { return OP(ir) == 0x0 && FUNC(ir) == 0xc /* SYSCALL */; } #endif