Skip to content

Commit

Permalink
Kernel: Slap UNMAP_AFTER_INIT on a bunch more functions
Browse files Browse the repository at this point in the history
We're now able to unmap 100 KiB of kernel text after init. :^)
  • Loading branch information
awesomekling committed Feb 19, 2021
1 parent e920c74 commit 2b2828a
Show file tree
Hide file tree
Showing 36 changed files with 105 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Kernel/ACPI/DynamicParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace Kernel {
namespace ACPI {

DynamicParser::DynamicParser(PhysicalAddress rsdp)
UNMAP_AFTER_INIT DynamicParser::DynamicParser(PhysicalAddress rsdp)
: IRQHandler(9)
, Parser(rsdp)
{
Expand Down
4 changes: 2 additions & 2 deletions Kernel/ACPI/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum class FeatureLevel {
Disabled,
};

static FeatureLevel determine_feature_level()
UNMAP_AFTER_INIT static FeatureLevel determine_feature_level()
{
auto value = kernel_command_line().lookup("acpi").value_or("on");
if (value == "limited")
Expand All @@ -47,7 +47,7 @@ static FeatureLevel determine_feature_level()
return FeatureLevel::Enabled;
}

void initialize()
UNMAP_AFTER_INIT void initialize()
{
auto feature_level = determine_feature_level();
if (feature_level == FeatureLevel::Disabled)
Expand Down
16 changes: 8 additions & 8 deletions Kernel/ACPI/MultiProcessorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@

namespace Kernel {

OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
UNMAP_AFTER_INIT OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
{
auto floating_pointer = find_floating_pointer();
if (!floating_pointer.has_value())
return {};
return adopt_own(*new MultiProcessorParser(floating_pointer.value()));
}

MultiProcessorParser::MultiProcessorParser(PhysicalAddress floating_pointer)
UNMAP_AFTER_INIT MultiProcessorParser::MultiProcessorParser(PhysicalAddress floating_pointer)
: m_floating_pointer(floating_pointer)
{
klog() << "MultiProcessor: Floating Pointer Structure @ " << m_floating_pointer;
parse_floating_pointer_data();
parse_configuration_table();
}

void MultiProcessorParser::parse_floating_pointer_data()
UNMAP_AFTER_INIT void MultiProcessorParser::parse_floating_pointer_data()
{
auto floating_pointer = map_typed<MultiProcessor::FloatingPointer>(m_floating_pointer);
m_configuration_table = PhysicalAddress(floating_pointer->physical_address_ptr);
dbgln("Features {}, IMCR? {}", floating_pointer->feature_info[0], (floating_pointer->feature_info[0] & (1 << 7)));
}

void MultiProcessorParser::parse_configuration_table()
UNMAP_AFTER_INIT void MultiProcessorParser::parse_configuration_table()
{
auto configuration_table_length = map_typed<MultiProcessor::ConfigurationTableHeader>(m_configuration_table)->length;
auto config_table = map_typed<MultiProcessor::ConfigurationTableHeader>(m_configuration_table, configuration_table_length);
Expand Down Expand Up @@ -102,7 +102,7 @@ void MultiProcessorParser::parse_configuration_table()
}
}

Optional<PhysicalAddress> MultiProcessorParser::find_floating_pointer()
UNMAP_AFTER_INIT Optional<PhysicalAddress> MultiProcessorParser::find_floating_pointer()
{
StringView signature("_MP_");
auto mp_floating_pointer = map_ebda().find_chunk_starting_with(signature, 16);
Expand All @@ -111,7 +111,7 @@ Optional<PhysicalAddress> MultiProcessorParser::find_floating_pointer()
return map_bios().find_chunk_starting_with(signature, 16);
}

Vector<u8> MultiProcessorParser::get_pci_bus_ids() const
UNMAP_AFTER_INIT Vector<u8> MultiProcessorParser::get_pci_bus_ids() const
{
Vector<u8> pci_bus_ids;
for (auto& entry : m_bus_entries) {
Expand All @@ -121,7 +121,7 @@ Vector<u8> MultiProcessorParser::get_pci_bus_ids() const
return pci_bus_ids;
}

Vector<PCIInterruptOverrideMetadata> MultiProcessorParser::get_pci_interrupt_redirections()
UNMAP_AFTER_INIT Vector<PCIInterruptOverrideMetadata> MultiProcessorParser::get_pci_interrupt_redirections()
{
dbgln("MultiProcessor: Get PCI IOAPIC redirections");
Vector<PCIInterruptOverrideMetadata> overrides;
Expand All @@ -148,7 +148,7 @@ Vector<PCIInterruptOverrideMetadata> MultiProcessorParser::get_pci_interrupt_red
return overrides;
}

PCIInterruptOverrideMetadata::PCIInterruptOverrideMetadata(u8 bus_id, u8 polarity, u8 trigger_mode, u8 source_irq, u32 ioapic_id, u16 ioapic_int_pin)
UNMAP_AFTER_INIT PCIInterruptOverrideMetadata::PCIInterruptOverrideMetadata(u8 bus_id, u8 polarity, u8 trigger_mode, u8 source_irq, u32 ioapic_id, u16 ioapic_int_pin)
: m_bus_id(bus_id)
, m_polarity(polarity)
, m_trigger_mode(trigger_mode)
Expand Down
22 changes: 11 additions & 11 deletions Kernel/ACPI/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt, const StringVi
static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt, const StringView& signature);
static bool validate_table(const Structures::SDTHeader&, size_t length);

void Parser::locate_static_data()
UNMAP_AFTER_INIT void Parser::locate_static_data()
{
locate_main_system_description_table();
initialize_main_system_description_table();
init_fadt();
init_facs();
}

PhysicalAddress Parser::find_table(const StringView& signature)
UNMAP_AFTER_INIT PhysicalAddress Parser::find_table(const StringView& signature)
{
dbgln_if(ACPI_DEBUG, "ACPI: Calling Find Table method!");
for (auto p_sdt : m_sdt_pointers) {
Expand All @@ -78,12 +78,12 @@ PhysicalAddress Parser::find_table(const StringView& signature)
return {};
}

void Parser::init_facs()
UNMAP_AFTER_INIT void Parser::init_facs()
{
m_facs = find_table("FACS");
}

void Parser::init_fadt()
UNMAP_AFTER_INIT void Parser::init_fadt()
{
klog() << "ACPI: Initializing Fixed ACPI data";
klog() << "ACPI: Searching for the Fixed ACPI Data Table";
Expand Down Expand Up @@ -250,7 +250,7 @@ u8 Parser::get_table_revision(PhysicalAddress table_header)
return map_typed<Structures::SDTHeader>(table_header)->revision;
}

void Parser::initialize_main_system_description_table()
UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table()
{
#if ACPI_DEBUG
dbgln("ACPI: Checking Main SDT Length to choose the correct mapping size");
Expand Down Expand Up @@ -284,7 +284,7 @@ void Parser::initialize_main_system_description_table()
}
}

void Parser::locate_main_system_description_table()
UNMAP_AFTER_INIT void Parser::locate_main_system_description_table()
{
auto rsdp = map_typed<Structures::RSDPDescriptor20>(m_rsdp);
if (rsdp->base.revision == 0) {
Expand All @@ -303,7 +303,7 @@ void Parser::locate_main_system_description_table()
}
}

Parser::Parser(PhysicalAddress rsdp)
UNMAP_AFTER_INIT Parser::Parser(PhysicalAddress rsdp)
: m_rsdp(rsdp)
{
klog() << "ACPI: Using RSDP @ " << rsdp;
Expand All @@ -321,7 +321,7 @@ static bool validate_table(const Structures::SDTHeader& v_header, size_t length)
return false;
}

Optional<PhysicalAddress> StaticParsing::find_rsdp()
UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_rsdp()
{
StringView signature("RSD PTR ");
auto rsdp = map_ebda().find_chunk_starting_with(signature, 16);
Expand All @@ -330,7 +330,7 @@ Optional<PhysicalAddress> StaticParsing::find_rsdp()
return map_bios().find_chunk_starting_with(signature, 16);
}

PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature)
UNMAP_AFTER_INIT PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
ASSERT(signature.length() == 4);
Expand All @@ -348,7 +348,7 @@ PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const St
ASSERT_NOT_REACHED();
}

static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature)
UNMAP_AFTER_INIT static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
ASSERT(signature.length() == 4);
Expand All @@ -371,7 +371,7 @@ static bool match_table_signature(PhysicalAddress table_header, const StringView
return !strncmp(table->h.sig, signature.characters_without_null_termination(), 4);
}

static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature)
UNMAP_AFTER_INIT static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
ASSERT(signature.length() == 4);
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Arch/i386/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ NEVER_INLINE UNMAP_AFTER_INIT void write_cr4(u32 value)
asm volatile("movl %%eax, %%cr4" ::"a"(value));
}

