Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 1a4a6eb445a51eb8953ba5285ca07be9d70b7572 1 parent b5cb108
Sébastien Bourdeauducq authored February 03, 2012

Showing 44 changed files with 5,360 additions and 0 deletions. Show diff stats Hide diff stats

  1. 45  software/include.mak
  2. 24  software/include/base/assert.h
  3. 35  software/include/base/board.h
  4. 34  software/include/base/console.h
  5. 68  software/include/base/ctype.h
  6. 39  software/include/base/endian.h
  7. 62  software/include/base/irq.h
  8. 25  software/include/base/limits.h
  9. 43  software/include/base/stdarg.h
  10. 29  software/include/base/stdio.h
  11. 55  software/include/base/stdlib.h
  12. 39  software/include/base/string.h
  13. 26  software/include/base/system.h
  14. 29  software/include/base/uart.h
  15. 6  software/include/base/version.h
  16. 31  software/include/extra/blockdev.h
  17. 24  software/include/extra/crc.h
  18. 28  software/include/extra/fatfs.h
  19. 34  software/include/hw/capabilities.h
  20. 27  software/include/hw/common.h
  21. 34  software/include/hw/flash.h
  22. 35  software/include/hw/gpio.h
  23. 23  software/include/hw/interrupts.h
  24. 55  software/include/hw/sysctl.h
  25. 39  software/include/hw/uart.h
  26. 15  software/libbase/Makefile
  27. 84  software/libbase/atof.c
  28. 87  software/libbase/board.c
  29. 108  software/libbase/console.c
  30. 53  software/libbase/divsi3.c
  31. 577  software/libbase/libc.c
  32. 126  software/libbase/milieu.h
  33. 125  software/libbase/softfloat-glue.c
  34. 646  software/libbase/softfloat-macros.h
  35. 125  software/libbase/softfloat-specialize.h
  36. 1,030  software/libbase/softfloat.c
  37. 119  software/libbase/softfloat.h
  38. 82  software/libbase/system.c
  39. 125  software/libbase/uart.c
  40. 328  software/libbase/vsnprintf.c
  41. 273  software/libextra/blockdev.c
  42. 47  software/libextra/crc16.c
  43. 81  software/libextra/crc32.c
  44. 440  software/libextra/fatfs.c
45  software/include.mak
... ...
@@ -0,0 +1,45 @@
  1
+# Mico32 toolchain
  2
+#
  3
+CROSS_COMPILER=lm32-rtems4.11-
  4
+
  5
+CC_normal := $(CROSS_COMPILER)gcc
  6
+AR_normal := $(CROSS_COMPILER)ar
  7
+AS_normal := $(CROSS_COMPILER)as
  8
+LD_normal := $(CROSS_COMPILER)ld
  9
+OBJCOPY_normal := $(CROSS_COMPILER)objcopy
  10
+RANLIB_normal  := $(CROSS_COMPILER)ranlib
  11
+
  12
+CC_quiet = @echo " CC " $@ && $(CROSS_COMPILER)gcc
  13
+AR_quiet = @echo " AR " $@ && $(CROSS_COMPILER)ar
  14
+AS_quiet = @echo " AS " $@ && $(CROSS_COMPILER)as
  15
+LD_quiet = @echo " LD " $@ && $(CROSS_COMPILER)ld
  16
+OBJCOPY_quiet = @echo " OBJCOPY " $@ && $(CROSS_COMPILER)objcopy
  17
+RANLIB_quiet  = @echo " RANLIB  " $@ && $(CROSS_COMPILER)ranlib
  18
+
  19
+ifeq ($(V),1)
  20
+    CC = $(CC_normal)
  21
+    AR = $(AR_normal)
  22
+    AS = $(AS_normal)
  23
+    LD = $(LD_normal)
  24
+    OBJCOPY = $(OBJCOPY_normal)
  25
+    RANLIB  = $(RANLIB_normal)
  26
+else
  27
+    CC = $(CC_quiet)
  28
