diff mbox

[5/9] Add halt() and some error codes

Message ID 1381767815-12510-6-git-send-email-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones Oct. 14, 2013, 4:23 p.m. UTC
Add a halt function that can be used by the test infrastructure on error
paths before exit() works. Also add some error codes that can be passed
to halt() in case the serial isn't working either. Then, on register
inspection of the halted guest we may be able to quickly determine the
problem without having to find the halt() call-site using its return
address.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/errno.h    | 15 +++++++++++++++
 lib/libcflat.h |  2 ++
 lib/x86/io.c   |  6 ++++++
 3 files changed, 23 insertions(+)
 create mode 100644 lib/errno.h
diff mbox

Patch

diff --git a/lib/errno.h b/lib/errno.h
new file mode 100644
index 0000000000000..4c7478229baf3
--- /dev/null
+++ b/lib/errno.h
@@ -0,0 +1,15 @@ 
+#ifndef _ERRNO_H_
+#define _ERRNO_H_
+/*
+ * Define some error codes for the test infrastructure's use.
+ * (Ab)use the standard E* names for syntax highlighting...
+ */
+#define MAXERR	127		/* exit(-1) */
+#define EINTR	(MAXERR - 1)	/* unhandled exception */
+#define EIO	(MAXERR - 2)	/* I/O error */
+#define ENXIO	(MAXERR - 3)	/* no serial */
+#define ENOEXEC	(MAXERR - 4)	/* bad test file format */
+#define ENOMEM	(MAXERR - 5)	/* Out of memory */
+#define ENODEV	(MAXERR - 6)	/* no testdev device */
+#define EINVAL	(MAXERR - 7)	/* Invalid argument */
+#endif
diff --git a/lib/libcflat.h b/lib/libcflat.h
index 140c172e77d54..a1be635ab4ee9 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -37,6 +37,7 @@  typedef _Bool bool;
 #define true 1
 #define false 0
 
+extern void halt(int code);
 extern void exit(int code);
 
 extern unsigned long strlen(const char *buf);
@@ -57,4 +58,5 @@  extern long atol(const char *ptr);
 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
 
 #define NULL ((void *)0UL)
+#include "errno.h"
 #endif
diff --git a/lib/x86/io.c b/lib/x86/io.c
index d3b971ef67b0e..7a36c9ca0c951 100644
--- a/lib/x86/io.c
+++ b/lib/x86/io.c
@@ -1,4 +1,5 @@ 
 #include "libcflat.h"
+#include "processor.h"
 #include "smp.h"
 #include "io.h"
 #ifndef USE_SERIAL
@@ -81,3 +82,8 @@  void exit(int code)
         asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4));
 #endif
 }
+
+void halt(int code)
+{
+	safe_halt();
+}