rmheader.S revision 1.3
1/*	$NetBSD: rmheader.S,v 1.3 2006/07/13 15:51:54 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	0			/* 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	mov	r0, #OSFSControl_AddFS
94	adr	r1, rmbase
95	mov	r2, #(fsib - rmbase)
96	mov	r3, #0
97	swi	XOS_FSControl
98	ldmfd	r13!, {pc}		/* If that failed, so do we */
99
100rmfinal:
101	stmfd	r13!, {r14}
102	mov	r0, #OSFSControl_RemoveFS
103	adr	r1, rmtitle
104	swi	XOS_FSControl
105	cmp	r0, r0			/* Clear V flag */
106	ldmfd	r13!, {pc}
107
108Lerror:
109	teq	pc, pc			/* In 26-bit mode? */
110	ldmneia	r13!, {r14}		/* If so, load up return address */
111	orrnes	pc, r14, #R15_FLAG_V	/* and return setting V flag */
112	mrs	r14, cpsr		/* Otherwise get cpsr */
113	orr	r14, r14, #PSR_V_bit	/* set V flag */
114	msr	cpsr_c, r14		/* put it back */
115	ldmfd	r13!, {pc}		/* and return */
116
117Loldbase:
118	.word	0
119L_DYNAMIC:
120	.word	_DYNAMIC - rmbase
121
122
123fsentry_open:
124	stmfd	r13!, {r0-r7, r14}
125	mov	r0, r13
126	adr	r14, fsentry_ret
127	b	nbfs_open
128
129fsentry_getbytes:
130	stmfd	r13!, {r0-r7, r14}
131	mov	r0, r13
132	adr	r14, fsentry_ret
133	b	nbfs_getbytes
134
135fsentry_putbytes:
136	stmfd	r13!, {r0-r7, r14}
137	mov	r0, r13
138	adr	r14, fsentry_ret
139	b	nbfs_putbytes
140
141fsentry_args:
142	stmfd	r13!, {r0-r7, r14}
143	mov	r0, r13
144	adr	r14, fsentry_ret
145	b	nbfs_args
146
147fsentry_close:
148	stmfd	r13!, {r0-r7, r14}
149	mov	r0, r13
150	adr	r14, fsentry_ret
151	b	nbfs_close
152
153fsentry_file:
154	stmfd	r13!, {r0-r7, r14}
155	mov	r0, r13
156	adr	r14, fsentry_ret
157	b	nbfs_file
158
159fsentry_func:
160	stmfd	r13!, {r0-r7, r14}
161	mov	r0, r13
162	adr	r14, fsentry_ret
163	b	nbfs_func
164
165fsentry_ret:
166	cmp	r0, #0
167	ldmeqfd	r13!, {r0-r7, pc}
168	add	r13, r13, #4
169	ldmfd	r13!, {r1-r7}
170	b	Lerror
171
172rmcmdtbl:
173	.asciz	"NBFS"			/* Command text */
174	.align
175	.word	rmcmd_nbfs - rmbase	/* Command code */
176	.byte	0x00			/* Min 0 parameters */
177	.byte	0x00			/* No GSTransed parameters */
178	.byte	0x00			/* Max 0 parameters */
179	.byte	0x00			/* Normal command */
180	.word	rmcmd_nbfs_syntax - rmbase /* Syntax message */
181	.word	rmcmd_nbfs_help - rmbase /* Help message */
182
183	.byte	0			/* end of list */
184
185rmcmd_nbfs_syntax:
186	.asciz	"Syntax: NBFS"
187rmcmd_nbfs_help:
188	.asciz	"*NBFS selects NBFS as the current filing system."
189	.align
190
191rmcmd_nbfs:
192	/* We're called with r0 -> command tail. */
193	stmfd	r13!, {r14}
194	mov	r0, #OSFSControl_SelectFS
195	adr	r1, rmtitle
196	swi	XOS_FSControl
197	ldmfd	r13!, {pc}
198