+    AR = $(AR_quiet)
  29
+    AS = $(AS_quiet)
  30
+    LD = $(LD_quiet)
  31
+    OBJCOPY = $(OBJCOPY_quiet)
  32
+    RANLIB  = $(RANLIB_quiet)
  33
+endif
  34
+
  35
+# Toolchain options
  36
+#
  37
+INCLUDES_NOLIBC ?= -nostdinc -I$(MMDIR)/software/include/base
  38
+INCLUDES = $(INCLUDES_NOLIBC) -I$(MMDIR)/software/include -I$(MMDIR)/tools
  39
+ASFLAGS = $(INCLUDES) -nostdinc
  40
+# later: -Wmissing-prototypes
  41
+CFLAGS = -O9 -Wall -Wstrict-prototypes -Wold-style-definition -Wshadow \
  42
+	 -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled \
  43
+	 -msign-extend-enabled -fno-builtin -fsigned-char \
  44
+	 -fsingle-precision-constant $(INCLUDES)
  45
+LDFLAGS = -nostdlib -nodefaultlibs
24  software/include/base/assert.h
... ...
@@ -0,0 +1,24 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ * Copyright (C) Linux kernel developers
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17
+ */
  18
+
  19
+#ifndef __ASSERT_H
  20
+#define __ASSERT_H
  21
+
  22
+#define assert(x)
  23
+
  24
+#endif /* __ASSERT_H */
35  software/include/base/board.h
... ...
@@ -0,0 +1,35 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __BOARD_H
  19
+#define __BOARD_H
  20
+
  21
+#define BOARD_NAME_LEN 32
  22
+
  23
+struct board_desc {
  24
+	unsigned short int id;
  25
+	char name[BOARD_NAME_LEN];
  26
+	unsigned int ethernet_phyadr;
  27
+};
  28
+
  29
+const struct board_desc *get_board_desc_id(unsigned short int id);
  30
+const struct board_desc *get_board_desc(void);
  31
+int get_pcb_revision(void);
  32
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
  33
+void get_soc_version_formatted(char *version);
  34
+
  35
+#endif /* __BOARD_H */
34  software/include/base/console.h
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __CONSOLE_H
  19
+#define __CONSOLE_H
  20
+
  21
+typedef void (*console_write_hook)(char);
  22
+typedef char (*console_read_hook)(void);
  23
+typedef int (*console_read_nonblock_hook)(void);
  24
+
  25
+void console_set_write_hook(console_write_hook h);
  26
+void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn);
  27
+
  28
+char readchar(void);
  29
+int readchar_nonblock(void);
  30
+
  31
+int puts(const char *s);
  32
+void putsnonl(const char *s);
  33
+
  34
+#endif /* __CONSOLE_H */
68  software/include/base/ctype.h
... ...
@@ -0,0 +1,68 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __CTYPE_H
  19
+#define __CTYPE_H
  20
+
  21
+static inline int isdigit(char c)
  22
+{
  23
+	return (c >= '0') && (c <= '9');
  24
+}
  25
+
  26
+static inline int isxdigit(char c)
  27
+{
  28
+	return isdigit(c) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
  29
+}
  30
+
  31
+static inline int isupper(char c)
  32
+{
  33
+	return (c >= 'A') && (c <= 'Z');
  34
+}
  35
+
  36
+static inline int islower(char c)
  37
+{
  38
+	return (c >= 'a') && (c <= 'z');
  39
+}
  40
+
  41
+static inline unsigned char tolower(unsigned char c)
  42
+{
  43
+	if (isupper(c))
  44
+		c -= 'A'-'a';
  45
+	return c;
  46
+}
  47
+
  48
+static inline unsigned char toupper(unsigned char c)
  49
+{
  50
+	if (islower(c))
  51
+		c -= 'a'-'A';
  52
+	return c;
  53
+}
  54
+
  55
+static inline char isspace(unsigned char c)
  56
