Implement setjmp(3) and longjmp(3).
This commit is contained in:
parent
70a661e1ab
commit
aca2a41401
|
@ -166,6 +166,7 @@ clock.o \
|
||||||
close.o \
|
close.o \
|
||||||
$(CPUDIR)/calltrace.o \
|
$(CPUDIR)/calltrace.o \
|
||||||
$(CPUDIR)/fork.o \
|
$(CPUDIR)/fork.o \
|
||||||
|
$(CPUDIR)/setjmp.o \
|
||||||
$(CPUDIR)/signal.o \
|
$(CPUDIR)/signal.o \
|
||||||
$(CPUDIR)/syscall.o \
|
$(CPUDIR)/syscall.o \
|
||||||
creat.o \
|
creat.o \
|
||||||
|
@ -293,7 +294,6 @@ select.o \
|
||||||
setegid.o \
|
setegid.o \
|
||||||
seteuid.o \
|
seteuid.o \
|
||||||
setgid.o \
|
setgid.o \
|
||||||
setjmp.o \
|
|
||||||
setlocale.o \
|
setlocale.o \
|
||||||
settermmode.o \
|
settermmode.o \
|
||||||
setuid.o \
|
setuid.o \
|
||||||
|
|
|
@ -29,12 +29,13 @@
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
struct jmp_buf_struct
|
#if defined(__x86_64__)
|
||||||
{
|
typedef unsigned long jmp_buf[8];
|
||||||
int unused;
|
#elif defined(__i386__)
|
||||||
};
|
typedef unsigned long jmp_buf[6];
|
||||||
|
#else
|
||||||
typedef struct jmp_buf_struct jmp_buf[1];
|
#error "You need to implement jmp_buf on your CPU"
|
||||||
|
#endif
|
||||||
|
|
||||||
void longjmp(jmp_buf env, int val);
|
void longjmp(jmp_buf env, int val);
|
||||||
int setjmp(jmp_buf env);
|
int setjmp(jmp_buf env);
|
||||||
|
|
|
@ -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.
|
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
|
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/>.
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
setjmp.c
|
x86/setjmp.s
|
||||||
Stack environment declarations.
|
Implement the assembly part of setjmp.
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
.global setjmp
|
||||||
#include <stdlib.h>
|
.type setjmp, @function
|
||||||
#include <setjmp.h>
|
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)
|
.global longjmp
|
||||||
{
|
.type longjmp, @function
|
||||||
(void) env;
|
longjmp:
|
||||||
(void) val;
|
mov 4(%esp), %ecx
|
||||||
fprintf(stderr, "setjmp(3) and longjmp(3) are unimplemented, abort!\n");
|
mov 8(%esp), %edx
|
||||||
abort();
|
testl %edx, %edx
|
||||||
}
|
jnz 1f
|
||||||
|
mov $1, %edx
|
||||||
int setjmp(jmp_buf env)
|
1:
|
||||||
{
|
# TODO: Floating point stuff!
|
||||||
(void) env;
|
mov 0x04(%ecx), %esi
|
||||||
return 0;
|
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…
Reference in New Issue