Home | History | Annotate | Line # | Download | only in oea
ofw_subr.S revision 1.7.6.1
      1  1.7.6.1      mjf /*	$NetBSD: ofw_subr.S,v 1.7.6.1 2008/06/02 13:22:32 mjf Exp $	*/
      2      1.1     matt 
      3      1.1     matt /*
      4      1.1     matt  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5      1.1     matt  * Copyright (C) 1995, 1996 TooLs GmbH.
      6      1.1     matt  * All rights reserved.
      7      1.1     matt  *
      8      1.1     matt  * Redistribution and use in source and binary forms, with or without
      9      1.1     matt  * modification, are permitted provided that the following conditions
     10      1.1     matt  * are met:
     11      1.1     matt  * 1. Redistributions of source code must retain the above copyright
     12      1.1     matt  *    notice, this list of conditions and the following disclaimer.
     13      1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     15      1.1     matt  *    documentation and/or other materials provided with the distribution.
     16      1.1     matt  * 3. All advertising materials mentioning features or use of this software
     17      1.1     matt  *    must display the following acknowledgement:
     18      1.1     matt  *	This product includes software developed by TooLs GmbH.
     19      1.1     matt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20      1.1     matt  *    derived from this software without specific prior written permission.
     21      1.1     matt  *
     22      1.1     matt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23      1.1     matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.1     matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.1     matt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26      1.1     matt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27      1.1     matt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28      1.1     matt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29      1.1     matt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30      1.1     matt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31      1.1     matt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.1     matt  */
     33      1.1     matt 
     34      1.1     matt 
     35      1.1     matt 	.local	firmstk
     36      1.3  sanjayl 	.globl	openfirmware_entry
     37      1.1     matt 	.local	ofwsrsave
     38      1.1     matt 	.local	OF_buffer
     39      1.1     matt 
     40      1.1     matt 	.data
     41      1.1     matt GLOBAL(ofmsr)
     42      1.1     matt 	.long	0,0,0,0,0		/* msr & sprg[0-3] used in OF */
     43      1.1     matt 
     44      1.1     matt GLOBAL(ofwsprg0save)
     45      1.1     matt 	.long	0
     46      1.1     matt 
     47      1.4  aymeric GLOBAL(ofwreal_incharge)
     48      1.4  aymeric 	.long	0
     49      1.4  aymeric 
     50      1.1     matt 	.comm	firmstk,NBPG,8
     51      1.1     matt 	.comm	OF_buffer,NBPG,4
     52      1.1     matt 	.comm	openfirmware_entry,4,4	/* openfirmware entry point */
     53      1.1     matt 	.comm	ofwsrsave,64,4		/* openfirmware SR savearea */
     54      1.1     matt 
     55      1.1     matt /*
     56      1.1     matt  * Called by start to save the initial OFW state so we can restore it
     57      1.1     matt  * when call back to OFW.
     58      1.1     matt  */
     59      1.1     matt ENTRY_NOPROFILE(ofwinit)
     60      1.1     matt #ifdef	FIRMWORKSBUGS
     61      1.7  garbled 	mfmsr	%r0
     62      1.7  garbled 	andi.	%r0,%r0,PSL_IR|PSL_DR
     63      1.1     matt 	beq	1f
     64      1.1     matt 
     65      1.7  garbled 	li	%r8,1
     66      1.7  garbled 	lis	%r9,ofwreal_incharge@ha
     67      1.7  garbled 	stw	%r8,ofwreal_incharge@l(9)
     68      1.4  aymeric 
     69      1.7  garbled 	mflr	%r30
     70      1.1     matt 	bl	_C_LABEL(ofwr_init)
     71      1.7  garbled 	mtlr	%r30
     72      1.1     matt 1:
     73      1.1     matt #endif
     74      1.7  garbled 	lis	%r8,openfirmware_entry@ha
     75      1.7  garbled 	stw	%r5,openfirmware_entry@l(%r8) /* save client interface handler*/
     76      1.1     matt 
     77      1.7  garbled 	mfmsr	%r0
     78      1.7  garbled 	lis	%r9,ofmsr@ha
     79      1.7  garbled 	stwu	%r0,ofmsr@l(%r9)		/* save initial MSR value */
     80      1.7  garbled 
     81      1.7  garbled         mfsprg  %r0,0			/* save SPRGs */
     82      1.7  garbled        	stwu	%r0,4(%r9)
     83      1.7  garbled         mfsprg  %r0,1
     84      1.7  garbled        	stwu	%r0,4(%r9)
     85      1.7  garbled         mfsprg  %r0,2
     86      1.7  garbled        	stwu	%r0,4(%r9)
     87      1.7  garbled         mfsprg  %r0,3
     88      1.7  garbled        	stw	%r0,4(%r9)
     89      1.7  garbled 
     90      1.7  garbled 	lis	%r8,OF_buffer@ha
     91      1.7  garbled 	addi	%r8,%r8,OF_buffer@l
     92      1.7  garbled 	lis	%r9,_C_LABEL(OF_buf)@ha
     93      1.7  garbled 	stw	%r8,_C_LABEL(OF_buf)@l(%r9)
     94      1.1     matt 
     95      1.1     matt 	blr
     96      1.1     matt 
     97      1.1     matt /*
     98      1.1     matt  * OpenFirmware entry point
     99      1.1     matt  */
    100      1.1     matt 	.text
    101      1.1     matt ENTRY(openfirmware)
    102      1.7  garbled 	mflr	%r0			/* save return address */
    103      1.7  garbled 	stw	%r0,4(%r1)
    104      1.7  garbled 	stwu	%r1,-16(%r1)		/* setup stack frame */
    105      1.7  garbled 
    106      1.7  garbled 	lis	%r4,openfirmware_entry@ha	/* get firmware entry point */
    107      1.7  garbled 	lwz	%r4,openfirmware_entry@l(%r4)
    108      1.7  garbled 	mtlr	%r4
    109      1.7  garbled 
    110      1.7  garbled 	mfsprg	%r5,0			/* save current sprg0 (curcpu) */
    111      1.7  garbled 	lis	%r4,ofwsprg0save@ha
    112      1.7  garbled 	addi	%r4,%r4,ofwsprg0save@l
    113      1.7  garbled 	stw	%r5,0(%r4)
    114      1.4  aymeric 
    115      1.4  aymeric #ifdef FIRMWORKSBUGS
    116      1.7  garbled 	lis	%r4,ofwreal_incharge@ha
    117      1.7  garbled 	lwz	%r4,ofwreal_incharge@l(%r4)
    118      1.7  garbled 	cmpwi	%r4,1
    119      1.4  aymeric 	bne	1f
    120      1.4  aymeric 	blrl
    121      1.6  garbled 	b	4f
    122      1.4  aymeric 1:
    123      1.6  garbled #endif
    124      1.7  garbled 	mfmsr	%r4			/* save msr */
    125      1.7  garbled 	stw	%r4,8(%r1)
    126      1.4  aymeric 
    127      1.7  garbled 	li	%r0,0			/* clear battable translations */
    128  1.7.6.1      mjf 	mtmsr	%r0
    129      1.6  garbled #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
    130      1.7  garbled 	mtdbatu	2,%r0
    131      1.7  garbled 	mtdbatu	3,%r0
    132      1.7  garbled 	mtibatu	2,%r0
    133      1.7  garbled 	mtibatu	3,%r0
    134      1.3  sanjayl #endif /* PPC_OEA */
    135      1.1     matt 
    136      1.7  garbled 	lis	%r4,ofwsrsave@ha		/* save current SRs */
    137      1.7  garbled 	addi	%r4,%r4,ofwsrsave@l
    138      1.7  garbled 	li	%r5,0
    139      1.7  garbled 1:	mfsrin	%r0,%r5
    140      1.7  garbled 	stw	%r0,0(%r4)
    141      1.7  garbled 	addi	%r4,%r4,4
    142      1.7  garbled 	addis	%r5,%r5,0x10000000@h
    143      1.7  garbled 	cmpwi	%r5,0
    144      1.1     matt 	bne	1b
    145      1.1     matt 
    146      1.7  garbled 	lis	%r4,_C_LABEL(ofw_pmap)@ha	/* load OFW SR */
    147      1.7  garbled 	addi	%r4,%r4,_C_LABEL(ofw_pmap)@l
    148      1.7  garbled 	lwz	%r0,PM_KERNELSR(%r4)
    149      1.7  garbled 	cmpwi	%r0,0			/* pm_sr[KERNEL_SR] == 0? */
    150      1.1     matt 	beq	2f			/* then skip (not initialized yet) */
    151      1.7  garbled 	li	%r5,0
    152      1.7  garbled 1:	lwz	%r0,0(%r4)
    153      1.7  garbled 	mtsrin	%r0,%r5
    154      1.7  garbled 	addi	%r4,%r4,4
    155      1.7  garbled 	addis	%r5,%r5,0x10000000@h
    156      1.7  garbled 	cmpwi	%r5,0
    157      1.1     matt 	bne	1b
    158      1.1     matt 2:
    159      1.7  garbled 	lis	%r4,ofmsr@ha		/* Open Firmware msr + sprg[0-3] */
    160      1.7  garbled 	lwzu	%r5,ofmsr+16@l(%r4)
    161      1.7  garbled 	mtsprg	3,%r5
    162      1.7  garbled 	lwzu	%r5,-4(%r4)
    163      1.7  garbled 	mtsprg	2,%r5
    164      1.7  garbled 	lwzu	%r5,-4(%r4)
    165      1.7  garbled 	mtsprg	1,%r5
    166      1.7  garbled 	lwzu	%r5,-4(%r4)
    167      1.7  garbled 	mtsprg	0,%r5
    168      1.7  garbled 	lwz	%r5,-4(%r4)
    169      1.7  garbled 	mtmsr	%r5
    170      1.1     matt 	isync
    171      1.1     matt 
    172      1.1     matt 	blrl				/* call Open Firmware */
    173      1.1     matt 
    174      1.7  garbled 	lis	%r4,ofwsrsave@ha	/* restore saved SRs */
    175      1.7  garbled 	addi	%r4,%r4,ofwsrsave@l
    176      1.7  garbled 	li	%r5,0
    177      1.7  garbled 1:	lwz	%r0,0(%r4)
    178      1.7  garbled 	mtsrin	%r0,%r5
    179      1.7  garbled 	addi	%r4,%r4,4
    180      1.7  garbled 	addis	%r5,%r5,0x10000000@h
    181      1.7  garbled 	cmpwi	%r5,0
    182      1.1     matt 	bne	1b
    183      1.1     matt 
    184      1.7  garbled 	lwz	%r4,8(%r1)		/* restore msr */
    185      1.7  garbled 	mtmsr	%r4
    186      1.1     matt 	isync
    187      1.6  garbled 4:
    188      1.7  garbled 	lis	%r4,ofwsprg0save@ha	/* restore saved sprg0 (curcpu) */
    189      1.7  garbled 	addi	%r4,%r4,ofwsprg0save@l
    190      1.7  garbled 	lwz	%r5,0(%r4)
    191      1.7  garbled 	mtsprg	0,%r5
    192      1.7  garbled 
    193      1.7  garbled 	lwz	%r1,0(%r1)		/* and return */
    194      1.7  garbled 	lwz	%r0,4(%r1)
    195      1.7  garbled 	mtlr	%r0
    196      1.1     matt 	blr
    197      1.1     matt 
    198      1.1     matt /*
    199      1.1     matt  * Switch to/from OpenFirmware real mode stack
    200      1.1     matt  *
    201      1.1     matt  * Note: has to be called as the very first thing in OpenFirmware interface
    202      1.1     matt  * routines.
    203      1.1     matt  * E.g.:
    204      1.1     matt  * int
    205      1.1     matt  * OF_xxx(arg1, arg2)
    206      1.1     matt  * type arg1, arg2;
    207      1.1     matt  * {
    208      1.1     matt  *	static struct {
    209      1.1     matt  *		char *name;
    210      1.1     matt  *		int nargs;
    211      1.1     matt  *		int nreturns;
    212      1.1     matt  *		char *method;
    213      1.1     matt  *		int arg1;
    214      1.1     matt  *		int arg2;
    215      1.1     matt  *		int ret;
    216      1.1     matt  *	} args = {
    217      1.1     matt  *		"xxx",
    218      1.1     matt  *		2,
    219      1.1     matt  *		1,
    220      1.1     matt  *	};
    221      1.1     matt  *
    222      1.1     matt  *	ofw_stack();
    223      1.1     matt  *	args.arg1 = arg1;
    224      1.1     matt  *	args.arg2 = arg2;
    225      1.1     matt  *	if (openfirmware(&args) < 0)
    226      1.1     matt  *		return -1;
    227      1.1     matt  *	return args.ret;
    228      1.1     matt  * }
    229      1.1     matt  */
    230      1.1     matt 
    231      1.1     matt ENTRY(ofw_stack)
    232      1.7  garbled 	mfmsr	%r8			/* turn off interrupts */
    233      1.7  garbled 	andi.	%r0,%r8,~(PSL_EE|PSL_RI)@l
    234      1.7  garbled 	mtmsr	%r0
    235      1.7  garbled 	stw	%r8,4(%r1)		/* abuse return address slot */
    236      1.7  garbled 
    237      1.7  garbled 	lwz	%r5,0(%r1)		/* get length of stack frame */
    238      1.7  garbled 	subf	%r5,%r1,%r5
    239      1.7  garbled 
    240      1.7  garbled 	lis	%r7,firmstk+NBPG-8@ha
    241      1.7  garbled 	addi	%r7,%r7,firmstk+NBPG-8@l
    242      1.7  garbled 	lis	%r6,ofw_back@ha
    243      1.7  garbled 	addi	%r6,%r6,ofw_back@l
    244      1.7  garbled 	subf	%r4,%r5,%r7		/* make room for stack frame on
    245      1.1     matt 					   new stack */
    246      1.7  garbled 	stw	%r6,-4(%r7)		/* setup return pointer */
    247      1.7  garbled 	stwu	%r1,-8(%r7)
    248      1.1     matt 
    249      1.7  garbled 	stw	%r7,-8(%r4)
    250      1.1     matt 
    251      1.7  garbled 	addi	%r3,%r1,8
    252      1.7  garbled 	addi	%r1,%r4,-8
    253      1.7  garbled 	subi	%r5,%r5,8
    254      1.1     matt 
    255      1.1     matt 	b	_C_LABEL(ofbcopy)	/* and copy it */
    256      1.1     matt 
    257      1.1     matt ofw_back:
    258      1.7  garbled 	lwz	%r1,0(%r1)		/* get callers original stack pointer */
    259      1.1     matt 
    260      1.7  garbled 	lwz	%r0,4(%r1)		/* get saved msr from abused slot */
    261      1.7  garbled 	mtmsr	%r0
    262      1.1     matt 
    263      1.7  garbled 	lwz	%r1,0(%r1)		/* return */
    264      1.7  garbled 	lwz	%r0,4(%r1)
    265      1.7  garbled 	mtlr	%r0
    266      1.1     matt 	blr
    267