Home | History | Annotate | Line # | Download | only in aarch64
      1 /*	$NetBSD: linux32_sigcode.S,v 1.2 2024/02/07 04:20:28 msaitoh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2021 Ryo Shimizu
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <machine/asm.h>
     30 
     31 RCSID("$NetBSD: linux32_sigcode.S,v 1.2 2024/02/07 04:20:28 msaitoh Exp $")
     32 
     33 #include <compat/linux32/linux32_syscall.h>
     34 
     35 /*
     36  * linux aarch32 Signal trampoline code
     37  */
     38 	.text
     39 	.section .rodata
     40 	.align 12
     41 
     42 	.global	_C_LABEL(linux32_sigcode)
     43 _C_LABEL(linux32_sigcode):
     44 	/* mov r7, #LINUX32_SYS_sigreturn */
     45 	.word	0xe3a07000 + LINUX32_SYS_sigreturn
     46 	.word	0xef000000	/* svc 0   */
     47 	/* NOTREACHED */
     48 	.word	0xe7f000f0	/* udf #0  */
     49 
     50 	.global	_C_LABEL(linux32_rt_sigcode)
     51 _C_LABEL(linux32_rt_sigcode):
     52 	/* mov r7, #LINUX32_SYS_rt_sigreturn */
     53 	.word	0xe3a07000 + LINUX32_SYS_rt_sigreturn
     54 	.word	0xef000000	/* svc 0   */
     55 	/* NOTREACHED */
     56 	.word	0xe7f000f0	/* udf #0  */
     57 
     58 /*
     59  * linux/arm kuser_helper
     60  *   - should be mapped on userspace vaddr 0xffff0f60
     61  *   - https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
     62  */
     63 
     64 .kuser_helper_pad:
     65 #define KUSER_HELPER_START	0x00000f60
     66 	.space	KUSER_HELPER_START - (.kuser_helper_pad - _C_LABEL(linux32_sigcode))
     67 
     68 /*
     69  * 0xffff0f60
     70  * int __kuser_cmpxchg64(const int64_t *oldval, const int64_t *newval, volatile int64_t *ptr);
     71  */
     72 .__kuser_cmpxchg64:
     73 	.word	0xe92d00f0	/* push {r4, r5, r6, r7}  */
     74 	.word	0xf57ff05f	/* dmb sy                 */
     75 	.word	0xe1c040d0	/* ldrd r4, [r0]          */
     76 	.word	0xe1c160d0	/* ldrd r6, [r1]          */
     77 	.word	0xe1b20f9f	/* ldrexd r0, [r2]        */
     78 	.word	0xe0500004	/* subs r0, r0, r4        */
     79 	.word	0xe0c11005	/* sbc r1, r1, r5         */
     80 	.word	0xe1900001	/* orrs r0, r0, r1        */
     81 	.word	0x01a20f96	/* strexdeq r0, r6, [r2]  */
     82 	.word	0xf57ff05f	/* dmb sy                 */
     83 	.word	0xe8bd00f0	/* pop {r4, r5, r6, r7}   */
     84 	.word	0xe12fff1e	/* bx lr                  */
     85 
     86 	.align	5
     87 /*
     88  * 0xffff0fa0
     89  * void __kuser_memory_barrier(void);
     90  */
     91 .__kuser_memory_barrier:
     92 	.word	0xf57ff05f	/* dmb sy  */
     93 	.word	0xe12fff1e	/* bx lr   */
     94 
     95 	.align	5
     96 /*
     97  * 0xffff0fc0
     98  * int __kuser_cmpxchg(int32_t oldval, int32_t newval, volatile int32_t *ptr);
     99  */
    100 .__kuser_cmpxchg:
    101 	.word	0xf57ff05f	/* dmb sy                */
    102 	.word	0xe1923f9f	/* ldrex r3, [r2]        */
    103 	.word	0xe0530000	/* subs r0, r3, r0       */
    104 	.word	0x01820f91	/* strexeq r0, r1, [r2]  */
    105 	.word	0xf57ff05f	/* dmb sy                */
    106 	.word	0xe12fff1e	/* bx lr                 */
    107 
    108 
    109 	.align	5
    110 /* 0xffff0fe0 */
    111 .__kuser_get_tls:
    112 	.word	0xee1d0f70	/* mrc p15, 0, r0, c13, c0, 3  */
    113 	.word	0xe12fff1e	/* bx lr                       */
    114 
    115 	.align	4
    116 /* 0xffff0ff0 */
    117 	.word	0
    118 /* 0xffff0ff4 */
    119 	.word	0
    120 /* 0xffff0ff8 */
    121 	.word	0
    122 
    123 /* 0xffff0ffc */
    124 .__kuser_helper_version:
    125 	.word	2
    126 
    127 
    128 	.global	_C_LABEL(linux32_esigcode)
    129 _C_LABEL(linux32_esigcode):
    130