Home | History | Annotate | Line # | Download | only in arm32
frame.h revision 1.6
      1 /*	$NetBSD: frame.h,v 1.6 2003/10/23 08:59:10 scw Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994-1997 Mark Brinicombe.
      5  * Copyright (c) 1994 Brini.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software written for Brini by Mark Brinicombe
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by Brini.
     21  * 4. The name of the company nor the name of the author may be used to
     22  *    endorse or promote products derived from this software without specific
     23  *    prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  * RiscBSD kernel project
     38  *
     39  * frame.h
     40  *
     41  * Stack frames structures
     42  *
     43  * Created      : 30/09/94
     44  */
     45 
     46 #ifndef _ARM32_FRAME_H_
     47 #define _ARM32_FRAME_H_
     48 
     49 #include <arm/frame.h>		/* Common ARM stack frames */
     50 
     51 #ifndef _LOCORE
     52 
     53 /*
     54  * System stack frames.
     55  */
     56 
     57 typedef struct irqframe {
     58 	unsigned int if_spsr;
     59 	unsigned int if_r0;
     60 	unsigned int if_r1;
     61 	unsigned int if_r2;
     62 	unsigned int if_r3;
     63 	unsigned int if_r4;
     64 	unsigned int if_r5;
     65 	unsigned int if_r6;
     66 	unsigned int if_r7;
     67 	unsigned int if_r8;
     68 	unsigned int if_r9;
     69 	unsigned int if_r10;
     70 	unsigned int if_r11;
     71 	unsigned int if_r12;
     72 	unsigned int if_usr_sp;
     73 	unsigned int if_usr_lr;
     74 	unsigned int if_svc_sp;
     75 	unsigned int if_svc_lr;
     76 	unsigned int if_pc;
     77 } irqframe_t;
     78 
     79 #define clockframe irqframe
     80 
     81 /*
     82  * Switch frame
     83  */
     84 
     85 struct switchframe {
     86 	u_int	sf_r4;
     87 	u_int	sf_r5;
     88 	u_int	sf_r6;
     89 	u_int	sf_r7;
     90 	u_int	sf_pc;
     91 };
     92 
     93 /*
     94  * Stack frame. Used during stack traces (db_trace.c)
     95  */
     96 struct frame {
     97 	u_int	fr_fp;
     98 	u_int	fr_sp;
     99 	u_int	fr_lr;
    100 	u_int	fr_pc;
    101 };
    102 
    103 #ifdef _KERNEL
    104 void validate_trapframe __P((trapframe_t *, int));
    105 #endif /* _KERNEL */
    106 
    107 #else /* _LOCORE */
    108 
    109 /*
    110  * ASM macros for pushing and pulling trapframes from the stack
    111  *
    112  * These macros are used to handle the irqframe and trapframe structures
    113  * defined above.
    114  */
    115 
    116 /*
    117  * PUSHFRAME - macro to push a trap frame on the stack in the current mode
    118  * Since the current mode is used, the SVC lr field is not defined.
    119  *
    120  * NOTE: r13 and r14 are stored separately as a work around for the
    121  * SA110 rev 2 STM^ bug
    122  */
    123 
    124 #define PUSHFRAME							   \
    125 	str	lr, [sp, #-4]!;		/* Push the return address */	   \
    126 	sub	sp, sp, #(4*17);	/* Adjust the stack pointer */	   \
    127 	stmia	sp, {r0-r12};		/* Push the user mode registers */ \
    128 	add	r0, sp, #(4*13);	/* Adjust the stack pointer */	   \
    129 	stmia	r0, {r13-r14}^;		/* Push the user mode registers */ \
    130         mov     r0, r0;                 /* NOP for previous instruction */ \
    131 	mrs	r0, spsr_all;		/* Put the SPSR on the stack */	   \
    132 	str	r0, [sp, #-4]!;
    133 
    134 /*
    135  * PULLFRAME - macro to pull a trap frame from the stack in the current mode
    136  * Since the current mode is used, the SVC lr field is ignored.
    137  */
    138 
    139 #define PULLFRAME							   \
    140         ldr     r0, [sp], #0x0004;      /* Get the SPSR from stack */	   \
    141         msr     spsr_all, r0;						   \
    142         ldmia   sp, {r0-r14}^;		/* Restore registers (usr mode) */ \
    143         mov     r0, r0;                 /* NOP for previous instruction */ \
    144 	add	sp, sp, #(4*17);	/* Adjust the stack pointer */	   \
    145  	ldr	lr, [sp], #0x0004;	/* Pull the return address */
    146 
    147 /*
    148  * PUSHFRAMEINSVC - macro to push a trap frame on the stack in SVC32 mode
    149  * This should only be used if the processor is not currently in SVC32
    150  * mode. The processor mode is switched to SVC mode and the trap frame is
    151  * stored. The SVC lr field is used to store the previous value of
    152  * lr in SVC mode.
    153  *
    154  * NOTE: r13 and r14 are stored separately as a work around for the
    155  * SA110 rev 2 STM^ bug
    156  */
    157 
    158 #define PUSHFRAMEINSVC							   \
    159 	stmdb	sp, {r0-r3};		/* Save 4 registers */		   \
    160 	mov	r0, lr;			/* Save xxx32 r14 */		   \
    161 	mov	r1, sp;			/* Save xxx32 sp */		   \
    162 	mrs	r3, spsr;		/* Save xxx32 spsr */		   \
    163 	mrs     r2, cpsr; 		/* Get the CPSR */		   \
    164 	bic     r2, r2, #(PSR_MODE);	/* Fix for SVC mode */		   \
    165 	orr     r2, r2, #(PSR_SVC32_MODE);				   \
    166 	msr     cpsr_c, r2;		/* Punch into SVC mode */	   \
    167 	mov	r2, sp;			/* Save	SVC sp */		   \
    168 	str	r0, [sp, #-4]!;		/* Push return address */	   \
    169 	str	lr, [sp, #-4]!;		/* Push SVC lr */		   \
    170 	str	r2, [sp, #-4]!;		/* Push SVC sp */		   \
    171 	msr     spsr_all, r3;		/* Restore correct spsr */	   \
    172 	ldmdb	r1, {r0-r3};		/* Restore 4 regs from xxx mode */ \
    173 	sub	sp, sp, #(4*15);	/* Adjust the stack pointer */	   \
    174 	stmia	sp, {r0-r12};		/* Push the user mode registers */ \
    175 	add	r0, sp, #(4*13);	/* Adjust the stack pointer */	   \
    176 	stmia	r0, {r13-r14}^;		/* Push the user mode registers */ \
    177         mov     r0, r0;                 /* NOP for previous instruction */ \
    178 	mrs	r0, spsr_all;		/* Put the SPSR on the stack */	   \
    179 	str	r0, [sp, #-4]!
    180 
    181 /*
    182  * PULLFRAMEFROMSVCANDEXIT - macro to pull a trap frame from the stack
    183  * in SVC32 mode and restore the saved processor mode and PC.
    184  * This should be used when the SVC lr register needs to be restored on
    185  * exit.
    186  */
    187 
    188 #define PULLFRAMEFROMSVCANDEXIT						   \
    189         ldr     r0, [sp], #0x0004;	/* Get the SPSR from stack */	   \
    190         msr     spsr_all, r0;		/* restore SPSR */		   \
    191         ldmia   sp, {r0-r14}^;		/* Restore registers (usr mode) */ \
    192         mov     r0, r0;	  		/* NOP for previous instruction */ \
    193 	add	sp, sp, #(4*15);	/* Adjust the stack pointer */	   \
    194 	ldmia	sp, {sp, lr, pc}^	/* Restore lr and exit */
    195 
    196 #endif /* _LOCORE */
    197 
    198 #endif /* _ARM32_FRAME_H_ */
    199 
    200 /* End of frame.h */
    201