diff options
| -rwxr-xr-x[-rw-r--r--] | LICENSE | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | README.md | 2 | ||||
| -rw-r--r-- | binwrite.c | 21 | ||||
| -rwxr-xr-x[-rw-r--r--] | makefile | 10 | ||||
| -rwxr-xr-x | mips | bin | 17624 -> 0 bytes | |||
| -rw-r--r-- | mips.o | bin | 11504 -> 0 bytes | |||
| -rwxr-xr-x[-rw-r--r--] | qdme.c (renamed from mips.c) | 46 | ||||
| -rw-r--r-- | qdme.h | 50 | ||||
| -rwxr-xr-x[-rw-r--r--] | test.bin | bin | 32 -> 32 bytes |
9 files changed, 59 insertions, 70 deletions
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; -} @@ -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) Binary files differBinary files differ@@ -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; @@ -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 + Binary files differ |
