Subversion Repositories HelenOS-historic

Rev

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

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