Subversion Repositories HelenOS

Rev

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

Rev 1994 Rev 2015
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 <align.h>
42
#include <align.h>
43
#include <panic.h>
43
#include <panic.h>
44
#include <memstr.h>
44
#include <memstr.h>
45
#include <config.h>
45
#include <config.h>
46
#include <bitops.h>
46
#include <bitops.h>
47
#include <print.h>
47
#include <print.h>
-
 
48
#include <ddi/ddi.h>
48
 
49
 
49
#include "helenos.xbm"
50
#include "helenos.xbm"
50
 
51
 
-
 
52
static parea_t fb_parea;        /**< Physical memory area for fb. */
-
 
53
 
51
SPINLOCK_INITIALIZE(fb_lock);
54
SPINLOCK_INITIALIZE(fb_lock);
52
 
55
 
53
static uint8_t *fbaddress = NULL;
56
static uint8_t *fbaddress = NULL;
54
 
57
 
55
static uint8_t *blankline = NULL;
58
static uint8_t *blankline = NULL;
56
static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */
59
static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */
57
static int dboffset;
60
static int dboffset;
58
 
61
 
59
static unsigned int xres = 0;
62
static unsigned int xres = 0;
60
static unsigned int yres = 0;
63
static unsigned int yres = 0;
61
static unsigned int scanline = 0;
64
static unsigned int scanline = 0;
62
static unsigned int pixelbytes = 0;
65
static unsigned int pixelbytes = 0;
63
#ifdef FB_INVERT_COLORS
66
#ifdef FB_INVERT_COLORS
64
static bool invert_colors = true;
67
static bool invert_colors = true;
65
#else
68
#else
66
static bool invert_colors = false;
69
static bool invert_colors = false;
67
#endif
70
#endif
68
 
71
 
69
static unsigned int position = 0;
72
static unsigned int position = 0;
70
static unsigned int columns = 0;
73
static unsigned int columns = 0;
71
static unsigned int rows = 0;
74
static unsigned int rows = 0;
72
 
75
 
73
#define COL_WIDTH   8
76
#define COL_WIDTH   8
74
#define ROW_BYTES   (scanline * FONT_SCANLINES)
77
#define ROW_BYTES   (scanline * FONT_SCANLINES)
75
 
78
 
76
#define BGCOLOR     0x000080
79
#define BGCOLOR     0x000080
77
#define FGCOLOR     0xffff00
80
#define FGCOLOR     0xffff00
78
#define LOGOCOLOR   0x2020b0
81
#define LOGOCOLOR   0x2020b0
79
 
82
 
80
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
83
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
81
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
84
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
82
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
85
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
83
 
86
 
84
#define POINTPOS(x, y)  ((y) * scanline + (x) * pixelbytes)
87
#define POINTPOS(x, y)  ((y) * scanline + (x) * pixelbytes)
85
 
88
 
86
/***************************************************************/
89
/***************************************************************/
87
/* Pixel specific fuctions */
90
/* Pixel specific fuctions */
88
 
91
 
89
static void (*rgb2scr)(void *, int);
92
static void (*rgb2scr)(void *, int);
90
static int (*scr2rgb)(void *);
93
static int (*scr2rgb)(void *);
91
 
94
 
92
static inline int COLOR(int color)
95
static inline int COLOR(int color)
93
{
96
{
94
    return invert_colors ? ~color : color;
97
    return invert_colors ? ~color : color;
95
}
98
}
96
 
99
 
97
/* Conversion routines between different color representations */
100
/* Conversion routines between different color representations */
98
static void rgb_byte0888(void *dst, int rgb)
101
static void rgb_byte0888(void *dst, int rgb)
99
{
102
{
100
    *((int *) dst) = rgb;
103
    *((int *) dst) = rgb;
101
}
104
}
102
 
105
 
