xref: /kvm-unit-tests/lib/powerpc/io.c (revision 6ed97c50871a0d85e9ef5e1f4da96bc4263b4b97)
1 /*
2  * Each architecture must implement puts() and exit().
3  *
4  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
5  *
6  * This work is licensed under the terms of the GNU LGPL, version 2.
7  */
8 #include <libcflat.h>
9 #include <asm/spinlock.h>
10 #include <asm/rtas.h>
11 
12 extern void halt(int code);
13 extern void putchar(int c);
14 
15 static struct spinlock print_lock;
16 
17 void io_init(void)
18 {
19 	rtas_init();
20 }
21 
22 void puts(const char *s)
23 {
24 	spin_lock(&print_lock);
25 	while (*s)
26 		putchar(*s++);
27 	spin_unlock(&print_lock);
28 }
29 
30 void exit(int code)
31 {
32 // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(),
33 //        maybe by plugging chr-testdev into a spapr-vty.
34 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
35 	rtas_power_off();
36 	halt(code);
37 }
38