Subversion Repositories HelenOS

Rev

Rev 3790 | Rev 3876 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3790 Rev 3844
1
/*
1
/*
2
 * Copyright (c) 2008 Martin Decky
2
 * Copyright (c) 2008 Martin Decky
3
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * Copyright (c) 2006 Ondrej Palkovsky
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
/** @addtogroup genarch
30
/** @addtogroup genarch
31
 * @{
31
 * @{
32
 */
32
 */
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <genarch/fb/font-8x16.h>
36
#include <genarch/fb/font-8x16.h>
37
#include <genarch/fb/logo-196x66.h>
37
#include <genarch/fb/logo-196x66.h>
38
#include <genarch/fb/visuals.h>
38
#include <genarch/fb/visuals.h>
39
#include <genarch/fb/fb.h>
39
#include <genarch/fb/fb.h>
40
#include <console/chardev.h>
40
#include <console/chardev.h>
41
#include <console/console.h>
41
#include <console/console.h>
42
#include <sysinfo/sysinfo.h>
42
#include <sysinfo/sysinfo.h>
43
#include <mm/slab.h>
43
#include <mm/slab.h>
44
#include <align.h>
44
#include <align.h>
45
#include <panic.h>
45
#include <panic.h>
46
#include <memstr.h>
46
#include <memstr.h>
47
#include <config.h>
47
#include <config.h>
48
#include <bitops.h>
48
#include <bitops.h>
49
#include <print.h>
49
#include <print.h>
50
#include <ddi/ddi.h>
50
#include <ddi/ddi.h>
51
#include <arch/types.h>
51
#include <arch/types.h>
52
 
52
 
53
SPINLOCK_INITIALIZE(fb_lock);
53
SPINLOCK_INITIALIZE(fb_lock);
54
 
54
 
55
/**< Physical memory area for fb. */
55
/**< Physical memory area for fb. */
56
static parea_t fb_parea;
56
static parea_t fb_parea;
57
 
57
 
58
static uint8_t *fb_addr;
58
static uint8_t *fb_addr;
59
static uint8_t *backbuf;
59
static uint8_t *backbuf;
60
static uint8_t *glyphs;
60
static uint8_t *glyphs;
61
static uint8_t *bgscan;
61
static uint8_t *bgscan;
62
 
62
 
63
static unsigned int xres;
63
static unsigned int xres;
64
static unsigned int yres;
64
static unsigned int yres;
65
 
65
 
66
static unsigned int ylogo;
66
static unsigned int ylogo;
67
static unsigned int ytrim;
67
static unsigned int ytrim;
68
static unsigned int rowtrim;
68
static unsigned int rowtrim;
69
 
69
 
70
static unsigned int scanline;
70
static unsigned int scanline;
71
static unsigned int glyphscanline;
71
static unsigned int glyphscanline;
72
 
72
 
73
static unsigned int pixelbytes;
73
static unsigned int pixelbytes;
74
static unsigned int glyphbytes;
74
static unsigned int glyphbytes;
75
static unsigned int bgscanbytes;
75
static unsigned int bgscanbytes;
76
 
76
 
77
static unsigned int cols;
77
static unsigned int cols;
78
static unsigned int rows;
78
static unsigned int rows;
79
static unsigned int position = 0;
79
static unsigned int position = 0;
80
 
80
 
81
#define BG_COLOR     0x000080
81
#define BG_COLOR     0x000080
82
#define FG_COLOR     0xffff00
82
#define FG_COLOR     0xffff00
83
 
83
 
84
#define CURSOR       219
84
#define CURSOR       219
85
 
85
 
86
#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
86
#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
87
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
87
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
88
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
88
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
89
 
89
 
90
#define COL2X(col)           ((col) * FONT_WIDTH)
90
#define COL2X(col)           ((col) * FONT_WIDTH)
91
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
91
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
92
 
92
 
93
#define X2COL(x)             ((x) / FONT_WIDTH)
93
#define X2COL(x)             ((x) / FONT_WIDTH)
94
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
94
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
95
 
95
 
96
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
96
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
97
#define BB_POS(col, row)     ((row) * cols + (col))
97
#define BB_POS(col, row)     ((row) * cols + (col))
98
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
98
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
99
 
99
 
100
 
100
 
