11.1Sjmcneill/*	$NetBSD: locore.S,v 1.1 2026/01/09 22:54:28 jmcneill Exp $	*/
21.1Sjmcneill/*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
31.1Sjmcneill
41.1Sjmcneill/*
51.1Sjmcneill * Copyright (C) 1995, 1996 Wolfgang Solfrank.
61.1Sjmcneill * Copyright (C) 1995, 1996 TooLs GmbH.
71.1Sjmcneill * All rights reserved.
81.1Sjmcneill *
91.1Sjmcneill * Redistribution and use in source and binary forms, with or without
101.1Sjmcneill * modification, are permitted provided that the following conditions
111.1Sjmcneill * are met:
121.1Sjmcneill * 1. Redistributions of source code must retain the above copyright
131.1Sjmcneill *    notice, this list of conditions and the following disclaimer.
141.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
151.1Sjmcneill *    notice, this list of conditions and the following disclaimer in the
161.1Sjmcneill *    documentation and/or other materials provided with the distribution.
171.1Sjmcneill * 3. All advertising materials mentioning features or use of this software
181.1Sjmcneill *    must display the following acknowledgement:
191.1Sjmcneill *	This product includes software developed by TooLs GmbH.
201.1Sjmcneill * 4. The name of TooLs GmbH may not be used to endorse or promote products
211.1Sjmcneill *    derived from this software without specific prior written permission.
221.1Sjmcneill *
231.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
241.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
251.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Sjmcneill * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
271.1Sjmcneill * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
281.1Sjmcneill * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
291.1Sjmcneill * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
301.1Sjmcneill * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
311.1Sjmcneill * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
321.1Sjmcneill * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331.1Sjmcneill */
341.1Sjmcneill
351.1Sjmcneill#include "opt_ddb.h"
361.1Sjmcneill#include "opt_kgdb.h"
371.1Sjmcneill#include "opt_ppcparam.h"
381.1Sjmcneill#include "assym.h"
391.1Sjmcneill
401.1Sjmcneill#include <sys/syscall.h>
411.1Sjmcneill
421.1Sjmcneill#include <machine/param.h>
431.1Sjmcneill#include <machine/psl.h>
441.1Sjmcneill#include <machine/trap.h>
451.1Sjmcneill#include <machine/asm.h>
461.1Sjmcneill
471.1Sjmcneill#include <powerpc/spr.h>
481.1Sjmcneill#include <powerpc/oea/spr.h>
491.1Sjmcneill#include <powerpc/oea/hid.h>
501.1Sjmcneill
511.1Sjmcneill#include "ksyms.h"
521.1Sjmcneill
531.1Sjmcneill/*
541.1Sjmcneill * Some instructions gas doesn't understand (yet?)
551.1Sjmcneill */
561.1Sjmcneill#define	bdneq	bdnzf 2,
571.1Sjmcneill
581.1Sjmcneill/*
591.1Sjmcneill * Globals
601.1Sjmcneill */
611.1SjmcneillGLOBAL(startsym)
621.1Sjmcneill	.long	0			/* start symbol table */
631.1SjmcneillGLOBAL(endsym)
641.1Sjmcneill	.long	0			/* end symbol table */
651.1Sjmcneill/*
661.1Sjmcneill * This symbol is here for the benefit of kvm_mkdb, and is supposed to
671.1Sjmcneill * mark the start of kernel text.
681.1Sjmcneill */
691.1Sjmcneill	.text
701.1Sjmcneill	.globl	_C_LABEL(kernel_text)
711.1Sjmcneill_C_LABEL(kernel_text):
721.1Sjmcneill
731.1Sjmcneill/*
741.1Sjmcneill * Startup entry.  Note, this must be the first thing in the text
751.1Sjmcneill * segment!
761.1Sjmcneill */
771.1Sjmcneill	.text
781.1Sjmcneill	.globl	__start
791.1Sjmcneill__start:
801.1Sjmcneill	b	__mmu_init
811.1Sjmcneill
821.1Sjmcneill	/*
831.1Sjmcneill	 * Command-line argument protocol supported by HBC.
841.1Sjmcneill	 */
851.1Sjmcneill	.long	0x5f617267	/* WII_ARGV_MAGIC */
861.1Sjmcneill	.globl	_C_LABEL(wii_argv)
871.1Sjmcneill_C_LABEL(wii_argv):
881.1Sjmcneill	.long	0		/* argv magic, set by loader */
891.1Sjmcneill	.long	0		/* command line */
901.1Sjmcneill	.long	0		/* command line length */
911.1Sjmcneill	.long	0		/* argc */
921.1Sjmcneill	.long	0		/* argv */
931.1Sjmcneill	.long	0		/* end of argv */
941.1Sjmcneill
951.1Sjmcneill__mmu_init:
961.1Sjmcneill	/* reset MMU to a known state */
971.1Sjmcneill#include "mmuinit.S"
981.1Sjmcneill
991.1Sjmcneill	/* compute end of kernel memory */
1001.1Sjmcneill	lis	%r4, _C_LABEL(end)@ha
1011.1Sjmcneill	addi	%r4, %r4, _C_LABEL(end)@l
1021.1Sjmcneill
1031.1Sjmcneill#if NKSYMS || defined(DDB) || defined(MODULAR)
1041.1Sjmcneill	/* If we had symbol table location we'd store it here and would've adjusted r4 here */
1051.1Sjmcneill	lis	%r7, _C_LABEL(startsym)@ha
1061.1Sjmcneill	addi	%r7, %r7, _C_LABEL(startsym)@l
1071.1Sjmcneill	stw	%r4, 0(%r7)
1081.1Sjmcneill	lis	%r7, _C_LABEL(endsym)@ha
1091.1Sjmcneill	addi	%r7, %r7,_C_LABEL(endsym)@l
1101.1Sjmcneill	stw	%r4, 0(%r7)
1111.1Sjmcneill#endif
1121.1Sjmcneill
1131.1Sjmcneill	lis	%r1, 0
1141.1Sjmcneill	INIT_CPUINFO(%r4, %r1, %r9, %r0)
1151.1Sjmcneill
1161.1Sjmcneill	lis	%r3, __start@ha
1171.1Sjmcneill	addi	%r3, %r3, __start@l
1181.1Sjmcneill
1191.1Sjmcneill	xor	%r5, %r5, %r5
1201.1Sjmcneill	xor	%r6, %r6, %r6
1211.1Sjmcneill	bl	_C_LABEL(initppc)
1221.1Sjmcneill
1231.1Sjmcneill	sync
1241.1Sjmcneill	isync
1251.1Sjmcneill	mfspr	%r8, SPR_HID0
1261.1Sjmcneill	ori	%r8, %r8, (HID0_ICE | HID0_DCE)@l
1271.1Sjmcneill	isync
1281.1Sjmcneill	mtspr	SPR_HID0, %r8
1291.1Sjmcneill	sync
1301.1Sjmcneill	isync
1311.1Sjmcneill
1321.1Sjmcneill	bl	_C_LABEL(main)
1331.1Sjmcneill
1341.1Sjmcneillloop:	b	loop			/* XXX not reached */
1351.1Sjmcneill
1361.1Sjmcneill	.globl	_C_LABEL(enable_intr)
1371.1Sjmcneill_C_LABEL(enable_intr):
1381.1Sjmcneill	mfmsr	%r3
1391.1Sjmcneill	ori	%r3, %r3, PSL_EE@l
1401.1Sjmcneill	mtmsr	%r3
1411.1Sjmcneill	blr
1421.1Sjmcneill
1431.1Sjmcneill	.globl	_C_LABEL(disable_intr)
1441.1Sjmcneill_C_LABEL(disable_intr):
1451.1Sjmcneill	mfmsr	%r3
1461.1Sjmcneill 	andi.	%r3, %r3, ~PSL_EE@l
1471.1Sjmcneill	mtmsr	%r3
1481.1Sjmcneill	blr
1491.1Sjmcneill
1501.1Sjmcneill/*
1511.1Sjmcneill * Include common switch / setfault code
1521.1Sjmcneill */
1531.1Sjmcneill#include <powerpc/powerpc/locore_subr.S>
1541.1Sjmcneill
1551.1Sjmcneill/*
1561.1Sjmcneill * Include common trap / exception code
1571.1Sjmcneill */
1581.1Sjmcneill#include <powerpc/powerpc/trap_subr.S>
1591.1Sjmcneill
1601.1Sjmcneill/*
1611.1Sjmcneill * Include PIO routines
1621.1Sjmcneill */
1631.1Sjmcneill#include <powerpc/powerpc/pio_subr.S>
164