xref: /kvm-unit-tests/s390x/snippets/c/cstart.S (revision 1a4529ce83922a5da6a68d3c659c51833e7d691e)
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,15
19	xgr \i,\i
20	.endr
21	/* 0x3000 is the stack page for now */
22	lghi	%r15, stackptr
23	sam64
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
40initial_cr0:
41	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
42	.quad	0x0000000000040000
43