Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 88a909e
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cd546ed
Choose a head ref
  • 5 commits
  • 8 files changed
  • 1 contributor

Commits on May 25, 2012

  1. software/libbase: srand and RAND_MAX

    Sebastien Bourdeauducq committed May 25, 2012
    Copy the full SHA
    8e04611 View commit details
  2. libbase: setjmp/longjmp

    Sebastien Bourdeauducq committed May 25, 2012
    Copy the full SHA
    598498e View commit details
  3. software/common.mak: support changing source directory

    Sebastien Bourdeauducq committed May 25, 2012
    Copy the full SHA
    d66835d View commit details
  4. software/libbase: improve limits.h

    Sebastien Bourdeauducq committed May 25, 2012
    Copy the full SHA
    fdc7da5 View commit details
  5. software/libbase: stddef.h

    Sebastien Bourdeauducq committed May 25, 2012
    Copy the full SHA
    cd546ed View commit details
6 changes: 3 additions & 3 deletions software/common.mak
Original file line number Diff line number Diff line change
@@ -44,9 +44,9 @@ LDFLAGS = -nostdlib -nodefaultlibs
# compile and generate dependencies, based on
# http://scottmcpeak.com/autodepend/autodepend.html

%.o: %.c
$(CC) -c $(CFLAGS) $*.c -o $*.o
@$(CC_normal) -MM $(CFLAGS) $*.c > $*.d
%.o: $(SRCDIR)%.c
$(CC) -c $(CFLAGS) $(SRCDIR)$*.c -o $*.o
@$(CC_normal) -MM $(CFLAGS) $(SRCDIR)$*.c > $*.d
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
9 changes: 7 additions & 2 deletions software/include/base/limits.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef __LIMITS_H
#define __LIMITS_H

#define INT_MIN ((((unsigned long)-1) >> 1) + 1)
#define INT_MAX (((unsigned long)-1) >> 1)
#define INT_MIN 0x7fffffff
#define INT_MAX 0x80000000

#define SHRT_MIN 0x8000
#define SHRT_MAX 0x7fff

#define UCHAR_MAX 0xff

#endif /* __LIMITS_H */
12 changes: 12 additions & 0 deletions software/include/base/setjmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __SETJMP_H
#define __SETJMP_H

#define _JBLEN 19

typedef int jmp_buf[_JBLEN];

int setjmp(jmp_buf env);
void longjmp(jmp_buf env, int val);

#endif /* __SETJMP_H */

11 changes: 11 additions & 0 deletions software/include/base/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __STDDEF_H
#define __STDDEF_H

#define NULL ((void *)0)

typedef unsigned long size_t;
typedef long ptrdiff_t;

#define offsetof(s,m) (size_t)&(((s *)0)->m)

#endif /* __STDDEF_H */
10 changes: 5 additions & 5 deletions software/include/base/stdlib.h
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
#ifndef __STDLIB_H
#define __STDLIB_H

#include <stddef.h>

#define PRINTF_ZEROPAD 1 /* pad with zero */
#define PRINTF_SIGN 2 /* unsigned/signed long */
#define PRINTF_PLUS 4 /* show plus */
@@ -27,11 +29,6 @@
#define PRINTF_SPECIAL 32 /* 0x */
#define PRINTF_LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */

typedef unsigned long size_t;
typedef long ptrdiff_t;

#define NULL ((void *)0)

#define likely(x) x
#define unlikely(x) x

@@ -49,7 +46,10 @@ char *number(char *buf, char *end, unsigned long num, int base, int size, int pr
long strtol(const char *nptr, char **endptr, int base);
float atof(const char *s);

#define RAND_MAX 2147483647

unsigned int rand(void);
void srand(unsigned int seed);
void abort(void);

#endif /* __STDLIB_H */
2 changes: 1 addition & 1 deletion software/libbase/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
M2DIR=../..
include $(M2DIR)/software/common.mak

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
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

all: libbase.a

11 changes: 8 additions & 3 deletions software/libbase/libc.c
Original file line number Diff line number Diff line change
@@ -563,11 +563,16 @@ int sprintf(char * buf, const char *fmt, ...)
* rand - Returns a pseudo random number
*/

static unsigned int seed;
static unsigned int randseed;
unsigned int rand(void)
{
seed = 129 * seed + 907633385;
return seed;
randseed = 129 * randseed + 907633385;
return randseed;
}

void srand(unsigned int seed)
{
randseed = seed;
}

void abort(void)
94 changes: 94 additions & 0 deletions software/libbase/setjmp.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* setjmp/longjmp for LatticeMico32.
* Contributed by Jon Beniston <jon@beniston.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

.section .text
.align 4

.globl setjmp
.type setjmp,@function
.globl longjmp
.type longjmp,@function

/* setjmp: save all callee saves into jmp_buf
r1 - Address of jmp_buf
*/

setjmp:
sw (r1+0), r11
sw (r1+4), r12
sw (r1+8), r13
sw (r1+12), r14
sw (r1+16), r15
sw (r1+20), r16
sw (r1+24), r17
sw (r1+28), r18
sw (r1+32), r19
sw (r1+36), r20
sw (r1+40), r21
sw (r1+44), r22
sw (r1+48), r23
sw (r1+52), r24
sw (r1+56), r25
sw (r1+60), gp
sw (r1+64), fp
sw (r1+68), sp
sw (r1+72), ra
mvi r1, 0
ret

/* longjmp: restore all callee saves from jmp_buf
r1 - Address of jmb_buf
r2 - Value to return with
*/

.global longjmp
.type longjmp,@function
.align 4

longjmp:
lw r11, (r1+0)
lw r12, (r1+4)
lw r13, (r1+8)
lw r14, (r1+12)
lw r15, (r1+16)
lw r16, (r1+20)
lw r17, (r1+24)
lw r18, (r1+28)
lw r19, (r1+32)
lw r20, (r1+36)
lw r21, (r1+40)
lw r22, (r1+44)
lw r23, (r1+48)
lw r24, (r1+52)
lw r25, (r1+56)
lw gp, (r1+60)
lw fp, (r1+64)
lw sp, (r1+68)
lw ra, (r1+72)
mv r1, r2
ret