+{
  57
+	if(c == ' '
  58
+		|| c == '\f'
  59
+		|| c == '\n'
  60
+		|| c == '\r'
  61
+		|| c == '\t'
  62
+		|| c == '\v')
  63
+		return 1;
  64
+
  65
+	return 0;
  66
+}
  67
+
  68
+#endif /* __CTYPE_H */
39  software/include/base/endian.h
... ...
@@ -0,0 +1,39 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ * 
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ * 
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ * 
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __ENDIAN_H
  19
+#define __ENDIAN_H
  20
+
  21
+#define __LITTLE_ENDIAN 0
  22
+#define __BIG_ENDIAN 1
  23
+#define __BYTE_ORDER __BIG_ENDIAN
  24
+
  25
+static inline unsigned int le32toh(unsigned int val)
  26
+{
  27
+	return (val & 0xff) << 24 |
  28
+		(val & 0xff00) << 8 |
  29
+		(val & 0xff0000) >> 8 |
  30
+		(val & 0xff000000) >> 24;
  31
+}
  32
+
  33
+static inline unsigned short le16toh(unsigned short val)
  34
+{
  35
+	return (val & 0xff) << 8 |
  36
+		(val & 0xff00) >> 8;
  37
+}
  38
+
  39
+#endif /* __ENDIAN_H */
62  software/include/base/irq.h
... ...
@@ -0,0 +1,62 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __IRQ_H
  19
+#define __IRQ_H
  20
+
  21
+static inline void irq_enable(unsigned int en)
  22
+{
  23
+       __asm__ __volatile__("wcsr IE, %0" : : "r" (en));
  24
+}
  25
+
  26
+static inline unsigned int irq_getmask(void)
  27
+{
  28
+       unsigned int mask;
  29
+       __asm__ __volatile__("rcsr %0, IM" : "=r" (mask));
  30
+       return mask;
  31
+}
  32
+
  33
+static inline void irq_setmask(unsigned int mask)
  34
+{
  35
+       __asm__ __volatile__("wcsr IM, %0" : : "r" (mask));
  36
+}
  37
+
  38
+static inline unsigned int irq_pending(void)
  39
+{
  40
+       unsigned int pending;
  41
+       __asm__ __volatile__("rcsr %0, IP" : "=r" (pending));
  42
+       return pending;
  43
+}
  44
+
  45
+static inline void irq_ack(unsigned int mask)
  46
+{
  47
+       __asm__ __volatile__("wcsr IP, %0" : : "r" (mask));
  48
+}
  49
+
  50
+static inline unsigned int irq_getie(void)
  51
+{
  52
+       unsigned int ie;
  53
+       __asm__ __volatile__("rcsr %0, IE" : "=r" (ie));
  54
+       return ie;
  55
+}
  56
+
  57
+static inline void irq_setie(unsigned int ie)
  58
+{
  59
+       __asm__ __volatile__("wcsr IE, %0" : : "r" (ie));
  60
+}
  61
+
  62
+#endif /* __IRQ_H */
25  software/include/base/limits.h
... ...
@@ -0,0 +1,25 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ * Copyright (C) Linux kernel developers
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17
+ */
  18
+
  19
+#ifndef __LIMITS_H
  20
+#define __LIMITS_H
  21
+
  22
+#define INT_MIN ((((unsigned long)-1) >> 1) + 1)
  23
+#define INT_MAX (((unsigned long)-1) >> 1)
  24
+
  25
+#endif /* __LIMITS_H */
43  software/include/base/stdarg.h
... ...
@@ -0,0 +1,43 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ * Copyright (C) Linux kernel developers
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17
+ */
  18
+
  19
+#ifndef __STDARG_H
  20
+#define __STDARG_H
  21
+
  22
+#include <stdlib.h>
  23
+
  24
+#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
  25
+#define va_start(v,l) __builtin_va_start((v),l)
  26
+#else
  27
+#define va_start(v,l) __builtin_stdarg_start((v),l)
  28
+#endif
  29
+
  30
+#define va_arg(ap, type) \
  31
