Browse code

- experimental mips2 and >=2 support (R4000, R5000, R6000)

Andrei Pelinescu-Onciul authored on 12/09/2004 16:32:30
Showing 3 changed files
... ...
@@ -32,6 +32,7 @@
32 32
 #  2003-11-08  mips1 support introduced (andrei)
33 33
 #  2003-11-24  openbsd 3.4 (elf) fixes (andrei)
34 34
 #  2004-07-27  darwin (mac os x) port  (andrei)
35
+#  2004-09-12  mips2 & cobalt support introduced (andrei)
35 36
 
36 37
 
37 38
 # check if already included/exported
... ...
@@ -48,12 +49,12 @@ MAIN_NAME=ser
48 49
 VERSION = 0
49 50
 PATCHLEVEL = 8
50 51
 SUBLEVEL =   99
51
-EXTRAVERSION = -dev4
52
+EXTRAVERSION = -dev5
52 53
 
53 54
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
54 55
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
55 56
 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
56
-			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" )
57
+			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" -e "s/cobalt/mips2/" )
57 58
 OSREL = $(shell uname -r)
58 59
 
59 60
 # TLS support
... ...
@@ -403,6 +404,11 @@ ifeq ($(ARCH), mips)
403 404
 	use_fast_lock=no
404 405
 endif
405 406
 
407
+ifeq ($(ARCH), mips2)
408
+# mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
409
+	use_fast_lock=yes
410
+endif
411
+
406 412
 ifeq ($(use_fast_lock), yes)
407 413
 	DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 
408 414
 	found_lock_method=yes
... ...
@@ -577,6 +583,34 @@ $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
577 583
 endif		#CC_NAME, gcc
578 584
 endif	#ARCH, mips
579 585
 
586
+	#if  >=mips2 (R4000, R5000, R6000 ....)
587
+ifeq	($(ARCH), mips2)
588
+		# if gcc 
589
+ifeq		($(CC_NAME), gcc)
590
+				#common stuff
591
+				CFLAGS= -mips2 -O9 -funroll-loops  -Wcast-align $(PROFILE) \
592
+					-Wall   \
593
+			#if gcc 3.0
594
+ifeq			($(CC_SHORTVER), 3.0)
595
+					CFLAGS+=
596
+else
597
+ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
598
+$(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
599
+					for better results)
600
+					CFLAGS+=
601
+else
602
+				#really old version
603
+$(warning			You are using an old and unsupported gcc \
604
+					 version ($(CC_SHORTVER)), compile at your own risk!)
605
+	
606
+endif			# CC_SHORTVER, 2.9x
607
+endif			# CC_SHORTVER, 3.0
608
+	
609
+else		# CC_NAME, gcc
610
+				#other compilers
611
+$(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
612
+endif		#CC_NAME, gcc
613
+endif	#ARCH, mips2
580 614
 
581 615
 CFLAGS+= $(CC_EXTRA_OPTS)
582 616
 
... ...
@@ -30,9 +30,12 @@
30 30
  */
31 31
 /*
32 32
  *
33
- *
33
+ *History:
34
+ *--------
35
+ *  2002-02-05  created by andrei
34 36
  *  2003-01-16  added PPC locking code contributed by Dinos Dorkofikis
35 37
  *               <kdor@intranet.gr>
38
+ *  2004-09-12  added MIPS locking for ISA>=2 (>r3000)  (andrei)
36 39
  *
37 40
  */
38 41
 
... ...
@@ -106,6 +109,21 @@ inline static int tsl(fl_lock_t* lock)
106 109
 			: "r"(1), "b" (lock) :
107 110
 			"memory", "cc"
108 111
         );
112
+#elif defined __CPU_mips2
113
+	long tmp;
114
+	
115
+	asm volatile(
116
+		".set noreorder\n\t"
117
+		"1:  ll %1, %2   \n\t"
118
+		"    li %0, 1 \n\t"
119
+		"    sc %0, %2  \n\t"
120
+		"    beqz %0, 1b \n\t"
121
+		"    nop \n\t"
122
+		".set reorder\n\t"
123
+		: "=&r" (tmp), "=&r" (val), "=m" (*lock) 
124
+		: "0" (tmp), "2" (*lock) 
125
+		: "cc"
126
+	);
109 127
 #else
