diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e1e148a --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +OBJS=emul.o emul_mem.o emul_reg.o emul_io_std.o emul_io_file.o +CC=gcc + +emulcomp: $(OBJS) + $(CC) $(OBJS) -o emulcomp + +emul.o: emul.c + $(CC) -c emul.c + +emul_mem.o: emul_mem.c + $(CC) -c emul_mem.c +emul_reg.o: emul_reg.c + $(CC) -c emul_reg.c + +emul_io_std.o: emul_io_std.c + $(CC) -c emul_io_std.c +emul_io_file.o: emul_io_file.c + $(CC) -c emul_io_file.c + +clean: + rm -f $(OBJS) diff --git a/emul.c b/emul.c new file mode 100644 index 0000000..49eee05 --- /dev/null +++ b/emul.c @@ -0,0 +1,15 @@ +#include "emul_reg.h" +#include "emul_mem.h" +#include "emul_io_std.h" + +int main(void) { + emul_reg_init(); + emul_open_file("test.txt", "w+"); + emul_out_file('a'); + emul_out_file('a'); + emul_out_file('a'); + emul_out_file('a'); + emul_out_file('a'); + emul_out_file('a'); + emul_close_file(); +} diff --git a/emul.o b/emul.o new file mode 100644 index 0000000..7c3e101 --- /dev/null +++ b/emul.o Binary files differ diff --git a/emul_inst.c b/emul_inst.c new file mode 100644 index 0000000..7825381 --- /dev/null +++ b/emul_inst.c @@ -0,0 +1 @@ +#include "emul_inst.h" diff --git a/emul_inst.h b/emul_inst.h new file mode 100644 index 0000000..9609874 --- /dev/null +++ b/emul_inst.h @@ -0,0 +1,6 @@ +#ifndef EMUL_INST__ +#define EMUL_INST__ + + + +#endif diff --git a/emul_inst_decipher.c b/emul_inst_decipher.c new file mode 100644 index 0000000..5b238d6 --- /dev/null +++ b/emul_inst_decipher.c @@ -0,0 +1,63 @@ +#include "emul_inst_decipher.h" +#include + +/* +typedef struct { + int opecode; + int string; +} emul_isa_t; +*/ + +emul_isa_t isa_dict[] { + { ADD, "add" }, + { ADDI, "addi" }, + { SUB, "sub" }, + + { SLT, "slt" }, + { SLTI, "slti" }, + { SEQ, "seq" }, + { SGE, "sge" }, + { SGT, "sgt" }, + { SLE, "sle"}, + { SNE, "sne" }, + + { B, "b"}, + { BEQ, "beq" }, + { BNE, "bne" }, + { J, "j" }, + + { LW, "lw" }, + + { SW, "sw" }, + + { MOVE, "move" } +}; + +FILE *fp; + +void emul_inst_dec_init() { +} + +void emul_inst_dec_load(char *filename) { + if ((fp = open(filename_cache, "r")) == NULL) { + fprintf(stderr, "%s is can not open", filename); + } +} +void emul_inst_dec_close() { + fclose(fp); +} + +// Example: +// ASM: add St0, Ss0, Ss1 +// RETURN: add +int emul_inst_dec_get_opecode() { + +} + +// Example: +// ASM: add St0, Ss0, Ss1 +// RETURN: St0 +// RETURN: Ss0 +// RETURN: Ss1 +int emul_inst_dec_get_operand() { +} diff --git a/emul_inst_decipher.h b/emul_inst_decipher.h new file mode 100644 index 0000000..d34621d --- /dev/null +++ b/emul_inst_decipher.h @@ -0,0 +1,30 @@ +#ifndef EMUL_INST_DECIPHER__ +#ifndef EMUL_INST_DECIPHER__ + +#include "emul_inst_isa.h" +#include "emul_io_file" + +typedef struct { + int opecode; + int string; +} emul_isa_t; + +void emul_inst_dec_init(); + +void emul_inst_dec_load(char *filename); + +void emul_inst_dec_close(); + +// Example: +// ASM: add St0, Ss0, Ss1 +// RETURN: add +int emul_inst_dec_get_opecode(); + +// Example: +// ASM: add St0, Ss0, Ss1 +// RETURN: St0 +// RETURN: Ss0 +// RETURN: Ss1 +int emul_inst_dec_get_operand(); + +#endif diff --git a/emul_inst_isa.h b/emul_inst_isa.h new file mode 100644 index 0000000..3bd115b --- /dev/null +++ b/emul_inst_isa.h @@ -0,0 +1,102 @@ +#ifndef EMUL_INST_ISA__ +#define EMUL_INST_ISA__ + +enum EMUL_ISA { + ADD, + ADDI, + AND, + ANDI, + CLO, + CLZ, + DIV, + MULT, + MUL, + MULO, + MADD, + MSUB, + NEG, + NOR, + NOT, + OR, + ORI, + REM, + SLL, + SLLV, + SRA, + SRAV, + SRL, + SRLV, + ROL, + ROR, + SUB, + XOR, + XORI, + + LUI, + LI, + + SLT, + SLTI, + SEQ, + SGE, + SGT, + SLE, + SNE, + + B, + BEQ, + BGEZ, + BGEZAL, + BGTZ, + BLEZ, + BLTZAL, + BLTZ, + BNE, + BEQZ, + BGE, + BGT, + BLE, + BLT, + BNEZ, + + J, + JAL, + JALR, + JR, + + LA, + LB, + LH, + LW, + LWL, + LWR, + LD, + ULH, + ULW, + LL, + + SB, + SH, + SW, + SWL, + SWR, + SD, + USH, + USW, + SC, + + MOVE, + MFHI, + MFLO, + MTHI, + MTLO, + MOVN, + MOVZ, + + SYSCALL, + BREAK, + NOP +} + +#endif + diff --git a/emul_io.h b/emul_io.h new file mode 100644 index 0000000..38f291b --- /dev/null +++ b/emul_io.h @@ -0,0 +1,7 @@ +#ifndef EMUL_IO__ +#define EMUL_IO__ + +#include "emul_io_std.h" +#include "emul_io_file.h" + +#endif diff --git a/emul_io_file.c b/emul_io_file.c new file mode 100644 index 0000000..d13214b --- /dev/null +++ b/emul_io_file.c @@ -0,0 +1,21 @@ +#include "emul_io_file.h" + +FILE *fp; + +void emul_out_file(char c) { + fputc(c, fp); +} + +char emul_cin_file() { + return fgetc(fp); +} + +void emul_open_file(char *filename, char *mode) { + if ((fp = fopen(filename, mode)) == NULL) { + fprintf(stderr, "File open failed: %s\n", filename); + } +} + +void emul_close_file() { + fclose(fp); +} diff --git a/emul_io_file.h b/emul_io_file.h new file mode 100644 index 0000000..3f0fe2e --- /dev/null +++ b/emul_io_file.h @@ -0,0 +1,15 @@ +#ifndef EMUL_IO_FILE__ +#define EMUL_IO_FILE__ + +#include + +void emul_out_file(char); + +char emul_cin_file(); + +void emul_open_file(char*, char*); + +/* this must be closed when closed application */ +void emul_close_file(); + +#endif diff --git a/emul_io_file.o b/emul_io_file.o new file mode 100644 index 0000000..ea7568d --- /dev/null +++ b/emul_io_file.o Binary files differ diff --git a/emul_io_std.c b/emul_io_std.c new file mode 100644 index 0000000..83914c1 --- /dev/null +++ b/emul_io_std.c @@ -0,0 +1,9 @@ +#include "emul_io_std.h" + +void emul_out_std(char c) { + putchar(c); +} + +char emul_cin_std() { + return getchar(); +} diff --git a/emul_io_std.h b/emul_io_std.h new file mode 100644 index 0000000..fff1897 --- /dev/null +++ b/emul_io_std.h @@ -0,0 +1,10 @@ +#ifndef EMUL_IO_STD__ +#define EMUL_IO_STD__ + +#include + +void emul_out_std(char c); + +char emul_cin_std(); + +#endif diff --git a/emul_io_std.o b/emul_io_std.o new file mode 100644 index 0000000..8eac8f8 --- /dev/null +++ b/emul_io_std.o Binary files differ diff --git a/emul_mem.c b/emul_mem.c new file mode 100644 index 0000000..fb1d4c2 --- /dev/null +++ b/emul_mem.c @@ -0,0 +1 @@ +#include "emul_mem.h" diff --git a/emul_mem.h b/emul_mem.h new file mode 100644 index 0000000..8c2a1cf --- /dev/null +++ b/emul_mem.h @@ -0,0 +1,8 @@ +#ifndef EMUL_MEM__ +#define EMUL_MEM__ + +#define EMUL_MEMSIZE 1024 + +char mem[EMUL_MEMSIZE]; + +#endif diff --git a/emul_mem.o b/emul_mem.o new file mode 100644 index 0000000..587d549 --- /dev/null +++ b/emul_mem.o Binary files differ diff --git a/emul_reg.c b/emul_reg.c new file mode 100644 index 0000000..79d4ca9 --- /dev/null +++ b/emul_reg.c @@ -0,0 +1,5 @@ +#include "emul_reg.h" + +void emul_reg_init() { + reg[Szero] = 0; +} diff --git a/emul_reg.h b/emul_reg.h new file mode 100644 index 0000000..5967c93 --- /dev/null +++ b/emul_reg.h @@ -0,0 +1,52 @@ +#ifndef EMUL_REG__ +#define EMUL_REG__ + +#define Szero 0 // Zero register + +#define Sat 1 // using asem + +#define Sv0 2 // return +#define Sv1 3 + +#define Sa0 4 // argment +#define Sa1 5 +#define Sa2 6 +#define Sa3 7 + +#define St0 8 // temp +#define St1 9 +#define St2 10 +#define St3 11 +#define St4 12 +#define St5 13 +#define St6 14 +#define St7 15 + +#define Ss0 16 // var +#define Ss1 17 +#define Ss2 18 +#define Ss3 19 +#define Ss4 20 +#define Ss5 21 +#define Ss6 22 +#define Ss7 23 + +#define Sk0 26 // kernel +#define Sk1 27 + +#define Sgp 28 // grobal + +#define Ssp 29 // stack + +#define Sfp 30 // frame + +#define Sra 31 // return address + + +int reg[32]; + +/* initialize register + * this must be called */ +void emul_reg_init(); + +#endif diff --git a/emul_reg.o b/emul_reg.o new file mode 100644 index 0000000..afc48ff --- /dev/null +++ b/emul_reg.o Binary files differ diff --git a/emulcomp b/emulcomp new file mode 100755 index 0000000..d6256a6 --- /dev/null +++ b/emulcomp Binary files differ diff --git "a/resorce/2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" "b/resorce/2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" new file mode 100644 index 0000000..04b4dd5 --- /dev/null +++ "b/resorce/2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" @@ -0,0 +1,6 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=2015年度 システムプログラミングへのリンク +Type=Link +URL=http://www.swlab.cs.okayama-u.ac.jp/~nom/lect/p3/index.html#orgheadline4 +Icon=text-html diff --git "a/resorce/MIPS\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243 - Wikipedia.desktop" "b/resorce/MIPS\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243 - Wikipedia.desktop" new file mode 100644 index 0000000..1334599 --- /dev/null +++ "b/resorce/MIPS\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243 - Wikipedia.desktop" @@ -0,0 +1,6 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=MIPSアーキテクチャ - Wikipediaへのリンク +Type=Link +URL=https://ja.wikipedia.org/wiki/MIPS%E3%82%A2%E3%83%BC%E3%82%AD%E3%83%86%E3%82%AF%E3%83%81%E3%83%A3#MIPS_I_.E3.81.AE.E5.91.BD.E4.BB.A4.E5.BD.A2.E5.BC.8F +Icon=text-html diff --git "a/resorce/\346\274\224\347\277\222\343\201\247\344\275\277\347\224\250\343\201\231\343\202\213\344\270\273\343\201\252 MIPS \345\221\275\344\273\244 - 2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" "b/resorce/\346\274\224\347\277\222\343\201\247\344\275\277\347\224\250\343\201\231\343\202\213\344\270\273\343\201\252 MIPS \345\221\275\344\273\244 - 2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" new file mode 100644 index 0000000..b4b564f --- /dev/null +++ "b/resorce/\346\274\224\347\277\222\343\201\247\344\275\277\347\224\250\343\201\231\343\202\213\344\270\273\343\201\252 MIPS \345\221\275\344\273\244 - 2015\345\271\264\345\272\246 \343\202\267\343\202\271\343\203\206\343\203\240\343\203\227\343\203\255\343\202\260\343\203\251\343\203\237\343\203\263\343\202\260.desktop" @@ -0,0 +1,6 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=演習で使用する主な MIPS 命令 - 2015年度 システムプログラミングへのリンク +Type=Link +URL=http://www.swlab.cs.okayama-u.ac.jp/~nom/lect/p3/concise-mips-instruction-set.html +Icon=text-html