101
static void (*rgb_conv)(void *, uint32_t);
101
static void (*rgb_conv)(void *, uint32_t);
102
 
102
 
103
 
103
 
104
/** ARGB 8:8:8:8 conversion
104
/** ARGB 8:8:8:8 conversion
105
 *
105
 *
106
 */
106
 */
107
static void rgb_0888(void *dst, uint32_t rgb)
107
static void rgb_0888(void *dst, uint32_t rgb)
108
{
108
{
109
    *((uint32_t *) dst) = rgb & 0xffffff;
109
    *((uint32_t *) dst) = rgb & 0xffffff;
110
}
110
}
111
 
111
 
112
 
112
 
113
/** ABGR 8:8:8:8 conversion
113
/** ABGR 8:8:8:8 conversion
114
 *
114
 *
115
 */
115
 */
116
static void bgr_0888(void *dst, uint32_t rgb)
116
static void bgr_0888(void *dst, uint32_t rgb)
117
{
117
{
118
    *((uint32_t *) dst)
118
    *((uint32_t *) dst)
119
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
119
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
120
}
120
}
121
 
121
 
122
 
122
 
123
/** BGR 8:8:8 conversion
123
/** BGR 8:8:8 conversion
124
 *
124
 *
125
 */
125
 */
126
static void rgb_888(void *dst, uint32_t rgb)
126
static void rgb_888(void *dst, uint32_t rgb)
127
{
127
{
128
#if defined(FB_INVERT_ENDIAN)
128
#if defined(FB_INVERT_ENDIAN)
129
    ((uint8_t *) dst)[0] = RED(rgb, 8);
129
    ((uint8_t *) dst)[0] = RED(rgb, 8);
130
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
130
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
131
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
131
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
132
#else
132
#else
133
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
133
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
134
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
134
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
135
    ((uint8_t *) dst)[2] = RED(rgb, 8);
135
    ((uint8_t *) dst)[2] = RED(rgb, 8);
136
#endif
136
#endif
137
}
137
}
138
 
138
 
139
 
139
 
140
/** RGB 5:5:5 conversion
140
/** RGB 5:5:5 conversion
141
 *
141
 *
142
 */
142
 */
143
static void rgb_555(void *dst, uint32_t rgb)
143
static void rgb_555(void *dst, uint32_t rgb)
144
{
144
{
145
    *((uint16_t *) dst)
145
    *((uint16_t *) dst)
146
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
146
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
147
}
147
}
148
 
148
 
149
 
149
 
150
/** RGB 5:6:5 conversion
150
/** RGB 5:6:5 conversion
151
 *
151
 *
152
 */
152
 */
153
static void rgb_565(void *dst, uint32_t rgb)
153
static void rgb_565(void *dst, uint32_t rgb)
154
{
154
{
155
    *((uint16_t *) dst)
155
    *((uint16_t *) dst)
156
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
156
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
157
}
157
}
158
 
158
 
159
 
159
 
160
/** RGB 3:2:3
160
/** RGB 3:2:3
161
 *
161
 *
162
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
162
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
163
 * will most likely use a color palette. The color appearance
163
 * will most likely use a color palette. The color appearance
164
 * will be pretty random and depend on the default installed
164
 * will be pretty random and depend on the default installed
165
 * palette. This could be fixed by supporting custom palette
165
 * palette. This could be fixed by supporting custom palette
166
 * and setting it to simulate the 8-bit truecolor.
166
 * and setting it to simulate the 8-bit truecolor.
167
 *
167
 *
168
 * Currently we set the palette on the ia32, amd64 and sparc64 port.
168
 * Currently we set the palette on the ia32, amd64 and sparc64 port.
169
 *
169
 *
170
 * Note that the byte is being inverted by this function. The reason is
170
 * Note that the byte is being inverted by this function. The reason is
171
 * that we would like to use a color palette where the white color code
171
 * that we would like to use a color palette where the white color code
172
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
172
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
173
 * use these codes for black and white and prevent to set codes
173
 * use these codes for black and white and prevent to set codes
174
 * 0 and 255 to other colors.
174
 * 0 and 255 to other colors.
175
 *
175
 *
176
 */
176
 */
