Skip to content
Permalink
Browse files
Copy some software code from the original Milkymist SoC.
Libbase should keep its RAM usage to a minimum as it is meant to
be executed before the SDRAM is up and running. (Having lots of
code is OK though as we XIP from the flash)
  • Loading branch information
Sebastien Bourdeauducq committed Feb 3, 2012
1 parent b5cb108 commit 1a4a6eb445a51eb8953ba5285ca07be9d70b7572
Showing with 5,360 additions and 0 deletions.
  1. +45 −0 software/include.mak
  2. +24 −0 software/include/base/assert.h
  3. +35 −0 software/include/base/board.h
  4. +34 −0 software/include/base/console.h
  5. +68 −0 software/include/base/ctype.h
  6. +39 −0 software/include/base/endian.h
  7. +62 −0 software/include/base/irq.h
  8. +25 −0 software/include/base/limits.h
  9. +43 −0 software/include/base/stdarg.h
  10. +29 −0 software/include/base/stdio.h
  11. +55 −0 software/include/base/stdlib.h
  12. +39 −0 software/include/base/string.h
  13. +26 −0 software/include/base/system.h
  14. +29 −0 software/include/base/uart.h
  15. +6 −0 software/include/base/version.h
  16. +31 −0 software/include/extra/blockdev.h
  17. +24 −0 software/include/extra/crc.h
  18. +28 −0 software/include/extra/fatfs.h
  19. +34 −0 software/include/hw/capabilities.h
  20. +27 −0 software/include/hw/common.h
  21. +34 −0 software/include/hw/flash.h
  22. +35 −0 software/include/hw/gpio.h
  23. +23 −0 software/include/hw/interrupts.h
  24. +55 −0 software/include/hw/sysctl.h
  25. +39 −0 software/include/hw/uart.h
  26. +15 −0 software/libbase/Makefile
  27. +84 −0 software/libbase/atof.c
  28. +87 −0 software/libbase/board.c
  29. +108 −0 software/libbase/console.c
  30. +53 −0 software/libbase/divsi3.c
  31. +577 −0 software/libbase/libc.c
  32. +126 −0 software/libbase/milieu.h
  33. +125 −0 software/libbase/softfloat-glue.c
  34. +646 −0 software/libbase/softfloat-macros.h
  35. +125 −0 software/libbase/softfloat-specialize.h
  36. +1,030 −0 software/libbase/softfloat.c
  37. +119 −0 software/libbase/softfloat.h
  38. +82 −0 software/libbase/system.c
  39. +125 −0 software/libbase/uart.c
  40. +328 −0 software/libbase/vsnprintf.c
  41. +273 −0 software/libextra/blockdev.c
  42. +47 −0 software/libextra/crc16.c
  43. +81 −0 software/libextra/crc32.c
  44. +440 −0 software/libextra/fatfs.c
@@ -0,0 +1,45 @@
# Mico32 toolchain
#
CROSS_COMPILER=lm32-rtems4.11-

CC_normal := $(CROSS_COMPILER)gcc
AR_normal := $(CROSS_COMPILER)ar
AS_normal := $(CROSS_COMPILER)as
LD_normal := $(CROSS_COMPILER)ld
OBJCOPY_normal := $(CROSS_COMPILER)objcopy
RANLIB_normal := $(CROSS_COMPILER)ranlib

CC_quiet = @echo " CC " $@ && $(CROSS_COMPILER)gcc
AR_quiet = @echo " AR " $@ && $(CROSS_COMPILER)ar
AS_quiet = @echo " AS " $@ && $(CROSS_COMPILER)as
LD_quiet = @echo " LD " $@ && $(CROSS_COMPILER)ld
OBJCOPY_quiet = @echo " OBJCOPY " $@ && $(CROSS_COMPILER)objcopy
RANLIB_quiet = @echo " RANLIB " $@ && $(CROSS_COMPILER)ranlib

ifeq ($(V),1)
CC = $(CC_normal)
AR = $(AR_normal)
AS = $(AS_normal)
LD = $(LD_normal)
OBJCOPY = $(OBJCOPY_normal)
RANLIB = $(RANLIB_normal)
else
CC = $(CC_quiet)
AR = $(AR_quiet)
AS = $(AS_quiet)
LD = $(LD_quiet)
OBJCOPY = $(OBJCOPY_quiet)
RANLIB = $(RANLIB_quiet)
endif