+	__builtin_va_arg((ap), type)
  32
+
  33
+#define va_end(ap) \
  34
+	__builtin_va_end(ap)
  35
+
  36
+#define va_list \
  37
+	__builtin_va_list
  38
+
  39
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
  40
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
  41
+int vsprintf(char *buf, const char *fmt, va_list args);
  42
+
  43
+#endif /* __STDARG_H */
29  software/include/base/stdio.h
... ...
@@ -0,0 +1,29 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __STDIO_H
  19
+#define __STDIO_H
  20
+
  21
+#include <stdlib.h>
  22
+
  23
+int snprintf(char *buf, size_t size, const char *fmt, ...);
  24
+int scnprintf(char *buf, size_t size, const char *fmt, ...);
  25
+int sprintf(char *buf, const char *fmt, ...);
  26
+
  27
+int printf(const char *fmt, ...);
  28
+
  29
+#endif /* __STDIO_H */
55  software/include/base/stdlib.h
... ...
@@ -0,0 +1,55 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2011 Sebastien Bourdeauducq
  4
+ * Copyright (C) Linux kernel developers
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17
+ */
  18
+
  19
+#ifndef __STDLIB_H
  20
+#define __STDLIB_H
  21
+
  22
+#define PRINTF_ZEROPAD	1		/* pad with zero */
  23
+#define PRINTF_SIGN	2		/* unsigned/signed long */
  24
+#define PRINTF_PLUS	4		/* show plus */
  25
+#define PRINTF_SPACE	8		/* space if plus */
  26
+#define PRINTF_LEFT	16		/* left justified */
  27
+#define PRINTF_SPECIAL	32		/* 0x */
  28
+#define PRINTF_LARGE	64		/* use 'ABCDEF' instead of 'abcdef' */
  29
+
  30
+typedef int size_t;
  31
+typedef int ptrdiff_t;
  32
+
  33
+#define NULL ((void *)0)
  34
+
  35
+#define likely(x) x
  36
+#define unlikely(x) x
  37
+
  38
+#define abs(x) ((x) > 0 ? (x) : -(x))
  39
+
  40
+unsigned long strtoul(const char *nptr, char **endptr, int base);
  41
+int skip_atoi(const char **s);
  42
+static inline int atoi(const char *nptr) {
  43
+	return strtoul(nptr, NULL, 0);
  44
+}
  45
+static inline long atol(const char *nptr) {
  46
+	return (long)atoi(nptr);
  47
+}
  48
+char *number(char *buf, char *end, unsigned long num, int base, int size, int precision, int type);
  49
+long strtol(const char *nptr, char **endptr, int base);
  50
+float atof(const char *s);
  51
+
  52
+unsigned int rand(void);
  53
+void abort(void);
  54
+
  55
+#endif /* __STDLIB_H */
39  software/include/base/string.h
... ...
@@ -0,0 +1,39 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ * Copyright (C) Linus Torvalds and Linux kernel developers
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17
+ */
  18
+
  19
+#ifndef __STRING_H
  20
+#define __STRING_H
  21
+
  22
+#include <stdlib.h>
  23
+
  24
+char *strchr(const char *s, int c);
  25
+char *strrchr(const char *s, int c);
  26
+char *strnchr(const char *s, size_t count, int c);
  27
+char *strcpy(char *dest, const char *src);
  28
+char *strncpy(char *dest, const char *src, size_t count);
  29
+int strcmp(const char *cs, const char *ct);
  30
+int strncmp(const char *cs, const char *ct, size_t count);
  31
+size_t strlen(const char *s);
  32
+size_t strnlen(const char *s, size_t count);
  33
+int memcmp(const void *cs, const void *ct, size_t count);
  34
+void *memset(void *s, int c, size_t count);
  35
+void *memcpy(void *to, const void *from, size_t n);
  36
+void *memmove(void *dest, const void *src, size_t count);
  37
+char *strstr(const char *s1, const char *s2);
  38
+
  39
