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