103
static int byte0888_rgb(void *src)
106
static int byte0888_rgb(void *src)
104
{
107
{
105
    return (*((int *) src)) & 0xffffff;
108
    return (*((int *) src)) & 0xffffff;
106
}
109
}
107
 
110
 
108
static void bgr_byte0888(void *dst, int rgb)
111
static void bgr_byte0888(void *dst, int rgb)
109
{
112
{
110
    *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb, 8);
113
    *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb, 8);
111
}
114
}
112
 
115
 
113
static int byte0888_bgr(void *src)
116
static int byte0888_bgr(void *src)
114
{
117
{
115
    int color = *(uint32_t *)(src);
118
    int color = *(uint32_t *)(src);
116
    return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color >> 16) & 0xff);
119
    return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color >> 16) & 0xff);
117
}
120
}
118
 
121
 
119
static void rgb_byte888(void *dst, int rgb)
122
static void rgb_byte888(void *dst, int rgb)
120
{
123
{
121
    uint8_t *scr = dst;
124
    uint8_t *scr = dst;
122
#if defined(FB_INVERT_ENDIAN)
125
#if defined(FB_INVERT_ENDIAN)
123
    scr[0] = RED(rgb, 8);
126
    scr[0] = RED(rgb, 8);
124
    scr[1] = GREEN(rgb, 8);
127
    scr[1] = GREEN(rgb, 8);
125
    scr[2] = BLUE(rgb, 8);
128
    scr[2] = BLUE(rgb, 8);
126
#else
129
#else
127
    scr[2] = RED(rgb, 8);
130
    scr[2] = RED(rgb, 8);
128
    scr[1] = GREEN(rgb, 8);
131
    scr[1] = GREEN(rgb, 8);
129
    scr[0] = BLUE(rgb, 8);
132
    scr[0] = BLUE(rgb, 8);
130
#endif
133
#endif
131
}
134
}
132
 
135
 
133
static int byte888_rgb(void *src)
136
static int byte888_rgb(void *src)
134
{
137
{
135
    uint8_t *scr = src;
138
    uint8_t *scr = src;
136
#if defined(FB_INVERT_ENDIAN)
139
#if defined(FB_INVERT_ENDIAN)
137
    return scr[0] << 16 | scr[1] << 8 | scr[2];
140
    return scr[0] << 16 | scr[1] << 8 | scr[2];
138
#else
141
#else
139
    return scr[2] << 16 | scr[1] << 8 | scr[0];
142
    return scr[2] << 16 | scr[1] << 8 | scr[0];
140
#endif  
143
#endif  
141
}
144
}
142
 
145
 
143
/**  16-bit depth (5:5:5) */
146
/**  16-bit depth (5:5:5) */
144
static void rgb_byte555(void *dst, int rgb)
147
static void rgb_byte555(void *dst, int rgb)
145
{
148
{
146
    /* 5-bit, 5-bits, 5-bits */
149
    /* 5-bit, 5-bits, 5-bits */
147
    *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5);
150
    *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5);
148
}
151
}
149
 
152
 
150
/** 16-bit depth (5:5:5) */
153
/** 16-bit depth (5:5:5) */
151
static int byte555_rgb(void *src)
154
static int byte555_rgb(void *src)
152
{
155
{
153
    int color = *(uint16_t *)(src);
156
    int color = *(uint16_t *)(src);
154
    return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
157
    return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
155
}
158
}
156
 
159
 
157
/**  16-bit depth (5:6:5) */
160
/**  16-bit depth (5:6:5) */
158
static void rgb_byte565(void *dst, int rgb)
161
static void rgb_byte565(void *dst, int rgb)
159
{
162
{
160
    /* 5-bit, 6-bits, 5-bits */
163
    /* 5-bit, 6-bits, 5-bits */
161
    *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
164
    *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
162
}
165
}
163
 
166
 
