Subversion Repositories HelenOS

Rev

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

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