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

Everywhere: Make the codebase more architecture aware

This commit is contained in:
Undefine 2022-07-22 20:48:24 +02:00 committed by Brian Gianforcaro
parent 6c4b5775e1
commit 97cc33ca47
22 changed files with 108 additions and 36 deletions

View file

@ -85,8 +85,10 @@ ErrorOr<void> Coredump::write_elf_header()
elf_file_header.e_ident[EI_MAG3] = 'F';
#if ARCH(I386)
elf_file_header.e_ident[EI_CLASS] = ELFCLASS32;
#else
#elif ARCH(X86_64) || ARCH(AARCH64)
elf_file_header.e_ident[EI_CLASS] = ELFCLASS64;
#else
# error Unknown architecture
#endif
elf_file_header.e_ident[EI_DATA] = ELFDATA2LSB;
elf_file_header.e_ident[EI_VERSION] = EV_CURRENT;
@ -101,8 +103,12 @@ ErrorOr<void> Coredump::write_elf_header()
elf_file_header.e_type = ET_CORE;
#if ARCH(I386)
elf_file_header.e_machine = EM_386;
#else
#elif ARCH(X86_64)
elf_file_header.e_machine = EM_X86_64;
#elif ARCH(AARCH64)
elf_file_header.e_machine = EM_AARCH64;
#else
# error Unknown architecture
#endif
elf_file_header.e_version = 1;
elf_file_header.e_entry = 0;

View file

@ -20,8 +20,10 @@
#if ARCH(I386)
static constexpr size_t CHUNK_SIZE = 32;
#else
#elif ARCH(X86_64) || ARCH(AARCH64)
static constexpr size_t CHUNK_SIZE = 64;
#else
# error Unknown architecture
#endif
static_assert(is_power_of_two(CHUNK_SIZE));

View file

@ -191,8 +191,10 @@ RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, Non
first_thread->regs().set_ip((FlatPtr)entry);
#if ARCH(I386)
first_thread->regs().esp = FlatPtr(entry_data); // entry function argument is expected to be in regs.esp
#else
#elif ARCH(X86_64)
first_thread->regs().rdi = FlatPtr(entry_data); // entry function argument is expected to be in regs.rdi
#else
# error Unknown architecture
#endif
if (do_register == RegisterProcess::Yes)

View file

@ -149,10 +149,12 @@ static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]]
push_on_new_stack(envp);
push_on_new_stack(argv);
push_on_new_stack(argv_entries.size());
#else
#elif ARCH(X86_64)
regs.rdi = argv_entries.size();
regs.rsi = argv;
regs.rdx = envp;
#else
# error Unknown architecture
#endif
VERIFY(new_sp % 16 == 0);

View file

@ -89,7 +89,7 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
dbgln_if(FORK_DEBUG, "fork: child will begin executing at {:#04x}:{:p} with stack {:#04x}:{:p}, kstack {:#04x}:{:p}",
child_regs.cs, child_regs.eip, child_regs.ss, child_regs.esp, child_regs.ss0, child_regs.esp0);
#else
#elif ARCH(X86_64)
auto& child_regs = child_first_thread->m_regs;
child_regs.rax = 0; // fork() returns 0 in the child :^)
child_regs.rbx = regs.rbx;
@ -113,6 +113,8 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
dbgln_if(FORK_DEBUG, "fork: child will begin executing at {:#04x}:{:p} with stack {:p}, kstack {:p}",
child_regs.cs, child_regs.rip, child_regs.rsp, child_regs.rsp0);
#else
# error Unknown architecture
#endif
{

View file

@ -19,8 +19,12 @@ ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
memcpy(buf.version, "FIXME", 6);
#if ARCH(I386)
memcpy(buf.machine, "i686", 5);
#else
#elif ARCH(X86_64)
memcpy(buf.machine, "x86_64", 7);
#elif ARCH(AARCH64)
memcpy(buf.machine, "AArch64", 7);
#else
# error Unknown architecture
#endif
hostname().with_shared([&](auto const& name) {

View file

@ -96,11 +96,13 @@ Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Memory::Region> ker
m_regs.ss = GDT_SELECTOR_DATA3 | 3;
m_regs.gs = GDT_SELECTOR_TLS | 3;
}
#else
#elif ARCH(X86_64)
if (m_process->is_kernel_process())
m_regs.cs = GDT_SELECTOR_CODE0;
else
m_regs.cs = GDT_SELECTOR_CODE3 | 3;
#else
# error Unknown architecture
#endif
m_regs.cr3 = m_process->address_space().page_directory().cr3();

View file

@ -93,7 +93,7 @@ static u64 read_register_safe64(HPETRegister const& reg)
{
#if ARCH(X86_64)
return reg.full;
#else
#elif ARCH(I386)
// As per 2.4.7 this reads the 64 bit value in a consistent manner
// using only 32 bit reads
u32 low, high = reg.high;
@ -105,6 +105,8 @@ static u64 read_register_safe64(HPETRegister const& reg)
high = new_high;
}
return ((u64)high << 32) | (u64)low;
#else
# error Unknown architecture
#endif
}