Skip to content

Commit

Permalink
feat datapath added
Browse files Browse the repository at this point in the history
  • Loading branch information
kdhrepos committed May 9, 2024
1 parent cf7f631 commit 8f2ee60
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datapath/alu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "core.h"

/* we need basic arithmetic operations like add, sub, mult, div
* and logical operations
*/
3 changes: 3 additions & 0 deletions datapath/ctrl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "core.h"
7 changes: 7 additions & 0 deletions datapath/decode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "core.h"

/* instruction decoder */

/* hazard detection */
3 changes: 3 additions & 0 deletions datapath/fetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "core.h"
3 changes: 3 additions & 0 deletions datapath/mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "core.h"
1 change: 1 addition & 0 deletions datapath/regfile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* MIPS32 Register File */
42 changes: 42 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <stdio.h>
#include "core.h"

/*
* Component Init
**/
void init_simulator(MIPS32Simulator * sim)
{
/* Memory Init */
for (int i = 0; i < MEM_SIZE; i++)
sim->memory[i] = 0;

/* GP Register Init */
for (int i = 0; i < GP_REG_SIZE; i++)
sim->gp_registers[i] = 0;

sim->pc = 0; /* PC Init */
}

void run_simulator(MIPS32Simulator * sim)
{
while(TRUE)
{
int inst = sim -> memory[sim -> pc / 4]; /* Current Instruction */
sim -> pc += 4; /* Next Instruction */

int opcode = (inst >> 26) & 0x3F;
int rs = (inst >> 21) & 0x1F;
int rt = (inst >> 16) & 0x1F;
int rd = (inst >> 11) & 0x1F;
int imm = inst & 0xFFFF;
}
}

int main()
{
MIPS32Simulator sim;

init_simulator(&sim);
}

0 comments on commit 8f2ee60

Please sign in to comment.