Rev 2071 | Rev 2089 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2086 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genarch |
29 | /** @addtogroup genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <genarch/fb/font-8x16.h> |
35 | #include <genarch/fb/font-8x16.h> |
36 | #include <genarch/fb/visuals.h> |
36 | #include <genarch/fb/visuals.h> |
37 | #include <genarch/fb/fb.h> |
37 | #include <genarch/fb/fb.h> |
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
41 | #include <mm/slab.h> |
41 | #include <mm/slab.h> |
42 | #include <panic.h> |
42 | #include <panic.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
44 | #include <config.h> |
44 | #include <config.h> |
45 | #include <bitops.h> |
45 | #include <bitops.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | #include <ddi/ddi.h> |
47 | #include <ddi/ddi.h> |
48 | #include <arch/types.h> |
48 | #include <arch/types.h> |
49 | #include <typedefs.h> |
49 | #include <typedefs.h> |
50 | 50 | ||
51 | #include "helenos.xbm" |
51 | #include "helenos.xbm" |
52 | 52 | ||
53 | static parea_t fb_parea; /**< Physical memory area for fb. */ |
53 | static parea_t fb_parea; /**< Physical memory area for fb. */ |
54 | 54 | ||
55 | SPINLOCK_INITIALIZE(fb_lock); |
55 | SPINLOCK_INITIALIZE(fb_lock); |
56 | 56 | ||
57 | static uint8_t *fbaddress = NULL; |
57 | static uint8_t *fbaddress = NULL; |
58 | 58 | ||
59 | static uint8_t *blankline = NULL; |
59 | static uint8_t *blankline = NULL; |
60 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
60 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
61 | static index_t dboffset; |
61 | static index_t dboffset; |
62 | 62 | ||
63 | static unsigned int xres = 0; |
63 | static unsigned int xres = 0; |
64 | static unsigned int yres = 0; |
64 | static unsigned int yres = 0; |
65 | static unsigned int scanline = 0; |
65 | static unsigned int scanline = 0; |
66 | static unsigned int pixelbytes = 0; |
66 | static unsigned int pixelbytes = 0; |
67 | #ifdef FB_INVERT_COLORS |
67 | #ifdef FB_INVERT_COLORS |
68 | static bool invert_colors = true; |
68 | static bool invert_colors = true; |
69 | #else |
69 | #else |
70 | static bool invert_colors = false; |
70 | static bool invert_colors = false; |
71 | #endif |
71 | #endif |
72 | 72 | ||
73 | static unsigned int position = 0; |
73 | static unsigned int position = 0; |
74 | static unsigned int columns = 0; |
74 | static unsigned int columns = 0; |
75 | static unsigned int rows = 0; |
75 | static unsigned int rows = 0; |
76 | 76 | ||
77 | #define COL_WIDTH 8 |
77 | #define COL_WIDTH 8 |
78 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
78 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
79 | 79 | ||
80 | #define BGCOLOR 0x000080 |
80 | #define BGCOLOR 0x000080 |
81 | #define FGCOLOR 0xffff00 |
81 | #define FGCOLOR 0xffff00 |
82 | #define LOGOCOLOR 0x2020b0 |
82 | #define LOGOCOLOR 0x2020b0 |
83 | 83 | ||
84 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
84 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
86 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
86 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
87 | 87 | ||
88 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
88 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
89 | 89 | ||
90 | /***************************************************************/ |
90 | /***************************************************************/ |
91 | /* Pixel specific fuctions */ |
91 | /* Pixel specific fuctions */ |
92 | 92 | ||
93 | static void (*rgb2scr)(void *, int); |
93 | static void (*rgb2scr)(void *, int); |
94 | static int (*scr2rgb)(void *); |
94 | static int (*scr2rgb)(void *); |
95 | 95 | ||
96 | static inline int COLOR(int color) |
96 | static inline int COLOR(int color) |
97 | { |
97 | { |
98 | return invert_colors ? ~color : color; |
98 | return invert_colors ? ~color : color; |
99 | } |
99 | } |
100 | 100 | ||
101 | /* Conversion routines between different color representations */ |
101 | /* Conversion routines between different color representations */ |
102 | static void rgb_byte0888(void *dst, int rgb) |
102 | static void rgb_byte0888(void *dst, int rgb) |
103 | { |
103 | { |
104 | *((int *) dst) = rgb; |
104 | *((int *) dst) = rgb; |
105 | } |
105 | } |
106 | 106 | ||
107 | static int byte0888_rgb(void *src) |
107 | static int byte0888_rgb(void *src) |
108 | { |
108 | { |
109 | return (*((int *) src)) & 0xffffff; |
109 | return (*((int *) src)) & 0xffffff; |
110 | } |
110 | } |
111 | 111 | ||
112 | static void bgr_byte0888(void *dst, int rgb) |
112 | static void bgr_byte0888(void *dst, int rgb) |
113 | { |
113 | { |
114 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb, |
114 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | |
115 | 8); |
115 | RED(rgb, 8); |
116 | } |
116 | } |
117 | 117 | ||
118 | static int byte0888_bgr(void *src) |
118 | static int byte0888_bgr(void *src) |
119 | { |
119 | { |
120 | int color = *(uint32_t *)(src); |
120 | int color = *(uint32_t *)(src); |
121 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color |
121 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
122 | >> 16) & 0xff); |
122 | ((color >> 16) & 0xff); |
123 | } |
123 | } |
124 | 124 | ||
125 | static void rgb_byte888(void *dst, int rgb) |
125 | static void rgb_byte888(void *dst, int rgb) |
126 | { |
126 | { |
127 | uint8_t *scr = dst; |
127 | uint8_t *scr = dst; |
128 | #if defined(FB_INVERT_ENDIAN) |
128 | #if defined(FB_INVERT_ENDIAN) |
129 | scr[0] = RED(rgb, 8); |
129 | scr[0] = RED(rgb, 8); |
130 | scr[1] = GREEN(rgb, 8); |
130 | scr[1] = GREEN(rgb, 8); |
131 | scr[2] = BLUE(rgb, 8); |
131 | scr[2] = BLUE(rgb, 8); |
132 | #else |
132 | #else |
133 | scr[2] = RED(rgb, 8); |
133 | scr[2] = RED(rgb, 8); |
134 | scr[1] = GREEN(rgb, 8); |
134 | scr[1] = GREEN(rgb, 8); |
135 | scr[0] = BLUE(rgb, 8); |
135 | scr[0] = BLUE(rgb, 8); |
136 | #endif |
136 | #endif |
137 | } |
137 | } |
138 | 138 | ||
139 | static int byte888_rgb(void *src) |
139 | static int byte888_rgb(void *src) |
140 | { |
140 | { |
141 | uint8_t *scr = src; |
141 | uint8_t *scr = src; |
142 | #if defined(FB_INVERT_ENDIAN) |
142 | #if defined(FB_INVERT_ENDIAN) |
143 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
143 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
144 | #else |
144 | #else |
145 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
145 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
146 | #endif |
146 | #endif |
147 | } |
147 | } |
148 | 148 | ||
149 | /** 16-bit depth (5:5:5) */ |
149 | /** 16-bit depth (5:5:5) */ |
150 | static void rgb_byte555(void *dst, int rgb) |
150 | static void rgb_byte555(void *dst, int rgb) |
151 | { |
151 | { |
152 | /* 5-bit, 5-bits, 5-bits */ |
152 | /* 5-bit, 5-bits, 5-bits */ |
153 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, |
153 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
154 | 5); |
154 | BLUE(rgb, 5); |
155 | } |
155 | } |
156 | 156 | ||
157 | /** 16-bit depth (5:5:5) */ |
157 | /** 16-bit depth (5:5:5) */ |
158 | static int byte555_rgb(void *src) |
158 | static int byte555_rgb(void *src) |
159 | { |
159 | { |
160 | int color = *(uint16_t *)(src); |
160 | int color = *(uint16_t *)(src); |
161 | return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << |
161 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
162 | (8 + 3)) | ((color & 0x1f) << 3); |
162 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
163 | } |
163 | } |
164 | 164 | ||
165 | /** 16-bit depth (5:6:5) */ |
165 | /** 16-bit depth (5:6:5) */ |
166 | static void rgb_byte565(void *dst, int rgb) |
166 | static void rgb_byte565(void *dst, int rgb) |
167 | { |
167 | { |
168 | /* 5-bit, 6-bits, 5-bits */ |
168 | /* 5-bit, 6-bits, 5-bits */ |
169 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
169 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
- | 170 | BLUE(rgb, 5); |
|
170 | } |
171 | } |
171 | 172 | ||
172 | /** 16-bit depth (5:6:5) */ |
173 | /** 16-bit depth (5:6:5) */ |
173 | static int byte565_rgb(void *src) |
174 | static int byte565_rgb(void *src) |
174 | { |
175 | { |
175 | int color = *(uint16_t *)(src); |
176 | int color = *(uint16_t *)(src); |
176 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << |
177 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
177 | (8 + 2)) | ((color & 0x1f) << 3); |
178 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
178 | } |
179 | } |
179 | 180 | ||
180 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
181 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
181 | * |
182 | * |
182 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
183 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
183 | * will most likely use a color palette. The color appearance |
184 | * will most likely use a color palette. The color appearance |
184 | * will be pretty random and depend on the default installed |
185 | * will be pretty random and depend on the default installed |
185 | * palette. This could be fixed by supporting custom palette |
186 | * palette. This could be fixed by supporting custom palette |
186 | * and setting it to simulate the 8-bit truecolor. |
187 | * and setting it to simulate the 8-bit truecolor. |
187 | */ |
188 | */ |
188 | static void rgb_byte8(void *dst, int rgb) |
189 | static void rgb_byte8(void *dst, int rgb) |
189 | { |
190 | { |
190 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, |
191 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
191 | 3); |
192 | BLUE(rgb, 3); |
192 | } |
193 | } |
193 | 194 | ||
194 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
195 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
195 | * |
196 | * |
196 | * See the comment for rgb_byte(). |
197 | * See the comment for rgb_byte(). |
197 | */ |
198 | */ |
198 | static int byte8_rgb(void *src) |
199 | static int byte8_rgb(void *src) |
199 | { |
200 | { |
200 | int color = *(uint8_t *)src; |
201 | int color = *(uint8_t *)src; |
201 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 |
202 | return (((color >> 5) & 0x7) << (16 + 5)) | |
202 | + 6)) | ((color & 0x7) << 5); |
203 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
203 | } |
204 | } |
204 | 205 | ||
205 | static void putpixel(unsigned int x, unsigned int y, int color) |
206 | static void putpixel(unsigned int x, unsigned int y, int color) |
206 | { |
207 | { |
207 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
208 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
208 | 209 | ||
209 | if (dbbuffer) { |
210 | if (dbbuffer) { |
210 | int dline = (y + dboffset) % yres; |
211 | int dline = (y + dboffset) % yres; |
211 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
212 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
212 | } |
213 | } |
213 | } |
214 | } |
214 | 215 | ||
215 | /** Get pixel from viewport */ |
216 | /** Get pixel from viewport */ |
216 | static int getpixel(unsigned int x, unsigned int y) |
217 | static int getpixel(unsigned int x, unsigned int y) |
217 | { |
218 | { |
218 | if (dbbuffer) { |
219 | if (dbbuffer) { |
219 | int dline = (y + dboffset) % yres; |
220 | int dline = (y + dboffset) % yres; |
220 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
221 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
221 | } |
222 | } |
222 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
223 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
223 | } |
224 | } |
224 | 225 | ||
225 | 226 | ||
226 | /** Fill screen with background color */ |
227 | /** Fill screen with background color */ |
227 | static void clear_screen(void) |
228 | static void clear_screen(void) |
228 | { |
229 | { |
229 | unsigned int y; |
230 | unsigned int y; |
230 | 231 | ||
231 | for (y = 0; y < yres; y++) { |
232 | for (y = 0; y < yres; y++) { |
232 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
233 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
233 | if (dbbuffer) |
234 | if (dbbuffer) |
234 | memcpy(&dbbuffer[scanline * y], blankline, xres * |
235 | memcpy(&dbbuffer[scanline * y], blankline, |
235 | pixelbytes); |
236 | xres * pixelbytes); |
236 | } |
237 | } |
237 | } |
238 | } |
238 | 239 | ||
239 | 240 | ||
240 | /** Scroll screen one row up */ |
241 | /** Scroll screen one row up */ |
241 | static void scroll_screen(void) |
242 | static void scroll_screen(void) |
242 | { |
243 | { |
243 | if (dbbuffer) { |
244 | if (dbbuffer) { |
244 | count_t first; |
245 | count_t first; |
245 | 246 | ||
- | 247 | /* Clear the last row */ |
|
246 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
248 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
247 | 249 | ||
248 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
250 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
249 | first = yres - dboffset; |
251 | first = yres - dboffset; |
250 | 252 | ||
- | 253 | /* Move all rows one row up */ |
|
- | 254 | if (xres * pixelbytes == scanline) { |
|
251 | memcpy(fbaddress, &dbbuffer[scanline * dboffset], first * |
255 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
252 | scanline); |
256 | first * scanline); |
253 | memcpy(&fbaddress[first * scanline], dbbuffer, dboffset * |
257 | memcpy(&fbaddress[first * scanline], dbbuffer, |
- | 258 | dboffset * scanline); |
|
- | 259 | } else { |
|
- | 260 | /* |
|
- | 261 | * When the scanline is bigger than number of bytes |
|
- | 262 | * in the X-resolution, chances are that the |
|
- | 263 | * frame buffer memory past the X-resolution is special |
|
- | 264 | * in some way. For example, the SUNW,ffb framebuffer |
|
- | 265 | * wraps this area around the beginning of the same |
|
- | 266 | * line. To avoid troubles, copy only memory as |
|
- | 267 | * specified by the resolution. |
|
- | 268 | */ |
|
254 | scanline); |
269 | int i; |
- | 270 | ||
- | 271 | for (i = 0; i < first; i++) |
|
- | 272 | memcpy(&fbaddress[i * scanline], |
|
- | 273 | &dbbuffer[(dboffset + i) * scanline], |
|
- | 274 | xres * pixelbytes); |
|
- | 275 | for (i = 0; i < dboffset; i++) |
|
- | 276 | memcpy(&fbaddress[(first + i) * scanline], |
|
- | 277 | &dbbuffer[i * scanline], xres * pixelbytes); |
|
- | 278 | } |
|
255 | } else { |
279 | } else { |
256 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
280 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
257 | 281 | ||
- | 282 | if (xres * pixelbytes == scanline) { |
|
- | 283 | /* Move all rows one row up */ |
|
- | 284 | memcpy((void *) fbaddress, |
|
258 | memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], |
285 | (void *) &fbaddress[ROW_BYTES], |
259 | scanline * yres - ROW_BYTES); |
286 | scanline * yres - ROW_BYTES); |
260 | /* Clear last row */ |
287 | /* Clear the last row */ |
261 | memcpy((void *) lastline, (void *) blankline, ROW_BYTES); |
288 | memcpy((void *) lastline, (void *) blankline, |
- | 289 | ROW_BYTES); |
|
- | 290 | } else { |
|
- | 291 | /* |
|
- | 292 | * See the comment in the dbbuffer case. |
|
- | 293 | */ |
|
- | 294 | int i; |
|
- | 295 | ||
- | 296 | /* Move all rows one row up */ |
|
- | 297 | for (i = 0; i < yres - FONT_SCANLINES; i++) |
|
- | 298 | memcpy(&fbaddress[i * scanline], |
|
- | 299 | &fbaddress[(i + FONT_SCANLINES) * scanline], |
|
- | 300 | xres * pixelbytes); |
|
- | 301 | /* Clear the last row */ |
|
- | 302 | for (i = 0; i < FONT_SCANLINES; i++) |
|
- | 303 | memcpy(&lastline[i * scanline], |
|
- | 304 | &blankline[i * scanline], |
|
- | 305 | xres * pixelbytes); |
|
- | 306 | } |
|
262 | } |
307 | } |
263 | } |
308 | } |
264 | 309 | ||
265 | 310 | ||
266 | static void invert_pixel(unsigned int x, unsigned int y) |
311 | static void invert_pixel(unsigned int x, unsigned int y) |
267 | { |
312 | { |
268 | putpixel(x, y, ~getpixel(x, y)); |
313 | putpixel(x, y, ~getpixel(x, y)); |
269 | } |
314 | } |
270 | 315 | ||
271 | 316 | ||
272 | /** Draw one line of glyph at a given position */ |
317 | /** Draw one line of glyph at a given position */ |
273 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
318 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
274 | { |
319 | { |
275 | unsigned int i; |
320 | unsigned int i; |
276 | 321 | ||
277 | for (i = 0; i < 8; i++) |
322 | for (i = 0; i < 8; i++) |
278 | if (glline & (1 << (7 - i))) { |
323 | if (glline & (1 << (7 - i))) { |
279 | putpixel(x + i, y, FGCOLOR); |
324 | putpixel(x + i, y, FGCOLOR); |
280 | } else |
325 | } else |
281 | putpixel(x + i, y, BGCOLOR); |
326 | putpixel(x + i, y, BGCOLOR); |
282 | } |
327 | } |
283 | 328 | ||
284 | /***************************************************************/ |
329 | /***************************************************************/ |
285 | /* Character-console functions */ |
330 | /* Character-console functions */ |
286 | 331 | ||
287 | /** Draw character at given position */ |
332 | /** Draw character at given position */ |
288 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
333 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
289 | { |
334 | { |
290 | unsigned int y; |
335 | unsigned int y; |
291 | 336 | ||
292 | for (y = 0; y < FONT_SCANLINES; y++) |
337 | for (y = 0; y < FONT_SCANLINES; y++) |
293 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * |
338 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
294 | COL_WIDTH, row * FONT_SCANLINES + y); |
339 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
295 | } |
340 | } |
296 | 341 | ||
297 | /** Invert character at given position */ |
342 | /** Invert character at given position */ |
298 | static void invert_char(unsigned int col, unsigned int row) |
343 | static void invert_char(unsigned int col, unsigned int row) |
299 | { |
344 | { |
300 | unsigned int x; |
345 | unsigned int x; |
301 | unsigned int y; |
346 | unsigned int y; |
302 | 347 | ||
303 | for (x = 0; x < COL_WIDTH; x++) |
348 | for (x = 0; x < COL_WIDTH; x++) |
304 | for (y = 0; y < FONT_SCANLINES; y++) |
349 | for (y = 0; y < FONT_SCANLINES; y++) |
305 | invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + |
350 | invert_pixel(col * COL_WIDTH + x, |
306 | y); |
351 | row * FONT_SCANLINES + y); |
307 | } |
352 | } |
308 | 353 | ||
309 | /** Draw character at default position */ |
354 | /** Draw character at default position */ |
310 | static void draw_char(char chr) |
355 | static void draw_char(char chr) |
311 | { |
356 | { |
312 | draw_glyph(chr, position % columns, position / columns); |
357 | draw_glyph(chr, position % columns, position / columns); |
313 | } |
358 | } |
314 | 359 | ||
315 | static void draw_logo(unsigned int startx, unsigned int starty) |
360 | static void draw_logo(unsigned int startx, unsigned int starty) |
316 | { |
361 | { |
317 | unsigned int x; |
362 | unsigned int x; |
318 | unsigned int y; |
363 | unsigned int y; |
319 | unsigned int byte; |
364 | unsigned int byte; |
320 | unsigned int rowbytes; |
365 | unsigned int rowbytes; |
321 | 366 | ||
322 | rowbytes = (helenos_width - 1) / 8 + 1; |
367 | rowbytes = (helenos_width - 1) / 8 + 1; |
323 | 368 | ||
324 | for (y = 0; y < helenos_height; y++) |
369 | for (y = 0; y < helenos_height; y++) |
325 | for (x = 0; x < helenos_width; x++) { |
370 | for (x = 0; x < helenos_width; x++) { |
326 | byte = helenos_bits[rowbytes * y + x / 8]; |
371 | byte = helenos_bits[rowbytes * y + x / 8]; |
327 | byte >>= x % 8; |
372 | byte >>= x % 8; |
328 | if (byte & 1) |
373 | if (byte & 1) |
329 | putpixel(startx + x, starty + y, |
374 | putpixel(startx + x, starty + y, |
330 | COLOR(LOGOCOLOR)); |
375 | COLOR(LOGOCOLOR)); |
331 | } |
376 | } |
332 | } |
377 | } |
333 | 378 | ||
334 | /***************************************************************/ |
379 | /***************************************************************/ |
335 | /* Stdout specific functions */ |
380 | /* Stdout specific functions */ |
336 | 381 | ||
337 | static void invert_cursor(void) |
382 | static void invert_cursor(void) |
338 | { |
383 | { |
339 | invert_char(position % columns, position / columns); |
384 | invert_char(position % columns, position / columns); |
340 | } |
385 | } |
341 | 386 | ||
342 | /** Print character to screen |
387 | /** Print character to screen |
343 | * |
388 | * |
344 | * Emulate basic terminal commands |
389 | * Emulate basic terminal commands |
345 | */ |
390 | */ |
346 | static void fb_putchar(chardev_t *dev, char ch) |
391 | static void fb_putchar(chardev_t *dev, char ch) |
347 | { |
392 | { |
348 | spinlock_lock(&fb_lock); |
393 | spinlock_lock(&fb_lock); |
349 | 394 | ||
350 | switch (ch) { |
395 | switch (ch) { |
351 | case '\n': |
396 | case '\n': |
352 | invert_cursor(); |
397 | invert_cursor(); |
353 | position += columns; |
398 | position += columns; |
354 | position -= position % columns; |
399 | position -= position % columns; |
355 | break; |
400 | break; |
356 | case '\r': |
401 | case '\r': |
357 | invert_cursor(); |
402 | invert_cursor(); |
358 | position -= position % columns; |
403 | position -= position % columns; |
359 | break; |
404 | break; |
360 | case '\b': |
405 | case '\b': |
361 | invert_cursor(); |
406 | invert_cursor(); |
362 | if (position % columns) |
407 | if (position % columns) |
363 | position--; |
408 | position--; |
364 | break; |
409 | break; |
365 | case '\t': |
410 | case '\t': |
366 | invert_cursor(); |
411 | invert_cursor(); |
367 | do { |
412 | do { |
368 | draw_char(' '); |
413 | draw_char(' '); |
369 | position++; |
414 | position++; |
370 | } while ((position % 8) && position < columns * rows); |
415 | } while ((position % 8) && position < columns * rows); |
371 | break; |
416 | break; |
372 | default: |
417 | default: |
373 | draw_char(ch); |
418 | draw_char(ch); |
374 | position++; |
419 | position++; |
375 | } |
420 | } |
376 | 421 | ||
377 | if (position >= columns * rows) { |
422 | if (position >= columns * rows) { |
378 | position -= columns; |
423 | position -= columns; |
379 | scroll_screen(); |
424 | scroll_screen(); |
380 | } |
425 | } |
381 | 426 | ||
382 | invert_cursor(); |
427 | invert_cursor(); |
383 | 428 | ||
384 | spinlock_unlock(&fb_lock); |
429 | spinlock_unlock(&fb_lock); |
385 | } |
430 | } |
386 | 431 | ||
387 | static chardev_t framebuffer; |
432 | static chardev_t framebuffer; |
388 | static chardev_operations_t fb_ops = { |
433 | static chardev_operations_t fb_ops = { |
389 | .write = fb_putchar, |
434 | .write = fb_putchar, |
390 | }; |
435 | }; |
391 | 436 | ||
392 | 437 | ||
393 | /** Initialize framebuffer as a chardev output device |
438 | /** Initialize framebuffer as a chardev output device |
394 | * |
439 | * |
395 | * @param addr Physical address of the framebuffer |
440 | * @param addr Physical address of the framebuffer |
396 | * @param x Screen width in pixels |
441 | * @param x Screen width in pixels |
397 | * @param y Screen height in pixels |
442 | * @param y Screen height in pixels |
398 | * @param scan Bytes per one scanline |
443 | * @param scan Bytes per one scanline |
399 | * @param visual Color model |
444 | * @param visual Color model |
400 | * |
445 | * |
401 | */ |
446 | */ |
402 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, |
447 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, |
403 | unsigned int visual) |
448 | unsigned int visual) |
404 | { |
449 | { |
405 | switch (visual) { |
450 | switch (visual) { |
406 | case VISUAL_INDIRECT_8: |
451 | case VISUAL_INDIRECT_8: |
407 | rgb2scr = rgb_byte8; |
452 | rgb2scr = rgb_byte8; |
408 | scr2rgb = byte8_rgb; |
453 | scr2rgb = byte8_rgb; |
409 | pixelbytes = 1; |
454 | pixelbytes = 1; |
410 | break; |
455 | break; |
411 | case VISUAL_RGB_5_5_5: |
456 | case VISUAL_RGB_5_5_5: |
412 | rgb2scr = rgb_byte555; |
457 | rgb2scr = rgb_byte555; |
413 | scr2rgb = byte555_rgb; |
458 | scr2rgb = byte555_rgb; |
414 | pixelbytes = 2; |
459 | pixelbytes = 2; |
415 | break; |
460 | break; |
416 | case VISUAL_RGB_5_6_5: |
461 | case VISUAL_RGB_5_6_5: |
417 | rgb2scr = rgb_byte565; |
462 | rgb2scr = rgb_byte565; |
418 | scr2rgb = byte565_rgb; |
463 | scr2rgb = byte565_rgb; |
419 | pixelbytes = 2; |
464 | pixelbytes = 2; |
420 | break; |
465 | break; |
421 | case VISUAL_RGB_8_8_8: |
466 | case VISUAL_RGB_8_8_8: |
422 | rgb2scr = rgb_byte888; |
467 | rgb2scr = rgb_byte888; |
423 | scr2rgb = byte888_rgb; |
468 | scr2rgb = byte888_rgb; |
424 | pixelbytes = 3; |
469 | pixelbytes = 3; |
425 | break; |
470 | break; |
426 | case VISUAL_RGB_8_8_8_0: |
471 | case VISUAL_RGB_8_8_8_0: |
427 | rgb2scr = rgb_byte888; |
472 | rgb2scr = rgb_byte888; |
428 | scr2rgb = byte888_rgb; |
473 | scr2rgb = byte888_rgb; |
429 | pixelbytes = 4; |
474 | pixelbytes = 4; |
430 | break; |
475 | break; |
431 | case VISUAL_RGB_0_8_8_8: |
476 | case VISUAL_RGB_0_8_8_8: |
432 | rgb2scr = rgb_byte0888; |
477 | rgb2scr = rgb_byte0888; |
433 | scr2rgb = byte0888_rgb; |
478 | scr2rgb = byte0888_rgb; |
434 | pixelbytes = 4; |
479 | pixelbytes = 4; |
435 | break; |
480 | break; |
436 | case VISUAL_BGR_0_8_8_8: |
481 | case VISUAL_BGR_0_8_8_8: |
437 | rgb2scr = bgr_byte0888; |
482 | rgb2scr = bgr_byte0888; |
438 | scr2rgb = byte0888_bgr; |
483 | scr2rgb = byte0888_bgr; |
439 | pixelbytes = 4; |
484 | pixelbytes = 4; |
440 | break; |
485 | break; |
441 | default: |
486 | default: |
442 | panic("Unsupported visual.\n"); |
487 | panic("Unsupported visual.\n"); |
443 | } |
488 | } |
444 | 489 | ||
445 | unsigned int fbsize = scan * y; |
490 | unsigned int fbsize = scan * y; |
446 | 491 | ||
447 | /* Map the framebuffer */ |
492 | /* Map the framebuffer */ |
448 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
493 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
449 | 494 | ||
450 | xres = x; |
495 | xres = x; |
451 | yres = y; |
496 | yres = y; |
452 | scanline = scan; |
497 | scanline = scan; |
453 | 498 | ||
454 | rows = y / FONT_SCANLINES; |
499 | rows = y / FONT_SCANLINES; |
455 | columns = x / COL_WIDTH; |
500 | columns = x / COL_WIDTH; |
456 | 501 | ||
457 | fb_parea.pbase = (uintptr_t) addr; |
502 | fb_parea.pbase = (uintptr_t) addr; |
458 | fb_parea.vbase = (uintptr_t) fbaddress; |
503 | fb_parea.vbase = (uintptr_t) fbaddress; |
459 | fb_parea.frames = SIZE2FRAMES(fbsize); |
504 | fb_parea.frames = SIZE2FRAMES(fbsize); |
460 | fb_parea.cacheable = false; |
505 | fb_parea.cacheable = false; |
461 | ddi_parea_register(&fb_parea); |
506 | ddi_parea_register(&fb_parea); |
462 | 507 | ||
463 | sysinfo_set_item_val("fb", NULL, true); |
508 | sysinfo_set_item_val("fb", NULL, true); |
464 | sysinfo_set_item_val("fb.kind", NULL, 1); |
509 | sysinfo_set_item_val("fb.kind", NULL, 1); |
465 | sysinfo_set_item_val("fb.width", NULL, xres); |
510 | sysinfo_set_item_val("fb.width", NULL, xres); |
466 | sysinfo_set_item_val("fb.height", NULL, yres); |
511 | sysinfo_set_item_val("fb.height", NULL, yres); |
467 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
512 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
468 | sysinfo_set_item_val("fb.visual", NULL, visual); |
513 | sysinfo_set_item_val("fb.visual", NULL, visual); |
469 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
514 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
470 | sysinfo_set_item_val("fb.address.color", NULL, PAGE_COLOR((uintptr_t) |
515 | sysinfo_set_item_val("fb.address.color", NULL, |
471 | fbaddress)); |
516 | PAGE_COLOR((uintptr_t) fbaddress)); |
472 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
517 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
473 | 518 | ||
474 | /* Allocate double buffer */ |
519 | /* Allocate double buffer */ |
475 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
520 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
476 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
521 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
477 | if (!dbbuffer) |
522 | if (!dbbuffer) |
478 | printf("Failed to allocate scroll buffer.\n"); |
523 | printf("Failed to allocate scroll buffer.\n"); |
479 | dboffset = 0; |
524 | dboffset = 0; |
480 | 525 | ||
481 | /* Initialized blank line */ |
526 | /* Initialized blank line */ |
482 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
527 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
483 | if (!blankline) |
528 | if (!blankline) |
484 | panic("Failed to allocate blank line for framebuffer."); |
529 | panic("Failed to allocate blank line for framebuffer."); |
485 | for (y = 0; y < FONT_SCANLINES; y++) |
530 | for (y = 0; y < FONT_SCANLINES; y++) |
486 | for (x = 0; x < xres; x++) |
531 | for (x = 0; x < xres; x++) |
487 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
532 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
488 | 533 | ||
489 | clear_screen(); |
534 | clear_screen(); |
490 | 535 | ||
491 | /* Update size of screen to match text area */ |
536 | /* Update size of screen to match text area */ |
492 | yres = rows * FONT_SCANLINES; |
537 | yres = rows * FONT_SCANLINES; |
493 | 538 | ||
494 | draw_logo(xres - helenos_width, 0); |
539 | draw_logo(xres - helenos_width, 0); |
495 | invert_cursor(); |
540 | invert_cursor(); |
496 | 541 | ||
497 | chardev_initialize("fb", &framebuffer, &fb_ops); |
542 | chardev_initialize("fb", &framebuffer, &fb_ops); |
498 | stdout = &framebuffer; |
543 | stdout = &framebuffer; |
499 | } |
544 | } |
500 | 545 | ||
501 | /** @} |
546 | /** @} |
502 | */ |
547 | */ |
503 | 548 |