Home | History | Annotate | Line # | Download | only in arm32
cpuswitch.S revision 1.3.2.5
      1  1.3.2.5  nathanw /*	$NetBSD: cpuswitch.S,v 1.3.2.5 2002/02/28 04:07:21 nathanw Exp $	*/
      2  1.3.2.2  thorpej 
      3  1.3.2.2  thorpej /*
      4  1.3.2.2  thorpej  * Copyright (c) 1994-1998 Mark Brinicombe.
      5  1.3.2.2  thorpej  * Copyright (c) 1994 Brini.
      6  1.3.2.2  thorpej  * All rights reserved.
      7  1.3.2.2  thorpej  *
      8  1.3.2.2  thorpej  * This code is derived from software written for Brini by Mark Brinicombe
      9  1.3.2.2  thorpej  *
     10  1.3.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.3.2.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.3.2.2  thorpej  * are met:
     13  1.3.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.3.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.3.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.3.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.3.2.2  thorpej  *    must display the following acknowledgement:
     20  1.3.2.2  thorpej  *	This product includes software developed by Brini.
     21  1.3.2.2  thorpej  * 4. The name of the company nor the name of the author may be used to
     22  1.3.2.2  thorpej  *    endorse or promote products derived from this software without specific
     23  1.3.2.2  thorpej  *    prior written permission.
     24  1.3.2.2  thorpej  *
     25  1.3.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26  1.3.2.2  thorpej  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27  1.3.2.2  thorpej  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.3.2.2  thorpej  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29  1.3.2.2  thorpej  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30  1.3.2.2  thorpej  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31  1.3.2.2  thorpej  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.3.2.2  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.3.2.2  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.3.2.2  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.3.2.2  thorpej  * SUCH DAMAGE.
     36  1.3.2.2  thorpej  *
     37  1.3.2.2  thorpej  * RiscBSD kernel project
     38  1.3.2.2  thorpej  *
     39  1.3.2.2  thorpej  * cpuswitch.S
     40  1.3.2.2  thorpej  *
     41  1.3.2.2  thorpej  * cpu switching functions
     42  1.3.2.2  thorpej  *
     43  1.3.2.2  thorpej  * Created      : 15/10/94
     44  1.3.2.2  thorpej  */
     45  1.3.2.2  thorpej 
     46  1.3.2.2  thorpej #include "opt_armfpe.h"
     47  1.3.2.2  thorpej 
     48  1.3.2.2  thorpej #include "assym.h"
     49  1.3.2.2  thorpej #include <machine/param.h>
     50  1.3.2.2  thorpej #include <machine/cpu.h>
     51  1.3.2.2  thorpej #include <machine/frame.h>
     52  1.3.2.2  thorpej #include <machine/asm.h>
     53  1.3.2.2  thorpej 
     54  1.3.2.2  thorpej #undef IRQdisable
     55  1.3.2.2  thorpej #undef IRQenable
     56  1.3.2.2  thorpej 
     57  1.3.2.2  thorpej /*
     58  1.3.2.2  thorpej  * New experimental definitions of IRQdisable and IRQenable
     59  1.3.2.2  thorpej  * These keep FIQ's enabled since FIQ's are special.
     60  1.3.2.2  thorpej  */
     61  1.3.2.2  thorpej 
     62  1.3.2.2  thorpej #define IRQdisable \
     63  1.3.2.2  thorpej 	mrs	r14, cpsr_all ; \
     64  1.3.2.2  thorpej 	orr	r14, r14, #(I32_bit) ; \
     65  1.3.2.2  thorpej 	msr	cpsr_all, r14 ; \
     66  1.3.2.2  thorpej 
     67  1.3.2.2  thorpej #define IRQenable \
     68  1.3.2.2  thorpej 	mrs	r14, cpsr_all ; \
     69  1.3.2.2  thorpej 	bic	r14, r14, #(I32_bit) ; \
     70  1.3.2.2  thorpej 	msr	cpsr_all, r14 ; \
     71  1.3.2.2  thorpej 
     72  1.3.2.2  thorpej /*
     73  1.3.2.2  thorpej  * setrunqueue() and remrunqueue()
     74  1.3.2.2  thorpej  *
     75  1.3.2.2  thorpej  * Functions to add and remove a process for the run queue.
     76  1.3.2.2  thorpej  */
     77  1.3.2.2  thorpej 
     78  1.3.2.2  thorpej 	.text
     79  1.3.2.2  thorpej 
     80  1.3.2.2  thorpej Lwhichqs:
     81  1.3.2.2  thorpej 	.word	_C_LABEL(sched_whichqs)
     82  1.3.2.2  thorpej 
     83  1.3.2.2  thorpej Lqs:
     84  1.3.2.2  thorpej 	.word	_C_LABEL(sched_qs)
     85  1.3.2.2  thorpej 
     86  1.3.2.2  thorpej /*
     87  1.3.2.2  thorpej  * On entry
     88  1.3.2.2  thorpej  *	r0 = lwp
     89  1.3.2.2  thorpej  */
     90  1.3.2.2  thorpej 
     91  1.3.2.2  thorpej ENTRY(setrunqueue)
     92  1.3.2.2  thorpej 	/*
     93  1.3.2.2  thorpej 	 * Local register usage
     94  1.3.2.2  thorpej 	 * 	r0 = process
     95  1.3.2.2  thorpej 	 * 	r1 = queue
     96  1.3.2.2  thorpej 	 * 	r2 = &qs[queue] and temp
     97  1.3.2.2  thorpej 	 * 	r3 = temp
     98  1.3.2.2  thorpej 	 *	r12 = whichqs
     99  1.3.2.2  thorpej 	 */
    100  1.3.2.2  thorpej #ifdef DIAGNOSTIC
    101  1.3.2.2  thorpej 	ldr	r1, [r0, #(L_BACK)]
    102  1.3.2.2  thorpej 	teq	r1, #0x00000000
    103  1.3.2.2  thorpej 	bne	Lsetrunqueue_erg
    104  1.3.2.2  thorpej 
    105  1.3.2.2  thorpej 	ldr	r1, [r0, #(L_WCHAN)]
    106  1.3.2.2  thorpej 	teq	r1, #0x00000000
    107  1.3.2.2  thorpej 	bne	Lsetrunqueue_erg
    108  1.3.2.2  thorpej #endif
    109  1.3.2.2  thorpej 
    110  1.3.2.2  thorpej 	/* Get the priority of the queue */
    111  1.3.2.2  thorpej 	ldrb	r1, [r0, #(L_PRIORITY)]
    112  1.3.2.2  thorpej 	mov	r1, r1, lsr #2
    113  1.3.2.2  thorpej 
    114  1.3.2.2  thorpej 	/* Indicate that there is a process on this queue */
    115  1.3.2.2  thorpej 	ldr	r12, Lwhichqs
    116  1.3.2.2  thorpej 	ldr	r2, [r12]
    117  1.3.2.2  thorpej 	mov	r3, #0x00000001
    118  1.3.2.2  thorpej 	mov	r3, r3, lsl r1
    119  1.3.2.2  thorpej 	orr	r2, r2, r3
    120  1.3.2.2  thorpej 	str	r2, [r12]
    121  1.3.2.2  thorpej 
    122  1.3.2.2  thorpej 	/* Get the address of the queue */
    123  1.3.2.2  thorpej 	ldr	r2, Lqs
    124  1.3.2.2  thorpej 	add	r1, r2, r1, lsl # 3
    125  1.3.2.2  thorpej 
    126  1.3.2.2  thorpej 	/* Hook the process in */
    127  1.3.2.2  thorpej 	str	r1, [r0, #(L_FORW)]
    128  1.3.2.2  thorpej 	ldr	r2, [r1, #(L_BACK)]
    129  1.3.2.2  thorpej 
    130  1.3.2.2  thorpej 	str	r0, [r1, #(L_BACK)]
    131  1.3.2.2  thorpej #ifdef DIAGNOSTIC
    132  1.3.2.2  thorpej 	teq	r2, #0x00000000
    133  1.3.2.2  thorpej 	beq	Lsetrunqueue_erg
    134  1.3.2.2  thorpej #endif
    135  1.3.2.2  thorpej 	str	r0, [r2, #(L_FORW)]
    136  1.3.2.2  thorpej 	str	r2, [r0, #(L_BACK)]
    137  1.3.2.2  thorpej 
    138  1.3.2.2  thorpej 	mov	pc, lr
    139  1.3.2.2  thorpej 
    140  1.3.2.2  thorpej #ifdef DIAGNOSTIC
    141  1.3.2.2  thorpej Lsetrunqueue_erg:
    142  1.3.2.2  thorpej 	mov	r2, r1
    143  1.3.2.2  thorpej 	mov	r1, r0
    144  1.3.2.2  thorpej 	add	r0, pc, #Ltext1 - . - 8
    145  1.3.2.2  thorpej 	bl	_C_LABEL(printf)
    146  1.3.2.2  thorpej 
    147  1.3.2.2  thorpej 	ldr	r2, Lqs
    148  1.3.2.2  thorpej 	ldr	r1, [r2]
    149  1.3.2.2  thorpej 	add	r0, pc, #Ltext2 - . - 8
    150  1.3.2.2  thorpej 	b	_C_LABEL(panic)
    151  1.3.2.2  thorpej 
    152  1.3.2.2  thorpej Ltext1:
    153  1.3.2.2  thorpej 	.asciz	"setrunqueue : %08x %08x\n"
    154  1.3.2.2  thorpej Ltext2:
    155  1.3.2.2  thorpej 	.asciz	"setrunqueue : [qs]=%08x qs=%08x\n"
    156  1.3.2.2  thorpej 	.align	0
    157  1.3.2.2  thorpej #endif
    158  1.3.2.2  thorpej 
    159  1.3.2.2  thorpej /*
    160  1.3.2.2  thorpej  * On entry
    161  1.3.2.2  thorpej  *	r0 = lwp
    162  1.3.2.2  thorpej  */
    163  1.3.2.2  thorpej 
    164  1.3.2.2  thorpej ENTRY(remrunqueue)
    165  1.3.2.2  thorpej 	/*
    166  1.3.2.2  thorpej 	 * Local register usage
    167  1.3.2.2  thorpej 	 *	r0 = oldproc
    168  1.3.2.2  thorpej 	 * 	r1 = queue
    169  1.3.2.2  thorpej 	 * 	r2 = &qs[queue] and scratch
    170  1.3.2.2  thorpej 	 *	r3 = scratch
    171  1.3.2.2  thorpej 	 *	r12 = whichqs
    172  1.3.2.2  thorpej 	 */
    173  1.3.2.2  thorpej 
    174  1.3.2.2  thorpej 	/* Get the priority of the queue */
    175  1.3.2.2  thorpej 	ldrb	r1, [r0, #(L_PRIORITY)]
    176  1.3.2.2  thorpej 	mov	r1, r1, lsr #2
    177  1.3.2.2  thorpej 
    178  1.3.2.2  thorpej 	/* Unhook the process */
    179  1.3.2.2  thorpej 	ldr	r2, [r0, #(L_FORW)]
    180  1.3.2.2  thorpej 	ldr	r3, [r0, #(L_BACK)]
    181  1.3.2.2  thorpej 
    182  1.3.2.2  thorpej 	str	r3, [r2, #(L_BACK)]
    183  1.3.2.2  thorpej 	str	r2, [r3, #(L_FORW)]
    184  1.3.2.2  thorpej 
    185  1.3.2.2  thorpej 	/* If the queue is now empty clear the queue not empty flag */
    186  1.3.2.2  thorpej 	teq	r2, r3
    187  1.3.2.2  thorpej 
    188  1.3.2.2  thorpej 	/* This could be reworked to avoid the use of r4 */
    189  1.3.2.2  thorpej 	ldreq	r12, Lwhichqs
    190  1.3.2.2  thorpej 	ldreq	r2, [r12]
    191  1.3.2.2  thorpej 	moveq	r3, #0x00000001
    192  1.3.2.2  thorpej 	moveq	r3, r3, lsl r1
    193  1.3.2.2  thorpej 	biceq	r2, r2, r3
    194  1.3.2.2  thorpej 	streq	r2, [r12]
    195  1.3.2.2  thorpej 
    196  1.3.2.2  thorpej 	/* Remove the back pointer for the process */
    197  1.3.2.2  thorpej 	mov	r1, #0x00000000
    198  1.3.2.2  thorpej 	str	r1, [r0, #(L_BACK)]
    199  1.3.2.2  thorpej 
    200  1.3.2.2  thorpej 	mov	pc, lr
    201  1.3.2.2  thorpej 
    202  1.3.2.2  thorpej 
    203  1.3.2.2  thorpej /*
    204  1.3.2.2  thorpej  * cpuswitch()
    205  1.3.2.2  thorpej  *
    206  1.3.2.2  thorpej  * preforms a process context switch.
    207  1.3.2.2  thorpej  * This function has several entry points
    208  1.3.2.2  thorpej  */
    209  1.3.2.2  thorpej 
    210  1.3.2.2  thorpej Lcurproc:
    211  1.3.2.2  thorpej 	.word	_C_LABEL(curproc)
    212  1.3.2.2  thorpej 
    213  1.3.2.2  thorpej Lcurpcb:
    214  1.3.2.2  thorpej 	.word	_C_LABEL(curpcb)
    215  1.3.2.2  thorpej 
    216  1.3.2.2  thorpej Lwant_resched:
    217  1.3.2.2  thorpej 	.word	_C_LABEL(want_resched)
    218  1.3.2.2  thorpej 
    219  1.3.2.2  thorpej Lcpufuncs:
    220  1.3.2.2  thorpej 	.word	_C_LABEL(cpufuncs)
    221  1.3.2.2  thorpej 
    222  1.3.2.2  thorpej 	.data
    223  1.3.2.2  thorpej 	.global	_C_LABEL(curpcb)
    224  1.3.2.2  thorpej _C_LABEL(curpcb):
    225  1.3.2.2  thorpej 	.word	0x00000000
    226  1.3.2.2  thorpej 	.text
    227  1.3.2.2  thorpej 
    228  1.3.2.2  thorpej Lblock_userspace_access:
    229  1.3.2.2  thorpej 	.word	_C_LABEL(block_userspace_access)
    230  1.3.2.2  thorpej 
    231  1.3.2.2  thorpej /*
    232  1.3.2.2  thorpej  * Idle loop, exercised while waiting for a process to wake up.
    233  1.3.2.2  thorpej  */
    234  1.3.2.4  nathanw ASENTRY_NP(idle)
    235  1.3.2.2  thorpej 	/* Enable interrupts */
    236  1.3.2.2  thorpej 	IRQenable
    237  1.3.2.2  thorpej 
    238  1.3.2.2  thorpej 	/* XXX - r1 needs to be preserved for cpu_switch */
    239  1.3.2.2  thorpej 	mov	r7, r1
    240  1.3.2.2  thorpej 	ldr	r3, Lcpufuncs
    241  1.3.2.2  thorpej 	mov	r0, #0
    242  1.3.2.2  thorpej 	add	lr, pc, #Lidle_slept - . - 8
    243  1.3.2.2  thorpej 	ldr	pc, [r3, #CF_SLEEP]
    244  1.3.2.2  thorpej 
    245  1.3.2.2  thorpej Lidle_slept:
    246  1.3.2.2  thorpej 	mov	r1, r7
    247  1.3.2.2  thorpej 
    248  1.3.2.2  thorpej 	/* Disable interrupts while we check for an active queue */
    249  1.3.2.2  thorpej 	IRQdisable
    250  1.3.2.2  thorpej 	ldr	r7, Lwhichqs
    251  1.3.2.2  thorpej 	ldr	r3, [r7]
    252  1.3.2.2  thorpej 	teq	r3, #0x00000000
    253  1.3.2.2  thorpej 	bne	sw1
    254  1.3.2.2  thorpej 
    255  1.3.2.2  thorpej 	/* All processes are still asleep so idle a while longer */
    256  1.3.2.4  nathanw 	b	_ASM_LABEL(idle)
    257  1.3.2.2  thorpej 
    258  1.3.2.2  thorpej 
    259  1.3.2.2  thorpej /*
    260  1.3.2.2  thorpej  * Find a new lwp to run, save the current context and
    261  1.3.2.2  thorpej  * load the new context
    262  1.3.2.2  thorpej  *
    263  1.3.2.2  thorpej  * Arguments:
    264  1.3.2.2  thorpej  *	r0	'struct lwp *' of the current LWP
    265  1.3.2.2  thorpej  */
    266  1.3.2.2  thorpej 
    267  1.3.2.2  thorpej ENTRY(cpu_switch)
    268  1.3.2.2  thorpej /*
    269  1.3.2.2  thorpej  * Local register usage. Some of these registers are out of date.
    270  1.3.2.2  thorpej  * r1 = oldlwp
    271  1.3.2.2  thorpej  * r2 = spl level
    272  1.3.2.2  thorpej  * r3 = whichqs
    273  1.3.2.2  thorpej  * r4 = queue
    274  1.3.2.2  thorpej  * r5 = &qs[queue]
    275  1.3.2.2  thorpej  * r6 = newlwp
    276  1.3.2.2  thorpej  * r7 = scratch
    277  1.3.2.2  thorpej  */
    278  1.3.2.2  thorpej 	stmfd	sp!, {r4-r7, lr}
    279  1.3.2.2  thorpej 
    280  1.3.2.2  thorpej 	/*
    281  1.3.2.2  thorpej 	 * Get the current lwp and indicate that there is no longer
    282  1.3.2.2  thorpej 	 * a valid process (curproc = 0)
    283  1.3.2.2  thorpej 	 */
    284  1.3.2.2  thorpej 	ldr	r7, Lcurproc
    285  1.3.2.2  thorpej 	ldr	r1, [r7]
    286  1.3.2.2  thorpej 	mov	r0, #0x00000000
    287  1.3.2.2  thorpej 	str	r0, [r7]
    288  1.3.2.2  thorpej 
    289  1.3.2.2  thorpej 	/* Zero the pcb */
    290  1.3.2.2  thorpej 	ldr	r7, Lcurpcb
    291  1.3.2.2  thorpej 	str	r0, [r7]
    292  1.3.2.2  thorpej 
    293  1.3.2.2  thorpej 	/* Lower the spl level to spl0 and get the current spl level. */
    294  1.3.2.2  thorpej 	mov	r7, r1
    295  1.3.2.2  thorpej 
    296  1.3.2.4  nathanw #ifdef __NEWINTR
    297  1.3.2.4  nathanw 	mov	r0, #(IPL_NONE)
    298  1.3.2.4  nathanw 	bl	_C_LABEL(_spllower)
    299  1.3.2.4  nathanw #else /* ! __NEWINTR */
    300  1.3.2.2  thorpej #ifdef spl0
    301  1.3.2.2  thorpej 	mov	r0, #(_SPL_0)
    302  1.3.2.2  thorpej 	bl	_C_LABEL(splx)
    303  1.3.2.2  thorpej #else
    304  1.3.2.2  thorpej 	bl	_C_LABEL(spl0)
    305  1.3.2.4  nathanw #endif /* spl0 */
    306  1.3.2.4  nathanw #endif /* __NEWINTR */
    307  1.3.2.2  thorpej 
    308  1.3.2.2  thorpej 	/* Push the old spl level onto the stack */
    309  1.3.2.2  thorpej 	str	r0, [sp, #-0x0004]!
    310  1.3.2.2  thorpej 
    311  1.3.2.2  thorpej 	mov	r1, r7
    312  1.3.2.2  thorpej 
    313  1.3.2.2  thorpej 	/* First phase : find a new lwp */
    314  1.3.2.2  thorpej 
    315  1.3.2.2  thorpej 	/* rem: r1 = old proc */
    316  1.3.2.2  thorpej 
    317  1.3.2.2  thorpej switch_search:
    318  1.3.2.2  thorpej 	IRQdisable
    319  1.3.2.2  thorpej 
    320  1.3.2.2  thorpej 	/* Do we have any active queues  */
    321  1.3.2.2  thorpej 	ldr	r7, Lwhichqs
    322  1.3.2.2  thorpej 	ldr	r3, [r7]
    323  1.3.2.2  thorpej 
    324  1.3.2.2  thorpej 	/* If not we must idle until we do. */
    325  1.3.2.2  thorpej 	teq	r3, #0x00000000
    326  1.3.2.4  nathanw 	beq	_ASM_LABEL(idle)
    327  1.3.2.2  thorpej 
    328  1.3.2.2  thorpej sw1:
    329  1.3.2.2  thorpej 	/* rem: r1 = old lwp */
    330  1.3.2.2  thorpej 	/* rem: r3 = whichqs */
    331  1.3.2.2  thorpej 	/* rem: interrupts are disabled */
    332  1.3.2.2  thorpej 
    333  1.3.2.2  thorpej 	/*
    334  1.3.2.2  thorpej 	 * We have found an active queue. Currently we do not know which queue
    335  1.3.2.2  thorpej 	 * is active just that one of them is.
    336  1.3.2.2  thorpej 	 */
    337  1.3.2.2  thorpej 	/* this is the ffs algorithm devised by d.seal and posted to
    338  1.3.2.2  thorpej 	 * comp.sys.arm on 16 Feb 1994.
    339  1.3.2.2  thorpej 	 */
    340  1.3.2.2  thorpej  	rsb	r5, r3, #0
    341  1.3.2.2  thorpej  	ands	r0, r3, r5
    342  1.3.2.2  thorpej 
    343  1.3.2.2  thorpej 	adr	r5, Lcpu_switch_ffs_table
    344  1.3.2.2  thorpej 
    345  1.3.2.2  thorpej 				    /* X = R0 */
    346  1.3.2.2  thorpej 	orr	r4, r0, r0, lsl #4  /* r4 = X * 0x11 */
    347  1.3.2.2  thorpej 	orr	r4, r4, r4, lsl #6  /* r4 = X * 0x451 */
    348  1.3.2.2  thorpej 	rsb	r4, r4, r4, lsl #16 /* r4 = X * 0x0450fbaf */
    349  1.3.2.2  thorpej 
    350  1.3.2.2  thorpej 	/* used further down, saves SA stall */
    351  1.3.2.2  thorpej 	ldr	r6, Lqs
    352  1.3.2.2  thorpej 
    353  1.3.2.2  thorpej 	/* now lookup in table indexed on top 6 bits of a4 */
    354  1.3.2.2  thorpej 	ldrb	r4, [ r5, r4, lsr #26 ]
    355  1.3.2.2  thorpej 
    356  1.3.2.2  thorpej 	/* rem: r0 = bit mask of chosen queue (1 << r4) */
    357  1.3.2.2  thorpej 	/* rem: r1 = old lwp */
    358  1.3.2.2  thorpej 	/* rem: r3 = whichqs */
    359  1.3.2.2  thorpej 	/* rem: r4 = queue number */
    360  1.3.2.2  thorpej 	/* rem: interrupts are disabled */
    361  1.3.2.2  thorpej 
    362  1.3.2.2  thorpej 	/* Get the address of the queue (&qs[queue]) */
    363  1.3.2.2  thorpej 	add	r5, r6, r4, lsl #3
    364  1.3.2.2  thorpej 
    365  1.3.2.2  thorpej 	/*
    366  1.3.2.2  thorpej 	 * Get the lwp from the queue and place the next process in
    367  1.3.2.2  thorpej 	 * the queue at the head. This basically unlinks the lwp at
    368  1.3.2.2  thorpej 	 * the head of the queue.
    369  1.3.2.2  thorpej 	 */
    370  1.3.2.2  thorpej 	ldr	r6, [r5, #(L_FORW)]
    371  1.3.2.2  thorpej 
    372  1.3.2.2  thorpej 	/* rem: r6 = new lwp */
    373  1.3.2.2  thorpej 	ldr	r7, [r6, #(L_FORW)]
    374  1.3.2.2  thorpej 	str	r7, [r5, #(L_FORW)]
    375  1.3.2.2  thorpej 
    376  1.3.2.2  thorpej 	/*
    377  1.3.2.2  thorpej 	 * Test to see if the queue is now empty. If the head of the queue
    378  1.3.2.2  thorpej 	 * points to the queue itself then there are no more lwps in
    379  1.3.2.2  thorpej 	 * the queue. We can therefore clear the queue not empty flag held
    380  1.3.2.2  thorpej 	 * in r3.
    381  1.3.2.2  thorpej 	 */
    382  1.3.2.2  thorpej 
    383  1.3.2.2  thorpej 	teq	r5, r7
    384  1.3.2.2  thorpej 	biceq	r3, r3, r0
    385  1.3.2.2  thorpej 
    386  1.3.2.2  thorpej 	/* rem: r0 = bit mask of chosen queue (1 << r4) - NOT NEEDED AN MORE */
    387  1.3.2.2  thorpej 
    388  1.3.2.2  thorpej 	/* Fix the back pointer for the lwp now at the head of the queue. */
    389  1.3.2.2  thorpej 	ldr	r0, [r6, #(L_BACK)]
    390  1.3.2.2  thorpej 	str	r0, [r7, #(L_BACK)]
    391  1.3.2.2  thorpej 
    392  1.3.2.2  thorpej 	/* Update the RAM copy of the queue not empty flags word. */
    393  1.3.2.2  thorpej 	ldr	r7, Lwhichqs
    394  1.3.2.2  thorpej 	str	r3, [r7]
    395  1.3.2.2  thorpej 
    396  1.3.2.2  thorpej 	/* rem: r1 = old lwp */
    397  1.3.2.2  thorpej 	/* rem: r3 = whichqs - NOT NEEDED ANY MORE */
    398  1.3.2.2  thorpej 	/* rem: r4 = queue number - NOT NEEDED ANY MORE */
    399  1.3.2.2  thorpej 	/* rem: r6 = new lwp */
    400  1.3.2.2  thorpej 	/* rem: interrupts are disabled */
    401  1.3.2.2  thorpej 
    402  1.3.2.2  thorpej 	/* Clear the want_resched flag */
    403  1.3.2.2  thorpej 	ldr	r7, Lwant_resched
    404  1.3.2.4  nathanw 	mov	r0, #0x00000000
    405  1.3.2.2  thorpej 	str	r0, [r7]
    406  1.3.2.2  thorpej 
    407  1.3.2.2  thorpej 	/*
    408  1.3.2.2  thorpej 	 * Clear the back pointer of the lwp we have removed from
    409  1.3.2.2  thorpej 	 * the head of the queue. The new lwp is isolated now.
    410  1.3.2.2  thorpej 	 */
    411  1.3.2.2  thorpej 	str	r0, [r6, #(L_BACK)]
    412  1.3.2.2  thorpej 
    413  1.3.2.2  thorpej switch_resume:
    414  1.3.2.2  thorpej 	/* l->l_cpu initialized in fork1() for single-processor */
    415  1.3.2.2  thorpej 
    416  1.3.2.2  thorpej 	/* Process is now on a processor. */
    417  1.3.2.2  thorpej 	mov	r0, #LSONPROC			/* l->l_stat = LSONPROC */
    418  1.3.2.3  thorpej 	str	r0, [r6, #(L_STAT)]
    419  1.3.2.2  thorpej 
    420  1.3.2.2  thorpej 	/* We have a new curproc now so make a note it */
    421  1.3.2.2  thorpej 	ldr	r7, Lcurproc
    422  1.3.2.2  thorpej 	str	r6, [r7]
    423  1.3.2.2  thorpej 
    424  1.3.2.2  thorpej 	/* Hook in a new pcb */
    425  1.3.2.2  thorpej 	ldr	r7, Lcurpcb
    426  1.3.2.2  thorpej 	ldr	r0, [r6, #(L_ADDR)]
    427  1.3.2.2  thorpej 	str	r0, [r7]
    428  1.3.2.2  thorpej 
    429  1.3.2.2  thorpej 	/* At this point we can allow IRQ's again. */
    430  1.3.2.2  thorpej 	IRQenable
    431  1.3.2.2  thorpej 
    432  1.3.2.2  thorpej 	/* rem: r1 = old lwp */
    433  1.3.2.2  thorpej 	/* rem: r4 = return value */
    434  1.3.2.2  thorpej 	/* rem: r6 = new process */
    435  1.3.2.4  nathanw 	/* rem: interrupts are enabled */
    436  1.3.2.2  thorpej 
    437  1.3.2.2  thorpej 	/*
    438  1.3.2.2  thorpej 	 * If the new process is the same as the process that called
    439  1.3.2.2  thorpej 	 * cpu_switch() then we do not need to save and restore any
    440  1.3.2.2  thorpej 	 * contexts. This means we can make a quick exit.
    441  1.3.2.2  thorpej 	 * The test is simple if curproc on entry (now in r1) is the
    442  1.3.2.2  thorpej 	 * same as the proc removed from the queue we can jump to the exit.
    443  1.3.2.2  thorpej 	 */
    444  1.3.2.2  thorpej 	teq	r1, r6
    445  1.3.2.2  thorpej 	moveq	r4, #0x00000000		/* default to "didn't switch" */
    446  1.3.2.2  thorpej 	beq	switch_return
    447  1.3.2.2  thorpej 
    448  1.3.2.2  thorpej 	/*
    449  1.3.2.2  thorpej 	 * At this point, we are guaranteed to be switching to
    450  1.3.2.2  thorpej 	 * a new lwp.
    451  1.3.2.2  thorpej 	 */
    452  1.3.2.2  thorpej 	mov	r4, #0x00000001
    453  1.3.2.2  thorpej 
    454  1.3.2.2  thorpej 	/*
    455  1.3.2.2  thorpej 	 * If the curproc on entry to cpu_switch was zero then the
    456  1.3.2.2  thorpej 	 * process that called it was exiting. This means that we do
    457  1.3.2.2  thorpej 	 * not need to save the current context. Instead we can jump
    458  1.3.2.2  thorpej 	 * straight to restoring the context for the new process.
    459  1.3.2.2  thorpej 	 */
    460  1.3.2.2  thorpej 	teq	r1, #0x00000000
    461  1.3.2.2  thorpej 	beq	switch_exited
    462  1.3.2.2  thorpej 
    463  1.3.2.2  thorpej 	/* rem: r1 = old proc */
    464  1.3.2.2  thorpej 	/* rem: r4 = return value */
    465  1.3.2.2  thorpej 	/* rem: r6 = new process */
    466  1.3.2.4  nathanw 	/* rem: interrupts are enabled */
    467  1.3.2.2  thorpej 
    468  1.3.2.2  thorpej 	/* Stage two : Save old context */
    469  1.3.2.2  thorpej 
    470  1.3.2.2  thorpej 	/* Remember the old process in r0 */
    471  1.3.2.2  thorpej 	mov	r0, r1
    472  1.3.2.2  thorpej 
    473  1.3.2.2  thorpej 	/* Get the user structure for the old process. */
    474  1.3.2.2  thorpej 	ldr	r1, [r1, #(L_ADDR)]
    475  1.3.2.2  thorpej 
    476  1.3.2.2  thorpej 	/* Save all the registers in the old process's pcb */
    477  1.3.2.2  thorpej 	add	r7, r1, #(PCB_R8)
    478  1.3.2.2  thorpej 	stmia	r7, {r8-r13}
    479  1.3.2.2  thorpej 
    480  1.3.2.2  thorpej 	/*
    481  1.3.2.2  thorpej 	 * This can be optimised... We know we want to go from SVC32
    482  1.3.2.2  thorpej 	 * mode to UND32 mode
    483  1.3.2.2  thorpej 	 */
    484  1.3.2.2  thorpej         mrs	r3, cpsr_all
    485  1.3.2.2  thorpej 	bic	r2, r3, #(PSR_MODE)
    486  1.3.2.2  thorpej 	orr	r2, r2, #(PSR_UND32_MODE | I32_bit)
    487  1.3.2.2  thorpej         msr	cpsr_all, r2
    488  1.3.2.2  thorpej 
    489  1.3.2.2  thorpej 	str	sp, [r1, #(PCB_UND_SP)]
    490  1.3.2.2  thorpej 
    491  1.3.2.2  thorpej         msr	cpsr_all, r3		/* Restore the old mode */
    492  1.3.2.2  thorpej 
    493  1.3.2.2  thorpej 	/* rem: r0 = old proc */
    494  1.3.2.4  nathanw 	/* rem: r1 = old pcb */
    495  1.3.2.2  thorpej 	/* rem: r4 = return value */
    496  1.3.2.2  thorpej 	/* rem: r6 = new process */
    497  1.3.2.4  nathanw 	/* rem: interrupts are enabled */
    498  1.3.2.2  thorpej 
    499  1.3.2.2  thorpej 	/* What else needs to be saved  Only FPA stuff when that is supported */
    500  1.3.2.2  thorpej 
    501  1.3.2.2  thorpej 	/* Third phase : restore saved context */
    502  1.3.2.2  thorpej 
    503  1.3.2.2  thorpej switch_exited:
    504  1.3.2.2  thorpej 	/* Don't allow user space access beween the purge and the switch */
    505  1.3.2.2  thorpej 	ldr	r3, Lblock_userspace_access
    506  1.3.2.2  thorpej 	ldr	r2, [r3]
    507  1.3.2.2  thorpej 	orr	r0, r2, #1
    508  1.3.2.2  thorpej 	str	r0, [r3]
    509  1.3.2.2  thorpej 
    510  1.3.2.2  thorpej 	stmfd	sp!, {r0-r3}
    511  1.3.2.2  thorpej 	ldr	r0, Lcpufuncs
    512  1.3.2.2  thorpej 	add	lr, pc, #Lcs_cache_purged - . - 8
    513  1.3.2.5  nathanw 	ldr	pc, [r0, #CF_IDCACHE_WBINV_ALL]
    514  1.3.2.2  thorpej 
    515  1.3.2.2  thorpej Lcs_cache_purged:
    516  1.3.2.2  thorpej 	ldmfd	sp!, {r0-r3}
    517  1.3.2.2  thorpej 
    518  1.3.2.2  thorpej 	/* At this point we need to kill IRQ's again. */
    519  1.3.2.2  thorpej 	IRQdisable
    520  1.3.2.2  thorpej 
    521  1.3.2.2  thorpej 	/* Interrupts are disabled so we can allow user space accesses again
    522  1.3.2.2  thorpej 	 * as none will occur until interrupts are re-enabled after the
    523  1.3.2.2  thorpej 	 * switch.
    524  1.3.2.2  thorpej 	 */
    525  1.3.2.2  thorpej 	str	r2, [r3]
    526  1.3.2.2  thorpej 
    527  1.3.2.2  thorpej 	/* Get the user structure for the new process in r1 */
    528  1.3.2.2  thorpej 	ldr	r1, [r6, #(L_ADDR)]
    529  1.3.2.2  thorpej 
    530  1.3.2.2  thorpej 	/* Get the pagedir physical address for the process. */
    531  1.3.2.2  thorpej 	ldr	r0, [r1, #(PCB_PAGEDIR)]
    532  1.3.2.2  thorpej 
    533  1.3.2.2  thorpej 	/* Switch the memory to the new process */
    534  1.3.2.2  thorpej 	ldr	r3, Lcpufuncs
    535  1.3.2.2  thorpej 	add	lr, pc, #Lcs_context_switched - . - 8
    536  1.3.2.2  thorpej 	ldr	pc, [r3, #CF_CONTEXT_SWITCH]
    537  1.3.2.2  thorpej 
    538  1.3.2.2  thorpej Lcs_context_switched:
    539  1.3.2.2  thorpej 	/*
    540  1.3.2.2  thorpej 	 * This can be optimised... We know we want to go from SVC32
    541  1.3.2.2  thorpej 	 * mode to UND32 mode
    542  1.3.2.2  thorpej 	 */
    543  1.3.2.2  thorpej         mrs	r3, cpsr_all
    544  1.3.2.2  thorpej 	bic	r2, r3, #(PSR_MODE)
    545  1.3.2.2  thorpej 	orr	r2, r2, #(PSR_UND32_MODE)
    546  1.3.2.2  thorpej         msr	cpsr_all, r2
    547  1.3.2.2  thorpej 
    548  1.3.2.2  thorpej 	ldr	sp, [r1, #(PCB_UND_SP)]
    549  1.3.2.2  thorpej 
    550  1.3.2.2  thorpej         msr	cpsr_all, r3		/* Restore the old mode */
    551  1.3.2.2  thorpej 
    552  1.3.2.2  thorpej 	/* Restore all the save registers */
    553  1.3.2.2  thorpej 	add	r7, r1, #PCB_R8
    554  1.3.2.2  thorpej 	ldmia	r7, {r8-r13}
    555  1.3.2.2  thorpej 
    556  1.3.2.2  thorpej #ifdef ARMFPE
    557  1.3.2.2  thorpej 	add	r0, r1, #(USER_SIZE) & 0x00ff
    558  1.3.2.2  thorpej 	add	r0, r0, #(USER_SIZE) & 0xff00
    559  1.3.2.2  thorpej 	bl	_C_LABEL(arm_fpe_core_changecontext)
    560  1.3.2.2  thorpej #endif
    561  1.3.2.2  thorpej 
    562  1.3.2.2  thorpej 	/* We can enable interrupts again */
    563  1.3.2.2  thorpej 	IRQenable
    564  1.3.2.2  thorpej 
    565  1.3.2.2  thorpej switch_return:
    566  1.3.2.2  thorpej 
    567  1.3.2.2  thorpej 	/* Get the spl level from the stack and update the current spl level */
    568  1.3.2.2  thorpej 	ldr	r0, [sp], #0x0004
    569  1.3.2.2  thorpej 	bl	_C_LABEL(splx)
    570  1.3.2.2  thorpej 
    571  1.3.2.2  thorpej 	/* cpu_switch returns 1 == switched, 0 == didn't switch */
    572  1.3.2.2  thorpej 	mov	r0, r4
    573  1.3.2.2  thorpej 
    574  1.3.2.2  thorpej 	/*
    575  1.3.2.2  thorpej 	 * Pull the registers that got pushed when either savectx() or
    576  1.3.2.2  thorpej 	 * cpu_switch() was called and return.
    577  1.3.2.2  thorpej 	 */
    578  1.3.2.2  thorpej 	ldmfd	sp!, {r4-r7, pc}
    579  1.3.2.2  thorpej 
    580  1.3.2.2  thorpej /*
    581  1.3.2.2  thorpej  * cpu_preempt(struct lwp *current, struct lwp *next)
    582  1.3.2.2  thorpej  * Switch to the specified next LWP
    583  1.3.2.2  thorpej  * Arguments:
    584  1.3.2.2  thorpej  *
    585  1.3.2.2  thorpej  *	r0	'struct lwp *' of the current LWP
    586  1.3.2.2  thorpej  *	r1	'struct lwp *' of the LWP to switch to
    587  1.3.2.2  thorpej  */
    588  1.3.2.2  thorpej ENTRY(cpu_preempt)
    589  1.3.2.2  thorpej 	stmfd	sp!, {r4-r7, lr}
    590  1.3.2.2  thorpej 
    591  1.3.2.2  thorpej 	/* Lower the spl level to spl0 and get the current spl level. */
    592  1.3.2.2  thorpej 	mov	r6, r0		/* save old lwp */
    593  1.3.2.2  thorpej 	mov	r7, r1		/* save new lwp */
    594  1.3.2.2  thorpej 
    595  1.3.2.2  thorpej #ifdef spl0
    596  1.3.2.2  thorpej 	mov	r0, #(_SPL_0)
    597  1.3.2.2  thorpej 	bl	_C_LABEL(splx)
    598  1.3.2.2  thorpej #else
    599  1.3.2.2  thorpej 	bl	_C_LABEL(spl0)
    600  1.3.2.2  thorpej #endif
    601  1.3.2.2  thorpej 
    602  1.3.2.2  thorpej 	/* Push the old spl level onto the stack */
    603  1.3.2.2  thorpej 	str	r0, [sp, #-0x0004]!
    604  1.3.2.2  thorpej 
    605  1.3.2.2  thorpej 	mov	r0, r6		/* restore old lwp */
    606  1.3.2.2  thorpej 	mov	r1, r7		/* restore new lwp */
    607  1.3.2.2  thorpej 
    608  1.3.2.2  thorpej 	/* rem: r1 = new lwp */
    609  1.3.2.2  thorpej 
    610  1.3.2.2  thorpej 	IRQdisable
    611  1.3.2.2  thorpej 
    612  1.3.2.2  thorpej 	/* Do we have any active queues? */
    613  1.3.2.2  thorpej 	ldr	r7, Lwhichqs
    614  1.3.2.2  thorpej 	ldr	r3, [r7]
    615  1.3.2.2  thorpej 
    616  1.3.2.2  thorpej 	/* If none, panic! */
    617  1.3.2.2  thorpej 	teq	r3, #0x00000000
    618  1.3.2.2  thorpej 	beq	preempt_noqueues
    619  1.3.2.2  thorpej 
    620  1.3.2.2  thorpej 	/* rem: r0 = old lwp */
    621  1.3.2.2  thorpej 	/* rem: r1 = new lwp */
    622  1.3.2.2  thorpej 	/* rem: r3 = whichqs */
    623  1.3.2.2  thorpej 	/* rem: r7 = &whichqs */
    624  1.3.2.2  thorpej 	/* rem: interrupts are disabled */
    625  1.3.2.2  thorpej 
    626  1.3.2.2  thorpej 	/* Compute the queue bit corresponding to the new lwp. */
    627  1.3.2.2  thorpej 	ldrb	r4, [r1, #(L_PRIORITY)]
    628  1.3.2.2  thorpej 	mov	r2, #0x00000001
    629  1.3.2.2  thorpej 	mov	r4, r4, lsr #2		/* queue number */
    630  1.3.2.2  thorpej 	mov	r2, r2, lsl r4		/* queue bit */
    631  1.3.2.2  thorpej 
    632  1.3.2.2  thorpej 	/* rem: r0 = old lwp */
    633  1.3.2.2  thorpej 	/* rem: r1 = new lwp */
    634  1.3.2.2  thorpej 	/* rem: r2 = queue bit */
    635  1.3.2.2  thorpej 	/* rem: r3 = whichqs */
    636  1.3.2.2  thorpej 	/* rem: r4 = queue number */
    637  1.3.2.2  thorpej 	/* rem: r7 = &whichqs */
    638  1.3.2.2  thorpej 
    639  1.3.2.2  thorpej 	/*
    640  1.3.2.2  thorpej 	 * Unlink the lwp from the queue.
    641  1.3.2.2  thorpej 	 */
    642  1.3.2.2  thorpej 	ldr	r5, [r1, #(L_BACK)]	/* r5 = l->l_back */
    643  1.3.2.2  thorpej 	mov	r6, #0x00000000
    644  1.3.2.2  thorpej 	str	r6, [r1, #(L_BACK)]	/* firewall: l->l_back = NULL */
    645  1.3.2.2  thorpej 	ldr	r6, [r1, #(L_FORW)]	/* r6 = l->l_forw */
    646  1.3.2.2  thorpej 	str	r5, [r6, #(L_BACK)]	/* r6->l_back = r5 */
    647  1.3.2.2  thorpej 	str	r6, [r5, #(L_FORW)]	/* r5->l_forw = r6 */
    648  1.3.2.2  thorpej 
    649  1.3.2.2  thorpej 	teq	r5, r6			/* see if queue is empty */
    650  1.3.2.2  thorpej 	biceq	r3, r3, r2		/* clear bit if so */
    651  1.3.2.2  thorpej 	streq	r3, [r7]		/* store it back if so */
    652  1.3.2.2  thorpej 
    653  1.3.2.2  thorpej 	/* rem: r2 (queue bit) now free */
    654  1.3.2.2  thorpej 	/* rem: r3 (whichqs) now free */
    655  1.3.2.2  thorpej 	/* rem: r7 (&whichqs) now free */
    656  1.3.2.2  thorpej 
    657  1.3.2.2  thorpej 	/*
    658  1.3.2.2  thorpej 	 * Okay, set up registers the way cpu_switch() wants them,
    659  1.3.2.2  thorpej 	 * and jump into the middle of it (where we bring up the
    660  1.3.2.2  thorpej 	 * new process).
    661  1.3.2.2  thorpej 	 */
    662  1.3.2.2  thorpej 	mov	r6, r1			/* r6 = new lwp */
    663  1.3.2.2  thorpej 	mov	r1, r0			/* r1 = old lwp */
    664  1.3.2.2  thorpej 	b	switch_resume
    665  1.3.2.2  thorpej 
    666  1.3.2.2  thorpej preempt_noqueues:
    667  1.3.2.2  thorpej 	add	r0, pc, #preemptpanic - . - 8
    668  1.3.2.2  thorpej 	bl	_C_LABEL(panic)
    669  1.3.2.2  thorpej 
    670  1.3.2.2  thorpej preemptpanic:
    671  1.3.2.2  thorpej 	.asciz	"cpu_preempt: whichqs empty"
    672  1.3.2.2  thorpej 	.align	0
    673  1.3.2.2  thorpej 
    674  1.3.2.2  thorpej Llwp0:
    675  1.3.2.2  thorpej 	.word	_C_LABEL(lwp0)
    676  1.3.2.2  thorpej 
    677  1.3.2.2  thorpej Lkernel_map:
    678  1.3.2.2  thorpej 	.word	_C_LABEL(kernel_map)
    679  1.3.2.2  thorpej 
    680  1.3.2.2  thorpej 
    681  1.3.2.2  thorpej ENTRY(switch_exit)
    682  1.3.2.2  thorpej 	/*
    683  1.3.2.2  thorpej 	 * r0 = lwp
    684  1.3.2.2  thorpej 	 * r1 = lwp0
    685  1.3.2.2  thorpej 	 */
    686  1.3.2.2  thorpej 
    687  1.3.2.2  thorpej 	mov	r3, r0
    688  1.3.2.2  thorpej  	ldr	r1, Llwp0
    689  1.3.2.2  thorpej 
    690  1.3.2.2  thorpej 	/* In case we fault */
    691  1.3.2.2  thorpej 	ldr	r0, Lcurproc
    692  1.3.2.4  nathanw 	mov	r2, #0x00000000
    693  1.3.2.2  thorpej 	str	r2, [r0]
    694  1.3.2.2  thorpej 
    695  1.3.2.2  thorpej /*	ldr	r0, Lcurpcb
    696  1.3.2.2  thorpej 	str	r2, [r0]*/
    697  1.3.2.2  thorpej 
    698  1.3.2.2  thorpej 	/* Switch to lwp0 context */
    699  1.3.2.2  thorpej 
    700  1.3.2.2  thorpej 	stmfd	sp!, {r0-r3}
    701  1.3.2.2  thorpej 
    702  1.3.2.2  thorpej 	ldr	r0, Lcpufuncs
    703  1.3.2.2  thorpej 	add	lr, pc, #Lse_cache_purged - . - 8
    704  1.3.2.5  nathanw 	ldr	pc, [r0, #CF_IDCACHE_WBINV_ALL]
    705  1.3.2.2  thorpej 
    706  1.3.2.2  thorpej Lse_cache_purged:
    707  1.3.2.2  thorpej 	ldmfd	sp!, {r0-r3}
    708  1.3.2.2  thorpej 
    709  1.3.2.2  thorpej 	IRQdisable
    710  1.3.2.2  thorpej 
    711  1.3.2.2  thorpej 	ldr	r2, [r1, #(L_ADDR)]
    712  1.3.2.2  thorpej 	ldr	r0, [r2, #(PCB_PAGEDIR)]
    713  1.3.2.2  thorpej 
    714  1.3.2.2  thorpej 	/* Switch the memory to the new process */
    715  1.3.2.2  thorpej 	ldr	r4, Lcpufuncs
    716  1.3.2.2  thorpej 	add	lr, pc, #Lse_context_switched - . - 8
    717  1.3.2.2  thorpej 	ldr	pc, [r4, #CF_CONTEXT_SWITCH]
    718  1.3.2.2  thorpej 
    719  1.3.2.2  thorpej Lse_context_switched:
    720  1.3.2.2  thorpej 	/* Restore all the save registers */
    721  1.3.2.2  thorpej 	add	r7, r2, #PCB_R8
    722  1.3.2.2  thorpej 	ldmia	r7, {r8-r13}
    723  1.3.2.2  thorpej 
    724  1.3.2.2  thorpej 	/* This is not really needed ! */
    725  1.3.2.2  thorpej 	/* Yes it is for the su and fu routines */
    726  1.3.2.2  thorpej 	ldr	r0, Lcurpcb
    727  1.3.2.2  thorpej 	str	r2, [r0]
    728  1.3.2.2  thorpej 
    729  1.3.2.2  thorpej 	IRQenable
    730  1.3.2.2  thorpej 
    731  1.3.2.2  thorpej /*	str	r3, [sp, #-0x0004]!*/
    732  1.3.2.2  thorpej 
    733  1.3.2.2  thorpej 	/*
    734  1.3.2.2  thorpej 	 * Schedule the vmspace and stack to be freed.
    735  1.3.2.2  thorpej 	 */
    736  1.3.2.2  thorpej 	mov	r0, r3			/* exit2(l) */
    737  1.3.2.2  thorpej 	bl	_C_LABEL(exit2)
    738  1.3.2.2  thorpej 
    739  1.3.2.2  thorpej 	/* Paranoia */
    740  1.3.2.2  thorpej 	mov	r0, #0x00000000
    741  1.3.2.2  thorpej 	ldr	r1, Lcurproc
    742  1.3.2.2  thorpej 	str	r0, [r1]
    743  1.3.2.2  thorpej 
    744  1.3.2.2  thorpej         ldr     r1, Llwp0
    745  1.3.2.2  thorpej 	b	switch_search
    746  1.3.2.2  thorpej 
    747  1.3.2.2  thorpej ENTRY(switch_lwp_exit)
    748  1.3.2.2  thorpej 	/*
    749  1.3.2.2  thorpej 	 * r0 = lwp
    750  1.3.2.2  thorpej 	 * r1 = lwp0
    751  1.3.2.2  thorpej 	 */
    752  1.3.2.2  thorpej 
    753  1.3.2.2  thorpej 	mov	r3, r0
    754  1.3.2.2  thorpej  	ldr	r1, Llwp0
    755  1.3.2.2  thorpej 
    756  1.3.2.2  thorpej 	/* In case we fault */
    757  1.3.2.2  thorpej 	mov	r2, #0x00000000
    758  1.3.2.2  thorpej 	ldr	r0, Lcurproc
    759  1.3.2.2  thorpej 	str	r2, [r0]
    760  1.3.2.2  thorpej 
    761  1.3.2.2  thorpej /*	ldr	r0, Lcurpcb
    762  1.3.2.2  thorpej 	str	r2, [r0]*/
    763  1.3.2.2  thorpej 
    764  1.3.2.2  thorpej 	/* Switch to lwp0 context */
    765  1.3.2.2  thorpej 
    766  1.3.2.2  thorpej 	stmfd	sp!, {r0-r3}
    767  1.3.2.2  thorpej 
    768  1.3.2.2  thorpej 	ldr	r0, Lcpufuncs
    769  1.3.2.2  thorpej 	add	lr, pc, #Lsle_cache_purged - . - 8
    770  1.3.2.2  thorpej 	ldr	pc, [r0, #CF_CACHE_PURGE_ID]
    771  1.3.2.2  thorpej 
    772  1.3.2.2  thorpej Lsle_cache_purged:
    773  1.3.2.2  thorpej 	ldmfd	sp!, {r0-r3}
    774  1.3.2.2  thorpej 
    775  1.3.2.2  thorpej 	IRQdisable
    776  1.3.2.2  thorpej 
    777  1.3.2.2  thorpej 	ldr	r2, [r1, #(L_ADDR)]
    778  1.3.2.2  thorpej 	ldr	r0, [r2, #(PCB_PAGEDIR)]
    779  1.3.2.2  thorpej 
    780  1.3.2.2  thorpej 	/* Switch the memory to the new process */
    781  1.3.2.2  thorpej 	ldr	r4, Lcpufuncs
    782  1.3.2.2  thorpej 	add	lr, pc, #Lsle_context_switched - . - 8
    783  1.3.2.2  thorpej 	ldr	pc, [r4, #CF_CONTEXT_SWITCH]
    784  1.3.2.2  thorpej 
    785  1.3.2.2  thorpej Lsle_context_switched:
    786  1.3.2.2  thorpej 	/* Restore all the save registers */
    787  1.3.2.2  thorpej 	add	r7, r2, #PCB_R8
    788  1.3.2.2  thorpej 	ldmia	r7, {r8-r13}
    789  1.3.2.2  thorpej 
    790  1.3.2.2  thorpej 	/* This is not really needed ! */
    791  1.3.2.2  thorpej 	/* Yes it is for the su and fu routines */
    792  1.3.2.2  thorpej 	ldr	r0, Lcurpcb
    793  1.3.2.2  thorpej 	str	r2, [r0]
    794  1.3.2.2  thorpej 
    795  1.3.2.2  thorpej 	IRQenable
    796  1.3.2.2  thorpej 
    797  1.3.2.2  thorpej /*	str	r3, [sp, #-0x0004]!*/
    798  1.3.2.2  thorpej 
    799  1.3.2.2  thorpej 	/*
    800  1.3.2.2  thorpej 	 * Schedule the vmspace and stack to be freed.
    801  1.3.2.2  thorpej 	 */
    802  1.3.2.2  thorpej 	mov	r0, r3			/* lwp_exit2(l) */
    803  1.3.2.2  thorpej 	bl	_C_LABEL(lwp_exit2)
    804  1.3.2.2  thorpej 
    805  1.3.2.2  thorpej 	/* Paranoia */
    806  1.3.2.2  thorpej 	ldr	r1, Lcurproc
    807  1.3.2.4  nathanw 	mov	r0, #0x00000000
    808  1.3.2.2  thorpej 	str	r0, [r1]
    809  1.3.2.2  thorpej 
    810  1.3.2.2  thorpej         ldr     r1, Llwp0
    811  1.3.2.2  thorpej 	b	switch_search
    812  1.3.2.2  thorpej 
    813  1.3.2.2  thorpej ENTRY(savectx)
    814  1.3.2.2  thorpej 	/*
    815  1.3.2.2  thorpej 	 * r0 = pcb
    816  1.3.2.2  thorpej 	 */
    817  1.3.2.2  thorpej 
    818  1.3.2.2  thorpej 	/* Push registers.*/
    819  1.3.2.2  thorpej 	stmfd	sp!, {r4-r7, lr}
    820  1.3.2.2  thorpej 
    821  1.3.2.2  thorpej 	/* Store all the registers in the process's pcb */
    822  1.3.2.2  thorpej 	add	r2, r0, #(PCB_R8)
    823  1.3.2.2  thorpej 	stmia	r2, {r8-r13}
    824  1.3.2.2  thorpej 
    825  1.3.2.2  thorpej 	/* Pull the regs of the stack */
    826  1.3.2.2  thorpej 	ldmfd	sp!, {r4-r7, pc}
    827  1.3.2.2  thorpej 
    828  1.3.2.2  thorpej ENTRY(proc_trampoline)
    829  1.3.2.2  thorpej 	add	lr, pc, #(trampoline_return - . - 8)
    830  1.3.2.2  thorpej 	mov	r0, r5
    831  1.3.2.2  thorpej 	mov	r1, sp
    832  1.3.2.2  thorpej 	mov	pc, r4
    833  1.3.2.2  thorpej 
    834  1.3.2.2  thorpej trampoline_return:
    835  1.3.2.2  thorpej 	/* Kill irq's */
    836  1.3.2.2  thorpej         mrs     r0, cpsr_all
    837  1.3.2.2  thorpej         orr     r0, r0, #(I32_bit)
    838  1.3.2.2  thorpej         msr     cpsr_all, r0
    839  1.3.2.2  thorpej 
    840  1.3.2.2  thorpej 	PULLFRAME
    841  1.3.2.2  thorpej 
    842  1.3.2.2  thorpej 	movs	pc, lr			/* Exit */
    843  1.3.2.2  thorpej 
    844  1.3.2.2  thorpej 	.type Lcpu_switch_ffs_table, _ASM_TYPE_OBJECT;
    845  1.3.2.2  thorpej Lcpu_switch_ffs_table:
    846  1.3.2.2  thorpej /* same as ffs table but all nums are -1 from that */
    847  1.3.2.2  thorpej /*               0   1   2   3   4   5   6   7           */
    848  1.3.2.2  thorpej 	.byte	 0,  0,  1, 12,  2,  6,  0, 13  /*  0- 7 */
    849  1.3.2.2  thorpej 	.byte	 3,  0,  7,  0,  0,  0,  0, 14  /*  8-15 */
    850  1.3.2.2  thorpej 	.byte	10,  4,  0,  0,  8,  0,  0, 25  /* 16-23 */
    851  1.3.2.2  thorpej 	.byte	 0,  0,  0,  0,  0, 21, 27, 15  /* 24-31 */
    852  1.3.2.2  thorpej 	.byte	31, 11,  5,  0,  0,  0,  0,  0	/* 32-39 */
    853  1.3.2.2  thorpej 	.byte	 9,  0,  0, 24,  0,  0, 20, 26  /* 40-47 */
    854  1.3.2.2  thorpej 	.byte	30,  0,  0,  0,  0, 23,  0, 19  /* 48-55 */
    855  1.3.2.2  thorpej 	.byte   29,  0, 22, 18, 28, 17, 16,  0  /* 56-63 */
    856  1.3.2.2  thorpej 
    857  1.3.2.2  thorpej /* End of cpuswitch.S */
    858