aboutsummaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/pdcurses-backend
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@secunet.com>2011-07-07 15:41:53 +0200
committerStefan Reinauer <stefan.reinauer@coreboot.org>2011-08-04 08:10:41 +0200
commit3b77b723ca209199c8a224702812441e2196d452 (patch)
treecbf3be2c724139ec80a33dbf8e002b7871ef9307 /payloads/libpayload/curses/pdcurses-backend
parent1ac19e28eed4f6c53a4f295eb55500c65fc80f8d (diff)
libpayload: Add PDCurses and ncurses' libform/libmenu
PDCurses provides an alternative implementation of the curses library standard in addition to tinycurses. Where tinycurses is really tiny, PDCurses is more complete and provides virtually unlimited windows and the full API. The PDCurses code is brought in "vanilla", with all local changes residing in curses/pdcurses-backend/ In addition to a curses library, this change also provides libpanel (as part of the PDCurses code), and libform and libmenu which were derived from ncurses-5.9. As they rely on ncurses internals (and PDCurses is not ncurses), more changes were required for these libraries to work. The build system is extended to install the right set of header files depending on the selected curses implementation. Change-Id: I9e5b920f94b6510da01da2f656196a993170d1c5 Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Reviewed-on: http://review.coreboot.org/106 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones <marcj303@gmail.com>
Diffstat (limited to 'payloads/libpayload/curses/pdcurses-backend')
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/config.h134
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/lppdc.h10
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/nc_alloc.h4
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/ncurses_cfg.h40
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdcdisp.c247
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdcgetsc.c48
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdckbd.c194
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdcscrn.c161
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdcsetsc.c32
-rw-r--r--payloads/libpayload/curses/pdcurses-backend/pdcutil.c49
10 files changed, 919 insertions, 0 deletions
diff --git a/payloads/libpayload/curses/pdcurses-backend/config.h b/payloads/libpayload/curses/pdcurses-backend/config.h
new file mode 100644
index 0000000000..a338593473
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/config.h
@@ -0,0 +1,134 @@
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define if you have the <DECkeySym.h> header file */
+/* #undef HAVE_DECKEYSYM_H */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <dl.h> header file. */
+/* #undef HAVE_DL_H */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+/* #undef HAVE_FCNTL_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `poll' function. */
+/* #undef HAVE_POLL */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define if you have the <Sunkeysym.h> header file */
+/* #undef HAVE_SUNKEYSYM_H */
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+/* #undef HAVE_SYS_SELECT_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+/* #undef HAVE_SYS_STAT_H */
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `usleep' function. */
+#define HAVE_USLEEP 1
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#define HAVE_VSNPRINTF 1
+
+/* Define to 1 if you have the `vsscanf' function. */
+#define HAVE_VSSCANF 1
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_BEGIN */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_DELETE */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_DOWN */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_END */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_HOME */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_INSERT */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_LEFT */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_NEXT */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_PRIOR */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_RIGHT */
+
+/* Define if you have this defined in <keysym.h> */
+/* #undef HAVE_XK_KP_UP */
+
+/* Define if you have the <xpm.h> header file */
+/* #undef HAVE_XPM_H */
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "coreboot@coreboot.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "PDCurses"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "PDCurses 3.4+libpayload"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "PDCurses"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "3.4+libpayload"
+
+/* Define as the system defined limit for number of signals */
+#define PDC_MAX_SIGNALS NSIG
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Define if you want to use neXtaw library */
+/* #undef USE_NEXTAW */
+
+/* Define if you want to use Xaw3d library */
+/* #undef USE_XAW3D */
+
+/* Define XPointer is typedefed in X11/Xlib.h */
+/* #undef XPOINTER_TYPEDEFED */
diff --git a/payloads/libpayload/curses/pdcurses-backend/lppdc.h b/payloads/libpayload/curses/pdcurses-backend/lppdc.h
new file mode 100644
index 0000000000..56330a9336
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/lppdc.h
@@ -0,0 +1,10 @@
+#include <libpayload-config.h>
+#include <curses.h>
+#include <curspriv.h>
+
+extern int curses_flags;
+extern unsigned char *pdc_atrtab;
+extern short curstoreal[16], realtocurs[16];
+
+#define F_ENABLE_CONSOLE 1
+#define F_ENABLE_SERIAL 2
diff --git a/payloads/libpayload/curses/pdcurses-backend/nc_alloc.h b/payloads/libpayload/curses/pdcurses-backend/nc_alloc.h
new file mode 100644
index 0000000000..95d41f9aa9
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/nc_alloc.h
@@ -0,0 +1,4 @@
+#define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type))
+#define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type))
+#define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type))
+
diff --git a/payloads/libpayload/curses/pdcurses-backend/ncurses_cfg.h b/payloads/libpayload/curses/pdcurses-backend/ncurses_cfg.h
new file mode 100644
index 0000000000..c6184bebc5
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/ncurses_cfg.h
@@ -0,0 +1,40 @@
+#define USE_RCS_IDS 0
+#define USE_WIDEC_SUPPORT 0
+#define NCURSES_SP_FUNCS 0
+#define DECL_ERRNO 0
+#define NCURSES_INTEROP_FUNCS 0
+
+#define NCURSES_API
+#define NCURSES_IMPEXP
+#define NCURSES_INLINE
+#define NCURSES_SP_DCLx
+#define NCURSES_SP_NAME(x) x
+#define NCURSES_EXPORT_VAR(x) x
+#define NCURSES_EXPORT(x) x
+
+#define SP_PARM SP
+#define CURRENT_SCREEN SP
+#define StdScreen(x) stdscr
+
+#define T(x)
+#define T_CALLED(x...)
+
+#define GCC_UNUSED __attribute__((unused))
+
+#define BLANK (' '|A_NORMAL)
+#define ZEROS ('\0'|A_NORMAL)
+#define ISBLANK isblank
+
+#define ChCharOf(c) ((c) & (chtype)A_CHARTEXT)
+#define CharOf(c) ChCharOf(c)
+
+#define WINDOW_ATTRS(x) ((x)->_attrs)
+#define IsValidScreen(x) 1
+
+#define returnCode return
+#define returnWin return
+#define returnCPtr return
+#define returnVoidPtr return
+#define returnPtr return
+#define returnAttr return
+#define returnBool return
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c b/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c
new file mode 100644
index 0000000000..80073ac73a
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c
@@ -0,0 +1,247 @@
+/* Public Domain Curses */
+/* This file is BSD licensed, Copyright 2011 secunet AG */
+
+#include "lppdc.h"
+#include <libpayload.h>
+
+/* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these
+ match code page 437 and compatible pages (CP850, CP852, etc.) */
+
+#ifdef CHTYPE_LONG
+
+# define A(x) ((chtype)x | A_ALTCHARSET)
+
+chtype acs_map[128] =
+{
+ A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10),
+ A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19),
+ A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28),
+ A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(',
+ ')', '*',
+
+ A(0x1a), A(0x1b), A(0x18), A(0x19),
+
+ '/',
+
+ 0xdb,
+
+ '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
+ '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
+
+ A(0x04), 0xb1,
+
+ 'b', 'c', 'd', 'e',
+
+ 0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 0x2d,
+ 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 0xe3,
+ 0xd8, 0x9c, 0xf9,
+
+ A(127)
+};
+
+# undef A
+
+#endif
+
+/* See terminfo(5). */
+chtype fallback_acs_map[128] =
+ {
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', '>', '<', '^', 'v', ' ',
+ '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ '+', ':', ' ', ' ', ' ', ' ', '\\', '#',
+ '#', '#', '+', '+', '+', '+', '+', '~',
+ '-', '-', '-', '_', '+', '+', '+', '+',
+ '|', '<', '>', '*', '!', 'f', 'o', ' ',
+ };
+
+#ifdef CONFIG_SERIAL_CONSOLE
+#ifdef CONFIG_SERIAL_ACS_FALLBACK
+chtype serial_acs_map[128];
+#else
+/* See acsc of vt100. */
+chtype serial_acs_map[128] =
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ '`', 'a', 0, 0, 0, 0, 'f', 'g',
+ 0, 0, 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', '{', '|', '}', '~', 0,
+ };
+#endif
+#endif
+
+#ifdef CONFIG_VIDEO_CONSOLE
+/* See acsc of linux. */
+chtype console_acs_map[128] =
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, '\020', '\021', '\030', '\031', 0,
+ '\333', 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ '\004', '\261', 0, 0, 0, 0, '\370', '\361',
+ '\260', '\316', '\331', '\277', '\332', '\300', '\305', '~',
+ '\304', '\304', '\304', '_', '\303', '\264', '\301', '\302',
+ '\263', '\363', '\362', '\343', '\330', '\234', '\376', 0,
+ };
+#endif
+
+/* position hardware cursor at (y, x) */
+
+void PDC_gotoyx(int row, int col)
+{
+ PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ serial_set_cursor(col, row);
+#endif
+#ifdef CONFIG_VIDEO_CONSOLE
+ video_console_set_cursor(col, row);
+#endif
+}
+
+/* update the given physical line to look like the corresponding line in
+ curscr */
+
+void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
+{
+ int j, ch, attr;
+
+ PDC_LOG(("PDC_transform_line() - called: line %d, len %d, curses_flags %d\n", lineno, len, curses_flags));
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ int serial_is_bold = 0;
+ int serial_is_reverse = 0;
+ int serial_is_altcharset = 0;
+ int serial_cur_pair = 0;
+ int need_altcharset;
+
+ if (curses_flags & F_ENABLE_SERIAL) {
+ serial_end_bold();
+ serial_end_altcharset();
+ serial_set_cursor(lineno, x);
+ }
+#endif
+
+ for (j = 0; j < len; j++)
+ {
+ ch = srcp[j];
+ attr = ch;
+#ifdef CONFIG_SERIAL_CONSOLE
+ if (curses_flags & F_ENABLE_SERIAL) {
+ if (attr & A_BOLD) {
+ if (!serial_is_bold) {
+ serial_start_bold();
+ serial_is_bold = 1;
+ }
+ } else {
+ if (serial_is_bold) {
+ serial_end_bold();
+ serial_is_bold = 0;
+ /* work around serial.c
+ * shortcoming:
+ */
+ serial_is_reverse = 0;
+ serial_cur_pair = 0;
+ }
+ }
+
+ if (attr & A_REVERSE) {
+ if (!serial_is_reverse) {
+ serial_start_reverse();
+ serial_is_reverse = 1;
+ }
+ } else {
+ if (serial_is_reverse) {
+ serial_end_reverse();
+ serial_is_reverse = 0;
+ /* work around serial.c
+ * shortcoming:
+ */
+ serial_is_bold = 0;
+ serial_cur_pair = 0;
+ }
+ }
+
+ need_altcharset = 0;
+ if (attr & A_ALTCHARSET) {
+ if (serial_acs_map[ch & 0x7f]) {
+ ch = serial_acs_map[ch & 0x7f];
+ need_altcharset = 1;
+ } else
+ ch = fallback_acs_map[ch & 0x7f];
+ }
+ if (need_altcharset && !serial_is_altcharset) {
+ serial_start_altcharset();
+ serial_is_altcharset = 1;
+ }
+ if (!need_altcharset && serial_is_altcharset) {
+ serial_end_altcharset();
+ serial_is_altcharset = 0;
+ }
+
+ if (serial_cur_pair != PAIR_NUMBER(attr)) {
+ short int fg, bg;
+ pair_content(PAIR_NUMBER(attr),
+ &fg, &bg);
+ serial_set_color(fg, bg);
+ serial_cur_pair = PAIR_NUMBER(attr);
+ }
+
+ serial_putchar(ch & 0xff);
+
+ }
+#endif
+#ifdef CONFIG_VIDEO_CONSOLE
+ unsigned char c = pdc_atrtab[srcp[j] >> PDC_ATTR_SHIFT];
+
+ if (curses_flags & F_ENABLE_CONSOLE) {
+ if (attr & A_ALTCHARSET) {
+ if (console_acs_map[ch & 0x7f])
+ ch = console_acs_map[ch & 0x7f];
+ else
+ ch = fallback_acs_map[ch & 0x7f];
+ }
+
+ /*
+ * FIXME: Somewhere along the line, the
+ * character value is getting sign-extented.
+ * For now grab just the 8 bit character,
+ * but this will break wide characters!
+ */
+ video_console_putc(lineno, x + j, (c << 8) | ( ch & 0xff));
+ }
+#endif
+ }
+}
+
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcgetsc.c b/payloads/libpayload/curses/pdcurses-backend/pdcgetsc.c
new file mode 100644
index 0000000000..835b840fba
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdcgetsc.c
@@ -0,0 +1,48 @@
+/* Public Domain Curses */
+/* This file is BSD licensed, Copyright 2011 secunet AG */
+
+#include "lppdc.h"
+
+#include <stdlib.h>
+
+/* return width of screen/viewport */
+
+int PDC_get_columns(void)
+{
+ int cols;
+
+ PDC_LOG(("PDC_get_columns() - called\n"));
+
+ /* hardcode to 80 */
+ cols = 80;
+
+ PDC_LOG(("PDC_get_columns() - returned: cols %d\n", cols));
+
+ return cols;
+}
+
+/* get the cursor size/shape */
+
+int PDC_get_cursor_mode(void)
+{
+ PDC_LOG(("PDC_get_cursor_mode() - called\n"));
+
+ /* only have one cursor type */
+ return SP->visibility;
+}
+
+/* return number of screen rows */
+
+int PDC_get_rows(void)
+{
+ int rows;
+
+ PDC_LOG(("PDC_get_rows() - called\n"));
+
+ /* hardcode to 25 */
+ rows = 25;
+
+ PDC_LOG(("PDC_get_rows() - returned: rows %d\n", rows));
+
+ return rows;
+}
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdckbd.c b/payloads/libpayload/curses/pdcurses-backend/pdckbd.c
new file mode 100644
index 0000000000..4a039ffbc4
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdckbd.c
@@ -0,0 +1,194 @@
+/* Public Domain Curses */
+
+#include "lppdc.h"
+#include <usb/usb.h>
+
+unsigned long pdc_key_modifiers = 0L;
+
+#ifdef CONFIG_SERIAL_CONSOLE
+/* We treat serial like a vt100 terminal. For now we
+ do the cooking in here, but we should probably eventually
+ pass it to dedicated vt100 code */
+
+static int getkeyseq(char *buffer, int len, int max)
+{
+ int i;
+
+ while (1) {
+ for(i = 0; i < 75; i++) {
+ if (serial_havechar())
+ break;
+ mdelay(1);
+ }
+
+ if (i == 75)
+ return len;
+
+ buffer[len++] = serial_getchar();
+ if (len == max)
+ return len;
+ }
+}
+
+static struct {
+ const char *seq;
+ int key;
+} escape_codes[] = {
+ { "[A", KEY_UP },
+ { "[B", KEY_DOWN },
+ { "[C", KEY_RIGHT },
+ { "[D", KEY_LEFT },
+ { "[F", KEY_END },
+ { "[H", KEY_HOME },
+ { "[2~", KEY_IC },
+ { "[3~", KEY_DC },
+ { "[5~", KEY_PPAGE },
+ { "[6~", KEY_NPAGE },
+ { "OP", KEY_F(1) },
+ { "OQ", KEY_F(2) },
+ { "OR", KEY_F(3) },
+ { "OS", KEY_F(4) },
+ { "[15~", KEY_F(5) },
+ { "[17~", KEY_F(6) },
+ { "[18~", KEY_F(7) },
+ { "[19~", KEY_F(8) },
+ { "[20~", KEY_F(9) },
+ { "[21~", KEY_F(10) },
+ { "[23~", KEY_F(11) },
+ { "[24~", KEY_F(12) },
+ { NULL },
+};
+
+static int handle_escape(void)
+{
+ char buffer[5];
+ int len = getkeyseq(buffer, 0, sizeof(buffer));
+ int i, t;
+
+ if (len == 0)
+ return 27;
+
+ for(i = 0; escape_codes[i].seq != NULL; i++) {
+ const char *p = escape_codes[i].seq;
+
+ for(t = 0; t < len; t++) {
+ if (!*p || *p != buffer[t])
+ break;
+ p++;
+ }
+
+ if (t == len)
+ return escape_codes[i].key;
+ }
+
+ return 0;
+}
+
+static int cook_serial(unsigned char ch)
+{
+ switch(ch) {
+ case 8:
+ return KEY_BACKSPACE;
+
+ case 27:
+ return handle_escape();
+
+ default:
+ return ch;
+ }
+}
+#endif
+
+void PDC_set_keyboard_binary(bool on)
+{
+ PDC_LOG(("PDC_set_keyboard_binary() - called\n"));
+}
+
+/* check if a key event is waiting */
+
+bool PDC_check_key(void)
+{
+#ifdef CONFIG_USB_HID
+ usb_poll();
+ if ((curses_flags & F_ENABLE_CONSOLE) &&
+ usbhid_havechar()) {
+ return TRUE;
+ }
+#endif
+
+#ifdef CONFIG_PC_KEYBOARD
+ if ((curses_flags & F_ENABLE_CONSOLE) &&
+ keyboard_havechar()) {
+ return TRUE;
+ }
+#endif
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ if ((curses_flags & F_ENABLE_SERIAL) &&
+ serial_havechar()) {
+ return TRUE;
+ }
+#endif
+
+ return FALSE;
+}
+
+/* return the next available key event */
+
+int PDC_get_key(void)
+{
+ int c = 0;
+
+#ifdef CONFIG_USB_HID
+ usb_poll();
+ if ((curses_flags & F_ENABLE_CONSOLE) &&
+ usbhid_havechar()) {
+ c = usbhid_getchar();
+ }
+#endif
+
+#ifdef CONFIG_PC_KEYBOARD
+ if ((curses_flags & F_ENABLE_CONSOLE) &&
+ keyboard_havechar()) {
+ c = keyboard_getchar();
+ }
+#endif
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ if ((curses_flags & F_ENABLE_SERIAL) &&
+ serial_havechar()) {
+ c = cook_serial(serial_getchar());
+ }
+#endif
+
+ SP->key_code = FALSE;
+
+ if (c == 0) {
+ c = ERR;
+ }
+ if (c >= KEY_MIN) {
+ SP->key_code = TRUE;
+ }
+
+ return c;
+}
+
+/* discard any pending keyboard input -- this is the core
+ routine for flushinp() */
+
+void PDC_flushinp(void)
+{
+ PDC_LOG(("PDC_flushinp() - called\n"));
+
+ while (PDC_check_key()) PDC_get_key();
+}
+
+int PDC_mouse_set(void)
+{
+ return ERR;
+}
+
+int PDC_modifiers_set(void)
+{
+ return OK;
+}
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcscrn.c b/payloads/libpayload/curses/pdcurses-backend/pdcscrn.c
new file mode 100644
index 0000000000..b8d9e4e3d6
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdcscrn.c
@@ -0,0 +1,161 @@
+/* Public Domain Curses */
+
+#include "lppdc.h"
+
+#include <stdlib.h>
+
+#ifdef CHTYPE_LONG
+# define PDC_OFFSET 32
+#else
+# define PDC_OFFSET 8
+#endif
+
+/* COLOR_PAIR to attribute encoding table. */
+
+unsigned char *pdc_atrtab = (unsigned char *)NULL;
+
+short curstoreal[16], realtocurs[16] =
+{
+ COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED,
+ COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8,
+ COLOR_BLUE + 8, COLOR_GREEN + 8, COLOR_CYAN + 8, COLOR_RED + 8,
+ COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8
+};
+
+/* close the physical screen -- may restore the screen to its state
+ before PDC_scr_open(); miscellaneous cleanup */
+
+void PDC_scr_close(void)
+{
+ PDC_LOG(("PDC_scr_close() - called\n"));
+
+ reset_shell_mode();
+
+ if (SP->visibility != 1)
+ curs_set(1);
+
+ /* Position cursor to the bottom left of the screen. */
+
+ PDC_gotoyx(PDC_get_rows() - 2, 0);
+}
+
+void PDC_scr_free(void)
+{
+ if (SP)
+ free(SP);
+ if (pdc_atrtab)
+ free(pdc_atrtab);
+
+ pdc_atrtab = (unsigned char *)NULL;
+}
+
+/* open the physical screen -- allocate SP, miscellaneous intialization,
+ and may save the existing screen for later restoration */
+
+int PDC_scr_open(int argc, char **argv)
+{
+ int i;
+
+ PDC_LOG(("PDC_scr_open() - called\n"));
+
+ SP = calloc(1, sizeof(SCREEN));
+ pdc_atrtab = calloc(PDC_COLOR_PAIRS * PDC_OFFSET, 1);
+
+ if (!SP || !pdc_atrtab)
+ return ERR;
+
+ for (i = 0; i < 16; i++)
+ curstoreal[realtocurs[i]] = i;
+
+ SP->orig_attr = FALSE;
+
+ SP->lines = PDC_get_rows();
+ SP->cols = PDC_get_columns();
+
+#if CONFIG_SPEAKER
+ SP->audible = TRUE;
+#endif
+
+ return OK;
+}
+
+/* the core of resize_term() */
+
+int PDC_resize_screen(int nlines, int ncols)
+{
+ PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
+ nlines, ncols));
+
+ return ERR;
+}
+
+void PDC_reset_prog_mode(void)
+{
+ PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
+}
+
+void PDC_reset_shell_mode(void)
+{
+ PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
+}
+
+void PDC_restore_screen_mode(int i)
+{
+}
+
+void PDC_save_screen_mode(int i)
+{
+}
+
+void PDC_init_pair(short pair, short fg, short bg)
+{
+ unsigned char att, temp_bg;
+ chtype i;
+
+ fg = curstoreal[fg];
+ bg = curstoreal[bg];
+
+ for (i = 0; i < PDC_OFFSET; i++)
+ {
+ att = fg | (bg << 4);
+
+ if (i & (A_REVERSE >> PDC_ATTR_SHIFT))
+ att = bg | (fg << 4);
+ if (i & (A_UNDERLINE >> PDC_ATTR_SHIFT))
+ att = 1;
+ if (i & (A_INVIS >> PDC_ATTR_SHIFT))
+ {
+ temp_bg = att >> 4;
+ att = temp_bg << 4 | temp_bg;
+ }
+ if (i & (A_BOLD >> PDC_ATTR_SHIFT))
+ att |= 8;
+ if (i & (A_BLINK >> PDC_ATTR_SHIFT))
+ att |= 128;
+
+ pdc_atrtab[pair * PDC_OFFSET + i] = att;
+ }
+}
+
+int PDC_pair_content(short pair, short *fg, short *bg)
+{
+ *fg = realtocurs[pdc_atrtab[pair * PDC_OFFSET] & 0x0F];
+ *bg = realtocurs[(pdc_atrtab[pair * PDC_OFFSET] & 0xF0) >> 4];
+
+ return OK;
+}
+
+bool PDC_can_change_color(void)
+{
+ return FALSE;
+}
+
+int PDC_color_content(short color, short *red, short *green, short *blue)
+{
+ return ERR;
+}
+
+int PDC_init_color(short color, short red, short green, short blue)
+{
+ return ERR;
+}
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcsetsc.c b/payloads/libpayload/curses/pdcurses-backend/pdcsetsc.c
new file mode 100644
index 0000000000..49d66abcb9
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdcsetsc.c
@@ -0,0 +1,32 @@
+/* Public Domain Curses */
+/* This file is BSD licensed, Copyright 2011 secunet AG */
+
+#include "lppdc.h"
+
+int PDC_curs_set(int visibility)
+{
+ int ret_vis;
+
+ PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility));
+
+ ret_vis = SP->visibility;
+ SP->visibility = visibility;
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ if (curses_flags & F_ENABLE_SERIAL) {
+ serial_cursor_enable(visibility);
+ }
+#endif
+#ifdef CONFIG_VIDEO_CONSOLE
+ if (curses_flags & F_ENABLE_CONSOLE) {
+ video_console_cursor_enable(visibility);
+ }
+#endif
+
+ return ret_vis;
+}
+
+int PDC_set_blink(bool blinkon)
+{
+ return ERR;
+}
diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcutil.c b/payloads/libpayload/curses/pdcurses-backend/pdcutil.c
new file mode 100644
index 0000000000..8fb3e161d7
--- /dev/null
+++ b/payloads/libpayload/curses/pdcurses-backend/pdcutil.c
@@ -0,0 +1,49 @@
+/* Public Domain Curses */
+/* This file is BSD licensed, Copyright 2011 secunet AG */
+
+#include "lppdc.h"
+#include <libpayload.h>
+
+int curses_flags = F_ENABLE_SERIAL | F_ENABLE_CONSOLE;
+
+void PDC_beep(void)
+{
+ PDC_LOG(("PDC_beep() - called\n"));
+
+#ifdef CONFIG_SPEAKER
+ speaker_tone(1760, 500); /* 1760 == note A6 */
+#endif
+}
+
+void PDC_napms(int ms)
+{
+ PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
+
+ mdelay(ms);
+}
+
+const char *PDC_sysname(void)
+{
+ return "LIBPAYLOAD";
+}
+
+void curses_enable_serial(int enable)
+{
+ curses_flags = (curses_flags & ~F_ENABLE_SERIAL) | (enable * F_ENABLE_SERIAL);
+}
+
+void curses_enable_vga(int enable)
+{
+ curses_flags = (curses_flags & ~F_ENABLE_CONSOLE) | (enable * F_ENABLE_CONSOLE);
+}
+
+int curses_serial_enabled()
+{
+ return !!(curses_flags & F_ENABLE_SERIAL);
+}
+
+int curses_vga_enabled()
+{
+ return !!(curses_flags & F_ENABLE_CONSOLE);
+}
+