xref: /openbsd/sys/arch/luna88k/stand/boot/locore.S (revision 5746cf29)
1*5746cf29Sguenther/*	$OpenBSD: locore.S,v 1.4 2022/12/06 18:50:59 guenther Exp $	*/
296f141a8Smiod
396f141a8Smiod/*
496f141a8Smiod * Copyright (c) 2013 Miodrag Vallat.
596f141a8Smiod *
696f141a8Smiod * Permission to use, copy, modify, and distribute this software for any
796f141a8Smiod * purpose with or without fee is hereby granted, provided that the above
896f141a8Smiod * copyright notice and this permission notice appear in all copies.
996f141a8Smiod *
1096f141a8Smiod * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1196f141a8Smiod * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1296f141a8Smiod * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1396f141a8Smiod * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1496f141a8Smiod * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1596f141a8Smiod * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1696f141a8Smiod * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1796f141a8Smiod */
1896f141a8Smiod/*
1996f141a8Smiod * Mach Operating System
2096f141a8Smiod * Copyright (c) 1993-1991 Carnegie Mellon University
2196f141a8Smiod * Copyright (c) 1991 OMRON Corporation
2296f141a8Smiod * All Rights Reserved.
2396f141a8Smiod *
2496f141a8Smiod * Permission to use, copy, modify and distribute this software and its
2596f141a8Smiod * documentation is hereby granted, provided that both the copyright
2696f141a8Smiod * notice and this permission notice appear in all copies of the
2796f141a8Smiod * software, derivative works or modified versions, and any portions
2896f141a8Smiod * thereof, and that both notices appear in supporting documentation.
2996f141a8Smiod *
3096f141a8Smiod * CARNEGIE MELLON AND OMRON ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
3196f141a8Smiod * CONDITION.  CARNEGIE MELLON AND OMRON DISCLAIM ANY LIABILITY OF ANY KIND
3296f141a8Smiod * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
3396f141a8Smiod *
3496f141a8Smiod * Carnegie Mellon requests users of this software to return to
3596f141a8Smiod *
3696f141a8Smiod *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
3796f141a8Smiod *  School of Computer Science
3896f141a8Smiod *  Carnegie Mellon University
3996f141a8Smiod *  Pittsburgh PA 15213-3890
4096f141a8Smiod *
4196f141a8Smiod * any improvements or extensions that they make and grant Carnegie the
4296f141a8Smiod * rights to redistribute these changes.
4396f141a8Smiod */
4496f141a8Smiod
4596f141a8Smiod#define _KERNEL
4696f141a8Smiod#define _LOCORE
4796f141a8Smiod
4896f141a8Smiod#include <machine/asm.h>
49d2f66e2eSmiod#include <machine/board.h>
5096f141a8Smiod#include <machine/psl.h>
5196f141a8Smiod
5296f141a8Smiod	.text
5396f141a8Smiod
5496f141a8SmiodASGLOBAL(__start)
5596f141a8Smiod	NOP
5696f141a8Smiod	NOP
5796f141a8Smiod
5896f141a8SmiodASLOCAL(main_start)
5996f141a8Smiod	/*
6096f141a8Smiod	 * We want to only run on one processors, but still allow the
6196f141a8Smiod	 * other processors to run the kernel after it is loaded.
6296f141a8Smiod	 *
6396f141a8Smiod	 * To achieve this, we will `park' secondary processors into
6496f141a8Smiod	 * a spin loop, which they will exit once the kernel entry
6596f141a8Smiod	 * point and arguments are known.
6696f141a8Smiod	 *
6796f141a8Smiod	 * They will then proceed to run the kernel, as if the kernel
6896f141a8Smiod	 * had been directly booted from the PROM.
6996f141a8Smiod	 */
70*5746cf29Sguenther	or.u	%r3,  %r0,  %hi16(cpu_park_address)
71*5746cf29Sguenther	or	%r3,  %r3,  %lo16(cpu_park_address)
7296f141a8Smiod
73*5746cf29Sguenther	or.u	%r2,  %r0,  %hi16(cpu_park)
74*5746cf29Sguenther	or	%r2,  %r2,  %lo16(cpu_park)
7596f141a8Smiod	FLUSH_PIPELINE
7696f141a8Smiod	xmem	%r2,  %r3,  %r0
7796f141a8Smiod
7896f141a8Smiod	bcnd	eq0,  %r2, 1f	/* master! causing all the others to park */
7996f141a8Smiod	jmp	%r2		/* park ourselves */
8096f141a8Smiod
8196f141a8Smiod1:
8296f141a8Smiod	/* clear BSS */
83*5746cf29Sguenther	or.u	%r2, %r0, %hi16(edata)
84*5746cf29Sguenther	or	%r2, %r2, %lo16(edata)
85*5746cf29Sguenther	or.u	%r4, %r0, %hi16(end)
86*5746cf29Sguenther	or	%r4, %r4, %lo16(end)
8796f141a8Smiod1:	st	%r0, %r2, %r0
8896f141a8Smiod	addu	%r2, %r2, 4
8996f141a8Smiod	cmp	%r3, %r2, %r4
9096f141a8Smiod	bb1	ne,  %r3, 1b
9196f141a8Smiod
9296f141a8Smiod	/* setup stack, below our image */
93*5746cf29Sguenther	or.u	%r31, %r0,  %hi16(__start)
94*5746cf29Sguenther	or	%r31, %r31, %lo16(__start)
9596f141a8Smiod
9696f141a8Smiod	/* read dip switch settings */
97d2f66e2eSmiod	or.u	%r11, %r0,  %hi16(OBIO_PIO0A)
98d2f66e2eSmiod	ld.bu	%r10, %r11, %lo16(OBIO_PIO0A)
9996f141a8Smiod	mak	%r10, %r10, 0<8>
100d2f66e2eSmiod	ld.bu	%r12, %r11, %lo16(OBIO_PIO0B)
10196f141a8Smiod	or	%r10, %r10, %r12
10296f141a8Smiod
103*5746cf29Sguenther	or.u	%r11, %r0,  %hi16(dipswitch)
104*5746cf29Sguenther	st.h	%r10, %r11, %lo16(dipswitch)
10596f141a8Smiod
106*5746cf29Sguenther	bsr	main
107*5746cf29Sguenther	bsr	_rtt
10896f141a8Smiod1:	br	1b
10996f141a8Smiod
11096f141a8SmiodASLOCAL(cpu_park)
11196f141a8Smiod	/* spin a while */
11296f141a8Smiod	or.u	%r2,  %r0,  1
11396f141a8Smiod9:
11496f141a8Smiod	subu	%r2,  %r2,  1
11596f141a8Smiod	bcnd	ne0,  %r2,  9b
11696f141a8Smiod
11796f141a8Smiod	/* if kernel entry point is known, exit */
118*5746cf29Sguenther	or.u	%r1,  %r0,  %hi16(cpu_boot)
119*5746cf29Sguenther	ld	%r1,  %r1,  %lo16(cpu_boot)
120*5746cf29Sguenther	bcnd	eq0,  %r1,  cpu_park
12196f141a8Smiod
12296f141a8Smiod	or.u	%r2,  %r0,  1
12396f141a8Smiod9:
12496f141a8Smiod	subu	%r2,  %r2,  1
12596f141a8Smiod	bcnd	ne0,  %r2,  9b
12696f141a8Smiod
127*5746cf29Sguenther	or.u	%r2,  %r0, %hi16(cpu_bootarg1)
128*5746cf29Sguenther	ld	%r2,  %r2, %lo16(cpu_bootarg1)
129*5746cf29Sguenther	or.u	%r3,  %r0, %hi16(cpu_bootarg2)
130*5746cf29Sguenther	ld	%r3,  %r3, %lo16(cpu_bootarg2)
131*5746cf29Sguenther	or.u	%r4,  %r0, %hi16(cpu_bootarg3)
132*5746cf29Sguenther	ld	%r4,  %r4, %lo16(cpu_bootarg3)
133*5746cf29Sguenther	or.u	%r5,  %r0, %hi16(cpu_bootarg4)
134*5746cf29Sguenther	ld	%r5,  %r5, %lo16(cpu_bootarg4)
13596f141a8Smiod
13696f141a8Smiod	jmp	%r1
13796f141a8Smiod
13896f141a8SmiodGLOBAL(delay)
13996f141a8Smiod	bcnd	eq0, %r2, 2f
140*5746cf29Sguenther	or.u	%r3, %r0, %hi16(cpuspeed)
141*5746cf29Sguenther	ld	%r3, %r3, %lo16(cpuspeed)
14296f141a8Smiod	mul	%r4, %r2, %r3
14396f141a8Smiod	subu	%r4, %r4, 4
14496f141a8Smiod1:
14596f141a8Smiod	bcnd.n	gt0, %r4, 1b
14696f141a8Smiod	 subu	%r4, %r4, 2
14796f141a8Smiod2:
14896f141a8Smiod	jmp	%r1
14996f141a8Smiod
15096f141a8Smiod	.data
15196f141a8Smiod
15296f141a8SmiodASLOCAL(cpu_park_address)
15396f141a8Smiod	.word	0
154