summaryrefslogtreecommitdiff
path: root/emulators/kqemu-kmod-devel/files/extra-patch-jk-200905-02
blob: 84a8568879e79c403075e37e76252a95859c16f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From: jan.kiszka@siemens.com (Jan Kiszka)
Subject: [Qemu-devel] [PATCH 2/5] kqemu: i386: Reorder DS and ES on
	exception stack
Date: Fri, 29 May 2009 19:18:31 +0200
Message-ID: <20090529171831.14265.74474.stgit@mchn012c.ww002.siemens.net>
To: qemu-devel@nongnu.org

This is a KQEMU upstream bug: In case the non-trivial paths of
LOAD_SEG_CACHE in exception_return are taken for both DS and ES, the
current code will break as it assumes to read from the monitor's DS in
the restore code for ES. Fix this by swapping both segments on the stack
so that ES is always restored before DS.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 common/i386/monitor_asm.S |   16 ++++++++--------
 common/kqemu_int.h        |    6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git common/i386/monitor_asm.S b/common/i386/monitor_asm.S
index 04f4258..e996553 100644
Index: common/i386/monitor_asm.S
--- common/i386/monitor_asm.S
+++ common/i386/monitor_asm.S
@@ -214,8 +214,8 @@ __monitor_exception:
         pushl %edx
         pushl %ecx
         pushl %eax
-        pushl %es
         pushl %ds
+        pushl %es
 
 /* compute the address of the monitor context */
         call 1f
@@ -260,17 +260,17 @@ exception_return:
         cmpb $3, KQEMU_STATE_cpu_state_cpl(%ebx)
         je normal_seg_load
         popl %eax
-        LOAD_SEG_CACHE(%ds, R_DS, (11 * 4))
+        LOAD_SEG_CACHE(%es, R_ES, (11 * 4))
         popl %eax
-        LOAD_SEG_CACHE(%es, R_ES, (10 * 4))
+        LOAD_SEG_CACHE(%ds, R_DS, (10 * 4))
         jmp 2f
 normal_seg_load:        
 #endif        
 1:
-        popl %ds
+        popl %es
         SEG_EXCEPTION(1b)
 1:
-        popl %es
+        popl %ds
         SEG_EXCEPTION(1b)
 2:      
                 
@@ -295,10 +295,10 @@ SEG_EXCEPTION(1b)
 
 exception_return_to_monitor:
 1:
-        popl %ds
+        popl %es
         SEG_EXCEPTION(1b)
 1:
-        popl %es
+        popl %ds
         SEG_EXCEPTION(1b)
         popl %eax
         popl %ecx
@@ -363,8 +363,8 @@ __monitor_interrupt:
         pushl %edx
         pushl %ecx
         pushl %eax
-        pushl %es
         pushl %ds
+        pushl %es
         
 /* compute the address of the monitor context */
         call 1f
diff --git common/kqemu_int.h common/kqemu_int.h
index f19f7ca..4b59cb3 100644
Index: common/kqemu_int.h
--- common/kqemu_int.h
+++ common/kqemu_int.h
@@ -367,10 +367,10 @@ struct kqemu_exception_regs {
 };
 #else
 struct kqemu_exception_regs {
-    uint16_t ds_sel; /* 0 */
-    uint16_t ds_sel_h;
-    uint16_t es_sel; /* 1 */
+    uint16_t es_sel; /* 0 */
     uint16_t es_sel_h;
+    uint16_t ds_sel; /* 1 */
+    uint16_t ds_sel_h;
     uint32_t eax;    /* 2 */
     uint32_t ecx;
     uint32_t edx;