/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Macro used to simplify coding multi-line assembler.3* Some of the bit test macro can simplify down to one line4* depending on the mask value.5*6* Copyright (C) 2004 Microtronix Datacom Ltd.7*8* All rights reserved.9*/10#ifndef _ASM_NIOS2_ASMMACROS_H11#define _ASM_NIOS2_ASMMACROS_H12/*13* ANDs reg2 with mask and places the result in reg1.14*15* You cannnot use the same register for reg1 & reg2.16*/1718.macro ANDI32 reg1, reg2, mask19.if \mask & 0xffff20.if \mask & 0xffff000021movhi \reg1, %hi(\mask)22movui \reg1, %lo(\mask)23and \reg1, \reg1, \reg224.else25andi \reg1, \reg2, %lo(\mask)26.endif27.else28andhi \reg1, \reg2, %hi(\mask)29.endif30.endm3132/*33* ORs reg2 with mask and places the result in reg1.34*35* It is safe to use the same register for reg1 & reg2.36*/3738.macro ORI32 reg1, reg2, mask39.if \mask & 0xffff40.if \mask & 0xffff000041orhi \reg1, \reg2, %hi(\mask)42ori \reg1, \reg2, %lo(\mask)43.else44ori \reg1, \reg2, %lo(\mask)45.endif46.else47orhi \reg1, \reg2, %hi(\mask)48.endif49.endm5051/*52* XORs reg2 with mask and places the result in reg1.53*54* It is safe to use the same register for reg1 & reg2.55*/5657.macro XORI32 reg1, reg2, mask58.if \mask & 0xffff59.if \mask & 0xffff000060xorhi \reg1, \reg2, %hi(\mask)61xori \reg1, \reg1, %lo(\mask)62.else63xori \reg1, \reg2, %lo(\mask)64.endif65.else66xorhi \reg1, \reg2, %hi(\mask)67.endif68.endm6970/*71* This is a support macro for BTBZ & BTBNZ. It checks72* the bit to make sure it is valid 32 value.73*74* It is safe to use the same register for reg1 & reg2.75*/7677.macro BT reg1, reg2, bit78.if \bit > 3179.err80.else81.if \bit < 1682andi \reg1, \reg2, (1 << \bit)83.else84andhi \reg1, \reg2, (1 << (\bit - 16))85.endif86.endif87.endm8889/*90* Tests the bit in reg2 and branches to label if the91* bit is zero. The result of the bit test is stored in reg1.92*93* It is safe to use the same register for reg1 & reg2.94*/9596.macro BTBZ reg1, reg2, bit, label97BT \reg1, \reg2, \bit98beq \reg1, r0, \label99.endm100101/*102* Tests the bit in reg2 and branches to label if the103* bit is non-zero. The result of the bit test is stored in reg1.104*105* It is safe to use the same register for reg1 & reg2.106*/107108.macro BTBNZ reg1, reg2, bit, label109BT \reg1, \reg2, \bit110bne \reg1, r0, \label111.endm112113/*114* Tests the bit in reg2 and then compliments the bit in reg2.115* The result of the bit test is stored in reg1.116*117* It is NOT safe to use the same register for reg1 & reg2.118*/119120.macro BTC reg1, reg2, bit121.if \bit > 31122.err123.else124.if \bit < 16125andi \reg1, \reg2, (1 << \bit)126xori \reg2, \reg2, (1 << \bit)127.else128andhi \reg1, \reg2, (1 << (\bit - 16))129xorhi \reg2, \reg2, (1 << (\bit - 16))130.endif131.endif132.endm133134/*135* Tests the bit in reg2 and then sets the bit in reg2.136* The result of the bit test is stored in reg1.137*138* It is NOT safe to use the same register for reg1 & reg2.139*/140141.macro BTS reg1, reg2, bit142.if \bit > 31143.err144.else145.if \bit < 16146andi \reg1, \reg2, (1 << \bit)147ori \reg2, \reg2, (1 << \bit)148.else149andhi \reg1, \reg2, (1 << (\bit - 16))150orhi \reg2, \reg2, (1 << (\bit - 16))151.endif152.endif153.endm154155/*156* Tests the bit in reg2 and then resets the bit in reg2.157* The result of the bit test is stored in reg1.158*159* It is NOT safe to use the same register for reg1 & reg2.160*/161162.macro BTR reg1, reg2, bit163.if \bit > 31164.err165.else166.if \bit < 16167andi \reg1, \reg2, (1 << \bit)168andi \reg2, \reg2, %lo(~(1 << \bit))169.else170andhi \reg1, \reg2, (1 << (\bit - 16))171andhi \reg2, \reg2, %lo(~(1 << (\bit - 16)))172.endif173.endif174.endm175176/*177* Tests the bit in reg2 and then compliments the bit in reg2.178* The result of the bit test is stored in reg1. If the179* original bit was zero it branches to label.180*181* It is NOT safe to use the same register for reg1 & reg2.182*/183184.macro BTCBZ reg1, reg2, bit, label185BTC \reg1, \reg2, \bit186beq \reg1, r0, \label187.endm188189/*190* Tests the bit in reg2 and then compliments the bit in reg2.191* The result of the bit test is stored in reg1. If the192* original bit was non-zero it branches to label.193*194* It is NOT safe to use the same register for reg1 & reg2.195*/196197.macro BTCBNZ reg1, reg2, bit, label198BTC \reg1, \reg2, \bit199bne \reg1, r0, \label200.endm201202/*203* Tests the bit in reg2 and then sets the bit in reg2.204* The result of the bit test is stored in reg1. If the205* original bit was zero it branches to label.206*207* It is NOT safe to use the same register for reg1 & reg2.208*/209210.macro BTSBZ reg1, reg2, bit, label211BTS \reg1, \reg2, \bit212beq \reg1, r0, \label213.endm214215/*216* Tests the bit in reg2 and then sets the bit in reg2.217* The result of the bit test is stored in reg1. If the218* original bit was non-zero it branches to label.219*220* It is NOT safe to use the same register for reg1 & reg2.221*/222223.macro BTSBNZ reg1, reg2, bit, label224BTS \reg1, \reg2, \bit225bne \reg1, r0, \label226.endm227228/*229* Tests the bit in reg2 and then resets the bit in reg2.230* The result of the bit test is stored in reg1. If the231* original bit was zero it branches to label.232*233* It is NOT safe to use the same register for reg1 & reg2.234*/235236.macro BTRBZ reg1, reg2, bit, label237BTR \reg1, \reg2, \bit238bne \reg1, r0, \label239.endm240241/*242* Tests the bit in reg2 and then resets the bit in reg2.243* The result of the bit test is stored in reg1. If the244* original bit was non-zero it branches to label.245*246* It is NOT safe to use the same register for reg1 & reg2.247*/248249.macro BTRBNZ reg1, reg2, bit, label250BTR \reg1, \reg2, \bit251bne \reg1, r0, \label252.endm253254/*255* Tests the bits in mask against reg2 stores the result in reg1.256* If the all the bits in the mask are zero it branches to label.257*258* It is safe to use the same register for reg1 & reg2.259*/260261.macro TSTBZ reg1, reg2, mask, label262ANDI32 \reg1, \reg2, \mask263beq \reg1, r0, \label264.endm265266/*267* Tests the bits in mask against reg2 stores the result in reg1.268* If the any of the bits in the mask are 1 it branches to label.269*270* It is safe to use the same register for reg1 & reg2.271*/272273.macro TSTBNZ reg1, reg2, mask, label274ANDI32 \reg1, \reg2, \mask275bne \reg1, r0, \label276.endm277278/*279* Pushes reg onto the stack.280*/281282.macro PUSH reg283addi sp, sp, -4284stw \reg, 0(sp)285.endm286287/*288* Pops the top of the stack into reg.289*/290291.macro POP reg292ldw \reg, 0(sp)293addi sp, sp, 4294.endm295296297#endif /* _ASM_NIOS2_ASMMACROS_H */298299300