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