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