+#endif /* __STRING_H */
26  software/include/base/system.h
... ...
@@ -0,0 +1,26 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __SYSTEM_H
  19
+#define __SYSTEM_H
  20
+
  21
+void flush_cpu_icache(void);
  22
+void flush_cpu_dcache(void);
  23
+__attribute__((noreturn)) void reboot(void);
  24
+__attribute__((noreturn)) void reconf(void);
  25
+
  26
+#endif /* __SYSTEM_H */
29  software/include/base/uart.h
... ...
@@ -0,0 +1,29 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __UART_H
  19
+#define __UART_H
  20
+
  21
+void uart_init(void);
  22
+void uart_isr(void);
  23
+void uart_sync(void);
  24
+
  25
+void uart_write(char c);
  26
+char uart_read(void);
  27
+int uart_read_nonblock(void);
  28
+
  29
+#endif
6  software/include/base/version.h
... ...
@@ -0,0 +1,6 @@
  1
+#ifndef __VERSION_H
  2
+#define __VERSION_H
  3
+
  4
+#define VERSION "2.0-X"
  5
+
  6
+#endif /* __VERSION_H */
31  software/include/extra/blockdev.h
... ...
@@ -0,0 +1,31 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __BLOCKDEV_H
  19
+#define __BLOCKDEV_H
  20
+
  21
+enum {
  22
+	BLOCKDEV_MEMORY_CARD
  23
+};
  24
+
  25
+int bd_init(int devnr);
  26
+int bd_readblock(unsigned int block, void *buffer);
  27
+void bd_done(void);
  28
+
  29
+int bd_has_part_table(int devnr);
  30
+
  31
+#endif /* __BLOCKDEV_H */
24  software/include/extra/crc.h
... ...
@@ -0,0 +1,24 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __CRC_H
  19
+#define __CRC_H
  20
+
  21
+unsigned short crc16(const unsigned char *buffer, int len);
  22
+unsigned int crc32(const unsigned char *buffer, unsigned int len);
  23
+
  24
+#endif
28  software/include/extra/fatfs.h
... ...
@@ -0,0 +1,28 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __FATFS_H
  19
+#define __FATFS_H
  20
+
  21
+typedef int (*fatfs_dir_callback)(const char *, const char *, void *);
  22
+
  23
+int fatfs_init(int devnr);
  24
+int fatfs_list_files(fatfs_dir_callback cb, void *param);
  25
+int fatfs_load(const char *filename, char *buffer, int size, int *realsize);
  26
+void fatfs_done(void);
  27
+
  28
+#endif /* __FATFS_H */
34  software/include/hw/capabilities.h
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_CAPABILITIES
  19
+#define __HW_CAPABILITIES
  20
+
  21
+#define CAP_MEMORYCARD		(0x00000001)
  22
+#define CAP_AC97		(0x00000002)
  23
+#define CAP_PFPU		(0x00000004)
  24
+#define CAP_TMU			(0x00000008)
  25
+#define CAP_ETHERNET		(0x00000010)
  26
+#define CAP_FMLMETER		(0x00000020)
  27
+#define CAP_VIDEOIN		(0x00000040)
  28
+#define CAP_MIDI		(0x00000080)
  29
+#define CAP_DMX			(0x00000100)
  30
+#define CAP_IR			(0x00000200)
  31
+#define CAP_USB			(0x00000400)
  32
+#define CAP_MEMTEST		(0x00000800)
  33
+
  34
+#endif /* __HW_CAPABILITIES */
27  software/include/hw/common.h
... ...
@@ -0,0 +1,27 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_COMMON_H
  19
+#define __HW_COMMON_H
  20
+
  21
+#ifdef __ASSEMBLER__
  22
+#define MMPTR(x) x
  23
+#else
  24
+#define MMPTR(x) (*((volatile unsigned int *)(x)))
  25
+#endif
  26
+
  27
+#endif
34  software/include/hw/flash.h
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_FLASH_H
  19
