[1] | 1 | /* |
---|
| 2 | * hal_uspace.c - implementation of Generic User Space Access API for MIPS32 |
---|
| 3 | * |
---|
[626] | 4 | * Author Alain Greiner (2016,2017,2018,2019) |
---|
[1] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH.. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH. is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH. is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[1] | 25 | #include <hal_uspace.h> |
---|
[626] | 26 | #include <hal_special.h> |
---|
[1] | 27 | #include <hal_irqmask.h> |
---|
| 28 | |
---|
[425] | 29 | #include <printk.h> |
---|
| 30 | #include <thread.h> |
---|
| 31 | |
---|
[626] | 32 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | // This function moves <size> bytes from a source buffer in user virtual space, |
---|
[637] | 34 | // defined by the <u_src_ptr> argument, to a destination kernel buffer, defined by the |
---|
| 35 | // <k_dst_xp> argument. |
---|
| 36 | // It works in a critical section, as it modifies two CP2 registers: |
---|
[626] | 37 | // It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the |
---|
| 38 | // user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer. |
---|
| 39 | // If the two buffers are aligned on a word boundary, it moves the data word per word |
---|
| 40 | // in a first loop, and moves byte per byte the remaining bytes in a second loop. |
---|
| 41 | // If the buffers are not aligned, it moves all data byte per byte. |
---|
| 42 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[637] | 43 | // @ k_dst_xp : extended pointer on destination kernel buffer |
---|
| 44 | // @ u_src_ptr : pointer on source user buffer |
---|
[626] | 45 | // @ size : number of bytes to move |
---|
| 46 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[637] | 47 | void hal_copy_from_uspace( xptr_t k_dst_xp, |
---|
| 48 | void * u_src_ptr, |
---|
[425] | 49 | uint32_t size ) |
---|
[1] | 50 | { |
---|
| 51 | uint32_t save_sr; |
---|
[637] | 52 | uint32_t words; // number of words (if buffers aligned) |
---|
| 53 | uint32_t src = (uint32_t)u_src_ptr; |
---|
| 54 | uint32_t dst = (uint32_t)GET_PTR( k_dst_xp ); |
---|
| 55 | uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp ); |
---|
| 56 | |
---|
[626] | 57 | |
---|
[610] | 58 | #if DEBUG_HAL_USPACE |
---|
[626] | 59 | thread_t * this = CURRENT_THREAD; |
---|
| 60 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 61 | if( cycle > DEBUG_HAL_USPACE ) |
---|
| 62 | printk("\n[%s] thread[%x,%x] enter / %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n", |
---|
[637] | 63 | __FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle ); |
---|
[610] | 64 | #endif |
---|
| 65 | |
---|
[626] | 66 | if( (dst & 0x3) || (src & 0x3) ) words = 0; // do it all in bytes |
---|
| 67 | else words = size >> 2; |
---|
[1] | 68 | |
---|
[626] | 69 | // enter critical section |
---|
[1] | 70 | hal_disable_irq( &save_sr ); |
---|
| 71 | |
---|
[626] | 72 | asm volatile( ".set noreorder \n" |
---|
| 73 | |
---|
| 74 | /* initialise registers */ |
---|
| 75 | "move $8, %0 \n" /* $8 <= src */ |
---|
| 76 | "move $9, %1 \n" /* $9 <= dst */ |
---|
| 77 | "move $10, %2 \n" /* $10 <= words */ |
---|
| 78 | "move $11, %3 \n" /* $11 <= size */ |
---|
| 79 | "mfc2 $12, $1 \n" /* $12 <= old MMU_MODE */ |
---|
| 80 | "ori $13, $12, 0x4 \n" /* $13 <= MMU_MODE with DTLB */ |
---|
[407] | 81 | |
---|
[637] | 82 | /* save old MMU_DATA_EXT and set cxy in it */ |
---|
[626] | 83 | "mfc2 $16, $24 \n" /* $16 <= old MMU_DATA_EXT */ |
---|
[637] | 84 | "mtc2 %4, $24 \n" /* MMU_DATA_EXT <= cxy */ |
---|
[1] | 85 | |
---|
[626] | 86 | /* transfer one word per iteration in first loop if aligned */ |
---|
| 87 | "move $15, $10 \n" /* $15 <= words ($15 == i) */ |
---|
| 88 | "1: \n" |
---|
| 89 | "beq $15, $0, 2f \n" /* exit loop if (i==0) */ |
---|
| 90 | "nop \n" |
---|
| 91 | "mtc2 $13, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
| 92 | "lw $14, 0($8) \n" /* word from user space */ |
---|
| 93 | "mtc2 $12, $1 \n" /* restore old MMU_MODE */ |
---|
| 94 | "sw $14, 0($9) \n" /* word to kernel space */ |
---|
| 95 | "addi $15, $15, -1 \n" /* i-- */ |
---|
| 96 | "addi $8, $8, 4 \n" /* src += 4 bytes */ |
---|
| 97 | "j 1b \n" |
---|
| 98 | "addi $9, $9, 4 \n" /* dst += 4 bytes */ |
---|
[1] | 99 | |
---|
[626] | 100 | /* transfer one byte per iteration in this second loop */ |
---|
| 101 | "2: \n" |
---|
| 102 | "sll $15, $10, 2 \n" /* $15 <= words*4 ($15 == i) */ |
---|
| 103 | "3: \n" |
---|
| 104 | "beq $15, $11, 4f \n" /* exit loop if (i == size) */ |
---|
| 105 | "nop \n" |
---|
| 106 | "mtc2 $13, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
| 107 | "lb $14, 0($8) \n" /* byte from user space */ |
---|
| 108 | "mtc2 $12, $1 \n" /* restore omd MMU_MODE */ |
---|
| 109 | "sb $14, 0($9) \n" /* byte to kernel space */ |
---|
| 110 | "addi $15, $15, 1 \n" /* i++ */ |
---|
| 111 | "addi $8, $8, 1 \n" /* src += 1 byte */ |
---|
| 112 | "j 3b \n" |
---|
| 113 | "addi $9, $9, 1 \n" /* dst += 1 byte */ |
---|
[1] | 114 | |
---|
[626] | 115 | /* restore old MMU_DATA_EXT register */ |
---|
| 116 | "4: \n" |
---|
| 117 | "mtc2 $16, $24 \n" /* MMU__DATA_EXT <= $16 */ |
---|
| 118 | ".set reorder \n" |
---|
| 119 | : |
---|
[637] | 120 | : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy) |
---|
[626] | 121 | : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" ); |
---|
[1] | 122 | |
---|
[626] | 123 | // exit critical section |
---|
[1] | 124 | hal_restore_irq( save_sr ); |
---|
| 125 | |
---|
[610] | 126 | #if DEBUG_HAL_USPACE |
---|
[626] | 127 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 128 | if( cycle > DEBUG_HAL_USPACE ) |
---|
| 129 | printk("\n[%s] thread[%x,%x] moved %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n", |
---|
[637] | 130 | __FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle ); |
---|
[610] | 131 | #endif |
---|
| 132 | |
---|
[87] | 133 | } // end hal_copy_from_uspace() |
---|
| 134 | |
---|
[626] | 135 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 136 | // This function moves <size> bytes from a source kernel buffer, defined by the |
---|
[637] | 137 | // <k_src_xp> argument, to a destination buffer in user virtual space, defined by |
---|
| 138 | // the <u_dst_ptr> argument. |
---|
| 139 | // It works in a critical section, as it modifies two CP2 registers: |
---|
[626] | 140 | // It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the |
---|
| 141 | // user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer. |
---|
| 142 | // If the two buffers are aligned on a word boundary, it moves the data word per word |
---|
| 143 | // in a first loop, and moves byte per byte the remaining bytes in a second loop. |
---|
| 144 | // If the buffers are not aligned, it moves all data byte per byte. |
---|
| 145 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[637] | 146 | // @ u_dst_ptr : pointer on destination user buffer |
---|
| 147 | // @ k_src_xp : extended pointer on source kernel buffer |
---|
| 148 | // @ size : number of bytes to move |
---|
[626] | 149 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[637] | 150 | void hal_copy_to_uspace( void * u_dst_ptr, |
---|
| 151 | xptr_t k_src_xp, |
---|
[1] | 152 | uint32_t size ) |
---|
| 153 | { |
---|
| 154 | uint32_t save_sr; |
---|
[637] | 155 | uint32_t words; // number of words (if buffers aligned) |
---|
| 156 | uint32_t dst = (uint32_t)u_dst_ptr; |
---|
| 157 | uint32_t src = (uint32_t)GET_PTR( k_src_xp ); |
---|
| 158 | uint32_t cxy = (uint32_t)GET_CXY( k_src_xp ); |
---|
[1] | 159 | |
---|
[610] | 160 | #if DEBUG_HAL_USPACE |
---|
[626] | 161 | thread_t * this = CURRENT_THREAD; |
---|
| 162 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 163 | if( cycle > DEBUG_HAL_USPACE ) |
---|
| 164 | printk("\n[%s] thread[%x,%x] enter / %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n", |
---|
[637] | 165 | __FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle ); |
---|
[610] | 166 | #endif |
---|
| 167 | |
---|
[626] | 168 | if( (dst & 0x3) || (src & 0x3) ) words = 0; // not aligned |
---|
| 169 | else words = size >> 2; |
---|
[1] | 170 | |
---|
[626] | 171 | // enter critical section |
---|
[1] | 172 | hal_disable_irq( &save_sr ); |
---|
| 173 | |
---|
[626] | 174 | asm volatile( ".set noreorder \n" |
---|
| 175 | |
---|
| 176 | /* initialise registers */ |
---|
| 177 | "move $8, %0 \n" /* $8 <= k_src */ |
---|
| 178 | "move $9, %1 \n" /* $9 <= u_dst */ |
---|
| 179 | "move $10, %2 \n" /* $10 <= words */ |
---|
| 180 | "move $11, %3 \n" /* $11 <= size */ |
---|
| 181 | "mfc2 $12, $1 \n" /* $12 <= old MMU_MODE */ |
---|
| 182 | "ori $13, $12, 0x4 \n" /* $13 <= MMU_MODE with DTLB */ |
---|
[1] | 183 | |
---|
[637] | 184 | /* save old MMU_DATA_EXT and set cxy in it */ |
---|
[626] | 185 | "mfc2 $16, $24 \n" /* $16 <= old MMU_DATA_EXT */ |
---|
[637] | 186 | "mtc2 %4, $24 \n" /* MMU_DATA_EXT <= cxy */ |
---|
[1] | 187 | |
---|
[626] | 188 | /* transfer one word per iteration in first loop if aligned */ |
---|
| 189 | "move $15, $10 \n" /* $15 <= words ($15 == i) */ |
---|
| 190 | "1: \n" |
---|
| 191 | "beq $15, $0, 2f \n" /* exit loop if (i==0) */ |
---|
| 192 | "nop \n" |
---|
| 193 | "lw $14, 0($8) \n" /* load from kernel space */ |
---|
| 194 | "mtc2 $13, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
| 195 | "sw $14, 0($9) \n" /* store to user space */ |
---|
| 196 | "mtc2 $12, $1 \n" /* restore old MMU_MODE */ |
---|
| 197 | "addi $15, $15, -1 \n" /* i-- */ |
---|
| 198 | "addi $8, $8, 4 \n" /* src += 4 bytes */ |
---|
| 199 | "j 1b \n" |
---|
| 200 | "addi $9, $9, 4 \n" /* dst += 4 bytes */ |
---|
[1] | 201 | |
---|
[626] | 202 | /* transfer one byte per iteration in this second loop */ |
---|
| 203 | "2: \n" |
---|
| 204 | "sll $15, $10, 2 \n" /* $15 <= words*4 ($15 == i) */ |
---|
| 205 | "3: \n" |
---|
| 206 | "beq $15, $11, 4f \n" /* exit loop if (i == size) */ |
---|
| 207 | "nop \n" |
---|
| 208 | "lb $14, 0($8) \n" /* byte from kernel space */ |
---|
| 209 | "mtc2 $13, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
| 210 | "sb $14, 0($9) \n" /* byte to user space */ |
---|
| 211 | "mtc2 $12, $1 \n" /* restore omd MMU_MODE */ |
---|
| 212 | "addi $15, $15, 1 \n" /* i++ */ |
---|
| 213 | "addi $8, $8, 1 \n" /* src += 1 byte */ |
---|
| 214 | "j 3b \n" |
---|
| 215 | "addi $9, $9, 1 \n" /* dst += 1 byte */ |
---|
[1] | 216 | |
---|
[626] | 217 | /* restore old MMU_DATA_EXT register */ |
---|
| 218 | "4: \n" |
---|
| 219 | "mtc2 $16, $24 \n" /* MMU__DATA_EXT <= $16 */ |
---|
| 220 | ".set reorder \n" |
---|
| 221 | : |
---|
[637] | 222 | : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy) |
---|
[626] | 223 | : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" ); |
---|
| 224 | |
---|
| 225 | // exit critical section |
---|
[1] | 226 | hal_restore_irq( save_sr ); |
---|
| 227 | |
---|
[610] | 228 | #if DEBUG_HAL_USPACE |
---|
[626] | 229 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 230 | if( cycle > DEBUG_HAL_USPACE ) |
---|
| 231 | printk("\n[%s] thread[%x,%x] moved %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n", |
---|
[637] | 232 | __FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle ); |
---|
[610] | 233 | #endif |
---|
| 234 | |
---|
[87] | 235 | } // end hal_copy_to_uspace() |
---|
| 236 | |
---|
[637] | 237 | ///////////////////////////////////////////////// |
---|
| 238 | void hal_strcpy_from_uspace( xptr_t k_dst_xp, |
---|
| 239 | char * u_src_ptr, |
---|
[407] | 240 | uint32_t size ) |
---|
[87] | 241 | { |
---|
[407] | 242 | uint32_t save_sr; |
---|
[637] | 243 | uint32_t src = (uint32_t)u_src_ptr; |
---|
| 244 | uint32_t dst = (uint32_t)GET_PTR( k_dst_xp ); |
---|
| 245 | uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp ); |
---|
[87] | 246 | |
---|
| 247 | hal_disable_irq( &save_sr ); |
---|
| 248 | |
---|
[425] | 249 | // loop on characters while ( (character != NUL) and (count < size ) ) |
---|
[637] | 250 | |
---|
[87] | 251 | asm volatile( |
---|
[407] | 252 | ".set noreorder \n" |
---|
[637] | 253 | |
---|
| 254 | /* save old MMU_DATA_EXT and set cxy in it */ |
---|
| 255 | "mfc2 $16, $24 \n" /* $16 <= old MMU_DATA_EXT */ |
---|
| 256 | "mtc2 %3, $24 \n" /* MMU_DATA_EXT <= cxy */ |
---|
| 257 | |
---|
[407] | 258 | "move $11, %0 \n" /* $11 <= count == size */ |
---|
| 259 | "move $12, %1 \n" /* $12 <= u_src */ |
---|
| 260 | "move $13, %2 \n" /* $13 <= k_dst */ |
---|
[637] | 261 | "mfc2 $15, $1 \n" /* $15 <= MMU_MODE */ |
---|
| 262 | "ori $14, $15, 0x4 \n" /* $14 <= MMU_MODE / DTLB ON */ |
---|
| 263 | |
---|
[407] | 264 | "1: \n" |
---|
[87] | 265 | "mtc2 $14, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
[407] | 266 | "lb $10, 0($12) \n" /* read char from user space */ |
---|
[637] | 267 | "mtc2 $15, $1 \n" /* MMU_MODE <= DTLB OFF */ |
---|
[407] | 268 | "sb $10, 0($13) \n" /* store char to kernel space */ |
---|
[425] | 269 | "beq $10, $0, 2f \n" /* exit if char = 0 */ |
---|
[407] | 270 | "addi $11, $11, -1 \n" /* decrement count */ |
---|
| 271 | "addi $12, $12, 1 \n" /* increment u_src pointer */ |
---|
| 272 | "beq $11, $0, 2f \n" /* exit if count == 0 */ |
---|
| 273 | "addi $13, $13, 1 \n" /* increment k_src pointer */ |
---|
| 274 | "j 1b \n" /* jump to next iteration */ |
---|
| 275 | "2: \n" |
---|
[87] | 276 | "nop \n" |
---|
[637] | 277 | |
---|
| 278 | /* restore old MMU_DATA_EXT register */ |
---|
| 279 | "mtc2 $16, $24 \n" /* MMU_DATA_EXT <= $16 */ |
---|
| 280 | |
---|
[407] | 281 | ".set reorder \n" |
---|
| 282 | : |
---|
[637] | 283 | : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy) |
---|
| 284 | : "$10","$11","$12","$13","$14","$15","$16" ); |
---|
[407] | 285 | |
---|
| 286 | hal_restore_irq( save_sr ); |
---|
[87] | 287 | |
---|
| 288 | } // hal_strcpy_from_uspace() |
---|
| 289 | |
---|
[637] | 290 | //////////////////////////////////////////////// |
---|
| 291 | void hal_strcpy_to_uspace( char * u_dst_ptr, |
---|
| 292 | xptr_t k_src_xp, |
---|
[407] | 293 | uint32_t size ) |
---|
[121] | 294 | { |
---|
[407] | 295 | uint32_t save_sr; |
---|
[637] | 296 | uint32_t dst = (uint32_t)u_dst_ptr; |
---|
| 297 | uint32_t src = (uint32_t)GET_PTR( k_src_xp ); |
---|
| 298 | uint32_t cxy = (uint32_t)GET_CXY( k_src_xp ); |
---|
[87] | 299 | |
---|
| 300 | hal_disable_irq( &save_sr ); |
---|
| 301 | |
---|
[407] | 302 | // loop on characters while ( (character != NUL) and (count < size) ) |
---|
[637] | 303 | |
---|
[87] | 304 | asm volatile( |
---|
[407] | 305 | ".set noreorder \n" |
---|
[637] | 306 | |
---|
| 307 | /* save old MMU_DATA_EXT and set cxy in it */ |
---|
| 308 | "mfc2 $16, $24 \n" /* $16 <= old MMU_DATA_EXT */ |
---|
| 309 | "mtc2 %3, $24 \n" /* MMU_DATA_EXT <= cxy */ |
---|
| 310 | |
---|
[407] | 311 | "move $11, %0 \n" /* $11 <= count == size */ |
---|
| 312 | "move $12, %1 \n" /* $12 <= k_src */ |
---|
| 313 | "move $13, %2 \n" /* $13 <= u_dst */ |
---|
[637] | 314 | "mfc2 $15, $1 \n" /* $15 <= MMU_MODE */ |
---|
| 315 | "ori $14, $15, 0x4 \n" /* $14 <= MMU_MODE modified */ |
---|
| 316 | |
---|
[407] | 317 | "1: \n" |
---|
| 318 | "lb $10, 0($12) \n" /* read char from kernel space */ |
---|
[87] | 319 | "mtc2 $14, $1 \n" /* MMU_MODE <= DTLB ON */ |
---|
[407] | 320 | "sb $10, 0($13) \n" /* store char to user space */ |
---|
[637] | 321 | "mtc2 $15, $1 \n" /* MMU_MODE <= DTLB OFF */ |
---|
[425] | 322 | "beq $10, $0, 2f \n" /* exit if char == 0 */ |
---|
[407] | 323 | "addi $11, $11, -1 \n" /* decrement count */ |
---|
| 324 | "addi $12, $12, 1 \n" /* increment k_src pointer */ |
---|
[637] | 325 | "beq $11, $0, 2f \n" /* exit if count == 0 */ |
---|
[407] | 326 | "addi $13, $13, 1 \n" /* increment u_src pointer */ |
---|
| 327 | "j 1b \n" /* jump to next iteration */ |
---|
| 328 | "2: \n" |
---|
[87] | 329 | "nop \n" |
---|
[637] | 330 | |
---|
| 331 | /* restore old MMU_DATA_EXT register */ |
---|
| 332 | "mtc2 $16, $24 \n" /* MMU_DATA_EXT <= $16 */ |
---|
| 333 | |
---|
[407] | 334 | ".set reorder \n" |
---|
| 335 | : |
---|
[637] | 336 | : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy) |
---|
| 337 | : "$10","$11","$12","$13","$14","$15","$16" ); |
---|
[407] | 338 | |
---|
| 339 | hal_restore_irq( save_sr ); |
---|
[87] | 340 | |
---|
[299] | 341 | } // hal_strcpy_to_uspace() |
---|
[87] | 342 | |
---|
[1] | 343 | /////////////////////////////////////////////// |
---|
| 344 | uint32_t hal_strlen_from_uspace( char * u_str ) |
---|
| 345 | { |
---|
| 346 | uint32_t save_sr; |
---|
[407] | 347 | uint32_t count = 0; |
---|
[425] | 348 | uint32_t str = (uint32_t)u_str; |
---|
[1] | 349 | |
---|
| 350 | hal_disable_irq( &save_sr ); |
---|
| 351 | |
---|
| 352 | asm volatile( |
---|
[407] | 353 | ".set noreorder \n" |
---|
[425] | 354 | "move $13, %1 \n" /* $13 <= str */ |
---|
[625] | 355 | "mfc2 $15, $1 \n" /* $15 <= MMU_MODE (DTLB off) */ |
---|
[425] | 356 | "ori $14, $15, 0x4 \n" /* $14 <= mode DTLB on */ |
---|
[1] | 357 | "1: \n" |
---|
[425] | 358 | "mtc2 $14, $1 \n" /* set DTLB on */ |
---|
[625] | 359 | "lb $12, 0($13) \n" /* $12 <= one byte from u_space */ |
---|
[425] | 360 | "mtc2 $15, $1 \n" /* set DTLB off */ |
---|
[1] | 361 | "addi $13, $13, 1 \n" /* increment address */ |
---|
[407] | 362 | "bne $12, $0, 1b \n" /* loop until NUL found */ |
---|
| 363 | "addi %0, %0, 1 \n" /* increment count */ |
---|
| 364 | ".set reorder \n" |
---|
| 365 | : "+r"(count) |
---|
| 366 | : "r"(str) |
---|
| 367 | : "$12","$13","$14","$15" ); |
---|
[1] | 368 | |
---|
| 369 | hal_restore_irq( save_sr ); |
---|
| 370 | |
---|
| 371 | return count; |
---|
| 372 | } |
---|
| 373 | |
---|