1/*
2 * memset routine for Z8000
3 * Copyright (C) 2004 Christian Groessler <chris@groessler.org>
4 *
5 * Permission to use, copy, modify, and distribute this file
6 * for any purpose is hereby granted without fee, provided that
7 * the above copyright notice and this notice appears in all
8 * copies.
9 *
10 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 */
13
14/* void *memset(void *buffer, int value, size_t length);
15 */
16
17	name	"memset.S"
18
19	.text
20	even
21global	_memset
22
23_memset:
24
25#ifdef __Z8001__
26	segm
27
28#ifdef __STD_CALL__
29	ldl	rr6,rr14(#4)
30	ld	r5,rr14(#8)
31	ldl	rr2,rr14(#10)
32#else
33	pushl	@rr14,rr6
34#endif
35
36/* rr2  - length
37 * rl5  - value
38 * rr6  - buffer
39 */
40	testl	rr2
41	jr	z,finish
42
43	ldb	rh5,rl5
44	ld	r1,r5		/* r1 contains value */
45	bit	r7,#0
46	jr	z,not_odd
47
48	ldb	@rr6,rl1
49	inc	r7,#1
50	subl	rr2,#1
51	jr	z,finish
52
53not_odd:ld	r0,r3		/* remember length */
54	srl	r3,#1
55	jr	z,no_words
56
57	ldl	rr4,rr6
58	ld	@rr6,r1
59	inc	r7,#2
60	dec	r3,#1
61	jr	z,no_words
62
63	ldir	@rr6,@rr4,r3	/* fill words */
64
65no_words:
66	bit	r0,#0		/* one byte remaining? */
67	jr	z,finish
68
69	ldb	@rr6,rl1
70
71finish:
72#ifdef __STD_CALL__
73	ldl	rr6,rr14(#4)
74#else
75	popl	rr2,@rr14
76#endif
77
78
79#else		/* above Z8001, below Z8002 */
80
81
82	unsegm
83
84#ifdef __STD_CALL__
85	ld	r7,r15(#2)
86	ld	r6,r15(#4)
87	ld	r5,r15(#6)
88#else
89	ld	r2,r7		/* buffer pointer return value */
90#endif
91
92/* r5  - length
93 * r6  - value
94 * r7  - buffer
95 */
96	test	r5
97	jr	z,finish
98
99	ldb	rh6,rl6
100	ld	r1,r6		/* r1 contains value */
101	bit	r7,#0
102	jr	z,not_odd
103
104	ldb	@r7,rl1
105	inc	r7,#1
106	dec	r5,#1
107	jr	z,finish
108
109not_odd:ld	r0,r5		/* remember length */
110	srl	r5,#1
111	jr	z,no_words
112
113	ld	r4,r7
114	ld	@r7,r1
115	inc	r7,#2
116	dec	r5,#1
117	jr	z,no_words
118
119	ldir	@r7,@r4,r5	/* fill words */
120
121no_words:
122	bit	r0,#0		/* one byte remaining? */
123	jr	z,finish
124
125	ldb	@r7,rl1
126
127finish:
128#ifdef __STD_CALL__
129	ld	r7,r15(#2)
130#endif
131
132#endif	/* Z8002 */
133
134	ret
135	.end
136