1/* 2Copyright (c) 1990 The Regents of the University of California. 3All rights reserved. 4 5Redistribution and use in source and binary forms are permitted 6provided that the above copyright notice and this paragraph are 7duplicated in all such forms and that any documentation, 8and/or other materials related to such 9distribution and use acknowledge that the software was developed 10by the University of California, Berkeley. The name of the 11University may not be used to endorse or promote products derived 12from this software without specific prior written permission. 13THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17#include <picolibc.h> 18 19#include "setarch.h" 20 21#include "defines.h" 22 23#if defined (__H8300SX__) 24 25 .global _memset 26_memset: 27 ; Use er3 is a temporary since er0 must remain unchanged on exit. 28 mov.l er0,er3 29 30 ; Fill er1 with the byte to copy. 31 mov.b r1l,r1h 32 mov.w r1,e1 33 34 ; Account for any excess bytes and words that will be copied after 35 ; the main loop. r2 >= 0 if there is a longword to copy. 36 sub #4,LEN(r2) 37 blo longs_done 38 39 ; Copy one byte if doing so will make er3 word-aligned. 40 ; This isn't needed for correctness but it makes the main loop 41 ; slightly faster. 42 bld #0,r3l 43 bcc word_aligned 44 mov.b r1l,@er3+ 45 sub #1,LEN(r2) 46 blo longs_done 47 48word_aligned: 49 ; Likewise one word for longword alignment. 50 bld #1,r3l 51 bcc long_copy 52 mov.w r1,@er3+ 53 sub #2,LEN(r2) 54 blo longs_done 55 56long_copy: 57 ; Copy longwords. 58 mov.l er1,@er3+ 59 sub #4,LEN(r2) 60 bhs long_copy 61 62longs_done: 63 ; At this point, we need to copy r2 & 3 bytes. Copy a word 64 ; if necessary. 65 bld #1,r2l 66 bcc words_done 67 mov.w r1,@er3+ 68 69words_done: 70 ; Copy a byte. 71 bld #0,r2l 72 bcc bytes_done 73 mov.b r1l,@er3+ 74 75bytes_done: 76 rts 77 78#else 79 80; A0P pointer to cursor 81; A1P thing to copy 82 .global _memset 83 84_memset: 85 86; MOVP @(2/4,r7),A2P ; dst 87; MOVP @(4/8,r7),A1 ; src thing 88; MOVP @(6/12,r7),A3P ; len 89 90 MOVP A2P,A2P 91 beq quit 92 93 ; A3 points to the end of the area 94 MOVP A0P,A3P 95 ADDP A2P,A3P 96 97 ; see if we can do it in words 98 ; by oring in the start of the buffer to the end address 99 100 or A0L,A2L 101 btst #0,A2L 102 bne byteloop 103 104 ; we can do it a word at a time 105 106 mov.b A1L,A1H 107 108wordloop: 109 mov.w A1,@-A3P 110 CMPP A3P,A0P 111 bne wordloop 112quit: rts 113 114byteloop: 115 mov.b A1L,@-A3P 116 CMPP A3P,A0P 117 bne byteloop 118 rts 119 120#endif 121