xref: /netbsd-src/sys/compat/linux32/arch/aarch64/linux32_sigcode.S (revision 90313c06e62e910bf0d1bb24faa9d17dcefd0ab6)
1*90313c06Smsaitoh/*	$NetBSD: linux32_sigcode.S,v 1.2 2024/02/07 04:20:28 msaitoh Exp $	*/
22f5e5e73Sryo
32f5e5e73Sryo/*-
4*90313c06Smsaitoh * Copyright (c) 2021 Ryo Shimizu
52f5e5e73Sryo * All rights reserved.
62f5e5e73Sryo *
72f5e5e73Sryo * Redistribution and use in source and binary forms, with or without
82f5e5e73Sryo * modification, are permitted provided that the following conditions
92f5e5e73Sryo * are met:
102f5e5e73Sryo * 1. Redistributions of source code must retain the above copyright
112f5e5e73Sryo *    notice, this list of conditions and the following disclaimer.
122f5e5e73Sryo * 2. Redistributions in binary form must reproduce the above copyright
132f5e5e73Sryo *    notice, this list of conditions and the following disclaimer in the
142f5e5e73Sryo *    documentation and/or other materials provided with the distribution.
152f5e5e73Sryo *
162f5e5e73Sryo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
172f5e5e73Sryo * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
182f5e5e73Sryo * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192f5e5e73Sryo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
202f5e5e73Sryo * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
212f5e5e73Sryo * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
222f5e5e73Sryo * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232f5e5e73Sryo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
242f5e5e73Sryo * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
252f5e5e73Sryo * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
262f5e5e73Sryo * POSSIBILITY OF SUCH DAMAGE.
272f5e5e73Sryo */
282f5e5e73Sryo
292f5e5e73Sryo#include <machine/asm.h>
302f5e5e73Sryo
31*90313c06SmsaitohRCSID("$NetBSD: linux32_sigcode.S,v 1.2 2024/02/07 04:20:28 msaitoh Exp $")
322f5e5e73Sryo
332f5e5e73Sryo#include <compat/linux32/linux32_syscall.h>
342f5e5e73Sryo
352f5e5e73Sryo/*
362f5e5e73Sryo * linux aarch32 Signal trampoline code
372f5e5e73Sryo */
382f5e5e73Sryo	.text
392f5e5e73Sryo	.section .rodata
402f5e5e73Sryo	.align 12
412f5e5e73Sryo
422f5e5e73Sryo	.global	_C_LABEL(linux32_sigcode)
432f5e5e73Sryo_C_LABEL(linux32_sigcode):
442f5e5e73Sryo	/* mov r7, #LINUX32_SYS_sigreturn */
452f5e5e73Sryo	.word	0xe3a07000 + LINUX32_SYS_sigreturn
462f5e5e73Sryo	.word	0xef000000	/* svc 0   */
472f5e5e73Sryo	/* NOTREACHED */
482f5e5e73Sryo	.word	0xe7f000f0	/* udf #0  */
492f5e5e73Sryo
502f5e5e73Sryo	.global	_C_LABEL(linux32_rt_sigcode)
512f5e5e73Sryo_C_LABEL(linux32_rt_sigcode):
522f5e5e73Sryo	/* mov r7, #LINUX32_SYS_rt_sigreturn */
532f5e5e73Sryo	.word	0xe3a07000 + LINUX32_SYS_rt_sigreturn
542f5e5e73Sryo	.word	0xef000000	/* svc 0   */
552f5e5e73Sryo	/* NOTREACHED */
562f5e5e73Sryo	.word	0xe7f000f0	/* udf #0  */
572f5e5e73Sryo
582f5e5e73Sryo/*
592f5e5e73Sryo * linux/arm kuser_helper
602f5e5e73Sryo *   - should be mapped on userspace vaddr 0xffff0f60
612f5e5e73Sryo *   - https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
622f5e5e73Sryo */
632f5e5e73Sryo
642f5e5e73Sryo.kuser_helper_pad:
652f5e5e73Sryo#define KUSER_HELPER_START	0x00000f60
662f5e5e73Sryo	.space	KUSER_HELPER_START - (.kuser_helper_pad - _C_LABEL(linux32_sigcode))
672f5e5e73Sryo
682f5e5e73Sryo/*
692f5e5e73Sryo * 0xffff0f60
702f5e5e73Sryo * int __kuser_cmpxchg64(const int64_t *oldval, const int64_t *newval, volatile int64_t *ptr);
712f5e5e73Sryo */
722f5e5e73Sryo.__kuser_cmpxchg64:
732f5e5e73Sryo	.word	0xe92d00f0	/* push {r4, r5, r6, r7}  */
742f5e5e73Sryo	.word	0xf57ff05f	/* dmb sy                 */
752f5e5e73Sryo	.word	0xe1c040d0	/* ldrd r4, [r0]          */
762f5e5e73Sryo	.word	0xe1c160d0	/* ldrd r6, [r1]          */
772f5e5e73Sryo	.word	0xe1b20f9f	/* ldrexd r0, [r2]        */
782f5e5e73Sryo	.word	0xe0500004	/* subs r0, r0, r4        */
792f5e5e73Sryo	.word	0xe0c11005	/* sbc r1, r1, r5         */
802f5e5e73Sryo	.word	0xe1900001	/* orrs r0, r0, r1        */
812f5e5e73Sryo	.word	0x01a20f96	/* strexdeq r0, r6, [r2]  */
822f5e5e73Sryo	.word	0xf57ff05f	/* dmb sy                 */
832f5e5e73Sryo	.word	0xe8bd00f0	/* pop {r4, r5, r6, r7}   */
842f5e5e73Sryo	.word	0xe12fff1e	/* bx lr                  */
852f5e5e73Sryo
862f5e5e73Sryo	.align	5
872f5e5e73Sryo/*
882f5e5e73Sryo * 0xffff0fa0
892f5e5e73Sryo * void __kuser_memory_barrier(void);
902f5e5e73Sryo */
912f5e5e73Sryo.__kuser_memory_barrier:
922f5e5e73Sryo	.word	0xf57ff05f	/* dmb sy  */
932f5e5e73Sryo	.word	0xe12fff1e	/* bx lr   */
942f5e5e73Sryo
952f5e5e73Sryo	.align	5
962f5e5e73Sryo/*
972f5e5e73Sryo * 0xffff0fc0
982f5e5e73Sryo * int __kuser_cmpxchg(int32_t oldval, int32_t newval, volatile int32_t *ptr);
992f5e5e73Sryo */
1002f5e5e73Sryo.__kuser_cmpxchg:
1012f5e5e73Sryo	.word	0xf57ff05f	/* dmb sy                */
1022f5e5e73Sryo	.word	0xe1923f9f	/* ldrex r3, [r2]        */
1032f5e5e73Sryo	.word	0xe0530000	/* subs r0, r3, r0       */
1042f5e5e73Sryo	.word	0x01820f91	/* strexeq r0, r1, [r2]  */
1052f5e5e73Sryo	.word	0xf57ff05f	/* dmb sy                */
1062f5e5e73Sryo	.word	0xe12fff1e	/* bx lr                 */
1072f5e5e73Sryo
1082f5e5e73Sryo
1092f5e5e73Sryo	.align	5
1102f5e5e73Sryo/* 0xffff0fe0 */
1112f5e5e73Sryo.__kuser_get_tls:
1122f5e5e73Sryo	.word	0xee1d0f70	/* mrc p15, 0, r0, c13, c0, 3  */
1132f5e5e73Sryo	.word	0xe12fff1e	/* bx lr                       */
1142f5e5e73Sryo
1152f5e5e73Sryo	.align	4
1162f5e5e73Sryo/* 0xffff0ff0 */
1172f5e5e73Sryo	.word	0
1182f5e5e73Sryo/* 0xffff0ff4 */
1192f5e5e73Sryo	.word	0
1202f5e5e73Sryo/* 0xffff0ff8 */
1212f5e5e73Sryo	.word	0
1222f5e5e73Sryo
1232f5e5e73Sryo/* 0xffff0ffc */
1242f5e5e73Sryo.__kuser_helper_version:
1252f5e5e73Sryo	.word	2
1262f5e5e73Sryo
1272f5e5e73Sryo
1282f5e5e73Sryo	.global	_C_LABEL(linux32_esigcode)
1292f5e5e73Sryo_C_LABEL(linux32_esigcode):
130