summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--asm/Makefile10
-rw-r--r--asm/_tags2
-rw-r--r--asm/asm.ml2
-rw-r--r--asm/asmlex.mll7
-rw-r--r--asm/asmpars.mly26
-rw-r--r--asm/test.asm26
-rw-r--r--cpu/Makefile2
-rw-r--r--cpu/cpu.ml15
-rw-r--r--cpu/prog_test1.rom42
-rw-r--r--monitor/disp.c21
-rw-r--r--monitor/mon.c1
-rw-r--r--monitor/mon.h1
-rw-r--r--sched/Makefile2
-rw-r--r--sched/_tags3
15 files changed, 132 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index eda51f2..e0ae8b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
csim/csim
sched/sched
monitor/mon
+asm/asm
*.o
*.ps
*/*.net
diff --git a/asm/Makefile b/asm/Makefile
new file mode 100644
index 0000000..8ac2004
--- /dev/null
+++ b/asm/Makefile
@@ -0,0 +1,10 @@
+
+all: asm
+
+asm: assembler.ml asm.ml asmlex.mll asmpars.mly
+ ocamlbuild assembler.native
+ mv assembler.native asm
+
+clean:
+ rm asm
+ rm -r _build
diff --git a/asm/_tags b/asm/_tags
index b2f3704..3ed8b5a 100644
--- a/asm/_tags
+++ b/asm/_tags
@@ -1,2 +1,4 @@
true: use_menhir
+<*.ml>: debug
+<*.byte>: use_unix, debug
diff --git a/asm/asm.ml b/asm/asm.ml
index 47f5f7b..71b73a8 100644
--- a/asm/asm.ml
+++ b/asm/asm.ml
@@ -1,3 +1,5 @@
+exception Asm_error of string
+
type reg = int
type imm =
diff --git a/asm/asmlex.mll b/asm/asmlex.mll
index 873e32d..7be493e 100644
--- a/asm/asmlex.mll
+++ b/asm/asmlex.mll
@@ -54,8 +54,8 @@
let valh d =
let c = Char.code d in
if c >= Char.code '0' && c <= Char.code '9' then c - (Char.code '0')
- else if c >= Char.code 'a' && c <= Char.code 'f' then c - (Char.code 'a')
- else c - (Char.code 'A')
+ else if c >= Char.code 'a' && c <= Char.code 'f' then c - (Char.code 'a') + 10
+ else c - (Char.code 'A') + 10
let read_16 n =
let res = ref 0 in
@@ -96,7 +96,7 @@ rule token = parse
{ INT (read_16 n) }
| (digit)+ as n { INT (int_of_string n) }
| "0b" (['0' '1']+ as n) { INT (read_2 n) }
- | ['A'-'Z']+ as name { REG (List.assoc name regs) }
+ | ['A'-'Z']+ as name { try REG (List.assoc name regs) with Not_found -> raise (Asm_error ("no reg " ^ name))}
| '$' (['0'-'7'] as n) { REG (Char.code n - (Char.code '0')) }
| ".text" { TEXT }
| ".data" { DATA }
@@ -127,3 +127,4 @@ and comment = parse
| eof { EOF }
| '\n' { Lexing.new_line lexbuf; token lexbuf }
| _ { comment lexbuf }
+
diff --git a/asm/asmpars.mly b/asm/asmpars.mly
index 8f47c91..4850c55 100644
--- a/asm/asmpars.mly
+++ b/asm/asmpars.mly
@@ -51,23 +51,23 @@ program:
lbls = !lbls2 } }
data:
- DATA d=datas* { d }
-
+ DATA d=datas* { d }
+
datas:
| labeld datas { () }
| BYTE n=INT { add ram n }
| WORD n=INT { add ram (2*n) }
labeli:
- id=ID COLON { lbls2 := Imap.add id (!pc,true) !lbls2 }
+ id=ID COLON { lbls2 := Imap.add id (!pc,true) !lbls2 }
labeld:
- id=ID COLON { lbls2 := Imap.add id (!ram,false) !lbls2 }
+ id=ID COLON { lbls2 := Imap.add id (!ram,false) !lbls2 }
instr:
- | labeli i=instr { i }
- | i=_instr { i }
-
+ | labeli i=instr { i }
+ | i=_instr { i }
+
_instr:
| o=ROP r1=REG r2=REG r3=REG { add pc 2; [R (o,r1,r2,r3)] }
| o=RIOP r1=REG r2=REG imm=imm
@@ -122,9 +122,9 @@ _instr:
| MOVE r1=REG r2=REG { add pc 2; [R (Add,r1,r2,0)] }
| NOT r1=REG r2=REG { add pc 2; [R (Nor,r1,r2,0)] }
| JZ r=REG l=ID { let l = li false 5 (Lab l) in
- add pc 2; l @ [R (Jer,r,5,0)] }
+ add pc 2; l @ [R (Jer,5,r,0)] }
| JNZ r=REG l=ID { let l = li false 5 (Lab l) in
- add pc 2; l @ [R (Jner,r,5,0)] }
+ add pc 2; l @ [R (Jner,5,r,0)] }
| POP r=REG { add pc 4; [Lw (r,7,0); Incri (7,2)] }
| PUSH r=REG { add pc 4; [Incri (7,-2); Sw (r,7,0)] }
| BYTE bs=int* { List.map (fun b -> add pc 1; Byte b) bs }
@@ -133,9 +133,9 @@ _instr:
| ASCII s=STR { List.map (fun c -> add pc 1; Byte (Char.code c)) s }
imm:
- | id=ID { Lab id }
- | n=int { Imm n }
+ | id=ID { Lab id }
+ | n=int { Imm n }
int:
- | n=INT { n }
- | MINUS n=INT { - n }
+ | n=INT { n }
+ | MINUS n=INT { - n }
diff --git a/asm/test.asm b/asm/test.asm
new file mode 100644
index 0000000..4c3369f
--- /dev/null
+++ b/asm/test.asm
@@ -0,0 +1,26 @@
+.text
+init:
+ liuz B 0x40
+ lw B 0(B)
+ jz B init
+ add D D B
+ push D
+ li A msgtick
+ jal ser_out_msg
+ pop D
+ j init
+
+ser_out_msg:
+ liuz C 0x41
+ lil C 0x02
+ser_out_msg_loop:
+ lb B 0(A)
+ jz B ser_out_msg_ret
+ sb B 0(C)
+ incri A 1
+ j ser_out_msg_loop
+ser_out_msg_ret:
+ jr RA
+
+msgtick:
+ ascii "Tick!"
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..4c71fad
--- /dev/null
+++ b/cpu/prog_test1.rom
@@ -0,0 +1,42 @@
+54 8
+ # init:
+00000010 01011011 # liuz B 64
+00000010 01000001 # lw B 0(B)
+00000000 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)
+00001100 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)
+01110100 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
+ # msgtick:
+10010110
+ # msgtick:
+11000110
+ # msgtick:
+11010110
+ # msgtick:
+10000100
+ # msgtick:
+00000000
+
diff --git a/monitor/disp.c b/monitor/disp.c
index 992c712..84dd941 100644
--- a/monitor/disp.c
+++ b/monitor/disp.c
@@ -86,19 +86,18 @@ void disp_display(t_mon *mon) {
wprintw(wpstatus, "\nInputs:\n");
for (i = 0; i < mon->n_inputs; i++) {
- wprintw(wpstatus, " %d. %s%s\t%s (%d)\t%s\n",
+ wprintw(wpstatus, "%s %d. %s (%d)\t%s\n",
+ (i == mon->ticker_input ? "T" : (i == mon->ser_in_in ? ">" : " ")),
i,
- (i == mon->ticker_input ? "T" : ""),
- (i == mon->ser_in_in ? ">" : ""),
mon->inputs[i].name, mon->inputs[i].size, mon->inputs[i].value);
}
if (mon->n_inputs == 0) wprintw(wpstatus, "\t(none)\n");
wprintw(wpstatus, "\nOutputs:\n");
for (i = 0; i < mon->n_outputs; i++) {
- wprintw(wpstatus, " %d. %s%s\t%s\t%s\t%ld\n", i,
- (i == mon->ser_out ? "<" : ""),
- (i == mon->ser_in_busy_out ? "!" : ""),
+ wprintw(wpstatus, "%s %d. %s\t%s %ld\n",
+ (i == mon->ser_out ? "<" : (i == mon->ser_in_busy_out ? "!" : " ")),
+ i,
mon->outputs[i].name, mon->outputs[i].v_bin, mon->outputs[i].v_int);
}
if (mon->n_outputs == 0) wprintw(wpstatus, "\t(none)\n");
@@ -147,4 +146,14 @@ void disp_display(t_mon *mon) {
}
+void disp_display_ser(t_mon *mon) {
+ if (mon->ser_out_buf != 0) {
+ wprintw(wpoutput, "%c", mon->ser_out_buf);
+ wrefresh(wpoutput);
+ mon->ser_out_buf = 0;
+
+ wmove(wcmdline, 0, cmd_pos + 2);
+ wrefresh(wcmdline);
+ }
+}
diff --git a/monitor/mon.c b/monitor/mon.c
index 19055c7..baef98b 100644
--- a/monitor/mon.c
+++ b/monitor/mon.c
@@ -285,4 +285,5 @@ void mon_step(t_mon *mon) {
}
mon->step++;
+ disp_display_ser(mon);
}
diff --git a/monitor/mon.h b/monitor/mon.h
index 0040eda..32d60c4 100644
--- a/monitor/mon.h
+++ b/monitor/mon.h
@@ -61,6 +61,7 @@ typedef struct {
void disp_init();
void disp_display(t_mon *mon);
+void disp_display_ser(t_mon *mon);
void disp_finish();
void handle_kbd(t_mon *mon);
diff --git a/sched/Makefile b/sched/Makefile
index 4d36b96..35d6ddc 100644
--- a/sched/Makefile
+++ b/sched/Makefile
@@ -3,7 +3,7 @@ IN=graph.ml main.ml netlist_ast.ml netlist_dumb.ml netlist_lexer.mll netlist.ml
all: sched
sched: $(IN)
- ocamlbuild -libs unix main.native
+ ocamlbuild main.native
mv main.native sched
clean:
diff --git a/sched/_tags b/sched/_tags
index 503ce62..007e22c 100644
--- a/sched/_tags
+++ b/sched/_tags
@@ -1,3 +1,4 @@
true: use_menhir
<*.ml>: debug
-<*.byte>: use_unix, debug \ No newline at end of file
+<*.byte>: use_unix, debug
+<*.native>: use_unix