Home | History | Annotate | Line # | Download | only in nbfs
      1 /*	$NetBSD: rmheader.S,v 1.5 2021/02/06 21:45:38 joerg 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 
     39 .syntax unified
     40 
     41 rmbase:
     42 	.word	0			/* Start code */
     43 	.word	rminit - rmbase		/* Initialisation code */
     44 	.word	rmfinal - rmbase	/* Finalisation code */
     45 	.word	rmservice - rmbase	/* Service call handler */
     46 	.word	rmtitle - rmbase	/* Title string */
     47 	.word	rmhelp - rmbase		/* Help string */
     48 	.word	rmcmdtbl - rmbase	/* Help and command keyword table */
     49 	.word	0			/* SWI chunk base number */
     50 	.word	0			/* SWI handler code offset */
     51 	.word	0			/* SWI decoding table offset */
     52 	.word	0			/* SWI decoding code offset */
     53 	.word	0			/* Messages filename offset */
     54 	.word	flags - rmbase		/* Module flags extension offset */
     55 
     56 fsib:	/* Filing system information block */
     57 	.word	rmtitle - rmbase	/* Filing system name */
     58 	.word	rmtitle - rmbase	/* Filing system boot text */
     59 	.word	fsentry_open - rmbase
     60 	.word	fsentry_getbytes - rmbase
     61 	.word	fsentry_putbytes - rmbase
     62 	.word	fsentry_args - rmbase
     63 	.word	fsentry_close - rmbase
     64 	.word	fsentry_file - rmbase
     65 	.word	fileswitch_SUPPORTS_SPECIAL | fileswitch_READ_ONLY | NBFS_FSNUM
     66 	.word	fsentry_func - rmbase
     67 	.word	0			/* FSEntry_GBPB */
     68 	.word	0			/* Extra information word */
     69 
     70 rmtitle:
     71 	.asciz	"NBFS"
     72 	.align
     73 flags:
     74 	.word	0			/* not 32 bit compatible */
     75 
     76 rminit:
     77 	/*
     78 	 * Module initialisation code
     79 	 *
     80 	 * On entry:
     81 	 * r10 = pointer to environment string
     82 	 * r11 = I/O base or instantiation number
     83 	 * r12 = pointer to private word
     84 	 * r14 = return address
     85 	 */
     86 	stmfd	r13!, {r14}
     87 	ldr	r1, Loldbase		/* Get old base address */
     88 	adr	r2, rmbase		/* Get new base address */
     89 	str	r2, Loldbase		/* New is the new old */
     90 	ldr	r0, L_DYNAMIC		/* Pointer to the dynamic table */
     91 	add	r0, r0, r2		/* ... relocated appropriately */
     92 	bl	relocate_self		/* Call the relocation code */
     93 	cmp	r0, #0
     94 	bne	Lerror
     95 	bl	Laddfs
     96 	ldmfd	r13!, {pc}
     97 
     98 Laddfs:
     99 	stmfd	r13!, {r14}
    100 	mov	r0, #OSFSControl_AddFS
    101 	adr	r1, rmbase
    102 	ldr	r2, =(fsib - rmbase)
    103 	mov	r3, #0
    104 	swi	XOS_FSControl
    105 	ldmfd	r13!, {pc}		/* If that failed, so do we */
    106 
    107 rmfinal:
    108 	stmfd	r13!, {r14}
    109 	mov	r0, #OSFSControl_RemoveFS
    110 	adr	r1, rmtitle
    111 	swi	XOS_FSControl
    112 	cmp	r0, r0			/* Clear V flag */
    113 	ldmfd	r13!, {pc}
    114 
    115 rmservice:
    116 	cmp	r1, #Service_FSRedeclare
    117 	movne	pc, r14
    118 	stmfd	r13!, {r0-r3, r14}
    119 	bl	Laddfs
    120 	ldmfd	r13!, {r0-r3, pc}
    121 
    122 Lerror:
    123 	teq	pc, pc			/* In 26-bit mode? */
    124 	ldmfdne	r13!, {r14}		/* If so, load up return address */
    125 	orrsne	pc, r14, #R15_FLAG_V	/* and return setting V flag */
    126 	mrs	r14, cpsr		/* Otherwise get cpsr */
    127 	orr	r14, r14, #PSR_V_bit	/* set V flag */
    128 	msr	cpsr_c, r14		/* put it back */
    129 	ldmfd	r13!, {pc}		/* and return */
    130 
    131 Loldbase:
    132 	.word	0
    133 L_DYNAMIC:
    134 	.word	_DYNAMIC - rmbase
    135 
    136 
    137 fsentry_open:
    138 	stmfd	r13!, {r0-r7, r14}
    139 	mov	r0, r13
    140 	adr	r14, fsentry_ret
    141 	b	nbfs_open
    142 
    143 fsentry_getbytes:
    144 	stmfd	r13!, {r0-r7, r14}
    145 	mov	r0, r13
    146 	adr	r14, fsentry_ret
    147 	b	nbfs_getbytes
    148 
    149 fsentry_putbytes:
    150 	stmfd	r13!, {r0-r7, r14}
    151 	mov	r0, r13
    152 	adr	r14, fsentry_ret
    153 	b	nbfs_putbytes
    154 
    155 fsentry_args:
    156 	stmfd	r13!, {r0-r7, r14}
    157 	mov	r0, r13
    158 	adr	r14, fsentry_ret
    159 	b	nbfs_args
    160 
    161 fsentry_close:
    162 	stmfd	r13!, {r0-r7, r14}
    163 	mov	r0, r13
    164 	adr	r14, fsentry_ret
    165 	b	nbfs_close
    166 
    167 fsentry_file:
    168 	stmfd	r13!, {r0-r7, r14}
    169 	mov	r0, r13
    170 	adr	r14, fsentry_ret
    171 	b	nbfs_file
    172 
    173 fsentry_func:
    174 	stmfd	r13!, {r0-r7, r14}
    175 	mov	r0, r13
    176 	adr	r14, fsentry_ret
    177 	b	nbfs_func
    178 
    179 fsentry_ret:
    180 	cmp	r0, #0
    181 	popeq	{r0-r7, pc}
    182 	add	r13, r13, #4
    183 	pop	{r1-r7}
    184 	b	Lerror
    185 
    186 rmcmdtbl:
    187 	.asciz	"NBFS"			/* Command text */
    188 	.align
    189 	.word	rmcmd_nbfs - rmbase	/* Command code */
    190 	.byte	0x00			/* Min 0 parameters */
    191 	.byte	0x00			/* No GSTransed parameters */
    192 	.byte	0x00			/* Max 0 parameters */
    193 	.byte	0x00			/* Normal command */
    194 	.word	rmcmd_nbfs_syntax - rmbase /* Syntax message */
    195 	.word	rmcmd_nbfs_help - rmbase /* Help message */
    196 
    197 	.byte	0			/* end of list */
    198 
    199 rmcmd_nbfs_syntax:
    200 	.asciz	"Syntax: NBFS"
    201 rmcmd_nbfs_help:
    202 	.asciz	"*NBFS selects NBFS as the current filing system."
    203 	.align
    204 
    205 rmcmd_nbfs:
    206 	/* We're called with r0 -> command tail. */
    207 	stmfd	r13!, {r14}
    208 	mov	r0, #OSFSControl_SelectFS
    209 	adr	r1, rmtitle
    210 	swi	XOS_FSControl
    211 	ldmfd	r13!, {pc}
    212