1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:27:35 +00:00

Kernel: Replace raw asm functions with naked ones

This commit is contained in:
Hendiadyoin1 2021-07-05 15:34:07 +02:00 committed by Gunnar Beutner
parent c830de4983
commit 9b7e48c6bd
7 changed files with 203 additions and 202 deletions

View file

@ -42,122 +42,122 @@ static EntropySource s_entropy_source_interrupts { EntropySource::Static::Interr
// clang-format off
#if ARCH(I386)
#define EH_ENTRY(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
asm( \
".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \
" pusha\n" \
" pushl %ds\n" \
" pushl %es\n" \
" pushl %fs\n" \
" pushl %gs\n" \
" pushl %ss\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n" \
" mov %ax, %ds\n" \
" mov %ax, %es\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n" \
" mov %ax, %gs\n" \
" pushl %esp \n" /* set TrapFrame::regs */ \
" subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n" \
" pushl %esp \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n");
#define EH_ENTRY(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
NAKED void title##_asm_entry(){ \
asm( \
" pusha\n" \
" pushl %ds\n" \
" pushl %es\n" \
" pushl %fs\n" \
" pushl %gs\n" \
" pushl %ss\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n" \
" mov %ax, %ds\n" \
" mov %ax, %es\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n" \
" mov %ax, %gs\n" \
" pushl %esp \n" /* set TrapFrame::regs */ \
" subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n" \
" pushl %esp \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n"); \
}
#define EH_ENTRY_NO_CODE(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
asm( \
".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \
" pushl $0x0\n" \
" pusha\n" \
" pushl %ds\n" \
" pushl %es\n" \
" pushl %fs\n" \
" pushl %gs\n" \
" pushl %ss\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n" \
" mov %ax, %ds\n" \
" mov %ax, %es\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n" \
" mov %ax, %gs\n" \
" pushl %esp \n" /* set TrapFrame::regs */ \
" subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n" \
" pushl %esp \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n");
#define EH_ENTRY_NO_CODE(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
NAKED void title##_asm_entry(){ \
asm( \
" pushl $0x0\n" \
" pusha\n" \
" pushl %ds\n" \
" pushl %es\n" \
" pushl %fs\n" \
" pushl %gs\n" \
" pushl %ss\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n" \
" mov %ax, %ds\n" \
" mov %ax, %es\n" \
" mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n" \
" mov %ax, %gs\n" \
" pushl %esp \n" /* set TrapFrame::regs */ \
" subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n" \
" pushl %esp \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n"); \
}
#elif ARCH(X86_64)
#define EH_ENTRY(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
asm( \
".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \
" pushq %r15\n" \
" pushq %r14\n" \
" pushq %r13\n" \
" pushq %r12\n" \
" pushq %r11\n" \
" pushq %r10\n" \
" pushq %r9\n" \
" pushq %r8\n" \
" pushq %rax\n" \
" pushq %rcx\n" \
" pushq %rdx\n" \
" pushq %rbx\n" \
" pushq %rsp\n" \
" pushq %rbp\n" \
" pushq %rsi\n" \
" pushq %rdi\n" \
" pushq %rsp \n" /* set TrapFrame::regs */ \
" subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n" \
" subq $0x8, %rsp\n" /* align stack */ \
" lea 0x8(%rsp), %rdi \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" lea 0x8(%rsp), %rdi \n" \
" call " #title "_handler\n" \
" addq $0x8, %rsp\n" /* undo alignment */ \
" jmp common_trap_exit \n");
#define EH_ENTRY(ec, title) \
extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
NAKED void title##_asm_entry(){ \
asm( \
" pushq %r15\n" \
" pushq %r14\n" \
" pushq %r13\n" \
" pushq %r12\n" \
" pushq %r11\n" \
" pushq %r10\n" \
" pushq %r9\n" \
" pushq %r8\n" \
" pushq %rax\n" \
" pushq %rcx\n" \
" pushq %rdx\n" \
" pushq %rbx\n" \
" pushq %rsp\n" \
" pushq %rbp\n" \
" pushq %rsi\n" \
" pushq %rdi\n" \
" pushq %rsp \n" /* set TrapFrame::regs */ \
" subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n" \
" subq $0x8, %rsp\n" /* align stack */ \
" lea 0x8(%rsp), %rdi \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" lea 0x8(%rsp), %rdi \n" \
" call " #title "_handler\n" \
" addq $0x8, %rsp\n" /* undo alignment */ \
" jmp common_trap_exit \n"); \
}
#define EH_ENTRY_NO_CODE(ec, title) \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
extern "C" void title##_asm_entry(); \
asm( \
".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \
" pushq $0x0\n" \
" pushq %r15\n" \
" pushq %r14\n" \
" pushq %r13\n" \
" pushq %r12\n" \
" pushq %r11\n" \
" pushq %r10\n" \
" pushq %r9\n" \
" pushq %r8\n" \
" pushq %rax\n" \
" pushq %rcx\n" \
" pushq %rdx\n" \
" pushq %rbx\n" \
" pushq %rsp\n" \
" pushq %rbp\n" \
" pushq %rsi\n" \
" pushq %rdi\n" \
" pushq %rsp \n" /* set TrapFrame::regs */ \
" subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n" \
" movq %rsp, %rdi \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" movq %rsp, %rdi \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n");
#define EH_ENTRY_NO_CODE(ec, title) \
extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
extern "C" void title##_asm_entry(); \
NAKED void title##_asm_entry(){ \
asm( \
" pushq $0x0\n" \
" pushq %r15\n" \
" pushq %r14\n" \
" pushq %r13\n" \
" pushq %r12\n" \
" pushq %r11\n" \
" pushq %r10\n" \
" pushq %r9\n" \
" pushq %r8\n" \
" pushq %rax\n" \
" pushq %rcx\n" \
" pushq %rdx\n" \
" pushq %rbx\n" \
" pushq %rsp\n" \
" pushq %rbp\n" \
" pushq %rsi\n" \
" pushq %rdi\n" \
" pushq %rsp \n" /* set TrapFrame::regs */ \
" subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n" \
" movq %rsp, %rdi \n" \
" cld\n" \
" call enter_trap_no_irq \n" \
" movq %rsp, %rdi \n" \
" call " #title "_handler\n" \
" jmp common_trap_exit \n"); \
}
#endif
// clang-format on

View file

@ -37,10 +37,6 @@ static volatile bool s_smp_enabled;
static Atomic<ProcessorMessage*> s_message_pool;
Atomic<u32> Processor::s_idle_cpu_mask { 0 };
extern "C" void thread_context_first_enter(void);
extern "C" void exit_kernel_thread(void);
extern "C" void do_assume_context(Thread* thread, u32 flags);
// The compiler can't see the calls to these functions inside assembly.
// Declare them, to avoid dead code warnings.
extern "C" void context_first_init(Thread* from_thread, Thread* to_thread, TrapFrame* trap) __attribute__((used));