rmheader.S revision 1.4
1/*	$NetBSD: rmheader.S,v 1.4 2006/07/13 16:09:58 bjh21 Exp $	*/
2
3/*-
4 * Copyright (c) 2001, 2006 Ben Harris
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * Relocatable module header for NBFS.
32 */
33
34#include <arm/armreg.h>
35#include <riscoscalls.h>
36
37#include "nbfs.h"
38
39rmbase:
40	.word	0			/* Start code */
41	.word	rminit - rmbase		/* Initialisation code */
42	.word	rmfinal - rmbase	/* Finalisation code */
43	.word	rmservice - rmbase	/* Service call handler */
44	.word	rmtitle - rmbase	/* Title string */
45	.word	rmhelp - rmbase		/* Help string */
46	.word	rmcmdtbl - rmbase	/* Help and command keyword table */
47	.word	0			/* SWI chunk base number */
48	.word	0			/* SWI handler code offset */
49	.word	0			/* SWI decoding table offset */
50	.word	0			/* SWI decoding code offset */
51	.word	0			/* Messages filename offset */
52	.word	flags - rmbase		/* Module flags extension offset */
53
54fsib:	/* Filing system information block */
55	.word	rmtitle - rmbase	/* Filing system name */
56	.word	rmtitle - rmbase	/* Filing system boot text */
57	.word	fsentry_open - rmbase
58	.word	fsentry_getbytes - rmbase
59	.word	fsentry_putbytes - rmbase
60	.word	fsentry_args - rmbase
61	.word	fsentry_close - rmbase
62	.word	fsentry_file - rmbase
63	.word	fileswitch_SUPPORTS_SPECIAL | fileswitch_READ_ONLY | NBFS_FSNUM
64	.word	fsentry_func - rmbase
65	.word	0			/* FSEntry_GBPB */
66	.word	0			/* Extra information word */
67
68rmtitle:
69	.asciz	"NBFS"
70	.align
71flags:
72	.word	0			/* not 32 bit compatible */
73
74rminit:
75	/*
76	 * Module initialisation code
77	 *
78	 * On entry:
79	 * r10 = pointer to environment string
80	 * r11 = I/O base or instantiation number
81	 * r12 = pointer to private word
82	 * r14 = return address
83	 */
84	stmfd	r13!, {r14}
85	ldr	r1, Loldbase		/* Get old base address */
86	adr	r2, rmbase		/* Get new base address */
87	str	r2, Loldbase		/* New is the new old */
88	ldr	r0, L_DYNAMIC		/* Pointer to the dynamic table */
89	add	r0, r0, r2		/* ... relocated appropriately */
90	bl	relocate_self		/* Call the relocation code */
91	cmp	r0, #0
92	bne	Lerror
93	bl	Laddfs
94	ldmfd	r13!, {pc}
95
96Laddfs:
97	stmfd	r13!, {r14}
98	mov	r0, #OSFSControl_AddFS
99	adr	r1, rmbase
100	mov	r2, #(fsib - rmbase)
101	mov	r3, #0
102	swi	XOS_FSControl
103	ldmfd	r13!, {pc}		/* If that failed, so do we */
104
105rmfinal:
106	stmfd	r13!, {r14}
107	mov	r0, #OSFSControl_RemoveFS
108	adr	r1, rmtitle
109	swi	XOS_FSControl
110	cmp	r0, r0			/* Clear V flag */
111	ldmfd	r13!, {pc}
112
113rmservice:
114	cmp	r1, #Service_FSRedeclare
115	movne	pc, r14
116	stmfd	r13!, {r0-r3, r14}
117	bl	Laddfs
118	ldmfd	r13!, {r0-r3, pc}
119
120Lerror:
121	teq	pc, pc			/* In 26-bit mode? */
122	ldmneia	r13!, {r14}		/* If so, load up return address */
123	orrnes	pc, r14, #R15_FLAG_V	/* and return setting V flag */
124	mrs	r14, cpsr		/* Otherwise get cpsr */
125	orr	r14, r14, #PSR_V_bit	/* set V flag */
126	msr	cpsr_c, r14		/* put it back */
127	ldmfd	r13!, {pc}		/* and return */
128
129Loldbase:
130	.word	0
131L_DYNAMIC:
132	.word	_DYNAMIC - rmbase
133
134
135fsentry_open:
136	stmfd	r13!, {r0-r7, r14}
137	mov	r0, r13
138	adr	r14, fsentry_ret
139	b	nbfs_open
140
141fsentry_getbytes:
142	stmfd	r13!, {r0-r7, r14}
143	mov	r0, r13
144	adr	r14, fsentry_ret
145	b	nbfs_getbytes
146
147fsentry_putbytes:
148	stmfd	r13!, {r0-r7, r14}
149	mov	r0, r13
150	adr	r14, fsentry_ret
151	b	nbfs_putbytes
152
153fsentry_args:
154	stmfd	r13!, {r0-r7, r14}
155	mov	r0, r13
156	adr	r14, fsentry_ret
157	b	nbfs_args
158
159fsentry_close:
160	stmfd	r13!, {r0-r7, r14}
161	mov	r0, r13
162	adr	r14, fsentry_ret
163	b	nbfs_close
164
165fsentry_file:
166	stmfd	r13!, {r0-r7, r14}
167	mov	r0, r13
168	adr	r14, fsentry_ret
169	b	nbfs_file
170
171fsentry_func:
172	stmfd	r13!, {r0-r7, r14}
173	mov	r0, r13
174	adr	r14, fsentry_ret
175	b	nbfs_func
176
177fsentry_ret:
178	cmp	r0, #0
179	ldmeqfd	r13!, {r0-r7, pc}
180	add	r13, r13, #4
181	ldmfd	r13!, {r1-r7}
182	b	Lerror
183
184rmcmdtbl:
185	.asciz	"NBFS"			/* Command text */
186	.align
187	.word	rmcmd_nbfs - rmbase	/* Command code */
188	.byte	0x00			/* Min 0 parameters */
189	.byte	0x00			/* No GSTransed parameters */
190	.byte	0x00			/* Max 0 parameters */
191	.byte	0x00			/* Normal command */
192	.word	rmcmd_nbfs_syntax - rmbase /* Syntax message */
193	.word	rmcmd_nbfs_help - rmbase /* Help message */
194
195	.byte	0			/* end of list */
196
197rmcmd_nbfs_syntax:
198	.asciz	"Syntax: NBFS"
199rmcmd_nbfs_help:
200	.asciz	"*NBFS selects NBFS as the current filing system."
201	.align
202
203rmcmd_nbfs:
204	/* We're called with r0 -> command tail. */
205	stmfd	r13!, {r14}
206	mov	r0, #OSFSControl_SelectFS
207	adr	r1, rmtitle
208	swi	XOS_FSControl
209	ldmfd	r13!, {pc}
210