mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Implement setjmp(3) and longjmp(3).
This commit is contained in:
parent
70a661e1ab
commit
aca2a41401
4 changed files with 108 additions and 26 deletions
|
@ -166,6 +166,7 @@ clock.o \
|
|||
close.o \
|
||||
$(CPUDIR)/calltrace.o \
|
||||
$(CPUDIR)/fork.o \
|
||||
$(CPUDIR)/setjmp.o \
|
||||
$(CPUDIR)/signal.o \
|
||||
$(CPUDIR)/syscall.o \
|
||||
creat.o \
|
||||
|
@ -293,7 +294,6 @@ select.o \
|
|||
setegid.o \
|
||||
seteuid.o \
|
||||
setgid.o \
|
||||
setjmp.o \
|
||||
setlocale.o \
|
||||
settermmode.o \
|
||||
setuid.o \
|
||||
|
|
|
@ -29,12 +29,13 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct jmp_buf_struct
|
||||
{
|
||||
int unused;
|
||||
};
|
||||
|
||||
typedef struct jmp_buf_struct jmp_buf[1];
|
||||
#if defined(__x86_64__)
|
||||
typedef unsigned long jmp_buf[8];
|
||||
#elif defined(__i386__)
|
||||
typedef unsigned long jmp_buf[6];
|
||||
#else
|
||||
#error "You need to implement jmp_buf on your CPU"
|
||||
#endif
|
||||
|
||||
void longjmp(jmp_buf env, int val);
|
||||
int setjmp(jmp_buf env);
|
||||
|
|
62
libc/x64/setjmp.s
Normal file
62
libc/x64/setjmp.s
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
x64/setjmp.s
|
||||
Implement the assembly part of setjmp.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
.global setjmp
|
||||
.type setjmp, @function
|
||||
setjmp:
|
||||
# TODO: Floating point stuff!
|
||||
mov %rbx, 0x00(%rdi)
|
||||
mov %rsp, 0x08(%rdi)
|
||||
mov %rbp, 0x10(%rdi)
|
||||
mov %r12, 0x18(%rdi)
|
||||
mov %r13, 0x20(%rdi)
|
||||
mov %r14, 0x28(%rdi)
|
||||
mov %r15, 0x30(%rdi)
|
||||
mov 0(%rsp), %rax
|
||||
mov %rax, 0x38(%rdi)
|
||||
xorl %eax, %eax
|
||||
.Lsetjmp_return:
|
||||
ret
|
||||
.size setjmp, . - setjmp
|
||||
|
||||
.global longjmp
|
||||
.type longjmp, @function
|
||||
longjmp:
|
||||
testl %esi, %esi
|
||||
jnz 1f
|
||||
mov $1, %esi
|
||||
1:
|
||||
# TODO: Floating point stuff!
|
||||
mov 0x00(%rdi), %rbx
|
||||
mov 0x08(%rdi), %rsp
|
||||
mov 0x10(%rdi), %rbp
|
||||
mov 0x18(%rdi), %r12
|
||||
mov 0x20(%rdi), %r13
|
||||
mov 0x28(%rdi), %r14
|
||||
mov 0x30(%rdi), %r15
|
||||
mov 0x38(%rdi), %rax
|
||||
mov %rax, 0(%rsp)
|
||||
mov %esi, %eax
|
||||
jmp .Lsetjmp_return
|
||||
.size longjmp, . - longjmp
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -17,25 +17,44 @@
|
|||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
setjmp.c
|
||||
Stack environment declarations.
|
||||
x86/setjmp.s
|
||||
Implement the assembly part of setjmp.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
.global setjmp
|
||||
.type setjmp, @function
|
||||
setjmp:
|
||||
mov 4(%esp), %ecx
|
||||
# TODO: Floating point stuff!
|
||||
mov %ebx, 0x00(%ecx)
|
||||
mov %esi, 0x04(%ecx)
|
||||
mov %edi, 0x08(%ecx)
|
||||
mov %ebp, 0x0C(%ecx)
|
||||
mov %esp, 0x10(%ecx)
|
||||
mov 0(%esp), %eax
|
||||
mov %eax, 0x14(%ecx)
|
||||
xorl %eax, %eax
|
||||
.Lsetjmp_return:
|
||||
ret
|
||||
.size setjmp, . - setjmp
|
||||
|
||||
void longjmp(jmp_buf env, int val)
|
||||
{
|
||||
(void) env;
|
||||
(void) val;
|
||||
fprintf(stderr, "setjmp(3) and longjmp(3) are unimplemented, abort!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
int setjmp(jmp_buf env)
|
||||
{
|
||||
(void) env;
|
||||
return 0;
|
||||
}
|
||||
.global longjmp
|
||||
.type longjmp, @function
|
||||
longjmp:
|
||||
mov 4(%esp), %ecx
|
||||
mov 8(%esp), %edx
|
||||
testl %edx, %edx
|
||||
jnz 1f
|
||||
mov $1, %edx
|
||||
1:
|
||||
# TODO: Floating point stuff!
|
||||
mov 0x04(%ecx), %esi
|
||||
mov 0x08(%ecx), %edi
|
||||
mov 0x0C(%ecx), %ebp
|
||||
mov 0x10(%ecx), %esp
|
||||
mov 0x14(%ecx), %eax
|
||||
mov %eax, 0(%esp)
|
||||
mov %edx, %eax
|
||||
jmp .Lsetjmp_return
|
||||
.size longjmp, . - longjmp
|
Loading…
Add table
Reference in a new issue