Skip to content
Snippets Groups Projects
Commit b10292f7 authored by lang0909's avatar lang0909
Browse files

Add header file

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #2187 canceled
parse.h 0 → 100644
/***************************************************************/
/* */
/* MIPS-32 Instruction Level Simulator */
/* */
/* SCE212 Ajou University */
/* parse.h */
/* Adapted from CS311@KAIST */
/* */
/***************************************************************/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* DO NOT MODIFY THIS FILE! */
/* You should only the parse.c and run.c files! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
#ifndef _PARSE_H_
#define _PARSE_H_
#include <stdio.h>
#include "util.h"
extern int text_size;
extern int data_size;
/* functions */
/** Implement the two parsing_* functions in parse.c */
instruction parsing_instr(const char *buffer, const int index);
void parsing_data(const char *buffer, const int index);
void print_parse_result();
#endif
run.h 0 → 100644
/***************************************************************/
/* */
/* MIPS-32 Instruction Level Simulator */
/* */
/* SCE212 Ajou University */
/* run.h */
/* Adapted from CS311@KAIST */
/* */
/***************************************************************/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* DO NOT MODIFY THIS FILE! */
/* You should only the parse.c and run.c files! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
#ifndef _RUN_H_
#define _RUN_H_
#include <stdio.h>
#include "util.h"
#define OPCODE(INST) (INST)->opcode
#define SET_OPCODE(INST, VAL) (INST)->opcode = (short)(VAL)
#define FUNC(INST) (INST)->func_code
#define SET_FUNC(INST, VAL) (INST)->func_code = (short)(VAL)
#define RS(INST) (INST)->r_t.r_i.rs
#define SET_RS(INST, VAL) (INST)->r_t.r_i.rs = (unsigned char)(VAL)
#define RT(INST) (INST)->r_t.r_i.rt
#define SET_RT(INST, VAL) (INST)->r_t.r_i.rt = (unsigned char)(VAL)
#define RD(INST) (INST)->r_t.r_i.r_i.r.rd
#define SET_RD(INST, VAL) (INST)->r_t.r_i.r_i.r.rd = (unsigned char)(VAL)
#define FS(INST) RD(INST)
#define SET_FS(INST, VAL) SET_RD(INST, VAL)
#define FT(INST) RT(INST)
#define SET_FT(INST, VAL) SET_RT(INST, VAL)
#define FD(INST) SHAMT(INST)
#define SET_FD(INST, VAL) SET_SHAMT(INST, VAL)
#define SHAMT(INST) (INST)->r_t.r_i.r_i.r.shamt
#define SET_SHAMT(INST, VAL) (INST)->r_t.r_i.r_i.r.shamt = (unsigned char)(VAL)
#define IMM(INST) (INST)->r_t.r_i.r_i.imm
#define SET_IMM(INST, VAL) (INST)->r_t.r_i.r_i.imm = (short)(VAL)
#define BASE(INST) RS(INST)
#define SET_BASE(INST, VAL) SET_RS(INST, VAL)
#define IOFFSET(INST) IMM(INST)
#define SET_IOFFSET(INST, VAL) SET_IMM(INST, VAL)
#define IDISP(INST) (SIGN_EX (IOFFSET (INST) << 2))
#define COND(INST) RS(INST)
#define SET_COND(INST, VAL) SET_RS(INST, VAL)
#define CC(INST) (RT(INST) >> 2)
#define ND(INST) ((RT(INST) & 0x2) >> 1)
#define TF(INST) (RT(INST) & 0x1)
#define TARGET(INST) (INST)->r_t.target
#define SET_TARGET(INST, VAL) (INST)->r_t.target = (mem_addr)(VAL)
#define ENCODING(INST) (INST)->encoding
#define SET_ENCODING(INST, VAL) (INST)->encoding = (int32)(VAL)
#define EXPR(INST) (INST)->expr
#define SET_EXPR(INST, VAL) (INST)->expr = (imm_expr*)(VAL)
#define SOURCE(INST) (INST)->source_line
#define SET_SOURCE(INST, VAL) (INST)->source_line = (char *)(VAL)
/* Sign Extension */
#define SIGN_EX(X) (((X) & 0x8000) ? ((X) | 0xffff0000) : (X))
#define COND_UN 0x1
#define COND_EQ 0x2
#define COND_LT 0x4
#define COND_IN 0x8
/* Minimum and maximum values that fit in instruction's imm field */
#define IMM_MIN 0xffff8000
#define IMM_MAX 0x00007fff
#define UIMM_MIN (unsigned)0
#define UIMM_MAX ((unsigned)((1<<16)-1))
#define BRANCH_INST(TEST, TARGET, NULLIFY) \
{ \
if (TEST) \
{ \
uint32_t target = (TARGET); \
JUMP_INST(target) \
} \
}
#define JUMP_INST(TARGET) \
{ \
CURRENT_STATE.PC = (TARGET); \
}
#define LOAD_INST(DEST_A, LD, MASK) \
{ \
LOAD_INST_BASE (DEST_A, (LD & (MASK))) \
}
#define LOAD_INST_BASE(DEST_A, VALUE) \
{ \
*(DEST_A) = (VALUE); \
}
/* functions */
instruction* get_inst_info(uint32_t pc);
void process_instruction();
#endif
util.h 0 → 100644
/***************************************************************/
/* */
/* MIPS-32 Instruction Level Simulator */
/* */
/* SCE212 Ajou University */
/* util.h */
/* Adapted from CS311@KAIST */
/* */
/***************************************************************/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* DO NOT MODIFY THIS FILE! */
/* You should only the parse.c and run.c files! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
#ifndef _UTIL_H_
#define _UTIL_H_
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define FALSE 0
#define TRUE 1
/* Basic Information */
#define MEM_TEXT_START 0x00400000
#define MEM_TEXT_SIZE 0x00100000
#define MEM_DATA_START 0x10000000
#define MEM_DATA_SIZE 0x00100000
#define MIPS_REGS 32
#define BYTES_PER_WORD 4
typedef struct CPU_State_Struct {
uint32_t PC; /* program counter */
uint32_t REGS[MIPS_REGS]; /* register file. */
} CPU_State;
/* You should decode your instructions from the
* ASCII-binary format to this structured format */
typedef struct inst_s {
short opcode;
/*R-type*/
short func_code;
union {
/* R-type or I-type: */
struct {
unsigned char rs;
unsigned char rt;
union {
short imm;
struct {
unsigned char rd;
unsigned char shamt;
} r;
} r_i;
} r_i;
/* J-type: */
uint32_t target;
} r_t;
uint32_t value;
} instruction;
/* All simulated memory will be managed by this structure
* use the mem_write_32() and mem_read_32() functions to
* access/modify the simulated memory */
typedef struct {
uint32_t start, size;
uint8_t *mem;
} mem_region_t;
/* For PC * Registers */
extern CPU_State CURRENT_STATE;
/* For Instructions */
extern instruction *INST_INFO;
extern int NUM_INST;
/* For Memory Regions */
extern mem_region_t MEM_REGIONS[2];
/* For Execution */
extern int RUN_BIT; /* run bit */
extern int INSTRUCTION_COUNT;
/* Functions */
char** str_split(char *a_str, const char a_delim);
int fromBinary(char *s);
uint32_t mem_read_32(uint32_t address);
void mem_write_32(uint32_t address, uint32_t value);
void cycle();
void run(int num_cycles);
void go();
void mdump(int start, int stop);
void rdump();
void init_memory();
void init_inst_info();
/* YOU IMPLEMENT THIS FUNCTION */
void process_instruction();
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment