[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MiNT] [PATCH] cflib for ColdFire
Hello.
Here are the cflib patches for ColdFire. I'm annoyed that nkcc is duplicated
to XaAES, but that's another problem.
There are 2 steps.
1) Rename lib/cflib/nkcc-gc.s to nkcc-gc.S and do whatever is required for
CVS. Then apply cflib1.patch:
Added preprocessor support. Contributed by Vincent Riviere.
2) cflib2.patch:
Added ColdFire support and rationalized xFSL clobber lists. Contributed by
Vincent Riviere.
If everything goes well we should see lib/m5475/libcflib.a in the next lib
daily build.
Alan, please commit!
--
Vincent Rivière
diff -x CVS -aurN lib.orig/cflib/Makefile.objs lib/cflib/Makefile.objs
--- lib.orig/cflib/Makefile.objs 2010-01-15 20:45:35.265625000 +0100
+++ lib/cflib/Makefile.objs 2011-08-01 19:27:22.187500000 +0200
@@ -30,7 +30,7 @@
endif
# default definitions
-OBJS = $(COBJS:.c=.o) $(SOBJS:.s=.o)
+OBJS = $(COBJS:.c=.o) $(SOBJS:.S=.o)
VPATH = ..
diff -x CVS -aurN lib.orig/cflib/SRCFILES lib/cflib/SRCFILES
--- lib.orig/cflib/SRCFILES 2001-02-17 02:28:25.000000000 +0100
+++ lib/cflib/SRCFILES 2011-08-01 18:09:28.781250000 +0200
@@ -169,6 +169,6 @@
wdial_uniconify.c
SOBJS = \
- nkcc-gc.s
+ nkcc-gc.S
SRCFILES = $(HEADER) $(COBJS) $(SOBJS)
diff -x CVS -aurN lib.orig/cflib/Makefile lib/cflib/Makefile
--- lib.orig/cflib/Makefile 2011-04-29 22:11:10.640625000 +0200
+++ lib/cflib/Makefile 2011-08-01 18:37:05.593750000 +0200
@@ -29,6 +29,10 @@
ALL_LIBS += normal020
endif
+ifeq ($(WITH_V4E_LIB),yes)
+ALL_LIBS += normalv4e
+endif
+
libs: $(ALL_LIBS)
normal:
@@ -40,6 +44,9 @@
normal020:
$(MAKE) libcflib020.a TARGET="020"
+normalv4e:
+ $(MAKE) libcflibv4e.a TARGET="v4e"
+
libcflib$(TARGET).a: objs
$(RM) $@
$(AR) rc $@ \
@@ -69,6 +76,9 @@
ifeq ($(WITH_020_LIB),yes)
install -m 644 libcflib020.a ${PREFIX}/lib/m68020-60/libcflib.a
endif
+ifeq ($(WITH_V4E_LIB),yes)
+ install -m 644 libcflibv4e.a ${PREFIX}/lib/m5475/libcflib.a
+endif
install -m 644 cflib.hyp ${PREFIX}/stguide
install -m 644 cflib.ref ${PREFIX}/stguide
@@ -80,5 +90,8 @@
ifeq ($(WITH_020_LIB),yes)
rm -f ${PREFIX}/lib/m68020-60/libcflib.a
endif
+ifeq ($(WITH_V4E_LIB),yes)
+ rm -f ${PREFIX}/lib/m5475/libcflib.a
+endif
rm -f ${PREFIX}/stguide/cflib.hyp
rm -f ${PREFIX}/stguide/cflib.ref
diff -x CVS -aurN lib.orig/cflib/Makefile.objs lib/cflib/Makefile.objs
--- lib.orig/cflib/Makefile.objs 2011-08-01 19:27:22.187500000 +0200
+++ lib/cflib/Makefile.objs 2011-08-01 18:33:34.453125000 +0200
@@ -29,6 +29,10 @@
GENERAL += -m68020-60
endif
+ifeq ($(TARGET),v4e)
+GENERAL += -mcpu=5475
+endif
+
# default definitions
OBJS = $(COBJS:.c=.o) $(SOBJS:.S=.o)
diff -x CVS -aurN lib.orig/cflib/fontsel.c lib/cflib/fontsel.c
--- lib.orig/cflib/fontsel.c 2010-02-16 21:12:42.015625000 +0100
+++ lib/cflib/fontsel.c 2011-08-01 17:57:46.171875000 +0200
@@ -53,15 +53,15 @@
register long retvalue __asm__("d0"); \
\
__asm__ volatile \
- (" \
- movl %3,sp@-; \
- movw %2,sp@-; \
- movl %1,a0; \
- jsr a0@; \
- addw #6,sp " \
+ ( \
+ "movl %3,sp@-\n\t" \
+ "movw %2,sp@-\n\t" \
+ "movl %1,a0\n\t" \
+ "jsr a0@\n\t" \
+ "addql #6,sp" \
: "=r"(retvalue) /* output */ \
- : "r"(f), "g"(w), "g"(l) /* input */ \
- : __CLOBBER_RETURN("d0") "d1", "d2", "a0" /* clobbered regs */ \
+ : "r"(f), "r"(w), "r"(l) /* input */ \
+ : __CLOBBER_RETURN("d0") "d1", "a0", "a1" /* clobbered regs */ \
AND_MEMORY \
); \
retvalue; \
@@ -73,15 +73,15 @@
register long retvalue __asm__("d0"); \
\
__asm__ volatile \
- (" \
- movl %3,sp@-; \
- movw %2,sp@-; \
- movl %1,a0; \
- jsr a0@; \
- addw #6,sp " \
+ ( \
+ "movl %3,sp@-\n\t" \
+ "movw %2,sp@-\n\t" \
+ "movl %1,a0\n\t" \
+ "jsr a0@\n\t" \
+ "addql #6,sp" \
: "=r"(retvalue) /* output */ \
- : "r"(f), "g"(w), "g"(l) /* input */ \
- : __CLOBBER_RETURN("d0") "d1", "a0" /* clobbered regs */ \
+ : "r"(f), "r"(w), "r"(l) /* input */ \
+ : __CLOBBER_RETURN("d0") "d1", "a0", "a1" /* clobbered regs */ \
AND_MEMORY \
); \
retvalue; \
@@ -93,14 +93,14 @@
register long retvalue __asm__("d0"); \
\
__asm__ volatile \
- (" \
- movw %2,sp@-; \
- movl %1,a0; \
- jsr a0@; \
- addw #2,sp " \
+ ( \
+ "movw %2,sp@-\n\t" \
+ "movl %1,a0\n\t" \
+ "jsr a0@\n\t" \
+ "addql #2,sp" \
: "=r"(retvalue) /* outputs */ \
- : "r"(f), "g"(w) /* inputs */ \
- : "a0" /* clobbered regs */ \
+ : "r"(f), "r"(w) /* inputs */ \
+ : __CLOBBER_RETURN("d0") "d1", "a0", "a1" /* clobbered regs */ \
AND_MEMORY \
); \
retvalue; \
diff -x CVS -aurN lib.orig/cflib/nkcc-gc.S lib/cflib/nkcc-gc.S
--- lib.orig/cflib/nkcc-gc.S 2009-12-20 17:42:28.156250000 +0100
+++ lib/cflib/nkcc-gc.S 2011-08-01 18:27:58.125000000 +0200
@@ -1,7 +1,7 @@
|***************************************************************************
|
-| Reduzierte NKCC f?r die CF-Lib
-| Version f?r GNU-C
+| reduced NKCC for the CF-Lib
+| GNU-C compatible version
|
|***************************************************************************
@@ -9,7 +9,7 @@
| ASSEMBLER CONTROL SECTION
|***************************************************************************
-VERSION = 0x0294 | NKCC's version #
+VERSION = 0x0294 | NKCC's version
NKFf_FUNC = 0x8000
NKFf_RESVD = 0x4000
@@ -69,32 +69,56 @@
btst #NKFb_NUM,d0 | on numeric keypad?
beqs search | no ->
- movew #0x4a,d1 | yes: try all numeric keypad
+ moveql #0x4a,d1 | yes: try all numeric keypad
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d0 | scan codes first
+#else
cmpb a0@(d1:w),d0 | scan codes first
+#endif
beqs found1 | it matches ->
- movew #0x4e,d1
+ moveql #0x4e,d1
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d0
+#else
cmpb a0@(d1:w),d0
+#endif
beqs found1
- movew #0x63,d1 | block starts at 0x63
+ moveql #0x63,d1 | block starts at 0x63
numsearch:
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d0 | match?
+#else
cmpb a0@(d1:w),d0 | match?
+#endif
beqs found1 | yes ->
+#ifdef __mcoldfire__
+ addql #1,d1 | next scan code
+#else
addqw #1,d1 | next scan code
+#endif
cmpw #0x73,d1 | block end at 0x72
bcss numsearch | continue search ->
search:
- movew #1,d1 | start with first valid scan code
+ moveql #1,d1 | start with first valid scan code
mainsearch:
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d0 | match?
+#else
cmpb a0@(d1:w),d0 | match?
+#endif
beqs found1 | yes ->
+#ifdef __mcoldfire__
+ addql #1,d1 | next scan code
+#else
addqb #1,d1 | next scan code
+#endif
cmpb #0x78,d1 | 0x78 = last valid scan code
bcss mainsearch | continue search ->
@@ -118,7 +142,8 @@
_nkc_init:
|------------- fetch addresses of TOS' key scan code translation tables
- moveml d2/a2,sp@- | backup registers
+ movel a2,sp@- | backup registers
+ movel d2,sp@-
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
@@ -133,7 +158,8 @@
movel a0@,pkey_caps | get ^CapsLock table
movew #VERSION,d0 | load version #
- moveml sp@+,d2/a2 | restore registers
+ movel sp@+,d2 | restore registers
+ movel sp@+,a2
rts | bye
|***************************************************************************
@@ -143,25 +169,44 @@
|***************************************************************************
_nkc_tos2n:
- movel sp@(4), d0 | Parameter ?ber Stack!
+ movel sp@(4), d0 | Parameter via Stack!
+#ifdef __mcoldfire__
+ lea sp@(-12),sp
+ movem.l d2-d4,sp@ | store registers
+#else
movem.l d2-d4,sp@- | store registers
+#endif
|------------- separate TOS key code
movel d0,d1 | TOS key code
swap d1 | .W = scan code and flags
movew d1,d2 | copy
+#ifdef __mcoldfire__
+ movel #0xff,d3 | and-mask
+ andl d3,d0 | .B = ASCII code
+ andl d3,d1 | .B = scan code
+#else
movew #0xff,d3 | and-mask
andw d3,d0 | .B = ASCII code
andw d3,d1 | .B = scan code
+#endif
beq tos306 | scancode=zero (key code created
| by ASCII input of TOS 3.06)? ->
+#ifdef __mcoldfire__
+ andl #0x1f00,d2 | .W = key flags (in high byte)
+#else
andw #0x1f00,d2 | .W = key flags (in high byte)
+#endif
|------------- decide which translation table to use
movew d2,d3 | key flags
+#ifdef __mcoldfire__
+ andl #NKFf_SHIFT,d3 | isolate bits for shift keys
+#else
andw #NKFf_SHIFT,d3 | isolate bits for shift keys
+#endif
beqs ktab11 | shift key pressed? no->
movel pkey_shift,a0 | yes: use shift table
@@ -196,17 +241,37 @@
movew d2,d1 | flags
| andw #NKFf_ALT|NKFf_CTRL,d1 | Alternate or Control?
+#ifdef __mcoldfire__
+ andl #0xc00,d1 | Alternate or Control?
+#else
andw #0xc00,d1 | Alternate or Control?
+#endif
beqs special | no ->
+#ifdef __mcoldfire__
+ orl #NKFf_NUM,d0 | yes: set numeric keypad flag
+#else
orw #NKFf_NUM,d0 | yes: set numeric keypad flag
+#endif
| and #NKFf_CAPS|NKFf_SHIFT,d2 | mask off both flags
+#ifdef __mcoldfire__
+ andl #0x1300,d2 | mask off both flags
+#else
andw #0x1300,d2 | mask off both flags
+#endif
special:
+#ifdef __mcoldfire__
+ orl d2,d0 | combine with ASCII code
+#else
orw d2,d0 | combine with ASCII code
+#endif
| orw #NKFf_FUNC|NKFf_RESVD,d0 | set function and resvd
+#ifdef __mcoldfire__
+ orl #0x1300,d0 | set function and resvd
+#else
orw #0x1300,d0 | set function and resvd
+#endif
cmpb #0x20,d0 | ASCII code in range?
bcc exit2 | yes ->
@@ -219,9 +284,15 @@
cmpb #0x78,d1 | scan code of Alt + number?
bcss scan1 | no->
+#ifdef __mcoldfire__
+ subl #0x76,d1 | yes: calculate REAL scan code
+ moveb a0@(d1:l),d0 | fetch ASCII code
+ orl #NKFf_ALT,d2 | set Alternate flag
+#else
subb #0x76,d1 | yes: calculate REAL scan code
moveb a0@(d1:w),d0 | fetch ASCII code
orw #NKFf_ALT,d2 | set Alternate flag
+#endif
bra cat_codes | -> add flag byte and exit
|------------- check if exception scan code from cursor keypad
@@ -236,7 +307,11 @@
cmpb d1,d3 | scan code found?
bnes search_scan | no: continue search ->
+#ifdef __mcoldfire__
+ lsrl #8,d3 | .B = NKC
+#else
lsrw #8,d3 | .B = NKC
+#endif
moveql #0,d0 | mark: key code found
bras scan2 | ->
@@ -246,7 +321,11 @@
|------------- check if rubbish ASCII code and erase it, if so
scan2:
+#ifdef __mcoldfire__
+ moveb a0@(d1:l),d4 | ASCII code from translation table
+#else
moveb a0@(d1:w),d4 | ASCII code from translation table
+#endif
cmpb #32,d0 | ASCII returned by TOS < 32?
bccs scan3 | no -> can't be rubbish
@@ -266,7 +345,11 @@
beqs scan4 | equal: normal key ->
| and #!NKFf_ALT,d2 | no: clear Alternate flag
+#ifdef __mcoldfire__
+ andl #0xF7FF,d2 | no: clear Alternate flag
+#else
andw #0xF7FF,d2 | no: clear Alternate flag
+#endif
|------------- check if ASCII code found yet, and set it, if not
@@ -303,7 +386,11 @@
bhis scan7 | no ->
numeric:
+#ifdef __mcoldfire__
+ orl #NKFf_NUM,d2 | yes: set numeric bit
+#else
orw #NKFf_NUM,d2 | yes: set numeric bit
+#endif
|------------- check if "function key" and set bit accordingly
@@ -311,7 +398,11 @@
cmpb #32,d0 | ASCII code less than 32?
bccs scan8 | no ->
+#ifdef __mcoldfire__
+ orl #NKFf_FUNC,d2 | yes: set function bit
+#else
orw #NKFf_FUNC,d2 | yes: set function bit
+#endif
|------------- check special case: Return or Enter key
@@ -332,11 +423,23 @@
cmpb #0x5d,d1
bhis scan9 | no ->
+#ifdef __mcoldfire__
+ subl #0x54-0x3b,d1 | yes: scan code for unshifted key
+#else
subb #0x54-0x3b,d1 | yes: scan code for unshifted key
+#endif
movew d2,d3 | shift flags
+#ifdef __mcoldfire__
+ andl #NKFf_SHIFT,d3 | any shift key flag set?
+#else
andw #NKFf_SHIFT,d3 | any shift key flag set?
+#endif
bnes scan9 | yes ->
+#ifdef __mcoldfire__
+ orl #NKFf_SHIFT,d2 | no: set both flags
+#else
orw #NKFf_SHIFT,d2 | no: set both flags
+#endif
scan9:
cmpb #0x3b,d1 | (unshifted) function key?
@@ -346,50 +449,92 @@
bhis cat_codes | no ->
moveb d1,d0 | yes: calc NKC
+#ifdef __mcoldfire__
+ subl #0x2b,d0
+#else
subb #0x2b,d0
+#endif
|------------- final flag handling| mix key code (low byte) and flag byte
cat_codes:
movel pkey_shift,a0 | ^shifted table
+#ifdef __mcoldfire__
+ moveb a0@(d1:l),d3 | get shifted ASCII code
+ orl d2,d0 | mix flags with key code
+ tst.w d0
+#else
moveb a0@(d1:w),d3 | get shifted ASCII code
orw d2,d0 | mix flags with key code
+#endif
bmis scan10 | result is "function key"? ->
+#ifdef __mcoldfire__
+ andl #NKFf_CTRL+NKFf_ALT,d2 | Control or Alternate pressed?
+#else
andw #NKFf_CTRL+NKFf_ALT,d2 | Control or Alternate pressed?
+#endif
bnes scan11 | yes ->
scan10:
movel pkey_unshift,a0 | ^unshifted table
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d3 | shifted ASCII = unshifted ASCII?
+#else
cmpb a0@(d1:w),d3 | shifted ASCII = unshifted ASCII?
+#endif
beqs scan12 | yes ->
bras exit2 | no ->
scan11:
+#ifdef __mcoldfire__
+ orl #NKFf_FUNC,d0 | Alt/Ctrl + char: set function bit
+#else
orw #NKFf_FUNC,d0 | Alt/Ctrl + char: set function bit
+#endif
movel pkey_caps,a0 | ^CapsLock table
+#ifdef __mcoldfire__
+ cmpb a0@(d1:l),d3 | shifted ASCII = CapsLocked ASCII?
+#else
cmpb a0@(d1:w),d3 | shifted ASCII = CapsLocked ASCII?
+#endif
bnes exit2 | no ->
moveb d3,d0 | yes: use shifted ASCII code
scan12:
+#ifdef __mcoldfire__
+ orl #NKFf_RESVD,d0 | yes: nkc_cmp() has to check
+#else
orw #NKFf_RESVD,d0 | yes: nkc_cmp() has to check
+#endif
|------------- restore registers and exit
exit2:
tstw d0 | set CCR
+#ifdef __mcoldfire__
+ movem.l sp@,d2-d4 | restore registers
+ lea sp@(12),sp
+#else
movem.l sp@+,d2-d4 | restore registers
+#endif
rts | bye
|------------- special handling for key codes created by TOS' 3.06 ASCII input
tos306:
+#ifdef __mcoldfire__
+ andl #NKFf_CAPS,d2 | isolate CapsLock flag
+ orl d2,d0 | merge with ASCII code
+ movem.l sp@,d2-d4 | restore registers
+ lea sp@(12),sp
+#else
andw #NKFf_CAPS,d2 | isolate CapsLock flag
orw d2,d0 | merge with ASCII code
movem.l sp@+,d2-d4 | restore registers
+#endif
rts | bye
|***************************************************************************
@@ -403,7 +548,11 @@
movew d0,d1 | normalized key code
| and #NKFf_FUNC|NKFf_ALT|NKFf_CTRL,d1| isolate flags
+#ifdef __mcoldfire__
+ andl #0x8c00,d1 | isolate flags
+#else
andw #0x8c00,d1 | isolate flags
+#endif
cmpw #NKFf_FUNC,d1 | only function flag set?
bnes ktab20 | no ->
@@ -419,10 +568,18 @@
beqs mackey | no ->
| or #NKFf_ALT|NKFf_CTRL,d0 | yes: set Alternate + Control
+#ifdef __mcoldfire__
+ orl #0xc00,d1 | yes: set Alternate + Control?
+#else
orw #0xc00,d1 | yes: set Alternate + Control?
+#endif
mackey:
+#ifdef __mcoldfire__
+ orl #0xff,d0 | scan code always 0xff
+#else
orb #0xff,d0 | scan code always 0xff
+#endif
swap d0 | flags and scan code in upper word
moveb d1,d0 | ASCII code
bra exit3 | ->
@@ -431,7 +588,11 @@
ktab20:
movew d0,d1 | normalized key code
+#ifdef __mcoldfire__
+ andl #NKFf_SHIFT,d1 | isolate bits for shift keys
+#else
andw #NKFf_SHIFT,d1 | isolate bits for shift keys
+#endif
beqs ktab21 | shift key pressed? no->
lea n_to_scan_s,a1 | ^default translation table
@@ -465,7 +626,11 @@
lea tolower,a0 | ^upper->lower case table
moveql #0,d2 | clear for word operation
moveb d0,d2 | ASCII code
+#ifdef __mcoldfire__
+ moveb a0@(d2:l),d0 | get lowercased ASCII code
+#else
moveb a0@(d2:w),d0 | get lowercased ASCII code
+#endif
movel d1,a0 | restore a0
bsr nk_findscan | try to find scan code again
bnes found2 | found ->
@@ -476,7 +641,11 @@
notfound:
moveql #0,d1 | not found: clear for word op.
moveb d0,d1 | unchanged ASCII code
+#ifdef __mcoldfire__
+ andl #0x1f00,d0 | keep shift flags only
+#else
andw #0x1f00,d0 | keep shift flags only
+#endif
swap d0 | -> high word (scan code = 0)
movew d1,d0 | low word: ASCII code
bra exit3 | ->
@@ -487,14 +656,22 @@
btst #NKFb_FUNC,d0 | function key?
bnes func | yes ->
+#ifdef __mcoldfire__
+ andl #0xffff10ff,d0 | clear all flags except CapsLock
+#else
andw #0x10ff,d0 | clear all flags except CapsLock
+#endif
bras notfound | ->
func:
moveql #0,d1 | clear for word operation
moveb d0,d1 | ASCII code (0...0x1f)
movew d1,d2 | copy
+#ifdef __mcoldfire__
+ moveb a1@(d1:l),d1 | get scan code
+#else
moveb a1@(d1:w),d1 | get scan code
+#endif
bnes getascii | valid? ->
moveq #0,d0 | invalid key code!! return 0
@@ -502,8 +679,13 @@
getascii:
lea n_to_scan_u,a1 | ^unshifted translation table
+#ifdef __mcoldfire__
+ moveb a1@(d2:l),d2 | get scan code from unshifted tab.
+ moveb a0@(d2:l),d0 | get ASCII from system's table
+#else
moveb a1@(d2:w),d2 | get scan code from unshifted tab.
moveb a0@(d2:w),d0 | get ASCII from system's table
+#endif
| register contents:
|
@@ -514,7 +696,11 @@
found2:
movew d0,d2 | flags and ASCII code
+#ifdef __mcoldfire__
+ andl #0x1f00,d0 | isolate shift flags
+#else
andw #0x1f00,d0 | isolate shift flags
+#endif
moveb d1,d0 | merge with scan code
swap d0 | -> high byte
clrw d0 | erase low word
@@ -558,12 +744,20 @@
cmpb d0,d1 | ASCII code found?
bnes ascloop | no -> continue search
+#ifdef __mcoldfire__
+ lsrl #8,d1 | yes: get translated code
+#else
lsrw #8,d1 | yes: get translated code
+#endif
moveb d1,d0 | use it
bras exit3 | ->
noctrlasc:
+#ifdef __mcoldfire__
+ andl #0x1f,d0 | mask off upper 3 bits
+#else
andb #0x1f,d0 | mask off upper 3 bits
+#endif
bras exit3 | ->
|------------- handling for Alternate key flag
@@ -610,9 +804,13 @@
|***************************************************************************
_nkc_toupper:
- movel sp@(4),d1 | Parameter ?ber Stack!
+ movel sp@(4),d1 | Parameter via Stack!
lea toupper,a0 | ^upper case translation table
+#ifdef __mcoldfire__
+ andl #0xff,d1 | high byte = 0 for word operation
+#else
andw #0xff,d1 | high byte = 0 for word operation
+#endif
moveb a0@(d1:l),d0 | convert
rts | bye
@@ -623,9 +821,13 @@
|***************************************************************************
_nkc_tolower:
- movel sp@(4),d1 | Parameter ?ber Stack!
+ movel sp@(4),d1 | Parameter via Stack!
lea tolower,a0 | ^lower case translation table
+#ifdef __mcoldfire__
+ andl #0xff,d1 | high byte = 0 for word operation
+#else
andw #0xff,d1 | high byte = 0 for word operation
+#endif
moveb a0@(d1:l),d0 | convert
rts | bye