Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 8 files changed
  • 0 comments
  • 1 contributor
6  software/common.mak
@@ -44,9 +44,9 @@ LDFLAGS = -nostdlib -nodefaultlibs
44 44
 # compile and generate dependencies, based on
45 45
 # http://scottmcpeak.com/autodepend/autodepend.html
46 46
 
47  
-%.o: %.c
48  
-	$(CC) -c $(CFLAGS) $*.c -o $*.o
49  
-	@$(CC_normal) -MM $(CFLAGS) $*.c > $*.d
  47
+%.o: $(SRCDIR)%.c
  48
+	$(CC) -c $(CFLAGS) $(SRCDIR)$*.c -o $*.o
  49
+	@$(CC_normal) -MM $(CFLAGS) $(SRCDIR)$*.c > $*.d
50 50
 	@mv -f $*.d $*.d.tmp
51 51
 	@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
52 52
 	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
9  software/include/base/limits.h
... ...
@@ -1,7 +1,12 @@
1 1
 #ifndef __LIMITS_H
2 2
 #define __LIMITS_H
3 3
 
4  
-#define INT_MIN ((((unsigned long)-1) >> 1) + 1)
5  
-#define INT_MAX (((unsigned long)-1) >> 1)
  4
+#define INT_MIN 0x7fffffff
  5
+#define INT_MAX 0x80000000
  6
+
  7
+#define SHRT_MIN 0x8000
  8
+#define SHRT_MAX 0x7fff
  9
+
  10
+#define UCHAR_MAX 0xff
6 11
 
7 12
 #endif /* __LIMITS_H */
12  software/include/base/setjmp.h
... ...
@@ -0,0 +1,12 @@
  1
+#ifndef __SETJMP_H
  2
+#define __SETJMP_H
  3
+
  4
+#define _JBLEN 19
  5
+
  6
+typedef	int jmp_buf[_JBLEN];
  7
+
  8
+int setjmp(jmp_buf env);
  9
+void longjmp(jmp_buf env, int val);
  10
+
  11
+#endif /* __SETJMP_H */
  12
+
11  software/include/base/stddef.h
... ...
@@ -0,0 +1,11 @@
  1
+#ifndef __STDDEF_H
  2
+#define __STDDEF_H
  3
+
  4
+#define NULL ((void *)0)
  5
+
  6
+typedef unsigned long size_t;
  7
+typedef long ptrdiff_t;
  8
+
  9
+#define offsetof(s,m) (size_t)&(((s *)0)->m)
  10
+
  11
+#endif /* __STDDEF_H */
10  software/include/base/stdlib.h
@@ -19,6 +19,8 @@
19 19
 #ifndef __STDLIB_H
20 20
 #define __STDLIB_H
21 21
 
  22
+#include <stddef.h>
  23
+
22 24
 #define PRINTF_ZEROPAD	1		/* pad with zero */
23 25
 #define PRINTF_SIGN	2		/* unsigned/signed long */
24 26
 #define PRINTF_PLUS	4		/* show plus */
@@ -27,11 +29,6 @@
27 29
 #define PRINTF_SPECIAL	32		/* 0x */
28 30
 #define PRINTF_LARGE	64		/* use 'ABCDEF' instead of 'abcdef' */
29 31
 
30  
-typedef unsigned long size_t;
31  
-typedef long ptrdiff_t;
32  
-
33  
-#define NULL ((void *)0)
34  
-
35 32
 #define likely(x) x
36 33
 #define unlikely(x) x
37 34
 
