xref: /kvm-unit-tests/lib/s390x/io.c (revision 728e71ee457384eb1cf2d5111d1e4329498581db)
1 /*
2  * s390x io implementation
3  *
4  * Copyright (c) 2017 Red Hat Inc
5  *
6  * Authors:
7  *  Thomas Huth <thuth@redhat.com>
8  *  David Hildenbrand <david@redhat.com>
9  *
10  * This code is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Library General Public License version 2.
12  */
13 #include <libcflat.h>
14 #include <argv.h>
15 #include <asm/spinlock.h>
16 #include <asm/facility.h>
17 #include "sclp.h"
18 
19 extern char ipl_args[];
20 uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
21 
22 static struct spinlock lock;
23 
24 void setup(void);
25 
26 void puts(const char *s)
27 {
28 	spin_lock(&lock);
29 	sclp_print(s);
30 	spin_unlock(&lock);
31 }
32 
33 static void sigp_stop(void)
34 {
35 	register unsigned long status asm ("1") = 0;
36 	register unsigned long cpu asm ("2") = 0;
37 
38 	asm volatile(
39 		"	sigp %0,%1,0(%2)\n"
40 		: "+d" (status)  : "d" (cpu), "d" (5) : "cc");
41 }
42 
43 void setup(void)
44 {
45 	setup_args_progname(ipl_args);
46 	setup_facilities();
47 	sclp_ascii_setup();
48 	sclp_memory_setup();
49 }
50 
51 void exit(int code)
52 {
53 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
54 	sigp_stop();
55 }
56