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