 GBLL ARM32
ARM32 SETL {TRUE}
 MACRO
$name ERR $number,$message
 GBLS ErrText$name
 GBLA ErrNum$name
 GBLL ErrUsed$name
ErrText$name SETS "$message"
ErrNum$name SETA $number
ErrUsed$name SETL {FALSE}
 MEND
 MACRO
$name XERR $number,$tag,$message
 GBLS ErrText$name
 GBLS ErrTag$name
 GBLA ErrNum$name
 GBLL ErrUsed$name
ErrTag$name SETS "$tag"
ErrText$name SETS "$message"
ErrNum$name SETA $number
ErrUsed$name SETL {FALSE}
 MEND
 MACRO
$label MKERR $name
 ASSERT :LNOT:ErrUsed$name
ErrUsed$name SETL {TRUE}
$label & ErrNum$name
 = ErrText$name,0
 ALIGN
 MEND
 MACRO
$label MKXERR $name
 ASSERT :LNOT:ErrUsed$name
ErrUsed$name SETL {TRUE}
$label & ErrNum$name
 = ErrTag$name,0
 ALIGN
 MEND
 MACRO
$label NOP
$label MOV r0,r0
 MEND
 MACRO
$label FLP $dest,$src
 ASSERT $dest<>$src
$label MOV $dest,$src,LSR#8
 BIC $dest,$dest,#&0000FF00
 BIC $src,$src,$dest,LSL#8
 ORR $src,$dest,$src,LSL#8
 MOV $dest,$src,LSR#16
 ORR $dest,$dest,$src,LSL#16
 MEND
 MACRO
$second FOLLOWS $first
 ASSERT $first+4=$second
 MEND
 MACRO
 MVC $dest,$const,$assumed
 [ "$assumed"=""
 [ $const<>0
 MOV $dest,#$const
 ]
 |
 [ $const<>$assumed
 MOV $dest,#$const
 ]
 ]
 MEND
 MACRO
$label SETV $cond
 [ ARM32
$label MSR$cond CPSR_flg,#V_bit
 |
$label CMP$cond pc,#&80000000
 ]
 MEND
 GBLS strucname
 MACRO
$label STRUC $reg
strucname SETS "$label"
 [ "$reg"=""
 ^ 0
 |
 ^ 0,$reg
 ]
 MEND
 MACRO
$label X $size
 [ $size>=4
 # (((:INDEX:@)+3):AND::NOT:3)-(:INDEX:@)
 ]
 [ "$strucname"=""
$label # $size
 |
$strucname._$label # $size
 ]
 MEND
 MACRO
$label STREND
 # (((:INDEX:@)+3):AND::NOT:3)-(:INDEX:@)
 [ "$label"<>""
$label # 0
 ]
 [ "$strucname"<>""
$strucname._Size * :INDEX:@
 ]
 MEND
 MACRO
$label INT $mult
 [ "$mult"=""
$label X 4
 |
$label X 4*$mult
 ]
 MEND
 MACRO
$label CHAR $mult
 [ "$mult"=""
$label X 1
 |
$label X 1*$mult
 ]
 MEND
 GBLA unionsize
 MACRO
 XX $s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9
 [ "$s0"<>""
 [ $s0._Size>unionsize
unionsize SETA $s0._Size
 ]
 XX $s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9
 ]
 MEND
 MACRO
$label UNION $s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9
unionsize SETA 0
 XX $s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9
$label._Size * unionsize
 MEND
 GBLS reglist
 GBLA stackalloc
 GBLL backtrace
 GBLL entry
 GBLA linkword
 MACRO
$label STRC $name
$label X $name._Size
 MEND
 GBLL BackTrace
BackTrace SETL {FALSE}
 MACRO
$label PROF $name
$label
 [ BackTrace
 B %ft5
 = "PROF"
4
 & 0
 = "BACK"
 [ "$label"<>""
 = "+$label",0
 |
 = "+$name",0
 ]
 ALIGN
5
 STMFD sp!,{lr}
 LDR lr,%bt4
 ADD lr,lr,#1
 STR lr,%bt4
 LDMFD sp!,{lr}
 ]
 MEND
 MACRO
$label |__SAVE| $regs,$cc,$ent,$stack,$nolr
 ALIGN