static void sse_init()
UNMAP_AFTER_INIT static void sse_init()
{
write_cr0((read_cr0() & 0xfffffffbu) | 0x2);
write_cr4(read_cr4() | 0x600);
Expand Down Expand Up @@ -1540,7 +1540,7 @@ void Processor::assume_context(Thread& thread, u32 flags)
ASSERT_NOT_REACHED();
}

extern "C" void pre_init_finished(void)
extern "C" UNMAP_AFTER_INIT void pre_init_finished(void)
{
ASSERT(g_scheduler_lock.own_lock());

Expand All @@ -1553,14 +1553,14 @@ extern "C" void pre_init_finished(void)
Scheduler::leave_on_first_switch(prev_flags);
}

extern "C" void post_init_finished(void)
extern "C" UNMAP_AFTER_INIT void post_init_finished(void)
{
// We need to re-acquire the scheduler lock before a context switch
// transfers control into the idle loop, which needs the lock held
Scheduler::prepare_for_idle_loop();
}

void Processor::initialize_context_switching(Thread& initial_thread)
UNMAP_AFTER_INIT void Processor::initialize_context_switching(Thread& initial_thread)
{
ASSERT(initial_thread.process().is_kernel_process());

Expand Down
6 changes: 3 additions & 3 deletions Kernel/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Kernel {
static char s_cmd_line[1024];
static CommandLine* s_the;

void CommandLine::early_initialize(const char* cmd_line)
UNMAP_AFTER_INIT void CommandLine::early_initialize(const char* cmd_line)
{
if (!cmd_line)
return;
Expand All @@ -49,13 +49,13 @@ const CommandLine& kernel_command_line()
return *s_the;
}

void CommandLine::initialize()
UNMAP_AFTER_INIT void CommandLine::initialize()
{
ASSERT(!s_the);
s_the = new CommandLine(s_cmd_line);
}

CommandLine::CommandLine(const String& string)
UNMAP_AFTER_INIT CommandLine::CommandLine(const String& string)
: m_string(string)
{
s_the = this;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ UNMAP_AFTER_INIT Console::Console()
{
}

Console::~Console()
UNMAP_AFTER_INIT Console::~Console()
{
}

Expand Down
14 changes: 7 additions & 7 deletions Kernel/DMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Kernel {

AK::Singleton<DMIExpose> s_the;

void DMIExpose::set_64_bit_entry_initialization_values()
UNMAP_AFTER_INIT void DMIExpose::set_64_bit_entry_initialization_values()
{
klog() << "DMIExpose: SMBIOS 64bit Entry point @ " << m_entry_point;
auto smbios_entry = map_typed<SMBIOS::EntryPoint64bit>(PhysicalAddress(m_entry_point), SMBIOS_SEARCH_AREA_SIZE);
Expand All @@ -51,7 +51,7 @@ void DMIExpose::set_64_bit_entry_initialization_values()
m_structure_table_length = smbios_entry.ptr()->table_maximum_size;
}

void DMIExpose::set_32_bit_entry_initialization_values()
UNMAP_AFTER_INIT void DMIExpose::set_32_bit_entry_initialization_values()
{
klog() << "DMIExpose: SMBIOS 32bit Entry point @ " << m_entry_point;
auto smbios_entry = map_typed<SMBIOS::EntryPoint32bit>(PhysicalAddress(m_entry_point), SMBIOS_SEARCH_AREA_SIZE);
Expand All @@ -60,7 +60,7 @@ void DMIExpose::set_32_bit_entry_initialization_values()
m_structure_table_length = smbios_entry.ptr()->legacy_structure.smboios_table_length;
}

void DMIExpose::initialize()
UNMAP_AFTER_INIT void DMIExpose::initialize()
{
s_the.ensure_instance();
}
Expand All @@ -79,7 +79,7 @@ size_t DMIExpose::structure_table_length() const
return m_structure_table_length;
}

void DMIExpose::initialize_exposer()
UNMAP_AFTER_INIT void DMIExpose::initialize_exposer()
{
ASSERT(!(m_entry_point.is_null()));
if (m_using_64bit_entry_point) {
Expand All @@ -101,7 +101,7 @@ OwnPtr<KBuffer> DMIExpose::structure_table() const
return KBuffer::try_create_with_bytes(Span<u8> { dmi_blob.ptr(), m_structure_table_length });
}

DMIExpose::DMIExpose()
UNMAP_AFTER_INIT DMIExpose::DMIExpose()
{
auto entry_32bit = find_entry32bit_point();
m_entry_point = entry_32bit.value();
Expand All @@ -117,12 +117,12 @@ DMIExpose::DMIExpose()
initialize_exposer();
}

Optional<PhysicalAddress> DMIExpose::find_entry64bit_point()
UNMAP_AFTER_INIT Optional<PhysicalAddress> DMIExpose::find_entry64bit_point()
{
return map_bios().find_chunk_starting_with("_SM3_", 16);
}

Optional<PhysicalAddress> DMIExpose::find_entry32bit_point()
UNMAP_AFTER_INIT Optional<PhysicalAddress> DMIExpose::find_entry32bit_point()
{
return map_bios().find_chunk_starting_with("_SM_", 16);
}
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Devices/BXVGADevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Kernel {

static AK::Singleton<BXVGADevice> s_the;

void BXVGADevice::initialize()
UNMAP_AFTER_INIT void BXVGADevice::initialize()
{
s_the.ensure_instance();
}
Expand All @@ -70,7 +70,7 @@ BXVGADevice& BXVGADevice::the()
return *s_the;
}

BXVGADevice::BXVGADevice()
UNMAP_AFTER_INIT BXVGADevice::BXVGADevice()
: BlockDevice(29, 0)

{
Expand Down Expand Up @@ -157,7 +157,7 @@ void BXVGADevice::set_y_offset(size_t y_offset)
set_register(VBE_DISPI_INDEX_Y_OFFSET, (u16)y_offset);
}

u32 BXVGADevice::find_framebuffer_address()
UNMAP_AFTER_INIT u32 BXVGADevice::find_framebuffer_address()
{
// NOTE: The QEMU card has the same PCI ID as the Bochs one.
static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 };
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Devices/KeyboardDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,19 @@ static const Keyboard::CharacterMapData DEFAULT_CHARACTER_MAP =
};
// clang-format on

KeyboardDevice::KeyboardDevice()
UNMAP_AFTER_INIT KeyboardDevice::KeyboardDevice()
: IRQHandler(IRQ_KEYBOARD)
, CharacterDevice(85, 1)
, m_controller(I8042Controller::the())
, m_character_map("en-us", DEFAULT_CHARACTER_MAP)
{
}

KeyboardDevice::~KeyboardDevice()
UNMAP_AFTER_INIT KeyboardDevice::~KeyboardDevice()
{
}

bool KeyboardDevice::initialize()
UNMAP_AFTER_INIT bool KeyboardDevice::initialize()
{
if (!m_controller.reset_device(I8042Controller::Device::Keyboard)) {
dbgln("KeyboardDevice: I8042 controller failed to reset device");
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/MBVGADevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MBVGADevice& MBVGADevice::the()
return *s_the;
}

MBVGADevice::MBVGADevice(PhysicalAddress addr, size_t pitch, size_t width, size_t height)
UNMAP_AFTER_INIT MBVGADevice::MBVGADevice(PhysicalAddress addr, size_t pitch, size_t width, size_t height)
: BlockDevice(29, 0)
, m_framebuffer_address(addr)
, m_framebuffer_pitch(pitch)
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Devices/MemoryDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@

namespace Kernel {

MemoryDevice::MemoryDevice()
UNMAP_AFTER_INIT MemoryDevice::MemoryDevice()
: CharacterDevice(1, 1)
{
}

MemoryDevice::~MemoryDevice()
UNMAP_AFTER_INIT MemoryDevice::~MemoryDevice()
{
}

Expand Down
Loading

0 comments on commit 2b2828a

Please sign in to comment.