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