1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds/* linux/arch/sparc/lib/memset.S: Sparc optimized memset, bzero and clear_user code 31da177e4SLinus Torvalds * Copyright (C) 1991,1996 Free Software Foundation 41da177e4SLinus Torvalds * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 51da177e4SLinus Torvalds * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 61da177e4SLinus Torvalds * 774cad25cSAndreas Larsson * Calls to memset returns initial %o0. Calls to bzero returns 0, if ok, and 874cad25cSAndreas Larsson * number of bytes not yet set if exception occurs and we were called as 974cad25cSAndreas Larsson * clear_user. 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds#include <asm/ptrace.h> 13d3867f04SAl Viro#include <asm/export.h> 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds/* Work around cpp -rob */ 161da177e4SLinus Torvalds#define ALLOC #alloc 171da177e4SLinus Torvalds#define EXECINSTR #execinstr 181da177e4SLinus Torvalds#define EX(x,y,a,b) \ 191da177e4SLinus Torvalds98: x,y; \ 201da177e4SLinus Torvalds .section .fixup,ALLOC,EXECINSTR; \ 211da177e4SLinus Torvalds .align 4; \ 22*e51ea544SAl Viro99: retl; \ 231da177e4SLinus Torvalds a, b, %o0; \ 241da177e4SLinus Torvalds .section __ex_table,ALLOC; \ 251da177e4SLinus Torvalds .align 4; \ 261da177e4SLinus Torvalds .word 98b, 99b; \ 271da177e4SLinus Torvalds .text; \ 281da177e4SLinus Torvalds .align 4 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds#define EXT(start,end,handler) \ 311da177e4SLinus Torvalds .section __ex_table,ALLOC; \ 321da177e4SLinus Torvalds .align 4; \ 331da177e4SLinus Torvalds .word start, 0, end, handler; \ 341da177e4SLinus Torvalds .text; \ 351da177e4SLinus Torvalds .align 4 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds/* Please don't change these macros, unless you change the logic 381da177e4SLinus Torvalds * in the .fixup section below as well. 391da177e4SLinus Torvalds * Store 64 bytes at (BASE + OFFSET) using value SOURCE. */ 401da177e4SLinus Torvalds#define ZERO_BIG_BLOCK(base, offset, source) \ 411da177e4SLinus Torvalds std source, [base + offset + 0x00]; \ 421da177e4SLinus Torvalds std source, [base + offset + 0x08]; \ 431da177e4SLinus Torvalds std source, [base + offset + 0x10]; \ 441da177e4SLinus Torvalds std source, [base + offset + 0x18]; \ 451da177e4SLinus Torvalds std source, [base + offset + 0x20]; \ 461da177e4SLinus Torvalds std source, [base + offset + 0x28]; \ 471da177e4SLinus Torvalds std source, [base + offset + 0x30]; \ 481da177e4SLinus Torvalds std source, [base + offset + 0x38]; 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds#define ZERO_LAST_BLOCKS(base, offset, source) \ 511da177e4SLinus Torvalds std source, [base - offset - 0x38]; \ 521da177e4SLinus Torvalds std source, [base - offset - 0x30]; \ 531da177e4SLinus Torvalds std source, [base - offset - 0x28]; \ 541da177e4SLinus Torvalds std source, [base - offset - 0x20]; \ 551da177e4SLinus Torvalds std source, [base - offset - 0x18]; \ 561da177e4SLinus Torvalds std source, [base - offset - 0x10]; \ 571da177e4SLinus Torvalds std source, [base - offset - 0x08]; \ 581da177e4SLinus Torvalds std source, [base - offset - 0x00]; 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds .text 611da177e4SLinus Torvalds .align 4 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds .globl __bzero_begin 641da177e4SLinus Torvalds__bzero_begin: 651da177e4SLinus Torvalds 664d14a459SDavid S. Miller .globl __bzero 67f5a651f1SNagarathnam Muthusamy .type __bzero,#function 681da177e4SLinus Torvalds .globl memset 69d3867f04SAl Viro EXPORT_SYMBOL(__bzero) 70d3867f04SAl Viro EXPORT_SYMBOL(memset) 711da177e4SLinus Torvalds .globl __memset_start, __memset_end 721da177e4SLinus Torvalds__memset_start: 731da177e4SLinus Torvaldsmemset: 7474cad25cSAndreas Larsson mov %o0, %g1 7574cad25cSAndreas Larsson mov 1, %g4 761da177e4SLinus Torvalds and %o1, 0xff, %g3 771da177e4SLinus Torvalds sll %g3, 8, %g2 781da177e4SLinus Torvalds or %g3, %g2, %g3 791da177e4SLinus Torvalds sll %g3, 16, %g2 801da177e4SLinus Torvalds or %g3, %g2, %g3 811da177e4SLinus Torvalds b 1f 821da177e4SLinus Torvalds mov %o2, %o1 831da177e4SLinus Torvalds3: 841da177e4SLinus Torvalds cmp %o2, 3 851da177e4SLinus Torvalds be 2f 861da177e4SLinus Torvalds EX(stb %g3, [%o0], sub %o1, 0) 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds cmp %o2, 2 891da177e4SLinus Torvalds be 2f 901da177e4SLinus Torvalds EX(stb %g3, [%o0 + 0x01], sub %o1, 1) 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds EX(stb %g3, [%o0 + 0x02], sub %o1, 2) 931da177e4SLinus Torvalds2: 941da177e4SLinus Torvalds sub %o2, 4, %o2 951da177e4SLinus Torvalds add %o1, %o2, %o1 961da177e4SLinus Torvalds b 4f 971da177e4SLinus Torvalds sub %o0, %o2, %o0 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds__bzero: 10074cad25cSAndreas Larsson clr %g4 1011da177e4SLinus Torvalds mov %g0, %g3 1021da177e4SLinus Torvalds1: 1031da177e4SLinus Torvalds cmp %o1, 7 1041da177e4SLinus Torvalds bleu 7f 1051da177e4SLinus Torvalds andcc %o0, 3, %o2 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds bne 3b 1081da177e4SLinus Torvalds4: 1091da177e4SLinus Torvalds andcc %o0, 4, %g0 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds be 2f 1121da177e4SLinus Torvalds mov %g3, %g2 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds EX(st %g3, [%o0], sub %o1, 0) 1151da177e4SLinus Torvalds sub %o1, 4, %o1 1161da177e4SLinus Torvalds add %o0, 4, %o0 1171da177e4SLinus Torvalds2: 1181da177e4SLinus Torvalds andcc %o1, 0xffffff80, %o3 ! Now everything is 8 aligned and o1 is len to run 1191da177e4SLinus Torvalds be 9f 1201da177e4SLinus Torvalds andcc %o1, 0x78, %o2 1211da177e4SLinus Torvalds10: 1221da177e4SLinus Torvalds ZERO_BIG_BLOCK(%o0, 0x00, %g2) 1231da177e4SLinus Torvalds subcc %o3, 128, %o3 1241da177e4SLinus Torvalds ZERO_BIG_BLOCK(%o0, 0x40, %g2) 1251da177e4SLinus Torvalds11: 1261da177e4SLinus Torvalds EXT(10b, 11b, 20f) 1271da177e4SLinus Torvalds bne 10b 1281da177e4SLinus Torvalds add %o0, 128, %o0 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds orcc %o2, %g0, %g0 1311da177e4SLinus Torvalds9: 1321da177e4SLinus Torvalds be 13f 1331da177e4SLinus Torvalds andcc %o1, 7, %o1 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds srl %o2, 1, %o3 1361da177e4SLinus Torvalds set 13f, %o4 1371da177e4SLinus Torvalds sub %o4, %o3, %o4 1381da177e4SLinus Torvalds jmp %o4 1391da177e4SLinus Torvalds add %o0, %o2, %o0 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds12: 1421da177e4SLinus Torvalds ZERO_LAST_BLOCKS(%o0, 0x48, %g2) 1431da177e4SLinus Torvalds ZERO_LAST_BLOCKS(%o0, 0x08, %g2) 1441da177e4SLinus Torvalds13: 1451da177e4SLinus Torvalds be 8f 1461da177e4SLinus Torvalds andcc %o1, 4, %g0 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds be 1f 1491da177e4SLinus Torvalds andcc %o1, 2, %g0 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds EX(st %g3, [%o0], and %o1, 7) 1521da177e4SLinus Torvalds add %o0, 4, %o0 1531da177e4SLinus Torvalds1: 1541da177e4SLinus Torvalds be 1f 1551da177e4SLinus Torvalds andcc %o1, 1, %g0 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds EX(sth %g3, [%o0], and %o1, 3) 1581da177e4SLinus Torvalds add %o0, 2, %o0 1591da177e4SLinus Torvalds1: 1601da177e4SLinus Torvalds bne,a 8f 1611da177e4SLinus Torvalds EX(stb %g3, [%o0], and %o1, 1) 1621da177e4SLinus Torvalds8: 16374cad25cSAndreas Larsson b 0f 16474cad25cSAndreas Larsson nop 1651da177e4SLinus Torvalds7: 1661da177e4SLinus Torvalds be 13b 1671da177e4SLinus Torvalds orcc %o1, 0, %g0 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds be 0f 1701da177e4SLinus Torvalds8: 1711da177e4SLinus Torvalds add %o0, 1, %o0 1721da177e4SLinus Torvalds subcc %o1, 1, %o1 173f61698e6SAlexander Shmelev bne 8b 1741da177e4SLinus Torvalds EX(stb %g3, [%o0 - 1], add %o1, 1) 1751da177e4SLinus Torvalds0: 17674cad25cSAndreas Larsson andcc %g4, 1, %g0 17774cad25cSAndreas Larsson be 5f 17874cad25cSAndreas Larsson nop 17974cad25cSAndreas Larsson retl 18074cad25cSAndreas Larsson mov %g1, %o0 18174cad25cSAndreas Larsson5: 1821da177e4SLinus Torvalds retl 1831da177e4SLinus Torvalds clr %o0 1841da177e4SLinus Torvalds__memset_end: 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds .section .fixup,#alloc,#execinstr 1871da177e4SLinus Torvalds .align 4 1881da177e4SLinus Torvalds20: 1891da177e4SLinus Torvalds cmp %g2, 8 1901da177e4SLinus Torvalds bleu 1f 1911da177e4SLinus Torvalds and %o1, 0x7f, %o1 1921da177e4SLinus Torvalds sub %g2, 9, %g2 1931da177e4SLinus Torvalds add %o3, 64, %o3 1941da177e4SLinus Torvalds1: 1951da177e4SLinus Torvalds sll %g2, 3, %g2 1961da177e4SLinus Torvalds add %o3, %o1, %o0 197*e51ea544SAl Viro retl 1981da177e4SLinus Torvalds sub %o0, %g2, %o0 1991da177e4SLinus Torvalds21: 2001da177e4SLinus Torvalds mov 8, %o0 2011da177e4SLinus Torvalds and %o1, 7, %o1 2021da177e4SLinus Torvalds sub %o0, %g2, %o0 2031da177e4SLinus Torvalds sll %o0, 3, %o0 204*e51ea544SAl Viro retl 2051da177e4SLinus Torvalds add %o0, %o1, %o0 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds .globl __bzero_end 2081da177e4SLinus Torvalds__bzero_end: 209