chiark / gitweb /
instruction set aliases and summary
authorian <ian>
Sat, 23 Apr 2005 13:36:11 +0000 (13:36 +0000)
committerian <ian>
Sat, 23 Apr 2005 13:36:11 +0000 (13:36 +0000)
iwjpictest/.cvsignore
iwjpictest/Makefile
iwjpictest/insn-aliases.inc-gen [new file with mode: 0755]

index b9fbbebcfb7486c09609cb5fb150a8ba87e55a8d..9ddea0c7884b375015a837e587ca538feb7246ec 100644 (file)
@@ -1,3 +1,7 @@
 *.hex
 *.cod
 *.lst
+insn-*.ps
+insn-*.txt
+insn-aliases.inc
+*.tmp
index 9737068389f964cd77b342715f53d8ab6fdc6a33..fab06cd87d67e2d32e77251773b2a8be2a6791c6 100644 (file)
@@ -1,9 +1,26 @@
-TARGETS=       config.hex
+TARGETS=       config.hex $(INSN_TARGETS)
+
+INSN_TARGETS=  insn-aliases.inc insn-1.ps insn-2.ps
 
 PROGRAMS=      flasher copybits serialloop
 
+include ../common.make
 include ../pic.make
 
 clean:         pic-clean
+               rm -f $(INSN_TARGETS)
+
+insn-aliases.inc:      insn-aliases.inc-gen
+               ./$< --macros $o
+
+insn-%.txt:    insn-aliases.inc-gen Makefile
+               sed -e '1,/^#--1--/d; /^#--2--/,$$d' <$< >$@.1.tmp
+               ./$< --descs >$@.2.tmp
+               sort -t % -k 1.$(subst 2,28,$*) <$@.2.tmp >>$@.1.tmp
+               sed -e '1,/^#--2--/d; /^#--3--/,$$d' <$< >>$@.1.tmp
+               mv -f $@.1.tmp $@
+
+insn-%.ps:     insn-%.txt
+               atp -T A4 -B -f Courier8.2 <$< $o
 
 copybits.o serialloop.o:       onecopybit.inc
