Subversion Repositories HelenOS-historic

Rev

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

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