summaryrefslogtreecommitdiff
path: root/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'cpu')
-rw-r--r--cpu/Makefile2
-rw-r--r--cpu/cpu.ml15
-rw-r--r--cpu/prog_test1.rom36
3 files changed, 48 insertions, 5 deletions
diff --git a/cpu/Makefile b/cpu/Makefile
index 898b007..5efa691 100644
--- a/cpu/Makefile
+++ b/cpu/Makefile
@@ -8,7 +8,7 @@ SIM=../csim/csim
MON=../monitor/mon
all: _build/cpu_opt.dumb
- $(MON) $(SIM) -rom ROM0 prog_rom0.rom $<
+ $(MON) $(SIM) -rom ROM0 prog_test1.rom $<
%.sim: _build/%.dumb
$(SIM) -n 12 $<
diff --git a/cpu/cpu.ml b/cpu/cpu.ml
index b7e394b..1d1eea8 100644
--- a/cpu/cpu.ml
+++ b/cpu/cpu.ml
@@ -6,6 +6,8 @@ let ser_in_busy, save_ser_in_busy = loop 1
let dbg_ra, save_dbg_ra = loop 16
let dbg_read_data, save_dbg_read_data = loop 8
+let dbg_wa, save_dbg_wa = loop 16
+let dbg_write_data, save_dbg_write_data = loop 8
let cpu_ram ra we wa d =
(* Ram chip has word size = 8 bits and address size = 16 bits
@@ -61,6 +63,8 @@ let cpu_ram ra we wa d =
save_dbg_ra ra ^.
save_dbg_read_data read_data ^.
+ save_dbg_wa wa ^.
+ save_dbg_write_data d ^.
read_data
@@ -183,6 +187,7 @@ let rl, rh, i, ex, exf, pc =
let instr_j = exec ^& eq_c 5 i_i 0b01000 in
let next_pc = mux instr_j next_pc (nadder 16 pc (sign_extend 11 16 i_jd)) in
(* instruction : jal *)
+ let link_pc = next_pc in
let instr_jal = exec ^& eq_c 5 i_i 0b01001 in
let next_pc = mux instr_jal next_pc (nadder 16 pc (sign_extend 11 16 i_jd)) in
let instr_jalxx = instr_jal in
@@ -196,7 +201,7 @@ let rl, rh, i, ex, exf, pc =
let next_pc = mux cond_jxxr next_pc v_r in
(* prologue for jal/jalr *)
let wr = mux instr_jalxx wr (const "011") in
- let rwd = mux instr_jalxx rwd next_pc in
+ let rwd = mux instr_jalxx rwd link_pc in
(* instruction : lra *)
let instr_lra = exec ^& eq_c 5 i_i 0b01100 in
@@ -287,11 +292,13 @@ let p =
[
"read_ilow", 1, rl;
"read_ihi", 1, rh;
- "exec_instr", 1, ex;
- "exec_finished", 1, exf;
- "instruction", 16, i;
+ "ex_instr", 1, ex;
+ "ex_finish", 1, exf;
+ "i", 16, i;
"ra", 16, dbg_ra;
"read_data", 8, dbg_read_data;
+ "wa", 16, dbg_wa;
+ "write_data", 8, dbg_write_data;
"pc", 16, pc;
"r0_Z", 16, r0;
"r1_A", 16, r1;
diff --git a/cpu/prog_test1.rom b/cpu/prog_test1.rom
new file mode 100644
index 0000000..0d352b7
--- /dev/null
+++ b/cpu/prog_test1.rom
@@ -0,0 +1,36 @@
+58 8
+11111111 11111011 # liuz SP 255
+00000000 00100000 # add D Z Z
+ # init:
+00000010 01011011 # liuz B 64
+00000010 01000001 # lw B 0(B)
+00100000 10110011 # lilz E init
+00000000 10101011 # liu E init
+01000010 10101010 # jer E B Z
+00010001 00100000 # add D D B
+01111111 11101100 # incri SP -2
+00000111 00110001 # sw D 0(SP)
+00101100 10010011 # lilz A msgtick
+00000000 10001011 # liu A msgtick
+00010000 00010010 # jal ser_out_msg
+00000111 00100001 # lw D 0(SP)
+01000000 11101100 # incri SP 2
+01100111 11100010 # j init
+ # ser_out_msg:
+10000010 11011011 # liuz C 65
+01000000 11000011 # lil C 2
+ # ser_out_msg_loop:
+00000100 01001001 # lb B 0(A)
+01001100 10110011 # lilz E ser_out_msg_ret
+00000000 10101011 # liu E ser_out_msg_ret
+01000010 10101010 # jer E B Z
+00000110 01011001 # sb B 0(C)
+10000000 10001100 # incri A 1
+00101111 11100010 # j ser_out_msg_loop
+ # ser_out_msg_ret:
+00000000 01101010 # jr RA
+ # msgtick:
+00101010 10010110 # bytes 84 105
+11000110 11010110 # bytes 99 107
+10000100 00000000 # bytes 33 0
+