Generic26 14.3 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
        SUBT    Generic CPU Specific Definitions

17 18 19 20 21 22 23
OldOpt  SETA    {OPT}
        OPT     OptNoList+OptNoP1List

 [ :LNOT: :DEF: Included_Hdr_CPU_Generic26
        GBLL    Included_Hdr_CPU_Generic26
Included_Hdr_CPU_Generic26 SETL {TRUE}

Neil Turton's avatar
Neil Turton committed
24 25 26 27 28 29 30 31
; ***********************************
; ***    C h a n g e   L i s t    ***
; ***********************************
;
; Date       Name          Description
; ----       ----          -----------
; 13-Jul-93  JRoach        Created
; 30-Jun-94  AMcC          Restore OPT
32 33 34
; 05-Nov-99  KBracey       Keep an eye on No26bitCode flag

 [ :LNOT: :DEF: Included_Hdr_Machine_Machine
35
        GET     Hdr:Machine.<Machine>
36
 ]
Neil Turton's avatar
Neil Turton committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

        ; Standard register names

r0      RN      0
R0      RN      r0
r1      RN      1
R1      RN      r1
r2      RN      2
R2      RN      r2
r3      RN      3
R3      RN      r3
r4      RN      4
R4      RN      r4
r5      RN      5
R5      RN      r5
r6      RN      6
R6      RN      r6
r7      RN      7
R7      RN      r7
r8      RN      8
R8      RN      r8
r9      RN      9
R9      RN      r9
r10     RN      10
R10     RN      r10
r11     RN      11
R11     RN      r11
r12     RN      12
R12     RN      r12
r13     RN      13
R13     RN      r13
r14     RN      14
R14     RN      r14
r15     RN      15
R15     RN      r15


        ; Special names for the banked registers

r13_usr RN      13
r14_usr RN      14

79 80
r8_fiq  RN      8
r9_fiq  RN      9
Neil Turton's avatar
Neil Turton committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
r10_fiq RN      10
r11_fiq RN      11
r12_fiq RN      12
r13_fiq RN      13
r14_fiq RN      14

r13_irq RN      13
r14_irq RN      14

r13_svc RN      13
r14_svc RN      14


        ; Standard register synonyms

lr      RN      r14                     ; Link Register
LR      RN      r14
lr_usr  RN      r14_usr
lr_fiq  RN      r14_fiq
lr_irq  RN      r14_irq
lr_svc  RN      r14_svc
link    RN      r14
LINK    RN      r14

pc      RN      r15                     ; Program Counter
PC      RN      r15

108
 [ :LNOT: No26bitCode
Neil Turton's avatar
Neil Turton committed
109 110
psr     RN      r15                     ; Processor Status Register
PSR     RN      r15
111
 ]
Neil Turton's avatar
Neil Turton committed
112 113 114 115 116 117 118 119 120 121 122 123


        ; Registers for the ARM Procedure Calling Standard

sl      RN      10
SL      RN      10
fp      RN      11
FP      RN      11
IP      RN      12
ip      RN      12


124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
        ; Condition code symbols

Cond_EQ *       0  :SHL: 28
Cond_NE *       1  :SHL: 28
Cond_CS *       2  :SHL: 28
Cond_HS * Cond_CS
Cond_CC *       3  :SHL: 28
Cond_LO * Cond_CC
Cond_MI *       4  :SHL: 28
Cond_PL *       5  :SHL: 28
Cond_VS *       6  :SHL: 28
Cond_VC *       7  :SHL: 28
Cond_HI *       8  :SHL: 28
Cond_LS *       9  :SHL: 28
Cond_GE *       10 :SHL: 28
Cond_LT *       11 :SHL: 28
Cond_GT *       12 :SHL: 28
Cond_LE *       13 :SHL: 28
Cond_AL *       14 :SHL: 28
Cond_   * Cond_AL
Cond_NV *       15 :SHL: 28

Neil Turton's avatar
Neil Turton committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        ; Flag position specifiers for the PSR

N_bit_number    *       31
Z_bit_number    *       30
C_bit_number    *       29
V_bit_number    *       28
I_bit_number    *       27
F_bit_number    *       26


        ; Flag value specifiers for the PSR

N_bit           *       1 :SHL: N_bit_number
Z_bit           *       1 :SHL: Z_bit_number
C_bit           *       1 :SHL: C_bit_number
V_bit           *       1 :SHL: V_bit_number
I_bit           *       1 :SHL: I_bit_number
F_bit           *       1 :SHL: F_bit_number
164
M_bits          *       2_11
Neil Turton's avatar
Neil Turton committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209


        ; Processor mode values for the PSR

USR_mode        *      2_00
FIQ_mode        *      2_01
IRQ_mode        *      2_10
SVC_mode        *      2_11

ARM_CC_Mask     *   &FC000003           ; Processor condition flags + mode bits


        ; Co_processor number allocations

                        ^       0
ARMCoProc_Reserved      #       1       ;  0, Reserved by Acorn
ARMCoProc_FPU           #       1       ;  1, All floating point systems
ARMCoProc_FPUextra      #       1       ;  2, For extra FP instructions
ARMCoProc_3             #       1       ;  3,
ARMCoProc_4             #       1       ;  4,
ARMCoProc_5             #       1       ;  5,
ARMCoProc_6             #       1       ;  6,
ARMCoProc_OMBRA         #       1       ;  7, Olivetti/Acorn 80x86
ARMCoProc_TestHardware  #       1       ;  8, Acorn
ARMCoProc_9             #       1       ;  9,
ARMCoProc_10            #       1       ; 10,
ARMCoProc_11            #       1       ; 11,
ARMCoProc_12            #       1       ; 12,
ARMCoProc_13            #       1       ; 13,
ARMCoProc_14            #       1       ; 14,
ARMCoProc_CacheControl  #       1       ; 15, Part of the ARM3 CPU


        ; 26 bit processor specific macro definitions

; ************************************************************
; ***  BSR - Branch to subroutine saving R14 on the stack  ***
; ************************************************************
        MACRO
$label  BSR     $dest
$label  Push    R14
        BL      $dest
        Pull    R14
        MEND

210
 [ No32bitCode
Neil Turton's avatar
Neil Turton committed
211 212 213 214 215 216 217 218 219 220 221 222 223
; ************************************************
; ***  CLC - Clear carry flag - will set nzcv  ***
; ************************************************
        MACRO
$label  CLC     $cond
$label  CMN$cond pc, #0
        MEND

; ***********************************************
; ***  CLRPSR - Clear bits in PSR from the    ***
; ***  mask in $bits, using register $regtmp  ***
; ***********************************************
        MACRO
224 225
$label  CLRPSR  $bits, $regtmp, $cond, $oldpsr
$label
Kevin Bracey's avatar
Kevin Bracey committed
226
        [ "$oldpsr" <> ""
227 228 229
        MOV$cond   $oldpsr, pc
        ]
        MVN$cond   $regtmp, #$bits
Neil Turton's avatar
Neil Turton committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        TST$cond.P $regtmp, pc
        MEND

; **************************************************
; *** CLRV - Clear overflow flag - will set nzCv ***
; **************************************************
        MACRO
$label  CLRV    $cond
$label  CMP$cond pc, #0
        MEND

; **********************************************************************************
; ***  PHPSEI - Disable IRQs, saving an old interrupt state indicator in a       ***
; ***  register, default R14.  Note that this code preserves the C and V flags.  ***
; **********************************************************************************
        MACRO
246 247
$label  PHPSEI  $register=R14, $regtmp  ; (we don't use regtmp, 32-bit one does)
        LCLS    usereg
Neil Turton's avatar
Neil Turton committed
248
  [     "$register" = ""
249
usereg  SETS    "R14"
Neil Turton's avatar
Neil Turton committed
250
  |
251
usereg  SETS    "$register"
Neil Turton's avatar
Neil Turton committed
252
  ]
253 254 255 256
$label  MOV     $usereg, #I_bit
        TST     $usereg, PC             ; is I_bit set ?
        TEQEQP  $usereg, PC             ; no, then set it (and $register = I_bit)
        MOVNE   $usereg, #0             ; yes, then leave alone (and $register = 0)
Neil Turton's avatar
Neil Turton committed
257 258 259 260 261 262 263
        MEND

; **************************************************************************
; ***  PLP - Restore IRQ state from the indicator in a register (set up  ***
; ***  by PHPSEI).  Note that this code preserves the C and V flags.     ***
; **************************************************************************
        MACRO
264
$label  PLP     $register=R14
265
        LCLS    usereg
Neil Turton's avatar
Neil Turton committed
266
  [     "$register" = ""
267
usereg  SETS    "R14"
Neil Turton's avatar
Neil Turton committed
268
  |
269
usereg  SETS    "$register"
Neil Turton's avatar
Neil Turton committed
270
  ]
271
$label  TEQP    $usereg, PC
Neil Turton's avatar
Neil Turton committed
272
        MEND
273
 ]
Neil Turton's avatar
Neil Turton committed
274 275 276 277 278 279 280 281 282 283 284 285 286

; ****************
; ***  RETURN  ***
; ****************
        MACRO
$label  RETURN  $cond
$label  MOV$cond pc, lr
        MEND

; *****************
; ***  RETURNS  ***
; *****************
        MACRO
287 288 289 290
$label  RETURNS $cond, $nowarn
 [ "$nowarn"=""
 ! 0, "RETURNS macro indicates possible 32-bit incompatibility", 1
 ]
Neil Turton's avatar
Neil Turton committed
291 292
$label  MOV$cond.S pc, lr
        MEND
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321

 [ No32bitCode
; ******************
; ***  RETURNVC  ***
; ******************
        MACRO
$label  RETURNVC  $cond
$label  BIC$cond.S pc, lr, #V_bit
        MEND

; ******************
; ***  RETURNVS  ***
; ******************
        MACRO
$label  RETURNVS  $cond
$label  ORR$cond.S pc, lr, #V_bit
        MEND

; ****************************************************
; ***  SavePSR - Save the PSR in a register, to be ***
; ***  restored later using RestorePSR             ***
; ****************************************************
        MACRO
$label  SavePSR  $reg, $cond
$label  MOV$cond $reg, pc
        MEND

; ****************************************************
; ***  RestPSR - Restore the PSR from a register   ***
322
; ***  set up by SavePSR                           ***
323 324 325 326 327 328 329
; ***  $fields may be set to "f" if the PSR fields ***
; ***  c,x,s do not need restoring, which will     ***
; ***  save a few cycles on newer ARMs (but the    ***
; ***  No32bitCode version of the macro will set   ***
; ***  the c field anyway). Values other than "f", ***
; ***  "cf", "fc" and unset are deprecated for     ***
; ***  compatibility with No32bitCode.             ***
330 331 332
; ****************************************************
        MACRO
$label  RestPSR    $reg, $cond, $fields
333 334 335
  [ "$fields"<>"" :LAND: "$fields"<>"cf" :LAND: "$fields"<>"fc" :LAND: "$fields"<>"f"
        !       0, "Unpredictable behaviour due to deprecated RestPSR fields parameter"
  ]
336 337
$label  TEQ$cond.P pc, $reg
        MEND
Neil Turton's avatar
Neil Turton committed
338 339 340 341 342 343

; ****************************************************
; ***  SCPSR - Set and clear bits in PSR from the  ***
; ***  masks $set, $clr, using register $regtmp    ***
; ****************************************************
        MACRO
344 345 346 347 348 349 350
$label  SCPSR   $set, $clr, $regtmp, $cond, $oldpsr
        LCLS    srcreg
        [ "$oldpsr"=""
srcreg  SETS    "$regtmp"
        |
srcreg  SETS    "$oldpsr"
        ]
351 352
        [ (($set) :AND: ($clr)) <> 0
        ! 1, "Attempt to simultaneously set and clear a bit in SCPSR"
353
        ]
354 355
$label  MOV$cond   $srcreg, pc
        ORR$cond   $regtmp, $srcreg, #($set) :OR: ($clr)
Neil Turton's avatar
Neil Turton committed
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
        TEQ$cond.P $regtmp, #$clr
        MEND

; **********************************************
; ***  SEC - Set carry flag - will set nzCv  ***
; **********************************************
        MACRO
$label  SEC     $cond
$label  CMP$cond pc, #0
        MEND

; ************************************************
; ***  SETPSR - Set bits in PSR from the mask  ***
; ***  in $bits, using register $regtmp        ***
; ************************************************
        MACRO
372 373 374 375 376 377 378 379 380
$label  SETPSR  $bits, $regtmp, $cond, $oldpsr
        LCLS    srcreg
        [ "$oldpsr"=""
srcreg  SETS    "$regtmp"
        |
srcreg  SETS    "$oldpsr"
        ]
$label  MOV$cond   $srcreg, pc
        ORR$cond   $regtmp, $srcreg, #$bits
Neil Turton's avatar
Neil Turton committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        TEQ$cond.P $regtmp, #0
        MEND

; **************************************************
; ***  SETV - Set overflow flag - will set NzcV  ***
; **************************************************
        MACRO
$label  SETV    $cond
$label  CMP$cond pc, #&80000000
        MEND

; ***********************************************
; ***  TOGPSR - Toggle bits in PSR from the   ***
; ***  mask in $bits, using register $regtmp  ***
; ***********************************************
        MACRO
397 398 399 400 401 402 403 404 405
$label  TOGPSR  $bits, $regtmp, $cond, $oldpsr
        LCLS    srcreg
        [ "$oldpsr"=""
srcreg  SETS    "$regtmp"
        |
srcreg  SETS    "$oldpsr"
        ]
$label  MOV$cond   $srcreg, pc
        TEQ$cond.P $srcreg, #$bits
Neil Turton's avatar
Neil Turton committed
406 407
        MEND

Stewart Brodie's avatar
Stewart Brodie committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421
; ***********************************************
; ***  TOGPSRR - Toggle bits in PSR from the  ***
; ***  mask in $regtog, using reg $regtmp     ***
; ***********************************************
        MACRO
$label  TOGPSRR $regtog, $regtmp, $cond, $oldpsr, $fields
        [ "$oldpsr"<>""
$label  MOV$cond   $oldpsr, pc
        TEQ$cond.P $regtog, pc
        |
$label  TEQ$cond.P $regtog, pc
        ]
        MEND

422 423 424 425 426 427 428 429 430 431
; *************************************************
; ***  WritePSRc - Set the PSR control bits to  ***
; ***  an absolute value.                       ***
; ***  Sets I,F,M[0:1], corrupts NZVC.          ***
; ***  Preserves 32-bitness.                    ***
; ***  Only use in IRQ26/32,FIQ26/32,SVC26/32   ***
; ***  Ignored in USR modes, illegal in others  ***
; ***  Use instead of TEQP PC,#$value           ***
; *************************************************
        MACRO
432
$label  WritePSRc $value, $regtmp, $cond, $oldpsr
433 434 435
      [ ($value :AND::NOT: (I_bit+F_bit+SVC_mode)) <> 0
        ! 1, "Illegal flags for WritePSRc"
      ]
436 437 438
 [ "$oldpsr" <> ""
        SavePSR $oldpsr, $cond
 ]
439
$label  TEQ$cond.P PC, #$value
440 441
        MEND

442 443 444 445 446 447 448
 ] ; No32bitCode

; *************************************************
; ***  RemovePSRFromReg - remove PSR bits from  ***
; ***  a PC (or register holding a PC, eg. lr)  ***
; ***  Preserves all PSR bits                   ***
; *************************************************
449 450
        MACRO
$label  RemovePSRFromReg $pcr, $tmp, $dest
451
        ; If $dest is supplied, it denotes an alternative target
452 453 454 455 456 457 458 459 460
        ; register from $pcr.  $dest and $tmp may be the same register.
        ;
        ; MRS is safe as it is a NOP if the processor doesn't understand it. The code
        ; takes bit 4 of the CPSR (always set in 32-bit modes, always clear in 26-bit
        ; modes), shifts it to the bottom bit and inverts it, then shifts it to the
        ; top bit so it can use ASR to duplicate it into 8 bits, and then ROR#30 to
        ; turn it into &FC000003 if you are in a 26-bit bit, 0 if you are in 32-bit
        ; mode. This value can be BIC'ed with lr to strip the PSR bits if they are
        ; there, or be a NOP if they are not.
461 462 463 464
        ;
        ; Must be in a known mode (currently USR26,USR32,IRQ26,IRQ32,FIQ26,FIQ32,
        ; SVC26,SVC32,ABT32,UND32,SYS32) - future modes may have bit 4 clear, yet
        ; they won't be 26-bit.
465 466 467 468 469 470 471 472 473
        ASSERT (1 :SHL: 4) = (USR32_mode - USR26_mode)
$label
        LCLS    dst
        [ "$dest" <> ""
dst SETS "$dest"
        |
dst SETS "$pcr"
        ]
        [ No32bitCode
474
        BIC     $dst, $pcr, #ARM_CC_Mask  ; 32-bit OK: inside No32bitCode macro
475 476 477 478 479 480 481 482 483 484 485 486
        |
        MRS     $tmp, CPSR
        MVN     $tmp, $tmp, LSR #4        ; bit 0 set in *26, clear in *32
        MOV     $tmp, $tmp, LSL #31       ; shift to top bit
        MOV     $tmp, $tmp, ASR #7        ; duplicate to top 8 bits
        BIC     $dst, $pcr, $tmp, ROR #30 ; remove PSR bits if in 26-bit mode
        ]
        MEND


 ] ; :LNOT: :DEF: Included_Hdr_CPU_Generic26

Neil Turton's avatar
Neil Turton committed
487 488
        OPT     OldOpt
        END
489