Subversion Repositories HelenOS

Rev

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

Rev 1682 Rev 1683
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
#include <genarch/fb/font-8x16.h>
29
#include <genarch/fb/font-8x16.h>
30
#include <genarch/fb/fb.h>
30
#include <genarch/fb/fb.h>
31
#include <console/chardev.h>
31
#include <console/chardev.h>
32
#include <console/console.h>
32
#include <console/console.h>
33
#include <sysinfo/sysinfo.h>
33
#include <sysinfo/sysinfo.h>
34
#include <mm/slab.h>
34
#include <mm/slab.h>
35
#include <align.h>
35
#include <align.h>
36
#include <panic.h>
36
#include <panic.h>
37
#include <memstr.h>
37
#include <memstr.h>
38
#include <config.h>
38
#include <config.h>
39
#include <bitops.h>
39
#include <bitops.h>
40
#include <print.h>
40
#include <print.h>
41
 
41
 
42
#include "helenos.xbm"
42
#include "helenos.xbm"
43
 
43
 
44
SPINLOCK_INITIALIZE(fb_lock);
44
SPINLOCK_INITIALIZE(fb_lock);
45
 
45
 
46
static __u8 *fbaddress = NULL;
46
static __u8 *fbaddress = NULL;
47
 
47
 
48
static __u8 *blankline = NULL;
48
static __u8 *blankline = NULL;
49
static __u8 *dbbuffer = NULL; /* Buffer for fast scrolling console */
49
static __u8 *dbbuffer = NULL; /* Buffer for fast scrolling console */
50
static int dboffset;
50
static int dboffset;
51
 
51
 
52
static unsigned int xres = 0;
52
static unsigned int xres = 0;
53
static unsigned int yres = 0;
53
static unsigned int yres = 0;
54
static unsigned int scanline = 0;
54
static unsigned int scanline = 0;
55
static unsigned int bitspp = 0;
55
static unsigned int bitspp = 0;
56
static unsigned int pixelbytes = 0;
56
static unsigned int pixelbytes = 0;
57
 
57
 
58
static unsigned int position = 0;
58
static unsigned int position = 0;
59
static unsigned int columns = 0;
59
static unsigned int columns = 0;
60
static unsigned int rows = 0;
60
static unsigned int rows = 0;
61
 
61
 
62
 
62
 
63
#define COL_WIDTH   8
63
#define COL_WIDTH   8
64
#define ROW_BYTES   (scanline * FONT_SCANLINES)
64
#define ROW_BYTES   (scanline * FONT_SCANLINES)
65
 
65
 
66
#define BGCOLOR     0x000080
66
#define BGCOLOR     0x000080
67
#define FGCOLOR     0xffff00
67
#define FGCOLOR     0xffff00
68
#define LOGOCOLOR   0x2020b0
68
#define LOGOCOLOR   0x2020b0
69
 
69
 
70
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
70
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
71
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
71
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
72
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
72
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
73
 
73
 
74
#define POINTPOS(x, y)  ((y) * scanline + (x) * pixelbytes)
74
#define POINTPOS(x, y)  ((y) * scanline + (x) * pixelbytes)
75
 
75
 
76
/***************************************************************/
76
/***************************************************************/
77
/* Pixel specific fuctions */
77
/* Pixel specific fuctions */
78
 
78
 
79
static void (*rgb2scr)(void *, int);
79
static void (*rgb2scr)(void *, int);
80
static int (*scr2rgb)(void *);
80
static int (*scr2rgb)(void *);
81
 
81
 
82
/* Conversion routines between different color representations */
82
/* Conversion routines between different color representations */
83
static void rgb_4byte(void *dst, int rgb)
83
static void rgb_4byte(void *dst, int rgb)
84
{
84
{
85
    *(int *)dst = rgb;
85
    *(int *)dst = rgb;
86
}
86
}
87
 
87
 
88
static int byte4_rgb(void *src)
88
static int byte4_rgb(void *src)
89
{
89
{
90
    return (*(int *)src) & 0xffffff;
90
    return (*(int *)src) & 0xffffff;
91
}
91
}
92
 
92
 
93
static void rgb_3byte(void *dst, int rgb)
93
static void rgb_3byte(void *dst, int rgb)
94
{
94
{
95
    __u8 *scr = dst;
95
    __u8 *scr = dst;
96
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
96
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
97
    scr[0] = RED(rgb, 8);
97
    scr[0] = RED(rgb, 8);
98
    scr[1] = GREEN(rgb, 8);
98
    scr[1] = GREEN(rgb, 8);
99
    scr[2] = BLUE(rgb, 8);
99
    scr[2] = BLUE(rgb, 8);
100
#else
100
#else
101
    scr[2] = RED(rgb, 8);
101
    scr[2] = RED(rgb, 8);
102
    scr[1] = GREEN(rgb, 8);
102
    scr[1] = GREEN(rgb, 8);
103
    scr[0] = BLUE(rgb, 8);
103
    scr[0] = BLUE(rgb, 8);
104
#endif
104
#endif
105
}
105
}
106
 
106
 
107
static int byte3_rgb(void *src)
107
static int byte3_rgb(void *src)
108
{
108
{
109
    __u8 *scr = src;
109
    __u8 *scr = src;
110
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
110
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
111
    return scr[0] << 16 | scr[1] << 8 | scr[2];
111
    return scr[0] << 16 | scr[1] << 8 | scr[2];
112
#else
112
#else
113
    return scr[2] << 16 | scr[1] << 8 | scr[0];
113
    return scr[2] << 16 | scr[1] << 8 | scr[0];
114
#endif  
114
#endif  
115
}
115
}
116
 
116
 
117
/**  16-bit depth (5:6:5) */
117
/**  16-bit depth (5:6:5) */
118
static void rgb_2byte(void *dst, int rgb)
118
static void rgb_2byte(void *dst, int rgb)
119
{
119
{
120
    /* 5-bit, 6-bits, 5-bits */
120
    /* 5-bit, 6-bits, 5-bits */
121
    *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
121
    *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
122
}
122
}
123
 
123
 
124
/** 16-bit depth (5:6:5) */
124
/** 16-bit depth (5:6:5) */
125
static int byte2_rgb(void *src)
125
static int byte2_rgb(void *src)
126
{
126
{
127
    int color = *(__u16 *)(src);
127
    int color = *(__u16 *)(src);
128
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
128
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
129
}
129
}
130
 
130
 
131
/** Put pixel - 8-bit depth (3:2:3) */
131
/** Put pixel - 8-bit depth (3:2:3) */
132
static void rgb_1byte(void *dst, int rgb)
132
static void rgb_1byte(void *dst, int rgb)
133
{
133
{
134
    *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
134
    *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
135
}
135
}
136
 
136
 
137
/** Return pixel color - 8-bit depth (3:2:3) */
137
/** Return pixel color - 8-bit depth (3:2:3) */
138
static int byte1_rgb(void *src)
138
static int byte1_rgb(void *src)
139
{
139
{
140
    int color = *(__u8 *)src;
140
    int color = *(__u8 *)src;
141
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
141
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
142
}
142
}
143
 
143
 
144
static void putpixel(unsigned int x, unsigned int y, int color)
144
static void putpixel(unsigned int x, unsigned int y, int color)
145
{
145
{
146
    (*rgb2scr)(&fbaddress[POINTPOS(x,y)],color);
146
    (*rgb2scr)(&fbaddress[POINTPOS(x,y)],color);
147
 
147
 
148
    if (dbbuffer) {
148
    if (dbbuffer) {
149
        int dline = (y + dboffset) % yres;
149
        int dline = (y + dboffset) % yres;
150
        (*rgb2scr)(&dbbuffer[POINTPOS(x,dline)],color);
150
        (*rgb2scr)(&dbbuffer[POINTPOS(x,dline)],color);
151
    }
151
    }
152
}
152
}
153
 
153
 
154
/** Get pixel from viewport */
154
/** Get pixel from viewport */
155
static int getpixel(unsigned int x, unsigned int y)
155
static int getpixel(unsigned int x, unsigned int y)
156
{
156
{
157
    if (dbbuffer) {
157
    if (dbbuffer) {
158
        int dline = (y + dboffset) % yres;
158
        int dline = (y + dboffset) % yres;
159
        return (*scr2rgb)(&dbbuffer[POINTPOS(x,dline)]);
159
        return (*scr2rgb)(&dbbuffer[POINTPOS(x,dline)]);
160
    }
160
    }
161
    return (*scr2rgb)(&fbaddress[POINTPOS(x,y)]);
161
    return (*scr2rgb)(&fbaddress[POINTPOS(x,y)]);
162
}
162
}
163
 
163
 
164
 
164
 
165
/** Fill screen with background color */
165
/** Fill screen with background color */
166
static void clear_screen(void)
166
static void clear_screen(void)
167
{
167
{
168
    unsigned int y;
168
    unsigned int y;
169
 
169
 
170
    for (y = 0; y < yres; y++) {
170
    for (y = 0; y < yres; y++) {
171
        memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes);
171
        memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes);
172
        if (dbbuffer)
172
        if (dbbuffer)
173
            memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes);
173
            memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes);
174
    }
174
    }
175
}
175
}
176
 
176
 
177
 
177
 
178
/** Scroll screen one row up */
178
/** Scroll screen one row up */
179
static void scroll_screen(void)
179
static void scroll_screen(void)
180
{
180
{
181
    __u8 *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
181
    __u8 *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
182
    int firstsz;
182
    int firstsz;
183
 
183
 
184
    if (dbbuffer) {
184
    if (dbbuffer) {
185
        memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline);
185
        memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline);
186
       
186
       
187
        dboffset = (dboffset + FONT_SCANLINES) % yres;
187
        dboffset = (dboffset + FONT_SCANLINES) % yres;
188
        firstsz = yres-dboffset;
188
        firstsz = yres-dboffset;
189
 
189
 
190
        memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline);
190
        memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline);
191
        memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline);
191
        memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline);
192
    } else {
192
    } else {
193
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
193
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
194
        /* Clear last row */
194
        /* Clear last row */
195
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
195
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
196
    }
196
    }
197
}
197
}
198
 
198
 
199
 
199
 
200
static void invert_pixel(unsigned int x, unsigned int y)
200
static void invert_pixel(unsigned int x, unsigned int y)
201
{
201
{
202
    putpixel(x, y, ~getpixel(x, y));
202
    putpixel(x, y, ~getpixel(x, y));
203
}
203
}
204
 
204
 
205
 
205
 
206
/** Draw one line of glyph at a given position */
206
/** Draw one line of glyph at a given position */
207
static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y)
207
static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y)
208
{
208
{
209
    unsigned int i;
209
    unsigned int i;
210
 
210
 
211
    for (i = 0; i < 8; i++)
211
    for (i = 0; i < 8; i++)
212
        if (glline & (1 << (7 - i))) {
212
        if (glline & (1 << (7 - i))) {
213
            putpixel(x + i, y, FGCOLOR);
213
            putpixel(x + i, y, FGCOLOR);
214
        } else
214
        } else
215
            putpixel(x + i, y, BGCOLOR);
215
            putpixel(x + i, y, BGCOLOR);
216
}
216
}
217
 
217
 
218
/***************************************************************/
218
/***************************************************************/
219
/* Character-console functions */
219
/* Character-console functions */
220
 
220
 
221
/** Draw character at given position */
221
/** Draw character at given position */
222
static void draw_glyph(__u8 glyph, unsigned int col, unsigned int row)
222
static void draw_glyph(__u8 glyph, unsigned int col, unsigned int row)
223
{
223
{
224
    unsigned int y;
224
    unsigned int y;
225
 
225
 
226
    for (y = 0; y < FONT_SCANLINES; y++)
226
    for (y = 0; y < FONT_SCANLINES; y++)
227
        draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
227
        draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
228
}
228
}
229
 
