From: Paolo Bonzini <pbonzini@redhat.com>
To: Arthur Chunqi Li <yzt356@gmail.com>
Cc: kvm@vger.kernel.org, jan.kiszka@web.de, gleb@redhat.com
Subject: Re: [PATCH v2 1/2] kvm-unit-tests : Add setjmp/longjmp to libcflat
Date: Tue, 16 Jul 2013 17:19:43 +0200 [thread overview]
Message-ID: <51E5648F.6050307@redhat.com> (raw)
In-Reply-To: <1373987466-2216-2-git-send-email-yzt356@gmail.com>
Il 16/07/2013 17:11, Arthur Chunqi Li ha scritto:
> Add setjmp and longjmp functions to libcflat. Now these two functions
> are only supported in X86_64 arch.
>
> New files added:
> lib/x86/setjmp64.S
> lib/x86/setjmp64.c
>
> Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
> ---
> config-x86_64.mak | 2 ++
> lib/x86/setjmp64.S | 27 +++++++++++++++++++++++++++
> lib/x86/setjmp64.h | 15 +++++++++++++++
> 3 files changed, 44 insertions(+)
> create mode 100644 lib/x86/setjmp64.S
> create mode 100644 lib/x86/setjmp64.h
>
> diff --git a/config-x86_64.mak b/config-x86_64.mak
> index 4e525f5..91ffcce 100644
> --- a/config-x86_64.mak
> +++ b/config-x86_64.mak
> @@ -4,6 +4,8 @@ bits = 64
> ldarch = elf64-x86-64
> CFLAGS += -D__x86_64__
>
> +cflatobjs += lib/x86/setjmp64.o
> +
> tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \
> $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \
> $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \
> diff --git a/lib/x86/setjmp64.S b/lib/x86/setjmp64.S
> new file mode 100644
> index 0000000..c8ae790
> --- /dev/null
> +++ b/lib/x86/setjmp64.S
> @@ -0,0 +1,27 @@
> +.globl setjmp
> +setjmp:
> + mov (%rsp), %rsi
> + mov %rsi, (%rdi)
> + mov %rsp, 0x8(%rdi)
> + mov %rbp, 0x10(%rdi)
> + mov %rbx, 0x18(%rdi)
> + mov %r12, 0x20(%rdi)
> + mov %r13, 0x28(%rdi)
> + mov %r14, 0x30(%rdi)
> + mov %r15, 0x38(%rdi)
> + xor %eax, %eax
> + ret
> +
> +.globl longjmp
> +longjmp:
> + mov %esi, %eax
> + mov 0x38(%rdi), %r15
> + mov 0x30(%rdi), %r14
> + mov 0x28(%rdi), %r13
> + mov 0x20(%rdi), %r12
> + mov 0x18(%rdi), %rbx
> + mov 0x10(%rdi), %rbp
> + mov 0x8(%rdi), %rsp
> + mov (%rdi), %rsi
> + mov %rsi, (%rsp)
> + ret
Nice!
> diff --git a/lib/x86/setjmp64.h b/lib/x86/setjmp64.h
> new file mode 100644
> index 0000000..98ff16a
> --- /dev/null
> +++ b/lib/x86/setjmp64.h
> @@ -0,0 +1,15 @@
> +#ifndef LIBCFLAT_SETJMP64_H
> +#define LIBCFLAT_SETJMP64_H
> +
> +#include "libcflat.h"
> +
> +struct jmp_buf {
> + u64 calling_rip;
> + u64 rsp, rbp, rbx;
> + u64 r12, r13, r14, r15;
> +};
Please make it a typedef instead. In fact, jmp_buf is typically an
array so that longjmp(env, 1) works without the ampersand. A
"struct-like" declaration can go in setjmp64.S as a comment.
With this change, you can put it in lib/setjmp.h so that implementation
for other arches can be added later.
Otherwise looks good, thanks!
Paolo
> +void longjmp(struct jmp_buf *env, int val);
> +int setjmp(struct jmp_buf *env);
> +
> +#endif
>
next prev parent reply other threads:[~2013-07-16 15:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-16 15:11 [PATCH v2 0/2] Basic nested VMX test suite Arthur Chunqi Li
2013-07-16 15:11 ` [PATCH v2 1/2] kvm-unit-tests : Add setjmp/longjmp to libcflat Arthur Chunqi Li
2013-07-16 15:19 ` Paolo Bonzini [this message]
2013-07-16 15:11 ` [PATCH v2 2/2] kvm-unit-tests : The first version of VMX nested test case Arthur Chunqi Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51E5648F.6050307@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
--cc=yzt356@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.