Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions arch/x86/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ ENTRY(entry_\sym)
END_FUNC(entry_\sym)
.endm

.macro MASK_USER_FLAGS
PUSHF
andl $~(USERMODE_FLAGS_MASK), (%_ASM_SP)
POPF
.endm

.macro interrupt_handler sym func
ENTRY(asm_interrupt_handler_\sym)
enter_from_usermode

MASK_USER_FLAGS

cld
SAVE_ALL_REGS
call \func
Expand Down
5 changes: 3 additions & 2 deletions arch/x86/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <lib.h>
#include <processor.h>
#include <segment.h>
#include <traps.h>

extern uint8_t *_boot_stack_ist_top;
extern uint8_t *_boot_stack_df_top;
Expand All @@ -49,7 +50,7 @@ gdt_ptr_t __data_init boot_gdt_ptr = {
.addr = _ul(&boot_gdt),
};

idt_entry_t __data_init boot_idt[256];
idt_entry_t __data_init boot_idt[MAX_INT];

idt_ptr_t boot_idt_ptr __data_init = {
.size = sizeof(boot_idt) - 1,
Expand Down Expand Up @@ -78,7 +79,7 @@ gdt_ptr_t __data_rmode rmode_gdt_ptr = {
.addr = _ul(&rmode_gdt),
};

idt_entry_t __data_rmode rmode_idt[256];
idt_entry_t __data_rmode rmode_idt[MAX_INT];

idt_ptr_t rmode_idt_ptr __data_rmode = {
.size = sizeof(rmode_idt) - 1,
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void init_traps(const cpu_t *cpu) {
percpu->idt = get_free_page(GFP_KERNEL | GFP_USER);
BUG_ON(!percpu->idt);

percpu->idt_ptr.size = (sizeof(percpu->idt) * MAX_INT) - 1;
percpu->idt_ptr.size = (sizeof(idt_entry_t) * MAX_INT) - 1;
percpu->idt_ptr.addr = _ul(percpu->idt);

/* clang-format off */
Expand Down
6 changes: 1 addition & 5 deletions common/usermode.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ static void init_syscall(void) {
/* FIXME: Add compat support */
wrmsr(MSR_CSTAR, _ul(NULL));

wrmsr(MSR_FMASK, X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | X86_EFLAGS_ZF |
X86_EFLAGS_SF | X86_EFLAGS_TF | X86_EFLAGS_IF | X86_EFLAGS_DF |
X86_EFLAGS_OF | X86_EFLAGS_ID | X86_EFLAGS_NT | X86_EFLAGS_RF |
X86_EFLAGS_AC | X86_EFLAGS_IOPL);

wrmsr(MSR_FMASK, USERMODE_FLAGS_MASK);
wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE);
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/acpi/acpica/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <smp/smp.h>
#include <spinlock.h>
#include <time.h>
#include <traps.h>

#include "acpi.h"

Expand Down Expand Up @@ -582,7 +583,7 @@ ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 InterruptLevel, ACPI_OSD_HANDLE
if (acpi_irq_installed)
return AE_ALREADY_EXISTS;

if (!Handler || InterruptLevel > ARRAY_SIZE(idt))
if (!Handler || InterruptLevel > MAX_INT)
return AE_BAD_PARAMETER;

acpi_irq_num = InterruptLevel;
Expand All @@ -605,7 +606,7 @@ ACPI_STATUS AcpiOsRemoveInterruptHandler(UINT32 InterruptLevel,
if (!acpi_irq_installed)
return AE_NOT_EXIST;

if (!Handler || InterruptLevel > ARRAY_SIZE(idt) || InterruptLevel != acpi_irq_num)
if (!Handler || InterruptLevel > MAX_INT || InterruptLevel != acpi_irq_num)
return AE_BAD_PARAMETER;

if (Handler != _ptr(get_intr_handler(&percpu->idt[acpi_irq_num])))
Expand Down
2 changes: 0 additions & 2 deletions include/arch/x86/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ static inline uint64_t get_intr_handler(const struct x86_gate64 *gate) {
}
#endif

extern idt_entry_t idt[256];
extern idt_ptr_t idt_ptr;
#endif /* __ASSEMBLY__ */

#endif /* KTF_SEGMENT_H */
5 changes: 5 additions & 0 deletions include/usermode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#define SYSCALL_MMAP 2
#define SYSCALL_MUNMAP 3

#define USERMODE_FLAGS_MASK \
(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | X86_EFLAGS_ZF | X86_EFLAGS_SF | \
X86_EFLAGS_TF | X86_EFLAGS_IF | X86_EFLAGS_DF | X86_EFLAGS_OF | X86_EFLAGS_ID | \
X86_EFLAGS_NT | X86_EFLAGS_RF | X86_EFLAGS_AC | X86_EFLAGS_IOPL)

#ifndef __ASSEMBLY__
#include <percpu.h>
#include <sched.h>
Expand Down