|
11 | 11 |
|
12 | 12 | (in-package thumb) |
13 | 13 |
|
| 14 | +(defun tCMPhir (rn rm cnd _) |
| 15 | + "cmp rn, rn" |
| 16 | + (when (condition-holds cnd) |
| 17 | + (let ((r (- rn rm))) |
| 18 | + (set-nzcv-from-registers r rn rm)))) |
| 19 | + |
| 20 | +(defun tADR (rd lbl cnd _) |
| 21 | + "adr rd, lbl" |
| 22 | + (when (condition-holds cnd) |
| 23 | + (let ((pc (* 4 (/ (t2pc) 4)))) |
| 24 | + (set$ rd (+ pc (lshift lbl 2)))))) |
| 25 | + |
14 | 26 | (defmacro tLOGs (op rd rn rm cnd) |
15 | 27 | (prog (set$ rd (op rn rm)) |
16 | 28 | (when (is-unconditional cnd) |
|
20 | 32 | (defun tEOR (rd _ rn rm cnd _) |
21 | 33 | (tLOGs logxor rd rn rm cnd)) |
22 | 34 |
|
| 35 | +(defun t2EORrs (rd rn rm simm cnd _ _) |
| 36 | + "eor.w rd, rn, rm, simm" |
| 37 | + (when (condition-holds cnd) |
| 38 | + (set$ rd (logxor rn (i-shift rm simm))))) |
| 39 | + |
23 | 40 | (defun tAND (rd _ rn rm cnd _) |
24 | 41 | (tLOGs logand rd rn rm cnd)) |
25 | 42 |
|
|
41 | 58 | (extract 23 16 rn) |
42 | 59 | (extract 31 24 rn))))) |
43 | 60 |
|
| 61 | +(defun tREV16 (rd rm cnd _) |
| 62 | + "rev16 rd rm" |
| 63 | + (when (condition-holds cnd) |
| 64 | + (set$ rd (concat |
| 65 | + (extract 23 16 rm) |
| 66 | + (extract 31 24 rm) |
| 67 | + (extract 7 0 rm) |
| 68 | + (extract 15 8 rm))))) |
| 69 | + |
44 | 70 | (defun tLSLrr (rd _ rn rm cnd _) |
45 | 71 | "lsls rd, rn, rm" |
46 | 72 | (shift-with-carry lshift rd rn rm cnd)) |
47 | 73 |
|
| 74 | +(defun t2LSLri (rd rm imm cnd _ _) |
| 75 | + "lsl.w rd, rm, #imm" |
| 76 | + (when (condition-holds cnd) |
| 77 | + (set$ rd (lshift rm imm)))) |
| 78 | + |
48 | 79 | (defun tLSRrr (rd _ rn rm cnd _) |
49 | 80 | "lsrs rd, rn, rm" |
50 | 81 | (shift-with-carry rshift rd rn rm cnd)) |
51 | 82 |
|
| 83 | +(defun t2LSRri (rd rm imm cnd _ _) |
| 84 | + "lsr.w rd, rm, #imm" |
| 85 | + (when (condition-holds cnd) |
| 86 | + (set$ rd (rshift rm imm)))) |
| 87 | + |
52 | 88 | (defun tTST (rn rm _ _) |
53 | 89 | "tst rn, rm" |
54 | 90 | (let ((rd (logand rn rm))) |
|
59 | 95 | (when (condition-holds cnd) |
60 | 96 | (set$ rd (+ rn (t2reg rm))))) |
61 | 97 |
|
| 98 | +(defun t2ADDrs (rd rn rm simm cnd _ _) |
| 99 | + "add.w rd, rn, rm, simm" |
| 100 | + (when (condition-holds cnd) |
| 101 | + (set$ rd (+ rn (i-shift rn simm))))) |
| 102 | + |
62 | 103 | (defun tSBC (rd _ rn rm cnd _) |
63 | 104 | (add-with-carry/it-block rd rn (lnot rm) CF cnd)) |
64 | 105 |
|
65 | 106 | (defun tRSB (rd _ rn cnd _) |
66 | 107 | "rsbs r3, r2, #0" |
67 | 108 | (add-with-carry/it-block rd 0 (lnot rn) 1 cnd)) |
68 | 109 |
|
| 110 | +(defun t2RSBrs (rd rn rm simm cnd _ _) |
| 111 | + "rsb rd, rn, rm, simm" |
| 112 | + (when (condition-holds cnd) |
| 113 | + (set$ rd (- (i-shift rm simm) rn)))) |
| 114 | + |
69 | 115 | (defun tMUL (rd _ rn rm cnd _) |
70 | 116 | (when (condition-holds cnd) |
71 | 117 | (set$ rd (* rn rm)) |
72 | 118 | (when (is-unconditional cnd) |
73 | 119 | (set ZF (is-zero rd)) |
74 | 120 | (set NF (msb rd))))) |
75 | 121 |
|
| 122 | +(defun t2STR_PRE (_ rt rn off cnd _) |
| 123 | + "str rt [rn, #off]!" |
| 124 | + (when (condition-holds cnd) |
| 125 | + (set$ rn (+ rn off)) |
| 126 | + (store-word rn rt))) |
| 127 | + |
76 | 128 | (defun t2STRDi8 (rt1 rt2 rn imm pre _) |
77 | 129 | "strd rt1, rt2, [rn, off]" |
78 | 130 | (when (condition-holds pre) |
79 | 131 | (store-word (+ rn imm) rt1) |
80 | 132 | (store-word (+ rn imm (sizeof word-width)) rt2))) |
81 | 133 |
|
| 134 | +(defun t2STRs (rt rn rm imm cnd _) |
| 135 | + "str.w rt [rn, rm, lsl imm]" |
| 136 | + (when (condition-holds cnd) |
| 137 | + (store-word (+ rn (lshift rm imm)) rt))) |
| 138 | + |
82 | 139 | (defun t2ADDri12 (rd rn imm pre _) |
83 | 140 | "addw rd, rn, imm; A7-189, T4 " |
84 | 141 | (when (condition-holds pre) |
|
115 | 172 | (when (condition-holds pre) |
116 | 173 | (t2set rt (load-word (+ rn (lshift rm imm)))))) |
117 | 174 |
|
| 175 | +(defun t2LDRi8 (rt rn imm cnd _) |
| 176 | + "ldr rt, [rn, #-imm]" |
| 177 | + (when (condition-holds cnd) |
| 178 | + (set$ rt (load-word (+ rn imm))))) |
| 179 | + |
| 180 | +(defun t2LDRDi8 (rt rt2 rn imm cnd _) |
| 181 | + "ldrd rt, rt2, [rn, #imm]" |
| 182 | + (when (condition-holds cnd) |
| 183 | + (set$ rt (load-word (+ rn imm))) |
| 184 | + (set$ rt2 (load-word (+ rn imm 4))))) |
| 185 | + |
| 186 | +(defun t2LDR_POST (rt _ rn off cnd _) |
| 187 | + "ldr rt, [rn], #imm" |
| 188 | + (when (condition-holds cnd) |
| 189 | + (let ((tmp rn)) |
| 190 | + (set$ rn (+ rn off)) |
| 191 | + (t2set rt (load-word tmp))))) |
| 192 | + |
| 193 | +(defun t2LDRB_PRE (rt _ rn off cnd _) |
| 194 | + "ldrb rt, [rn, #off]!" |
| 195 | + (when (condition-holds cnd) |
| 196 | + (set$ rn (+ rn off)) |
| 197 | + (set$ rt (cast-unsigned 32 (load-bits 8 rn))))) |
| 198 | + |
118 | 199 | (defun t2LDRSBi12 (rt rn imm pre _) |
119 | 200 | "ldrsb.w rt, [rn, imm]" |
120 | 201 | (when (condition-holds pre) |
|
0 commit comments