xref: /netbsd-src/sys/arch/acorn32/stand/boot32/rmheader.S (revision 95e1ffb15694e54f29f8baaa4232152b703c2a5a)
1*95e1ffb1Schristos/*	$NetBSD: rmheader.S,v 1.4 2005/12/11 12:16:08 christos Exp $	*/
246dbb0f2Sreinoud
346dbb0f2Sreinoud/*-
446dbb0f2Sreinoud * Copyright (c) 2001 Ben Harris
546dbb0f2Sreinoud * All rights reserved.
646dbb0f2Sreinoud *
746dbb0f2Sreinoud * Redistribution and use in source and binary forms, with or without
846dbb0f2Sreinoud * modification, are permitted provided that the following conditions
946dbb0f2Sreinoud * are met:
1046dbb0f2Sreinoud * 1. Redistributions of source code must retain the above copyright
1146dbb0f2Sreinoud *    notice, this list of conditions and the following disclaimer.
1246dbb0f2Sreinoud * 2. Redistributions in binary form must reproduce the above copyright
1346dbb0f2Sreinoud *    notice, this list of conditions and the following disclaimer in the
1446dbb0f2Sreinoud *    documentation and/or other materials provided with the distribution.
1546dbb0f2Sreinoud * 3. The name of the author may not be used to endorse or promote products
1646dbb0f2Sreinoud *    derived from this software without specific prior written permission.
1746dbb0f2Sreinoud *
1846dbb0f2Sreinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1946dbb0f2Sreinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2046dbb0f2Sreinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2146dbb0f2Sreinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2246dbb0f2Sreinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2346dbb0f2Sreinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2446dbb0f2Sreinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2546dbb0f2Sreinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2646dbb0f2Sreinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2746dbb0f2Sreinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2846dbb0f2Sreinoud */
2946dbb0f2Sreinoud
3046dbb0f2Sreinoud/*
3146dbb0f2Sreinoud * Relocatable module header for boot32.
3246dbb0f2Sreinoud */
3346dbb0f2Sreinoud
3446dbb0f2Sreinoud#include <riscoscalls.h>
3546dbb0f2Sreinoud
3646dbb0f2Sreinoudrmbase:
3746dbb0f2Sreinoud	b	rmstart			/* Start code */
3846dbb0f2Sreinoud	.word	0			/* Initialisation code */
3946dbb0f2Sreinoud	.word	0			/* Finalisation code */
4046dbb0f2Sreinoud	.word	0			/* Service call handler */
4146dbb0f2Sreinoud	.word	rmtitle - rmbase	/* Title string */
4246dbb0f2Sreinoud	.word	rmhelp - rmbase		/* Help string */
4346dbb0f2Sreinoud	.word	rmcmdtbl - rmbase	/* Help and command keyword table */
44de7bc02bSgavan	.word	0			/* SWI chunk base number */
45de7bc02bSgavan	.word	0			/* SWI handler code offset */
46de7bc02bSgavan	.word	0			/* SWI decoding table offset */
47de7bc02bSgavan	.word	0			/* SWI decoding code offset */
48de7bc02bSgavan	.word	0			/* Messages filename offset */
49de7bc02bSgavan	.word	flags - rmbase		/* Module flags extension offset */
5046dbb0f2Sreinoud
5146dbb0f2Sreinoudrmtitle:
5246dbb0f2Sreinoud	.asciz	"boot32"
5346dbb0f2Sreinoud	.align
54de7bc02bSgavanflags:
55de7bc02bSgavan	.word	1			/* 32 bit compatible */
56de7bc02bSgavan
5746dbb0f2Sreinoudrmstart:
5846dbb0f2Sreinoud	/*
5946dbb0f2Sreinoud	 * This entry point is called when we're started up as an application,
6046dbb0f2Sreinoud	 * so we're allowed to use application workspace.  This is good,
6146dbb0f2Sreinoud	 * because most of our code is linked to run at 0x8000.
6246dbb0f2Sreinoud	 */
6346dbb0f2Sreinoud	mov	r0, #0x8000
6446dbb0f2Sreinoud	adr	r1, rmbase
6546dbb0f2Sreinoud	ldr	r2, Lsize
6646dbb0f2SreinoudLcopyloop:
6746dbb0f2Sreinoud	ldr	r3, [r1], #4
6846dbb0f2Sreinoud	str	r3, [r0], #4
6946dbb0f2Sreinoud	subs	r2, r2, #4
7046dbb0f2Sreinoud	bgt	Lcopyloop
7146dbb0f2Sreinoud	mov	r0, #0x8000
7246dbb0f2Sreinoud	mov	r1, #128*1024
7346dbb0f2SreinoudLDsync_loop:
7446dbb0f2Sreinoud	ldrb	r3, [r0], #1
7546dbb0f2Sreinoud	subs	r1, r1, #1
7646dbb0f2Sreinoud	bgt	LDsync_loop
7746dbb0f2Sreinoud	ldr	r0, Lstart
7846dbb0f2Sreinoud	mov	pc, r0
7946dbb0f2Sreinoud
8034ce26d1Sreinoud	/*
8134ce26d1Sreinoud	 * The size of the code/data to be moved is not `end - rmbase' but
8234ce26d1Sreinoud	 * `__bss_start__ - rmbase' for the module is loaded into RISC OS
8334ce26d1Sreinoud	 * based on the filesize where as NetBSD doesn't have to include all
8434ce26d1Sreinoud	 * the bss space into the file itself. In some odd cases the
8534ce26d1Sreinoud	 * relocatable module area can be smaller than the module + bss and
8634ce26d1Sreinoud	 * thus bomb out.
8734ce26d1Sreinoud	 */
8846dbb0f2SreinoudLsize:
8934ce26d1Sreinoud	.word	__bss_start__ - rmbase
9046dbb0f2SreinoudLstart:
9146dbb0f2Sreinoud	.word	_start
9246dbb0f2Sreinoud
9346dbb0f2Sreinoudrmcmdtbl:
9446dbb0f2Sreinoud	.asciz	"boot32"		/* Command text */
9546dbb0f2Sreinoud	.align
9646dbb0f2Sreinoud	.word	rmcmd_boot32 - rmbase	/* Command code */
9746dbb0f2Sreinoud	.byte	0x00			/* Min 0 parameters */
9846dbb0f2Sreinoud	.byte	0x00			/* No GSTransed parameters */
9946dbb0f2Sreinoud	.byte	0xff			/* Max 255 parameters */
10046dbb0f2Sreinoud	.byte	0x00			/* Normal command */
10146dbb0f2Sreinoud	.word	0			/* No syntax message */
10246dbb0f2Sreinoud	.word	0			/* No help message */
10346dbb0f2Sreinoud
10446dbb0f2Sreinoudrmcmd_boot32:
10546dbb0f2Sreinoud	/* We're called with r0 -> command tail. */
10646dbb0f2Sreinoud	stmfd	r13!, {r14}
10746dbb0f2Sreinoud	mov	r2, r0
10846dbb0f2Sreinoud	mov	r0, #2
10946dbb0f2Sreinoud	adr	r1, rmtitle
11046dbb0f2Sreinoud	swi	XOS_Module
11146dbb0f2Sreinoud	ldmfd	r13!, {pc}
112