[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MiNT] cflib/gemlib/gemma trap sanitizer
Here is my patch to fix the potential problems with trashed registers on
trap calls in the lib directory (cflib/gemlib/gemma).
For gemlib and cflib, I added d1/d2/a2 to the list of potential trashed
registers. I don't know if it will fix something, but it can't harm, and it
seems to be the official way to do.
In gemma, the clobber list was clearly wrong, so programs using it may be
fixed with this patch.
I have tested this patch very few due to lack of test programs, but it
compiles well, and I really believe it is correct.
Dear maintainers, please commit this patch.
Beware: the file gemlib/_lc_asm.s has CR/LF line endings, they may be
removed by sending the patch on the list.
Please use the following CVS description:
--------------------
Always assume that d0-d2/a0-a2 can be modified on trap calls.
Replaced some assembler instructions by faster ones.
--------------------
Note: ColdFire support in included only for GemLib, as I have not ported the
other libs yet.
--
Vincent Rivière
diff -aurN -x CVS lib.orig/cflib/nkcc-gc.s lib/cflib/nkcc-gc.s
--- lib.orig/cflib/nkcc-gc.s 2004-05-17 10:23:39.000000000 +0200
+++ lib/cflib/nkcc-gc.s 2009-12-19 16:07:04.828125000 +0100
@@ -118,6 +118,7 @@
_nkc_init:
|------------- fetch addresses of TOS' key scan code translation tables
+ moveml d2/a2,sp@- | backup registers
moveql #-1,d0 | the function is also used to
movel d0,sp@- | change the addresses| values
movel d0,sp@- | of -1 as new addresses tell
@@ -131,8 +132,8 @@
movel a0@+,pkey_shift | get ^shifted table
movel a0@,pkey_caps | get ^CapsLock table
-exit1:
movew #VERSION,d0 | load version #
+ moveml sp@+,d2/a2 | restore registers
rts | bye
|***************************************************************************
diff -aurN -x CVS lib.orig/cflib/nkcc-pc.s lib/cflib/nkcc-pc.s
--- lib.orig/cflib/nkcc-pc.s 2000-09-21 13:23:20.000000000 +0200
+++ lib/cflib/nkcc-pc.s 2009-12-19 16:13:18.187500000 +0100
@@ -119,6 +119,8 @@
*------------- fetch addresses of TOS' key scan code translation tables
+ movem.l d2/a2,-(sp) ; backup registers
+
moveq.l #-1,d0 ; the function is also used to
move.l d0,-(sp) ; change the addresses; values
move.l d0,-(sp) ; of -1 as new addresses tell
@@ -132,6 +134,8 @@
move.l (a0)+,pkey_shift ; get ^shifted table
move.l (a0),pkey_caps ; get ^CapsLock table
+ movem.l (sp)+,d2/a2 ; restore registers
+
*------------- exit
.exit: move #VERSION,d0 ; load version #
diff -aurN -x CVS lib.orig/gemlib/_gc_asm_aes.S lib/gemlib/_gc_asm_aes.S
--- lib.orig/gemlib/_gc_asm_aes.S 2000-09-15 00:07:47.000000000 +0200
+++ lib/gemlib/_gc_asm_aes.S 2009-12-19 17:43:17.750000000 +0100
@@ -4,5 +4,17 @@
_aes:
movel sp@(4), d1 | hier kommt pb ?ber den Stack!
movew #200, d0
+#ifdef __mcoldfire__
+ movel a2, sp@- | backup registers
+ movel d2, sp@-
+#else
+ moveml d2/a2, sp@- | backup registers
+#endif
trap #2
+#ifdef __mcoldfire__
+ movel sp@+, d2 | restore registers
+ movel sp@+, a2
+#else
+ moveml sp@+, d2/a2 | restore registers
+#endif
rts
diff -aurN -x CVS lib.orig/gemlib/_gc_asm_vdi.S lib/gemlib/_gc_asm_vdi.S
--- lib.orig/gemlib/_gc_asm_vdi.S 2000-09-15 00:07:47.000000000 +0200
+++ lib/gemlib/_gc_asm_vdi.S 2009-12-19 17:43:13.765625000 +0100
@@ -3,6 +3,18 @@
_vdi:
movel sp@(4), d1
- movew #115, d0
+ moveq #115, d0
+#ifdef __mcoldfire__
+ movel a2, sp@- | backup registers
+ movel d2, sp@-
+#else
+ moveml d2/a2, sp@- | backup registers
+#endif
trap #2
+#ifdef __mcoldfire__
+ movel sp@+, d2 | restore registers
+ movel sp@+, a2
+#else
+ moveml sp@+, d2/a2 | restore registers
+#endif
rts
diff -aurN -x CVS lib.orig/gemlib/_gc_asm_vq_gdos.S lib/gemlib/_gc_asm_vq_gdos.S
--- lib.orig/gemlib/_gc_asm_vq_gdos.S 2000-09-15 00:07:47.000000000 +0200
+++ lib/gemlib/_gc_asm_vq_gdos.S 2009-12-19 17:39:40.421875000 +0100
@@ -2,8 +2,20 @@
.globl _vq_gdos
_vq_gdos:
- movew #-2,d0
+ moveq #-2,d0
+#ifdef __mcoldfire__
+ movel a2,sp@- | backup registers
+ movel d2,sp@-
+#else
+ moveml d2/a2,sp@- | backup registers
+#endif
trap #2
+#ifdef __mcoldfire__
+ movel sp@+,d2 | restore registers
+ movel sp@+,a2
+#else
+ moveml sp@+,d2/a2 | restore registers
+#endif
cmpw #-2,d0
sne d0
extw d0
diff -aurN -x CVS lib.orig/gemlib/_gc_asm_vq_vgdos.S lib/gemlib/_gc_asm_vq_vgdos.S
--- lib.orig/gemlib/_gc_asm_vq_vgdos.S 2000-09-15 00:07:47.000000000 +0200
+++ lib/gemlib/_gc_asm_vq_vgdos.S 2009-12-19 17:38:56.375000000 +0100
@@ -3,5 +3,17 @@
_vq_vgdos:
moveq #-2,d0
+#ifdef __mcoldfire__
+ movel a2,sp@- | backup registers
+ movel d2,sp@-
+#else
+ moveml d2/a2,sp@- | backup registers
+#endif
trap #2
+#ifdef __mcoldfire__
+ movel sp@+,d2 | restore registers
+ movel sp@+,a2
+#else
+ moveml sp@+,d2/a2 | restore registers
+#endif
rts
diff -aurN -x CVS lib.orig/gemlib/_lc_asm.s lib/gemlib/_lc_asm.s
--- lib.orig/gemlib/_lc_asm.s 2006-04-25 22:39:41.000000000 +0200
+++ lib/gemlib/_lc_asm.s 2009-12-19 17:03:05.937500000 +0100
@@ -15,14 +15,14 @@
_vdi: ;we *think* the vdi doesn't clobber a2/d2
move.l 4(sp),d1
movem.l d2/a2,-(a7) ;but we'll do this anyway until we've got gemlib sorted out
- move.w #115,d0
+ moveq #115,d0
trap #2
movem.l (a7)+,d2/a2
rts
_vq_gdos:
movem.l d2/a2,-(a7) ;precautionary
- move.w #-2,d0
+ moveq #-2,d0
trap #2
cmp.w #-2,d0
sne d0
diff -aurN -x CVS lib.orig/gemlib/_pc_asm.s lib/gemlib/_pc_asm.s
--- lib.orig/gemlib/_pc_asm.s 2000-09-15 00:07:47.000000000 +0200
+++ lib/gemlib/_pc_asm.s 2009-12-19 17:02:48.156250000 +0100
@@ -6,18 +6,24 @@
aes:
move.l a0,d1 ; pb in A0 und nicht auf Stack!
move.w #200,d0
+ movem.l d2/a2,-(sp) ; backup registers
trap #2
+ movem.l (sp)+,d2/a2 ; restore registers
rts
vdi:
move.l a0,d1
- move.w #115,d0
+ moveq #115,d0
+ movem.l d2/a2,-(sp) ; backup registers
trap #2
+ movem.l (sp)+,d2/a2 ; restore registers
rts
vq_gdos:
- move.w #-2,d0
+ moveq #-2,d0
+ movem.l d2/a2,-(sp) ; backup registers
trap #2
+ movem.l (sp)+,d2/a2 ; restore registers
cmp.w #-2,d0
sne d0
ext.w d0
@@ -25,5 +31,7 @@
vq_vgdos:
moveq #-2,d0
+ movem.l d2/a2,-(sp) ; backup registers
trap #2
+ movem.l (sp)+,d2/a2 ; restore registers
rts
diff -aurN -x CVS lib.orig/gemlib/_sx_asm.s lib/gemlib/_sx_asm.s
--- lib.orig/gemlib/_sx_asm.s 2003-02-28 21:46:37.000000000 +0100
+++ lib/gemlib/_sx_asm.s 2009-12-19 17:07:09.828125000 +0100
@@ -7,17 +7,23 @@
_aes: move.l 4(sp), d1
move.w #200, d0
+ movem.l d2/a2, -(sp) ; backup registers
trap #2
+ movem.l (sp)+, d2/a2 ; restore registers
rts
_vdi: move.l 4(sp), d1
- move.w #115, d0
+ moveq #115, d0
+ movem.l d2/a2, -(sp) ; backup registers
trap #2
+ movem.l (sp)+, d2/a2 ; restore registers
rts
_vq_gdos:
- move.w #-2, d0
+ moveq #-2, d0
+ movem.l d2/a2, -(sp) ; backup registers
trap #2
+ movem.l (sp)+, d2/a2 ; restore registers
cmp.w #-2, d0
sne d0
ext.w d0
@@ -25,5 +31,7 @@
_vq_vgdos:
moveq #-2, d0
+ movem.l d2/a2, -(sp) ; backup registers
trap #2
+ movem.l (sp)+, d2/a2 ; restore registers
rts
diff -aurN -x CVS lib.orig/gemlib/gem_aesP.h lib/gemlib/gem_aesP.h
--- lib.orig/gemlib/gem_aesP.h 2009-12-11 13:15:11.000000000 +0100
+++ lib/gemlib/gem_aesP.h 2009-12-19 17:10:49.937500000 +0100
@@ -20,8 +20,8 @@
"move.w #200,d0\n\t"
"trap #2"
:
- : "a"(aespb)
- : "d0","d1","a0","memory"
+ : "g"(aespb)
+ : "d0","d1","d2","a0","a1","a2","memory"
);
}
#define AES_TRAP(aespb) _aes_trap(&aespb)
diff -aurN -x CVS lib.orig/gemlib/gem_vdiP.h lib/gemlib/gem_vdiP.h
--- lib.orig/gemlib/gem_vdiP.h 2003-09-22 21:07:45.000000000 +0200
+++ lib/gemlib/gem_vdiP.h 2009-12-19 18:05:26.265625000 +0100
@@ -31,8 +31,8 @@
"move.w #115,d0\n\t" /* 0x0073 */
"trap #2"
:
- : "a"(vdipb), "g"(cntrl_0_1), "g"(cntrl_3), "g"(cntrl_5), "g"(handle)
- : "a0", "d0", "d1", "memory"
+ : "g"(vdipb), "g"(cntrl_0_1), "g"(cntrl_3), "g"(cntrl_5), "g"(handle)
+ : "d0", "d1", "d2", "a0", "a1", "a2", "memory"
);
}
#define VDI_TRAP_ESC(vdipb, handle, opcode, subop, cntrl_1, cntrl_3) \
@@ -46,15 +46,15 @@
"move.l a0,d1\n\t"
"move.l (a0),a0\n\t" /* vdipb->control */
"move.l %1,(a0)+\n\t" /* cntrl_0, cntrl_1 */
- "eor.l d0,d0\n\t"
+ "moveq #0,d0\n\t"
"move.l d0,(a0)+\n\t" /* cntrl_2, cntrl_3 */
"move.l d0,(a0)+\n\t" /* cntrl_4, cntrl_5 */
"move.w %2,(a0)\n\t" /* handle */
"move.w #115,d0\n\t" /* 0x0073 */
"trap #2"
:
- : "a"(vdipb), "g"(cntrl_0_1), "g"(handle)
- : "a0", "d0","d1","memory"
+ : "g"(vdipb), "g"(cntrl_0_1), "g"(handle)
+ : "d0", "d1", "d2", "a0", "a1", "a2", "memory"
);
}
#define VDI_TRAP_00(vdipb, handle, opcode) \
diff -aurN -x CVS lib.orig/gemma/src/gemproto.h lib/gemma/src/gemproto.h
--- lib.orig/gemma/src/gemproto.h 2009-07-08 22:06:27.000000000 +0200
+++ lib/gemma/src/gemproto.h 2009-12-19 16:46:30.015625000 +0100
@@ -24,9 +24,9 @@
"move.l %1,d1\n\t" \
"trap #2\n\t" \
: \
- : "g"(sysopcode), "a"(params) \
- : __CLOBBER_RETURN("d0") "d1" \
- );
+ : "g"(sysopcode), "g"(params) \
+ : "d0", "d1", "d2", "a0", "a1", "a2", "memory" \
+ );
}
/* AES */