164
/** 16-bit depth (5:6:5) */
167
/** 16-bit depth (5:6:5) */
165
static int byte565_rgb(void *src)
168
static int byte565_rgb(void *src)
166
{
169
{
167
    int color = *(uint16_t *)(src);
170
    int color = *(uint16_t *)(src);
168
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
171
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
169
}
172
}
170
 
173
 
171
/** Put pixel - 8-bit depth (color palette/3:2:3)
174
/** Put pixel - 8-bit depth (color palette/3:2:3)
172
 *
175
 *
173
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
176
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
174
 * will most likely use a color palette. The color appearance
177
 * will most likely use a color palette. The color appearance
175
 * will be pretty random and depend on the default installed
178
 * will be pretty random and depend on the default installed
176
 * palette. This could be fixed by supporting custom palette
179
 * palette. This could be fixed by supporting custom palette
177
 * and setting it to simulate the 8-bit truecolor.
180
 * and setting it to simulate the 8-bit truecolor.
178
 */
181
 */
179
static void rgb_byte8(void *dst, int rgb)
182
static void rgb_byte8(void *dst, int rgb)
180
{
183
{
181
    *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
184
    *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
182
}
185
}
183
 
186
 
184
/** Return pixel color - 8-bit depth (color palette/3:2:3)
187
/** Return pixel color - 8-bit depth (color palette/3:2:3)
185
 *
188
 *
186
 * See the comment for rgb_byte().
189
 * See the comment for rgb_byte().
187
 */
190
 */
188
static int byte8_rgb(void *src)
191
static int byte8_rgb(void *src)
189
{
192
{
190
    int color = *(uint8_t *)src;
193
    int color = *(uint8_t *)src;
191
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
194
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
192
}
195
}
193
 
196
 
194
static void putpixel(unsigned int x, unsigned int y, int color)
197
static void putpixel(unsigned int x, unsigned int y, int color)
195
{
198
{
196
    (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color));
199
    (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color));
197
 
200
 
198
    if (dbbuffer) {
201
    if (dbbuffer) {
199
        int dline = (y + dboffset) % yres;
202
        int dline = (y + dboffset) % yres;
200
        (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color));
203
        (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color));
201
    }
204
    }
202
}
205
}
203
 
206
 
204
/** Get pixel from viewport */
207
/** Get pixel from viewport */
205
static int getpixel(unsigned int x, unsigned int y)
208
static int getpixel(unsigned int x, unsigned int y)
206
{
209
{
207
    if (dbbuffer) {
210
    if (dbbuffer) {
208
        int dline = (y + dboffset) % yres;
211
        int dline = (y + dboffset) % yres;
209
        return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)]));
212
        return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)]));
210
    }
213
    }
211
    return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)]));
214
    return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)]));
212
}
215
}
213
 
216
 
214
 
217
 
215
/** Fill screen with background color */
218
/** Fill screen with background color */
216
static void clear_screen(void)
219
static void clear_screen(void)
217
{
220
{
218
    unsigned int y;
221
    unsigned int y;
219
 
222
 
220
    for (y = 0; y < yres; y++) {
223
    for (y = 0; y < yres; y++) {
221
        memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes);
224
        memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes);
222
        if (dbbuffer)
225
        if (dbbuffer)
223
            memcpy(&dbbuffer[scanline * y], blankline, xres * pixelbytes);
226
            memcpy(&dbbuffer[scanline * y], blankline, xres * pixelbytes);
224
    }
227
    }
225
}
228
}
226
 
229
 
227
 
230
 
