Print this page
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>

@@ -35,42 +35,75 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #include <sys/types.h>
+#include <sys/font.h>
+#if !defined(_BOOT)
 #include <sys/sunddi.h>
 #include <sys/sunldi.h>
 #include <sys/visual_io.h>
-#include <sys/font.h>
 #include <sys/list.h>
 #include <sys/tem.h>
 #include <sys/note.h>
+#endif
 
 /*
- * definitions for ANSI x3.64 terminal control language parser
+ * Definitions for ANSI x3.64 terminal control language parser.
+ * With UTF-8 support we use 32-bit value for Unicode codepoints.
+ *
+ * However, as we only need 21 bits for unicode char, we will use the
+ * rest of the bits for attributes, so we can save memory and
+ * have combined attribute+char in screen buffer. This will also allow us
+ * to keep better track about attributes and apply other optimizations.
+ *
+ * This setup will give us 11 bits for attributes (mask 0x7FF).
+ *  Bits  Meaning
+ *  0-20  char
+ * 21-31  attributes
+ *
+ * The current implementation is building the screen buffer in three parts,
+ * tvs_screen_buf is implementing the character array and the foreground
+ * and the background colors have tvs_fg_color and tvs_bg_color arrays.
+ * The character and color arrays are currently only used to restore the
+ * screen from tem switch (vt switch, or switch from Xorg session.
+ * To implement the console history, this buffering needs to be reviewed.
  */
 
+typedef uint32_t tem_char_t;    /* 32bit char to support UTF-8 */
+#define TEM_ATTR_MASK           0x7FF
+#define TEM_CHAR(c)             ((c) & 0x1fffff)
+#define TEM_CHAR_ATTR(c)        (((c) >> 21) & TEM_ATTR_MASK)
+#define TEM_ATTR(c)             (((c) & TEM_ATTR_MASK) << 21)
+
 #define TEM_MAXPARAMS   5       /* maximum number of ANSI paramters */
 #define TEM_MAXTAB      40      /* maximum number of tab stops */
 #define TEM_MAXFKEY     30      /* max length of function key with <ESC>Q */
-#define MAX_TEM         2       /* max number of loadable terminal emulators */
 
 #define TEM_SCROLL_UP           0
 #define TEM_SCROLL_DOWN         1
 #define TEM_SHIFT_LEFT          0
 #define TEM_SHIFT_RIGHT         1
 
+/* Attributes 0-0x7ff */
 #define TEM_ATTR_NORMAL         0x0000
 #define TEM_ATTR_REVERSE        0x0001
 #define TEM_ATTR_BOLD           0x0002
 #define TEM_ATTR_BLINK          0x0004
-#define TEM_ATTR_TRANSPARENT    0x0008
+#define TEM_ATTR_UNDERLINE      0x0008
 #define TEM_ATTR_SCREEN_REVERSE 0x0010
 #define TEM_ATTR_BRIGHT_FG      0x0020
 #define TEM_ATTR_BRIGHT_BG      0x0040
+#define TEM_ATTR_TRANSPARENT    0x0080
 
 #define ANSI_COLOR_BLACK        0
+#define ANSI_COLOR_RED          1
+#define ANSI_COLOR_GREEN        2
+#define ANSI_COLOR_BROWN        3
+#define ANSI_COLOR_BLUE         4
+#define ANSI_COLOR_MAGENTA      5
+#define ANSI_COLOR_CYAN         6
 #define ANSI_COLOR_WHITE        7
 
 #define TEM_TEXT_WHITE          0
 #define TEM_TEXT_BLACK          1
 #define TEM_TEXT_BLACK24_RED    0x00

@@ -83,39 +116,50 @@
 #define A_STATE_START                   0
 #define A_STATE_ESC                     1
 #define A_STATE_CSI                     2
 #define A_STATE_CSI_QMARK               3
 #define A_STATE_CSI_EQUAL               4
+#define A_STATE_OSC                     5
 
 /*
  * Default number of rows and columns
  */
+#ifdef _HAVE_TEM_FIRMWARE
 #define TEM_DEFAULT_ROWS        34
 #define TEM_DEFAULT_COLS        80
+#else
+#define TEM_DEFAULT_ROWS        25
+#define TEM_DEFAULT_COLS        80
+#endif
 
 /*
  * Default foreground/background color
  */
 
-#ifdef _HAVE_TEM_FIRMWARE
 #define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_BLACK
 #define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_WHITE
-#else /* _HAVE_TEM_FIRMWARE */
-#define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_WHITE
-#define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_BLACK
-#endif
 
