OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [drivers/] [char/] [consoledriver.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * linux/arch/arm/drivers/char/consoledriver.c
3
 *
4
 * Low-level console routines
5
 */
6
#include <linux/string.h>
7
 
8
#include <asm/hardware.h>
9
#include <asm/io.h>
10
 
11
#include "vt_kern.h"
12
 
13
#define palette_setpixel(p) outl(0x10000000|((p) & 255), IO_VIDC_BASE)
14
#define palette_write(v)  outl(0x00000000|((v) & 0x00ffffff), IO_VIDC_BASE)
15
/*
16
 * Don't allow underline through to erasing/scrolling routines
17
 */
18
#define FLG_MASK (~(FLG_UNDERLINE << 24))
19
 
20
extern void scroll_set_origin (unsigned long offset);
21
extern void ll_write_char(unsigned long ps, unsigned long chinfo);
22
 
23
static void vcd_buffer_gotoxy(struct con_struct *vcd)
24
{
25
        vcd->screen.pos = vcd->screen.origin;
26
        vcd->buffer.pos = vcd->curstate.y * vtdata.buffer.sizerow +
27
                          vcd->curstate.x;
28
}
29
 
30
static void vcd_buffer_scrollup(struct con_struct *vcd, unsigned int t, unsigned int b, unsigned int l)
31
{
32
        unsigned int old_top, new_top, old_end, new_end;
33
 
34
        if (b > vtdata.numrows || t >= b || l == 0)
35
                return;
36
 
37
        l *= vtdata.buffer.sizerow;
38
        old_top = t * vtdata.buffer.sizerow;
39
        new_top = old_top + l;
40
        new_end = b * vtdata.buffer.sizerow;
41
        old_end = new_end - l;
42
 
43
        if (new_top < new_end) /* we have something to move */
44
                memmove (vcd->buffer.buffer + old_top, vcd->buffer.buffer + new_top,
45
                         (new_end - new_top) << 2);
46
 
47
        if (old_end < new_end) {
48
                if (old_end < old_top)
49
                        old_end = old_top;
50
                memsetl (vcd->buffer.buffer + old_end, (vcd->combined_state & FLG_MASK) | 32,
51
                        (new_end - old_end) << 2);
52
        }
53
}
54
 
55
static void vcd_buffer_scrolldown(struct con_struct *vcd, unsigned int t, unsigned int b, unsigned int l)
56
{
57
        unsigned int old_top, new_top, old_end, new_end;
58
 
59
        if (b > vtdata.numrows || t >= b || l == 0)
60
                return;
61
 
62
        l *= vtdata.buffer.sizerow;
63
        new_top = t * vtdata.buffer.sizerow;
64
        old_top = new_top + l;
65
        old_end = b * vtdata.buffer.sizerow;
66
        new_end = old_end - l;
67
 
68
        if (new_top < new_end) /* we have something to move */
69
                memmove (vcd->buffer.buffer + old_top, vcd->buffer.buffer + new_top,
70
                         (new_end - new_top) << 2);
71
 
72
        if (new_top < old_top) { /* we have something to clear */
73
                if (old_top > old_end)
74
                        old_top = old_end;
75
                memsetl (vcd->buffer.buffer + new_top, (vcd->combined_state & FLG_MASK) | 32,
76
                                (old_top - new_top) << 2);
77
        }
78
}
79
 
80
static unsigned long *vcd_buffer_buffer_pos(struct con_struct *vcd, unsigned int offset)
81
{
82
        return vcd->buffer.buffer + offset;
83
}
84
 
85
static void vcd_buffer_delete_char(struct con_struct *vcd, unsigned int n)
86
{
87
        unsigned long *buffer;
88
        unsigned int len;
89
 
90
        buffer = vcd->buffer.buffer + vcd->buffer.pos;
91
 
92
        if (n >= vtdata.numcolumns - vcd->curstate.x) {
93
                n = vtdata.numcolumns - vcd->curstate.x;
94
                len = 0;
95
        } else {
96
                len = vtdata.numcolumns - vcd->curstate.x - n;
97
                memmove (buffer, buffer + n, len << 2);
98
        }
99
        memsetl (buffer + len, (vcd->combined_state & FLG_MASK) | 32, n << 2);
100
}
101
 
102
static void vcd_buffer_insert_char(struct con_struct *vcd, unsigned int n)
103
{
104
        unsigned long *buffer;
105
 
106
        buffer = vcd->buffer.buffer + vcd->buffer.pos;
107
 
108
        if (n >= vtdata.numcolumns - vcd->curstate.x)
109
                n = vtdata.numcolumns - vcd->curstate.x;
110
        else
111
                memmove (buffer + n, buffer, (vtdata.numcolumns - vcd->curstate.x - n) << 2);
112
        memsetl (buffer, (vcd->combined_state & FLG_MASK) | 32, n << 2);
113
}
114
 
115
static void vcd_buffer_write_char(struct con_struct *vcd, unsigned long character)
116
{
117
        if (vcd->need_wrap) {
118
                vcd->buffer.pos -= vcd->curstate.x;
119
                vcd->need_wrap = vcd->curstate.x = 0;
120
                if (vcd->curstate.y + 1 == vcd->bottom)
121
                        vcd_buffer_scrollup(vcd, vcd->top, vcd->bottom, 1);
122
                else if (vcd->curstate.y + 1 < vtdata.numrows) {
123
                        vcd->curstate.y += 1;
124
                        vcd->buffer.pos += vtdata.buffer.sizerow;
125
                }
126
        }
127
        if (vcd->decim)
128
                vcd_buffer_insert_char(vcd, 1);
129
        vcd->buffer.buffer[vcd->buffer.pos] = character;
130
 
131
        if (vcd->curstate.x + 1 == vtdata.numcolumns)
132
                vcd->need_wrap = vcd->decawm;
133
        else {
134
                vcd->curstate.x ++;
135
                vcd->buffer.pos ++;
136
        }
137
}
138
 
139
static void vcd_buffer_erase(struct con_struct *vcd, unsigned char sx, unsigned char sy,
140
                                unsigned char ex, unsigned char ey)
141
{
142
        unsigned int start = sy * vtdata.numcolumns + sx;
143
        unsigned int end = ey * vtdata.numcolumns + ex + 1;
144
 
145
        memsetl (vcd->buffer.buffer + start, (vcd->combined_state & FLG_MASK) | 32, (end - start) << 2);
146
}
147
 
148
struct console_driver buffer_driver = {
149
        vcd_buffer_gotoxy,
150
        vcd_buffer_scrollup,
151
        vcd_buffer_scrolldown,
152
        vcd_buffer_buffer_pos,
153
        vcd_buffer_delete_char,
154
        vcd_buffer_insert_char,
155
        NULL,
156
        vcd_buffer_write_char,
157
        vcd_buffer_erase
158
};
159
 
160
 
161
static void vcd_screen_gotoxy(struct con_struct *vcd)
162
{
163
        vcd->screen.pos = vcd->screen.origin +
164
                          vcd->curstate.y * vtdata.screen.sizerow +
165
                          vcd->curstate.x * vtdata.screen.bytespercharh;
166
        vcd->buffer.pos = vtdata.buffer.origin +
167
                          vcd->curstate.y * vtdata.buffer.sizerow +
168
                          vcd->curstate.x;
169
}
170
 
171
static void vcd_screen_scrollup(struct con_struct *vcd, unsigned int t, unsigned int b, unsigned int l)
172
{
173
        unsigned int hardware;
174
 
175
        if (b > vtdata.numrows || t >= b || l == 0)
176
                return;
177
 
178
        hardware = (b == vtdata.numrows && t == 0);
179
 
180
        if (hardware) {
181
                vcd->buffer.pos -= vtdata.buffer.origin;
182
                vtdata.buffer.origin += l * vtdata.buffer.sizerow;
183
                if (vtdata.buffer.origin > vtdata.buffer.lastorigin) {
184
                        memmove (vtdata.buffer.buffer,
185
                                 vtdata.buffer.buffer + vtdata.buffer.origin,
186
                                 (vtdata.buffer.totsize - vtdata.buffer.sizerow) << 2);
187
                        vtdata.buffer.origin = 0;
188
                }
189
                vcd->buffer.pos += vtdata.buffer.origin;
190
                memsetl (vtdata.buffer.buffer + vtdata.buffer.origin +
191
                                (vtdata.numrows - l) * vtdata.buffer.sizerow,
192
                                (vcd->combined_state & FLG_MASK) | 32,
193
                                l * vtdata.buffer.sizerow << 2);
194
 
195
                vcd->screen.pos -= vcd->screen.origin;
196
                vcd->screen.origin += l * vtdata.screen.sizerow;
197
                if (vcd->screen.origin >= vtdata.screen.memend)
198
                        vcd->screen.origin = vcd->screen.origin -
199
                                        vtdata.screen.memend + vtdata.screen.memstart;
200
                vcd->screen.pos += vcd->screen.origin;
201
                memsetl ((void *)(vcd->screen.origin + vtdata.screen.sizerow * (vtdata.numrows - l)),
202
                        vcd->cached_backcolwrd, l * vtdata.screen.sizerow);
203
                scroll_set_origin (vcd->screen.origin);
204
        } else {
205
                unsigned int old_top, new_top, old_end, new_end;
206
                unsigned char *origin = (unsigned char *)vcd->screen.origin;
207
 
208
                old_top = t;
209
                new_top = t + l;
210
                new_end = b;
211
                old_end = b - l;
212
 
213
                if (new_top < new_end) { /* we have something to move */
214
                        memmove (vtdata.buffer.buffer + vtdata.buffer.origin + old_top * vtdata.buffer.sizerow,
215
                                 vtdata.buffer.buffer + vtdata.buffer.origin + new_top * vtdata.buffer.sizerow,
216
                                 (new_end - new_top) * vtdata.buffer.sizerow << 2);
217
                        memmove (origin + old_top * vtdata.screen.sizerow,
218
                                 origin + new_top * vtdata.screen.sizerow,
219
                                 (new_end - new_top) * vtdata.screen.sizerow);
220
                }
221
                if (old_end < new_end) {
222
                        if (old_end < old_top)
223
                                old_end = old_top;
224
                        memsetl (vtdata.buffer.buffer + vtdata.buffer.origin + old_end * vtdata.buffer.sizerow,
225
                                 (vcd->combined_state & FLG_MASK) | 32,
226
                                 (new_end - old_end) * vtdata.buffer.sizerow << 2);
227
                        memsetl ((unsigned long *)(origin + old_end * vtdata.screen.sizerow),
228
                                 vcd->cached_backcolwrd,
229
                                 (new_end - old_end) * vtdata.screen.sizerow);
230
                }
231
        }
232
}
233
 
234
static void vcd_screen_scrolldown(struct con_struct *vcd, unsigned int t, unsigned int b, unsigned int l)
235
{
236
        unsigned int hardware;
237
        if (b > vtdata.numrows || t >= b || l == 0)
238
                return;
239
 
240
        hardware = (b == vtdata.numrows && t == 0);
241
 
242
        if (hardware) {
243
                vcd->buffer.pos -= vtdata.buffer.origin;
244
                vtdata.buffer.origin -= vtdata.buffer.sizerow;
245
                if ((int)vtdata.buffer.origin < 0) {
246
                        memmove (vtdata.buffer.buffer + vtdata.buffer.lastorigin + l * vtdata.buffer.sizerow,
247
                                 vtdata.buffer.buffer,
248
                                 (vtdata.buffer.totsize - l * vtdata.buffer.sizerow) << 2);
249
                        vtdata.buffer.origin = vtdata.buffer.lastorigin;
250
                }
251
                vcd->buffer.pos += vtdata.buffer.origin;
252
                memsetl (vtdata.buffer.buffer + vtdata.buffer.origin, (vcd->combined_state & FLG_MASK) | 32,
253
                                vtdata.buffer.sizerow << 2);
254
 
255
                vcd->screen.pos -= vcd->screen.origin;
256
                vcd->screen.origin -= l * vtdata.screen.sizerow;
257
                if (vcd->screen.origin < vtdata.screen.memstart)
258
                        vcd->screen.origin = vcd->screen.origin - vtdata.screen.memstart + vtdata.screen.memend;
259
                vcd->screen.pos += vcd->screen.origin;
260
                memsetl ((void *)vcd->screen.origin, vcd->cached_backcolwrd, l * vtdata.screen.sizerow);
261
                scroll_set_origin (vcd->screen.origin);
262
        } else {
263
                unsigned int old_top, new_top, old_end, new_end;
264
                unsigned char *origin = (unsigned char *)vcd->screen.origin;
265
 
266
                new_top = t;
267
                old_top = t + l;
268
                old_end = b;
269
                new_end = b - l;
270
 
271
                if (new_top < new_end) { /* we have something to move */
272
                        memmove (vtdata.buffer.buffer + vtdata.buffer.origin + old_top * vtdata.buffer.sizerow,
273
                                 vtdata.buffer.buffer + vtdata.buffer.origin + new_top * vtdata.buffer.sizerow,
274
                                 (new_end - new_top) * vtdata.buffer.sizerow << 2);
275
                        memmove (origin + old_top * vtdata.screen.sizerow,
276
                                 origin + new_top * vtdata.screen.sizerow,
277
                                 (new_end - new_top) * vtdata.screen.sizerow);
278
                }
279
                if (new_top < old_top) { /* we have something to clear */
280
                        if (old_top > old_end)
281
                                old_top = old_end;
282
                        memsetl (vtdata.buffer.buffer + vtdata.buffer.origin + new_top * vtdata.buffer.sizerow,
283
                                 (vcd->combined_state & FLG_MASK) | 32,
284
                                 (old_top - new_top) * vtdata.buffer.sizerow << 2);
285
                        memsetl ((unsigned long *)(origin + new_top * vtdata.screen.sizerow),
286
                                 vcd->cached_backcolwrd,
287
                                 (old_top - new_top) * vtdata.screen.sizerow);
288
                }
289
        }
290
}
291
 
292
static unsigned long *vcd_screen_buffer_pos(struct con_struct *vcd, unsigned int offset)
293
{
294
        return vtdata.buffer.buffer + vtdata.buffer.origin + offset;
295
}
296
 
297
static void vcd_screen_delete_char (struct con_struct *vcd, unsigned int n)
298
{
299
        unsigned int row, clear, movelen, setlen, bpr;
300
        unsigned char *to, *from;
301
        unsigned long *buffer;
302
 
303
        buffer = vtdata.buffer.buffer + vcd->buffer.pos;
304
 
305
        if (n >= vtdata.numcolumns - vcd->curstate.x) {
306
                n = vtdata.numcolumns - vcd->curstate.x;
307
                movelen = 0;
308
        } else {
309
                movelen = vtdata.numcolumns - vcd->curstate.x - n;
310
                memmove (buffer, buffer + n, movelen << 2);
311
        }
312
        memsetl (buffer + movelen, (vcd->combined_state & FLG_MASK) | 32, n << 2);
313
 
314
        clear = vcd->cached_backcolwrd & 255;
315
        to = (unsigned char *)vcd->screen.pos;
316
        setlen = n * vtdata.screen.bytespercharh;
317
        from = to + setlen;
318
        bpr = vtdata.numcolumns * vtdata.screen.bytespercharh;
319
        movelen = bpr - setlen - vcd->curstate.x * vtdata.screen.bytespercharh;
320
 
321
        for (row = vtdata.screen.bytespercharv; row > 0; row--, to += bpr, from += bpr) {
322
                memmove (to, from, movelen);
323
                memset (to + movelen, clear, setlen);
324
        }
325
}
326
 
327
static void vcd_screen_insert_char (struct con_struct *vcd, unsigned int n)
328
{
329
        unsigned int row, clear, movelen, setlen, bpr;
330
        unsigned char *to, *from;
331
        unsigned long *buffer;
332
 
333
        buffer = vtdata.buffer.buffer + vcd->buffer.pos;
334
 
335
        if (n >= vtdata.numcolumns - vcd->curstate.x)
336
                n = vtdata.numcolumns - vcd->curstate.x;
337
        else
338
                memmove (buffer + n, buffer, (vtdata.numcolumns - vcd->curstate.x - n) << 2);
339
        memsetl (buffer, (vcd->combined_state & FLG_MASK) | 32, n << 2);
340
 
341
        clear = vcd->cached_backcolwrd & 255;
342
        from = (unsigned char *)vcd->screen.pos;
343
        setlen = n * vtdata.screen.bytespercharh;
344
        to = from + setlen;
345
        bpr = vtdata.numcolumns * vtdata.screen.bytespercharh;
346
        movelen = bpr - setlen - vcd->curstate.x * vtdata.screen.bytespercharh;
347
 
348
        for (row = vtdata.screen.bytespercharv; row > 0; row--, to += bpr, from += bpr) {
349
                memmove (to, from, movelen);
350
                memset (from, clear, setlen);
351
        }
352
}
353
 
354
static void vcd_screen_put_char(struct con_struct *vcd, unsigned long character)
355
{
356
        char c = character & 255;
357
 
358
        if (c == 8) {
359
                if (!vcd->need_wrap) {
360
                        vcd->screen.pos -= vtdata.screen.bytespercharh;
361
                        vcd->buffer.pos --;
362
                        vcd->curstate.x --;
363
                } else
364
                        vcd->need_wrap = 0;
365
                return;
366
        }
367
        if (c == 10 || c == 13 || vcd->need_wrap) {
368
                vcd->screen.pos -= vcd->curstate.x * vtdata.screen.bytespercharh;
369
                vcd->buffer.pos -= vcd->curstate.x;
370
                vcd->need_wrap = vcd->curstate.x = 0;
371
                if (vcd->curstate.y + 1 == vcd->bottom)
372
                        vcd_screen_scrollup (vcd, vcd->top, vcd->bottom, 1);
373
                else if (vcd->curstate.y < vtdata.numrows - 1) {
374
                        vcd->curstate.y += 1;
375
                        vcd->buffer.pos += vtdata.buffer.sizerow;
376
                        vcd->screen.pos += vtdata.screen.sizerow;
377
                }
378
                if (c == 10 || c == 13)
379
                        return;
380
        }
381
        ll_write_char (vcd->screen.pos, character);
382
        vtdata.buffer.buffer[vcd->buffer.pos] = character;
383
 
384
        if (vcd->curstate.x + 1 == vtdata.numcolumns)
385
                vcd->need_wrap = 1;
386
        else {
387
                vcd->curstate.x++;
388
                vcd->screen.pos += vtdata.screen.bytespercharh;
389
                vcd->buffer.pos ++;
390
        }
391
}
392
 
393
static void vcd_screen_write_char(struct con_struct *vcd, unsigned long character)
394
{
395
        if (vcd->need_wrap) {
396
                vcd->screen.pos -= vcd->curstate.x * vtdata.screen.bytespercharh;
397
                vcd->buffer.pos -= vcd->curstate.x;
398
                vcd->need_wrap = vcd->curstate.x = 0;
399
                if (vcd->curstate.y + 1 == vcd->bottom)
400
                        vcd_screen_scrollup(vcd, vcd->top, vcd->bottom, 1);
401
                else if (vcd->curstate.y + 1 < vtdata.numrows) {
402
                        vcd->curstate.y += 1;
403
                        vcd->screen.pos += vtdata.screen.sizerow;
404
                        vcd->buffer.pos += vtdata.buffer.sizerow;
405
                }
406
        }
407
        if (vcd->decim)
408
                vcd_screen_insert_char(vcd, 1);
409
        vtdata.buffer.buffer[vcd->buffer.pos] = character;
410
        ll_write_char (vcd->screen.pos, character);
411
 
412
        if (vcd->curstate.x + 1 == vtdata.numcolumns)
413
                vcd->need_wrap = vcd->decawm;
414
        else {
415
                vcd->curstate.x ++;
416
                vcd->screen.pos += vtdata.screen.bytespercharh;
417
                vcd->buffer.pos ++;
418
        }
419
}
420
 
421
static void vcd_screen_erase (struct con_struct *vcd, unsigned char sx, unsigned char sy,
422
                      unsigned char ex, unsigned char ey)
423
{
424
        unsigned int start = sy * vtdata.numcolumns + sx;
425
        unsigned int end = ey * vtdata.numcolumns + ex + 1;
426
        unsigned char *origin;
427
 
428
        memsetl (vtdata.buffer.buffer + vtdata.buffer.origin + start,
429
                 (vcd->combined_state & FLG_MASK) | 32, (end - start) << 2);
430
        if (sx) { /* erase to end of line */
431
                unsigned int c, i, increment;
432
 
433
                origin = (unsigned char *)vcd->screen.origin +
434
                                sy * vtdata.screen.sizerow +
435
                                sx * vtdata.screen.bytespercharh;
436
                increment = vtdata.numcolumns * vtdata.screen.bytespercharh;
437
                if (sy == ey)
438
                        c = (ex - sx + 1) * vtdata.screen.bytespercharh;
439
                else
440
                        c = (vtdata.numcolumns - sx) * vtdata.screen.bytespercharh;
441
 
442
                for (i = vtdata.screen.bytespercharv; i; i--, origin += increment)
443
                        memset (origin, vcd->cached_backcolwrd, c);
444
                sy ++;
445
        }
446
 
447
        if (sy < ey) {
448
                origin = (unsigned char *)vcd->screen.origin + sy * vtdata.screen.sizerow;
449
                memset (origin, vcd->cached_backcolwrd, (ey - sy) * vtdata.screen.sizerow);
450
                sy = ey;
451
        }
452
 
453
        if (sy == ey) {
454
                unsigned int c, i, increment;
455
 
456
                origin = (unsigned char *)vcd->screen.origin +
457
                                sy * vtdata.screen.sizerow;
458
                increment = vtdata.numcolumns * vtdata.screen.bytespercharh;
459
                c = (ex + 1) * vtdata.screen.bytespercharh;
460
                for (i = vtdata.screen.bytespercharv; i; i--, origin += increment)
461
                        memset (origin, vcd->cached_backcolwrd, c);
462
        }
463
}
464
 
465
struct console_driver screen_driver = {
466
        vcd_screen_gotoxy,
467
        vcd_screen_scrollup,
468
        vcd_screen_scrolldown,
469
        vcd_screen_buffer_pos,
470
        vcd_screen_delete_char,
471
        vcd_screen_insert_char,
472
        vcd_screen_put_char,
473
        vcd_screen_write_char,
474
        vcd_screen_erase
475
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.