-
Notifications
You must be signed in to change notification settings - Fork 392
platform: set up syscall trap on SMP application processors #2370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| namespace x86 { | ||
| void init_syscall_trap(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include <arch/x86/cpu.hpp> | ||
| #include <arch/x86/syscall.hpp> | ||
|
|
||
| extern "C" void __syscall_entry(); | ||
|
|
||
| namespace x86 { | ||
|
|
||
| void init_syscall_trap() | ||
| { | ||
| uint64_t star_kernel_cs = 8ull << 32; | ||
| uint64_t star_user_cs = 8ull << 48; | ||
| uint64_t star = star_kernel_cs | star_user_cs; | ||
| CPU::write_msr(IA32_STAR, star); | ||
| CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #include "init_libc.hpp" | ||
|
|
||
| #include <arch/x86/cpu.hpp> | ||
| #include <arch/x86/syscall.hpp> | ||
| #include <kernel.hpp> | ||
| #include <kernel/auxvec.h> | ||
| #include <kernel/cpuid.hpp> | ||
|
|
@@ -153,18 +154,8 @@ namespace x86 | |
| aux[i++].set_long(AT_NULL, 0); | ||
|
|
||
| #ifdef PLATFORM_x86_pc | ||
| // SYSCALL instruction | ||
| #if defined(__x86_64__) | ||
| KDEBUG("* Initialize syscall MSR (64-bit)\n"); | ||
| uint64_t star_kernel_cs = 8ull << 32; | ||
| uint64_t star_user_cs = 8ull << 48; | ||
| uint64_t star = star_kernel_cs | star_user_cs; | ||
| x86::CPU::write_msr(IA32_STAR, star); | ||
| x86::CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); | ||
| #elif defined(__i386__) | ||
| KDEBUG("Initialize syscall intr (32-bit)\n"); | ||
| #warning Classical syscall interface missing for 32-bit | ||
| #endif | ||
| KDEBUG("* Initialize syscall trap\n"); | ||
| x86::init_syscall_trap(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still wondering if this should be part of libc initialization. I wouldn't do such a change in this PR fwiw, but I would consider opening an issue to discuss it further, maybe.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree — hooking syscall MSR setup off the libc init path is a bit odd, and I wouldn't want to reshuffle boot ordering inside this PR. I'll open an issue to discuss when/where syscall trap init should live (e.g. earlier platform bring-up vs libc/runtime init, and how that interacts with AP startup). This PR only extracts the MSR programming and ensures BSP + APs both call the same helper; it doesn't change when the BSP first calls it. Thanks for calling that out. |
||
| #endif | ||
|
|
||
| // GDB_ENTRY; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this under
x86only? I think syscalls can exist on any architecture, and thus it would make sense to declare this for all architectures, and require architectures for which it makes no sense to initialize syscalls to stub an empty implementation.Maybe @elstr-512 has an opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair question. I kept this under
x86::for this PR because the implementation is x86_64-specific (IA32_STAR/IA32_LSTAR) and IncludeOS only runs the syscall path on x86 PC today.A broader shape would be something like
os::init_syscall_trap()in a neutral header with arch stubs (no-op on aarch64, real impl on x86_64). That's a nice cleanup but a separate refactor from "APs also get the MSRs."I've left it as-is here to keep the diff small. Happy to follow up with an arch-neutral API if that's the direction you and @elstr-512 prefer — would you want that as a follow-up PR after this merges?