+typedef uint8_t text_color_t;
+typedef uint16_t text_attr_t;
 
-#define BUF_LEN         160 /* Two lines of data can be processed at a time */
+typedef struct {
+        uint8_t red[16];
+        uint8_t green[16];
+        uint8_t blue[16];
+} text_cmap_t;
 
-typedef uint32_t tem_char_t;    /* 32bit char to support UTF-8 */
-typedef uint8_t text_color_t;
+/* Color translation tables. */
+extern const uint8_t dim_xlate[8];
+extern const uint8_t brt_xlate[8];
+extern const uint8_t solaris_color_to_pc_color[16];
+extern const text_cmap_t cmap4_to_24;
 
+#if !defined(_BOOT)
 typedef struct tem_color {
         text_color_t    fg_color;
         text_color_t    bg_color;
-        unsigned short  a_flags;
+        text_attr_t     a_flags;
 } tem_color_t;
 
 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
 
 struct tem_pix_pos {

@@ -131,25 +175,24 @@
 struct tem_size {
         screen_size_t   width;
         screen_size_t   height;
 };
 
-typedef struct {
-        uint8_t red[16];
-        uint8_t green[16];
-        uint8_t blue[16];
-} text_cmap_t;
+/* Combined color and 32bit tem char */
+typedef struct term_char {
+        text_color_t    tc_fg_color;
+        text_color_t    tc_bg_color;
+        tem_char_t      tc_char;
+} term_char_t;
 
-extern text_cmap_t cmap4_to_24;
-
 /*
  * State structure for each virtual terminal emulator
  */
 struct tem_vt_state {
         kmutex_t        tvs_lock;
         uchar_t         tvs_fbmode;     /* framebuffer mode */
-        unsigned short  tvs_flags;      /* flags for this x3.64 terminal */
+        text_attr_t     tvs_flags;      /* flags for this x3.64 terminal */
         int             tvs_state;      /* state in output esc seq processing */
         boolean_t       tvs_gotparam;   /* does output esc seq have a param */
 
         int     tvs_curparam;   /* current param # of output esc seq */
         int     tvs_paramval;   /* value of current param */

@@ -160,46 +203,43 @@
 
         struct tem_char_pos tvs_s_cursor;       /* start cursor position */
         struct tem_char_pos tvs_c_cursor;       /* current cursor position */
         struct tem_char_pos tvs_r_cursor;       /* remembered cursor position */
 
-        unsigned char   *tvs_outbuf;    /* place to keep incomplete lines */
-        int             tvs_outbuf_size;
-        int             tvs_outindex;   /* index into a_outbuf */
+        term_char_t     *tvs_outbuf;    /* place to keep incomplete lines */
+        size_t          tvs_outbuf_size;
+        size_t          tvs_outindex;   /* index into a_outbuf */
         void            *tvs_pix_data;  /* pointer to tmp bitmap area */
-        int             tvs_pix_data_size;
+        size_t          tvs_pix_data_size;
         text_color_t    tvs_fg_color;
         text_color_t    tvs_bg_color;
         int             tvs_first_line; /* kernel console output begins */
 
-        unsigned char   *tvs_screen_buf;        /* whole screen buffer */
-        int             tvs_screen_buf_size;
-        text_color_t    *tvs_fg_buf;    /* fg_color attribute cache */
-        text_color_t    *tvs_bg_buf;    /* bg_color attribute cache */
-        int             tvs_color_buf_size;
+        term_char_t     *tvs_screen_buf;        /* whole screen buffer */
+        term_char_t     **tvs_screen_rows;      /* screen buffer rows */
+        size_t          tvs_screen_buf_size;
+        size_t          tvs_screen_history_size;
 
         unsigned        tvs_utf8_left;          /* UTF-8 code points */
         tem_char_t      tvs_utf8_partial;       /* UTF-8 char being completed */
 
         boolean_t       tvs_isactive;
-        int             tvs_initialized;        /* initialization flag */
+        boolean_t       tvs_initialized;        /* initialization flag */
 
         list_node_t     tvs_list_node;
 };
 _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state))
 
 typedef struct tem_safe_callbacks {
-        void (*tsc_display)(struct tem_vt_state *, unsigned char *, int,
-            screen_pos_t, screen_pos_t, unsigned char, unsigned char,
-            cred_t *, enum called_from);
+        void (*tsc_display)(struct tem_vt_state *, term_char_t *, int,
+            screen_pos_t, screen_pos_t, cred_t *, enum called_from);
         void (*tsc_copy)(struct tem_vt_state *,
             screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
         void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *,
             enum called_from);
-        void (*tsc_bit2pix)(struct tem_vt_state *, unsigned char,
-            unsigned char, unsigned char);
+        void (*tsc_bit2pix)(struct tem_vt_state *, term_char_t);
         void (*tsc_cls)(struct tem_vt_state *, int,
             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 } tem_safe_callbacks_t;
 
 /*

@@ -218,18 +258,20 @@
 
         int     ts_pix_data_size;       /* size of bitmap data areas */
         int     ts_pdepth;              /* pixel depth */
         struct font     ts_font;        /* font table */
 
-        unsigned char   *ts_blank_line; /* a blank line for scrolling */
+        term_char_t     *ts_blank_line; /* a blank line for scrolling */
         tem_safe_callbacks_t    *ts_callbacks;  /* internal output functions */
 
         int     ts_initialized;         /* initialization flag */
 
         tem_modechg_cb_t        ts_modechg_cb;
         tem_modechg_cb_arg_t    ts_modechg_arg;
 
+        color_map_fn_t  ts_color_map;
+
         tem_color_t     ts_init_color; /* initial color and attributes */
 
         struct tem_vt_state     *ts_active;
         kmutex_t        ts_lock;
         list_t          ts_list;        /* chain of all tems */

@@ -243,10 +285,11 @@
 /*
  * tems_* fuctions mean that they just operate on the common soft state
  * (tem_state_t), and tem_* functions mean that they operate on the
  * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c.
  */
+int     tems_cls_layered(struct vis_consclear *, cred_t *);
 void    tems_display_layered(struct vis_consdisplay *, cred_t *);
 void    tems_copy_layered(struct vis_conscopy *, cred_t *);
 void    tems_cursor_layered(struct vis_conscursor *, cred_t *);
 void    tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from);
 