reglist SETS "$regs"
 [ BackTrace
backtrace SETL Debug
 |
backtrace SETL {FALSE}
 ]
 [ backtrace
entry SETL "$ent"<>""
 B %ft76
 = "PROF"
70
 & 0
72
 = "BACK"
74
 [ "$label"<>""
 = "$label",0
 |
 = "not named",0
 ]
 ALIGN
76
$label
 STM$cc.FD sp!,{r0-r12,sp,lr,pc}
 [ entry
 IMPORT DebugTrapOn
 BL$cc DebugTrapOn
 ]
 SUB$cc sp,sp,#word*3
 LDR$cc lr,%ft78
 STR$cc lr,[sp,#word*2]
 ADR$cc lr,%bt74
 STR$cc lr,[sp,#word*1]
 LDR$cc lr,%bt72
 STR$cc lr,[sp,#word*0]
 LDR$cc lr,%bt70
 ADD$cc lr,lr,#1
 STR$cc lr,%bt70
 LDR$cc lr,[sp,#word*3+word*14]
 |
$label
 ]
 [ reglist=""
 [ "$nolr"=""
78 STM$cc.FD sp!,{lr}
 ]
 |
 [ "$nolr"=""
78 STM$cc.FD sp!,{$reglist,lr}
 |
78 STM$cc.FD sp!,{$reglist}
 ]
 ]
 [ "$stack"<>""
stackalloc SETA $stack
 |
stackalloc SETA 0
 ]
 [ stackalloc>0
 SUB sp,sp,#stackalloc
 ]
 MEND
 MACRO
$label SAVEe $regs,$cc
 [ "$cc"<>""
$label |__SAVE| "$regs",$cc,"e"
 |
$label |__SAVE| "$regs",AL,"e"
 ]
 MEND
 MACRO
$label SAVE $regs,$cc
$label |__SAVE| "$regs",$cc
 MEND
 MACRO
$label SAVEs $regs,$stack,$cc
 [ "$cc"<>""
$label |__SAVE| "$regs",$cc,"",$stack
 |
$label |__SAVE| "$regs",AL,"",$stack
 ]
 MEND
 MACRO
$label SAVEv $regs,$cc
 [ "$cc"<>""
$label |__SAVE| "$regs",$cc,"","","nolr"
 |
$label |__SAVE| "$regs",AL,"","","nolr"
 ]
 MEND
 MACRO
$label RESTORE $cc
$label
 [ backtrace:LAND:entry
 IMPORT DebugTrapOff
 BL$cc DebugTrapOff
 ]
 [ stackalloc>0
 ADD$cc sp,sp,#stackalloc
 ]
 [ reglist=""
 LDM$cc.FD sp!,{lr}
 |
 LDM$cc.FD sp!,{$reglist,lr}
 ]
 [ backtrace
 ADD$cc sp,sp,#word*3+word*16
 ]
 MEND
 MACRO
$label RETURN $cc
$label
 [ backtrace
 RESTORE $cc
 [ ARM32
 MOV$cc pc,lr
 |
 MOV$cc.S pc,lr
 ]
 |
 [ stackalloc>0
 ADD$cc sp,sp,#stackalloc
 ]
 [ reglist=""
 [ ARM32
 LDM$cc.FD sp!,{pc}
 |
 LDM$cc.FD sp!,{pc}^
 ]
 |
 [ ARM32
 LDM$cc.FD sp!,{$reglist,pc}
 |
 LDM$cc.FD sp!,{$reglist,pc}^
 ]
 ]
 ]
 MEND
 MACRO
$label KEEPERR $cc
$label
 [ reglist<>""
 [ reglist:LEFT:2="r0"
 STR$cc r0,[sp,#stackalloc]
 ]
 ]
 MEND
 MACRO
$label RETURN_IF_ERR
$label KEEPERR VS
 [ ARM32
 RETURN VS
 |
 RESTORE VS
 ORRVSS pc,lr,#V_bit
 ]
 MEND
 MACRO
$label RETURN_ERR
$label KEEPERR VS
 [ ARM32
 RETURN
 |
 RESTORE
 ORRVSS pc,lr,#V_bit
 BICS pc,lr,#V_bit
 ]
 MEND
 MACRO
$label RETURN_NOPSR $cc
$label
 [ backtrace
 RESTORE $cc
 MOV$cc pc,lr
 |
 [ stackalloc>0
 ADD sp,sp,#stackalloc
 ]
 [ reglist=""
 LDM$cc.FD sp!,{pc}
 |
 LDM$cc.FD sp!,{$reglist,pc}
 ]
 ]
 MEND
 MACRO
$label MkIEB $name,$noalign,$tag
 ALIGN
$label
ErrorBlock_$name
 & ErrorNumber_$name
 [ "$tag"=""
 = "$name",0
 |
 = "$tag",0
 ]
 [ "$noalign"=""
 ALIGN
 ]
 MEND
 MACRO
$label DivRem $rc,$ra,$rb,$rtemp
$label
 MOV $rtemp,$rb
 CMP $rtemp,$ra,LSR#1
01 MOVLS $rtemp,$rtemp,LSL#1
 CMPLS $rtemp,$ra,LSR#1
 BLS %BT01
 MOV $rc,#0
02 CMP $ra,$rtemp
 SUBCS $ra,$ra,$rtemp
 ADC $rc,$rc,$rc
 MOV $rtemp,$rtemp,LSR#1
 CMP $rtemp,$rb
 BCS %BT02
 MEND
 MACRO
 AddError $name,$text,$value
 [ "$value"=""
ErrorNumber_$name # 1
 |
ErrorNumber_$name * $value
 ]
 GBLS ErrorString_$name
ErrorString_$name SETS "$text"
 MEND
 MACRO
 AddFSError $class,$baseerr,$fsname,$fsnumber
 LCLA value
value SETA &10000+$fsnumber*&100+ErrorNumber_$baseerr._Pre
 LCLS string
string SETS ErrorString_$baseerr._Pre:CC:"$fsname":CC:ErrorString_$baseerr._Post
 LCLS string2
string2 SETS "&":CC:(:STR:value)
 AddError $class$baseerr,"$string",$string2
 MEND
 END
