summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2024-05-09 18:54:46 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2024-05-09 18:54:46 -0400
commit3cfd8e1da5dedecf9c306770acbc7125ec874d35 (patch)
tree23c7cfa69278e99d4cd08de3126a6ba074acbd95
parent3f51c2469c71154f6ce7cb75460488fd8e58e3ec (diff)
Move to Big Endian Binaries
-rwxr-xr-x[-rw-r--r--]LICENSE0
-rwxr-xr-x[-rw-r--r--]README.md2
-rw-r--r--binwrite.c21
-rwxr-xr-x[-rw-r--r--]makefile10
-rwxr-xr-xmipsbin17624 -> 0 bytes
-rw-r--r--mips.obin11504 -> 0 bytes
-rwxr-xr-x[-rw-r--r--]qdme.c (renamed from mips.c)46
-rw-r--r--qdme.h50
-rwxr-xr-x[-rw-r--r--]test.binbin32 -> 32 bytes
9 files changed, 59 insertions, 70 deletions
diff --git a/LICENSE b/LICENSE
index 10f0753..10f0753 100644..100755
--- a/LICENSE
+++ b/LICENSE
diff --git a/README.md b/README.md
index 370e3e6..d7b8757 100644..100755
--- a/README.md
+++ b/README.md
@@ -66,5 +66,5 @@ manually created, eventually this will change.
|14 |Not Implemented Yet|
|15 |Not Implemented Yet|
|16 |Not Implemented Yet|
-|17 |Exit with Status Code in $0|
+|17 |Exit with Status Code in $a0|
diff --git a/binwrite.c b/binwrite.c
deleted file mode 100644
index e70edbc..0000000
--- a/binwrite.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-
-int main(void) {
- uint32_t insts[] = {
- 0x2008000a, // addi $t0, $zero, 10
- 0x2009000b, // addi $t1, $zero, 11
- 0x01285020, // add $t2, $t1, $t0
- 0x20020001, // addi $v0, $zero, 1
- 0x000a2020, // add $a0, $zero, $t2
- 0x0000000C, // syscall
- 0x2002000a, // addi $v0, $zero, 10
- 0x0000000C, // syscall
- };
- FILE *fp = fopen("test.bin", "w");
- for (size_t i = 0; i < sizeof(insts) / sizeof(insts[0]); i++) {
- fwrite(insts + i, 1, 4, fp);
- }
- fclose(fp);
- return 0;
-}
diff --git a/makefile b/makefile
index e5c8228..d8e53c5 100644..100755
--- a/makefile
+++ b/makefile
@@ -1,13 +1,15 @@
CC=gcc
CFLAGS=-Wall -Werror -pedantic --std=c17
-OBJS=mips.o
-TARGET=mips
+OBJS=qdme.o
+TARGET=qdme
-%.o: %.c
- $(CC) $(CFLAGS) -c $@ $^
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c $@ $<
all: $(TARGET)
mips: $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
+clean:
+ rm -rf $(TARGET)
diff --git a/mips b/mips
deleted file mode 100755
index 3a7a0a9..0000000
--- a/mips
+++ /dev/null
Binary files differ
diff --git a/mips.o b/mips.o
deleted file mode 100644
index 1a23fe9..0000000
--- a/mips.o
+++ /dev/null
Binary files differ
diff --git a/mips.c b/qdme.c
index dcda5f7..c957609 100644..100755
--- a/mips.c
+++ b/qdme.c
@@ -1,51 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
-
-#define MEM_SIZE 36
-#define RA 31
-#define V0 2
-#define V1 3
-#define A0 4
-#define A1 5
-#define A2 6
-#define A3 7
-#define WORD_SIZE 4
-
-typedef struct {
- unsigned int op: 6;
- unsigned int rs: 5;
- unsigned int rt: 5;
- unsigned int rd: 5;
- unsigned int shamt: 5;
- unsigned int func: 6;
-} rtype_t;
-
-typedef struct {
- unsigned int op: 6;
- unsigned int rs: 5;
- unsigned int rt: 5;
- unsigned int imm: 16;
-} itype_t;
-
-typedef struct {
- unsigned int op: 6;
- unsigned int addr: 26;
-} jtype_t;
-
-typedef enum { NOP, RTYPE, ITYPE, JTYPE } type_t;
-
-typedef struct {
- type_t type;
- union {
- uint32_t value;
- rtype_t r;
- jtype_t j;
- itype_t i;
- };
-} inst_t;
+#include "qdme.h"
uint8_t memory[MEM_SIZE] = {0};
uint32_t pc = 0, hi = 0, lo = 0;
@@ -56,6 +13,7 @@ uint32_t regFile[32] = {0};
void InstFetch(inst_t *inst) {
uint32_t value = 0;
memcpy(&value, memory + pc, WORD_SIZE);
+ value = ntohl(value);
switch ((value & 0xFC000000) >> 24) {
case 0:
inst->type = RTYPE;
diff --git a/qdme.h b/qdme.h
new file mode 100644
index 0000000..50652f0
--- /dev/null
+++ b/qdme.h
@@ -0,0 +1,50 @@
+#ifndef _QDME_H
+#define _QDME_H
+
+#include <stdint.h>
+
+#define MEM_SIZE 36
+#define RA 31
+#define V0 2
+#define V1 3
+#define A0 4
+#define A1 5
+#define A2 6
+#define A3 7
+#define WORD_SIZE 4
+
+typedef struct {
+ unsigned int op: 6;
+ unsigned int rs: 5;
+ unsigned int rt: 5;
+ unsigned int rd: 5;
+ unsigned int shamt: 5;
+ unsigned int func: 6;
+} rtype_t;
+
+typedef struct {
+ unsigned int op: 6;
+ unsigned int rs: 5;
+ unsigned int rt: 5;
+ unsigned int imm: 16;
+} itype_t;
+
+typedef struct {
+ unsigned int op: 6;
+ unsigned int addr: 26;
+} jtype_t;
+
+typedef enum { NOP, RTYPE, ITYPE, JTYPE } type_t;
+
+typedef struct {
+ type_t type;
+ union {
+ rtype_t r;
+ jtype_t j;
+ itype_t i;
+ uint32_t value;
+ };
+} inst_t;
+
+#endif
+
diff --git a/test.bin b/test.bin
index cb24090..2cf7b8d 100644..100755
--- a/test.bin
+++ b/test.bin
Binary files differ