Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Computer_architecture_project2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lang0909
Computer_architecture_project2
Commits
b10292f7
Commit
b10292f7
authored
5 years ago
by
lang0909
Browse files
Options
Downloads
Patches
Plain Diff
Add header file
parents
Branches
master
No related tags found
No related merge requests found
Pipeline
#2187
canceled
5 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
parse.h
+32
-0
32 additions, 0 deletions
parse.h
run.h
+122
-0
122 additions, 0 deletions
run.h
util.h
+109
-0
109 additions, 0 deletions
util.h
with
263 additions
and
0 deletions
parse.h
0 → 100644
+
32
−
0
View file @
b10292f7
/***************************************************************/
/* */
/* 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
This diff is collapsed.
Click to expand it.
run.h
0 → 100644
+
122
−
0
View file @
b10292f7
/***************************************************************/
/* */
/* 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
This diff is collapsed.
Click to expand it.
util.h
0 → 100644
+
109
−
0
View file @
b10292f7
/***************************************************************/
/* */
/* 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment