Subversion Repositories HelenOS

Rev

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

Rev 3707 Rev 3709
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/visuals.h>
37
#include <genarch/fb/visuals.h>
38
#include <genarch/fb/fb.h>
38
#include <genarch/fb/fb.h>
39
#include <console/chardev.h>
39
#include <console/chardev.h>
40
#include <console/console.h>
40
#include <console/console.h>
41
#include <sysinfo/sysinfo.h>
41
#include <sysinfo/sysinfo.h>
42
#include <mm/slab.h>
42
#include <mm/slab.h>
43
#include <align.h>
43
#include <align.h>
44
#include <panic.h>
44
#include <panic.h>
45
#include <memstr.h>
45
#include <memstr.h>
46
#include <config.h>
46
#include <config.h>
47
#include <bitops.h>
47
#include <bitops.h>
48
#include <print.h>
48
#include <print.h>
49
#include <ddi/ddi.h>
49
#include <ddi/ddi.h>
50
#include <arch/types.h>
50
#include <arch/types.h>
51
 
51
 
52
SPINLOCK_INITIALIZE(fb_lock);
52
SPINLOCK_INITIALIZE(fb_lock);
53
 
53
 
54
/**< Physical memory area for fb. */
54
/**< Physical memory area for fb. */
55
static parea_t fb_parea;
55
static parea_t fb_parea;
56
 
56
 
57
static uint8_t *fb_addr;
57
static uint8_t *fb_addr;
58
static uint8_t *backbuf;
58
static uint8_t *backbuf;
59
static uint8_t *glyphs;
59
static uint8_t *glyphs;
60
 
60
 
61
static void *bgpixel;
61
static void *bgpixel;
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 scanline;
66
static unsigned int scanline;
67
static unsigned int glyphscanline;
67
static unsigned int glyphscanline;
68
 
68
 
69
static unsigned int pixelbytes;
69
static unsigned int pixelbytes;
70
static unsigned int glyphbytes;
70
static unsigned int glyphbytes;
71
 
71
 
72
static unsigned int cols;
72
static unsigned int cols;
73
static unsigned int rows;
73
static unsigned int rows;
74
static unsigned int position = 0;
74
static unsigned int position = 0;
75
 
75
 
76
#define BG_COLOR     0x000080
76
#define BG_COLOR     0x000080
77
#define FG_COLOR     0xffff00
77
#define FG_COLOR     0xffff00
78
 
78
 
79
#define CURSOR       219
79
#define CURSOR       219
80
 
80
 
81
#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))
82
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
82
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
83
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
83
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
84
 
84
 
85
#define COL2X(col)           ((col) * FONT_WIDTH)
85
#define COL2X(col)           ((col) * FONT_WIDTH)
86
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
86
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
87
 
87
 
88
#define X2COL(x)             ((x) / FONT_WIDTH)
88
#define X2COL(x)             ((x) / FONT_WIDTH)
89
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
89
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
90
 
90
 
91
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
91
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
92
#define BB_POS(col, row)     ((row) * cols + (col))
92
#define BB_POS(col, row)     ((row) * cols + (col))
93
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
93
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
94
 
94
 
95
 
95
 
96
static void (*rgb_conv)(void *, uint32_t);
96
static void (*rgb_conv)(void *, uint32_t);
97
 
97
 
98
 
98
 
99
/** ARGB 8:8:8:8 conversion
99
/** ARGB 8:8:8:8 conversion
100
 *
100
 *
101
 */
101
 */
102
static void rgb_0888(void *dst, uint32_t rgb)
102
static void rgb_0888(void *dst, uint32_t rgb)
103
{
103
{
104
    *((uint32_t *) dst) = rgb & 0xffffff;
104
    *((uint32_t *) dst) = rgb & 0xffffff;
105
}
105
}
106
 
106
 
107
 
107
 
108
/** ABGR 8:8:8:8 conversion
108
/** ABGR 8:8:8:8 conversion
109
 *
109
 *
110
 */
110
 */
111
static void bgr_0888(void *dst, uint32_t rgb)
111
static void bgr_0888(void *dst, uint32_t rgb)
112
{
112
{
113
    *((uint32_t *) dst)
113
    *((uint32_t *) dst)
114
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
114
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
115
}
115
}
116
 
116
 
117
 
117
 
118
/** BGR 8:8:8 conversion
118
/** BGR 8:8:8 conversion
119
 *
119
 *
120
 */
120
 */
121
static void rgb_888(void *dst, uint32_t rgb)
121
static void rgb_888(void *dst, uint32_t rgb)
122
{
122
{
123
#if defined(FB_INVERT_ENDIAN)
123
#if defined(FB_INVERT_ENDIAN)
124
    *((uint32_t *) dst)
124
    *((uint32_t *) dst)
125
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8)
125
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8)
126
        | (*((uint32_t *) dst) & 0xff0000);
126
        | (*((uint32_t *) dst) & 0xff0000);
127
#else
127
#else
128
    *((uint32_t *) dst)
128
    *((uint32_t *) dst)
129
        = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000);
129
        = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000);
130
#endif
130
#endif
131
}
131
}
132
 
132
 
133
 
133
 
134
/** RGB 5:5:5 conversion
134
/** RGB 5:5:5 conversion
135
 *
135
 *
136
 */
136
 */
137
static void rgb_555(void *dst, uint32_t rgb)
137
static void rgb_555(void *dst, uint32_t rgb)
138
{
138
{
139
    *((uint16_t *) dst)
139
    *((uint16_t *) dst)
140
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
140
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
141
}
141
}
142
 
142
 
143
 
143
 
144
/** RGB 5:6:5 conversion
144
/** RGB 5:6:5 conversion
145
 *
145
 *
146
 */
146
 */
147
static void rgb_565(void *dst, uint32_t rgb)
147
static void rgb_565(void *dst, uint32_t rgb)
148
{
148
{
149
    *((uint16_t *) dst)
149
    *((uint16_t *) dst)
150
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
150
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
151
}
151
}
152
 
152
 
153
 
153
 
154
/** RGB 3:2:3
154
/** RGB 3:2:3
155
 *
155
 *
156
 * 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
157
 * will most likely use a color palette. The color appearance
157
 * will most likely use a color palette. The color appearance
158
 * will be pretty random and depend on the default installed
158
 * will be pretty random and depend on the default installed
159
 * palette. This could be fixed by supporting custom palette
159
 * palette. This could be fixed by supporting custom palette
160
 * and setting it to simulate the 8-bit truecolor.
160
 * and setting it to simulate the 8-bit truecolor.
161
 *
161
 *
162
 * Currently we set the palette on the ia32 and sparc64 port.
162
 * Currently we set the palette on the ia32, amd64 and sparc64 port.
163
 *
163
 *
164
 * 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
165
 * 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
166
 * 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 (Sun Blade 1500)
167
 * 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
168
 * 0 and 255 to other colors.
168
 * 0 and 255 to other colors.
-
 
169
 *
169
 */
170
 */
170
static void rgb_323(void *dst, uint32_t rgb)
171
static void rgb_323(void *dst, uint32_t rgb)
171
{
172
{
172
    *((uint8_t *) dst)
173
    *((uint8_t *) dst)
173
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
174
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
174
}
175
}
175
 
176
 
176
 
177
 
177
/** Draw character at given position
178
/** Draw character at given position
178
 *
179
 *
179
 */
180
 */
180
static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
181
static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
181
{
182
{
182
    unsigned int x = COL2X(col);
183
    unsigned int x = COL2X(col);
183
    unsigned int y = ROW2Y(row);
184
    unsigned int y = ROW2Y(row);
184
    unsigned int yd;
185
    unsigned int yd;
185
   
186
   
186
    backbuf[BB_POS(col, row)] = glyph;
187
    backbuf[BB_POS(col, row)] = glyph;
187
   
188
   
188
    for (yd = 0; yd < FONT_SCANLINES; yd++)
189
    for (yd = 0; yd < FONT_SCANLINES; yd++)
189
        memcpy(&fb_addr[FB_POS(x, y + yd)],
190
        memcpy(&fb_addr[FB_POS(x, y + yd)],
190
            &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
191
            &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
191
}
192
}
192
 
193
 
193
 
194
 
194
/** Scroll screen down by one row
195
/** Scroll screen down by one row
195
 *
196
 *
196
 *
197
 *
197
 */
198
 */
198
static void scroll_screen(void)
199
static void scroll_screen(void)
199
{
200
{
200
    unsigned int row;
201
    unsigned int row;
201
   
202
   
202
    for (row = 0; row < rows; row++) {
203
    for (row = 0; row < rows; row++) {
203
        unsigned int y = ROW2Y(row);
204
        unsigned int y = ROW2Y(row);
204
        unsigned int yd;
205
        unsigned int yd;
205
       
206
       
206
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
207
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
207
            unsigned int x;
208
            unsigned int x;
208
            unsigned int col;
209
            unsigned int col;
209
           
210
           
210
            for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) {
211
            for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) {
211
                uint8_t glyph;
212
                uint8_t glyph;
212
               
213
               
213
                if (row < rows - 1) {
214
                if (row < rows - 1) {
214
                    if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)])
215
                    if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)])
215
                        continue;
216
                        continue;
216
                   
217
                   
217
                    glyph = backbuf[BB_POS(col, row + 1)];
218
                    glyph = backbuf[BB_POS(col, row + 1)];
218
                } else
219
                } else
219
                    glyph = 0;
220
                    glyph = 0;
220
               
221
               
221
                memcpy(&fb_addr[FB_POS(x, y + yd)],
222
                memcpy(&fb_addr[FB_POS(x, y + yd)],
222
                    &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
223
                    &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
223
            }
224
            }
224
        }
225
        }
225
    }
226
    }
226
   
227
   
227
    memcpy(backbuf, backbuf + cols, cols * (rows - 1));
228
    memcpy(backbuf, backbuf + cols, cols * (rows - 1));
228
    memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
229
    memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
229
}
230
}
230
 
231
 
231
 
232
 
232
static void cursor_put(void)
233
static void cursor_put(void)
233
{
234
{
234
    draw_glyph(CURSOR, position % cols, position / cols);
235
    draw_glyph(CURSOR, position % cols, position / cols);
235
}
236
}
236
 
237
 
237
 
238
 
238
static void cursor_remove(void)
239
static void cursor_remove(void)
239
{
240
{
240
    draw_glyph(0, position % cols, position / cols);
241
    draw_glyph(0, position % cols, position / cols);
241
}
242
}
242
 
243
 
243
 
244
 
244
/** Print character to screen
245
/** Print character to screen
245
 *
246
 *
246
 * Emulate basic terminal commands.
247
 * Emulate basic terminal commands.
247
 *
248
 *
248
 */
249
 */
249
static void fb_putchar(chardev_t *dev, char ch)
250
static void fb_putchar(chardev_t *dev, char ch)
250
{
251
{
251
    spinlock_lock(&fb_lock);
252
    spinlock_lock(&fb_lock);
252
   
253
   
253
    switch (ch) {
254
    switch (ch) {
254
    case '\n':
255
    case '\n':
255
        cursor_remove();
256
        cursor_remove();
256
        position += cols;
257
        position += cols;
257
        position -= position % cols;
258
        position -= position % cols;
258
        break;
259
        break;
259
    case '\r':
260
    case '\r':
260
        cursor_remove();
261
        cursor_remove();
261
        position -= position % cols;
262
        position -= position % cols;
262
        break;
263
        break;
263
    case '\b':
264
    case '\b':
264
        cursor_remove();
265
        cursor_remove();
265
        if (position % cols)
266
        if (position % cols)
266
            position--;
267
            position--;
267
        break;
268
        break;
268
    case '\t':
269
    case '\t':
269
        cursor_remove();
270
        cursor_remove();
270
        do {
271
        do {
271
            draw_glyph((uint8_t) ' ', position % cols, position / cols);
272
            draw_glyph((uint8_t) ' ', position % cols, position / cols);
272
            position++;
273
            position++;
273
        } while ((position % 8) && (position < cols * rows));
274
        } while ((position % 8) && (position < cols * rows));
274
        break;
275
        break;
275
    default:
276
    default:
276
        draw_glyph((uint8_t) ch, position % cols, position / cols);
277
        draw_glyph((uint8_t) ch, position % cols, position / cols);
277
        position++;
278
        position++;
278
    }
279
    }
279
   
280
   
280
    if (position >= cols * rows) {
281
    if (position >= cols * rows) {
281
        position -= cols;
282
        position -= cols;
282
        scroll_screen();
283
        scroll_screen();
283
    }
284
    }
284
   
285
   
285
    cursor_put();
286
    cursor_put();
286
   
287
   
287
    spinlock_unlock(&fb_lock);
288
    spinlock_unlock(&fb_lock);
288
}
289
}
289
 