229
 
230
/** Invert character at given position */
230
/** Invert character at given position */
231
static void invert_char(unsigned int col, unsigned int row)
231
static void invert_char(unsigned int col, unsigned int row)
232
{
232
{
233
    unsigned int x;
233
    unsigned int x;
234
    unsigned int y;
234
    unsigned int y;
235
 
235
 
236
    for (x = 0; x < COL_WIDTH; x++)
236
    for (x = 0; x < COL_WIDTH; x++)
237
        for (y = 0; y < FONT_SCANLINES; y++)
237
        for (y = 0; y < FONT_SCANLINES; y++)
238
            invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y);
238
            invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y);
239
}
239
}
240
 
240
 
241
/** Draw character at default position */
241
/** Draw character at default position */
242
static void draw_char(char chr)
242
static void draw_char(char chr)
243
{
243
{
244
    draw_glyph(chr, position % columns, position / columns);
244
    draw_glyph(chr, position % columns, position / columns);
245
}
245
}
246
 
246
 
247
static void draw_logo(unsigned int startx, unsigned int starty)
247
static void draw_logo(unsigned int startx, unsigned int starty)
248
{
248
{
249
    unsigned int x;
249
    unsigned int x;
250
    unsigned int y;
250
    unsigned int y;
251
    unsigned int byte;
251
    unsigned int byte;
252
    unsigned int rowbytes;
252
    unsigned int rowbytes;
253
 
253
 
254
    rowbytes = (helenos_width - 1) / 8 + 1;
254
    rowbytes = (helenos_width - 1) / 8 + 1;
255
 
255
 
256
    for (y = 0; y < helenos_height; y++)
256
    for (y = 0; y < helenos_height; y++)
257
        for (x = 0; x < helenos_width; x++) {
257
        for (x = 0; x < helenos_width; x++) {
258
            byte = helenos_bits[rowbytes * y + x / 8];
258
            byte = helenos_bits[rowbytes * y + x / 8];
259
            byte >>= x % 8;
259
            byte >>= x % 8;
260
            if (byte & 1)
260
            if (byte & 1)
261
                putpixel(startx + x, starty + y, LOGOCOLOR);
261
                putpixel(startx + x, starty + y, LOGOCOLOR);
262
        }
262
        }
263
}
263
}
264
 
264
 
265
/***************************************************************/
265
/***************************************************************/
266
/* Stdout specific functions */
266
/* Stdout specific functions */
267
 
267
 
268
static void invert_cursor(void)
268
static void invert_cursor(void)
269
{
269
{
270
    invert_char(position % columns, position / columns);
270
    invert_char(position % columns, position / columns);
271
}
271
}
272
 
272
 
273
/** Print character to screen
273
/** Print character to screen
274
 *
274
 *
275
 *  Emulate basic terminal commands
275
 *  Emulate basic terminal commands
276
 */
276
 */
277
static void fb_putchar(chardev_t *dev, char ch)
277
static void fb_putchar(chardev_t *dev, char ch)
278
{
278
{
279
    spinlock_lock(&fb_lock);
279
    spinlock_lock(&fb_lock);
280
   
280
   
281
    switch (ch) {
281
    switch (ch) {
282
        case '\n':
282
        case '\n':
283
            invert_cursor();
283
            invert_cursor();
284
            position += columns;
284
            position += columns;
285
            position -= position % columns;
285
            position -= position % columns;
286
            break;
286
            break;
287
        case '\r':
287
        case '\r':
288
            invert_cursor();
288
            invert_cursor();
289
            position -= position % columns;
289
            position -= position % columns;
290
            break;
290
            break;
291
        case '\b':
291
        case '\b':
292
            invert_cursor();
292
            invert_cursor();
293
            if (position % columns)
293
            if (position % columns)
294
                position--;
294
                position--;
295
            break;
295
            break;
296
        case '\t':
296
        case '\t':
297
            invert_cursor();
297
            invert_cursor();
298
            do {
298
            do {
299
                draw_char(' ');
299
                draw_char(' ');
300
                position++;
300
                position++;
301
            } while ((position % 8) && position < columns * rows);
301
            } while ((position % 8) && position < columns * rows);
302
            break;
302
            break;
303
        default:
303
        default:
304
            draw_char(ch);
304
            draw_char(ch);
305
            position++;
305
            position++;
306
    }
306
    }
307
   
307
   
308
    if (position >= columns * rows) {
308
    if (position >= columns * rows) {
309
        position -= columns;
309
        position -= columns;
310
        scroll_screen();
310
        scroll_screen();
311
    }
311
    }
312
   
312
   
313
    invert_cursor();
313
    invert_cursor();
314
   
314
   
315
    spinlock_unlock(&fb_lock);
315
    spinlock_unlock(&fb_lock);
316
}
316
}
317
 
