1 | include "common/StructuredTraces.ma". (* includes "basics/lists/listb.ma".*) |
---|
2 | |
---|
3 | include "ASM/Status.ma". (* includes "ASM/ASM.ma". *) |
---|
4 | include "ASM/Fetch.ma". |
---|
5 | |
---|
6 | definition ASM_classify00: ∀a. preinstruction a → status_class ≝ |
---|
7 | λa, pre. |
---|
8 | match pre with |
---|
9 | [ RET ⇒ cl_return |
---|
10 | | RETI ⇒ cl_return |
---|
11 | | JZ _ ⇒ cl_jump |
---|
12 | | JNZ _ ⇒ cl_jump |
---|
13 | | JC _ ⇒ cl_jump |
---|
14 | | JNC _ ⇒ cl_jump |
---|
15 | | JB _ _ ⇒ cl_jump |
---|
16 | | JNB _ _ ⇒ cl_jump |
---|
17 | | JBC _ _ ⇒ cl_jump |
---|
18 | | CJNE _ _ ⇒ cl_jump |
---|
19 | | DJNZ _ _ ⇒ cl_jump |
---|
20 | | JMP _ ⇒ cl_call |
---|
21 | | _ ⇒ cl_other |
---|
22 | ]. |
---|
23 | |
---|
24 | definition ASM_classify0: instruction → status_class ≝ |
---|
25 | λi. |
---|
26 | match i with |
---|
27 | [ RealInstruction pre ⇒ ASM_classify00 [[relative]] pre |
---|
28 | | ACALL _ ⇒ cl_call |
---|
29 | | LCALL _ ⇒ cl_call |
---|
30 | | AJMP _ ⇒ cl_other |
---|
31 | | LJMP _ ⇒ cl_other |
---|
32 | | SJMP _ ⇒ cl_other |
---|
33 | | _ ⇒ cl_other |
---|
34 | ]. |
---|
35 | |
---|
36 | definition current_instruction0 ≝ |
---|
37 | λcode_memory: BitVectorTrie Byte 16. |
---|
38 | λprogram_counter: Word. |
---|
39 | \fst (\fst (fetch … code_memory program_counter)). |
---|
40 | |
---|
41 | definition current_instruction ≝ |
---|
42 | λcode_memory. |
---|
43 | λs: Status code_memory. |
---|
44 | current_instruction0 code_memory (program_counter … s). |
---|
45 | |
---|
46 | definition current_instruction_label ≝ |
---|
47 | λcode_memory. |
---|
48 | λcost_labels: BitVectorTrie costlabel 16. |
---|
49 | λs: Status code_memory. |
---|
50 | let pc ≝ program_counter … code_memory s in |
---|
51 | lookup_opt … pc cost_labels. |
---|
52 | |
---|
53 | definition next_instruction_properly_relates_program_counters ≝ |
---|
54 | λcode_memory. |
---|
55 | λbefore: Status code_memory. |
---|
56 | λafter : Status code_memory. |
---|
57 | let program_counter_before ≝ program_counter ? code_memory before in |
---|
58 | let 〈instruction, program_counter_after, ticks〉 ≝ fetch code_memory program_counter_before in |
---|
59 | program_counter ? code_memory after = program_counter_after. |
---|
60 | |
---|
61 | definition word_deqset: DeqSet ≝ |
---|
62 | mk_DeqSet Word (eq_bv 16) ?. |
---|
63 | @refl_iff_eq_bv_true |
---|
64 | qed. |
---|
65 | |
---|
66 | definition OC_classify: ∀code_memory. Status code_memory → status_class ≝ |
---|
67 | λcode_memory. |
---|
68 | λs: Status code_memory. |
---|
69 | ASM_classify0 (current_instruction … s). |
---|