setjmp: implement <setjmp.h>
This commit is contained in:
+1
-1
@@ -8,6 +8,6 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
extern _Noreturn void __assert_fail(const char *file, int line, const char *message);
|
||||
[[noreturn]] void __assert_fail(const char *file, int line, const char *message);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef _YGGDRASIL_SETJMP_H
|
||||
#define _YGGDRASIL_SETJMP_H 1
|
||||
|
||||
int setjmp(jmp_buf env);
|
||||
[[noreturn]] void longjmp(jmp_buf env, int val);
|
||||
|
||||
#endif
|
||||
+4
-1
@@ -1,5 +1,7 @@
|
||||
#![allow(nonstandard_style, unused_variables)]
|
||||
|
||||
// TODO limits.h is compiler-provided
|
||||
|
||||
pub mod sys_types;
|
||||
pub mod sys_wait;
|
||||
|
||||
@@ -10,6 +12,7 @@ pub mod fcntl;
|
||||
pub mod limits;
|
||||
pub mod locale;
|
||||
pub mod math;
|
||||
pub mod setjmp;
|
||||
pub mod stdio;
|
||||
pub mod stdlib;
|
||||
pub mod string;
|
||||
@@ -43,7 +46,7 @@ NEVER iso646.h - alternative spellings
|
||||
----- libgen.h - definitions for pattern matching functions
|
||||
PARTIAL limits.h - implementation-defined constants
|
||||
----- locale.h - category macros
|
||||
----- math.h - mathematical declarations
|
||||
----- math.h - mathematical declarations TODO there're parts of libm in yggdrasil-rt
|
||||
----- monetary.h - monetary types
|
||||
NEVER mqueue.h - message queues (REALTIME)
|
||||
NEVER ndbm.h - definitions for ndbm database operations
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
language = "C"
|
||||
style = "Type"
|
||||
|
||||
sys_includes = ["stdarg.h", "stddef.h"]
|
||||
no_includes = true
|
||||
|
||||
include_guard = "_SETJMP_H"
|
||||
trailer = "#include <bits/setjmp.h>"
|
||||
|
||||
usize_type = "size_t"
|
||||
isize_type = "ssize_t"
|
||||
|
||||
[export]
|
||||
include = ["jmp_buf"]
|
||||
exclude = []
|
||||
@@ -0,0 +1,7 @@
|
||||
use core::ffi::c_int;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
mod x86_64;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub type jmp_buf = *mut x86_64::__jmp_buf;
|
||||
@@ -0,0 +1,46 @@
|
||||
.global setjmp
|
||||
.global longjmp
|
||||
|
||||
.global _setjmp
|
||||
.global _longjmp
|
||||
|
||||
.section .text
|
||||
// args:
|
||||
// %rdi -- __jmp_buf *env
|
||||
setjmp:
|
||||
_setjmp:
|
||||
movq %rbx, 0(%rdi)
|
||||
movq %rbp, 8(%rdi)
|
||||
movq %r12, 16(%rdi)
|
||||
movq %r13, 24(%rdi)
|
||||
movq %r14, 32(%rdi)
|
||||
movq %r15, 40(%rdi)
|
||||
// Calculate return stack and rip
|
||||
leaq 8(%rsp), %rax
|
||||
movq %rax, 48(%rdi)
|
||||
movq (%rsp), %rax
|
||||
movq %rax, 56(%rdi)
|
||||
|
||||
movq $0, %rax
|
||||
ret
|
||||
|
||||
// args:
|
||||
// %rdi -- __jmp_buf *env
|
||||
// %rsi -- int val
|
||||
longjmp:
|
||||
_longjmp:
|
||||
// Restore registers
|
||||
movq 0(%rdi), %rbx
|
||||
movq 8(%rdi), %rbp
|
||||
movq 16(%rdi), %r12
|
||||
movq 24(%rdi), %r13
|
||||
movq 32(%rdi), %r14
|
||||
movq 40(%rdi), %r15
|
||||
movq 48(%rdi), %rsp
|
||||
movq 56(%rdi), %rax
|
||||
pushq %rax
|
||||
|
||||
// Setup return value
|
||||
movq %rsi, %rax
|
||||
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
use core::{arch::global_asm, ffi::c_int};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct __jmp_buf {
|
||||
rip: usize,
|
||||
rsp: usize,
|
||||
r15: usize,
|
||||
r14: usize,
|
||||
r13: usize,
|
||||
r12: usize,
|
||||
rbp: usize,
|
||||
rbx: usize,
|
||||
}
|
||||
|
||||
global_asm!(include_str!("x86_64.S"), options(att_syntax));
|
||||
Reference in New Issue
Block a user