1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 15:44:57 +00:00

Kernel/Graphics + SystemServer: Support text mode properly

As we removed the support of VBE modesetting that was done by GRUB early
on boot, we need to determine if we can modeset the resolution with our
drivers, and if not, we should enable text mode and ensure that
SystemServer knows about it too.

Also, SystemServer should first check if there's a framebuffer device
node, which is an indication that text mode was not even if it was
requested. Then, if it doesn't find it, it should check what boot_mode
argument the user specified (in case it's self-test). This way if we
try to use bochs-display device (which is not VGA compatible) and
request a text mode, it will not honor the request and will continue
with graphical mode.

Also try to print critical messages with mininum memory allocations
possible.

In LibVT, We make the implementation flexible for kernel-specific
methods that are implemented in ConsoleImpl class.
This commit is contained in:
Liav A 2021-04-16 22:58:51 +03:00 committed by Andreas Kling
parent dac129e10b
commit 20743e8aed
41 changed files with 1832 additions and 321 deletions

View file

@ -16,6 +16,8 @@
#include <LibC/errno_numbers.h>
#include <LibC/sys/ioctl_numbers.h>
#include <Kernel/Panic.h>
namespace Kernel {
KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared)
@ -28,16 +30,51 @@ KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, c
if (range.size() != page_round_up(framebuffer_size_in_bytes()))
return EOVERFLOW;
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
// FIXME: We rely on the fact that only the WindowServer will mmap the framebuffer
// and only once when starting to work with it. If other program wants to do so, we need to fix this.
VERIFY(!m_userspace_framebuffer_region);
VERIFY(!m_userspace_real_framebuffer_vmobject);
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, page_round_up(framebuffer_size_in_bytes()));
if (!vmobject)
return ENOMEM;
return process.space().allocate_region_with_vmobject(
m_userspace_real_framebuffer_vmobject = vmobject;
auto result = process.space().allocate_region_with_vmobject(
range,
vmobject.release_nonnull(),
0,
"Framebuffer",
prot,
shared);
if (!result.is_error()) {
m_userspace_framebuffer_region = result.value();
}
return result;
}
void FramebufferDevice::dectivate_writes()
{
ScopedSpinLock lock(m_activation_lock);
if (!m_userspace_framebuffer_region)
return;
memcpy(m_swapped_framebuffer_region->vaddr().as_ptr(), m_real_framebuffer_region->vaddr().as_ptr(), page_round_up(framebuffer_size_in_bytes()));
auto vmobject = m_swapped_framebuffer_vmobject;
m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull());
m_userspace_framebuffer_region->remap();
}
void FramebufferDevice::activate_writes()
{
ScopedSpinLock lock(m_activation_lock);
if (!m_userspace_framebuffer_region || !m_real_framebuffer_vmobject)
return;
// restore the image we had in the void area
// FIXME: if we happen to have multiple Framebuffers that are writing to that location
// we will experience glitches...
memcpy(m_real_framebuffer_region->vaddr().as_ptr(), m_swapped_framebuffer_region->vaddr().as_ptr(), page_round_up(framebuffer_size_in_bytes()));
auto vmobject = m_userspace_real_framebuffer_vmobject;
m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull());
m_userspace_framebuffer_region->remap();
}
String FramebufferDevice::device_name() const
@ -45,6 +82,18 @@ String FramebufferDevice::device_name() const
return String::formatted("fb{}", minor());
}
UNMAP_AFTER_INIT void FramebufferDevice::initialize()
{
m_real_framebuffer_vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, page_round_up(framebuffer_size_in_bytes()));
VERIFY(m_real_framebuffer_vmobject);
m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, framebuffer_size_in_bytes(), "Framebuffer", Region::Access::Read | Region::Access::Write);
VERIFY(m_real_framebuffer_region);
m_swapped_framebuffer_vmobject = AnonymousVMObject::create_with_size(page_round_up(framebuffer_size_in_bytes()), AllocationStrategy::AllocateNow);
VERIFY(m_swapped_framebuffer_vmobject);
m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Region::Access::Read | Region::Access::Write);
VERIFY(m_swapped_framebuffer_region);
}
UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(PhysicalAddress addr, size_t pitch, size_t width, size_t height)
: BlockDevice(29, GraphicsManagement::the().current_minor_number())
, m_framebuffer_address(addr)
@ -52,6 +101,10 @@ UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(PhysicalAddress addr, size
, m_framebuffer_width(width)
, m_framebuffer_height(height)
{
VERIFY(!m_framebuffer_address.is_null());
VERIFY(m_framebuffer_pitch);
VERIFY(m_framebuffer_width);
VERIFY(m_framebuffer_height);
dbgln("Framebuffer {}: address={}, pitch={}, width={}, height={}", minor(), addr, pitch, width, height);
}