Kernel: Remove map_for_kernel() in MemoryManager

We don't need to have this method anymore. It was a hack that was used
in many components in the system but currently we use better methods to
create virtual memory mappings. To prevent any further use of this
method it's best to just remove it completely.

Also, the APIC code is disabled for now since it doesn't help booting
the system, and is broken since it relies on identity mapping to exist
in the first 1MB. Any call to the APIC code will result in assertion
failed.

In addition to that, the name of the method which is responsible to
create an identity mapping between 1MB to 2MB was changed, to be more
precise about its purpose.
This commit is contained in:
Liav A 2020-01-21 04:41:02 +02:00 committed by Andreas Kling
parent 60c32f44dd
commit 200a5b0649
Notes: sideshowbarker 2024-07-19 09:55:22 +09:00
4 changed files with 7 additions and 22 deletions

View file

@ -156,6 +156,8 @@ extern "C" u16 apic_ap_start_size;
bool init()
{
// FIXME: This code is broken and therefore isn't called. Please map everything correctly before calling this code.
ASSERT_NOT_REACHED();
if (!MSR::have())
return false;
@ -168,9 +170,8 @@ bool init()
kprintf("Initializing APIC, base: P%x\n", apic_base);
set_base(apic_base);
MM.map_for_kernel(VirtualAddress(apic_base.get()), apic_base, true); // Map memory, disable cache!
g_apic_base = apic_base.as_ptr();
// copy ap init code to P8000
memcpy(reinterpret_cast<u8*>(0x8000), reinterpret_cast<const u8*>(apic_ap_start), apic_ap_start_size);
return true;

View file

@ -55,7 +55,7 @@ MemoryManager::MemoryManager()
asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3()));
setup_low_1mb();
setup_low_identity_mapping();
protect_kernel_image();
}
@ -83,7 +83,7 @@ void MemoryManager::protect_kernel_image()
}
}
void MemoryManager::setup_low_1mb()
void MemoryManager::setup_low_identity_mapping()
{
m_low_page_table = allocate_user_physical_page(ShouldZeroFill::Yes);
@ -101,7 +101,7 @@ void MemoryManager::setup_low_1mb()
if (g_cpu_supports_nx)
pde_zero.set_execute_disabled(true);
for (uintptr_t offset = 0; offset < (2 * MB); offset += PAGE_SIZE) {
for (uintptr_t offset = (1 * MB); offset < (2 * MB); offset += PAGE_SIZE) {
auto& page_table_page = m_low_page_table;
auto& pte = quickmap_pt(page_table_page->paddr())[offset / PAGE_SIZE];
pte.set_physical_page_base(offset);
@ -532,17 +532,6 @@ PageTableEntry* MemoryManager::quickmap_pt(PhysicalAddress pt_paddr)
return (PageTableEntry*)0xffe08000;
}
void MemoryManager::map_for_kernel(VirtualAddress vaddr, PhysicalAddress paddr, bool cache_disabled)
{
auto& pte = ensure_pte(kernel_page_directory(), vaddr);
pte.set_physical_page_base(paddr.get());
pte.set_present(true);
pte.set_writable(true);
pte.set_user_allowed(false);
pte.set_cache_disabled(cache_disabled);
flush_tlb(vaddr);
}
u8* MemoryManager::quickmap_page(PhysicalPage& physical_page)
{
ASSERT_INTERRUPTS_DISABLED();

View file

@ -108,8 +108,6 @@ public:
void deallocate_user_physical_page(PhysicalPage&&);
void deallocate_supervisor_physical_page(PhysicalPage&&);
void map_for_kernel(VirtualAddress, PhysicalAddress, bool cache_disabled = false);
OwnPtr<Region> allocate_kernel_region(size_t, const StringView& name, u8 access, bool user_accessible = false, bool should_commit = true, bool cacheable = true);
OwnPtr<Region> allocate_kernel_region(PhysicalAddress, size_t, const StringView& name, u8 access, bool user_accessible = false, bool cacheable = false);
OwnPtr<Region> allocate_kernel_region_with_vmobject(VMObject&, size_t, const StringView& name, u8 access, bool user_accessible = false, bool cacheable = false);
@ -149,7 +147,7 @@ private:
void unregister_region(Region&);
void detect_cpu_features();
void setup_low_1mb();
void setup_low_identity_mapping();
void protect_kernel_image();
void parse_memory_map();
void flush_entire_tlb();

View file

@ -142,9 +142,6 @@ extern "C" [[noreturn]] void init()
PCI::Initializer::the().test_and_initialize(KParams::the().has("nopci_mmio"));
PCI::Initializer::the().dismiss();
if (APIC::init())
APIC::enable(0);
PIT::initialize();
PCI::enumerate_all([](const PCI::Address& address, PCI::ID id) {