vt(4): Use default VGA palette

Before this change, the VGA palette was configured to match the shell
palette (e.g. color #1 was red). There was one glitch early in boot when
the vt(4)'s VGA palette was loaded: the loader's logo would switch from
red to blue. Likewise for the "Booting..." message switching from blue
to red. That's because the loader's logo was drawed with the default VGA
palette where a few colors are swapped compared to the shell palette
(e.g. blue <-> red).

This change configures the default VGA palette during initialization and
converts input's colors from shell to VGA palette index.

There should be no visible changes, except the loader's logo which will
keep its original color.

Reviewed by:	eadler
This commit is contained in:
Jean-Sébastien Pédron 2018-05-10 17:00:33 +00:00
parent e525438697
commit 5e251aec86
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333464
3 changed files with 28 additions and 24 deletions

View File

@ -38,8 +38,6 @@ __FBSDID("$FreeBSD$");
#include <dev/vt/colors/vt_termcolors.h>
#define NCOLORS 16
static struct {
unsigned char r; /* Red percentage value. */
unsigned char g; /* Green percentage value. */
@ -64,16 +62,6 @@ static struct {
{100, 100, 100}, /* white */
};
/*
* Between console's palette and VGA's one:
* - blue and red are swapped (1 <-> 4)
* - yellow ad cyan are swapped (3 <-> 6)
*/
static const int cons_to_vga_colors[NCOLORS] = {
0, 4, 2, 6, 1, 5, 3, 7,
0, 4, 2, 6, 1, 5, 3, 7
};
static int
vt_parse_rgb_triplet(const char *rgb, unsigned char *r,
unsigned char *g, unsigned char *b)

View File

@ -46,7 +46,18 @@ enum vt_color_format {
COLOR_FORMAT_MAX = 15,
};
#define NCOLORS 16
/*
* Between console's palette and VGA's one:
* - blue and red are swapped (1 <-> 4)
* - yellow and cyan are swapped (3 <-> 6)
*/
static const int cons_to_vga_colors[NCOLORS] = {
0, 4, 2, 6, 1, 5, 3, 7,
8, 12, 10, 14, 9, 13, 11, 15
};
/* Helper to fill color map used by driver */
int vt_generate_cons_palette(uint32_t *palette, int format, uint32_t rmax,
int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset);

View File

@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/rman.h>
#include <dev/vt/vt.h>
#include <dev/vt/colors/vt_termcolors.h>
#include <dev/vt/hw/vga/vt_vga_reg.h>
#include <dev/pci/pcivar.h>
@ -152,7 +153,7 @@ vga_setfg(struct vt_device *vd, term_color_t color)
return;
REG_WRITE1(sc, VGA_GC_ADDRESS, VGA_GC_SET_RESET);
REG_WRITE1(sc, VGA_GC_DATA, color);
REG_WRITE1(sc, VGA_GC_DATA, cons_to_vga_colors[color]);
sc->vga_curfg = color;
}
@ -167,7 +168,7 @@ vga_setbg(struct vt_device *vd, term_color_t color)
return;
REG_WRITE1(sc, VGA_GC_ADDRESS, VGA_GC_SET_RESET);
REG_WRITE1(sc, VGA_GC_DATA, color);
REG_WRITE1(sc, VGA_GC_DATA, cons_to_vga_colors[color]);
/*
* Write 8 pixels using the background color to an off-screen
@ -888,7 +889,9 @@ vga_bitblt_text_txtmode(struct vt_device *vd, const struct vt_window *vw,
ch = vga_get_cp437(TCHAR_CHARACTER(c));
/* Convert colors to VGA attributes. */
attr = bg << 4 | fg;
attr =
cons_to_vga_colors[bg] << 4 |
cons_to_vga_colors[fg];
MEM_WRITE1(sc, (row * 80 + col) * 2 + 0,
ch);
@ -1114,43 +1117,45 @@ vga_initialize(struct vt_device *vd, int textmode)
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(0));
REG_WRITE1(sc, VGA_AC_WRITE, 0);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(1));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(2));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(3));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SG | VGA_AC_PAL_R);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(4));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(5));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(6));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SG | VGA_AC_PAL_R);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(7));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R | VGA_AC_PAL_G | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(8));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(9));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_R);
VGA_AC_PAL_SB | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(10));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_G);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(11));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G);
VGA_AC_PAL_SB | VGA_AC_PAL_G | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(12));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_B);
VGA_AC_PAL_SB | VGA_AC_PAL_R);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(13));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(14));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_G | VGA_AC_PAL_B);
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(15));
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G | VGA_AC_PAL_B);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_OVERSCAN_COLOR);
REG_WRITE1(sc, VGA_AC_WRITE, 0);
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_COLOR_PLANE_ENABLE);