blob: 8adb687c5254aef8e20249ebb71b6d88a3ee9366 [file] [log] [blame]
Russ Coxed0beea2009-11-17 22:16:55 -08001// Inferno's libkern/memmove-386.s
2// http://code.google.com/p/inferno-os/source/browse/libkern/memmove-386.s
3//
4// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5// Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
6// Portions Copyright 2009 The Go Authors. All rights reserved.
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24// THE SOFTWARE.
25
Rob Pike093493c2009-11-18 15:00:02 -080026 TEXT memmove(SB), 7, $0
Russ Coxed0beea2009-11-17 22:16:55 -080027
28 MOVL to+0(FP), DI
29 MOVL fr+4(FP), SI
30 MOVL n+8(FP), BX
Rob Pike093493c2009-11-18 15:00:02 -080031 CMPL BX, $0
Russ Coxed0beea2009-11-17 22:16:55 -080032 JLT fault
33
34/*
35 * check and set for backwards
36 * should we look closer for overlap?
37 */
38 CMPL SI, DI
39 JLS back
40
41/*
Rob Pike093493c2009-11-18 15:00:02 -080042 * forward copy loop
Russ Coxed0beea2009-11-17 22:16:55 -080043 */
44 MOVL BX, CX
45 SHRL $2, CX
46 ANDL $3, BX
47
48 REP; MOVSL
49 MOVL BX, CX
50 REP; MOVSB
51
52 MOVL to+0(FP),AX
53 RET
54/*
55 * whole thing backwards has
56 * adjusted addresses
57 */
58back:
59 ADDL BX, DI
60 ADDL BX, SI
61 STD
62
63/*
64 * copy
65 */
66 MOVL BX, CX
67 SHRL $2, CX
68 ANDL $3, BX
69
70 SUBL $4, DI
71 SUBL $4, SI
72 REP; MOVSL
73
74 ADDL $3, DI
75 ADDL $3, SI
76 MOVL BX, CX
77 REP; MOVSB
78
79 CLD
80 MOVL to+0(FP),AX
81 RET
82
83/*
84 * if called with negative count,
85 * treat as error rather than
86 * rotating all of memory
87 */
88fault:
89 MOVL $0,SI
90 MOVL 0(SI), AX
91 RET