228
/** Scroll screen one row up */
231
/** Scroll screen one row up */
229
static void scroll_screen(void)
232
static void scroll_screen(void)
230
{
233
{
231
    uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
234
    uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
232
    int firstsz;
235
    int firstsz;
233
 
236
 
234
    if (dbbuffer) {
237
    if (dbbuffer) {
235
        memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES);
238
        memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES);
236
       
239
       
237
        dboffset = (dboffset + FONT_SCANLINES) % yres;
240
        dboffset = (dboffset + FONT_SCANLINES) % yres;
238
        firstsz = yres - dboffset;
241
        firstsz = yres - dboffset;
239
 
242
 
240
        memcpy(fbaddress, &dbbuffer[scanline * dboffset], firstsz * scanline);
243
        memcpy(fbaddress, &dbbuffer[scanline * dboffset], firstsz * scanline);
241
        memcpy(&fbaddress[firstsz * scanline], dbbuffer, dboffset * scanline);
244
        memcpy(&fbaddress[firstsz * scanline], dbbuffer, dboffset * scanline);
242
    } else {
245
    } else {
243
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
246
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
244
        /* Clear last row */
247
        /* Clear last row */
245
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
248
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
246
    }
249
    }
247
}
250
}
248
 
251
 
249
 
252
 
250
static void invert_pixel(unsigned int x, unsigned int y)
253
static void invert_pixel(unsigned int x, unsigned int y)
251
{
254
{
252
    putpixel(x, y, ~getpixel(x, y));
255
    putpixel(x, y, ~getpixel(x, y));
253
}
256
}
254
 
257
 
255
 
258
 
256
/** Draw one line of glyph at a given position */
259
/** Draw one line of glyph at a given position */
257
static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y)
260
static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y)
258
{
261
{
259
    unsigned int i;
262
    unsigned int i;
260
 
263
 
261
    for (i = 0; i < 8; i++)
264
    for (i = 0; i < 8; i++)
262
        if (glline & (1 << (7 - i))) {
265
        if (glline & (1 << (7 - i))) {
263
            putpixel(x + i, y, FGCOLOR);
266
            putpixel(x + i, y, FGCOLOR);
264
        } else
267
        } else
265
            putpixel(x + i, y, BGCOLOR);
268
            putpixel(x + i, y, BGCOLOR);
266
}
269
}
267
 
270
 
268
/***************************************************************/
271
/***************************************************************/
269
/* Character-console functions */
272
/* Character-console functions */
270
 
273
 
271
/** Draw character at given position */
274
/** Draw character at given position */
272
static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
275
static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
273
{
276
{
274
    unsigned int y;
277
    unsigned int y;
275
 
278
 
276
    for (y = 0; y < FONT_SCANLINES; y++)
279
    for (y = 0; y < FONT_SCANLINES; y++)
277
        draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
280
        draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
278
}
281
}
279
 
282
 
280
/** Invert character at given position */
283
/** Invert character at given position */
281
static void invert_char(unsigned int col, unsigned int row)
284
static void invert_char(unsigned int col, unsigned int row)
282
{
285
{
283
    unsigned int x;
286
    unsigned int x;
284
    unsigned int y;
287
    unsigned int y;
285
 
288
 
286
    for (x = 0; x < COL_WIDTH; x++)
289
    for (x = 0; x < COL_WIDTH; x++)
287
        for (y = 0; y < FONT_SCANLINES; y++)
290
        for (y = 0; y < FONT_SCANLINES; y++)
288
            invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y);
291
            invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y);
289
}
292
}
290
 
293
 
291
/** Draw character at default position */
294
/** Draw character at default position */
292
static void draw_char(char chr)
295
static void draw_char(char chr)
293
{
296
{
294
    draw_glyph(chr, position % columns, position / columns);
297
    draw_glyph(chr, position % columns, position / columns);
295
}
298
}
296
 
299
 