+#define __HW_FLASH_H
  20
+
  21
+#define FLASH_OFFSET_STANDBY_BITSTREAM	(0x00000000) /* 640k */
  22
+
  23
+#define FLASH_OFFSET_RESCUE_BITSTREAM	(0x000A0000) /* 1536k */
  24
+#define FLASH_OFFSET_RESCUE_BIOS	(0x00220000) /* 128k */
  25
+#define FLASH_OFFSET_MAC_ADDRESS	(0x002200E0) /* within rescue BIOS */
  26
+#define FLASH_OFFSET_RESCUE_SPLASH	(0x00240000) /* 640k */
  27
+#define FLASH_OFFSET_RESCUE_APP		(0x002E0000) /* 4096k */
  28
+
  29
+#define FLASH_OFFSET_REGULAR_BITSTREAM	(0x006E0000) /* 1536k */
  30
+#define FLASH_OFFSET_REGULAR_BIOS	(0x00860000) /* 128k */
  31
+#define FLASH_OFFSET_REGULAR_SPLASH	(0x00880000) /* 640k */
  32
+#define FLASH_OFFSET_REGULAR_APP	(0x00920000) /* remaining space (23424k) */
  33
+
  34
+#endif /* __HW_FLASH_H */
35  software/include/hw/gpio.h
... ...
@@ -0,0 +1,35 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_GPIO_H
  19
+#define __HW_GPIO_H
  20
+
  21
+/* Inputs */
  22
+#define GPIO_BTN1	(0x00000001)
  23
+#define GPIO_BTN2	(0x00000002)
  24
+#define GPIO_BTN3	(0x00000004)
  25
+
  26
+#define GPIO_PCBREV0	(0x00000008)
  27
+#define GPIO_PCBREV1	(0x00000010)
  28
+#define GPIO_PCBREV2	(0x00000020)
  29
+#define GPIO_PCBREV3	(0x00000040)
  30
+
  31
+/* Outputs */
  32
+#define GPIO_LED1	(0x00000001)
  33
+#define GPIO_LED2	(0x00000002)
  34
+
  35
+#endif /* __HW_GPIO_H */
23  software/include/hw/interrupts.h
... ...
@@ -0,0 +1,23 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_INTERRUPTS_H
  19
+#define __HW_INTERRUPTS_H
  20
+
  21
+#define IRQ_UART		(0x00000001) /* 0 */
  22
+
  23
+#endif /* __HW_INTERRUPTS_H */
55  software/include/hw/sysctl.h
... ...
@@ -0,0 +1,55 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_SYSCTL_H
  19
+#define __HW_SYSCTL_H
  20
+
  21
+#include <hw/common.h>
  22
+
  23
+#define CSR_GPIO_IN		MMPTR(0xe0001000)
  24
+#define CSR_GPIO_OUT		MMPTR(0xe0001004)
  25
+#define CSR_GPIO_INTEN		MMPTR(0xe0001008)
  26
+
  27
+#define CSR_TIMER0_CONTROL	MMPTR(0xe0001010)
  28
+#define CSR_TIMER0_COMPARE	MMPTR(0xe0001014)
  29
+#define CSR_TIMER0_COUNTER	MMPTR(0xe0001018)
  30
+
  31
+#define CSR_TIMER1_CONTROL	MMPTR(0xe0001020)
  32
+#define CSR_TIMER1_COMPARE	MMPTR(0xe0001024)
  33
+#define CSR_TIMER1_COUNTER	MMPTR(0xe0001028)
  34
+
  35
+#define TIMER_ENABLE		(0x01)
  36
+#define TIMER_AUTORESTART	(0x02)
  37
+
  38
+#define CSR_ICAP		MMPTR(0xe0001040)
  39
+
  40
+#define ICAP_READY		(0x01)
  41
+
  42
+#define ICAP_CE			(0x10000)
  43
+#define ICAP_WRITE		(0x20000)
  44
+
  45
+#define CSR_DBG_SCRATCHPAD	MMPTR(0xe0001050)
  46
