Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, 2012, 2015 Jonas 'Sortie' Termansen.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* vga.cpp
|
|
|
|
* A Video Graphics Array driver.
|
|
|
|
*/
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2014-03-03 12:22:30 -05:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
#include <sortix/kernel/descriptor.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/inode.h>
|
2012-08-07 18:19:44 -04:00
|
|
|
#include <sortix/kernel/interlock.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/ioctx.h>
|
2014-03-03 12:22:30 -05:00
|
|
|
#include <sortix/kernel/ioport.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/kernel.h>
|
|
|
|
#include <sortix/kernel/kthread.h>
|
2013-05-12 18:41:30 -04:00
|
|
|
#include <sortix/kernel/process.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/refcount.h>
|
|
|
|
#include <sortix/kernel/scheduler.h>
|
|
|
|
#include <sortix/kernel/syscall.h>
|
2013-01-08 18:41:35 -05:00
|
|
|
|
2012-08-01 07:07:47 -04:00
|
|
|
#include "fs/util.h"
|
2011-08-08 09:18:39 -04:00
|
|
|
#include "vga.h"
|
2015-03-19 19:08:08 -04:00
|
|
|
#include "vgafont.h"
|
2012-07-22 09:51:38 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
namespace Sortix {
|
|
|
|
namespace VGA {
|
|
|
|
|
2012-09-21 13:25:22 -04:00
|
|
|
uint8_t* const VGA = (uint8_t* const) 0xB8000;
|
2012-07-22 11:01:34 -04:00
|
|
|
const unsigned WIDTH = 80;
|
|
|
|
const unsigned HEIGHT = 25;
|
|
|
|
const size_t VGA_SIZE = sizeof(uint16_t) * WIDTH * HEIGHT;
|
|
|
|
|
|
|
|
static void WriteIndex(uint16_t port, uint8_t index, uint8_t value)
|
2011-08-08 09:18:39 -04:00
|
|
|
{
|
2014-03-03 12:22:30 -05:00
|
|
|
outport8(port, index);
|
|
|
|
outport8(port+1, value);
|
2012-07-22 11:01:34 -04:00
|
|
|
}
|
2012-07-22 09:51:38 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
static uint8_t ReadIndex(uint16_t port, uint8_t index)
|
|
|
|
{
|
2014-03-03 12:22:30 -05:00
|
|
|
outport8(port, index);
|
|
|
|
return inport8(port+1);
|
2012-07-22 11:01:34 -04:00
|
|
|
}
|
2012-07-22 09:51:38 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
static uint8_t ReplaceIndex(uint16_t port, uint8_t index, uint8_t value)
|
|
|
|
{
|
|
|
|
uint8_t ret = ReadIndex(port, index);
|
|
|
|
WriteIndex(port, index, value);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-22 09:51:38 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
static void FetchVGAFont(uint8_t* font)
|
|
|
|
{
|
|
|
|
// TODO: I just got these magic constants off the net.
|
|
|
|
// Select plane 2 for reading.
|
|
|
|
uint8_t old_03ce_04 = ReplaceIndex(0x03CE, 0x04, 0x02);
|
|
|
|
// Clear even/odd mode.
|
|
|
|
uint8_t old_03ce_05 = ReplaceIndex(0x03CE, 0x05, 0x04);
|
|
|
|
// Map VGA Memory to 0xA0000 (Select 0xA0000-0xAFFFF).
|
|
|
|
uint8_t old_03ce_06 = ReplaceIndex(0x03CE, 0x06, 0x04);
|
|
|
|
// Set bitplane 2.
|
|
|
|
uint8_t old_03c4_02 = ReplaceIndex(0x03C4, 0x02, 0x04);
|
|
|
|
// Clear even/odd mode (the other way, don't ask why).
|
|
|
|
uint8_t old_03c4_04 = ReplaceIndex(0x03C4, 0x04, 0x07);
|
|
|
|
// The font data is now at 0xA0000, so fetch it. Note that there is
|
|
|
|
// reserved room for a 8x32 resolution but we are using 8x16.
|
|
|
|
const uint8_t* data = (const uint8_t*) 0xA0000UL;
|
2014-12-28 14:18:25 -05:00
|
|
|
// Patch the replacement chararacter onto character 0.
|
|
|
|
memcpy((uint8_t*) data + ((32*8)/8 * 0), font_replacement_character, VGA_FONT_CHARSIZE);
|
2012-07-22 11:01:34 -04:00
|
|
|
for ( size_t i = 0; i < VGA_FONT_NUMCHARS; i++ )
|
|
|
|
{
|
|
|
|
const uint8_t* src = data + (32*8)/8 * i;
|
|
|
|
uint8_t* dest = font + VGA_FONT_CHARSIZE * i;
|
2012-09-22 14:38:34 -04:00
|
|
|
memcpy(dest, src, VGA_FONT_CHARSIZE);
|
2012-07-22 11:01:34 -04:00
|
|
|
}
|
|
|
|
// Restore the VGA state.
|
|
|
|
WriteIndex(0x03C4, 0x02, old_03c4_02);
|
|
|
|
WriteIndex(0x03C4, 0x04, old_03c4_04);
|
|
|
|
WriteIndex(0x03CE, 0x05, old_03ce_05);
|
|
|
|
WriteIndex(0x03CE, 0x06, old_03ce_06);
|
|
|
|
WriteIndex(0x03CE, 0x04, old_03ce_04);
|
|
|
|
}
|
2012-07-22 09:51:38 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
const uint8_t* GetFont()
|
|
|
|
{
|
|
|
|
return vgafont;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
void Init(const char* devpath, Ref<Descriptor> slashdev)
|
2012-07-22 11:01:34 -04:00
|
|
|
{
|
2015-03-19 19:08:08 -04:00
|
|
|
if ( !Log::fallback_framebuffer )
|
|
|
|
FetchVGAFont(vgafont);
|
2012-08-07 18:19:44 -04:00
|
|
|
|
|
|
|
ioctx_t ctx; SetupKernelIOCtx(&ctx);
|
|
|
|
|
|
|
|
// Setup the vgafont device.
|
|
|
|
Ref<Inode> vgafontnode(new UtilMemoryBuffer(slashdev->dev, (ino_t) 0, 0, 0,
|
2015-03-19 19:08:08 -04:00
|
|
|
0660, vgafont, sizeof(vgafont),
|
2012-08-07 18:19:44 -04:00
|
|
|
false, false));
|
|
|
|
if ( !vgafontnode )
|
|
|
|
PanicF("Unable to allocate %s/vgafont inode.", devpath);
|
|
|
|
if ( LinkInodeInDir(&ctx, slashdev, "vgafont", vgafontnode) != 0 )
|
|
|
|
PanicF("Unable to link %s/vgafont to vga font.", devpath);
|
|
|
|
|
2015-03-19 19:08:08 -04:00
|
|
|
if ( Log::fallback_framebuffer )
|
|
|
|
return;
|
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
// Setup the vga device.
|
|
|
|
Ref<Inode> vganode(new UtilMemoryBuffer(slashdev->dev, (ino_t) 0, 0, 0,
|
|
|
|
0660, VGA, VGA_SIZE, true, false));
|
|
|
|
if ( !vganode )
|
|
|
|
PanicF("Unable to allocate %s/vga inode.", devpath);
|
|
|
|
if ( LinkInodeInDir(&ctx, slashdev, "vga", vganode) != 0 )
|
|
|
|
PanicF("Unable to link %s/vga to vga.", devpath);
|
2012-07-22 11:01:34 -04:00
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
// Changes the position of the hardware cursor.
|
|
|
|
void SetCursor(unsigned x, unsigned y)
|
|
|
|
{
|
2012-09-21 13:25:22 -04:00
|
|
|
unsigned value = x + y * WIDTH;
|
2012-07-22 11:01:34 -04:00
|
|
|
|
|
|
|
// This sends a command to indicies 14 and 15 in the
|
|
|
|
// CRT Control Register of the VGA controller. These
|
|
|
|
// are the high and low bytes of the index that show
|
|
|
|
// where the hardware cursor is to be 'blinking'.
|
2014-03-03 12:22:30 -05:00
|
|
|
outport8(0x3D4, 14);
|
|
|
|
outport8(0x3D5, (value >> 8) & 0xFF);
|
|
|
|
outport8(0x3D4, 15);
|
|
|
|
outport8(0x3D5, (value >> 0) & 0xFF);
|
2012-07-22 11:01:34 -04:00
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2012-07-22 11:01:34 -04:00
|
|
|
} // namespace VGA
|
|
|
|
} // namespace Sortix
|