···11+/*22+ * Macro used to simplify coding multi-line assembler.33+ * Some of the bit test macro can simplify down to one line44+ * depending on the mask value.55+ *66+ * Copyright (C) 2004 Microtronix Datacom Ltd.77+ *88+ * All rights reserved.99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of the GNU General Public License as published by1212+ * the Free Software Foundation; either version 2 of the License, or1313+ * (at your option) any later version.1414+ *1515+ * This program is distributed in the hope that it will be useful, but1616+ * WITHOUT ANY WARRANTY; without even the implied warranty of1717+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or1818+ * NON INFRINGEMENT. See the GNU General Public License for more1919+ * details.2020+ *2121+ */2222+#ifndef _ASM_NIOS2_ASMMACROS_H2323+#define _ASM_NIOS2_ASMMACROS_H2424+/*2525+ * ANDs reg2 with mask and places the result in reg1.2626+ *2727+ * You cannnot use the same register for reg1 & reg2.2828+ */2929+3030+.macro ANDI32 reg1, reg2, mask3131+.if \mask & 0xffff3232+ .if \mask & 0xffff00003333+ movhi \reg1, %hi(\mask)3434+ movui \reg1, %lo(\mask)3535+ and \reg1, \reg1, \reg23636+ .else3737+ andi \reg1, \reg2, %lo(\mask)3838+ .endif3939+.else4040+ andhi \reg1, \reg2, %hi(\mask)4141+.endif4242+.endm4343+4444+/*4545+ * ORs reg2 with mask and places the result in reg1.4646+ *4747+ * It is safe to use the same register for reg1 & reg2.4848+ */4949+5050+.macro ORI32 reg1, reg2, mask5151+.if \mask & 0xffff5252+ .if \mask & 0xffff00005353+ orhi \reg1, \reg2, %hi(\mask)5454+ ori \reg1, \reg2, %lo(\mask)5555+ .else5656+ ori \reg1, \reg2, %lo(\mask)5757+ .endif5858+.else5959+ orhi \reg1, \reg2, %hi(\mask)6060+.endif6161+.endm6262+6363+/*6464+ * XORs reg2 with mask and places the result in reg1.6565+ *6666+ * It is safe to use the same register for reg1 & reg2.6767+ */6868+6969+.macro XORI32 reg1, reg2, mask7070+.if \mask & 0xffff7171+ .if \mask & 0xffff00007272+ xorhi \reg1, \reg2, %hi(\mask)7373+ xori \reg1, \reg1, %lo(\mask)7474+ .else7575+ xori \reg1, \reg2, %lo(\mask)7676+ .endif7777+.else7878+ xorhi \reg1, \reg2, %hi(\mask)7979+.endif8080+.endm8181+8282+/*8383+ * This is a support macro for BTBZ & BTBNZ. It checks8484+ * the bit to make sure it is valid 32 value.8585+ *8686+ * It is safe to use the same register for reg1 & reg2.8787+ */8888+8989+.macro BT reg1, reg2, bit9090+.if \bit > 319191+ .err9292+.else9393+ .if \bit < 169494+ andi \reg1, \reg2, (1 << \bit)9595+ .else9696+ andhi \reg1, \reg2, (1 << (\bit - 16))9797+ .endif9898+.endif9999+.endm100100+101101+/*102102+ * Tests the bit in reg2 and branches to label if the103103+ * bit is zero. The result of the bit test is stored in reg1.104104+ *105105+ * It is safe to use the same register for reg1 & reg2.106106+ */107107+108108+.macro BTBZ reg1, reg2, bit, label109109+ BT \reg1, \reg2, \bit110110+ beq \reg1, r0, \label111111+.endm112112+113113+/*114114+ * Tests the bit in reg2 and branches to label if the115115+ * bit is non-zero. The result of the bit test is stored in reg1.116116+ *117117+ * It is safe to use the same register for reg1 & reg2.118118+ */119119+120120+.macro BTBNZ reg1, reg2, bit, label121121+ BT \reg1, \reg2, \bit122122+ bne \reg1, r0, \label123123+.endm124124+125125+/*126126+ * Tests the bit in reg2 and then compliments the bit in reg2.127127+ * The result of the bit test is stored in reg1.128128+ *129129+ * It is NOT safe to use the same register for reg1 & reg2.130130+ */131131+132132+.macro BTC reg1, reg2, bit133133+.if \bit > 31134134+ .err135135+.else136136+ .if \bit < 16137137+ andi \reg1, \reg2, (1 << \bit)138138+ xori \reg2, \reg2, (1 << \bit)139139+ .else140140+ andhi \reg1, \reg2, (1 << (\bit - 16))141141+ xorhi \reg2, \reg2, (1 << (\bit - 16))142142+ .endif143143+.endif144144+.endm145145+146146+/*147147+ * Tests the bit in reg2 and then sets the bit in reg2.148148+ * The result of the bit test is stored in reg1.149149+ *150150+ * It is NOT safe to use the same register for reg1 & reg2.151151+ */152152+153153+.macro BTS reg1, reg2, bit154154+.if \bit > 31155155+ .err156156+.else157157+ .if \bit < 16158158+ andi \reg1, \reg2, (1 << \bit)159159+ ori \reg2, \reg2, (1 << \bit)160160+ .else161161+ andhi \reg1, \reg2, (1 << (\bit - 16))162162+ orhi \reg2, \reg2, (1 << (\bit - 16))163163+ .endif164164+.endif165165+.endm166166+167167+/*168168+ * Tests the bit in reg2 and then resets the bit in reg2.169169+ * The result of the bit test is stored in reg1.170170+ *171171+ * It is NOT safe to use the same register for reg1 & reg2.172172+ */173173+174174+.macro BTR reg1, reg2, bit175175+.if \bit > 31176176+ .err177177+.else178178+ .if \bit < 16179179+ andi \reg1, \reg2, (1 << \bit)180180+ andi \reg2, \reg2, %lo(~(1 << \bit))181181+ .else182182+ andhi \reg1, \reg2, (1 << (\bit - 16))183183+ andhi \reg2, \reg2, %lo(~(1 << (\bit - 16)))184184+ .endif185185+.endif186186+.endm187187+188188+/*189189+ * Tests the bit in reg2 and then compliments the bit in reg2.190190+ * The result of the bit test is stored in reg1. If the191191+ * original bit was zero it branches to label.192192+ *193193+ * It is NOT safe to use the same register for reg1 & reg2.194194+ */195195+196196+.macro BTCBZ reg1, reg2, bit, label197197+ BTC \reg1, \reg2, \bit198198+ beq \reg1, r0, \label199199+.endm200200+201201+/*202202+ * Tests the bit in reg2 and then compliments the bit in reg2.203203+ * The result of the bit test is stored in reg1. If the204204+ * original bit was non-zero it branches to label.205205+ *206206+ * It is NOT safe to use the same register for reg1 & reg2.207207+ */208208+209209+.macro BTCBNZ reg1, reg2, bit, label210210+ BTC \reg1, \reg2, \bit211211+ bne \reg1, r0, \label212212+.endm213213+214214+/*215215+ * Tests the bit in reg2 and then sets the bit in reg2.216216+ * The result of the bit test is stored in reg1. If the217217+ * original bit was zero it branches to label.218218+ *219219+ * It is NOT safe to use the same register for reg1 & reg2.220220+ */221221+222222+.macro BTSBZ reg1, reg2, bit, label223223+ BTS \reg1, \reg2, \bit224224+ beq \reg1, r0, \label225225+.endm226226+227227+/*228228+ * Tests the bit in reg2 and then sets the bit in reg2.229229+ * The result of the bit test is stored in reg1. If the230230+ * original bit was non-zero it branches to label.231231+ *232232+ * It is NOT safe to use the same register for reg1 & reg2.233233+ */234234+235235+.macro BTSBNZ reg1, reg2, bit, label236236+ BTS \reg1, \reg2, \bit237237+ bne \reg1, r0, \label238238+.endm239239+240240+/*241241+ * Tests the bit in reg2 and then resets the bit in reg2.242242+ * The result of the bit test is stored in reg1. If the243243+ * original bit was zero it branches to label.244244+ *245245+ * It is NOT safe to use the same register for reg1 & reg2.246246+ */247247+248248+.macro BTRBZ reg1, reg2, bit, label249249+ BTR \reg1, \reg2, \bit250250+ bne \reg1, r0, \label251251+.endm252252+253253+/*254254+ * Tests the bit in reg2 and then resets the bit in reg2.255255+ * The result of the bit test is stored in reg1. If the256256+ * original bit was non-zero it branches to label.257257+ *258258+ * It is NOT safe to use the same register for reg1 & reg2.259259+ */260260+261261+.macro BTRBNZ reg1, reg2, bit, label262262+ BTR \reg1, \reg2, \bit263263+ bne \reg1, r0, \label264264+.endm265265+266266+/*267267+ * Tests the bits in mask against reg2 stores the result in reg1.268268+ * If the all the bits in the mask are zero it branches to label.269269+ *270270+ * It is safe to use the same register for reg1 & reg2.271271+ */272272+273273+.macro TSTBZ reg1, reg2, mask, label274274+ ANDI32 \reg1, \reg2, \mask275275+ beq \reg1, r0, \label276276+.endm277277+278278+/*279279+ * Tests the bits in mask against reg2 stores the result in reg1.280280+ * If the any of the bits in the mask are 1 it branches to label.281281+ *282282+ * It is safe to use the same register for reg1 & reg2.283283+ */284284+285285+.macro TSTBNZ reg1, reg2, mask, label286286+ ANDI32 \reg1, \reg2, \mask287287+ bne \reg1, r0, \label288288+.endm289289+290290+/*291291+ * Pushes reg onto the stack.292292+ */293293+294294+.macro PUSH reg295295+ addi sp, sp, -4296296+ stw \reg, 0(sp)297297+.endm298298+299299+/*300300+ * Pops the top of the stack into reg.301301+ */302302+303303+.macro POP reg304304+ ldw \reg, 0(sp)305305+ addi sp, sp, 4306306+.endm307307+308308+309309+#endif /* _ASM_NIOS2_ASMMACROS_H */
+20
arch/nios2/include/asm/asm-offsets.h
···11+/*22+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>33+ * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>44+ *55+ * This program is free software; you can redistribute it and/or modify66+ * it under the terms of the GNU General Public License as published by77+ * the Free Software Foundation; either version 2 of the License, or88+ * (at your option) any later version.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1717+ *1818+ */1919+2020+#include <generated/asm-offsets.h>
+88
arch/nios2/kernel/asm-offsets.c
···11+/*22+ * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License1515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1616+ *1717+ */1818+1919+#include <linux/stddef.h>2020+#include <linux/sched.h>2121+#include <linux/kernel_stat.h>2222+#include <linux/ptrace.h>2323+#include <linux/hardirq.h>2424+#include <linux/thread_info.h>2525+#include <linux/kbuild.h>2626+2727+int main(void)2828+{2929+ /* struct task_struct */3030+ OFFSET(TASK_THREAD, task_struct, thread);3131+ BLANK();3232+3333+ /* struct thread_struct */3434+ OFFSET(THREAD_KSP, thread_struct, ksp);3535+ OFFSET(THREAD_KPSR, thread_struct, kpsr);3636+ BLANK();3737+3838+ /* struct pt_regs */3939+ OFFSET(PT_ORIG_R2, pt_regs, orig_r2);4040+ OFFSET(PT_ORIG_R7, pt_regs, orig_r7);4141+4242+ OFFSET(PT_R1, pt_regs, r1);4343+ OFFSET(PT_R2, pt_regs, r2);4444+ OFFSET(PT_R3, pt_regs, r3);4545+ OFFSET(PT_R4, pt_regs, r4);4646+ OFFSET(PT_R5, pt_regs, r5);4747+ OFFSET(PT_R6, pt_regs, r6);4848+ OFFSET(PT_R7, pt_regs, r7);4949+ OFFSET(PT_R8, pt_regs, r8);5050+ OFFSET(PT_R9, pt_regs, r9);5151+ OFFSET(PT_R10, pt_regs, r10);5252+ OFFSET(PT_R11, pt_regs, r11);5353+ OFFSET(PT_R12, pt_regs, r12);5454+ OFFSET(PT_R13, pt_regs, r13);5555+ OFFSET(PT_R14, pt_regs, r14);5656+ OFFSET(PT_R15, pt_regs, r15);5757+ OFFSET(PT_EA, pt_regs, ea);5858+ OFFSET(PT_RA, pt_regs, ra);5959+ OFFSET(PT_FP, pt_regs, fp);6060+ OFFSET(PT_SP, pt_regs, sp);6161+ OFFSET(PT_GP, pt_regs, gp);6262+ OFFSET(PT_ESTATUS, pt_regs, estatus);6363+ DEFINE(PT_REGS_SIZE, sizeof(struct pt_regs));6464+ BLANK();6565+6666+ /* struct switch_stack */6767+ OFFSET(SW_R16, switch_stack, r16);6868+ OFFSET(SW_R17, switch_stack, r17);6969+ OFFSET(SW_R18, switch_stack, r18);7070+ OFFSET(SW_R19, switch_stack, r19);7171+ OFFSET(SW_R20, switch_stack, r20);7272+ OFFSET(SW_R21, switch_stack, r21);7373+ OFFSET(SW_R22, switch_stack, r22);7474+ OFFSET(SW_R23, switch_stack, r23);7575+ OFFSET(SW_FP, switch_stack, fp);7676+ OFFSET(SW_GP, switch_stack, gp);7777+ OFFSET(SW_RA, switch_stack, ra);7878+ DEFINE(SWITCH_STACK_SIZE, sizeof(struct switch_stack));7979+ BLANK();8080+8181+ /* struct thread_info */8282+ OFFSET(TI_TASK, thread_info, task);8383+ OFFSET(TI_FLAGS, thread_info, flags);8484+ OFFSET(TI_PREEMPT_COUNT, thread_info, preempt_count);8585+ BLANK();8686+8787+ return 0;8888+}