317
 
318
static chardev_t framebuffer;
318
static chardev_t framebuffer;
319
static chardev_operations_t fb_ops = {
319
static chardev_operations_t fb_ops = {
320
    .write = fb_putchar,
320
    .write = fb_putchar,
321
};
321
};
322
 
322
 
323
 
323
 
324
/** Initialize framebuffer as a chardev output device
324
/** Initialize framebuffer as a chardev output device
325
 *
325
 *
326
 * @param addr Physical address of the framebuffer
326
 * @param addr Physical address of the framebuffer
327
 * @param x    Screen width in pixels
327
 * @param x    Screen width in pixels
328
 * @param y    Screen height in pixels
328
 * @param y    Screen height in pixels
329
 * @param bpp  Bits per pixel (8, 16, 24, 32)
329
 * @param bpp  Bits per pixel (8, 16, 24, 32)
330
 * @param scan Bytes per one scanline
330
 * @param scan Bytes per one scanline
331
 *
331
 *
332
 */
332
 */
333
void fb_init(__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan)
333
void fb_init(__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan)
334
{
334
{
335
    switch (bpp) {
335
    switch (bpp) {
336
        case 8:
336
        case 8:
337
            rgb2scr = rgb_1byte;
337
            rgb2scr = rgb_1byte;
338
            scr2rgb = byte1_rgb;
338
            scr2rgb = byte1_rgb;
339
            pixelbytes = 1;
339
            pixelbytes = 1;
340
            break;
340
            break;
341
        case 16:
341
        case 16:
342
            rgb2scr = rgb_2byte;
342
            rgb2scr = rgb_2byte;
343
            scr2rgb = byte2_rgb;
343
            scr2rgb = byte2_rgb;
344
            pixelbytes = 2;
344
            pixelbytes = 2;
345
            break;
345
            break;
346
        case 24:
346
        case 24:
347
            rgb2scr = rgb_3byte;
347
            rgb2scr = rgb_3byte;
348
            scr2rgb = byte3_rgb;
348
            scr2rgb = byte3_rgb;
349
            pixelbytes = 3;
349
            pixelbytes = 3;
350
            break;
350
            break;
351
        case 32:
351
        case 32:
352
            rgb2scr = rgb_4byte;
352
            rgb2scr = rgb_4byte;
353
            scr2rgb = byte4_rgb;
353
            scr2rgb = byte4_rgb;
354
            pixelbytes = 4;
354
            pixelbytes = 4;
355
            break;
355
            break;
356
        default:
356
        default:
357
            panic("Unsupported bpp");
357
            panic("Unsupported bpp");
358
    }
358
    }
359
   
359
   
360
    unsigned int fbsize = scan * y;
360
    unsigned int fbsize = scan * y;
361
   
361
   
362
    /* Map the framebuffer */
362
    /* Map the framebuffer */
363
    fbaddress = (__u8 *) hw_map((__address) addr, fbsize);
363
    fbaddress = (__u8 *) hw_map((__address) addr, fbsize);
364
   
364
   
365
    xres = x;
365
    xres = x;
366
    yres = y;
366
    yres = y;
367
    bitspp = bpp;
367
    bitspp = bpp;
368
    scanline = scan;
368
    scanline = scan;
369
   
369
   
370
    rows = y / FONT_SCANLINES;
370
    rows = y / FONT_SCANLINES;
371
    columns = x / COL_WIDTH;
371
    columns = x / COL_WIDTH;
372
 
372
 
373
    /* Allocate double buffer */
373
    /* Allocate double buffer */
374
    int totsize = scanline * yres;
374
    int totsize = scanline * yres;
375
    int pages = SIZE2FRAMES(totsize);
375
    int pages = SIZE2FRAMES(totsize);
376
    int order;
376
    int order;
377
    int rc;
377
    int rc;
378
    if (pages == 1)
378
    if (pages == 1)
379
        order = 0;
379
        order = 0;
380
    else
380
    else
381
        order = fnzb(pages-1)+1;
381
        order = fnzb(pages-1)+1;
382
 
382
 
383
    pfn_t frame = frame_alloc_rc(order,FRAME_ATOMIC,&rc);
383
    pfn_t frame = frame_alloc_rc(order,FRAME_ATOMIC,&rc);
384
    if (!rc)
384
    if (!rc)
385
        dbbuffer = (void *)PA2KA(PFN2ADDR(frame));
385
        dbbuffer = (void *)PA2KA(PFN2ADDR(frame));
386
    else
386
    else
387
        printf("Failed to allocate scroll buffer.\n");
387
        printf("Failed to allocate scroll buffer.\n");
388
    dboffset = 0;
388
    dboffset = 0;
389
 
389
 
390
    /* Initialized blank line */
390
    /* Initialized blank line */
391
    blankline = (__u8 *) malloc(ROW_BYTES, FRAME_ATOMIC);
391
    blankline = (__u8 *) malloc(ROW_BYTES, FRAME_ATOMIC);
392
    ASSERT(blankline);
392
    ASSERT(blankline);
393
    for (y=0; y < FONT_SCANLINES; y++)
393
    for (y=0; y < FONT_SCANLINES; y++)
394
        for (x=0; x < xres; x++)
394
        for (x=0; x < xres; x++)
395
            (*rgb2scr)(&blankline[POINTPOS(x,y)],BGCOLOR);
395
            (*rgb2scr)(&blankline[POINTPOS(x,y)],BGCOLOR);
396
 
396
 
397
    clear_screen();
397
    clear_screen();
398
 
398
 
399
    /* Update size of screen to match text area */
399
    /* Update size of screen to match text area */
400
    yres = rows * FONT_SCANLINES;
400
    yres = rows * FONT_SCANLINES;
401
 
401
 
402
    draw_logo(xres - helenos_width, 0);
402
    draw_logo(xres - helenos_width, 0);
403
    invert_cursor();
403
    invert_cursor();
404
 
404
 
405
    chardev_initialize("fb", &framebuffer, &fb_ops);
405
    chardev_initialize("fb", &framebuffer, &fb_ops);
406
    stdout = &framebuffer;
406
    stdout = &framebuffer;
407
   
407
   
408
    sysinfo_set_item_val("fb", NULL, true);
408
    sysinfo_set_item_val("fb", NULL, true);
409
    sysinfo_set_item_val("fb.kind", NULL, 1);
409
    sysinfo_set_item_val("fb.kind", NULL, 1);
410
    sysinfo_set_item_val("fb.width", NULL, x);
410
    sysinfo_set_item_val("fb.width", NULL, xres);
411
    sysinfo_set_item_val("fb.height", NULL, y);
411
    sysinfo_set_item_val("fb.height", NULL, yres);
412
    sysinfo_set_item_val("fb.bpp", NULL, bpp);
412
    sysinfo_set_item_val("fb.bpp", NULL, bpp);
413
    sysinfo_set_item_val("fb.scanline", NULL, scan);
413
    sysinfo_set_item_val("fb.scanline", NULL, scan);
414
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
414
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
415
 
415
 
416
}
416
}
417
 
417