297
static void draw_logo(unsigned int startx, unsigned int starty)
300
static void draw_logo(unsigned int startx, unsigned int starty)
298
{
301
{
299
    unsigned int x;
302
    unsigned int x;
300
    unsigned int y;
303
    unsigned int y;
301
    unsigned int byte;
304
    unsigned int byte;
302
    unsigned int rowbytes;
305
    unsigned int rowbytes;
303
 
306
 
304
    rowbytes = (helenos_width - 1) / 8 + 1;
307
    rowbytes = (helenos_width - 1) / 8 + 1;
305
 
308
 
306
    for (y = 0; y < helenos_height; y++)
309
    for (y = 0; y < helenos_height; y++)
307
        for (x = 0; x < helenos_width; x++) {
310
        for (x = 0; x < helenos_width; x++) {
308
            byte = helenos_bits[rowbytes * y + x / 8];
311
            byte = helenos_bits[rowbytes * y + x / 8];
309
            byte >>= x % 8;
312
            byte >>= x % 8;
310
            if (byte & 1)
313
            if (byte & 1)
311
                putpixel(startx + x, starty + y, COLOR(LOGOCOLOR));
314
                putpixel(startx + x, starty + y, COLOR(LOGOCOLOR));
312
        }
315
        }
313
}
316
}
314
 
317
 
315
/***************************************************************/
318
/***************************************************************/
316
/* Stdout specific functions */
319
/* Stdout specific functions */
317
 
320
 
318
static void invert_cursor(void)
321
static void invert_cursor(void)
319
{
322
{
320
    invert_char(position % columns, position / columns);
323
    invert_char(position % columns, position / columns);
321
}
324
}
322
 
325
 
323
/** Print character to screen
326
/** Print character to screen
324
 *
327
 *
325
 *  Emulate basic terminal commands
328
 *  Emulate basic terminal commands
326
 */
329
 */
327
static void fb_putchar(chardev_t *dev, char ch)
330
static void fb_putchar(chardev_t *dev, char ch)
328
{
331
{
329
    spinlock_lock(&fb_lock);
332
    spinlock_lock(&fb_lock);
330
   
333
   
331
    switch (ch) {
334
    switch (ch) {
332
    case '\n':
335
    case '\n':
333
        invert_cursor();
336
        invert_cursor();
334
        position += columns;
337
        position += columns;
335
        position -= position % columns;
338
        position -= position % columns;
336
        break;
339
        break;
337
    case '\r':
340
    case '\r':
338
        invert_cursor();
341
        invert_cursor();
339
        position -= position % columns;
342
        position -= position % columns;
340
        break;
343
        break;
341
    case '\b':
344
    case '\b':
342
        invert_cursor();
345
        invert_cursor();
343
        if (position % columns)
346
        if (position % columns)
344
            position--;
347
            position--;
345
        break;
348
        break;
346
    case '\t':
349
    case '\t':
347
        invert_cursor();
350
        invert_cursor();
348
        do {
351
        do {
349
            draw_char(' ');
352
            draw_char(' ');
350
            position++;
353
            position++;
351
        } while ((position % 8) && position < columns * rows);
354
        } while ((position % 8) && position < columns * rows);
352
        break;
355
        break;
353
    default:
356
    default:
354
        draw_char(ch);
357
        draw_char(ch);
355
        position++;
358
        position++;
356
    }
359
    }
357
   
360
   
358
    if (position >= columns * rows) {
361
    if (position >= columns * rows) {
359
        position -= columns;
362
        position -= columns;
360
        scroll_screen();
363
        scroll_screen();
361
    }
364
    }
362
   
365
   
363
    invert_cursor();
366
    invert_cursor();
364
   
367
   
365
    spinlock_unlock(&fb_lock);
368
    spinlock_unlock(&fb_lock);
366
}
369
}
367
 
370
 
368
static chardev_t framebuffer;
371
static chardev_t framebuffer;
369
static chardev_operations_t fb_ops = {
372
static chardev_operations_t fb_ops = {
370
    .write = fb_putchar,
373
    .write = fb_putchar,
371
};
374
};
372
 
375
 
373
 
376
 
