[PATCH kvm-unit-tests 4/8] powerpc: Introduce getchar

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the unit test specific h_get_term_char() to powerpc common code
and call it getchar(). Other architectures may want to implement
getchar() too (ARM will in a coming patch), so put the prototype in
libcflat.h

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/libcflat.h          |  1 +
 lib/powerpc/asm/hcall.h |  1 +
 lib/powerpc/hcall.c     | 12 ++++++++++++
 powerpc/sprs.c          | 14 +-------------
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/libcflat.h b/lib/libcflat.h
index fb465415c14a..c680b69a926e 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -82,6 +82,7 @@ typedef u64			phys_addr_t;
 #define INVALID_PHYS_ADDR	(~(phys_addr_t)0)
 
 extern void puts(const char *s);
+extern int getchar(void);
 extern void exit(int code);
 extern void abort(void);
 extern long atol(const char *ptr);
diff --git a/lib/powerpc/asm/hcall.h b/lib/powerpc/asm/hcall.h
index 80aa3e304382..a8bd7e3afc37 100644
--- a/lib/powerpc/asm/hcall.h
+++ b/lib/powerpc/asm/hcall.h
@@ -19,6 +19,7 @@
 #define H_SET_DABR		0x28
 #define H_PAGE_INIT		0x2c
 #define H_CEDE			0xE0
+#define H_GET_TERM_CHAR		0x54
 #define H_PUT_TERM_CHAR		0x58
 #define H_RANDOM		0x300
 #define H_SET_MODE		0x31C
diff --git a/lib/powerpc/hcall.c b/lib/powerpc/hcall.c
index cd6d26680f7c..d65af93697e4 100644
--- a/lib/powerpc/hcall.c
+++ b/lib/powerpc/hcall.c
@@ -31,3 +31,15 @@ void putchar(int c)
 
 	hcall(H_PUT_TERM_CHAR, vty, nr_chars, chars);
 }
+
+int getchar(void)
+{
+	register unsigned long r3 asm("r3") = H_GET_TERM_CHAR;
+	register unsigned long r4 asm("r4") = 0; /* 0 == default vty */
+	register unsigned long r5 asm("r5");
+
+	asm volatile (" sc 1 "  : "+r"(r3), "+r"(r4), "=r"(r5)
+				: "r"(r3),  "r"(r4));
+
+	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : 0;
+}
diff --git a/powerpc/sprs.c b/powerpc/sprs.c
index 3b920e9f929a..5b5a54032819 100644
--- a/powerpc/sprs.c
+++ b/powerpc/sprs.c
@@ -38,18 +38,6 @@
 
 uint64_t before[1024], after[1024];
 
-static int h_get_term_char(uint64_t termno)
-{
-	register uint64_t r3 asm("r3") = 0x54; /* H_GET_TERM_CHAR */
-	register uint64_t r4 asm("r4") = termno;
-	register uint64_t r5 asm("r5");
-
-	asm volatile (" sc 1 "	: "+r"(r3), "+r"(r4), "=r"(r5)
-				: "r"(r3),  "r"(r4));
-
-	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : 0;
-}
-
 /* Common SPRs for all PowerPC CPUs */
 static void set_sprs_common(uint64_t val)
 {
@@ -297,7 +285,7 @@ int main(int argc, char **argv)
 
 	if (pause) {
 		puts("Now migrate the VM, then press a key to continue...\n");
-		while (h_get_term_char(0) == 0)
+		while (getchar() == 0)
 			cpu_relax();
 	} else {
 		puts("Sleeping...\n");
-- 
2.13.6




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux