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