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