[138] | 1 | open BitVectors;; |
---|
| 2 | open Physical;; |
---|
| 3 | |
---|
[100] | 4 | exception CodeTooLarge |
---|
[99] | 5 | |
---|
[138] | 6 | type time = int;; |
---|
[168] | 7 | type line = [ `P1 of byte |
---|
| 8 | | `P3 of byte |
---|
[209] | 9 | | `SerialBuff of [ `Eight of byte |
---|
| 10 | | `Nine of BitVectors.bit * byte |
---|
| 11 | ] |
---|
| 12 | ];; |
---|
[193] | 13 | |
---|
| 14 | val string_of_line: line -> string;; |
---|
[209] | 15 | |
---|
| 16 | type epsilon = int;; |
---|
| 17 | |
---|
[166] | 18 | (* In: reception time, line of input, new continuation, |
---|
| 19 | Out: transmission time, output line, expected duration until reply, |
---|
| 20 | new continuation. |
---|
| 21 | *) |
---|
[138] | 22 | type continuation = |
---|
[209] | 23 | [`In of time * line * epsilon * continuation] option * |
---|
| 24 | [`Out of (time -> line -> time * continuation) ];; |
---|
[99] | 25 | |
---|
[209] | 26 | type status = |
---|
| 27 | { |
---|
| 28 | (* Memory *) |
---|
| 29 | code_memory: WordMap.map; (* can be reduced *) |
---|
| 30 | low_internal_ram: Byte7Map.map; |
---|
| 31 | high_internal_ram: Byte7Map.map; |
---|
| 32 | external_ram: WordMap.map; |
---|
[99] | 33 | |
---|
[209] | 34 | (* Program counter *) |
---|
| 35 | pc: word; |
---|
[138] | 36 | |
---|
[209] | 37 | (* SFRs *) |
---|
| 38 | sp: byte; |
---|
| 39 | dpl: byte; |
---|
| 40 | dph: byte; |
---|
| 41 | pcon: byte; |
---|
| 42 | tcon: byte; |
---|
| 43 | tmod: byte; |
---|
| 44 | tl0: byte; |
---|
| 45 | tl1: byte; |
---|
| 46 | th0: byte; |
---|
| 47 | th1: byte; |
---|
| 48 | p1: byte; |
---|
| 49 | scon: byte; |
---|
| 50 | sbuf: byte; |
---|
| 51 | ie: byte; |
---|
| 52 | p3: byte; |
---|
| 53 | ip: byte; |
---|
| 54 | psw: byte; |
---|
| 55 | acc: byte; |
---|
| 56 | b: byte; |
---|
| 57 | t2con: byte; (* 8052 only *) |
---|
| 58 | rcap2l: byte; (* 8052 only *) |
---|
| 59 | rcap2h: byte; (* 8052 only *) |
---|
| 60 | tl2: byte; (* 8052 only *) |
---|
| 61 | th2: byte; (* 8052 only *) |
---|
[138] | 62 | |
---|
[209] | 63 | (* Latches for the output lines *) |
---|
| 64 | p1_latch: byte; |
---|
| 65 | p3_latch: byte; |
---|
[202] | 66 | |
---|
[209] | 67 | (* Fields for tracking the state of the processor. *) |
---|
| 68 | |
---|
| 69 | (* IO specific *) |
---|
| 70 | previous_p1_val: bool; |
---|
| 71 | previous_p3_val: bool; |
---|
[138] | 72 | |
---|
[209] | 73 | serial_epsilon_out: epsilon option; |
---|
| 74 | serial_epsilon_in: epsilon option; |
---|
| 75 | |
---|
[212] | 76 | io_epsilon: epsilon; |
---|
| 77 | |
---|
[209] | 78 | serial_v_in: [`Eight of byte | `Nine of (BitVectors.bit * byte) ] option; |
---|
| 79 | serial_v_out: [`Eight of byte | `Nine of (BitVectors.bit * byte) ] option; |
---|
| 80 | |
---|
| 81 | serial_k_out: continuation option; |
---|
| 82 | |
---|
| 83 | io: continuation; |
---|
| 84 | expected_out_time: [ `None | `Now | `At of time ]; |
---|
| 85 | |
---|
| 86 | (* Timer and clock specific *) |
---|
| 87 | clock: time; |
---|
| 88 | timer0: word; |
---|
| 89 | timer1: word; |
---|
[215] | 90 | timer2: word; (* can be missing *) |
---|
| 91 | |
---|
| 92 | esi_running: bool; |
---|
| 93 | t0i_running: bool; |
---|
| 94 | t1i_running: bool; |
---|
| 95 | e0i_running: bool; |
---|
| 96 | e1i_running: bool; |
---|
[216] | 97 | es_running: bool; |
---|
[209] | 98 | } |
---|
| 99 | |
---|
[195] | 100 | val string_of_status: status -> string |
---|
| 101 | |
---|
[138] | 102 | module IntMap: Map.S with type key = int |
---|
| 103 | |
---|
[213] | 104 | val assembly: ASM.assembly_program -> BitVectors.byte list (*ASM.instruction list * symbol_table *) * string IntMap.t |
---|
[138] | 105 | |
---|
| 106 | (* |
---|
| 107 | val link: |
---|
| 108 | (ASM.instruction list * symbol_table * cost_map) list -> BitVectors.byte list |
---|
| 109 | *) |
---|
| 110 | |
---|
[100] | 111 | val initialize: status |
---|
[99] | 112 | |
---|
[138] | 113 | val load_mem: Physical.WordMap.map -> status -> status |
---|
[100] | 114 | val load: BitVectors.byte list -> status -> status |
---|
| 115 | |
---|
[101] | 116 | exception Halt (* to be raised to stop execution *) |
---|
[100] | 117 | |
---|
| 118 | (* the callback function is used to observe the execution |
---|
| 119 | trace; it can raise Hold to stop execution. Otherwise |
---|
| 120 | the processor never halts. *) |
---|
| 121 | val execute: (status -> unit) -> status -> status |
---|
[138] | 122 | |
---|
| 123 | val fetch: Physical.WordMap.map -> word -> ASM.instruction * word * int |
---|