177
static void rgb_323(void *dst, uint32_t rgb)
177
static void rgb_323(void *dst, uint32_t rgb)
178
{
178
{
179
    *((uint8_t *) dst)
179
    *((uint8_t *) dst)
180
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
180
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
181
}
181
}
182
 
182
 
183
 
183
 
184
/** Hide logo and refresh screen
184
/** Hide logo and refresh screen
185
 *
185
 *
186
 */
186
 */
187
static void logo_hide(void)
187
static void logo_hide(bool silent)
188
{
188
{
189
    ylogo = 0;
189
    ylogo = 0;
190
    ytrim = yres;
190
    ytrim = yres;
191
    rowtrim = rows;
191
    rowtrim = rows;
-
 
192
    if (!silent)
192
    fb_redraw();
193
        fb_redraw();
193
}
194
}
194
 
195
 
195
 
196
 
196
/** Draw character at given position
197
/** Draw character at given position
197
 *
198
 *
198
 */
199
 */
199
static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row)
200
static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row, bool silent)
200
{
201
{
201
    unsigned int x = COL2X(col);
202
    unsigned int x = COL2X(col);
202
    unsigned int y = ROW2Y(row);
203
    unsigned int y = ROW2Y(row);
203
    unsigned int yd;
204
    unsigned int yd;
204
   
205
   
205
    if (y >= ytrim)
206
    if (y >= ytrim)
206
        logo_hide();
207
        logo_hide(silent);
207
   
208
   
208
    backbuf[BB_POS(col, row)] = glyph;
209
    backbuf[BB_POS(col, row)] = glyph;
209
   
210
   
-
 
211
    if (!silent) {
210
    for (yd = 0; yd < FONT_SCANLINES; yd++)
212
        for (yd = 0; yd < FONT_SCANLINES; yd++)
211
        memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)],
213
            memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)],
212
            &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
214
                &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
-
 
215
    }
213
}
216
}
214
 
217
 
215
 
218
 
216
/** Scroll screen down by one row
219
/** Scroll screen down by one row
217
 *
220
 *
218
 *
221
 *
219
 */
222
 */
220
static void screen_scroll(void)
223
static void screen_scroll(bool silent)
221
{
224
{
222
    if (ylogo > 0) {
225
    if (ylogo > 0) {
223
        logo_hide();
226
        logo_hide(silent);
224
        return;
227
        return;
225
    }
228
    }
226
   
229
   
227
    unsigned int row;
230
    if (!silent) {
228
   
-
 
229
    for (row = 0; row < rows; row++) {
-
 
230
        unsigned int y = ROW2Y(row);
-
 
231
        unsigned int yd;
231
        unsigned int row;
232
       
232
       
233
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
233
        for (row = 0; row < rows; row++) {
234
            unsigned int x;
234
            unsigned int y = ROW2Y(row);
235
            unsigned int col;
235
            unsigned int yd;
236
           
236
           
237
            for (col = 0, x = 0; col < cols; col++,
237
            for (yd = 0; yd < FONT_SCANLINES; yd++) {
238
                x += FONT_WIDTH) {
238
                unsigned int x;
239
                uint8_t glyph;
239
                unsigned int col;
240
               
240
               
241
                if (row < rows - 1) {
-
 
242
                    if (backbuf[BB_POS(col, row)] ==
241
                for (col = 0, x = 0; col < cols; col++,
243
                        backbuf[BB_POS(col, row + 1)])
242
                    x += FONT_WIDTH) {
244
                        continue;
243
                    uint8_t glyph;
245
                   
244
                   
-
 
245
                    if (row < rows - 1) {
-
 
246
                        if (backbuf[BB_POS(col, row)] ==
-
 
247
                            backbuf[BB_POS(col, row + 1)])
-
 
248
                            continue;
-
 
249
                       
246
                    glyph = backbuf[BB_POS(col, row + 1)];
250
                        glyph = backbuf[BB_POS(col, row + 1)];
247
                } else
251
                    } else
248
                    glyph = 0;
252
                        glyph = 0;
249
               
253
                   
250
                memcpy(&fb_addr[FB_POS(x, y + yd)],
254
                    memcpy(&fb_addr[FB_POS(x, y + yd)],
251
                    &glyphs[GLYPH_POS(glyph, yd)],
255
                        &glyphs[GLYPH_POS(glyph, yd)],
252
                    glyphscanline);
256
                        glyphscanline);
-
 
257
                }
253
            }
258
            }
254
        }
259
        }
255
    }
260
    }
256
   
261
   
257
    memmove(backbuf, backbuf + cols, cols * (rows - 1));
262
    memmove(backbuf, backbuf + cols, cols * (rows - 1));
258
    memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
263
    memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
259
}
264
}
260
 
