21#include "pedigree/kernel/BootstrapInfo.h"
22#include "pedigree/kernel/LockGuard.h"
23#include "pedigree/kernel/machine/Framebuffer.h"
24#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
25#include "pedigree/kernel/processor/VirtualAddressSpace.h"
26#include "pedigree/kernel/utilities/utility.h"
28X86Vga::X86Vga() : m_Framebuffer(
"Console framebuffer") {}
34 m_Console.invalidate();
43 nBufLen < FramebufferConsole::CellCount * 2 ? nBufLen : FramebufferConsole::CellCount * 2;
44 MemoryCopy(m_Console.cells(), pBuffer, length);
53 nBufLen < FramebufferConsole::CellCount * 2 ? nBufLen : FramebufferConsole::CellCount * 2;
54 MemoryCopy(pBuffer, m_Console.cells(), length);
59 m_Console.moveCursor(nX, nY);
61 if (m_pConsoleFramebuffer) {
62 m_pConsoleFramebuffer->
redraw();
69 if (m_pConsoleFramebuffer) {
70 m_pConsoleFramebuffer->
redraw();
74bool X86Vga::setFramebuffer(
Framebuffer* framebuffer) {
75 if (!framebuffer || framebuffer->getParent() || framebuffer->getBytesPerPixel() != 4 ||
76 framebuffer->getWidth() > UINT32_MAX || framebuffer->getHeight() > UINT32_MAX ||
77 (framebuffer->getFormat() != Graphics::Bits32_Rgb &&
78 framebuffer->getFormat() != Graphics::Bits32_Bgr)) {
82 const size_t pitch = framebuffer->getBytesPerLine();
83 if (pitch && framebuffer->getHeight() > SIZE_MAX / pitch) {
88 if (!m_Console.initialise(framebuffer->getRawBuffer(), pitch * framebuffer->getHeight(),
89 framebuffer->getWidth(), framebuffer->getHeight(), pitch,
90 framebuffer->getFormat() == Graphics::Bits32_Rgb ? 1 : 0)) {
94 m_pConsoleFramebuffer = framebuffer;
96 m_pConsoleFramebuffer->
redraw();
100bool X86Vga::initialise() {
103 if (!g_pBootstrapInfo || !g_pBootstrapInfo->getFramebuffer(info) || info.width < 640 ||
107 const uint64_t bytes =
static_cast<uint64_t
>(info.pitch) * info.height;
108 if (bytes > 256 * 1024 * 1024) {
112 const size_t offset = info.address & (pageSize - 1);
113 const size_t pages = (bytes + offset + pageSize - 1) / pageSize;
115 m_Framebuffer, pages,
120 info.address - offset)) {
123 m_Console.initialise(
reinterpret_cast<uint8_t*
>(m_Framebuffer.
virtualAddress()) + offset, bytes,
124 info.width, info.height, info.pitch, info.format);
void redraw(size_t x=~0UL, size_t y=~0UL, size_t w=~0UL, size_t h=~0UL, bool bChild=false)
void * virtualAddress() const
static const size_t continuous
static PhysicalMemoryManager & instance()
static constexpr size_t getPageSize() PURE
static const size_t force
static const size_t nonRamMemory
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)=0
static const size_t CacheDisable
static const size_t KernelMode
static const size_t Write
virtual bool setLargestTextMode()
virtual void pokeBuffer(uint8_t *pBuffer, size_t nBufLen)
virtual void moveCursor(size_t nX, size_t nY)
virtual void peekBuffer(uint8_t *pBuffer, size_t nBufLen)