290
 
290
static chardev_t framebuffer;
291
static chardev_t framebuffer;
291
static chardev_operations_t fb_ops = {
292
static chardev_operations_t fb_ops = {
292
    .write = fb_putchar,
293
    .write = fb_putchar,
293
};
294
};
294
 
295
 
295
 
296
 
296
/** Render glyphs
297
/** Render glyphs
297
 *
298
 *
298
 * Convert glyphs from device independent font
299
 * Convert glyphs from device independent font
299
 * description to current visual representation.
300
 * description to current visual representation.
300
 *
301
 *
301
 */
302
 */
302
static void render_glyphs(void)
303
static void render_glyphs(void)
303
{
304
{
304
    unsigned int glyph;
305
    unsigned int glyph;
305
   
306
   
306
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
307
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
307
        unsigned int y;
308
        unsigned int y;
308
       
309
       
309
        for (y = 0; y < FONT_SCANLINES; y++) {
310
        for (y = 0; y < FONT_SCANLINES; y++) {
310
            unsigned int x;
311
            unsigned int x;
311
           
312
           
312
            for (x = 0; x < FONT_WIDTH; x++)
313
            for (x = 0; x < FONT_WIDTH; x++)
313
                rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes],
314
                rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes],
314
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR);
315
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR);
315
        }
316
        }
316
    }
317
    }
317
   
318
   
318
    rgb_conv(bgpixel, BG_COLOR);
319
    rgb_conv(bgpixel, BG_COLOR);
319
}
320
}
320
 
321
 
321
 
322
 
322
/** Refresh the screen
323
/** Refresh the screen
323
 *
324
 *
324
 */
325
 */
325
void fb_redraw(void)
326
void fb_redraw(void)
326
{
327
{
327
    unsigned int row;
328
    unsigned int row;
328
   
329
   
329
    for (row = 0; row < rows; row++) {
330
    for (row = 0; row < rows; row++) {
330
        unsigned int y = ROW2Y(row);
331
        unsigned int y = ROW2Y(row);
331
        unsigned int yd;
332
        unsigned int yd;
332
       
333
       
333
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
334
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
334
            unsigned int x;
335
            unsigned int x;
335
            unsigned int col;
336
            unsigned int col;
336
           
337
           
337
            for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH)
338
            for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH)
338
                memcpy(&fb_addr[FB_POS(x, y + yd)],
339
                memcpy(&fb_addr[FB_POS(x, y + yd)],
339
                &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)],
340
                &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)],
340
                glyphscanline);
341
                glyphscanline);
341
        }
342
        }
342
    }
343
    }
343
   
344
   
344
    if (COL2X(cols) < xres) {
345
    if (COL2X(cols) < xres) {
345
        unsigned int y;
346
        unsigned int y;
346
       
347
       
347
        for (y = 0; y < yres; y++) {
348
        for (y = 0; y < yres; y++) {
348
            unsigned int x;
349
            unsigned int x;
349
           
350
           
350
            for (x = COL2X(cols); x < xres; x++)
351
            for (x = COL2X(cols); x < xres; x++)
351
                memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
352
                memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
352
        }
353
        }
353
    }
354
    }
