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 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following conditions:
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimers.
15 // * Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimers in the
17 // documentation and/or other materials provided with the distribution.
19 // * The names of the Software's authors and/or contributors
20 // may not be used to endorse or promote products derived from
21 // this Software without specific prior written permission.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
31 #include <System/IO.h>
32 #include <kern/kernel.h>
33 #include <kern/console.h>
34 #include <kern/notifier.h>
36 #include <kern/libc.h>
37 #include <kern/addrs.h>
38 #include <util/lock.h>
40 void vga_write(char *str);
44 class VGA : public Console {
48 unsigned long io_base;
54 void putc(int ch, int attr)
58 pos -= pos % line_width;
59 } else if (ch == '\r') {
60 pos -= pos % line_width;
62 // Use ll_swap_le16 rather than store_le16 in the hopes
63 // that the compiler can simply change the shifts around
64 // rather than assembling it one way and then ll_swapping.
66 // It's done as one atomic store rather than two single
67 // byte writes (which would eliminate endianness concerns)
68 // to eliminate the possibility of a race where the video
69 // card reads a character before its attribute has been
72 mem_base[pos++] = ll_swap_le16(ch | (attr << 8));
75 if (pos >= lines * line_width) {
78 // FIXME: until memcpy is more than a stupid byte-at-a-time
79 // loop, this could race with the video card.
81 memcpy(mem_base, mem_base + line_width,
82 line_width * (lines - 1) * sizeof(u16));
84 for (int i = 0; i < line_width; i++)
85 mem_base[pos + i] = ll_swap_le16(' ' | (7 << 8));
92 pos = (u16)ll_in_8(0x3d5) << 8;
94 pos |= ll_in_8(0x3d5);
100 ll_out_8(0x3d5, pos >> 8);
102 ll_out_8(0x3d5, pos & 0xff);
106 #include <servers/io/console/vga/IO/Console/VGA.h>
112 // FIXME: should be PCI mem space, not phys mem.
113 mem_base = (u16 *)Arch::phys_to_kvirt(0xb8000);
120 primary_console = this;
123 void write(Array<octet> buf, u64 *LEN)
125 if (!valid_size_t(*LEN))
126 /* throw something */
132 /* throw something */
135 Lock::AutoSpinLockRecIRQ autolock(lock);
138 for (size_t i = 0; i < len; i++)
144 void write_async(Array<octet> buf, u64 len, Notifier notifier)
147 io_notify(notifier, len, io_result::Success);
151 // Use a static constructor, so that it can be used before
152 // memory management is up and running.
158 #include <servers/io/console/vga/footer.cc>