Subversion Repositories HelenOS

Rev

Rev 3674 | Rev 4338 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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