Subversion Repositories HelenOS

Rev

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

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