354
   
355
   
355
    if (ROW2Y(rows) < yres) {
356
    if (ROW2Y(rows) < yres) {
356
        unsigned int y;
357
        unsigned int y;
357
       
358
       
358
        for (y = ROW2Y(rows); y < yres; y++) {
359
        for (y = ROW2Y(rows); y < yres; y++) {
359
            unsigned int x;
360
            unsigned int x;
360
           
361
           
361
            for (x = 0; x < xres; x++)
362
            for (x = 0; x < xres; x++)
362
                memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
363
                memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
363
        }
364
        }
364
    }
365
    }
365
}
366
}
366
 
367
 
367
 
368
 
368
/** Initialize framebuffer as a chardev output device
369
/** Initialize framebuffer as a chardev output device
369
 *
370
 *
370
 * @param addr   Physical address of the framebuffer
371
 * @param addr   Physical address of the framebuffer
371
 * @param x      Screen width in pixels
372
 * @param x      Screen width in pixels
372
 * @param y      Screen height in pixels
373
 * @param y      Screen height in pixels
373
 * @param scan   Bytes per one scanline
374
 * @param scan   Bytes per one scanline
374
 * @param visual Color model
375
 * @param visual Color model
375
 *
376
 *
376
 */
377
 */
377
void fb_init(fb_properties_t *props)
378
void fb_init(fb_properties_t *props)
378
{
379
{
379
    switch (props->visual) {
380
    switch (props->visual) {
380
    case VISUAL_INDIRECT_8:
381
    case VISUAL_INDIRECT_8:
381
        rgb_conv = rgb_323;
382
        rgb_conv = rgb_323;
382
        pixelbytes = 1;
383
        pixelbytes = 1;
383
        break;
384
        break;
384
    case VISUAL_RGB_5_5_5:
385
    case VISUAL_RGB_5_5_5:
385
        rgb_conv = rgb_555;
386
        rgb_conv = rgb_555;
386
        pixelbytes = 2;
387
        pixelbytes = 2;
387
        break;
388
        break;
388
    case VISUAL_RGB_5_6_5:
389
    case VISUAL_RGB_5_6_5:
389
        rgb_conv = rgb_565;
390
        rgb_conv = rgb_565;
390
        pixelbytes = 2;
391
        pixelbytes = 2;
391
        break;
392
        break;
392
    case VISUAL_RGB_8_8_8:
393
    case VISUAL_RGB_8_8_8:
393
        rgb_conv = rgb_888;
394
        rgb_conv = rgb_888;
394
        pixelbytes = 3;
395
        pixelbytes = 3;
395
        break;
396
        break;
396
    case VISUAL_RGB_8_8_8_0:
397
    case VISUAL_RGB_8_8_8_0:
397
        rgb_conv = rgb_888;
398
        rgb_conv = rgb_888;
398
        pixelbytes = 4;
399
        pixelbytes = 4;
399
        break;
400
        break;
400
    case VISUAL_RGB_0_8_8_8:
401
    case VISUAL_RGB_0_8_8_8:
401
        rgb_conv = rgb_0888;
402
        rgb_conv = rgb_0888;
402
        pixelbytes = 4;
403
        pixelbytes = 4;
403
        break;
404
        break;
404
    case VISUAL_BGR_0_8_8_8:
405
    case VISUAL_BGR_0_8_8_8:
405
        rgb_conv = bgr_0888;
406
        rgb_conv = bgr_0888;
406
        pixelbytes = 4;
407
        pixelbytes = 4;
407
        break;
408
        break;
408
    default:
409
    default:
409
        panic("Unsupported visual.\n");
410
        panic("Unsupported visual.\n");
410
    }
411
    }
411
   
412
   
412
    xres = props->x;
413
    xres = props->x;
413
    yres = props->y;
414
    yres = props->y;
414
    scanline = props->scan;
415
    scanline = props->scan;
415
   
416
   
416
    cols = xres / FONT_WIDTH;
417
    cols = xres / FONT_WIDTH;
417
    rows = yres / FONT_SCANLINES;
418
    rows = yres / FONT_SCANLINES;
418
   
419
   
419
    glyphscanline = FONT_WIDTH * pixelbytes;
420
    glyphscanline = FONT_WIDTH * pixelbytes;
420
    glyphbytes = glyphscanline * FONT_SCANLINES;
421
    glyphbytes = glyphscanline * FONT_SCANLINES;
421
   
422
   
422
    unsigned int fbsize = scanline * yres;
423
    unsigned int fbsize = scanline * yres;
423
    unsigned int bbsize = cols * rows;
424
    unsigned int bbsize = cols * rows;
424
    unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
425
    unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
425
   
426
   
426
    backbuf = (uint8_t *) malloc(bbsize, 0);
427
    backbuf = (uint8_t *) malloc(bbsize, 0);
427
    if (!backbuf)
428
    if (!backbuf)
428
        panic("Unable to allocate backbuffer.\n");
429
        panic("Unable to allocate backbuffer.\n");
429
   
430
   
430
    glyphs = (uint8_t *) malloc(glyphsize, 0);
431
    glyphs = (uint8_t *) malloc(glyphsize, 0);
431
    if (!glyphs)
432
    if (!glyphs)
432
        panic("Unable to allocate glyphs.\n");
433
        panic("Unable to allocate glyphs.\n");
433
   
434
   
434
    bgpixel = malloc(pixelbytes, 0);
435
    bgpixel = malloc(pixelbytes, 0);
435
    if (!bgpixel)
436
    if (!bgpixel)
436
        panic("Unable to allocate background pixel.\n");
437
        panic("Unable to allocate background pixel.\n");
437
   
438
   
438
    memsetb(backbuf, bbsize, 0);
439
    memsetb(backbuf, bbsize, 0);
439
    memsetb(glyphs, glyphsize, 0);
440
    memsetb(glyphs, glyphsize, 0);
440
    memsetb(bgpixel, pixelbytes, 0);
441
    memsetb(bgpixel, pixelbytes, 0);
441
   
442
   
442
    render_glyphs();
443
    render_glyphs();
443
   
444
   
444
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
445
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
445
   
446
   
446
    fb_parea.pbase = (uintptr_t) props->addr + props->offset;
447
    fb_parea.pbase = (uintptr_t) props->addr + props->offset;
447
    fb_parea.vbase = (uintptr_t) fb_addr;
448
    fb_parea.vbase = (uintptr_t) fb_addr;
448
    fb_parea.frames = SIZE2FRAMES(fbsize);
449
    fb_parea.frames = SIZE2FRAMES(fbsize);
449
    fb_parea.cacheable = false;
450
    fb_parea.cacheable = false;
450
    ddi_parea_register(&fb_parea);
451
    ddi_parea_register(&fb_parea);
451
   
452
   
452
    sysinfo_set_item_val("fb", NULL, true);
453
    sysinfo_set_item_val("fb", NULL, true);
453
    sysinfo_set_item_val("fb.kind", NULL, 1);
454
    sysinfo_set_item_val("fb.kind", NULL, 1);
454
    sysinfo_set_item_val("fb.width", NULL, xres);
455
    sysinfo_set_item_val("fb.width", NULL, xres);
455
    sysinfo_set_item_val("fb.height", NULL, yres);
456
    sysinfo_set_item_val("fb.height", NULL, yres);
456
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
457
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
457
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
458
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
458
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
459
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
459
   
460
   
460
    fb_redraw();
461
    fb_redraw();
461
   
462
   
462
    chardev_initialize("fb", &framebuffer, &fb_ops);
463
    chardev_initialize("fb", &framebuffer, &fb_ops);
463
    stdout = &framebuffer;
464
    stdout = &framebuffer;
464
}
465
}
465
 
466
 
466
/** @}
467
/** @}
467
 */
468
 */
468
 
469