1 ; Ubicom IP2K CPU description. -*- Scheme -*-
2 ; Copyright (C) 2002, 2009, 2011 Free Software Foundation, Inc.
4 ; Contributed by Red Hat Inc;
6 ; This file is part of the GNU Binutils.
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation; either version 3 of the License, or
11 ; (at your option) any later version.
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 (define-rtl-version 0 8)
25 (include "simplify.inc")
27 ; define-arch must appear first
30 (name ip2k) ; name of cpu family
31 (comment "Ubicom IP2000 family")
32 (default-alignment aligned)
34 (machs ip2022 ip2022ext)
44 (comment "instruction is a PAGE, LOADL, LOADH or BREAKX instruction")
51 (comment "instruction is a SKIP instruction")
54 ; Instruction set parameters.
58 (comment "Ubicom IP2000 ISA")
60 (default-insn-word-bitsize 16)
61 (default-insn-bitsize 16)
62 (base-insn-bitsize 16)
65 ; Cpu family definitions.
69 ; cpu names must be distinct from the architecture name and machine names.
71 (comment "Ubicom IP2000 Family")
78 (comment "Ubicom IP2022")
84 (comment "Ubicom IP2022 extended")
92 (name ip2k) (comment "VPE 2xxx") (attrs)
95 (unit u-exec "Execution Unit" ()
100 () ; profile action (default)
105 ; FIXME: It might simplify things to separate the execute process from the
106 ; one that updates the PC.
108 ; Instruction fields.
111 ; XXX: what VPE attrs
112 ; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
113 ; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
114 ; RESERVED: bits are not used to decode insn, must be all 0
115 ; RELOC: there is a relocation associated with this field (experiment)
118 (dnf f-imm8 "imm8" () 7 8)
119 (dnf f-reg "reg" (ABS-ADDR) 8 9)
120 (dnf f-addr16cjp "addr16cjp" (ABS-ADDR) 12 13)
121 (dnf f-dir "dir" () 9 1)
122 (dnf f-bitno "bit number" () 11 3)
123 (dnf f-op3 "op3" () 15 3)
124 (dnf f-op4 "op4" () 15 4)
125 (dnf f-op4mid "op4mid" () 11 4)
126 (dnf f-op6 "op6" () 15 6)
127 (dnf f-op8 "op8" () 15 8)
128 (dnf f-op6-10low "op6-10low" () 9 10)
129 (dnf f-op6-7low "op6-7low" () 9 7)
130 (dnf f-reti3 "reti3" () 2 3)
131 (dnf f-skipb "sb/snb" (ABS-ADDR) 12 1)
132 (dnf f-page3 "page3" () 2 3)
133 ;(define-ifield (name f-page3) (comment "page3") (attrs) (start 2) (length 3)
134 ; (encode (value pc) (srl WI value 13))
135 ; (decode (value pc) (sll WI value 13))
137 ; To fix the page/call asymmetry
138 ;(define-ifield (name f-page3) (comment "page3") (attrs) (start 2) (length 3)
139 ; (encode (value pc) (srl WI value 13))
140 ; (decode (value pc) (sll WI value 13))
147 ; insn-op6: bits 15-10
148 (define-normal-insn-enum insn-op6 "op6 enums" () OP6_ f-op6
149 (OTHER1 OTHER2 SUB DEC OR AND XOR ADD
150 TEST NOT INC DECSZ RR RL SWAP INCSZ
151 CSE POP SUBC DECSNZ MULU MULS INCSNZ ADDC
161 (define-normal-insn-enum insn-dir "dir enums" () DIR_ f-dir
162 ; This bit specifies the polarity of many two-operand instructions:
163 ; TO_W writes result to W regiser (eg. ADDC W,$fr)
164 ; NOTTO_W writes result in general register (eg. ADDC $fr,W)
169 ; insn-op4: bits 15-12
170 (define-normal-insn-enum insn-op4 "op4 enums" () OP4_ f-op4
171 (- - - - - - - LITERAL
172 CLRB SETB SNB SB - - - -
176 ; insn-op4mid: bits 11-8
177 ; used for f-op4=LITERAL
178 (define-normal-insn-enum insn-op4mid "op4mid enums" () OP4MID_ f-op4mid
179 (LOADH_L LOADL_L MULU_L MULS_L PUSH_L - CSNE_L CSE_L
180 RETW_L CMP_L SUB_L ADD_L MOV_L OR_L AND_L XOR_L)
183 ; insn-op3: bits 15-13
184 (define-normal-insn-enum insn-op3 "op3 enums" () OP3_ f-op3
185 (- - - - - - CALL JMP)
192 ; Bank-relative general purpose registers
194 ; (define-pmacro (build-reg-name n) (.splice (.str "$" n) n))
197 (name register-names)
198 (enum-prefix H-REGISTERS-)
200 ; These are the "Special Purpose Registers" that are not reserved
201 ("ADDRSEL" #x2) ("ADDRX" #x3)
202 ("IPH" #x4) ("IPL" #x5) ("SPH" #x6) ("SPL" #x7)
203 ("PCH" #x8) ("PCL" #x9) ("WREG" #xA) ("STATUS" #xB)
204 ("DPH" #xC) ("DPL" #xD) ("SPDREG" #xE) ("MULH" #xF)
205 ("ADDRH" #x10) ("ADDRL" #x11) ("DATAH" #x12) ("DATAL" #x13)
206 ("INTVECH" #x14) ("INTVECL" #x15) ("INTSPD" #x16) ("INTF" #x17)
207 ("INTE" #x18) ("INTED" #x19) ("FCFG" #x1A) ("TCTRL" #x1B)
208 ("XCFG" #x1C) ("EMCFG" #x1D) ("IPCH" #x1E) ("IPCL" #x1F)
209 ("RAIN" #x20) ("RAOUT" #x21) ("RADIR" #x22) ("LFSRH" #x23)
210 ("RBIN" #x24) ("RBOUT" #x25) ("RBDIR" #x26) ("LFSRL" #x27)
211 ("RCIN" #x28) ("RCOUT" #x29) ("RCDIR" #x2A) ("LFSRA" #x2B)
212 ("RDIN" #x2C) ("RDOUT" #x2D) ("RDDIR" #x2E)
213 ("REIN" #x30) ("REOUT" #x31) ("REDIR" #x32)
214 ("RFIN" #x34) ("RFOUT" #x35) ("RFDIR" #x36)
215 ("RGOUT" #x39) ("RGDIR" #x3A)
216 ("RTTMR" #x40) ("RTCFG" #x41) ("T0TMR" #x42) ("T0CFG" #x43)
217 ("T1CNTH" #x44) ("T1CNTL" #x45) ("T1CAP1H" #x46) ("T1CAP1L" #x47)
218 ("T1CAP2H" #x48) ("T1CMP2H" #x48) ("T1CAP2L" #x49) ("T1CMP2L" #x49) ; note aliases
219 ("T1CMP1H" #x4A) ("T1CMP1L" #x4B)
220 ("T1CFG1H" #x4C) ("T1CFG1L" #x4D) ("T1CFG2H" #x4E) ("T1CFG2L" #x4F)
221 ("ADCH" #x50) ("ADCL" #x51) ("ADCCFG" #x52) ("ADCTMR" #x53)
222 ("T2CNTH" #x54) ("T2CNTL" #x55) ("T2CAP1H" #x56) ("T2CAP1L" #x57)
223 ("T2CAP2H" #x58) ("T2CMP2H" #x58) ("T2CAP2L" #x59) ("T2CMP2L" #x59) ; note aliases
224 ("T2CMP1H" #x5A) ("T2CMP1L" #x5B)
225 ("T2CFG1H" #x5C) ("T2CFG1L" #x5D) ("T2CFG2H" #x5E) ("T2CFG2L" #x5F)
226 ("S1TMRH" #x60) ("S1TMRL" #x61) ("S1TBUFH" #x62) ("S1TBUFL" #x63)
227 ("S1TCFG" #x64) ("S1RCNT" #x65) ("S1RBUFH" #x66) ("S1RBUFL" #x67)
228 ("S1RCFG" #x68) ("S1RSYNC" #x69) ("S1INTF" #x6A) ("S1INTE" #x6B)
229 ("S1MODE" #x6C) ("S1SMASK" #x6D) ("PSPCFG" #x6E) ("CMPCFG" #x6F)
230 ("S2TMRH" #x70) ("S2TMRL" #x71) ("S2TBUFH" #x72) ("S2TBUFL" #x73)
231 ("S2TCFG" #x74) ("S2RCNT" #x75) ("S2RBUFH" #x76) ("S2RBUFL" #x77)
232 ("S2RCFG" #x78) ("S2RSYNC" #x79) ("S2INTF" #x7A) ("S2INTE" #x7B)
233 ("S2MODE" #x7C) ("S2SMASK" #x7D) ("CALLH" #x7E) ("CALLL" #x7F))
238 (comment "special-purpose registers")
239 (type register QI (128))
240 (get (index) (c-call QI "get_spr" index ))
241 (set (index newval) (c-call VOID "set_spr" index newval ))
246 ;; (name h-gpr-global)
247 ;; (comment "gpr registers - global")
248 ;; (type register QI (128))
251 ; The general register
255 (comment "all addressable registers")
257 (type register QI (512))
258 (get (index) (c-call QI "get_h_registers" index ))
259 (set (index newval) (c-call VOID "set_h_registers" index newval ))
262 ; The hardware stack.
263 ; Use {push,pop}_pc_stack c-calls to operate on this hardware element.
267 (comment "hardware stack")
268 (type register UHI (16))
271 (dsh h-pabits "page bits" () (register QI))
272 (dsh h-zbit "zero bit" () (register BI))
273 (dsh h-cbit "carry bit" () (register BI))
274 (dsh h-dcbit "digit-carry bit" () (register BI))
275 (dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
280 (define-operand (name addr16cjp) (comment "13-bit address") (attrs)
281 (type h-uint) (index f-addr16cjp) (handlers (parse "addr16_cjp") (print "dollarhex_cj"))) ; overload lit8 printer
282 (define-operand (name fr) (comment "register") (attrs)
283 (type h-registers) (index f-reg) (handlers (parse "fr") (print "fr")))
284 (define-operand (name lit8) (comment "8-bit signed literal") (attrs)
285 (type h-sint) (index f-imm8) (handlers (parse "lit8") (print "dollarhex8")))
286 (define-operand (name bitno) (comment "bit number") (attrs)
287 (type h-uint) (index f-bitno) (handlers (parse "bit3")(print "decimal")))
288 (define-operand (name addr16p) (comment "page number") (attrs)
289 (type h-uint) (index f-page3) (handlers (parse "addr16_cjp") (print "dollarhex_p")))
290 (define-operand (name addr16h) (comment "high 8 bits of address") (attrs)
291 (type h-uint) (index f-imm8) (handlers (parse "addr16") (print "dollarhex_addr16h")))
292 (define-operand (name addr16l) (comment "low 8 bits of address") (attrs)
293 (type h-uint) (index f-imm8) (handlers (parse "addr16") (print "dollarhex_addr16l")))
294 (define-operand (name reti3) (comment "reti flags") (attrs)
295 (type h-uint) (index f-reti3) (handlers (print "dollarhex")))
296 (dnop pabits "page bits" () h-pabits f-nil)
297 (dnop zbit "zero bit" () h-zbit f-nil)
298 (dnop cbit "carry bit" () h-cbit f-nil)
299 (dnop dcbit "digit carry bit" () h-dcbit f-nil)
300 ;;(dnop bank "bank register" () h-bank-no f-nil)
302 (define-pmacro w (reg h-spr #x0A))
303 (define-pmacro mulh (reg h-spr #x0F))
304 (define-pmacro dph (reg h-spr #x0C))
305 (define-pmacro dpl (reg h-spr #x0D))
306 (define-pmacro sph (reg h-spr #x06))
307 (define-pmacro spl (reg h-spr #x07))
308 (define-pmacro iph (reg h-spr #x04))
309 (define-pmacro ipl (reg h-spr #x05))
310 (define-pmacro addrh (reg h-spr #x10))
311 (define-pmacro addrl (reg h-spr #x11))
315 ; Pseudo-RTL for DC flag calculations
316 ; "DC" = "digit carry", ie carry between nibbles
317 (define-pmacro (add-dcflag a b c)
318 (add-cflag (sll QI a 4) (sll QI b 4) c)
321 (define-pmacro (sub-dcflag a b c)
322 (sub-cflag (sll QI a 4) (sll QI b 4) c)
325 ; Check to see if an fr is one of IPL, SPL, DPL, ADDRL, PCL.
326 (define-pmacro (LregCheck isLreg fr9bit)
328 (set isLreg #x0) ;; Assume it's not an Lreg
329 (if (or (or (eq fr9bit #x5) (eq fr9bit #x7))
331 (or (eq fr9bit #xd) (eq fr9bit #x11))))
338 ; Instructions, in order of the "Instruction Set Map" table on
339 ; pp 19-20 of IP2022 spec V1.09
344 (+ OP3_JMP addr16cjp)
345 (set pc (or (sll pabits 13) addr16cjp))
349 ; note that in call, we push pc instead of pc + 1 because the ip2k increments
350 ; the pc prior to execution of the instruction
354 (+ OP3_CALL addr16cjp)
356 (c-call "push_pc_stack" pc)
357 (set pc (or (sll pabits 13) addr16cjp)))
361 (dni sb "Skip if bit set"
365 (if (and fr (sll 1 bitno))
370 (dni snb "Skip if bit clear"
374 (if (not (and fr (sll 1 bitno)))
382 (+ OP4_SETB bitno fr)
383 (set fr (or fr (sll 1 bitno)))
387 (dni clrb "Clear bit"
390 (+ OP4_CLRB bitno fr)
391 (set fr (and fr (inv (sll 1 bitno))))
395 (dni xorw_l "XOR W,literal"
398 (+ OP4_LITERAL OP4MID_XOR_L lit8)
401 (set zbit (zflag w)))
405 (dni andw_l "AND W,literal"
408 (+ OP4_LITERAL OP4MID_AND_L lit8)
411 (set zbit (zflag w)))
415 (dni orw_l "OR W,literal"
418 (+ OP4_LITERAL OP4MID_OR_L lit8)
421 (set zbit (zflag w)))
425 (dni addw_l "ADD W,literal"
428 (+ OP4_LITERAL OP4MID_ADD_L lit8)
430 (set cbit (add-cflag w lit8 0))
431 (set dcbit (add-dcflag w lit8 0))
433 (set zbit (zflag w)))
437 (dni subw_l "SUB W,literal"
440 (+ OP4_LITERAL OP4MID_SUB_L lit8)
442 (set cbit (not (sub-cflag lit8 w 0)))
443 (set dcbit (not (sub-dcflag lit8 w 0)))
444 (set zbit (zflag (sub w lit8)))
445 (set w (sub lit8 w)))
449 (dni cmpw_l "CMP W,literal"
452 (+ OP4_LITERAL OP4MID_CMP_L lit8)
454 (set cbit (not (sub-cflag lit8 w 0)))
455 (set dcbit (not (sub-dcflag lit8 w 0)))
456 (set zbit (zflag (sub w lit8))))
460 (dni retw_l "RETW literal"
463 (+ OP4_LITERAL OP4MID_RETW_L lit8)
464 (sequence ((USI new_pc))
466 (set new_pc (c-call UHI "pop_pc_stack"))
467 (set pabits (srl new_pc 13))
472 (dni csew_l "CSE W,literal"
475 (+ OP4_LITERAL OP4MID_CSE_L lit8)
481 (dni csnew_l "CSNE W,literal"
484 (+ OP4_LITERAL OP4MID_CSNE_L lit8)
485 (if (not (eq w lit8))
490 (dni push_l "Push #lit8"
493 (+ OP4_LITERAL OP4MID_PUSH_L lit8)
496 (c-call VOID "adjuststackptr" (const -1))
502 (dni mulsw_l "Multiply W,literal (signed)"
505 (+ OP4_LITERAL OP4MID_MULS_L lit8)
507 (set tmp (mul (ext SI w) (ext SI (and UQI #xff lit8))))
508 (set w (and tmp #xFF))
509 (set mulh (srl tmp 8)))
513 (dni muluw_l "Multiply W,literal (unsigned)"
516 (+ OP4_LITERAL OP4MID_MULU_L lit8)
517 (sequence ((USI tmp))
518 (set tmp (and #xFFFF (mul (zext USI w) (zext USI lit8))))
519 (set w (and tmp #xFF))
520 (set mulh (srl tmp 8)))
524 (dni loadl_l "LoadL literal"
527 (+ OP4_LITERAL OP4MID_LOADL_L lit8)
528 (set dpl (and lit8 #x00FF))
532 (dni loadh_l "LoadH literal"
535 (+ OP4_LITERAL OP4MID_LOADH_L lit8)
536 (set dph (and lit8 #x00FF))
540 (dni loadl_a "LoadL addr16l"
543 (+ OP4_LITERAL OP4MID_LOADL_L addr16l)
544 (set dpl (and addr16l #x00FF))
548 (dni loadh_a "LoadH addr16h"
551 (+ OP4_LITERAL OP4MID_LOADH_L addr16h)
552 (set dph (and addr16l #x0FF00))
556 ;; THIS NO LONGER EXISTS -> Now LOADL
557 ;;(dni bank_l "Bank literal"
560 ;; (+ OP4_LITERAL OP4MID_BANK_L lit8)
565 (dni addcfr_w "Add w/carry fr,W"
568 (+ OP6_ADDC DIR_NOTTO_W fr)
569 (sequence ((QI result) (BI newcbit) (QI isLreg) (HI 16bval))
570 (set newcbit (add-cflag w fr cbit))
571 (set dcbit (add-dcflag w fr cbit))
572 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
573 ;; We can take advantage of the fact that by a lucky
574 ;; coincidence, the address of register xxxH is always
575 ;; one lower than the address of register xxxL.
576 (LregCheck isLreg (ifield f-reg))
579 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
580 (set 16bval (sll 16bval 8))
581 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
582 (set 16bval (addc HI 16bval w cbit))
583 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
584 (set (reg h-spr (sub (ifield f-reg) 1))
585 (and (srl 16bval 8) #xFF))
586 (set result (reg h-spr (ifield f-reg)))
588 (set result (addc w fr cbit)) ;; else part
591 (set zbit (zflag result))
597 (dni addcw_fr "Add w/carry W,fr"
600 (+ OP6_ADDC DIR_TO_W fr)
601 (sequence ((QI result) (BI newcbit))
602 (set newcbit (add-cflag w fr cbit))
603 (set dcbit (add-dcflag w fr cbit))
604 (set result (addc w fr cbit))
605 (set zbit (zflag result))
612 (dni incsnz_fr "Skip if fr++ not zero"
615 (+ OP6_INCSNZ DIR_NOTTO_W fr)
616 (sequence ((QI isLreg) (HI 16bval))
617 (LregCheck isLreg (ifield f-reg))
618 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
619 ;; We can take advantage of the fact that by a lucky
620 ;; coincidence, the address of register xxxH is always
621 ;; one lower than the address of register xxxL.
624 ; Create the 16 bit value
625 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
626 (set 16bval (sll 16bval 8))
627 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
628 ; Do 16 bit arithmetic.
629 (set 16bval (add HI 16bval 1))
630 ; Separate the 16 bit values into the H and L regs
631 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
632 (set (reg h-spr (sub (ifield f-reg) 1))
633 (and (srl 16bval 8) #xFF))
634 (set fr (reg h-spr (ifield f-reg)))
636 (set fr (add fr 1)) ; Do 8 bit arithmetic.
643 (dni incsnzw_fr "Skip if W=fr+1 not zero"
646 (+ OP6_INCSNZ DIR_TO_W fr)
654 (dni mulsw_fr "Multiply W,fr (signed)"
657 (+ OP6_MULS DIR_TO_W fr)
659 (set tmp (mul (ext SI w) (ext SI fr)))
660 (set w (and tmp #xFF))
661 (set mulh (srl tmp 8)))
665 (dni muluw_fr "Multiply W,fr (unsigned)"
668 (+ OP6_MULU DIR_TO_W fr)
669 (sequence ((USI tmp))
670 (set tmp (and #xFFFF (mul (zext USI w) (zext USI fr))))
671 (set w (and tmp #xFF))
672 (set mulh (srl tmp 8)))
676 (dni decsnz_fr "Skip if fr-- not zero"
679 (+ OP6_DECSNZ DIR_NOTTO_W fr)
680 (sequence ((QI isLreg) (HI 16bval))
681 (LregCheck isLreg (ifield f-reg))
682 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
683 ;; We can take advantage of the fact that by a lucky
684 ;; coincidence, the address of register xxxH is always
685 ;; one lower than the address of register xxxL.
688 ; Create the 16 bit value
689 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
690 (set 16bval (sll 16bval 8))
691 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
692 ; New 16 bit instruction
693 (set 16bval (sub HI 16bval 1))
694 ; Separate the 16 bit values into the H and L regs
695 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
696 (set (reg h-spr (sub (ifield f-reg) 1))
697 (and (srl 16bval 8) #xFF))
698 (set fr (reg h-spr (ifield f-reg)))
700 ; Original instruction
708 (dni decsnzw_fr "Skip if W=fr-1 not zero"
711 (+ OP6_DECSNZ DIR_TO_W fr)
719 (dni subcw_fr "Subract w/carry W,fr"
722 (+ OP6_SUBC DIR_TO_W fr)
723 (sequence ((QI result) (BI newcbit))
724 (set newcbit (not (sub-cflag fr w (not cbit))))
725 (set dcbit (not (sub-dcflag fr w (not cbit))))
726 (set result (subc fr w (not cbit)))
727 (set zbit (zflag result))
733 (dni subcfr_w "Subtract w/carry fr,W"
736 (+ OP6_SUBC DIR_NOTTO_W fr)
737 (sequence ((QI result) (BI newcbit) (QI isLreg) (HI 16bval))
738 (set newcbit (not (sub-cflag fr w (not cbit))))
739 (set dcbit (not (sub-dcflag fr w (not cbit))))
740 (LregCheck isLreg (ifield f-reg))
741 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
742 ;; We can take advantage of the fact that by a lucky
743 ;; coincidence, the address of register xxxH is always
744 ;; one lower than the address of register xxxL.
747 ; Create the 16 bit value
748 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
749 (set 16bval (sll 16bval 8))
750 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
751 ; New 16 bit instruction
752 (set 16bval (subc HI 16bval w (not cbit)))
753 ; Separate the 16 bit values into the H and L regs
754 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
755 (set (reg h-spr (sub (ifield f-reg) 1))
756 (and (srl 16bval 8) #xFF))
757 (set result (reg h-spr (ifield f-reg)))
759 ; Original instruction
760 (set result (subc fr w (not cbit)))
764 (set zbit (zflag result))
774 (+ OP6_POP (f-dir 1) fr)
776 (set fr (c-call QI "pop"))
777 (c-call VOID "adjuststackptr" (const 1))
782 (dni push_fr "Push fr"
785 (+ OP6_POP (f-dir 0) fr)
788 (c-call VOID "adjuststackptr" (const -1))
793 (dni csew_fr "Skip if equal W,fr"
796 (+ OP6_CSE (f-dir 1) fr)
802 (dni csnew_fr "Skip if not-equal W,fr"
805 (+ OP6_CSE (f-dir 0) fr)
811 ;;(dni csaw_fr "Skip if W above fr"
812 ;; ((MACH ip2022ext))
814 ;; (+ OP6_CSAB (f-dir 1) fr)
820 ;;(dni csbw_fr "Skip if W below fr"
821 ;; ((MACH ip2022ext))
823 ;; (+ OP6_CSAB (f-dir 0) fr)
829 (dni incsz_fr "Skip if fr++ zero"
832 (+ OP6_INCSZ DIR_NOTTO_W fr)
833 (sequence ((QI isLreg) (HI 16bval))
834 (LregCheck isLreg (ifield f-reg))
835 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
836 ;; We can take advantage of the fact that by a lucky
837 ;; coincidence, the address of register xxxH is always
838 ;; one lower than the address of register xxxL.
841 ; Create the 16 bit value
842 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
843 (set 16bval (sll 16bval 8))
844 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
845 ; New 16 bit instruction
846 (set 16bval (add HI 16bval 1))
847 ; Separate the 16 bit values into the H and L regs
848 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
849 (set (reg h-spr (sub (ifield f-reg) 1))
850 (and (srl 16bval 8) #xFF))
851 (set fr (reg h-spr (ifield f-reg)))
853 ; Original instruction
861 (dni incszw_fr "Skip if W=fr+1 zero"
864 (+ OP6_INCSZ DIR_TO_W fr)
872 (dni swap_fr "Swap fr nibbles"
875 (+ OP6_SWAP DIR_NOTTO_W fr)
876 (set fr (or (and (sll fr 4) #xf0)
877 (and (srl fr 4) #x0f)))
881 (dni swapw_fr "Swap fr nibbles into W"
884 (+ OP6_SWAP DIR_TO_W fr)
885 (set w (or (and (sll fr 4) #xf0)
886 (and (srl fr 4) #x0f)))
890 (dni rl_fr "Rotate fr left with carry"
893 (+ OP6_RL DIR_NOTTO_W fr)
894 (sequence ((QI newfr) (BI newc))
895 (set newc (and fr #x80))
896 (set newfr (or (sll fr 1) (if QI cbit 1 0)))
897 (set cbit (if QI newc 1 0))
902 (dni rlw_fr "Rotate fr left with carry into W"
905 (+ OP6_RL DIR_TO_W fr)
906 (sequence ((QI newfr) (BI newc))
907 (set newc (and fr #x80))
908 (set newfr (or (sll fr 1) (if QI cbit 1 0)))
909 (set cbit (if QI newc 1 0))
914 (dni rr_fr "Rotate fr right with carry"
917 (+ OP6_RR DIR_NOTTO_W fr)
918 (sequence ((QI newfr) (BI newc))
919 (set newc (and fr #x01))
920 (set newfr (or (srl fr 1) (if QI cbit #x80 #x00)))
921 (set cbit (if QI newc 1 0))
926 (dni rrw_fr "Rotate fr right with carry into W"
929 (+ OP6_RR DIR_TO_W fr)
930 (sequence ((QI newfr) (BI newc))
931 (set newc (and fr #x01))
932 (set newfr (or (srl fr 1) (if QI cbit #x80 #x00)))
933 (set cbit (if QI newc 1 0))
938 (dni decsz_fr "Skip if fr-- zero"
941 (+ OP6_DECSZ DIR_NOTTO_W fr)
942 (sequence ((QI isLreg) (HI 16bval))
943 (LregCheck isLreg (ifield f-reg))
944 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
945 ;; We can take advantage of the fact that by a lucky
946 ;; coincidence, the address of register xxxH is always
947 ;; one lower than the address of register xxxL.
950 ; Create the 16 bit value
951 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
952 (set 16bval (sll 16bval 8))
953 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
954 ; New 16 bit instruction
955 (set 16bval (sub HI 16bval 1))
956 ; Separate the 16 bit values into the H and L regs
957 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
958 (set (reg h-spr (sub (ifield f-reg) 1))
959 (and (srl 16bval 8) #xFF))
960 (set fr (reg h-spr (ifield f-reg)))
962 ; Original instruction
970 (dni decszw_fr "Skip if W=fr-1 zero"
973 (+ OP6_DECSZ DIR_TO_W fr)
981 (dni inc_fr "Increment fr"
984 (+ OP6_INC DIR_NOTTO_W fr)
985 (sequence ((QI isLreg) (HI 16bval))
986 (LregCheck isLreg (ifield f-reg))
987 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
988 ;; We can take advantage of the fact that by a lucky
989 ;; coincidence, the address of register xxxH is always
990 ;; one lower than the address of register xxxL.
993 ; Create the 16 bit value
994 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
995 (set 16bval (sll 16bval 8))
996 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
997 ; New 16 bit instruction
998 (set 16bval (add HI 16bval 1))
999 ; Separate the 16 bit values into the H and L regs
1000 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
1001 (set (reg h-spr (sub (ifield f-reg) 1))
1002 (and (srl 16bval 8) #xFF))
1003 (set fr (reg h-spr (ifield f-reg)))
1005 ; Original instruction
1008 (set zbit (zflag fr)))
1012 (dni incw_fr "Increment fr into w"
1015 (+ OP6_INC DIR_TO_W fr)
1018 (set zbit (zflag w)))
1022 (dni not_fr "Invert fr"
1025 (+ OP6_NOT DIR_NOTTO_W fr)
1028 (set zbit (zflag fr)))
1032 (dni notw_fr "Invert fr into w"
1035 (+ OP6_NOT DIR_TO_W fr)
1038 (set zbit (zflag w)))
1042 (dni test_fr "Test fr"
1045 (+ OP6_TEST DIR_NOTTO_W fr)
1047 (set zbit (zflag fr)))
1051 (dni movw_l "MOV W,literal"
1054 (+ OP4_LITERAL OP4MID_MOV_L lit8)
1059 (dni movfr_w "Move/test w into fr"
1062 (+ OP6_OTHER1 DIR_NOTTO_W fr)
1067 (dni movw_fr "Move/test fr into w"
1070 (+ OP6_TEST DIR_TO_W fr)
1073 (set zbit (zflag w)))
1078 (dni addfr_w "Add fr,W"
1081 (+ OP6_ADD DIR_NOTTO_W fr)
1082 (sequence ((QI result) (QI isLreg) (HI 16bval))
1083 (set cbit (add-cflag w fr 0))
1084 (set dcbit (add-dcflag w fr 0))
1085 (LregCheck isLreg (ifield f-reg))
1087 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
1088 ;; We can take advantage of the fact that by a lucky
1089 ;; coincidence, the address of register xxxH is always
1090 ;; one lower than the address of register xxxL.
1093 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
1094 (set 16bval (sll 16bval 8))
1095 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
1096 (set 16bval (add HI (and w #xFF) 16bval))
1097 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
1098 (set (reg h-spr (sub (ifield f-reg) 1))
1099 (and (srl 16bval 8) #xFF))
1100 (set result (reg h-spr (ifield f-reg)))
1102 (set result (addc w fr 0)) ;; else part
1104 (set zbit (zflag result))
1109 (dni addw_fr "Add W,fr"
1112 (+ OP6_ADD DIR_TO_W fr)
1113 (sequence ((QI result))
1114 (set cbit (add-cflag w fr 0))
1115 (set dcbit (add-dcflag w fr 0))
1116 (set result (addc w fr 0))
1117 (set zbit (zflag result))
1122 (dni xorfr_w "XOR fr,W"
1125 (+ OP6_XOR DIR_NOTTO_W fr)
1128 (set zbit (zflag fr)))
1132 (dni xorw_fr "XOR W,fr"
1135 (+ OP6_XOR DIR_TO_W fr)
1138 (set zbit (zflag w)))
1142 (dni andfr_w "AND fr,W"
1145 (+ OP6_AND DIR_NOTTO_W fr)
1148 (set zbit (zflag fr)))
1152 (dni andw_fr "AND W,fr"
1155 (+ OP6_AND DIR_TO_W fr)
1158 (set zbit (zflag w)))
1162 (dni orfr_w "OR fr,W"
1165 (+ OP6_OR DIR_NOTTO_W fr)
1168 (set zbit (zflag fr)))
1172 (dni orw_fr "OR W,fr"
1175 (+ OP6_OR DIR_TO_W fr)
1178 (set zbit (zflag w)))
1182 (dni dec_fr "Decrement fr"
1185 (+ OP6_DEC DIR_NOTTO_W fr)
1186 (sequence ((QI isLreg) (HI 16bval))
1187 (LregCheck isLreg (ifield f-reg))
1188 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
1189 ;; We can take advantage of the fact that by a lucky
1190 ;; coincidence, the address of register xxxH is always
1191 ;; one lower than the address of register xxxL.
1194 ; Create the 16 bit value
1195 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
1196 (set 16bval (sll 16bval 8))
1197 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
1198 ; New 16 bit instruction
1199 (set 16bval (sub HI 16bval 1))
1200 ; Separate the 16 bit values into the H and L regs
1201 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
1202 (set (reg h-spr (sub (ifield f-reg) 1))
1203 (and (srl 16bval 8) #xFF))
1204 (set fr (reg h-spr (ifield f-reg)))
1206 ; Original instruction
1209 (set zbit (zflag fr)))
1213 (dni decw_fr "Decrement fr into w"
1216 (+ OP6_DEC DIR_TO_W fr)
1219 (set zbit (zflag w)))
1223 (dni subfr_w "Sub fr,W"
1226 (+ OP6_SUB DIR_NOTTO_W fr)
1227 (sequence ((QI result) (QI isLreg) (HI 16bval))
1228 (set cbit (not (sub-cflag fr w 0)))
1229 (set dcbit (not (sub-dcflag fr w 0)))
1230 (LregCheck isLreg (ifield f-reg))
1231 ;; If fr is an Lreg, then we have to do 16-bit arithmetic.
1232 ;; We can take advantage of the fact that by a lucky
1233 ;; coincidence, the address of register xxxH is always
1234 ;; one lower than the address of register xxxL.
1237 ; Create the 16 bit value
1238 (set 16bval (reg h-spr (sub (ifield f-reg) 1)))
1239 (set 16bval (sll 16bval 8))
1240 (set 16bval (or 16bval (and (reg h-spr (ifield f-reg)) #xFF)))
1241 ; New 16 bit instruction
1242 (set 16bval (sub HI 16bval (and w #xFF)))
1243 ; Separate the 16 bit values into the H and L regs
1244 (set (reg h-spr (ifield f-reg)) (and 16bval #xFF))
1245 (set (reg h-spr (sub (ifield f-reg) 1))
1246 (and (srl 16bval 8) #xFF))
1247 (set result (reg h-spr (ifield f-reg)))
1249 ; Original instruction
1250 (set result (subc fr w 0))
1252 (set zbit (zflag result))
1257 (dni subw_fr "Sub W,fr"
1260 (+ OP6_SUB DIR_TO_W fr)
1261 (sequence ((QI result))
1262 (set cbit (not (sub-cflag fr w 0)))
1263 (set dcbit (not (sub-dcflag fr w 0)))
1264 (set result (subc fr w 0))
1265 (set zbit (zflag result))
1270 (dni clr_fr "Clear fr"
1273 (+ OP6_OTHER2 (f-dir 1) fr)
1276 (set zbit (zflag fr)))
1280 (dni cmpw_fr "CMP W,fr"
1283 (+ OP6_OTHER2 (f-dir 0) fr)
1285 (set cbit (not (sub-cflag fr w 0)))
1286 (set dcbit (not (sub-dcflag fr w 0)))
1287 (set zbit (zflag (sub w fr))))
1291 (dni speed "Set speed"
1295 (set (reg h-registers #x0E) lit8)
1299 (dni ireadi "Insn memory read with increment"
1302 (+ OP6_OTHER1 (f-op6-10low #x1D))
1303 (c-call "do_insn_read")
1307 (dni iwritei "Insn memory write with increment"
1310 (+ OP6_OTHER1 (f-op6-10low #x1C))
1311 (c-call "do_insn_write")
1315 (dni fread "Flash read"
1318 (+ OP6_OTHER1 (f-op6-10low #x1B))
1319 (c-call "do_flash_read")
1323 (dni fwrite "Flash write"
1326 (+ OP6_OTHER1 (f-op6-10low #x1A))
1327 (c-call "do_flash_write")
1331 (dni iread "Insn memory read"
1334 (+ OP6_OTHER1 (f-op6-10low #x19))
1335 (c-call "do_insn_read")
1339 (dni iwrite "Insn memory write"
1342 (+ OP6_OTHER1 (f-op6-10low #x18))
1343 (c-call "do_insn_write")
1347 (dni page "Set insn page"
1351 ;(+ OP6_OTHER1 (f-op6-7low #x2) page3)
1352 ;(set pabits (srl page3 13))
1353 (+ OP6_OTHER1 (f-op6-7low #x2) addr16p)
1354 (set pabits addr16p)
1358 (dni system "System call"
1361 (+ OP6_OTHER1 (f-op6-10low #xff))
1362 (c-call "do_system")
1366 (dni reti "Return from interrupt"
1369 (+ OP6_OTHER1 (f-op6-7low #x1) reti3)
1370 (c-call "do_reti" reti3)
1377 (+ OP6_OTHER1 (f-op6-10low #x07))
1378 (sequence ((USI new_pc))
1379 (set new_pc (c-call UHI "pop_pc_stack"))
1380 (set pabits (srl new_pc 13))
1385 (dni int "Software interrupt"
1388 (+ OP6_OTHER1 (f-op6-10low #x6))
1393 (dni breakx "Breakpoint with extended skip"
1396 (+ OP6_OTHER1 (f-op6-10low #x5))
1397 (c-call "do_break" pc)
1401 (dni cwdt "Clear watchdog timer"
1404 (+ OP6_OTHER1 (f-op6-10low #x4))
1405 (c-call "do_clear_wdt")
1409 (dni ferase "Flash erase"
1412 (+ OP6_OTHER1 (f-op6-10low #x3))
1413 (c-call "do_flash_erase")
1417 (dni retnp "Return, no page"
1420 (+ OP6_OTHER1 (f-op6-10low #x2))
1421 (sequence ((USI new_pc))
1422 (set new_pc (c-call UHI "pop_pc_stack"))
1427 (dni break "Breakpoint"
1430 (+ OP6_OTHER1 (f-op6-10low #x1))
1431 (c-call "do_break" pc)
1435 (dni nop "No operation"
1438 (+ OP6_OTHER1 (f-op6-10low #x0))
1444 ; Macro instructions
1445 (dnmi sc "Skip on carry"
1448 (emit sb (bitno 0) (fr #xB)) ; sb status.0
1451 (dnmi snc "Skip on no carry"
1454 (emit snb (bitno 0) (fr #xB)) ; snb status.0
1457 (dnmi sz "Skip on zero"
1460 (emit sb (bitno 2) (fr #xB)) ; sb status.2
1463 (dnmi snz "Skip on no zero"
1466 (emit snb (bitno 2) (fr #xB)) ; snb status.2
1469 (dnmi skip "Skip always"
1472 (emit snb (bitno 0) (fr 9)) ; snb pcl.0 | (pcl&1)<<12
1475 (dnmi skipb "Skip always"
1478 (emit sb (bitno 0) (fr 9)) ; sb pcl.0 | (pcl&1)<<12