+#define CSR_DBG_CTRL		MMPTR(0xe0001054)
  47
+
  48
+#define DBG_CTRL_GDB_ROM_LOCK	(0x01)
  49
+#define DBG_CTRL_BUS_ERR_EN	(0x02)
  50
+
  51
+#define CSR_FREQUENCY		MMPTR(0xe0001074)
  52
+#define CSR_CAPABILITIES	MMPTR(0xe0001078)
  53
+#define CSR_SYSTEM_ID		MMPTR(0xe000107c)
  54
+
  55
+#endif /* __HW_SYSCTL_H */
39  software/include/hw/uart.h
... ...
@@ -0,0 +1,39 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_UART_H
  19
+#define __HW_UART_H
  20
+
  21
+#include <hw/common.h>
  22
+
  23
+#define CSR_UART_RXTX 		MMPTR(0xe0000000)
  24
+#define CSR_UART_DIVISOR	MMPTR(0xe0000004)
  25
+#define CSR_UART_STAT		MMPTR(0xe0000008)
  26
+#define CSR_UART_CTRL		MMPTR(0xe000000c)
  27
+#define CSR_UART_DEBUG		MMPTR(0xe0000010)
  28
+
  29
+#define UART_STAT_THRE		(0x1)
  30
+#define UART_STAT_RX_EVT	(0x2)
  31
+#define UART_STAT_TX_EVT	(0x4)
  32
+
  33
+#define UART_CTRL_RX_INT	(0x1)
  34
+#define UART_CTRL_TX_INT	(0x2)
  35
+#define UART_CTRL_THRU		(0x4)
  36
+
  37
+#define UART_DEBUG_BREAK_EN	(0x1)
  38
+
  39
+#endif /* __HW_UART_H */
15  software/libbase/Makefile
... ...
@@ -0,0 +1,15 @@
  1
+MMDIR=../..
  2
+include $(MMDIR)/software/include.mak
  3
+
  4
+OBJECTS=divsi3.o libc.o console.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
  5
+
  6
+all: libbase.a
  7
+
  8
+libbase.a: $(OBJECTS)
  9
+	$(AR) clr libbase.a $(OBJECTS)
  10
+	$(RANLIB) libbase.a
  11
+
  12
+.PHONY: clean
  13
+
  14
+clean:
  15
+	rm -f *.o libbase.a .*~ *~ Makefile.bak
84  software/libbase/atof.c
... ...
@@ -0,0 +1,84 @@
  1
+/*  atof.c: converts an ASCII string to float
  2
+
  3
+    Copyright (C) 2003  Jesus Calvino-Fraga, jesusc@ieee.org
  4
+
  5
+    This library is free software; you can redistribute it and/or
  6
+    modify it under the terms of the GNU Lesser General Public
  7
+    License as published by the Free Software Foundation; either
  8
+    version 2.1 of the License, or (at your option) any later version.
  9
+
  10
+    This library is distributed in the hope that it will be useful,
  11
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13
+    Lesser General Public License for more details.
  14
+
  15
+    You should have received a copy of the GNU Lesser General Public
  16
+    License along with this library; if not, write to the Free Software
  17
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
  18
+
  19
+#include <stdlib.h>
  20
+#include <ctype.h>
  21
+
  22
+float atof(const char * s)
  23
+{
  24
+	float value, fraction;
  25
+	char iexp;
  26
+	char sign;
  27
+
  28
+	//Skip leading blanks
  29
+	while (isspace(*s)) s++;
  30
+
  31
+	//Get the sign
  32
+	if (*s == '-')
  33
+	{
  34
+		sign=1;
  35
+		s++;
  36
+	}
  37
+	else
  38
+	{
  39
+		sign=0;
  40
+		if (*s == '+') s++;
  41
+	}
  42
+
  43
+	//Get the integer part
  44
+	for (value=0.0f; isdigit(*s); s++)
  45
+	{
  46
+		value=10.0f*value+(*s-'0');
  47
+	}
  48
+
  49
+	//Get the fraction
  50
+	if (*s == '.')
  51
+	{
  52
+		s++;
  53
+		for (fraction=0.1f; isdigit(*s); s++)
  54
+		{
  55
+			value+=(*s-'0')*fraction;
  56
+			fraction*=0.1f;
  57
+		}
  58
+	}
  59
+
  60
+	//Finally, the exponent (not very efficient, but enough for now)
  61
+	if (toupper(*s)=='E')
  62
+	{
  63
+		s++;
  64
+		iexp=(char)atoi(s);
  65
+		{
  66
+			while(iexp!=0)
  67
+			{
  68
+				if(iexp<0)
  69
+				{
  70
+					value*=0.1f;
  71
+					iexp++;
  72
+				}
  73
+				else
  74
+				{
  75
+					value*=10.0f;
  76
+					iexp--;
  77
+				}
  78
+			}
  79
+		}
  80
+	}
  81
+
  82
+	if(sign) value*=-1.0f;
  83
+	return (value);
  84
+}
87  software/libbase/board.c
... ...
@@ -0,0 +1,87 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2011 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <hw/sysctl.h>
  19
+#include <hw/gpio.h>
  20
+#include <stdio.h>
  21
+#include <stdlib.h>
  22
+#include <board.h>
  23
+
  24
+static const struct board_desc boards[1] = {
  25
+	{
  26
+		.id = 0x4D31, /* M1 */
  27
