Rev 4347 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4347 | Rev 4348 | ||
---|---|---|---|
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 <ddi/ddi.h> |
51 | #include <ddi/ddi.h> |
51 | #include <arch/types.h> |
52 | #include <arch/types.h> |
52 | 53 | ||
53 | SPINLOCK_INITIALIZE(fb_lock); |
54 | SPINLOCK_INITIALIZE(fb_lock); |
54 | 55 | ||
55 | static uint8_t *fb_addr; |
56 | static uint8_t *fb_addr; |
56 | static uint16_t *backbuf; |
57 | static uint16_t *backbuf; |
57 | static uint8_t *glyphs; |
58 | static uint8_t *glyphs; |
58 | static uint8_t *bgscan; |
59 | static uint8_t *bgscan; |
59 | 60 | ||
60 | static unsigned int xres; |
61 | static unsigned int xres; |
61 | static unsigned int yres; |
62 | static unsigned int yres; |
62 | 63 | ||
63 | static unsigned int ylogo; |
64 | static unsigned int ylogo; |
64 | static unsigned int ytrim; |
65 | static unsigned int ytrim; |
65 | static unsigned int rowtrim; |
66 | static unsigned int rowtrim; |
66 | 67 | ||
67 | static unsigned int scanline; |
68 | static unsigned int scanline; |
68 | static unsigned int glyphscanline; |
69 | static unsigned int glyphscanline; |
69 | 70 | ||
70 | static unsigned int pixelbytes; |
71 | static unsigned int pixelbytes; |
71 | static unsigned int glyphbytes; |
72 | static unsigned int glyphbytes; |
72 | static unsigned int bgscanbytes; |
73 | static unsigned int bgscanbytes; |
73 | 74 | ||
74 | static unsigned int cols; |
75 | static unsigned int cols; |
75 | static unsigned int rows; |
76 | static unsigned int rows; |
76 | static unsigned int position = 0; |
77 | static unsigned int position = 0; |
77 | 78 | ||
78 | #define BG_COLOR 0x000080 |
79 | #define BG_COLOR 0x000080 |
79 | #define FG_COLOR 0xffff00 |
80 | #define FG_COLOR 0xffff00 |
80 | #define INV_COLOR 0xaaaaaa |
81 | #define INV_COLOR 0xaaaaaa |
81 | 82 | ||
82 | #define CURSOR 0x2588 |
- | |
83 | - | ||
84 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
83 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
84 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
86 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
85 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
87 | 86 | ||
88 | #define COL2X(col) ((col) * FONT_WIDTH) |
87 | #define COL2X(col) ((col) * FONT_WIDTH) |
89 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
88 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
90 | 89 | ||
91 | #define X2COL(x) ((x) / FONT_WIDTH) |
90 | #define X2COL(x) ((x) / FONT_WIDTH) |
92 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
91 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
93 | 92 | ||
94 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
93 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
95 | #define BB_POS(col, row) ((row) * cols + (col)) |
94 | #define BB_POS(col, row) ((row) * cols + (col)) |
96 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
95 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
97 | 96 | ||
98 | 97 | ||
99 | static void (*rgb_conv)(void *, uint32_t); |
98 | static void (*rgb_conv)(void *, uint32_t); |
100 | 99 | ||
101 | 100 | ||
102 | /** ARGB 8:8:8:8 conversion |
101 | /** ARGB 8:8:8:8 conversion |
103 | * |
102 | * |
104 | */ |
103 | */ |
105 | static void rgb_0888(void *dst, uint32_t rgb) |
104 | static void rgb_0888(void *dst, uint32_t rgb) |
106 | { |
105 | { |
107 | *((uint32_t *) dst) = rgb & 0xffffff; |
106 | *((uint32_t *) dst) = rgb & 0xffffff; |
108 | } |
107 | } |
109 | 108 | ||
110 | 109 | ||
111 | /** ABGR 8:8:8:8 conversion |
110 | /** ABGR 8:8:8:8 conversion |
112 | * |
111 | * |
113 | */ |
112 | */ |
114 | static void bgr_0888(void *dst, uint32_t rgb) |
113 | static void bgr_0888(void *dst, uint32_t rgb) |
115 | { |
114 | { |
116 | *((uint32_t *) dst) |
115 | *((uint32_t *) dst) |
117 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
116 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
118 | } |
117 | } |
119 | 118 | ||
120 | 119 | ||
121 | /** RGB 8:8:8 conversion |
120 | /** RGB 8:8:8 conversion |
122 | * |
121 | * |
123 | */ |
122 | */ |
124 | static void rgb_888(void *dst, uint32_t rgb) |
123 | static void rgb_888(void *dst, uint32_t rgb) |
125 | { |
124 | { |
126 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
125 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
127 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
126 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
128 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
127 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
129 | } |
128 | } |
130 | 129 | ||
131 | 130 | ||
132 | /** BGR 8:8:8 conversion |
131 | /** BGR 8:8:8 conversion |
133 | * |
132 | * |
134 | */ |
133 | */ |
135 | static void bgr_888(void *dst, uint32_t rgb) |
134 | static void bgr_888(void *dst, uint32_t rgb) |
136 | { |
135 | { |
137 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
136 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
138 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
137 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
139 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
138 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
140 | } |
139 | } |
141 | 140 | ||
142 | 141 | ||
143 | /** RGB 5:5:5 conversion |
142 | /** RGB 5:5:5 conversion |
144 | * |
143 | * |
145 | */ |
144 | */ |
146 | static void rgb_555(void *dst, uint32_t rgb) |
145 | static void rgb_555(void *dst, uint32_t rgb) |
147 | { |
146 | { |
148 | *((uint16_t *) dst) |
147 | *((uint16_t *) dst) |
149 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
148 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
150 | } |
149 | } |
151 | 150 | ||
152 | 151 | ||
153 | /** RGB 5:6:5 conversion |
152 | /** RGB 5:6:5 conversion |
154 | * |
153 | * |
155 | */ |
154 | */ |
156 | static void rgb_565(void *dst, uint32_t rgb) |
155 | static void rgb_565(void *dst, uint32_t rgb) |
157 | { |
156 | { |
158 | *((uint16_t *) dst) |
157 | *((uint16_t *) dst) |
159 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
158 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
160 | } |
159 | } |
161 | 160 | ||
162 | 161 | ||
163 | /** RGB 3:2:3 |
162 | /** RGB 3:2:3 |
164 | * |
163 | * |
165 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
164 | * 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 |
165 | * will most likely use a color palette. The color appearance |
167 | * will be pretty random and depend on the default installed |
166 | * will be pretty random and depend on the default installed |
168 | * palette. This could be fixed by supporting custom palette |
167 | * palette. This could be fixed by supporting custom palette |
169 | * and setting it to simulate the 8-bit truecolor. |
168 | * and setting it to simulate the 8-bit truecolor. |
170 | * |
169 | * |
171 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
170 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
172 | * |
171 | * |
173 | * Note that the byte is being inverted by this function. The reason is |
172 | * 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 |
173 | * 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) |
174 | * 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 |
175 | * use these codes for black and white and prevent to set codes |
177 | * 0 and 255 to other colors. |
176 | * 0 and 255 to other colors. |
178 | * |
177 | * |
179 | */ |
178 | */ |
180 | static void rgb_323(void *dst, uint32_t rgb) |
179 | static void rgb_323(void *dst, uint32_t rgb) |
181 | { |
180 | { |
182 | *((uint8_t *) dst) |
181 | *((uint8_t *) dst) |
183 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
182 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
184 | } |
183 | } |
185 | 184 | ||
186 | 185 | ||
187 | /** Hide logo and refresh screen |
186 | /** Hide logo and refresh screen |
188 | * |
187 | * |
189 | */ |
188 | */ |
190 | static void logo_hide(bool silent) |
189 | static void logo_hide(bool silent) |
191 | { |
190 | { |
192 | ylogo = 0; |
191 | ylogo = 0; |
193 | ytrim = yres; |
192 | ytrim = yres; |
194 | rowtrim = rows; |
193 | rowtrim = rows; |
195 | if (!silent) |
194 | if (!silent) |
196 | fb_redraw(); |
195 | fb_redraw(); |
197 | } |
196 | } |
198 | 197 | ||
199 | 198 | ||
200 | /** Draw character at given position |
199 | /** Draw character at given position |
201 | * |
200 | * |
202 | */ |
201 | */ |
203 | static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent) |
202 | static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay) |
204 | { |
203 | { |
205 | unsigned int x = COL2X(col); |
204 | unsigned int x = COL2X(col); |
206 | unsigned int y = ROW2Y(row); |
205 | unsigned int y = ROW2Y(row); |
207 | unsigned int yd; |
206 | unsigned int yd; |
208 | 207 | ||
209 | if (y >= ytrim) |
208 | if (y >= ytrim) |
210 | logo_hide(silent); |
209 | logo_hide(silent); |
211 | 210 | ||
- | 211 | if (!overlay) |
|
212 | backbuf[BB_POS(col, row)] = glyph; |
212 | backbuf[BB_POS(col, row)] = glyph; |
213 | 213 | ||
214 | if (!silent) { |
214 | if (!silent) { |
215 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
215 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
216 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
216 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
217 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
217 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
218 | } |
218 | } |
219 | } |
219 | } |
220 | 220 | ||
221 | 221 | ||
222 | /** Scroll screen down by one row |
222 | /** Scroll screen down by one row |
223 | * |
223 | * |
224 | * |
224 | * |
225 | */ |
225 | */ |
226 | static void screen_scroll(bool silent) |
226 | static void screen_scroll(bool silent) |
227 | { |
227 | { |
228 | if (ylogo > 0) { |
228 | if (ylogo > 0) { |
229 | logo_hide(silent); |
229 | logo_hide(silent); |
230 | return; |
230 | return; |
231 | } |
231 | } |
232 | 232 | ||
233 | if (!silent) { |
233 | if (!silent) { |
234 | unsigned int row; |
234 | unsigned int row; |
235 | 235 | ||
236 | for (row = 0; row < rows; row++) { |
236 | for (row = 0; row < rows; row++) { |
237 | unsigned int y = ROW2Y(row); |
237 | unsigned int y = ROW2Y(row); |
238 | unsigned int yd; |
238 | unsigned int yd; |
239 | 239 | ||
240 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
240 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
241 | unsigned int x; |
241 | unsigned int x; |
242 | unsigned int col; |
242 | unsigned int col; |
243 | 243 | ||
244 | for (col = 0, x = 0; col < cols; col++, |
244 | for (col = 0, x = 0; col < cols; col++, |
245 | x += FONT_WIDTH) { |
245 | x += FONT_WIDTH) { |
246 | uint16_t glyph; |
246 | uint16_t glyph; |
247 | 247 | ||
248 | if (row < rows - 1) { |
248 | if (row < rows - 1) { |
249 | if (backbuf[BB_POS(col, row)] == |
249 | if (backbuf[BB_POS(col, row)] == |
250 | backbuf[BB_POS(col, row + 1)]) |
250 | backbuf[BB_POS(col, row + 1)]) |
251 | continue; |
251 | continue; |
252 | 252 | ||
253 | glyph = backbuf[BB_POS(col, row + 1)]; |
253 | glyph = backbuf[BB_POS(col, row + 1)]; |
254 | } else |
254 | } else |
255 | glyph = 0; |
255 | glyph = 0; |
256 | 256 | ||
257 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
257 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
258 | &glyphs[GLYPH_POS(glyph, yd)], |
258 | &glyphs[GLYPH_POS(glyph, yd)], |
259 | glyphscanline); |
259 | glyphscanline); |
260 | } |
260 | } |
261 | } |
261 | } |
262 | } |
262 | } |
263 | } |
263 | } |
264 | 264 | ||
265 | memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t)); |
265 | memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t)); |
266 | memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
266 | memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
267 | } |
267 | } |
268 | 268 | ||
269 | 269 | ||
270 | static void cursor_put(bool silent) |
270 | static void cursor_put(bool silent) |
271 | { |
271 | { |
- | 272 | unsigned int col = position % cols; |
|
- | 273 | unsigned int row = position / cols; |
|
- | 274 | ||
272 | glyph_draw(fb_font_glyph(CURSOR), position % cols, position / cols, silent); |
275 | glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true); |
273 | } |
276 | } |
274 | 277 | ||
275 | 278 | ||
276 | static void cursor_remove(bool silent) |
279 | static void cursor_remove(bool silent) |
277 | { |
280 | { |
- | 281 | unsigned int col = position % cols; |
|
- | 282 | unsigned int row = position / cols; |
|
- | 283 | ||
278 | glyph_draw(fb_font_glyph(0), position % cols, position / cols, silent); |
284 | glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true); |
279 | } |
285 | } |
280 | 286 | ||
281 | 287 | ||
282 | /** Print character to screen |
288 | /** Print character to screen |
283 | * |
289 | * |
284 | * Emulate basic terminal commands. |
290 | * Emulate basic terminal commands. |
285 | * |
291 | * |
286 | */ |
292 | */ |
287 | static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent) |
293 | static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent) |
288 | { |
294 | { |
289 | spinlock_lock(&fb_lock); |
295 | spinlock_lock(&fb_lock); |
290 | 296 | ||
291 | switch (ch) { |
297 | switch (ch) { |
292 | case '\n': |
298 | case '\n': |
293 | cursor_remove(silent); |
299 | cursor_remove(silent); |
294 | position += cols; |
300 | position += cols; |
295 | position -= position % cols; |
301 | position -= position % cols; |
296 | break; |
302 | break; |
297 | case '\r': |
303 | case '\r': |
298 | cursor_remove(silent); |
304 | cursor_remove(silent); |
299 | position -= position % cols; |
305 | position -= position % cols; |
300 | break; |
306 | break; |
301 | case '\b': |
307 | case '\b': |
302 | cursor_remove(silent); |
308 | cursor_remove(silent); |
303 | if (position % cols) |
309 | if (position % cols) |
304 | position--; |
310 | position--; |
305 | break; |
311 | break; |
306 | case '\t': |
312 | case '\t': |
307 | cursor_remove(silent); |
313 | cursor_remove(silent); |
308 | do { |
314 | do { |
309 | glyph_draw(fb_font_glyph(' '), position % cols, |
315 | glyph_draw(fb_font_glyph(' '), position % cols, |
310 | position / cols, silent); |
316 | position / cols, silent, false); |
311 | position++; |
317 | position++; |
312 | } while ((position % 8) && (position < cols * rows)); |
318 | } while ((position % 8) && (position < cols * rows)); |
313 | break; |
319 | break; |
314 | default: |
320 | default: |
315 | glyph_draw(fb_font_glyph(ch), position % cols, |
321 | glyph_draw(fb_font_glyph(ch), position % cols, |
316 | position / cols, silent); |
322 | position / cols, silent, false); |
317 | position++; |
323 | position++; |
318 | } |
324 | } |
319 | 325 | ||
320 | if (position >= cols * rows) { |
326 | if (position >= cols * rows) { |
321 | position -= cols; |
327 | position -= cols; |
322 | screen_scroll(silent); |
328 | screen_scroll(silent); |
323 | } |
329 | } |
324 | 330 | ||
325 | cursor_put(silent); |
331 | cursor_put(silent); |
326 | 332 | ||
327 | spinlock_unlock(&fb_lock); |
333 | spinlock_unlock(&fb_lock); |
328 | } |
334 | } |
329 | 335 | ||
330 | static outdev_t fb_console; |
336 | static outdev_t fb_console; |
331 | static outdev_operations_t fb_ops = { |
337 | static outdev_operations_t fb_ops = { |
332 | .write = fb_putchar |
338 | .write = fb_putchar |
333 | }; |
339 | }; |
334 | 340 | ||
335 | 341 | ||
336 | /** Render glyphs |
342 | /** Render glyphs |
337 | * |
343 | * |
338 | * Convert glyphs from device independent font |
344 | * Convert glyphs from device independent font |
339 | * description to current visual representation. |
345 | * description to current visual representation. |
340 | * |
346 | * |
341 | */ |
347 | */ |
342 | static void glyphs_render(void) |
348 | static void glyphs_render(void) |
343 | { |
349 | { |
344 | /* Prerender glyphs */ |
350 | /* Prerender glyphs */ |
345 | uint16_t glyph; |
351 | uint16_t glyph; |
346 | 352 | ||
347 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
353 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
348 | uint32_t fg_color; |
354 | uint32_t fg_color; |
349 | 355 | ||
350 | if (glyph == FONT_GLYPHS - 1) |
356 | if (glyph == FONT_GLYPHS - 1) |
351 | fg_color = INV_COLOR; |
357 | fg_color = INV_COLOR; |
352 | else |
358 | else |
353 | fg_color = FG_COLOR; |
359 | fg_color = FG_COLOR; |
354 | 360 | ||
355 | unsigned int y; |
361 | unsigned int y; |
356 | 362 | ||
357 | for (y = 0; y < FONT_SCANLINES; y++) { |
363 | for (y = 0; y < FONT_SCANLINES; y++) { |
358 | unsigned int x; |
364 | unsigned int x; |
359 | 365 | ||
360 | for (x = 0; x < FONT_WIDTH; x++) { |
366 | for (x = 0; x < FONT_WIDTH; x++) { |
361 | void *dst = &glyphs[GLYPH_POS(glyph, y) + |
367 | void *dst = &glyphs[GLYPH_POS(glyph, y) + |
362 | x * pixelbytes]; |
368 | x * pixelbytes]; |
363 | uint32_t rgb = (fb_font[glyph][y] & |
369 | uint32_t rgb = (fb_font[glyph][y] & |
364 | (1 << (7 - x))) ? fg_color : BG_COLOR; |
370 | (1 << (7 - x))) ? fg_color : BG_COLOR; |
365 | rgb_conv(dst, rgb); |
371 | rgb_conv(dst, rgb); |
366 | } |
372 | } |
367 | } |
373 | } |
368 | } |
374 | } |
369 | 375 | ||
370 | /* Prerender background scanline */ |
376 | /* Prerender background scanline */ |
371 | unsigned int x; |
377 | unsigned int x; |
372 | 378 | ||
373 | for (x = 0; x < xres; x++) |
379 | for (x = 0; x < xres; x++) |
374 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
380 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
375 | } |
381 | } |
376 | 382 | ||
377 | 383 | ||
378 | /** Refresh the screen |
384 | /** Refresh the screen |
379 | * |
385 | * |
380 | */ |
386 | */ |
381 | void fb_redraw(void) |
387 | void fb_redraw(void) |
382 | { |
388 | { |
383 | if (ylogo > 0) { |
389 | if (ylogo > 0) { |
384 | unsigned int y; |
390 | unsigned int y; |
385 | 391 | ||
386 | for (y = 0; y < LOGO_HEIGHT; y++) { |
392 | for (y = 0; y < LOGO_HEIGHT; y++) { |
387 | unsigned int x; |
393 | unsigned int x; |
388 | 394 | ||
389 | for (x = 0; x < xres; x++) |
395 | for (x = 0; x < xres; x++) |
390 | rgb_conv(&fb_addr[FB_POS(x, y)], |
396 | rgb_conv(&fb_addr[FB_POS(x, y)], |
391 | (x < LOGO_WIDTH) ? |
397 | (x < LOGO_WIDTH) ? |
392 | fb_logo[y * LOGO_WIDTH + x] : |
398 | fb_logo[y * LOGO_WIDTH + x] : |
393 | LOGO_COLOR); |
399 | LOGO_COLOR); |
394 | } |
400 | } |
395 | } |
401 | } |
396 | 402 | ||
397 | unsigned int row; |
403 | unsigned int row; |
398 | 404 | ||
399 | for (row = 0; row < rowtrim; row++) { |
405 | for (row = 0; row < rowtrim; row++) { |
400 | unsigned int y = ylogo + ROW2Y(row); |
406 | unsigned int y = ylogo + ROW2Y(row); |
401 | unsigned int yd; |
407 | unsigned int yd; |
402 | 408 | ||
403 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
409 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
404 | unsigned int x; |
410 | unsigned int x; |
405 | unsigned int col; |
411 | unsigned int col; |
406 | 412 | ||
407 | for (col = 0, x = 0; col < cols; |
413 | for (col = 0, x = 0; col < cols; |
408 | col++, x += FONT_WIDTH) { |
414 | col++, x += FONT_WIDTH) { |
409 | uint16_t glyph = backbuf[BB_POS(col, row)]; |
415 | uint16_t glyph = backbuf[BB_POS(col, row)]; |
410 | void *dst = &fb_addr[FB_POS(x, y + yd)]; |
416 | void *dst = &fb_addr[FB_POS(x, y + yd)]; |
411 | void *src = &glyphs[GLYPH_POS(glyph, yd)]; |
417 | void *src = &glyphs[GLYPH_POS(glyph, yd)]; |
412 | memcpy(dst, src, glyphscanline); |
418 | memcpy(dst, src, glyphscanline); |
413 | } |
419 | } |
414 | } |
420 | } |
415 | } |
421 | } |
416 | 422 | ||
417 | if (COL2X(cols) < xres) { |
423 | if (COL2X(cols) < xres) { |
418 | unsigned int y; |
424 | unsigned int y; |
419 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
425 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
420 | 426 | ||
421 | for (y = ylogo; y < yres; y++) |
427 | for (y = ylogo; y < yres; y++) |
422 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
428 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
423 | } |
429 | } |
424 | 430 | ||
425 | if (ROW2Y(rowtrim) + ylogo < yres) { |
431 | if (ROW2Y(rowtrim) + ylogo < yres) { |
426 | unsigned int y; |
432 | unsigned int y; |
427 | 433 | ||
428 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
434 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
429 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
435 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
430 | } |
436 | } |
431 | } |
437 | } |
432 | 438 | ||
433 | 439 | ||
434 | /** Initialize framebuffer as a output character device |
440 | /** Initialize framebuffer as a output character device |
435 | * |
441 | * |
436 | * @param addr Physical address of the framebuffer |
442 | * @param addr Physical address of the framebuffer |
437 | * @param x Screen width in pixels |
443 | * @param x Screen width in pixels |
438 | * @param y Screen height in pixels |
444 | * @param y Screen height in pixels |
439 | * @param scan Bytes per one scanline |
445 | * @param scan Bytes per one scanline |
440 | * @param visual Color model |
446 | * @param visual Color model |
441 | * |
447 | * |
442 | */ |
448 | */ |
443 | void fb_init(fb_properties_t *props) |
449 | void fb_init(fb_properties_t *props) |
444 | { |
450 | { |
445 | switch (props->visual) { |
451 | switch (props->visual) { |
446 | case VISUAL_INDIRECT_8: |
452 | case VISUAL_INDIRECT_8: |
447 | rgb_conv = rgb_323; |
453 | rgb_conv = rgb_323; |
448 | pixelbytes = 1; |
454 | pixelbytes = 1; |
449 | break; |
455 | break; |
450 | case VISUAL_RGB_5_5_5: |
456 | case VISUAL_RGB_5_5_5: |
451 | rgb_conv = rgb_555; |
457 | rgb_conv = rgb_555; |
452 | pixelbytes = 2; |
458 | pixelbytes = 2; |
453 | break; |
459 | break; |
454 | case VISUAL_RGB_5_6_5: |
460 | case VISUAL_RGB_5_6_5: |
455 | rgb_conv = rgb_565; |
461 | rgb_conv = rgb_565; |
456 | pixelbytes = 2; |
462 | pixelbytes = 2; |
457 | break; |
463 | break; |
458 | case VISUAL_RGB_8_8_8: |
464 | case VISUAL_RGB_8_8_8: |
459 | rgb_conv = rgb_888; |
465 | rgb_conv = rgb_888; |
460 | pixelbytes = 3; |
466 | pixelbytes = 3; |
461 | break; |
467 | break; |
462 | case VISUAL_BGR_8_8_8: |
468 | case VISUAL_BGR_8_8_8: |
463 | rgb_conv = bgr_888; |
469 | rgb_conv = bgr_888; |
464 | pixelbytes = 3; |
470 | pixelbytes = 3; |
465 | break; |
471 | break; |
466 | case VISUAL_RGB_8_8_8_0: |
472 | case VISUAL_RGB_8_8_8_0: |
467 | rgb_conv = rgb_888; |
473 | rgb_conv = rgb_888; |
468 | pixelbytes = 4; |
474 | pixelbytes = 4; |
469 | break; |
475 | break; |
470 | case VISUAL_RGB_0_8_8_8: |
476 | case VISUAL_RGB_0_8_8_8: |
471 | rgb_conv = rgb_0888; |
477 | rgb_conv = rgb_0888; |
472 | pixelbytes = 4; |
478 | pixelbytes = 4; |
473 | break; |
479 | break; |
474 | case VISUAL_BGR_0_8_8_8: |
480 | case VISUAL_BGR_0_8_8_8: |
475 | rgb_conv = bgr_0888; |
481 | rgb_conv = bgr_0888; |
476 | pixelbytes = 4; |
482 | pixelbytes = 4; |
477 | break; |
483 | break; |
478 | default: |
484 | default: |
479 | panic("Unsupported visual."); |
485 | panic("Unsupported visual."); |
480 | } |
486 | } |
481 | 487 | ||
482 | xres = props->x; |
488 | xres = props->x; |
483 | yres = props->y; |
489 | yres = props->y; |
484 | scanline = props->scan; |
490 | scanline = props->scan; |
485 | 491 | ||
486 | cols = X2COL(xres); |
492 | cols = X2COL(xres); |
487 | rows = Y2ROW(yres); |
493 | rows = Y2ROW(yres); |
488 | 494 | ||
489 | if (yres > ylogo) { |
495 | if (yres > ylogo) { |
490 | ylogo = LOGO_HEIGHT; |
496 | ylogo = LOGO_HEIGHT; |
491 | rowtrim = rows - Y2ROW(ylogo); |
497 | rowtrim = rows - Y2ROW(ylogo); |
492 | if (ylogo % FONT_SCANLINES > 0) |
498 | if (ylogo % FONT_SCANLINES > 0) |
493 | rowtrim--; |
499 | rowtrim--; |
494 | ytrim = ROW2Y(rowtrim); |
500 | ytrim = ROW2Y(rowtrim); |
495 | } else { |
501 | } else { |
496 | ylogo = 0; |
502 | ylogo = 0; |
497 | ytrim = yres; |
503 | ytrim = yres; |
498 | rowtrim = rows; |
504 | rowtrim = rows; |
499 | } |
505 | } |
500 | 506 | ||
501 | glyphscanline = FONT_WIDTH * pixelbytes; |
507 | glyphscanline = FONT_WIDTH * pixelbytes; |
502 | glyphbytes = ROW2Y(glyphscanline); |
508 | glyphbytes = ROW2Y(glyphscanline); |
503 | bgscanbytes = xres * pixelbytes; |
509 | bgscanbytes = xres * pixelbytes; |
504 | 510 | ||
505 | size_t fbsize = scanline * yres; |
511 | size_t fbsize = scanline * yres; |
506 | size_t bbsize = cols * rows * sizeof(uint16_t); |
512 | size_t bbsize = cols * rows * sizeof(uint16_t); |
507 | size_t glyphsize = FONT_GLYPHS * glyphbytes; |
513 | size_t glyphsize = FONT_GLYPHS * glyphbytes; |
508 | 514 | ||
509 | backbuf = (uint16_t *) malloc(bbsize, 0); |
515 | backbuf = (uint16_t *) malloc(bbsize, 0); |
510 | if (!backbuf) |
516 | if (!backbuf) |
511 | panic("Unable to allocate backbuffer."); |
517 | panic("Unable to allocate backbuffer."); |
512 | 518 | ||
513 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
519 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
514 | if (!glyphs) |
520 | if (!glyphs) |
515 | panic("Unable to allocate glyphs."); |
521 | panic("Unable to allocate glyphs."); |
516 | 522 | ||
517 | bgscan = malloc(bgscanbytes, 0); |
523 | bgscan = malloc(bgscanbytes, 0); |
518 | if (!bgscan) |
524 | if (!bgscan) |
519 | panic("Unable to allocate background pixel."); |
525 | panic("Unable to allocate background pixel."); |
520 | 526 | ||
521 | memsetw(backbuf, cols * rows, 0); |
527 | memsetw(backbuf, cols * rows, 0); |
522 | 528 | ||
523 | glyphs_render(); |
529 | glyphs_render(); |
524 | 530 | ||
525 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
531 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
526 | 532 | ||
527 | sysinfo_set_item_val("fb", NULL, true); |
533 | sysinfo_set_item_val("fb", NULL, true); |
528 | sysinfo_set_item_val("fb.kind", NULL, 1); |
534 | sysinfo_set_item_val("fb.kind", NULL, 1); |
529 | sysinfo_set_item_val("fb.width", NULL, xres); |
535 | sysinfo_set_item_val("fb.width", NULL, xres); |
530 | sysinfo_set_item_val("fb.height", NULL, yres); |
536 | sysinfo_set_item_val("fb.height", NULL, yres); |
531 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
537 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
532 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
538 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
533 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
539 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
534 | 540 | ||
535 | fb_redraw(); |
541 | fb_redraw(); |
536 | 542 | ||
537 | outdev_initialize("fb", &fb_console, &fb_ops); |
543 | outdev_initialize("fb", &fb_console, &fb_ops); |
538 | stdout = &fb_console; |
544 | stdout = &fb_console; |
539 | } |
545 | } |
540 | 546 | ||
541 | /** @} |
547 | /** @} |
542 | */ |
548 | */ |
543 | 549 |