Subversion Repositories HelenOS-historic

Rev

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

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