Compare commits

...

6 Commits

Author SHA1 Message Date
Bananymous 34b10f61ce Kernel: Make PIT reserve its IRQ
PIT did not reserve IRQ leading to kernel panic if it was being
initialized.
2024-04-18 13:34:28 +03:00
Bananymous 1479b42112 Kernel: Don't even loop over processor when system has only BSP 2024-04-18 13:33:52 +03:00
Bananymous bb061d2a0a Kernel: Make 32bit not use large pages during boot
There is no guarantee that they are supported
2024-04-18 13:33:15 +03:00
Bananymous 061012a268 Kernel: Fix signal trampoline
32 bit did not even support it and 64 bit did not align stack
2024-04-18 13:32:40 +03:00
Bananymous a698f91db4 Kernel: Fix PriorityMutex::try_lock()
Forgot to check this when I updated Mutex::try_lock()
2024-04-18 01:36:15 +03:00
Bananymous 30d12a76bc Kernel: Fix 32 bit compilation 2024-04-18 01:35:56 +03:00
10 changed files with 75 additions and 10 deletions

View File

@ -7,22 +7,26 @@
.global signal_trampoline
signal_trampoline:
ud2
pushl %ebp
movl %esp, %ebp
subl $8, %esp
pusha
movl 40(%esp), %edi
movl 36(%esp), %eax
// align stack to 16 bytes
movl %esp, %ebx
andl $0x0F, %ebx
subl %ebx, %esp
subl $12, %esp
pushl %edi
call *%eax
addl $16, %esp
// restore stack
addl %ebx, %esp
popa
leave

View File

@ -82,9 +82,18 @@ boot_pdpt:
boot_pd:
.set i, 0
.rept 512
.long i + (PG_PAGE_SIZE | PG_READ_WRITE | PG_PRESENT)
.long V2P(boot_pts) + i + (PG_READ_WRITE | PG_PRESENT)
.long 0
.set i, i + 0x200000
.set i, i + 0x1000
.endr
boot_pts:
.set i, 0
.rept 512
.rept 512
.long i + (PG_READ_WRITE | PG_PRESENT)
.long 0
.set i, i + 0x1000
.endr
.endr
boot_gdt:

View File

@ -23,12 +23,18 @@ signal_trampoline:
pushq %r14
pushq %r15
// This is 16 byte aligned
movq 128(%rsp), %rdi
movq 120(%rsp), %rax
// align stack to 16 bytes
movq %rsp, %rbx
andq $0x0F, %rbx
subq %rbx, %rsp
call *%rax
// restore stack
addq %rbx, %rsp
popq %r15
popq %r14
popq %r13

View File

@ -43,7 +43,7 @@ namespace Kernel::ACPI::AML
if (!buffer_size.has_value())
return ParseResult::Failure;
uint32_t actual_buffer_size = BAN::Math::max(buffer_size.value(), buffer_context.aml_data.size());
uint32_t actual_buffer_size = BAN::Math::max<uint32_t>(buffer_size.value(), buffer_context.aml_data.size());
auto buffer = MUST(BAN::RefPtr<Buffer>::create());
MUST(buffer->buffer.resize(actual_buffer_size, 0));

View File

@ -103,6 +103,7 @@ namespace Kernel
ASSERT(m_lock_depth == 0);
}
m_lock_depth++;
return true;
}
void unlock()

View File

@ -94,7 +94,7 @@ namespace Kernel
private:
static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 64;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 4;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 64;
BAN::UniqPtr<VirtualRange> m_kernel_stack;
BAN::UniqPtr<VirtualRange> m_userspace_stack;
const pid_t m_tid { 0 };

View File

@ -19,10 +19,10 @@
namespace Kernel::ACPI
{
static uint32_t* s_global_lock { nullptr };
// https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#global-lock
#if ARCH(x86_64)
asm(R"(
.global acpi_acquire_global_lock
acpi_acquire_global_lock:
@ -54,6 +54,41 @@ acpi_release_global_lock:
ret
)");
#elif ARCH(i686)
asm(R"(
.global acpi_acquire_global_lock
acpi_acquire_global_lock:
movl 4(%esp), %ecx
movl (%ecx), %edx
andl $(~1), %edx
btsl $1, %edx
adcl $0, %edx
lock cmpxchgl %edx, (%ecx)
jnz acpi_acquire_global_lock
cmpb $3, %dl
sbbl %eax, %eax
negl %eax
ret
.global acpi_release_global_lock
acpi_release_global_lock:
movl 4(%esp), %ecx
movl (%ecx), %eax
movl %eax, %edx
andl $(~3), %edx
lock cmpxchgl %edx, (%ecx)
jnz acpi_release_global_lock
andl $1, %eax
ret
)");
#endif
// returns true if lock was acquired successfully
extern "C" bool acpi_acquire_global_lock(uint32_t* lock);

View File

@ -247,6 +247,13 @@ namespace Kernel
uint8_t bsp_id = Kernel::Processor::current_id();
dprintln("BSP lapic id: {}", bsp_id);
if (m_processors.size() == 1)
{
dprintln("Only one processor, skipping AP initialization");
*g_ap_startup_done = 1;
return;
}
for (auto& processor : m_processors)
{
if (processor.apic_id == bsp_id)

View File

@ -335,7 +335,9 @@ namespace Kernel
else if (signal_handler != (vaddr_t)SIG_DFL)
{
// call userspace signal handlers
#if ARCH(x86_64)
interrupt_stack.sp -= 128; // skip possible red-zone
#endif
write_to_stack(interrupt_stack.sp, interrupt_stack.ip);
write_to_stack(interrupt_stack.sp, signal);
write_to_stack(interrupt_stack.sp, signal_handler);

View File

@ -47,6 +47,7 @@ namespace Kernel
IO::outb(TIMER0_CTL, (timer_reload >> 0) & 0xff);
IO::outb(TIMER0_CTL, (timer_reload >> 8) & 0xff);
MUST(InterruptController::get().reserve_irq(PIT_IRQ));
set_irq(PIT_IRQ);
enable_interrupt();
}