265
 
261
 
266
 
262
static void cursor_put(void)
267
static void cursor_put(bool silent)
263
{
268
{
264
    glyph_draw(CURSOR, position % cols, position / cols);
269
    glyph_draw(CURSOR, position % cols, position / cols, silent);
265
}
270
}
266
 
271
 
267
 
272
 
268
static void cursor_remove(void)
273
static void cursor_remove(bool silent)
269
{
274
{
270
    glyph_draw(0, position % cols, position / cols);
275
    glyph_draw(0, position % cols, position / cols, silent);
271
}
276
}
272
 
277
 
273
 
278
 
274
/** Print character to screen
279
/** Print character to screen
275
 *
280
 *
276
 * Emulate basic terminal commands.
281
 * Emulate basic terminal commands.
277
 *
282
 *
278
 */
283
 */
279
static void fb_putchar(chardev_t *dev, char ch)
284
static void fb_putchar(chardev_t *dev, char ch, bool silent)
280
{
285
{
281
    spinlock_lock(&fb_lock);
286
    spinlock_lock(&fb_lock);
282
   
287
   
283
    switch (ch) {
288
    switch (ch) {
284
    case '\n':
289
    case '\n':
285
        cursor_remove();
290
        cursor_remove(silent);
286
        position += cols;
291
        position += cols;
287
        position -= position % cols;
292
        position -= position % cols;
288
        break;
293
        break;
289
    case '\r':
294
    case '\r':
290
        cursor_remove();
295
        cursor_remove(silent);
291
        position -= position % cols;
296
        position -= position % cols;
292
        break;
297
        break;
293
    case '\b':
298
    case '\b':
294
        cursor_remove();
299
        cursor_remove(silent);
295
        if (position % cols)
300
        if (position % cols)
296
            position--;
301
            position--;
297
        break;
302
        break;
298
    case '\t':
303
    case '\t':
299
        cursor_remove();
304
        cursor_remove(silent);
300
        do {
305
        do {
301
            glyph_draw((uint8_t) ' ', position % cols,
306
            glyph_draw((uint8_t) ' ', position % cols,
302
                position / cols);
307
                position / cols, silent);
303
            position++;
308
            position++;
304
        } while ((position % 8) && (position < cols * rows));
309
        } while ((position % 8) && (position < cols * rows));
305
        break;
310
        break;
306
    default:
311
    default:
307
        glyph_draw((uint8_t) ch, position % cols, position / cols);
312
        glyph_draw((uint8_t) ch, position % cols,
-
 
313
            position / cols, silent);
308
        position++;
314
        position++;
309
    }
315
    }
310
   
316
   
311
    if (position >= cols * rows) {
317
    if (position >= cols * rows) {
312
        position -= cols;
318
        position -= cols;
313
        screen_scroll();
319
        screen_scroll(silent);
314
    }
320
    }
315
   
321
   
316
    cursor_put();
322
    cursor_put(silent);
317
   
323
   
318
    spinlock_unlock(&fb_lock);
324
    spinlock_unlock(&fb_lock);
319
}
325
}
320
 
326
 
321
static chardev_t framebuffer;
327
static chardev_t framebuffer;
322
static chardev_operations_t fb_ops = {
328
static chardev_operations_t fb_ops = {
323
    .write = fb_putchar,
329
    .write = fb_putchar,
324
};
330
};
325
 
331
 
326
 
332
 
327
/** Render glyphs
333
/** Render glyphs
328
 *
334
 *
329
 * Convert glyphs from device independent font
335
 * Convert glyphs from device independent font
330
 * description to current visual representation.
336
 * description to current visual representation.
331
 *
337
 *
332
 */
338
 */
