Rev 4676 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4676 | Rev 4685 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Martin Decky |
2 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2006 Ondrej Palkovsky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup genarch |
30 | /** @addtogroup genarch |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <genarch/fb/font-8x16.h> |
36 | #include <genarch/fb/font-8x16.h> |
37 | #include <genarch/fb/logo-196x66.h> |
37 | #include <genarch/fb/logo-196x66.h> |
38 | #include <genarch/fb/visuals.h> |
38 | #include <genarch/fb/visuals.h> |
39 | #include <genarch/fb/fb.h> |
39 | #include <genarch/fb/fb.h> |
40 | #include <console/chardev.h> |
40 | #include <console/chardev.h> |
41 | #include <console/console.h> |
41 | #include <console/console.h> |
42 | #include <sysinfo/sysinfo.h> |
42 | #include <sysinfo/sysinfo.h> |
43 | #include <mm/slab.h> |
43 | #include <mm/slab.h> |
44 | #include <align.h> |
44 | #include <align.h> |
45 | #include <panic.h> |
45 | #include <panic.h> |
46 | #include <memstr.h> |
46 | #include <memstr.h> |
47 | #include <config.h> |
47 | #include <config.h> |
48 | #include <bitops.h> |
48 | #include <bitops.h> |
49 | #include <print.h> |
49 | #include <print.h> |
50 | #include <string.h> |
50 | #include <string.h> |
51 | #include <ddi/ddi.h> |
51 | #include <ddi/ddi.h> |
52 | #include <arch/types.h> |
52 | #include <arch/types.h> |
53 | #include <byteorder.h> |
53 | #include <byteorder.h> |
54 | 54 | ||
55 | SPINLOCK_INITIALIZE(fb_lock); |
55 | SPINLOCK_INITIALIZE(fb_lock); |
56 | 56 | ||
57 | static uint8_t *fb_addr; |
57 | static uint8_t *fb_addr; |
58 | static uint16_t *backbuf; |
58 | static uint16_t *backbuf; |
59 | static uint8_t *glyphs; |
59 | static uint8_t *glyphs; |
60 | static uint8_t *bgscan; |
60 | static uint8_t *bgscan; |
61 | 61 | ||
62 | static unsigned int xres; |
62 | static unsigned int xres; |
63 | static unsigned int yres; |
63 | static unsigned int yres; |
64 | 64 | ||
65 | static unsigned int ylogo; |
65 | static unsigned int ylogo; |
66 | static unsigned int ytrim; |
66 | static unsigned int ytrim; |
67 | static unsigned int rowtrim; |
67 | static unsigned int rowtrim; |
68 | 68 | ||
69 | static unsigned int scanline; |
69 | static unsigned int scanline; |
70 | static unsigned int glyphscanline; |
70 | static unsigned int glyphscanline; |
71 | 71 | ||
72 | static unsigned int pixelbytes; |
72 | static unsigned int pixelbytes; |
73 | static unsigned int glyphbytes; |
73 | static unsigned int glyphbytes; |
74 | static unsigned int bgscanbytes; |
74 | static unsigned int bgscanbytes; |
75 | 75 | ||
76 | static unsigned int cols; |
76 | static unsigned int cols; |
77 | static unsigned int rows; |
77 | static unsigned int rows; |
78 | static unsigned int position = 0; |
78 | static unsigned int position = 0; |
79 | 79 | ||
80 | #define BG_COLOR 0x000080 |
80 | #define BG_COLOR 0x000080 |
81 | #define FG_COLOR 0xffff00 |
81 | #define FG_COLOR 0xffff00 |
82 | #define INV_COLOR 0xaaaaaa |
82 | #define INV_COLOR 0xaaaaaa |
83 | 83 | ||
84 | #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
84 | #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
85 | #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
85 | #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
86 | #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1)) |
86 | #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1)) |
87 | 87 | ||
88 | #define COL2X(col) ((col) * FONT_WIDTH) |
88 | #define COL2X(col) ((col) * FONT_WIDTH) |
89 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
89 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
90 | 90 | ||
91 | #define X2COL(x) ((x) / FONT_WIDTH) |
91 | #define X2COL(x) ((x) / FONT_WIDTH) |
92 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
92 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
93 | 93 | ||
94 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
94 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
95 | #define BB_POS(col, row) ((row) * cols + (col)) |
95 | #define BB_POS(col, row) ((row) * cols + (col)) |
96 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
96 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
97 | 97 | ||
98 | 98 | ||
99 | static void (*rgb_conv)(void *, uint32_t); |
99 | static void (*rgb_conv)(void *, uint32_t); |
100 | 100 | ||
101 | /* |
101 | /* |
102 | * RGB conversion functions. |
102 | * RGB conversion functions. |
103 | * |
103 | * |
104 | * These functions write an RGB value to some memory in some predefined format. |
104 | * These functions write an RGB value to some memory in some predefined format. |
105 | * The naming convention corresponds to the format created by these functions. |
105 | * The naming convention corresponds to the format created by these functions. |
106 | * The functions use the so called network order (i.e. big endian) with respect |
106 | * The functions use the so called network order (i.e. big endian) with respect |
107 | * to their names. |
107 | * to their names. |
108 | */ |
108 | */ |
109 | 109 | ||
110 | static void rgb_0888(void *dst, uint32_t rgb) |
110 | static void rgb_0888(void *dst, uint32_t rgb) |
111 | { |
111 | { |
112 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
112 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
113 | (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8))); |
113 | (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8))); |
114 | } |
114 | } |
115 | 115 | ||
116 | static void bgr_0888(void *dst, uint32_t rgb) |
116 | static void bgr_0888(void *dst, uint32_t rgb) |
117 | { |
117 | { |
118 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
118 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
119 | (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8))); |
119 | (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8))); |
120 | } |
120 | } |
121 | 121 | ||
122 | static void rgb_8880(void *dst, uint32_t rgb) |
122 | static void rgb_8880(void *dst, uint32_t rgb) |
123 | { |
123 | { |
124 | *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) | |
124 | *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) | |
125 | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0); |
125 | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0); |
126 | } |
126 | } |
127 | 127 | ||
128 | static void bgr_8880(void *dst, uint32_t rgb) |
128 | static void bgr_8880(void *dst, uint32_t rgb) |
129 | { |
129 | { |
130 | *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) | |
130 | *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) | |
131 | (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0); |
131 | (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0); |
132 | } |
132 | } |
133 | 133 | ||
134 | static void rgb_888(void *dst, uint32_t rgb) |
134 | static void rgb_888(void *dst, uint32_t rgb) |
135 | { |
135 | { |
136 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
136 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
137 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
137 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
138 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
138 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
139 | } |
139 | } |
140 | 140 | ||
141 | static void bgr_888(void *dst, uint32_t rgb) |
141 | static void bgr_888(void *dst, uint32_t rgb) |
142 | { |
142 | { |
143 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
143 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
144 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
144 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
145 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
145 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
146 | } |
146 | } |
147 | 147 | ||
148 | static void bgr_555(void *dst, uint32_t rgb) |
148 | static void rgb_555_be(void *dst, uint32_t rgb) |
149 | { |
149 | { |
150 | uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff; |
150 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 10 | |
151 | uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2); |
151 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); |
152 | *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo); |
- | |
153 | } |
152 | } |
154 | 153 | ||
155 | static void bgr_565(void *dst, uint32_t rgb) |
154 | static void rgb_555_le(void *dst, uint32_t rgb) |
156 | { |
155 | { |
- | 156 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 10 | |
|
- | 157 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); |
|
- | 158 | } |
|
- | 159 | ||
- | 160 | static void rgb_565_be(void *dst, uint32_t rgb) |
|
- | 161 | { |
|
157 | uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff; |
162 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 11 | |
158 | uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3); |
163 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); |
- | 164 | } |
|
- | 165 | ||
- | 166 | static void rgb_565_le(void *dst, uint32_t rgb) |
|
- | 167 | { |
|
159 | *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo); |
168 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 11 | |
- | 169 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); |
|
160 | } |
170 | } |
161 | 171 | ||
162 | 172 | ||
163 | /** BGR 3:2:3 |
173 | /** BGR 3:2:3 |
164 | * |
174 | * |
165 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
175 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
166 | * will most likely use a color palette. The color appearance |
176 | * will most likely use a color palette. The color appearance |
167 | * will be pretty random and depend on the default installed |
177 | * will be pretty random and depend on the default installed |
168 | * palette. This could be fixed by supporting custom palette |
178 | * palette. This could be fixed by supporting custom palette |
169 | * and setting it to simulate the 8-bit truecolor. |
179 | * and setting it to simulate the 8-bit truecolor. |
170 | * |
180 | * |
171 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
181 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
172 | * |
182 | * |
173 | * Note that the byte is being inverted by this function. The reason is |
183 | * Note that the byte is being inverted by this function. The reason is |
174 | * that we would like to use a color palette where the white color code |
184 | * that we would like to use a color palette where the white color code |
175 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500) |
185 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500) |
176 | * use these codes for black and white and prevent to set codes |
186 | * use these codes for black and white and prevent to set codes |
177 | * 0 and 255 to other colors. |
187 | * 0 and 255 to other colors. |
178 | * |
188 | * |
179 | */ |
189 | */ |
180 | static void bgr_323(void *dst, uint32_t rgb) |
190 | static void bgr_323(void *dst, uint32_t rgb) |
181 | { |
191 | { |
182 | *((uint8_t *) dst) |
192 | *((uint8_t *) dst) |
183 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
193 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
184 | } |
194 | } |
185 | 195 | ||
186 | 196 | ||
187 | /** Hide logo and refresh screen |
197 | /** Hide logo and refresh screen |
188 | * |
198 | * |
189 | */ |
199 | */ |
190 | static void logo_hide(bool silent) |
200 | static void logo_hide(bool silent) |
191 | { |
201 | { |
192 | ylogo = 0; |
202 | ylogo = 0; |
193 | ytrim = yres; |
203 | ytrim = yres; |
194 | rowtrim = rows; |
204 | rowtrim = rows; |
195 | if (!silent) |
205 | if (!silent) |
196 | fb_redraw(); |
206 | fb_redraw(); |
197 | } |
207 | } |
198 | 208 | ||
199 | 209 | ||
200 | /** Draw character at given position |
210 | /** Draw character at given position |
201 | * |
211 | * |
202 | */ |
212 | */ |
203 | static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay) |
213 | static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay) |
204 | { |
214 | { |
205 | unsigned int x = COL2X(col); |
215 | unsigned int x = COL2X(col); |
206 | unsigned int y = ROW2Y(row); |
216 | unsigned int y = ROW2Y(row); |
207 | unsigned int yd; |
217 | unsigned int yd; |
208 | 218 | ||
209 | if (y >= ytrim) |
219 | if (y >= ytrim) |
210 | logo_hide(silent); |
220 | logo_hide(silent); |
211 | 221 | ||
212 | if (!overlay) |
222 | if (!overlay) |
213 | backbuf[BB_POS(col, row)] = glyph; |
223 | backbuf[BB_POS(col, row)] = glyph; |
214 | 224 | ||
215 | if (!silent) { |
225 | if (!silent) { |
216 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
226 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
217 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
227 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
218 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
228 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
219 | } |
229 | } |
220 | } |
230 | } |
221 | 231 | ||
222 | 232 | ||
223 | /** Scroll screen down by one row |
233 | /** Scroll screen down by one row |
224 | * |
234 | * |
225 | * |
235 | * |
226 | */ |
236 | */ |
227 | static void screen_scroll(bool silent) |
237 | static void screen_scroll(bool silent) |
228 | { |
238 | { |
229 | if (ylogo > 0) { |
239 | if (ylogo > 0) { |
230 | logo_hide(silent); |
240 | logo_hide(silent); |
231 | return; |
241 | return; |
232 | } |
242 | } |
233 | 243 | ||
234 | if (!silent) { |
244 | if (!silent) { |
235 | unsigned int row; |
245 | unsigned int row; |
236 | 246 | ||
237 | for (row = 0; row < rows; row++) { |
247 | for (row = 0; row < rows; row++) { |
238 | unsigned int y = ROW2Y(row); |
248 | unsigned int y = ROW2Y(row); |
239 | unsigned int yd; |
249 | unsigned int yd; |
240 | 250 | ||
241 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
251 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
242 | unsigned int x; |
252 | unsigned int x; |
243 | unsigned int col; |
253 | unsigned int col; |
244 | 254 | ||
245 | for (col = 0, x = 0; col < cols; col++, |
255 | for (col = 0, x = 0; col < cols; col++, |
246 | x += FONT_WIDTH) { |
256 | x += FONT_WIDTH) { |
247 | uint16_t glyph; |
257 | uint16_t glyph; |
248 | 258 | ||
249 | if (row < rows - 1) { |
259 | if (row < rows - 1) { |
250 | if (backbuf[BB_POS(col, row)] == |
260 | if (backbuf[BB_POS(col, row)] == |
251 | backbuf[BB_POS(col, row + 1)]) |
261 | backbuf[BB_POS(col, row + 1)]) |
252 | continue; |
262 | continue; |
253 | 263 | ||
254 | glyph = backbuf[BB_POS(col, row + 1)]; |
264 | glyph = backbuf[BB_POS(col, row + 1)]; |
255 | } else |
265 | } else |
256 | glyph = 0; |
266 | glyph = 0; |
257 | 267 | ||
258 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
268 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
259 | &glyphs[GLYPH_POS(glyph, yd)], |
269 | &glyphs[GLYPH_POS(glyph, yd)], |
260 | glyphscanline); |
270 | glyphscanline); |
261 | } |
271 | } |
262 | } |
272 | } |
263 | } |
273 | } |
264 | } |
274 | } |
265 | 275 | ||
266 | memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t)); |
276 | memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t)); |
267 | memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
277 | memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
268 | } |
278 | } |
269 | 279 | ||
270 | 280 | ||
271 | static void cursor_put(bool silent) |
281 | static void cursor_put(bool silent) |
272 | { |
282 | { |
273 | unsigned int col = position % cols; |
283 | unsigned int col = position % cols; |
274 | unsigned int row = position / cols; |
284 | unsigned int row = position / cols; |
275 | 285 | ||
276 | glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true); |
286 | glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true); |
277 | } |
287 | } |
278 | 288 | ||
279 | 289 | ||
280 | static void cursor_remove(bool silent) |
290 | static void cursor_remove(bool silent) |
281 | { |
291 | { |
282 | unsigned int col = position % cols; |
292 | unsigned int col = position % cols; |
283 | unsigned int row = position / cols; |
293 | unsigned int row = position / cols; |
284 | 294 | ||
285 | glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true); |
295 | glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true); |
286 | } |
296 | } |
287 | 297 | ||
288 | 298 | ||
289 | /** Print character to screen |
299 | /** Print character to screen |
290 | * |
300 | * |
291 | * Emulate basic terminal commands. |
301 | * Emulate basic terminal commands. |
292 | * |
302 | * |
293 | */ |
303 | */ |
294 | static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent) |
304 | static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent) |
295 | { |
305 | { |
296 | spinlock_lock(&fb_lock); |
306 | spinlock_lock(&fb_lock); |
297 | 307 | ||
298 | switch (ch) { |
308 | switch (ch) { |
299 | case '\n': |
309 | case '\n': |
300 | cursor_remove(silent); |
310 | cursor_remove(silent); |
301 | position += cols; |
311 | position += cols; |
302 | position -= position % cols; |
312 | position -= position % cols; |
303 | break; |
313 | break; |
304 | case '\r': |
314 | case '\r': |
305 | cursor_remove(silent); |
315 | cursor_remove(silent); |
306 | position -= position % cols; |
316 | position -= position % cols; |
307 | break; |
317 | break; |
308 | case '\b': |
318 | case '\b': |
309 | cursor_remove(silent); |
319 | cursor_remove(silent); |
310 | if (position % cols) |
320 | if (position % cols) |
311 | position--; |
321 | position--; |
312 | break; |
322 | break; |
313 | case '\t': |
323 | case '\t': |
314 | cursor_remove(silent); |
324 | cursor_remove(silent); |
315 | do { |
325 | do { |
316 | glyph_draw(fb_font_glyph(' '), position % cols, |
326 | glyph_draw(fb_font_glyph(' '), position % cols, |
317 | position / cols, silent, false); |
327 | position / cols, silent, false); |
318 | position++; |
328 | position++; |
319 | } while ((position % 8) && (position < cols * rows)); |
329 | } while ((position % 8) && (position < cols * rows)); |
320 | break; |
330 | break; |
321 | default: |
331 | default: |
322 | glyph_draw(fb_font_glyph(ch), position % cols, |
332 | glyph_draw(fb_font_glyph(ch), position % cols, |
323 | position / cols, silent, false); |
333 | position / cols, silent, false); |
324 | position++; |
334 | position++; |
325 | } |
335 | } |
326 | 336 | ||
327 | if (position >= cols * rows) { |
337 | if (position >= cols * rows) { |
328 | position -= cols; |
338 | position -= cols; |
329 | screen_scroll(silent); |
339 | screen_scroll(silent); |
330 | } |
340 | } |
331 | 341 | ||
332 | cursor_put(silent); |
342 | cursor_put(silent); |
333 | 343 | ||
334 | spinlock_unlock(&fb_lock); |
344 | spinlock_unlock(&fb_lock); |
335 | } |
345 | } |
336 | 346 | ||
337 | static outdev_t fb_console; |
347 | static outdev_t fb_console; |
338 | static outdev_operations_t fb_ops = { |
348 | static outdev_operations_t fb_ops = { |
339 | .write = fb_putchar |
349 | .write = fb_putchar |
340 | }; |
350 | }; |
341 | 351 | ||
342 | 352 | ||
343 | /** Render glyphs |
353 | /** Render glyphs |
344 | * |
354 | * |
345 | * Convert glyphs from device independent font |
355 | * Convert glyphs from device independent font |
346 | * description to current visual representation. |
356 | * description to current visual representation. |
347 | * |
357 | * |
348 | */ |
358 | */ |
349 | static void glyphs_render(void) |
359 | static void glyphs_render(void) |
350 | { |
360 | { |
351 | /* Prerender glyphs */ |
361 | /* Prerender glyphs */ |
352 | uint16_t glyph; |
362 | uint16_t glyph; |
353 | 363 | ||
354 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
364 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
355 | uint32_t fg_color; |
365 | uint32_t fg_color; |
356 | 366 | ||
357 | if (glyph == FONT_GLYPHS - 1) |
367 | if (glyph == FONT_GLYPHS - 1) |
358 | fg_color = INV_COLOR; |
368 | fg_color = INV_COLOR; |
359 | else |
369 | else |
360 | fg_color = FG_COLOR; |
370 | fg_color = FG_COLOR; |
361 | 371 | ||
362 | unsigned int y; |
372 | unsigned int y; |
363 | 373 | ||
364 | for (y = 0; y < FONT_SCANLINES; y++) { |
374 | for (y = 0; y < FONT_SCANLINES; y++) { |
365 | unsigned int x; |
375 | unsigned int x; |
366 | 376 | ||
367 | for (x = 0; x < FONT_WIDTH; x++) { |
377 | for (x = 0; x < FONT_WIDTH; x++) { |
368 | void *dst = &glyphs[GLYPH_POS(glyph, y) + |
378 | void *dst = &glyphs[GLYPH_POS(glyph, y) + |
369 | x * pixelbytes]; |
379 | x * pixelbytes]; |
370 | uint32_t rgb = (fb_font[glyph][y] & |
380 | uint32_t rgb = (fb_font[glyph][y] & |
371 | (1 << (7 - x))) ? fg_color : BG_COLOR; |
381 | (1 << (7 - x))) ? fg_color : BG_COLOR; |
372 | rgb_conv(dst, rgb); |
382 | rgb_conv(dst, rgb); |
373 | } |
383 | } |
374 | } |
384 | } |
375 | } |
385 | } |
376 | 386 | ||
377 | /* Prerender background scanline */ |
387 | /* Prerender background scanline */ |
378 | unsigned int x; |
388 | unsigned int x; |
379 | 389 | ||
380 | for (x = 0; x < xres; x++) |
390 | for (x = 0; x < xres; x++) |
381 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
391 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
382 | } |
392 | } |
383 | 393 | ||
384 | 394 | ||
385 | /** Refresh the screen |
395 | /** Refresh the screen |
386 | * |
396 | * |
387 | */ |
397 | */ |
388 | void fb_redraw(void) |
398 | void fb_redraw(void) |
389 | { |
399 | { |
390 | if (ylogo > 0) { |
400 | if (ylogo > 0) { |
391 | unsigned int y; |
401 | unsigned int y; |
392 | 402 | ||
393 | for (y = 0; y < LOGO_HEIGHT; y++) { |
403 | for (y = 0; y < LOGO_HEIGHT; y++) { |
394 | unsigned int x; |
404 | unsigned int x; |
395 | 405 | ||
396 | for (x = 0; x < xres; x++) |
406 | for (x = 0; x < xres; x++) |
397 | rgb_conv(&fb_addr[FB_POS(x, y)], |
407 | rgb_conv(&fb_addr[FB_POS(x, y)], |
398 | (x < LOGO_WIDTH) ? |
408 | (x < LOGO_WIDTH) ? |
399 | fb_logo[y * LOGO_WIDTH + x] : |
409 | fb_logo[y * LOGO_WIDTH + x] : |
400 | LOGO_COLOR); |
410 | LOGO_COLOR); |
401 | } |
411 | } |
402 | } |
412 | } |
403 | 413 | ||
404 | unsigned int row; |
414 | unsigned int row; |
405 | 415 | ||
406 | for (row = 0; row < rowtrim; row++) { |
416 | for (row = 0; row < rowtrim; row++) { |
407 | unsigned int y = ylogo + ROW2Y(row); |
417 | unsigned int y = ylogo + ROW2Y(row); |
408 | unsigned int yd; |
418 | unsigned int yd; |
409 | 419 | ||
410 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
420 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
411 | unsigned int x; |
421 | unsigned int x; |
412 | unsigned int col; |
422 | unsigned int col; |
413 | 423 | ||
414 | for (col = 0, x = 0; col < cols; |
424 | for (col = 0, x = 0; col < cols; |
415 | col++, x += FONT_WIDTH) { |
425 | col++, x += FONT_WIDTH) { |
416 | uint16_t glyph = backbuf[BB_POS(col, row)]; |
426 | uint16_t glyph = backbuf[BB_POS(col, row)]; |
417 | void *dst = &fb_addr[FB_POS(x, y + yd)]; |
427 | void *dst = &fb_addr[FB_POS(x, y + yd)]; |
418 | void *src = &glyphs[GLYPH_POS(glyph, yd)]; |
428 | void *src = &glyphs[GLYPH_POS(glyph, yd)]; |
419 | memcpy(dst, src, glyphscanline); |
429 | memcpy(dst, src, glyphscanline); |
420 | } |
430 | } |
421 | } |
431 | } |
422 | } |
432 | } |
423 | 433 | ||
424 | if (COL2X(cols) < xres) { |
434 | if (COL2X(cols) < xres) { |
425 | unsigned int y; |
435 | unsigned int y; |
426 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
436 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
427 | 437 | ||
428 | for (y = ylogo; y < yres; y++) |
438 | for (y = ylogo; y < yres; y++) |
429 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
439 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
430 | } |
440 | } |
431 | 441 | ||
432 | if (ROW2Y(rowtrim) + ylogo < yres) { |
442 | if (ROW2Y(rowtrim) + ylogo < yres) { |
433 | unsigned int y; |
443 | unsigned int y; |
434 | 444 | ||
435 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
445 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
436 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
446 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
437 | } |
447 | } |
438 | } |
448 | } |
439 | 449 | ||
440 | 450 | ||
441 | /** Initialize framebuffer as a output character device |
451 | /** Initialize framebuffer as a output character device |
442 | * |
452 | * |
443 | * @param addr Physical address of the framebuffer |
453 | * @param addr Physical address of the framebuffer |
444 | * @param x Screen width in pixels |
454 | * @param x Screen width in pixels |
445 | * @param y Screen height in pixels |
455 | * @param y Screen height in pixels |
446 | * @param scan Bytes per one scanline |
456 | * @param scan Bytes per one scanline |
447 | * @param visual Color model |
457 | * @param visual Color model |
448 | * |
458 | * |
449 | */ |
459 | */ |
450 | void fb_init(fb_properties_t *props) |
460 | void fb_init(fb_properties_t *props) |
451 | { |
461 | { |
452 | switch (props->visual) { |
462 | switch (props->visual) { |
453 | case VISUAL_INDIRECT_8: |
463 | case VISUAL_INDIRECT_8: |
454 | rgb_conv = bgr_323; |
464 | rgb_conv = bgr_323; |
455 | pixelbytes = 1; |
465 | pixelbytes = 1; |
456 | break; |
466 | break; |
457 | case VISUAL_BGR_5_5_5: |
467 | case VISUAL_RGB_5_5_5_LE: |
- | 468 | rgb_conv = rgb_555_le; |
|
- | 469 | pixelbytes = 2; |
|
- | 470 | break; |
|
- | 471 | case VISUAL_RGB_5_5_5_BE: |
|
458 | rgb_conv = bgr_555; |
472 | rgb_conv = rgb_555_be; |
- | 473 | pixelbytes = 2; |
|
- | 474 | break; |
|
- | 475 | case VISUAL_RGB_5_6_5_LE: |
|
- | 476 | rgb_conv = rgb_565_le; |
|
459 | pixelbytes = 2; |
477 | pixelbytes = 2; |
460 | break; |
478 | break; |
461 | case VISUAL_BGR_5_6_5: |
479 | case VISUAL_RGB_5_6_5_BE: |
462 | rgb_conv = bgr_565; |
480 | rgb_conv = rgb_565_be; |
463 | pixelbytes = 2; |
481 | pixelbytes = 2; |
464 | break; |
482 | break; |
465 | case VISUAL_RGB_8_8_8: |
483 | case VISUAL_RGB_8_8_8: |
466 | rgb_conv = rgb_888; |
484 | rgb_conv = rgb_888; |
467 | pixelbytes = 3; |
485 | pixelbytes = 3; |
468 | break; |
486 | break; |
469 | case VISUAL_BGR_8_8_8: |
487 | case VISUAL_BGR_8_8_8: |
470 | rgb_conv = bgr_888; |
488 | rgb_conv = bgr_888; |
471 | pixelbytes = 3; |
489 | pixelbytes = 3; |
472 | break; |
490 | break; |
473 | case VISUAL_RGB_8_8_8_0: |
491 | case VISUAL_RGB_8_8_8_0: |
474 | rgb_conv = rgb_8880; |
492 | rgb_conv = rgb_8880; |
475 | pixelbytes = 4; |
493 | pixelbytes = 4; |
476 | break; |
494 | break; |
477 | case VISUAL_RGB_0_8_8_8: |
495 | case VISUAL_RGB_0_8_8_8: |
478 | rgb_conv = rgb_0888; |
496 | rgb_conv = rgb_0888; |
479 | pixelbytes = 4; |
497 | pixelbytes = 4; |
480 | break; |
498 | break; |
481 | case VISUAL_BGR_0_8_8_8: |
499 | case VISUAL_BGR_0_8_8_8: |
482 | rgb_conv = bgr_0888; |
500 | rgb_conv = bgr_0888; |
483 | pixelbytes = 4; |
501 | pixelbytes = 4; |
484 | break; |
502 | break; |
485 | case VISUAL_BGR_8_8_8_0: |
503 | case VISUAL_BGR_8_8_8_0: |
486 | rgb_conv = bgr_8880; |
504 | rgb_conv = bgr_8880; |
487 | pixelbytes = 4; |
505 | pixelbytes = 4; |
488 | break; |
506 | break; |
489 | default: |
507 | default: |
490 | panic("Unsupported visual."); |
508 | panic("Unsupported visual."); |
491 | } |
509 | } |
492 | 510 | ||
493 | xres = props->x; |
511 | xres = props->x; |
494 | yres = props->y; |
512 | yres = props->y; |
495 | scanline = props->scan; |
513 | scanline = props->scan; |
496 | 514 | ||
497 | cols = X2COL(xres); |
515 | cols = X2COL(xres); |
498 | rows = Y2ROW(yres); |
516 | rows = Y2ROW(yres); |
499 | 517 | ||
500 | if (yres > ylogo) { |
518 | if (yres > ylogo) { |
501 | ylogo = LOGO_HEIGHT; |
519 | ylogo = LOGO_HEIGHT; |
502 | rowtrim = rows - Y2ROW(ylogo); |
520 | rowtrim = rows - Y2ROW(ylogo); |
503 | if (ylogo % FONT_SCANLINES > 0) |
521 | if (ylogo % FONT_SCANLINES > 0) |
504 | rowtrim--; |
522 | rowtrim--; |
505 | ytrim = ROW2Y(rowtrim); |
523 | ytrim = ROW2Y(rowtrim); |
506 | } else { |
524 | } else { |
507 | ylogo = 0; |
525 | ylogo = 0; |
508 | ytrim = yres; |
526 | ytrim = yres; |
509 | rowtrim = rows; |
527 | rowtrim = rows; |
510 | } |
528 | } |
511 | 529 | ||
512 | glyphscanline = FONT_WIDTH * pixelbytes; |
530 | glyphscanline = FONT_WIDTH * pixelbytes; |
513 | glyphbytes = ROW2Y(glyphscanline); |
531 | glyphbytes = ROW2Y(glyphscanline); |
514 | bgscanbytes = xres * pixelbytes; |
532 | bgscanbytes = xres * pixelbytes; |
515 | 533 | ||
516 | size_t fbsize = scanline * yres; |
534 | size_t fbsize = scanline * yres; |
517 | size_t bbsize = cols * rows * sizeof(uint16_t); |
535 | size_t bbsize = cols * rows * sizeof(uint16_t); |
518 | size_t glyphsize = FONT_GLYPHS * glyphbytes; |
536 | size_t glyphsize = FONT_GLYPHS * glyphbytes; |
519 | 537 | ||
520 | backbuf = (uint16_t *) malloc(bbsize, 0); |
538 | backbuf = (uint16_t *) malloc(bbsize, 0); |
521 | if (!backbuf) |
539 | if (!backbuf) |
522 | panic("Unable to allocate backbuffer."); |
540 | panic("Unable to allocate backbuffer."); |
523 | 541 | ||
524 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
542 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
525 | if (!glyphs) |
543 | if (!glyphs) |
526 | panic("Unable to allocate glyphs."); |
544 | panic("Unable to allocate glyphs."); |
527 | 545 | ||
528 | bgscan = malloc(bgscanbytes, 0); |
546 | bgscan = malloc(bgscanbytes, 0); |
529 | if (!bgscan) |
547 | if (!bgscan) |
530 | panic("Unable to allocate background pixel."); |
548 | panic("Unable to allocate background pixel."); |
531 | 549 | ||
532 | memsetw(backbuf, cols * rows, 0); |
550 | memsetw(backbuf, cols * rows, 0); |
533 | 551 | ||
534 | glyphs_render(); |
552 | glyphs_render(); |
535 | 553 | ||
536 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
554 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
537 | 555 | ||
538 | sysinfo_set_item_val("fb", NULL, true); |
556 | sysinfo_set_item_val("fb", NULL, true); |
539 | sysinfo_set_item_val("fb.kind", NULL, 1); |
557 | sysinfo_set_item_val("fb.kind", NULL, 1); |
540 | sysinfo_set_item_val("fb.width", NULL, xres); |
558 | sysinfo_set_item_val("fb.width", NULL, xres); |
541 | sysinfo_set_item_val("fb.height", NULL, yres); |
559 | sysinfo_set_item_val("fb.height", NULL, yres); |
542 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
560 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
543 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
561 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
544 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
562 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
545 | 563 | ||
546 | fb_redraw(); |
564 | fb_redraw(); |
547 | 565 | ||
548 | outdev_initialize("fb", &fb_console, &fb_ops); |
566 | outdev_initialize("fb", &fb_console, &fb_ops); |
549 | stdout = &fb_console; |
567 | stdout = &fb_console; |
550 | } |
568 | } |
551 | 569 | ||
552 | /** @} |
570 | /** @} |
553 | */ |
571 | */ |
554 | 572 |