FreeNOS
VGA.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/User.h>
19 #include <Types.h>
20 #include <MemoryBlock.h>
21 #include "VGA.h"
22 
23 VGA::VGA(const u32 inode,
24  const Size w,
25  const Size h)
27  , width(w)
28  , height(h)
29 {
30  m_identifier << "vga0";
31 }
32 
34 {
35  Memory::Range range;
36 
37  // Request VGA memory
38  range.size = PAGESIZE;
39  range.access = Memory::User |
42  range.virt = ZERO;
43  range.phys = VGA_PADDR;
44  VMCtl(SELF, MapContiguous, &range);
45 
46  // Point to the VGA mapping
47  vga = (u16 *) range.virt;
48 
49  // Clear screen
50  for (uint i = 0; i < width * height; i++)
51  {
52  vga[i] = VGA_CHAR(' ', LIGHTGREY, BLACK);
53  }
54 
55  // Disable hardware cursor
56  m_io.outb(VGA_IOADDR, 0x0a);
57  m_io.outb(VGA_IODATA, 1 << 5);
58 
59  // Successfull
60  return FileSystem::Success;
61 }
62 
64  Size & size,
65  const Size offset)
66 {
67  if (offset + size > width * height * sizeof(u16))
68  {
70  }
71 
72  buffer.write(vga + (offset / sizeof(u16)), size);
73  return FileSystem::Success;
74 }
75 
77  Size & size,
78  const Size offset)
79 {
80  if (offset + size > width * height * sizeof(u16))
81  {
83  }
84 
85  MemoryBlock::copy(vga + (offset / sizeof(u16)), buffer.getBuffer(), size);
86  return FileSystem::Success;
87 }
VGA.h
LIGHTGREY
@ LIGHTGREY
Definition: VGA.h:73
VGA::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read video memory.
Definition: VGA.cpp:63
MemoryBlock::copy
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Definition: MemoryBlock.cpp:36
Memory::Range
Memory range.
Definition: Memory.h:55
Types.h
Memory::Writable
@ Writable
Definition: Memory.h:42
Memory::User
@ User
Definition: Memory.h:44
VGA::initialize
virtual FileSystem::Result initialize()
Initialize the VGA device.
Definition: VGA.cpp:33
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
VGA_IOADDR
#define VGA_IOADDR
VGA I/O address port.
Definition: VGA.h:37
FileSystem::InvalidArgument
@ InvalidArgument
Definition: FileSystem.h:55
Device
Abstract device class interface.
Definition: Device.h:35
VGA_PADDR
#define VGA_PADDR
VGA physical video memory address.
Definition: VGA.h:34
MemoryBlock.h
VMCtl
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition: VMCtl.h:61
VGA::vga
u16 * vga
VGA video memory address.
Definition: VGA.h:151
FileSystem::Success
@ Success
Definition: FileSystem.h:54
Memory::Readable
@ Readable
Definition: Memory.h:41
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
VGA::height
Size height
Number of characters vertically.
Definition: VGA.h:157
SELF
#define SELF
Definition: ProcessID.h:35
Memory::Range::phys
Address phys
Physical address.
Definition: Memory.h:58
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
VGA_IODATA
#define VGA_IODATA
VGA I/O data port.
Definition: VGA.h:40
IOBuffer::getBuffer
u8 * getBuffer()
Get raw buffer.
Definition: IOBuffer.cpp:125
VGA::VGA
VGA(const u32 inode, const Size width=80, const Size height=25)
Class constructor function.
Definition: VGA.cpp:23
Device::m_identifier
String m_identifier
Unique identifier for this Device.
Definition: Device.h:79
VGA::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write video memory.
Definition: VGA.cpp:76
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
VGA::m_io
Arch::IO m_io
Port I/O object.
Definition: VGA.h:160
FileSystem::BlockDeviceFile
@ BlockDeviceFile
Definition: FileSystem.h:74
FileSystem
Definition: FileSystem.h:31
Memory::Range::virt
Address virt
Virtual address.
Definition: Memory.h:57
IOBuffer::write
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition: IOBuffer.cpp:180
VGA_CHAR
#define VGA_CHAR(ch, front, back)
Encodes a character for VGA output.
Definition: VGA.h:58
VGA::width
Size width
Number of characters horizontally.
Definition: VGA.h:154
Memory::Range::size
Size size
Size in number of bytes.
Definition: Memory.h:59
Memory::Range::access
Access access
Page access flags.
Definition: Memory.h:60
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
MapContiguous
@ MapContiguous
Definition: VMCtl.h:37
BLACK
@ BLACK
Definition: VGA.h:66