333
static void glyphs_render(void)
339
static void glyphs_render(void)
334
{
340
{
335
    /* Prerender glyphs */
341
    /* Prerender glyphs */
336
    unsigned int glyph;
342
    unsigned int glyph;
337
   
343
   
338
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
344
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
339
        unsigned int y;
345
        unsigned int y;
340
       
346
       
341
        for (y = 0; y < FONT_SCANLINES; y++) {
347
        for (y = 0; y < FONT_SCANLINES; y++) {
342
            unsigned int x;
348
            unsigned int x;
343
           
349
           
344
            for (x = 0; x < FONT_WIDTH; x++) {
350
            for (x = 0; x < FONT_WIDTH; x++) {
345
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
351
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
346
                    x * pixelbytes];
352
                    x * pixelbytes];
347
                uint32_t rgb = (fb_font[ROW2Y(glyph) + y] &
353
                uint32_t rgb = (fb_font[ROW2Y(glyph) + y] &
348
                    (1 << (7 - x))) ? FG_COLOR : BG_COLOR;
354
                    (1 << (7 - x))) ? FG_COLOR : BG_COLOR;
349
                rgb_conv(dst, rgb);
355
                rgb_conv(dst, rgb);
350
            }
356
            }
351
        }
357
        }
352
    }
358
    }
353
   
359
   
354
    /* Prerender background scanline */
360
    /* Prerender background scanline */
355
    unsigned int x;
361
    unsigned int x;
356
   
362
   
357
    for (x = 0; x < xres; x++)
363
    for (x = 0; x < xres; x++)
358
        rgb_conv(&bgscan[x * pixelbytes], BG_COLOR);
364
        rgb_conv(&bgscan[x * pixelbytes], BG_COLOR);
359
}
365
}
360
 
366
 
361
 
367
 
362
/** Refresh the screen
368
/** Refresh the screen
363
 *
369
 *
364
 */
370
 */
365
void fb_redraw(void)
371
void fb_redraw(void)
366
{
372
{
367
    if (ylogo > 0) {
373
    if (ylogo > 0) {
368
        unsigned int y;
374
        unsigned int y;
369
       
375
       
370
        for (y = 0; y < LOGO_HEIGHT; y++) {
376
        for (y = 0; y < LOGO_HEIGHT; y++) {
371
            unsigned int x;
377
            unsigned int x;
372
           
378
           
373
            for (x = 0; x < xres; x++)
379
            for (x = 0; x < xres; x++)
374
                rgb_conv(&fb_addr[FB_POS(x, y)],
380
                rgb_conv(&fb_addr[FB_POS(x, y)],
375
                    (x < LOGO_WIDTH) ?
381
                    (x < LOGO_WIDTH) ?
376
                    fb_logo[y * LOGO_WIDTH + x] :
382
                    fb_logo[y * LOGO_WIDTH + x] :
377
                    LOGO_COLOR);
383
                    LOGO_COLOR);
378
        }
384
        }
379
    }
385
    }
380
   
386
   
381
    unsigned int row;
387
    unsigned int row;
382
   
388
   
383
    for (row = 0; row < rowtrim; row++) {
389
    for (row = 0; row < rowtrim; row++) {
384
        unsigned int y = ylogo + ROW2Y(row);
390
        unsigned int y = ylogo + ROW2Y(row);
385
        unsigned int yd;
391
        unsigned int yd;
386
       
392
       
387
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
393
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
388
            unsigned int x;
394
            unsigned int x;
389
            unsigned int col;
395
            unsigned int col;
390
           
396
           
391
            for (col = 0, x = 0; col < cols;
397
            for (col = 0, x = 0; col < cols;
392
                col++, x += FONT_WIDTH) {
398
                col++, x += FONT_WIDTH) {
393
                void *d = &fb_addr[FB_POS(x, y + yd)];
399
                void *d = &fb_addr[FB_POS(x, y + yd)];
394
                void *s = &glyphs[GLYPH_POS(backbuf[BB_POS(col,
400
                void *s = &glyphs[GLYPH_POS(backbuf[BB_POS(col,
395
                    row)], yd)];
401
                    row)], yd)];
396
                memcpy(d, s, glyphscanline);
402
                memcpy(d, s, glyphscanline);
397
            }
403
            }
398
        }
404
        }
399
    }
405
    }
400
   
406
   
