/* MN10300 Optimised simple memory to memory copy1*2* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public Licence7* as published by the Free Software Foundation; either version8* 2 of the Licence, or (at your option) any later version.9*/10#include <asm/cache.h>1112.section .text13.balign L1_CACHE_BYTES1415###############################################################################16#17# void *memcpy(void *dst, const void *src, size_t n)18#19###############################################################################20.globl memcpy21.type memcpy,@function22memcpy:23movm [d2,d3],(sp)24mov d0,(12,sp)25mov d1,(16,sp)26mov (20,sp),d2 # count27mov d0,a0 # dst28mov d1,a1 # src29mov d0,e3 # the return value3031cmp +0,d232beq memcpy_done # return if zero-length copy3334# see if the three parameters are all four-byte aligned35or d0,d1,d336or d2,d337and +3,d338bne memcpy_1 # jump if not3940# we want to transfer as much as we can in chunks of 32 bytes41cmp +31,d242bls memcpy_4_remainder # 4-byte aligned remainder4344movm [exreg1],(sp)45add -32,d246mov +32,d34748memcpy_4_loop:49mov (a1+),d050mov (a1+),d151mov (a1+),e052mov (a1+),e153mov (a1+),e454mov (a1+),e555mov (a1+),e656mov (a1+),e757mov d0,(a0+)58mov d1,(a0+)59mov e0,(a0+)60mov e1,(a0+)61mov e4,(a0+)62mov e5,(a0+)63mov e6,(a0+)64mov e7,(a0+)6566sub d3,d267bcc memcpy_4_loop6869movm (sp),[exreg1]70add d3,d271beq memcpy_4_no_remainder7273memcpy_4_remainder:74# cut 4-7 words down to 0-375cmp +16,d276bcs memcpy_4_three_or_fewer_words77mov (a1+),d078mov (a1+),d179mov (a1+),e080mov (a1+),e181mov d0,(a0+)82mov d1,(a0+)83mov e0,(a0+)84mov e1,(a0+)85add -16,d286beq memcpy_4_no_remainder8788# copy the remaining 1, 2 or 3 words89memcpy_4_three_or_fewer_words:90cmp +8,d291bcs memcpy_4_one_word92beq memcpy_4_two_words93mov (a1+),d094mov d0,(a0+)95memcpy_4_two_words:96mov (a1+),d097mov d0,(a0+)98memcpy_4_one_word:99mov (a1+),d0100mov d0,(a0+)101102memcpy_4_no_remainder:103# check we copied the correct amount104# TODO: REMOVE CHECK105sub e3,a0,d2106mov (20,sp),d1107cmp d2,d1108beq memcpy_done109break110break111break112113memcpy_done:114mov e3,a0115ret [d2,d3],8116117# handle misaligned copying118memcpy_1:119add -1,d2120mov +1,d3121setlb # setlb requires the next insns122# to occupy exactly 4 bytes123124sub d3,d2125movbu (a1),d0126movbu d0,(a0)127add_add d3,a1,d3,a0128lcc129130mov e3,a0131ret [d2,d3],8132133memcpy_end:134.size memcpy, memcpy_end-memcpy135136137