110 128
 #error "unknown architecture"
111 129
 #endif
... ...
@@ -168,6 +186,14 @@ inline static void release_lock(fl_lock_t* lock)
168 186
 			: "memory"
169 187
         );
170 188
 	*lock = 0;
189
+#elif defined __CPU_mips2
190
+		asm volatile(
191
+		".set noreorder \n\t"
192
+		"    sync \n\t"
193
+		"    sw $0, %0 \n\t"
194
+		".set reorder \n\t"
195
+		: /*no output*/  : "m" (*lock) : "memory"
196
+	);
171 197
 #else
172 198
 #error "unknown architecture"
173 199
 #endif
174 200
new file mode 100644
... ...
@@ -0,0 +1,98 @@
1
+/*
2
+ *
3
+ *  simple locking test program
4
+ *  (no paralles stuff)
5
+ * 
6
+ *  Compile with: gcc -D__CPU_i386 -O3 on x86 machines and -D__CPU_mips
7
+ *  on mips machines.
8
+ *
9
+ *  -- andrei
10
+ *
11
+ *  
12
+ */
13
+
14
+#include <stdio.h>
15
+
16
+typedef volatile int fl_lock_t;
17
+
18
+
19
+
20
+int tsl(fl_lock_t* lock)
21
+{
22
+	long val;
23
+	
24
+#ifdef __CPU_mips
25
+	long tmp=0;
26
+	
27
+	asm volatile(
28
+		".set noreorder\n\t"
29
+		"1:  ll %1, %2   \n\t"
30
+		"    li %0, 1 \n\t"
31
+		"    sc %0, %2  \n\t"
32
+		"    beqz %0, 1b \n\t"
33
+		"    nop \n\t"
34
+		".set reorder\n\t"
35
+		: "=&r" (tmp), "=&r" (val), "=m" (*lock) 
36
+		: "0" (tmp), "2" (*lock) 
37
+		: "cc"
38
+	);
39
+#elif defined __CPU_i386
40
+	val=1;
41
+	asm volatile( 
42
+		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) 
43
+	);
44
+#else
45
+#error "cpu type not defined, add -D__CPU_<type> when compiling"
46
+#endif
47
+	
48
+	return val;
49
+}
50
+
51
+
52
+
53
+void release_lock(fl_lock_t* lock)
54
+{
55
+#ifdef __CPU_mips
56
+	int tmp;
57
+	tmp=0;
58
+	asm volatile(
59
+		".set noreorder \n\t"
60
+		"    sync \n\t"
61
+		"    sw $0, %0 \n\t"
62
+		".set reorder \n\t"
63
+		: /*no output*/  : "m" (*lock) : "memory"
64
+	);
65
+#elif defined __CPU_i386
66
+	asm volatile(
67
+		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
68
+	); 
69
+#else
70
+#error "cpu type not defined, add -D__CPU_<type> when compiling"
71
+#endif
72
+}
73
+
74
+
75
+
76
+int main(int argc, char** argv)
77
+{
78
+	fl_lock_t lock;
79
+	int r;
80
+	
81
+	lock=0;
82
+	printf("starting locking basic tests...\n");
83
+	
84
+	r=tsl(&lock);
85
+	printf(" tsl should return 0                 ... %d\n", r);
86
+	printf("     lock should be 1 now            ... %d\n", lock);
87
+	r=tsl(&lock);
88
+	printf(" tsl should return 1                 ... %d\n", r);
89
+	printf("     lock should still be 1 now      ... %d\n", lock);
90
+	release_lock(&lock);
91
+	printf(" release_lock: lock should be 0 now  ... %d\n", lock);
92
+	printf("trying tsl once more...\n");
93
+	r=tsl(&lock);
94
+	printf(" tsl should return 0                 ... %d\n", r);
95
+	printf("     lock should be 1 now            ... %d\n", lock);
96
+	printf("\ndone.\n");
97
+	return 0;
98
+}