+		.name = "Milkymist One",
  28
+		.ethernet_phyadr = 1
  29
+	},
  30
+};
  31
+
  32
+const struct board_desc *get_board_desc_id(unsigned short int id)
  33
+{
  34
+	unsigned int i;
  35
+
  36
+	for(i=0;i<sizeof(boards)/sizeof(boards[0]);i++)
  37
+		if(boards[i].id == id)
  38
+			return &boards[i];
  39
+	return NULL;
  40
+}
  41
+
  42
+const struct board_desc *get_board_desc(void)
  43
+{
  44
+	return get_board_desc_id(CSR_SYSTEM_ID & 0xffff);
  45
+}
  46
+
  47
+int get_pcb_revision(void)
  48
+{
  49
+	int r;
  50
+	unsigned int io;
  51
+
  52
+	io = CSR_GPIO_IN;
  53
+	r = 0;
  54
+	if(io & GPIO_PCBREV0)
  55
+		r |= 0x1;
  56
+	if(io & GPIO_PCBREV1)
  57
+		r |= 0x2;
  58
+	if(io & GPIO_PCBREV2)
  59
+		r |= 0x4;
  60
+	if(io & GPIO_PCBREV3)
  61
+		r |= 0x8;
  62
+	return r;
  63
+}
  64
+
  65
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
  66
+{
  67
+	unsigned int id;
  68
+
  69
+	id = CSR_SYSTEM_ID;
  70
+	*major = (id & 0xf0000000) >> 28;
  71
+	*minor = (id & 0x0f000000) >> 24;
  72
+	*subminor = (id & 0x00f00000) >> 20;
  73
+	*rc = (id & 0x000f0000) >> 16;
  74
+}
  75
+
  76
+void get_soc_version_formatted(char *version)
  77
+{
  78
+	unsigned int major, minor, subminor, rc;
  79
+
  80
+	get_soc_version(&major, &minor, &subminor, &rc);
  81
+
  82
+	version += sprintf(version, "%u.%u", major, minor);
  83
+	if(subminor != 0)
  84
+		version += sprintf(version, ".%u", subminor);
  85
+	if(rc != 0)
  86
+		sprintf(version, "RC%u", rc);
  87
+}
108  software/libbase/console.c
... ...
@@ -0,0 +1,108 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <uart.h>
  19
+#include <console.h>
  20
+#include <stdio.h>
  21
+#include <stdarg.h>
  22
+#include <irq.h>
  23
+#include <hw/interrupts.h>
  24
+