xref: /kvm-unit-tests/lib/powerpc/io.c (revision 2c96b77ec9d3b1fcec7525174e23a6240ee05949)
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 #include <asm/setup.h>
12 #include "io.h"
13 
14 static struct spinlock print_lock;
15 
16 void io_init(void)
17 {
18 	rtas_init();
19 }
20 
21 void puts(const char *s)
22 {
23 	spin_lock(&print_lock);
24 	while (*s)
25 		putchar(*s++);
26 	spin_unlock(&print_lock);
27 }
28 
29 /*
30  * Defining halt to take 'code' as an argument guarantees that it will
31  * be in r3 when we halt. That gives us a final chance to see the exit
32  * status while inspecting the halted unit test state.
33  */
34 extern void halt(int code);
35 
36 void exit(int code)
37 {
38 // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(),
39 //        maybe by plugging chr-testdev into a spapr-vty.
40 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
41 	rtas_power_off();
42 	halt(code);
43 	__builtin_unreachable();
44 }
45