xref: /kvm-unit-tests/lib/powerpc/io.c (revision 96d79976f779589bbdbb24474de8fd214b179d7e)
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 extern void halt(int code);
15 
16 static struct spinlock print_lock;
17 
18 void io_init(void)
19 {
20 	rtas_init();
21 }
22 
23 void puts(const char *s)
24 {
25 	spin_lock(&print_lock);
26 	while (*s)
27 		putchar(*s++);
28 	spin_unlock(&print_lock);
29 }
30 
31 void exit(int code)
32 {
33 // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(),
34 //        maybe by plugging chr-testdev into a spapr-vty.
35 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
36 	rtas_power_off();
37 	halt(code);
38 	__builtin_unreachable();
39 }
40