1 // io/console/vga.cc -- Kernel debugging console for standard VGA text mode
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
15 #include <System/IO.h>
16 #include <kern/kernel.h>
17 #include <kern/console.h>
18 #include <kern/notifier.h>
20 #include <kern/libc.h>
21 #include <kern/addrs.h>
22 #include <util/lock.h>
26 class VGA : public Console {
30 unsigned long io_base;
36 void putc(int ch, int attr)
40 pos -= pos % line_width;
41 } else if (ch == '\r') {
42 pos -= pos % line_width;
44 // Use ll_swap_le16 rather than store_le16 in the hopes
45 // that the compiler can simply change the shifts around
46 // rather than assembling it one way and then ll_swapping.
48 // It's done as one atomic store rather than two single
49 // byte writes (which would eliminate endianness concerns)
50 // to eliminate the possibility of a race where the video
51 // card reads a character before its attribute has been
54 mem_base[pos++] = ll_swap_le16(ch | (attr << 8));
57 if (pos >= lines * line_width) {
60 // FIXME: until memcpy is more than a stupid byte-at-a-time
61 // loop, this could race with the video card.
63 memcpy(mem_base, mem_base + line_width,
64 line_width * (lines - 1) * sizeof(u16));
66 for (int i = 0; i < line_width; i++)
67 mem_base[pos + i] = ll_swap_le16(' ' | (7 << 8));
74 pos = (u16)ll_in_8(0x3d5) << 8;
76 pos |= ll_in_8(0x3d5);
82 ll_out_8(0x3d5, pos >> 8);
84 ll_out_8(0x3d5, pos & 0xff);
88 #include <servers/io/console/vga/IO/Console/VGA.h>
94 // FIXME: should be PCI mem space, not phys mem.
95 mem_base = (u16 *)Arch::phys_to_kvirt(0xb8000);
102 primary_console = this;
105 void write(Array<octet> buf, u64 *LEN)
107 if (!valid_size_t(*LEN))
108 /* throw something */
114 /* throw something */
117 Lock::AutoSpinLockRecIRQ autolock(lock);
120 for (size_t i = 0; i < len; i++)
126 void write_async(Array<octet> buf, u64 len, Notifier notifier)
129 io_notify(notifier, len, io_result::Success);
133 // Use a static constructor, so that it can be used before
134 // memory management is up and running.
140 #include <servers/io/console/vga/footer.cc>