xv6/setjmp.S

50 lines
1.1 KiB
ArmAsm
Raw Normal View History

2006-09-07 14:12:30 +00:00
# int setjmp(struct jmpbuf *jmp);
# void longjmp(struct jmpbuf *jmp);
#
2006-09-08 14:20:43 +00:00
# Setjmp saves its stack environment in jmp for later use by longjmp.
# It returns 0.
2006-09-07 14:12:30 +00:00
#
2006-09-08 14:20:43 +00:00
# Longjmp restores the environment saved by the last call of setjmp.
# It then causes execution to continue as if the call of setjmp
2006-09-07 14:12:30 +00:00
# had just returned 1.
#
2006-09-08 14:20:43 +00:00
# The caller of setjmp must not itself have returned in the interim.
# All accessible data have values as of the time longjmp was called.
2006-09-07 14:12:30 +00:00
#
# [Description, but not code, borrowed from Plan 9.]
2006-07-11 01:07:40 +00:00
.globl setjmp
setjmp:
movl 4(%esp), %eax
2006-09-06 17:27:19 +00:00
movl %ebx, 0(%eax)
movl %ecx, 4(%eax)
movl %edx, 8(%eax)
movl %esi, 12(%eax)
movl %edi, 16(%eax)
movl %esp, 20(%eax)
movl %ebp, 24(%eax)
2006-09-07 14:12:30 +00:00
pushl 0(%esp) # %eip
popl 28(%eax)
2006-09-06 17:27:19 +00:00
2006-09-07 14:12:30 +00:00
movl $0, %eax # return value
ret
2006-07-11 01:07:40 +00:00
.globl longjmp
longjmp:
movl 4(%esp), %eax
2006-09-06 17:27:19 +00:00
movl 0(%eax), %ebx
movl 4(%eax), %ecx
movl 8(%eax), %edx
movl 12(%eax), %esi
movl 16(%eax), %edi
movl 20(%eax), %esp
movl 24(%eax), %ebp
2006-07-11 01:07:40 +00:00
2006-09-07 14:12:30 +00:00
addl $4, %esp # pop and discard %eip
pushl 28(%eax) # push new %eip
2006-09-06 17:27:19 +00:00
2006-09-07 14:12:30 +00:00
movl $1, %eax # return value (appears to come from setjmp!)
ret