401
    if (COL2X(cols) < xres) {
407
    if (COL2X(cols) < xres) {
402
        unsigned int y;
408
        unsigned int y;
403
        unsigned int size = (xres - COL2X(cols)) * pixelbytes;
409
        unsigned int size = (xres - COL2X(cols)) * pixelbytes;
404
       
410
       
405
        for (y = ylogo; y < yres; y++)
411
        for (y = ylogo; y < yres; y++)
406
            memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size);
412
            memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size);
407
    }
413
    }
408
   
414
   
409
    if (ROW2Y(rowtrim) + ylogo < yres) {
415
    if (ROW2Y(rowtrim) + ylogo < yres) {
410
        unsigned int y;
416
        unsigned int y;
411
       
417
       
412
        for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++)
418
        for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++)
413
            memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes);
419
            memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes);
414
    }
420
    }
415
}
421
}
416
 
422
 
417
 
423
 
418
/** Initialize framebuffer as a chardev output device
424
/** Initialize framebuffer as a chardev output device
419
 *
425
 *
420
 * @param addr   Physical address of the framebuffer
426
 * @param addr   Physical address of the framebuffer
421
 * @param x      Screen width in pixels
427
 * @param x      Screen width in pixels
422
 * @param y      Screen height in pixels
428
 * @param y      Screen height in pixels
423
 * @param scan   Bytes per one scanline
429
 * @param scan   Bytes per one scanline
424
 * @param visual Color model
430
 * @param visual Color model
425
 *
431
 *
426
 */
432
 */