@@ -255,14 +298,12 @@
             enum called_from);
 void    tem_safe_reset_display(struct tem_vt_state *, cred_t *,
             enum called_from, boolean_t, boolean_t);
 void    tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int,
             cred_t *, enum called_from);
-void    tem_safe_text_display(struct tem_vt_state *, uchar_t *,
-            int, screen_pos_t, screen_pos_t,
-            text_color_t, text_color_t,
-            cred_t *, enum called_from);
+void    tem_safe_text_display(struct tem_vt_state *, term_char_t *,
+            int, screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 void    tem_safe_text_copy(struct tem_vt_state *,
             screen_pos_t, screen_pos_t,
             screen_pos_t, screen_pos_t,
             screen_pos_t, screen_pos_t,
             cred_t *, enum called_from);

@@ -269,23 +310,20 @@
 void    tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *,
             enum called_from);
 void    tem_safe_text_cls(struct tem_vt_state *,
             int count, screen_pos_t row, screen_pos_t col,
             cred_t *credp, enum called_from called_from);
-void    tem_safe_pix_display(struct tem_vt_state *, uchar_t *,
-            int, screen_pos_t, screen_pos_t,
-            text_color_t, text_color_t,
-            cred_t *, enum called_from);
+void    tem_safe_pix_display(struct tem_vt_state *, term_char_t *,
+            int, screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 void    tem_safe_pix_copy(struct tem_vt_state *,
             screen_pos_t, screen_pos_t,
             screen_pos_t, screen_pos_t,
             screen_pos_t, screen_pos_t,
             cred_t *, enum called_from);
 void    tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *,
             enum called_from);
-void    tem_safe_pix_bit2pix(struct tem_vt_state *, unsigned char,
-            unsigned char, unsigned char);
+void    tem_safe_pix_bit2pix(struct tem_vt_state *, term_char_t);
 void    tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t,
             cred_t *, enum called_from);
 void    tem_safe_pix_cls_range(struct tem_vt_state *,
             screen_pos_t, int, int,
             screen_pos_t, int, int,

@@ -292,17 +330,18 @@
             boolean_t, cred_t *, enum called_from);
 
 void    tem_safe_pix_clear_entire_screen(struct tem_vt_state *,
             cred_t *, enum called_from);
 
-void    tem_safe_get_color(struct tem_vt_state *, text_color_t *,
-            text_color_t *, uint8_t);
+void    tem_safe_get_attr(struct tem_vt_state *, text_color_t *,
+            text_color_t *, text_attr_t *, uint8_t);
 
 void    tem_safe_blank_screen(struct tem_vt_state *, cred_t *,
             enum called_from);
 void    tem_safe_unblank_screen(struct tem_vt_state *, cred_t *,
             enum called_from);
+#endif  /* _BOOT */
 
 #ifdef __cplusplus
 }
 #endif