Home | History | Annotate | Line # | Download | only in nbfs
rmheader.S revision 1.1.4.2
      1 /*	$NetBSD: rmheader.S,v 1.1.4.2 2006/04/19 02:31:57 elad 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 rmbase:
     38 	.word	0			/* Start code */
     39 	.word	rminit - rmbase		/* Initialisation code */
     40 	.word	rmfinal - rmbase	/* Finalisation code */
     41 	.word	0			/* Service call handler */
     42 	.word	rmtitle - rmbase	/* Title string */
     43 	.word	rmhelp - rmbase		/* Help string */
     44 	.word	0			/* Help and command keyword table */
     45 	.word	0			/* SWI chunk base number */
     46 	.word	0			/* SWI handler code offset */
     47 	.word	0			/* SWI decoding table offset */
     48 	.word	0			/* SWI decoding code offset */
     49 	.word	0			/* Messages filename offset */
     50 	.word	flags - rmbase		/* Module flags extension offset */
     51 
     52 fsib:	/* Filing system information block */
     53 	.word	rmtitle - rmbase	/* Filing system name */
     54 	.word	rmtitle - rmbase	/* Filing system boot text */
     55 	.word	fsentry_open - rmbase
     56 	.word	fsentry_getbytes - rmbase
     57 	.word	fsentry_putbytes - rmbase
     58 	.word	fsentry_args - rmbase
     59 	.word	fsentry_close - rmbase
     60 	.word	fsentry_file - rmbase
     61 	.word	fileswitch_SUPPORTS_SPECIAL | fileswitch_READ_ONLY | \
     62 		0xf0 /* borrow UnixFS's number for now */
     63 	.word	fsentry_func - rmbase
     64 	.word	0			/* FSEntry_GBPB */
     65 	.word	0			/* Extra information word */
     66 
     67 rmtitle:
     68 	.asciz	"NBFS"
     69 	.align
     70 flags:
     71 	.word	0			/* not 32 bit compatible */
     72 
     73 rminit:
     74 	/*
     75 	 * Module initialisation code
     76 	 *
     77 	 * On entry:
     78 	 * r10 = pointer to environment string
     79 	 * r11 = I/O base or instantiation number
     80 	 * r12 = pointer to private word
     81 	 * r14 = return address
     82 	 */
     83 	stmfd	r13!, {r14}
     84 	ldr	r1, Loldbase		/* Get old base address */
     85 	adr	r2, rmbase		/* Get new base address */
     86 	str	r2, Loldbase		/* New is the new old */
     87 	ldr	r0, L_DYNAMIC		/* Pointer to the dynamic table */
     88 	add	r0, r0, r2		/* ... relocated appropriately */
     89 	bl	relocate_self		/* Call the relocation code */
     90 	cmp	r0, #0
     91 	bne	Lerror
     92 	mov	r0, #OSFSControl_AddFS
     93 	adr	r1, rmbase
     94 	mov	r2, #(fsib - rmbase)
     95 	mov	r3, #0
     96 	swi	XOS_FSControl
     97 	ldmfd	r13!, {pc}		/* If that failed, so do we */
     98 
     99 rmfinal:
    100 	stmfd	r13!, {r14}
    101 	mov	r0, #OSFSControl_RemoveFS
    102 	adr	r1, rmtitle
    103 	swi	XOS_FSControl
    104 	cmp	r0, r0			/* Clear V flag */
    105 	ldmfd	r13!, {pc}
    106 
    107 Lerror:
    108 	teq	pc, pc			/* In 26-bit mode? */
    109 	ldmneia	r13!, {r14}		/* If so, load up return address */
    110 	orrnes	pc, r14, #R15_FLAG_V	/* and return setting V flag */
    111 	mrs	r14, cpsr		/* Otherwise get cpsr */
    112 	orr	r14, r14, #PSR_V_bit	/* set V flag */
    113 	msr	cpsr_c, r14		/* put it back */
    114 	ldmfd	r13!, {pc}		/* and return */
    115 
    116 Loldbase:
    117 	.word	0
    118 L_DYNAMIC:
    119 	.word	_DYNAMIC - rmbase
    120 
    121 
    122 fsentry_open:
    123 	stmfd	r13!, {r0-r7, r14}
    124 	mov	r0, r13
    125 	adr	r14, fsentry_ret
    126 	b	nbfs_open
    127 
    128 fsentry_getbytes:
    129 	stmfd	r13!, {r0-r7, r14}
    130 	mov	r0, r13
    131 	adr	r14, fsentry_ret
    132 	b	nbfs_getbytes
    133 
    134 fsentry_putbytes:
    135 	stmfd	r13!, {r0-r7, r14}
    136 	mov	r0, r13
    137 	adr	r14, fsentry_ret
    138 	b	nbfs_putbytes
    139 
    140 fsentry_args:
    141 	stmfd	r13!, {r0-r7, r14}
    142 	mov	r0, r13
    143 	adr	r14, fsentry_ret
    144 	b	nbfs_args
    145 
    146 fsentry_close:
    147 	stmfd	r13!, {r0-r7, r14}
    148 	mov	r0, r13
    149 	adr	r14, fsentry_ret
    150 	b	nbfs_close
    151 
    152 fsentry_file:
    153 	stmfd	r13!, {r0-r7, r14}
    154 	mov	r0, r13
    155 	adr	r14, fsentry_ret
    156 	b	nbfs_file
    157 
    158 fsentry_func:
    159 	stmfd	r13!, {r0-r7, r14}
    160 	mov	r0, r13
    161 	adr	r14, fsentry_ret
    162 	b	nbfs_func
    163 
    164 fsentry_ret:
    165 	cmp	r0, #0
    166 	ldmeqfd	r13!, {r0-r7, pc}
    167 	add	r13, r13, #4
    168 	ldmfd	r13!, {r1-r7}
    169 	b	Lerror