Subversion Repositories HelenOS

Rev

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

Rev 2015 Rev 2054
Line 37... Line 37...
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;
Line 108... Line 109...
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;
Line 145... Line 148...
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
Line 179... Line 185...
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));
Line 221... Line 229...
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
 
Line 275... Line 288...
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
{
Line 309... Line 324...
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 */
Line 381... Line 397...
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;
Line 453... Line 470...
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 */