374
/** Initialize framebuffer as a chardev output device
377
/** Initialize framebuffer as a chardev output device
375
 *
378
 *
376
 * @param addr   Physical address of the framebuffer
379
 * @param addr   Physical address of the framebuffer
377
 * @param x      Screen width in pixels
380
 * @param x      Screen width in pixels
378
 * @param y      Screen height in pixels
381
 * @param y      Screen height in pixels
379
 * @param scan   Bytes per one scanline
382
 * @param scan   Bytes per one scanline
380
 * @param visual Color model
383
 * @param visual Color model
381
 *
384
 *
382
 */
385
 */
383
void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, unsigned int visual)
386
void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, unsigned int visual)
384
{
387
{
385
    switch (visual) {
388
    switch (visual) {
386
    case VISUAL_INDIRECT_8:
389
    case VISUAL_INDIRECT_8:
387
        rgb2scr = rgb_byte8;
390
        rgb2scr = rgb_byte8;
388
        scr2rgb = byte8_rgb;
391
        scr2rgb = byte8_rgb;
389
        pixelbytes = 1;
392
        pixelbytes = 1;
390
        break;
393
        break;
391
    case VISUAL_RGB_5_5_5:
394
    case VISUAL_RGB_5_5_5:
392
        rgb2scr = rgb_byte555;
395
        rgb2scr = rgb_byte555;
393
        scr2rgb = byte555_rgb;
396
        scr2rgb = byte555_rgb;
394
        pixelbytes = 2;
397
        pixelbytes = 2;
395
        break;
398
        break;
396
    case VISUAL_RGB_5_6_5:
399
    case VISUAL_RGB_5_6_5:
397
        rgb2scr = rgb_byte565;
400
        rgb2scr = rgb_byte565;
398
        scr2rgb = byte565_rgb;
401
        scr2rgb = byte565_rgb;
399
        pixelbytes = 2;
402
        pixelbytes = 2;
400
        break;
403
        break;
401
    case VISUAL_RGB_8_8_8:
404
    case VISUAL_RGB_8_8_8:
402
        rgb2scr = rgb_byte888;
405
        rgb2scr = rgb_byte888;
403
        scr2rgb = byte888_rgb;
406
        scr2rgb = byte888_rgb;
404
        pixelbytes = 3;
407
        pixelbytes = 3;
405
        break;
408
        break;
406
    case VISUAL_RGB_8_8_8_0:
409
    case VISUAL_RGB_8_8_8_0:
407
        rgb2scr = rgb_byte888;
410
        rgb2scr = rgb_byte888;
408
        scr2rgb = byte888_rgb;
411
        scr2rgb = byte888_rgb;
409
        pixelbytes = 4;
412
        pixelbytes = 4;
410
        break;
413
        break;
411
    case VISUAL_RGB_0_8_8_8:
414
    case VISUAL_RGB_0_8_8_8:
412
        rgb2scr = rgb_byte0888;
415
        rgb2scr = rgb_byte0888;
413
        scr2rgb = byte0888_rgb;
416
        scr2rgb = byte0888_rgb;
414
        pixelbytes = 4;
417
        pixelbytes = 4;
415
        break;
418
        break;
416
    case VISUAL_BGR_0_8_8_8:
419
    case VISUAL_BGR_0_8_8_8:
417
        rgb2scr = bgr_byte0888;
420
        rgb2scr = bgr_byte0888;
418
        scr2rgb = byte0888_bgr;
421
        scr2rgb = byte0888_bgr;
419
        pixelbytes = 4;
422
        pixelbytes = 4;
420
        break;
423
        break;
421
    default:
424
    default:
422
        panic("Unsupported visual.\n");
425
        panic("Unsupported visual.\n");
423
    }
426
    }
424
   
427
   
425
    unsigned int fbsize = scan * y;
428
    unsigned int fbsize = scan * y;
426
   
429
   
427
    /* Map the framebuffer */
430
    /* Map the framebuffer */
428
    fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize);
431
    fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize);
429
   
432
   
430
    xres = x;
433
    xres = x;
431
    yres = y;
