More x86 fixes

This commit is contained in:
Jeremy Soller
2022-08-20 20:51:01 -06:00
parent c1b20cdeab
commit a1d0b8fc35
3 changed files with 58 additions and 4 deletions
+22
View File
@@ -5,6 +5,27 @@
use core::arch::global_asm;
#[cfg(target_arch = "x86_64")]
global_asm!(
r#"
.section .init
.global _init
_init:
push ebp
mov ebp, esp
// Created a new stack frame and updated the stack pointer
// Body will be filled in by gcc and ended by crtn.o
.section .fini
.global _fini
_fini:
push ebp
mov ebp, esp
// Created a new stack frame and updated the stack pointer
// Body will be filled in by gcc and ended by crtn.o
"#
);
// https://wiki.osdev.org/Creating_a_C_Library#crtbegin.o.2C_crtend.o.2C_crti.o.2C_and_crtn.o
#[cfg(target_arch = "x86_64")]
global_asm!(
@@ -26,6 +47,7 @@ global_asm!(
// Body will be filled in by gcc and ended by crtn.o
"#
);
// https://git.musl-libc.org/cgit/musl/tree/crt/aarch64/crti.s
#[cfg(target_arch = "aarch64")]
global_asm!(
+18
View File
@@ -5,6 +5,23 @@
use core::arch::global_asm;
#[cfg(target_arch = "x86")]
global_asm!(
r#"
.section .init
// This happens after crti.o and gcc has inserted code
// Pop the stack frame
pop ebp
ret
.section .fini
// This happens after crti.o and gcc has inserted code
// Pop the stack frame
pop ebp
ret
"#
);
// https://wiki.osdev.org/Creating_a_C_Library#crtbegin.o.2C_crtend.o.2C_crti.o.2C_and_crtn.o
#[cfg(target_arch = "x86_64")]
global_asm!(
@@ -22,6 +39,7 @@ global_asm!(
ret
"#
);
// https://git.musl-libc.org/cgit/musl/tree/crt/aarch64/crtn.s
#[cfg(target_arch = "aarch64")]
global_asm!(
+18 -4
View File
@@ -195,11 +195,10 @@ impl Tcb {
Ok(tls_tcb.split_at_mut(size))
}
/// Architecture specific code to read a usize from the TCB - x86_64
/// Architecture specific code to read a usize from the TCB - aarch64
#[inline(always)]
#[cfg(target_arch = "aarch64")]
unsafe fn arch_read(offset: usize) -> usize {
// TODO: s/llvm_asm/asm/g
let tp: usize;
asm!(
"mrs {}, tpidr_el0",
@@ -209,9 +208,24 @@ impl Tcb {
*((tp + offset) as *const usize)
}
/// Architecture specific code to read a usize from the TCB - x86
#[inline(always)]
#[cfg(any(target_arch = "x86")]
unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, gs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - x86_64
#[inline(always)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(any(target_arch = "x86_64")]
unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
@@ -248,7 +262,7 @@ impl Tcb {
let _ = syscall::read(file, &mut env)
.expect_notls("failed to read fsbase");
env.fsbase = tp as u32;
env.gsbase = tp as u32;
let _ = syscall::write(file, &env)
.expect_notls("failed to write fsbase");