qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 06/10] target-i386: Use gen_lea_v_seg in pusha/popa
Date: Thu,  9 Jul 2015 08:15:18 +0100	[thread overview]
Message-ID: <1436426122-12276-7-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1436426122-12276-1-git-send-email-rth@twiddle.net>

More centralization of handling of segment bases.
Also fixes the note about 16-bit wrap around not fully handled.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 target-i386/translate.c | 50 +++++++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index f690f85..e9e2eee 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -2300,45 +2300,41 @@ static inline void gen_stack_A0(DisasContext *s)
     gen_lea_v_seg(s, s->ss32 ? MO_32 : MO_16, cpu_regs[R_ESP], R_SS, -1);
 }
 
-/* NOTE: wrap around in 16 bit not fully handled */
 static void gen_pusha(DisasContext *s)
 {
+    TCGMemOp s_ot = s->ss32 ? MO_32 : MO_16;
+    TCGMemOp d_ot = s->dflag;
+    int size = 1 << d_ot;
     int i;
-    gen_op_movl_A0_reg(R_ESP);
-    gen_op_addl_A0_im(-8 << s->dflag);
-    if (!s->ss32)
-        tcg_gen_ext16u_tl(cpu_A0, cpu_A0);
-    tcg_gen_mov_tl(cpu_T[1], cpu_A0);
-    if (s->addseg)
-        gen_op_addl_A0_seg(s, R_SS);
-    for(i = 0;i < 8; i++) {
-        gen_op_mov_v_reg(MO_32, cpu_T[0], 7 - i);
-        gen_op_st_v(s, s->dflag, cpu_T[0], cpu_A0);
-        gen_op_addl_A0_im(1 << s->dflag);
+
+    for (i = 0; i < 8; i++) {
+        tcg_gen_addi_tl(cpu_A0, cpu_regs[R_ESP], (i - 8) * size);
+        gen_lea_v_seg(s, s_ot, cpu_A0, R_SS, -1);
+        gen_op_st_v(s, d_ot, cpu_regs[7 - i], cpu_A0);
     }
-    gen_op_mov_reg_v(MO_16 + s->ss32, R_ESP, cpu_T[1]);
+
+    gen_stack_update(s, -8 * size);
 }
 
-/* NOTE: wrap around in 16 bit not fully handled */
 static void gen_popa(DisasContext *s)
 {
+    TCGMemOp s_ot = s->ss32 ? MO_32 : MO_16;
+    TCGMemOp d_ot = s->dflag;
+    int size = 1 << d_ot;
     int i;
-    gen_op_movl_A0_reg(R_ESP);
-    if (!s->ss32)
-        tcg_gen_ext16u_tl(cpu_A0, cpu_A0);
-    tcg_gen_mov_tl(cpu_T[1], cpu_A0);
-    tcg_gen_addi_tl(cpu_T[1], cpu_T[1], 8 << s->dflag);
-    if (s->addseg)
-        gen_op_addl_A0_seg(s, R_SS);
-    for(i = 0;i < 8; i++) {
+
+    for (i = 0; i < 8; i++) {
         /* ESP is not reloaded */
-        if (i != 3) {
-            gen_op_ld_v(s, s->dflag, cpu_T[0], cpu_A0);
-            gen_op_mov_reg_v(s->dflag, 7 - i, cpu_T[0]);
+        if (7 - i == R_ESP) {
+            continue;
         }
-        gen_op_addl_A0_im(1 << s->dflag);
+        tcg_gen_addi_tl(cpu_A0, cpu_regs[R_ESP], i * size);
+        gen_lea_v_seg(s, s_ot, cpu_A0, R_SS, -1);
+        gen_op_ld_v(s, d_ot, cpu_T[0], cpu_A0);
+        gen_op_mov_reg_v(d_ot, 7 - i, cpu_T[0]);
     }
-    gen_op_mov_reg_v(MO_16 + s->ss32, R_ESP, cpu_T[1]);
+
+    gen_stack_update(s, 8 * size);
 }
 
 static void gen_enter(DisasContext *s, int esp_addend, int level)
-- 
2.4.3

  parent reply	other threads:[~2015-07-09  7:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09  7:15 [Qemu-devel] [PATCH 00/10] target-i386 addressing cleanups Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 01/10] target-i386: Create gen_lea_v_seg Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 02/10] target-i386: Introduce mo_stacksize Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 03/10] target-i386: Use gen_lea_v_seg in gen_lea_modrm Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 04/10] target-i386: Use gen_lea_v_seg in stack subroutines Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 05/10] target-i386: Access segs via TCG registers Richard Henderson
2015-07-09 13:30   ` Paolo Bonzini
2015-07-10  6:48     ` Richard Henderson
2015-07-09  7:15 ` Richard Henderson [this message]
2015-07-09  7:15 ` [Qemu-devel] [PATCH 07/10] target-i386: Rewrite gen_enter inline Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 08/10] target-i386: Rewrite leave Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 09/10] target-i386: Tidy gen_add_A0_im Richard Henderson
2015-07-09  7:15 ` [Qemu-devel] [PATCH 10/10] target-i386: Deconstruct the cpu_T array Richard Henderson
2015-07-09 13:32 ` [Qemu-devel] [PATCH 00/10] target-i386 addressing cleanups Paolo Bonzini
2015-09-24  4:10 ` Richard Henderson
2015-09-25 16:56   ` Peter Maydell

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=1436426122-12276-7-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).