Rewritten and cleanup the file.

Share the string copying code between copyinstr() and copyoutstr().
This commit is contained in:
mark 1998-06-17 20:10:39 +00:00
parent 752ca327a1
commit 138ccaa418

View File

@ -1,4 +1,4 @@
/* $NetBSD: copystr.S,v 1.8 1998/04/01 23:00:14 mark Exp $ */ /* $NetBSD: copystr.S,v 1.9 1998/06/17 20:10:39 mark Exp $ */
/* /*
* Copyright (c) 1995 Mark Brinicombe. * Copyright (c) 1995 Mark Brinicombe.
@ -31,8 +31,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* RiscBSD kernel project
*
* copystr.S * copystr.S
* *
* optimised and fault protected copystr functions * optimised and fault protected copystr functions
@ -45,11 +43,16 @@
#include <sys/errno.h> #include <sys/errno.h>
.text .text
.align 0
Lcurpcb: Lcurpcb:
.word _curpcb .word _curpcb
Lcurproc: Lvm_min_address:
.word _curproc .word VM_MIN_ADDRESS
Lvm_maxuser_address:
.word VM_MAXUSER_ADDRESS
Lvm_maxkern_address:
.word VM_MAXKERN_ADDRESS
/* /*
* r0 - from * r0 - from
@ -100,13 +103,8 @@ Lcopystrexit:
ENTRY(copyinstr) ENTRY(copyinstr)
stmfd sp!, {r4-r6} stmfd sp!, {r4-r6}
teq r2, #0x00000000
moveq r5, #0x00000000
moveq r6, #0x00000000
beq Lcopyinstrexit
/* Validate addresses */
/* Validate user and kernel addresses */
ldr r4, Lvm_min_address ldr r4, Lvm_min_address
cmp r0, r4 cmp r0, r4
bcc Lbadaddress bcc Lbadaddress
@ -119,38 +117,8 @@ ENTRY(copyinstr)
cmp r1, r4 cmp r1, r4
bcs Lbadaddress bcs Lbadaddress
ldr r4, Lcurpcb /* Do the actual copy */
ldr r4, [r4] b do_copyinoutstr
#ifdef DIAGNOSTIC
teq r4, #0x00000000
beq Lcopystrpcbfault
#endif
add r5, pc, #Lcopystrfault - . - 8
str r5, [r4, #PCB_ONFAULT]
mov r6, #0x00000000
Lcopyinstr_loop:
ldrb r5, [r0], #0x0001
strb r5, [r1], #0x0001
add r6, r6, #0x00000001
teq r5, #0x00000000
teqne r6, r2
bne Lcopyinstr_loop
Lcopyinstrexit:
teq r3, #0x00000000
strne r6, [r3]
teq r5, #0x00000000
moveq r0, #0x00000000
movne r0, #ENAMETOOLONG
mov r6, #0x00000000
str r6, [r4, #PCB_ONFAULT]
ldmfd sp!, {r4-r6}
mov pc, lr
/* /*
* r0 - kernel space address * r0 - kernel space address
@ -163,13 +131,8 @@ Lcopyinstrexit:
ENTRY(copyoutstr) ENTRY(copyoutstr)
stmfd sp!, {r4-r6} stmfd sp!, {r4-r6}
teq r2, #0x00000000
moveq r5, #0x00000000
moveq r6, #0x00000000
beq Lcopyinstrexit
/* Validate addresses */
/* Validate user and kernel addresses */
ldr r4, Lvm_min_address ldr r4, Lvm_min_address
cmp r1, r4 cmp r1, r4
bcc Lbadaddress bcc Lbadaddress
@ -182,6 +145,13 @@ ENTRY(copyoutstr)
cmp r0, r4 cmp r0, r4
bcs Lbadaddress bcs Lbadaddress
/* Do the actual copy */
do_copyinoutstr:
teq r2, #0x00000000
moveq r5, #0x00000000
moveq r6, #0x00000000
beq Lcopyinoutstrexit
ldr r4, Lcurpcb ldr r4, Lcurpcb
ldr r4, [r4] ldr r4, [r4]
@ -194,15 +164,15 @@ ENTRY(copyoutstr)
str r5, [r4, #PCB_ONFAULT] str r5, [r4, #PCB_ONFAULT]
mov r6, #0x00000000 mov r6, #0x00000000
Lcopyoutstr_loop: Lcopyinoutstr_loop:
ldrb r5, [r0], #0x0001 ldrb r5, [r0], #0x0001
strb r5, [r1], #0x0001 strb r5, [r1], #0x0001
add r6, r6, #0x00000001 add r6, r6, #0x00000001
teq r5, #0x00000000 teq r5, #0x00000000
teqne r6, r2 teqne r6, r2
bne Lcopyoutstr_loop bne Lcopyinoutstr_loop
Lcopyoutstrexit: Lcopyinoutstrexit:
teq r3, #0x00000000 teq r3, #0x00000000
strne r6, [r3] strne r6, [r3]
@ -215,35 +185,27 @@ Lcopyoutstrexit:
ldmfd sp!, {r4-r6} ldmfd sp!, {r4-r6}
mov pc, lr mov pc, lr
Lvm_min_address: /* A fault occurred during the copy */
.word VM_MIN_ADDRESS
Lvm_maxuser_address:
.word VM_MAXUSER_ADDRESS
Lvm_maxkern_address:
.word VM_MAXKERN_ADDRESS
Lcopystrfault: Lcopystrfault:
mov r0, #0x00000000 mov r0, #0x00000000
str r0, [r4, #PCB_ONFAULT] str r0, [r4, #PCB_ONFAULT]
mov r0, #EFAULT
ldmfd sp!, {r4-r6}
mov pc, lr
/* FALLTHROUGH */
/* Source or Destination address was bad so fail */
Lbadaddress: Lbadaddress:
mov r0, #EFAULT
ldmfd sp!, {r4-r6} ldmfd sp!, {r4-r6}
mov r0, #EFAULT
mov pc, lr mov pc, lr
#ifdef DIAGNOSTIC #ifdef DIAGNOSTIC
Lcopystrpcbfault: Lcopystrpcbfault:
mov r2, r1 mov r2, r1
mov r1, r0 mov r1, r0
ldr r2, Lcurproc
ldr r2, [r2]
add r0, pc, #Lcopystrpcbfaulttext - . - 8 add r0, pc, #Lcopystrpcbfaulttext - . - 8
b _panic b _panic
Lcopystrpcbfaulttext: Lcopystrpcbfaulttext:
.asciz "Yikes - no valid PCB during copystr() addr1=%08x addr2=%08x curproc=%08x\n" .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"
.align 0 .align 0
#endif #endif