Home | History | Annotate | Line # | Download | only in oea
ofw_subr.S revision 1.16
      1  1.16   thorpej /*	$NetBSD: ofw_subr.S,v 1.16 2021/02/19 18:02:45 thorpej 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.12       rin #ifdef _KERNEL_OPT
     35  1.12       rin #include "opt_ppcarch.h"
     36  1.12       rin #endif
     37   1.1      matt 
     38  1.14   thorpej 	/* Stack used to call into OpenFirmware. */
     39  1.14   thorpej 	.lcomm	firmstk,NBPG,16
     40   1.1      matt 
     41  1.14   thorpej 	/* Buffer used to pass data to/from OpenFirmware. */
     42  1.11  macallan 	.lcomm	OF_buffer,NBPG + 36,4
     43  1.14   thorpej 
     44  1.14   thorpej 	/* The OpenFirmware entry point, provided by OpenFirmware. */
     45  1.14   thorpej 	.lcomm	ofentry,4,4
     46  1.14   thorpej 
     47  1.14   thorpej 	/* Entry trampoline used by openfirmware(). */
     48  1.14   thorpej 	.lcomm	oftramp,4,4
     49  1.14   thorpej 
     50  1.14   thorpej 	/* OpenFirmware SR save area */
     51  1.14   thorpej 	.lcomm	ofwsrsave,64,4
     52  1.14   thorpej 
     53  1.14   thorpej 	/* MSR and SPRG[0-3] used in OpenFirmware */
     54  1.14   thorpej 	.globl	ofwmsr
     55  1.14   thorpej 	.comm	ofwmsr,20,4
     56   1.1      matt 
     57  1.16   thorpej #ifdef FIRMWORKSBUGS
     58  1.16   thorpej 	.comm	ofwreal_incharge,4,4
     59  1.16   thorpej #endif
     60  1.16   thorpej 
     61   1.1      matt /*
     62   1.1      matt  * Called by start to save the initial OFW state so we can restore it
     63   1.1      matt  * when call back to OFW.
     64  1.14   thorpej  *
     65  1.14   thorpej  * We expect the registers to be as for the entry point into the kernel:
     66  1.14   thorpej  *
     67  1.14   thorpej  *	%r1	Stack provided by OpenFirmware / boot loader
     68  1.14   thorpej  *	%r5	OpenFirmware client entry point
     69  1.14   thorpej  *
     70  1.14   thorpej  * (others -- don't care)
     71   1.1      matt  */
     72   1.1      matt ENTRY_NOPROFILE(ofwinit)
     73  1.14   thorpej 	/* Save return address, Push a stack frame. */
     74  1.14   thorpej 	mflr	%r0
     75  1.14   thorpej 	stw	%r0,4(%r1)
     76  1.14   thorpej 	stwu	%r1,-16(%r1)
     77  1.14   thorpej 
     78  1.14   thorpej #ifdef FIRMWORKSBUGS
     79   1.7   garbled 	mfmsr	%r0
     80   1.7   garbled 	andi.	%r0,%r0,PSL_IR|PSL_DR
     81   1.1      matt 	beq	1f
     82   1.1      matt 
     83   1.7   garbled 	li	%r8,1
     84   1.7   garbled 	lis	%r9,ofwreal_incharge@ha
     85   1.9      matt 	stw	%r8,ofwreal_incharge@l(%r9)
     86   1.4   aymeric 
     87   1.1      matt 	bl	_C_LABEL(ofwr_init)
     88   1.1      matt 1:
     89   1.1      matt #endif
     90   1.1      matt 
     91  1.14   thorpej 	lis	%r8,ofentry@ha
     92  1.14   thorpej 	stw	%r5,ofentry@l(%r8)	/* save client interface handler */
     93  1.14   thorpej 
     94  1.14   thorpej 	/*
     95  1.14   thorpej 	 * Call directly into OpenFirmware until we're ready to use
     96  1.14   thorpej 	 * the trampoline.
     97  1.14   thorpej 	 */
     98  1.14   thorpej 	lis	%r8,oftramp@ha
     99  1.14   thorpej 	stw	%r5,oftramp@l(%r8)
    100  1.14   thorpej 
    101  1.14   thorpej 	/* Save the MSR that OpenFirmware is using. */
    102   1.7   garbled 	mfmsr	%r0
    103   1.9      matt 	lis	%r9,ofwmsr@ha
    104  1.14   thorpej 	stwu	%r0,ofwmsr@l(%r9)
    105   1.9      matt 
    106   1.9      matt 	mfsprg0	%r0				/* save SPRGs */
    107   1.9      matt 	stw	%r0,4(%r9)
    108   1.9      matt 	mfsprg1	%r0
    109   1.9      matt 	stw	%r0,8(%r9)
    110   1.9      matt 	mfsprg2	%r0
    111   1.9      matt 	stw	%r0,12(%r9)
    112   1.9      matt 	mfsprg3	%r0
    113   1.9      matt 	stw	%r0,16(%r9)
    114   1.7   garbled 
    115   1.7   garbled 	lis	%r8,OF_buffer@ha
    116   1.7   garbled 	addi	%r8,%r8,OF_buffer@l
    117   1.7   garbled 	lis	%r9,_C_LABEL(OF_buf)@ha
    118   1.7   garbled 	stw	%r8,_C_LABEL(OF_buf)@l(%r9)
    119   1.1      matt 
    120  1.15   thorpej 	/*
    121  1.15   thorpej 	 * Call into C code to perform additional early initialization.
    122  1.15   thorpej 	 */
    123  1.15   thorpej 	lis	%r8,_C_LABEL(ofw_bootstrap)@ha
    124  1.15   thorpej 	addi	%r8,%r8,_C_LABEL(ofw_bootstrap)@l
    125  1.15   thorpej 	mtctr	%r8
    126  1.15   thorpej 	bctrl
    127  1.14   thorpej 
    128  1.14   thorpej 	/*
    129  1.14   thorpej 	 * Jump off the trampoline for all subsequent calls
    130  1.14   thorpej 	 * into OpenFirmware.
    131  1.14   thorpej 	 */
    132  1.14   thorpej 	lis	%r5,_C_LABEL(openfirmware_trampoline)@ha
    133  1.14   thorpej 	addi	%r5,%r5,_C_LABEL(openfirmware_trampoline)@l
    134  1.14   thorpej 	lis	%r8,oftramp@ha
    135  1.14   thorpej 	stw	%r5,oftramp@l(%r8)
    136  1.14   thorpej 
    137  1.14   thorpej 	/* Retrieve LR, pop stack frame. */
    138  1.14   thorpej 	addi	%r1,%r1,16
    139  1.14   thorpej 	lwz	%r0,4(%r1)
    140  1.14   thorpej 	mtlr	%r0
    141  1.14   thorpej 
    142   1.1      matt 	blr
    143   1.1      matt 
    144   1.1      matt /*
    145  1.14   thorpej  * OpenFirmware trampoline.  We are already on the OpenFirmware stack.
    146   1.1      matt  */
    147  1.14   thorpej ENTRY_NOPROFILE(openfirmware_trampoline)
    148  1.13   thorpej 	mflr	%r0
    149  1.13   thorpej 	stw	%r0,4(%r1)		/* save return address */
    150  1.13   thorpej 
    151  1.13   thorpej 	/*
    152  1.14   thorpej 	 * Push stack frame and save area:
    153  1.13   thorpej 	 *
    154  1.14   thorpej 	 * [SP+8 save area]
    155  1.14   thorpej 	 * [SP+4 slot for saved LR in callee]
    156  1.14   thorpej 	 * [SP+0 saved SP]
    157  1.13   thorpej 	 */
    158  1.14   thorpej 	stwu	%r1,-48(%r1)
    159   1.7   garbled 
    160  1.14   thorpej 	lis	%r4,ofentry@ha		/* get firmware entry point */
    161  1.14   thorpej 	lwz	%r4,ofentry@l(%r4)
    162   1.7   garbled 	mtlr	%r4
    163   1.7   garbled 
    164   1.9      matt 	mfsprg0	%r5			/* save current sprg0 (curcpu) */
    165   1.9      matt 	stw	%r5,16(%r1)
    166   1.9      matt 	mfsprg1	%r5			/* save current sprg1 */
    167   1.9      matt 	stw	%r5,20(%r1)
    168   1.9      matt 	mfsprg2	%r5			/* save current sprg1 */
    169   1.9      matt 	stw	%r5,24(%r1)
    170   1.9      matt 	mfsprg3	%r5			/* save current sprg3 */
    171   1.9      matt 	stw	%r5,28(%r1)
    172   1.4   aymeric 
    173   1.4   aymeric #ifdef FIRMWORKSBUGS
    174   1.7   garbled 	lis	%r4,ofwreal_incharge@ha
    175   1.7   garbled 	lwz	%r4,ofwreal_incharge@l(%r4)
    176   1.7   garbled 	cmpwi	%r4,1
    177   1.4   aymeric 	bne	1f
    178   1.4   aymeric 	blrl
    179   1.6   garbled 	b	4f
    180   1.4   aymeric 1:
    181   1.6   garbled #endif
    182   1.7   garbled 	mfmsr	%r4			/* save msr */
    183   1.7   garbled 	stw	%r4,8(%r1)
    184   1.4   aymeric 
    185   1.7   garbled 	li	%r0,0			/* clear battable translations */
    186   1.8   garbled 	mtmsr	%r0
    187   1.6   garbled #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
    188   1.7   garbled 	mtdbatu	2,%r0
    189   1.7   garbled 	mtdbatu	3,%r0
    190   1.7   garbled 	mtibatu	2,%r0
    191   1.7   garbled 	mtibatu	3,%r0
    192   1.3   sanjayl #endif /* PPC_OEA */
    193   1.1      matt 
    194   1.7   garbled 	lis	%r4,ofwsrsave@ha		/* save current SRs */
    195   1.7   garbled 	addi	%r4,%r4,ofwsrsave@l
    196   1.7   garbled 	li	%r5,0
    197   1.7   garbled 1:	mfsrin	%r0,%r5
    198   1.7   garbled 	stw	%r0,0(%r4)
    199   1.7   garbled 	addi	%r4,%r4,4
    200   1.7   garbled 	addis	%r5,%r5,0x10000000@h
    201   1.7   garbled 	cmpwi	%r5,0
    202   1.1      matt 	bne	1b
    203   1.1      matt 
    204   1.7   garbled 	lis	%r4,_C_LABEL(ofw_pmap)@ha	/* load OFW SR */
    205   1.7   garbled 	addi	%r4,%r4,_C_LABEL(ofw_pmap)@l
    206   1.7   garbled 	lwz	%r0,PM_KERNELSR(%r4)
    207   1.7   garbled 	cmpwi	%r0,0			/* pm_sr[KERNEL_SR] == 0? */
    208   1.1      matt 	beq	2f			/* then skip (not initialized yet) */
    209   1.7   garbled 	li	%r5,0
    210   1.7   garbled 1:	lwz	%r0,0(%r4)
    211   1.7   garbled 	mtsrin	%r0,%r5
    212   1.7   garbled 	addi	%r4,%r4,4
    213   1.7   garbled 	addis	%r5,%r5,0x10000000@h
    214   1.7   garbled 	cmpwi	%r5,0
    215   1.1      matt 	bne	1b
    216   1.1      matt 2:
    217   1.9      matt 	lis	%r4,ofwmsr+16@ha	/* Open Firmware msr + sprg[0-3] */
    218   1.9      matt 	lwzu	%r5,ofwmsr+16@l(%r4)
    219   1.9      matt 	mtsprg3	%r5
    220   1.7   garbled 	lwz	%r5,-4(%r4)
    221   1.9      matt 	mtsprg2	%r5
    222   1.9      matt 	lwz	%r5,-8(%r4)
    223   1.9      matt 	mtsprg1	%r5
    224   1.9      matt 	lwz	%r5,-12(%r4)
    225   1.9      matt 	mtsprg0	%r5
    226   1.9      matt 	lwz	%r5,-16(%r4)
    227   1.7   garbled 	mtmsr	%r5
    228   1.1      matt 	isync
    229   1.1      matt 
    230   1.1      matt 	blrl				/* call Open Firmware */
    231   1.1      matt 
    232   1.7   garbled 	lis	%r4,ofwsrsave@ha	/* restore saved SRs */
    233   1.7   garbled 	addi	%r4,%r4,ofwsrsave@l
    234   1.7   garbled 	li	%r5,0
    235   1.7   garbled 1:	lwz	%r0,0(%r4)
    236   1.7   garbled 	mtsrin	%r0,%r5
    237   1.7   garbled 	addi	%r4,%r4,4
    238   1.7   garbled 	addis	%r5,%r5,0x10000000@h
    239   1.7   garbled 	cmpwi	%r5,0
    240   1.1      matt 	bne	1b
    241   1.1      matt 
    242   1.7   garbled 	lwz	%r4,8(%r1)		/* restore msr */
    243   1.7   garbled 	mtmsr	%r4
    244   1.1      matt 	isync
    245   1.6   garbled 4:
    246   1.9      matt 	lwz	%r5,16(%r1)		/* restore saved sprgs (curcpu) */
    247   1.9      matt 	mtsprg0	%r5
    248   1.9      matt 	lwz	%r5,20(%r1)
    249   1.9      matt 	mtsprg1	%r5
    250   1.9      matt 	lwz	%r5,24(%r1)
    251   1.9      matt 	mtsprg2	%r5
    252   1.9      matt 	lwz	%r5,28(%r1)
    253   1.9      matt 	mtsprg3	%r5
    254   1.7   garbled 
    255  1.14   thorpej 	addi	%r1,%r1,48		/* pop stack frame and save area */
    256  1.14   thorpej 	lwz	%r0,4(%r1)		/* return address */
    257  1.14   thorpej 	mtlr	%r0
    258  1.14   thorpej 	blr
    259  1.14   thorpej 
    260  1.14   thorpej /*
    261  1.14   thorpej  * Call into OpenFirmware.
    262  1.14   thorpej  */
    263  1.14   thorpej ENTRY_NOPROFILE(openfirmware)
    264  1.14   thorpej 	mflr	%r0
    265  1.14   thorpej 	stw	%r0,4(%r1)		/* save return address */
    266  1.14   thorpej 
    267  1.14   thorpej 	/* Switch to OpenFirmware stack. */
    268  1.14   thorpej 	lis	%r7,firmstk+NBPG-16@ha
    269  1.14   thorpej 	addi	%r7,%r7,firmstk+NBPG-16@l
    270  1.14   thorpej 	stw	%r1,0(%r7)		/* stash away prev stack pointer */
    271  1.14   thorpej 	mr	%r1,%r7
    272  1.14   thorpej 
    273  1.14   thorpej 	lis	%r4,oftramp@ha
    274  1.14   thorpej 	lwz	%r4,oftramp@l(%r4)
    275  1.14   thorpej 
    276  1.14   thorpej 	mtctr	%r4
    277  1.14   thorpej 	bctrl
    278  1.14   thorpej 
    279  1.14   thorpej 	lwz	%r1,0(%r1)		/* restore previous stack pointer */
    280  1.13   thorpej 	lwz	%r0,4(%r1)		/* return address */
    281   1.7   garbled 	mtlr	%r0
    282   1.1      matt 	blr
    283