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