Skip to content

Commit 242ffb3

Browse files
committed
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
1 parent c7886ad commit 242ffb3

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

sys/dev/vt/colors/vt_termcolors.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ __FBSDID("$FreeBSD$");
3838

3939
#include <dev/vt/colors/vt_termcolors.h>
4040

41-
#define NCOLORS 16
42-
4341
static struct {
4442
unsigned char r; /* Red percentage value. */
4543
unsigned char g; /* Green percentage value. */
@@ -64,16 +62,6 @@ static struct {
6462
{100, 100, 100}, /* white */
6563
};
6664

67-
/*
68-
* Between console's palette and VGA's one:
69-
* - blue and red are swapped (1 <-> 4)
70-
* - yellow ad cyan are swapped (3 <-> 6)
71-
*/
72-
static const int cons_to_vga_colors[NCOLORS] = {
73-
0, 4, 2, 6, 1, 5, 3, 7,
74-
0, 4, 2, 6, 1, 5, 3, 7
75-
};
76-
7765
static int
7866
vt_parse_rgb_triplet(const char *rgb, unsigned char *r,
7967
unsigned char *g, unsigned char *b)

sys/dev/vt/colors/vt_termcolors.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ enum vt_color_format {
4646
COLOR_FORMAT_MAX = 15,
4747
};
4848

49+
#define NCOLORS 16
50+
51+
/*
52+
* Between console's palette and VGA's one:
53+
* - blue and red are swapped (1 <-> 4)
54+
* - yellow and cyan are swapped (3 <-> 6)
55+
*/
56+
static const int cons_to_vga_colors[NCOLORS] = {
57+
0, 4, 2, 6, 1, 5, 3, 7,
58+
8, 12, 10, 14, 9, 13, 11, 15
59+
};
60+
4961
/* Helper to fill color map used by driver */
5062
int vt_generate_cons_palette(uint32_t *palette, int format, uint32_t rmax,
5163
int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset);
52-

sys/dev/vt/hw/vga/vt_vga.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
4343
#include <sys/rman.h>
4444

4545
#include <dev/vt/vt.h>
46+
#include <dev/vt/colors/vt_termcolors.h>
4647
#include <dev/vt/hw/vga/vt_vga_reg.h>
4748
#include <dev/pci/pcivar.h>
4849

@@ -152,7 +153,7 @@ vga_setfg(struct vt_device *vd, term_color_t color)
152153
return;
153154

154155
REG_WRITE1(sc, VGA_GC_ADDRESS, VGA_GC_SET_RESET);
155-
REG_WRITE1(sc, VGA_GC_DATA, color);
156+
REG_WRITE1(sc, VGA_GC_DATA, cons_to_vga_colors[color]);
156157
sc->vga_curfg = color;
157158
}
158159

@@ -167,7 +168,7 @@ vga_setbg(struct vt_device *vd, term_color_t color)
167168
return;
168169

169170
REG_WRITE1(sc, VGA_GC_ADDRESS, VGA_GC_SET_RESET);
170-
REG_WRITE1(sc, VGA_GC_DATA, color);
171+
REG_WRITE1(sc, VGA_GC_DATA, cons_to_vga_colors[color]);
171172

172173
/*
173174
* 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,
888889
ch = vga_get_cp437(TCHAR_CHARACTER(c));
889890

890891
/* Convert colors to VGA attributes. */
891-
attr = bg << 4 | fg;
892+
attr =
893+
cons_to_vga_colors[bg] << 4 |
894+
cons_to_vga_colors[fg];
892895

893896
MEM_WRITE1(sc, (row * 80 + col) * 2 + 0,
894897
ch);
@@ -1114,43 +1117,45 @@ vga_initialize(struct vt_device *vd, int textmode)
11141117
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(0));
11151118
REG_WRITE1(sc, VGA_AC_WRITE, 0);
11161119
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(1));
1117-
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R);
1120+
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_B);
11181121
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(2));
11191122
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G);
11201123
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(3));
1121-
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SG | VGA_AC_PAL_R);
1124+
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G | VGA_AC_PAL_B);
11221125
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(4));
1123-
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_B);
1126+
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R);
11241127
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(5));
11251128
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R | VGA_AC_PAL_B);
11261129
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(6));
1127-
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_G | VGA_AC_PAL_B);
1130+
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SG | VGA_AC_PAL_R);
11281131
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(7));
11291132
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_R | VGA_AC_PAL_G | VGA_AC_PAL_B);
1133+
11301134
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(8));
11311135
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
11321136
VGA_AC_PAL_SB);
11331137
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(9));
11341138
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
1135-
VGA_AC_PAL_SB | VGA_AC_PAL_R);
1139+
VGA_AC_PAL_SB | VGA_AC_PAL_B);
11361140
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(10));
11371141
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
11381142
VGA_AC_PAL_SB | VGA_AC_PAL_G);
11391143
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(11));
11401144
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
1141-
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G);
1145+
VGA_AC_PAL_SB | VGA_AC_PAL_G | VGA_AC_PAL_B);
11421146
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(12));
11431147
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
1144-
VGA_AC_PAL_SB | VGA_AC_PAL_B);
1148+
VGA_AC_PAL_SB | VGA_AC_PAL_R);
11451149
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(13));
11461150
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
11471151
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_B);
11481152
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(14));
11491153
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
1150-
VGA_AC_PAL_SB | VGA_AC_PAL_G | VGA_AC_PAL_B);
1154+
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G);
11511155
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PALETTE(15));
11521156
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_PAL_SR | VGA_AC_PAL_SG |
11531157
VGA_AC_PAL_SB | VGA_AC_PAL_R | VGA_AC_PAL_G | VGA_AC_PAL_B);
1158+
11541159
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_OVERSCAN_COLOR);
11551160
REG_WRITE1(sc, VGA_AC_WRITE, 0);
11561161
REG_WRITE1(sc, VGA_AC_WRITE, VGA_AC_COLOR_PLANE_ENABLE);

0 commit comments

Comments
 (0)