Split into HostContextGuard/GuestContextGuard

This commit is contained in:
2025-10-05 14:32:06 -06:00
parent cd7baffc5e
commit 0bc80b6618
46 changed files with 693 additions and 623 deletions

View File

@@ -346,14 +346,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Failed to install TIB for main thread\n");
return 1;
}
uint16_t hostFsSelector = 0;
uint16_t hostGsSelector = 0;
asm volatile("mov %%fs, %0" : "=r"(hostFsSelector));
asm volatile("mov %%gs, %0" : "=r"(hostGsSelector));
tib.hostFsSelector = hostFsSelector;
tib.hostGsSelector = hostGsSelector;
tib.hostSegmentsValid = 1;
wibo::setThreadTibForHost(&tib);
// Determine the guest program name
auto guestArgs = wibo::splitCommandLine(cmdLine.c_str());
@@ -490,10 +483,9 @@ int main(int argc, char **argv) {
}
// Invoke the damn thing
asm("movw %0, %%fs; call *%1" : : "r"(wibo::tibSelector), "r"(entryPoint));
if (tib.hostSegmentsValid) {
asm volatile("movw %0, %%fs" : : "r"(tib.hostFsSelector) : "memory");
asm volatile("movw %0, %%gs" : : "r"(tib.hostGsSelector) : "memory");
{
GUEST_CONTEXT_GUARD(&tib);
asm volatile("call *%0" : : "r"(entryPoint) : "memory");
}
DEBUG_LOG("We came back\n");
wibo::shutdownModuleRegistry();