434
    yres = y;
432
    scanline = scan;
435
    scanline = scan;
433
   
436
   
434
    rows = y / FONT_SCANLINES;
437
    rows = y / FONT_SCANLINES;
435
    columns = x / COL_WIDTH;
438
    columns = x / COL_WIDTH;
436
 
439
 
-
 
440
    fb_parea.pbase = (uintptr_t) addr;
-
 
441
    fb_parea.vbase = (uintptr_t) fbaddress;
-
 
442
    fb_parea.frames = SIZE2FRAMES(fbsize);
-
 
443
    fb_parea.cacheable = false;
-
 
444
    ddi_parea_register(&fb_parea);
-
 
445
 
437
    sysinfo_set_item_val("fb", NULL, true);
446
    sysinfo_set_item_val("fb", NULL, true);
438
    sysinfo_set_item_val("fb.kind", NULL, 1);
447
    sysinfo_set_item_val("fb.kind", NULL, 1);
439
    sysinfo_set_item_val("fb.width", NULL, xres);
448
    sysinfo_set_item_val("fb.width", NULL, xres);
440
    sysinfo_set_item_val("fb.height", NULL, yres);
449
    sysinfo_set_item_val("fb.height", NULL, yres);
441
    sysinfo_set_item_val("fb.scanline", NULL, scan);
450
    sysinfo_set_item_val("fb.scanline", NULL, scan);
442
    sysinfo_set_item_val("fb.visual", NULL, visual);
451
    sysinfo_set_item_val("fb.visual", NULL, visual);
443
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
452
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
-
 
453
    sysinfo_set_item_val("fb.address.color", NULL, PAGE_COLOR((uintptr_t)
-
 
454
        fbaddress));
444
    sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
455
    sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
445
 
456
 
446
    /* Allocate double buffer */
457
    /* Allocate double buffer */
447
    unsigned int order = fnzb(SIZE2FRAMES(ALIGN_UP(fbsize, FRAME_SIZE))) + 1;
458
    unsigned int order = fnzb(SIZE2FRAMES(ALIGN_UP(fbsize, FRAME_SIZE))) + 1;
448
    dbbuffer = (uint8_t * ) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
459
    dbbuffer = (uint8_t * ) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
449
    if (!dbbuffer)
460
    if (!dbbuffer)
450
        printf("Failed to allocate scroll buffer.\n");
461
        printf("Failed to allocate scroll buffer.\n");
451
    dboffset = 0;
462
    dboffset = 0;
452
 
463
 
453
    /* Initialized blank line */
464
    /* Initialized blank line */
454
    blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC);
465
    blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC);
455
    if (!blankline)
466
    if (!blankline)
456
        panic("Failed to allocate blank line for framebuffer.");
467
        panic("Failed to allocate blank line for framebuffer.");
457
    for (y = 0; y < FONT_SCANLINES; y++)
468
    for (y = 0; y < FONT_SCANLINES; y++)
458
        for (x = 0; x < xres; x++)
469
        for (x = 0; x < xres; x++)
459
            (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR));
470
            (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR));
460
   
471
   
461
    clear_screen();
472
    clear_screen();
462
 
473
 
463
    /* Update size of screen to match text area */
474
    /* Update size of screen to match text area */
464
    yres = rows * FONT_SCANLINES;
475
    yres = rows * FONT_SCANLINES;
465
 
476
 
466
    draw_logo(xres - helenos_width, 0);
477
    draw_logo(xres - helenos_width, 0);
467
    invert_cursor();
478
    invert_cursor();
468
 
479
 
469
    chardev_initialize("fb", &framebuffer, &fb_ops);
480
    chardev_initialize("fb", &framebuffer, &fb_ops);
470
    stdout = &framebuffer;
481
    stdout = &framebuffer;
471
}
482
}
472
 
483
 
473
/** @}
484
/** @}
474
 */
485
 */
475
 
486