diff --git a/iwjpictest/insn-aliases.inc-gen b/iwjpictest/insn-aliases.inc-gen
new file mode 100755 (executable)
index 0000000..8b499ce
--- /dev/null
@@ -0,0 +1,177 @@
+#!/bin/sh
+set -e
+
+badusage () { echo >&2 'bad usage'; exit 1; }
+
+comment=';'
+macros=false
+
+case "$1" in
+--macros)      macros=true ;;
+--descs)       comment='' ;;
+*)             badusage ;;
+esac
+test $# = 1 || badusage
+
+w=0xfe8
+
+desc () {
+       local use=$1 new=$2 formargs=$3 notes=$4
+       local fan="$(printf "%-6s %s" "$formargs" "$notes")"
+       if $descs; then
+               printf "$comment %-13s %-11s %-39s %s\n" \
+                       "$new" "$fan" "$ds" "$use"
+       fi
+}
+alias_r () {
+       local use=$1 new=$2 actargs=$3 formargs=$4
+       if $macros; then
+               cat <<END
+$new   macro   $formargs
+       $use    $actargs
+       endm
+END
+       fi
+}
+alias_f () {
+       local use=$1 new=$2 actargs=$3 formargs=$4 notes="$5"
+       formargs=${formargs#,}
+       desc $use $new "$formargs" "$notes"
+       alias_r "$use" "$new" "$actargs" "$formargs"
+}
+als_fa () {
+       local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5
+       desc $use "$base$ext" f$formargs A
+       alias_r $use ${base}${ext}  f$actargs   f$formargs
+       alias_r $use ${base}a${ext} f$actargs,0 f$formargs
+       alias_r $use ${base}b${ext} f$actargs,1 f$formargs
+}
+als_fa_1fw () {
+       local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5
+       als_fa $use ${base}f "$ext" "$actargs" "$formargs"
+       alias_f $use ${base}w$ext $w$actargs,0 "$formargs"
+}
+als_fda_2fw () {
+       local use=$1 base=$2 ext=$3
+       als_fa $use ${base}f "$ext" ,1
+       als_fa $use ${base}w "$ext" ,0
+}
+als_fda_1fw () {
+       local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5
+       als_fa $use ${base}f  "$ext" $actargs,1 "$formargs"
+       als_fa $use ${base}fw "$ext" $actargs,0 "$formargs"
+}
+als_k_lw () {
+       local use=$1 base=$2
+       alias_f $use ${base}_lw l l
+}
+als_k_lw_fda_2fw () {
+       local base=$1
+       als_fda_2fw     ${base}wf       ${base}_wf
+       als_k_lw        ${base}lw       ${base}
+}
+als_k_lw_fa () {
+       local base=$1
+       als_fa          ${base}wf       ${base}_wf
+       als_k_lw        ${base}lw       ${base}
+}
+
+noalias () {
+       local insn="$1"; shift
+       desc "$insn" "$insn" "$@"
+}
+descs_bra () {
+       local what=$1 flag=$2
+ ds="Branch if $what";         alias_f b$flag  bra_$flag  l l 8R
+ ds="Branch if Not $what";     alias_f bn$flag bra_n$flag l l 8R
+}
+
+if $macros; then echo ' ; autogenerated - do not edit'; fi
+
+# `literal operations' (DS282) that are also mirrored by
+# `byte-oriented file register operations' (DS280)
+ds='Add';                      als_k_lw_fda_2fw                add
+ds='Bitwise AND';              als_k_lw_fda_2fw                and
+ds='Bitwise Inclusive OR';     als_k_lw_fda_2fw                ior
+ds='Bitwise Exclusive OR';     als_k_lw_fda_2fw                xor
+ds='Move (flags unchanged)';   als_k_lw_fa                     mov
+ds='Multiply';                 als_k_lw_fa                     mul
+
+# `byte-oriented file register operations' (DS280)
+ds='Add with carry';           als_fda_2fw     addwfc  addc_wf
+ds='Clear';                    als_fa_1fw      clrf    clr_
+ds='Complement (bitwise NOT)'; als_fda_1fw     comf    com_
+ds='Compare; if F==W then...'; als_fa          cpfseq  cmp_fw  _ifne
+ds='Compare; if F<=W then...'; als_fa          cpfsgt  cmp_fw  _ifle
+ds='Compare; if F>=W then...'; als_fa          cpfslt  cmp_fw  _ifge
+ds='Decrement';                        als_fda_1fw     dec     dec_
+ds='Decrement; if !=0 then...';        als_fda_1fw     decfsz  dec_    _ifnz
+ds='Decrement; if =0 then...'; als_fda_1fw     dcfsnz  dec_    _ifz
+ds='Increment';                        als_fda_1fw     inc     inc_
+ds='Increment; if !=0 then...';        als_fda_1fw     incfsz  inc_    _ifnz
+ds='Increment; if =0 then...'; als_fda_1fw     infsnz  inc_    _ifz
+ds='Move';                     als_fa          movf    mov_fw  ''      ,0
+ds='Move F to same F';         als_fa          movf    mov_fsf ''      ,1
+ds='Move (flags unchanged)';   alias_f         movff   mov_ff  f,g     f,g
+ds='Negate';                   als_fda_1fw     negf    neg_
+ds='Rotate left (through carry)'; als_fda_1fw  rlcf    rlc_
+ds='Rotate left';              als_fda_1fw     rlncf   rl_
+ds='Rotate right (through carry)'; als_fda_1fw rrcf    rrc_
+ds='Rotate right';             als_fda_1fw     rrncf   rr_
+ds='Set all bits';             als_fa_1fw      setf    set_
+ds='Subtract with borrow';     als_fda_2fw     subfwb  subb_fw
+ds='Subtract with borrow';     als_fda_2fw     subwfb  subb_wf
+ds='Subtract';                 als_fda_2fw     subfw   sub_fw
+ds='Swap nybbles';             als_fda_1fw     swapf   swap_
+ds='Test; if !=0 then...';     als_fa_1fw      tstfsz  tst_    _ifnz
+
+# `bit-oriented file register operations' (DS280)
+ds='Bit Clear';                als_fa_1fw      bcf     bc_     ''      ,b      ,b
+ds='Bit Set';          als_fa_1fw      bsf     bs_     ''      ,b      ,b
+ds='Bit Test; if 1 then...'; als_fa_1fw        btfsc   bt_     _if1    ,b      ,b
+ds='Bit Test; if 0 then...'; als_fa_1fw        btfss   bt_     _if0    ,b      ,b
+
+# `control operations' (DS281)
+descs_bra Carry                c
+descs_bra Negative     n
+descs_bra Overflow     ov
+descs_bra Zero         z
+ds='Branch unconditionally';   noalias         bra     l       11R
+ds='Call subroutine';          noalias         call    l       20
+ds='Call subr., saving W,S,BSR'; alias_f call  call_s  l l     20
+ds='Clear watchdog timer';     noalias         clrwdt
+ds='Decimal adjust';           alias_f daw     da_w
+ds='Jump unconditionally';     noalias         goto    l       20
+ds='No Operation';             noalias         nop
+ds='Pop top of return stack';  noalias         pop
+ds='Push PC+2 onto stack';     noalias         push
+ds='Branch to subroutine';     noalias         rcall   l       8R
+ds='Reset the microcontroller';        noalias         reset
+ds="Return, reenabling Int's"; noalias         retfie
+ds="Return, ena.Int's, restoring W,S,BSR"; alias_f retfie retfie_r
+ds='Return with literal in W'; noalias         retlw
+ds='Return from subroutine';   noalias         return
+ds='Return, restoring W,S,BSR';        alias_f         return  return_r
+ds='Go into standby mode';     noalias         sleep
+
+# `literal operations' (DS282)
+ds='Subtract';                 als_k_lw                sublw   sub
+ds='Move literal to BSR'       alias_f movlb   mov_lb  l       4
+ds='Move literal to FSR<i>'    alias_f lfsr    mov_lfsr i,l i,l 2,12
+ds='Table Read'                        noalias         tblrd   */*+/*-/+*
+ds='Table Write'               noalias         tblwt   */*+/*-/+*
+
+if $macros; then echo ' ; the end'; fi
+
+exit 0
+#--1--
+Our opcode     Args  Notes Description                            Official
+ ------------- ------ ---- --------------------------------------- -------
+#--2--
+ ------------- ------ ---- --------------------------------------- -------
+Notes:  R  Branch uses relative offset.
+        A  Uses BSR for F iff F address is not in Access Bank.  There are
+           also <op>_<how>a (always uses access bank) and <op>_<how>b
+           (always uses BSR).  (<op>_<how>[ab]_if<what> for conditionals.)
+    digits Gives number of bits of address or offset.
+#--3--