xref: /kvm-unit-tests/s390x/snippets/c/cstart.S (revision 796217d86bec2b342b5db6a0bb6a179bfd7a180b)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Start assembly for snippets
4 *
5 * Copyright (c) 2021 IBM Corp.
6 *
7 * Authors:
8 *  Janosch Frank <frankja@linux.ibm.com>
9 */
10#include <asm/sigp.h>
11
12.section .init
13	.globl start
14start:
15	larl	%r1, initial_cr0
16	lctlg	%c0, %c0, 0(%r1)
17	/* XOR all registers with themselves to clear them fully. */
18	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
19	xgr \i,\i
20	.endr
21	sam64
22	/* 0x3000 is the stack page for now */
23	larl	%r15, stackptr
24	brasl	%r14, main
25	/*
26	 * If main() returns, we stop the CPU with the code below. We also
27	 * route some functions that are required by the libc (but not usable
28	 * from snippets) to the CPU stop code below, so that snippets can
29	 * still be linked against the libc code (to use non-related functions
30	 * like memset() etc.)
31	 */
32.global puts
33.global exit
34puts:
35exit:
36	/* For now let's only use cpu 0 in snippets so this will always work. */
37	xgr	%r0, %r0
38	sigp    %r2, %r0, SIGP_STOP
39
40	.align 8
41initial_cr0:
42	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
43	.quad	0x0000000000040000
44