427
void fb_init(fb_properties_t *props)
433
void fb_init(fb_properties_t *props)
428
{
434
{
429
    switch (props->visual) {
435
    switch (props->visual) {
430
    case VISUAL_INDIRECT_8:
436
    case VISUAL_INDIRECT_8:
431
        rgb_conv = rgb_323;
437
        rgb_conv = rgb_323;
432
        pixelbytes = 1;
438
        pixelbytes = 1;
433
        break;
439
        break;
434
    case VISUAL_RGB_5_5_5:
440
    case VISUAL_RGB_5_5_5:
435
        rgb_conv = rgb_555;
441
        rgb_conv = rgb_555;
436
        pixelbytes = 2;
442
        pixelbytes = 2;
437
        break;
443
        break;
438
    case VISUAL_RGB_5_6_5:
444
    case VISUAL_RGB_5_6_5:
439
        rgb_conv = rgb_565;
445
        rgb_conv = rgb_565;
440
        pixelbytes = 2;
446
        pixelbytes = 2;
441
        break;
447
        break;
442
    case VISUAL_RGB_8_8_8:
448
    case VISUAL_RGB_8_8_8:
443
        rgb_conv = rgb_888;
449
        rgb_conv = rgb_888;
444
        pixelbytes = 3;
450
        pixelbytes = 3;
445
        break;
451
        break;
446
    case VISUAL_RGB_8_8_8_0:
452
    case VISUAL_RGB_8_8_8_0:
447
        rgb_conv = rgb_888;
453
        rgb_conv = rgb_888;
448
        pixelbytes = 4;
454
        pixelbytes = 4;
449
        break;
455
        break;
450
    case VISUAL_RGB_0_8_8_8:
456
    case VISUAL_RGB_0_8_8_8:
451
        rgb_conv = rgb_0888;
457
        rgb_conv = rgb_0888;
452
        pixelbytes = 4;
458
        pixelbytes = 4;
453
        break;
459
        break;
454
    case VISUAL_BGR_0_8_8_8:
460
    case VISUAL_BGR_0_8_8_8:
455
        rgb_conv = bgr_0888;
461
        rgb_conv = bgr_0888;
456
        pixelbytes = 4;
462
        pixelbytes = 4;
457
        break;
463
        break;
458
    default:
464
    default:
459
        panic("Unsupported visual.");
465
        panic("Unsupported visual.");
460
    }
466
    }
461
   
467
   
462
    xres = props->x;
468
    xres = props->x;
463
    yres = props->y;
469
    yres = props->y;
464
    scanline = props->scan;
470
    scanline = props->scan;
465
   
471
   
466
    cols = X2COL(xres);
472
    cols = X2COL(xres);
467
    rows = Y2ROW(yres);
473
    rows = Y2ROW(yres);
468
   
474
   
469
    if (yres > ylogo) {
475
    if (yres > ylogo) {
470
        ylogo = LOGO_HEIGHT;
476
        ylogo = LOGO_HEIGHT;
471
        rowtrim = rows - Y2ROW(ylogo);
477
        rowtrim = rows - Y2ROW(ylogo);
472
        if (ylogo % FONT_SCANLINES > 0)
478
        if (ylogo % FONT_SCANLINES > 0)
473
            rowtrim--;
479
            rowtrim--;
474
        ytrim = ROW2Y(rowtrim);
480
        ytrim = ROW2Y(rowtrim);
475
    } else {
481
    } else {
476
        ylogo = 0;
482
        ylogo = 0;
477
        ytrim = yres;
483
        ytrim = yres;
478
        rowtrim = rows;
484
        rowtrim = rows;
479
    }
485
    }
480
   
486
   
481
    glyphscanline = FONT_WIDTH * pixelbytes;
487
    glyphscanline = FONT_WIDTH * pixelbytes;
482
    glyphbytes = ROW2Y(glyphscanline);
488
    glyphbytes = ROW2Y(glyphscanline);
483
    bgscanbytes = xres * pixelbytes;
489
    bgscanbytes = xres * pixelbytes;
484
   
490
   
485
    unsigned int fbsize = scanline * yres;
491
    unsigned int fbsize = scanline * yres;
486
    unsigned int bbsize = cols * rows;
492
    unsigned int bbsize = cols * rows;
487
    unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
493
    unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
488
   
494
   
489
    backbuf = (uint8_t *) malloc(bbsize, 0);
495
    backbuf = (uint8_t *) malloc(bbsize, 0);
490
    if (!backbuf)
496
    if (!backbuf)
491
        panic("Unable to allocate backbuffer.");
497
        panic("Unable to allocate backbuffer.");
492
   
498
   
493
    glyphs = (uint8_t *) malloc(glyphsize, 0);
499
    glyphs = (uint8_t *) malloc(glyphsize, 0);
494
    if (!glyphs)
500
    if (!glyphs)
495
        panic("Unable to allocate glyphs.");
501
        panic("Unable to allocate glyphs.");
496
   
502
   
497
    bgscan = malloc(bgscanbytes, 0);
503
    bgscan = malloc(bgscanbytes, 0);
498
    if (!bgscan)
504
    if (!bgscan)
499
        panic("Unable to allocate background pixel.");
505
        panic("Unable to allocate background pixel.");
500
   
506
   
501
    memsetb(backbuf, bbsize, 0);
507
    memsetb(backbuf, bbsize, 0);
502
   
508
   
503
    glyphs_render();
509
    glyphs_render();
504
   
510
   
505
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
511
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
506
   
512
   
507
    fb_parea.pbase = (uintptr_t) props->addr + props->offset;
513
    fb_parea.pbase = (uintptr_t) props->addr + props->offset;
508
    fb_parea.vbase = (uintptr_t) fb_addr;
514
    fb_parea.vbase = (uintptr_t) fb_addr;
509
    fb_parea.frames = SIZE2FRAMES(fbsize);
515
    fb_parea.frames = SIZE2FRAMES(fbsize);
510
    fb_parea.cacheable = false;
516
    fb_parea.cacheable = false;
511
    ddi_parea_register(&fb_parea);
517
    ddi_parea_register(&fb_parea);
512
   
518
   
513
    sysinfo_set_item_val("fb", NULL, true);
519
    sysinfo_set_item_val("fb", NULL, true);
514
    sysinfo_set_item_val("fb.kind", NULL, 1);
520
    sysinfo_set_item_val("fb.kind", NULL, 1);
515
    sysinfo_set_item_val("fb.width", NULL, xres);
521
    sysinfo_set_item_val("fb.width", NULL, xres);
516
    sysinfo_set_item_val("fb.height", NULL, yres);
522
    sysinfo_set_item_val("fb.height", NULL, yres);
517
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
523
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
518
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
524
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
519
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
525
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
520
   
526
   
521
    fb_redraw();
527
    fb_redraw();
522
   
528
   
523
    chardev_initialize("fb", &framebuffer, &fb_ops);
529
    chardev_initialize("fb", &framebuffer, &fb_ops);
524
    stdout = &framebuffer;
530
    stdout = &framebuffer;
525
}
531
}
526
 
532
 
527
/** @}
533
/** @}
528
 */
534
 */
529
 
535