@@ -49,7 +46,10 @@ char *number(char *buf, char *end, unsigned long num, int base, int size, int pr
49 46
 long strtol(const char *nptr, char **endptr, int base);
50 47
 float atof(const char *s);
51 48
 
  49
+#define   RAND_MAX        2147483647
  50
+
52 51
 unsigned int rand(void);
  52
+void srand(unsigned int seed);
53 53
 void abort(void);
54 54
 
55 55
 #endif /* __STDLIB_H */
2  software/libbase/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/common.mak
3 3
 
4  
-OBJECTS=divsi3.o libc.o crc16.o crc32.o console.o timer.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
  4
+OBJECTS=divsi3.o setjmp.o libc.o crc16.o crc32.o console.o timer.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
5 5
 
6 6
 all: libbase.a
7 7
 
11  software/libbase/libc.c
@@ -563,11 +563,16 @@ int sprintf(char * buf, const char *fmt, ...)
563 563
  * rand - Returns a pseudo random number
564 564
  */
565 565
 
566  
-static unsigned int seed;
  566
+static unsigned int randseed;
567 567
 unsigned int rand(void)
568 568
 {
569  
-	seed = 129 * seed + 907633385;
570  
-	return seed;
  569
+	randseed = 129 * randseed + 907633385;
  570
+	return randseed;
  571
+}
  572
+
  573
+void srand(unsigned int seed)
  574
+{
  575
+	randseed = seed;
571 576
 }
572 577
 
573 578
 void abort(void)
94  software/libbase/setjmp.S
... ...
@@ -0,0 +1,94 @@
  1
+/* 
  2
+ * setjmp/longjmp for LatticeMico32.
  3
+ * Contributed by Jon Beniston <jon@beniston.com>
  4
+ *
  5
+ * Redistribution and use in source and binary forms, with or without
  6
+ * modification, are permitted provided that the following conditions
  7
+ * are met:
  8
+ * 1. Redistributions of source code must retain the above copyright
  9
+ * notice, this list of conditions and the following disclaimer.
  10
+ * 2. Redistributions in binary form must reproduce the above copyright
  11
+ * notice, this list of conditions and the following disclaimer in the
  12
+ * documentation and/or other materials provided with the distribution.
  13
+ *
  14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24
+ * SUCH DAMAGE.
  25
+ */
  26
+ 
  27
+	.section	.text
  28
+	.align	4
  29
+
  30
+	.globl	setjmp
  31
+	.type	setjmp,@function
  32
+	.globl	longjmp
  33
+	.type	longjmp,@function
  34
+
  35
+/* setjmp: save all callee saves into jmp_buf
  36
+   r1 - Address of jmp_buf
  37
+*/
  38
+
  39
+setjmp:
  40
+        sw      (r1+0), r11
  41
+        sw      (r1+4), r12
  42
+        sw      (r1+8), r13
  43
+        sw      (r1+12), r14
  44
+        sw      (r1+16), r15
  45
+        sw      (r1+20), r16
  46
+        sw      (r1+24), r17
  47
+        sw      (r1+28), r18
  48
+        sw      (r1+32), r19
  49
+        sw      (r1+36), r20
  50
+        sw      (r1+40), r21
  51
+        sw      (r1+44), r22
  52
+        sw      (r1+48), r23
  53
+        sw      (r1+52), r24
  54
+        sw      (r1+56), r25
  55
+        sw      (r1+60), gp
  56
+        sw      (r1+64), fp
  57
+        sw      (r1+68), sp
  58
+        sw      (r1+72), ra
  59
+        mvi     r1, 0
  60
+        ret
  61
+
  62
+/* longjmp: restore all callee saves from jmp_buf
  63
+   r1 - Address of jmb_buf
  64
+   r2 - Value to return with
  65
+*/
  66
+
  67
+        .global     longjmp
  68
+        .type       longjmp,@function
  69
+        .align      4
  70
+
  71
+longjmp:
  72
+        lw      r11, (r1+0)
  73
+        lw      r12, (r1+4)
  74
+        lw      r13, (r1+8)
  75
+        lw      r14, (r1+12)
  76
+        lw      r15, (r1+16)
  77
+        lw      r16, (r1+20)
  78
+        lw      r17, (r1+24)
  79
+        lw      r18, (r1+28)
  80
+        lw      r19, (r1+32)
  81
+        lw      r20, (r1+36)
  82
+        lw      r21, (r1+40)
  83
+        lw      r22, (r1+44)
  84
+        lw      r23, (r1+48)
  85
+        lw      r24, (r1+52)
  86
+        lw      r25, (r1+56)
  87
+        lw      gp, (r1+60)
  88
+        lw      fp, (r1+64)
  89
+        lw      sp, (r1+68)
  90
+        lw      ra, (r1+72)
  91
+        mv      r1, r2
  92
+        ret
  93
+
  94
+

No commit comments for this range

Something went wrong with that request. Please try again.