Subversion Repositories HelenOS

Rev

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

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