# Toolchain options
#
INCLUDES_NOLIBC ?= -nostdinc -I$(MMDIR)/software/include/base
INCLUDES = $(INCLUDES_NOLIBC) -I$(MMDIR)/software/include -I$(MMDIR)/tools
ASFLAGS = $(INCLUDES) -nostdinc
# later: -Wmissing-prototypes
CFLAGS = -O9 -Wall -Wstrict-prototypes -Wold-style-definition -Wshadow \
-mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled \
-msign-extend-enabled -fno-builtin -fsigned-char \
-fsingle-precision-constant $(INCLUDES)
LDFLAGS = -nostdlib -nodefaultlibs
@@ -0,0 +1,24 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
* Copyright (C) Linux kernel developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ASSERT_H
#define __ASSERT_H

#define assert(x)

#endif /* __ASSERT_H */
@@ -0,0 +1,35 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __BOARD_H
#define __BOARD_H

#define BOARD_NAME_LEN 32

struct board_desc {
unsigned short int id;
char name[BOARD_NAME_LEN];
unsigned int ethernet_phyadr;
};

const struct board_desc *get_board_desc_id(unsigned short int id);
const struct board_desc *get_board_desc(void);
int get_pcb_revision(void);
void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
void get_soc_version_formatted(char *version);

#endif /* __BOARD_H */
@@ -0,0 +1,34 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CONSOLE_H
#define __CONSOLE_H

typedef void (*console_write_hook)(char);
typedef char (*console_read_hook)(void);
typedef int (*console_read_nonblock_hook)(void);

void console_set_write_hook(console_write_hook h);
void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn);

char readchar(void);
int readchar_nonblock(void);

int puts(const char *s);
void putsnonl(const char *s);

#endif /* __CONSOLE_H */
@@ -0,0 +1,68 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CTYPE_H
#define __CTYPE_H

static inline int isdigit(char c)
{
return (c >= '0') && (c <= '9');
}

static inline int isxdigit(char c)
{
return isdigit(c) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
}

static inline int isupper(char c)
{
return (c >= 'A') && (c <= 'Z');
}

static inline int islower(char c)
{
return (c >= 'a') && (c <= 'z');
}

static inline unsigned char tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}

static inline unsigned char toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}

static inline char isspace(unsigned char c)
{
if(c == ' '
|| c == '\f'
|| c == '\n'
|| c == '\r'
|| c == '\t'
|| c == '\v')
return 1;

return 0;
}

#endif /* __CTYPE_H */
@@ -0,0 +1,39 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ENDIAN_H
#define __ENDIAN_H

#define __LITTLE_ENDIAN 0
#define __BIG_ENDIAN 1
#define __BYTE_ORDER __BIG_ENDIAN

static inline unsigned int le32toh(unsigned int val)
{
return (val & 0xff) << 24 |
(val & 0xff00) << 8 |
(val & 0xff0000) >> 8 |
(val & 0xff000000) >> 24;
}

static inline unsigned short le16toh(unsigned short val)
{
return (val & 0xff) << 8 |
(val & 0xff00) >> 8;
}

#endif /* __ENDIAN_H */
@@ -0,0 +1,62 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __IRQ_H
#define __IRQ_H

static inline void irq_enable(unsigned int en)
{
__asm__ __volatile__("wcsr IE, %0" : : "r" (en));
}

static inline unsigned int irq_getmask(void)
{
unsigned int mask;
__asm__ __volatile__("rcsr %0, IM" : "=r" (mask));
return mask;
}

static inline void irq_setmask(unsigned int mask)
{
__asm__ __volatile__("wcsr IM, %0" : : "r" (mask));
}

static inline unsigned int irq_pending(void)
{
unsigned int pending;
__asm__ __volatile__("rcsr %0, IP" : "=r" (pending));
return pending;
}

static inline void irq_ack(unsigned int mask)
{
__asm__ __volatile__("wcsr IP, %0" : : "r" (mask));
}

static inline unsigned int irq_getie(void)
{
unsigned int ie;
__asm__ __volatile__("rcsr %0, IE" : "=r" (ie));
return ie;
}

static inline void irq_setie(unsigned int ie)
{
__asm__ __volatile__("wcsr IE, %0" : : "r" (ie));
}

#endif /* __IRQ_H */
@@ -0,0 +1,25 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
* Copyright (C) Linux kernel developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __LIMITS_H
#define __LIMITS_H

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

#endif /* __LIMITS_H */
@@ -0,0 +1,43 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
* Copyright (C) Linux kernel developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __STDARG_H
#define __STDARG_H

#include <stdlib.h>

#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
#define va_start(v,l) __builtin_va_start((v),l)
#else
#define va_start(v,l) __builtin_stdarg_start((v),l)
#endif

#define va_arg(ap, type) \
__builtin_va_arg((ap), type)

#define va_end(ap) \
__builtin_va_end(ap)

#define va_list \
__builtin_va_list

int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
int vsprintf(char *buf, const char *fmt, va_list args);

#endif /* __STDARG_H */
Loading

0 comments on commit 1a4a6eb

Please sign in to comment.