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)
This commit is contained in:
Sebastien Bourdeauducq 2012-02-03 12:08:17 +01:00
parent b5cb1083ab
commit 1a4a6eb445
44 changed files with 5360 additions and 0 deletions

45
software/include.mak Normal file
View File

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

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -0,0 +1,29 @@
/*
* 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 __STDIO_H
#define __STDIO_H
#include <stdlib.h>
int snprintf(char *buf, size_t size, const char *fmt, ...);
int scnprintf(char *buf, size_t size, const char *fmt, ...);
int sprintf(char *buf, const char *fmt, ...);
int printf(const char *fmt, ...);
#endif /* __STDIO_H */

View File

@ -0,0 +1,55 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 2011 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 __STDLIB_H
#define __STDLIB_H
#define PRINTF_ZEROPAD 1 /* pad with zero */
#define PRINTF_SIGN 2 /* unsigned/signed long */
#define PRINTF_PLUS 4 /* show plus */
#define PRINTF_SPACE 8 /* space if plus */
#define PRINTF_LEFT 16 /* left justified */
#define PRINTF_SPECIAL 32 /* 0x */
#define PRINTF_LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
typedef int size_t;
typedef int ptrdiff_t;
#define NULL ((void *)0)
#define likely(x) x
#define unlikely(x) x
#define abs(x) ((x) > 0 ? (x) : -(x))
unsigned long strtoul(const char *nptr, char **endptr, int base);
int skip_atoi(const char **s);
static inline int atoi(const char *nptr) {
return strtoul(nptr, NULL, 0);
}
static inline long atol(const char *nptr) {
return (long)atoi(nptr);
}
char *number(char *buf, char *end, unsigned long num, int base, int size, int precision, int type);
long strtol(const char *nptr, char **endptr, int base);
float atof(const char *s);
unsigned int rand(void);
void abort(void);
#endif /* __STDLIB_H */

View File

@ -0,0 +1,39 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
* Copyright (C) Linus Torvalds and 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 __STRING_H
#define __STRING_H
#include <stdlib.h>
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strnchr(const char *s, size_t count, int c);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t count);
int strcmp(const char *cs, const char *ct);
int strncmp(const char *cs, const char *ct, size_t count);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t count);
int memcmp(const void *cs, const void *ct, size_t count);
void *memset(void *s, int c, size_t count);
void *memcpy(void *to, const void *from, size_t n);
void *memmove(void *dest, const void *src, size_t count);
char *strstr(const char *s1, const char *s2);
#endif /* __STRING_H */

View File

@ -0,0 +1,26 @@
/*
* 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 __SYSTEM_H
#define __SYSTEM_H
void flush_cpu_icache(void);
void flush_cpu_dcache(void);
__attribute__((noreturn)) void reboot(void);
__attribute__((noreturn)) void reconf(void);
#endif /* __SYSTEM_H */

View File

@ -0,0 +1,29 @@
/*
* 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 __UART_H
#define __UART_H
void uart_init(void);
void uart_isr(void);
void uart_sync(void);
void uart_write(char c);
char uart_read(void);
int uart_read_nonblock(void);
#endif

View File

@ -0,0 +1,6 @@
#ifndef __VERSION_H
#define __VERSION_H
#define VERSION "2.0-X"
#endif /* __VERSION_H */

View File

@ -0,0 +1,31 @@
/*
* 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 __BLOCKDEV_H
#define __BLOCKDEV_H
enum {
BLOCKDEV_MEMORY_CARD
};
int bd_init(int devnr);
int bd_readblock(unsigned int block, void *buffer);
void bd_done(void);
int bd_has_part_table(int devnr);
#endif /* __BLOCKDEV_H */

View File

@ -0,0 +1,24 @@
/*
* 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 __CRC_H
#define __CRC_H
unsigned short crc16(const unsigned char *buffer, int len);
unsigned int crc32(const unsigned char *buffer, unsigned int len);
#endif

View File

@ -0,0 +1,28 @@
/*
* 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 __FATFS_H
#define __FATFS_H
typedef int (*fatfs_dir_callback)(const char *, const char *, void *);
int fatfs_init(int devnr);
int fatfs_list_files(fatfs_dir_callback cb, void *param);
int fatfs_load(const char *filename, char *buffer, int size, int *realsize);
void fatfs_done(void);
#endif /* __FATFS_H */

View File

@ -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 __HW_CAPABILITIES
#define __HW_CAPABILITIES
#define CAP_MEMORYCARD (0x00000001)
#define CAP_AC97 (0x00000002)
#define CAP_PFPU (0x00000004)
#define CAP_TMU (0x00000008)
#define CAP_ETHERNET (0x00000010)
#define CAP_FMLMETER (0x00000020)
#define CAP_VIDEOIN (0x00000040)
#define CAP_MIDI (0x00000080)
#define CAP_DMX (0x00000100)
#define CAP_IR (0x00000200)
#define CAP_USB (0x00000400)
#define CAP_MEMTEST (0x00000800)
#endif /* __HW_CAPABILITIES */

View File

@ -0,0 +1,27 @@
/*
* 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 __HW_COMMON_H
#define __HW_COMMON_H
#ifdef __ASSEMBLER__
#define MMPTR(x) x
#else
#define MMPTR(x) (*((volatile unsigned int *)(x)))
#endif
#endif

View File

@ -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 __HW_FLASH_H
#define __HW_FLASH_H
#define FLASH_OFFSET_STANDBY_BITSTREAM (0x00000000) /* 640k */
#define FLASH_OFFSET_RESCUE_BITSTREAM (0x000A0000) /* 1536k */
#define FLASH_OFFSET_RESCUE_BIOS (0x00220000) /* 128k */
#define FLASH_OFFSET_MAC_ADDRESS (0x002200E0) /* within rescue BIOS */
#define FLASH_OFFSET_RESCUE_SPLASH (0x00240000) /* 640k */
#define FLASH_OFFSET_RESCUE_APP (0x002E0000) /* 4096k */
#define FLASH_OFFSET_REGULAR_BITSTREAM (0x006E0000) /* 1536k */
#define FLASH_OFFSET_REGULAR_BIOS (0x00860000) /* 128k */
#define FLASH_OFFSET_REGULAR_SPLASH (0x00880000) /* 640k */
#define FLASH_OFFSET_REGULAR_APP (0x00920000) /* remaining space (23424k) */
#endif /* __HW_FLASH_H */

View File

@ -0,0 +1,35 @@
/*
* 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 __HW_GPIO_H
#define __HW_GPIO_H
/* Inputs */
#define GPIO_BTN1 (0x00000001)
#define GPIO_BTN2 (0x00000002)
#define GPIO_BTN3 (0x00000004)
#define GPIO_PCBREV0 (0x00000008)
#define GPIO_PCBREV1 (0x00000010)
#define GPIO_PCBREV2 (0x00000020)
#define GPIO_PCBREV3 (0x00000040)
/* Outputs */
#define GPIO_LED1 (0x00000001)
#define GPIO_LED2 (0x00000002)
#endif /* __HW_GPIO_H */

View File

@ -0,0 +1,23 @@
/*
* 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 __HW_INTERRUPTS_H
#define __HW_INTERRUPTS_H
#define IRQ_UART (0x00000001) /* 0 */
#endif /* __HW_INTERRUPTS_H */

View File

@ -0,0 +1,55 @@
/*
* 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 __HW_SYSCTL_H
#define __HW_SYSCTL_H
#include <hw/common.h>
#define CSR_GPIO_IN MMPTR(0xe0001000)
#define CSR_GPIO_OUT MMPTR(0xe0001004)
#define CSR_GPIO_INTEN MMPTR(0xe0001008)
#define CSR_TIMER0_CONTROL MMPTR(0xe0001010)
#define CSR_TIMER0_COMPARE MMPTR(0xe0001014)
#define CSR_TIMER0_COUNTER MMPTR(0xe0001018)
#define CSR_TIMER1_CONTROL MMPTR(0xe0001020)
#define CSR_TIMER1_COMPARE MMPTR(0xe0001024)
#define CSR_TIMER1_COUNTER MMPTR(0xe0001028)
#define TIMER_ENABLE (0x01)
#define TIMER_AUTORESTART (0x02)
#define CSR_ICAP MMPTR(0xe0001040)
#define ICAP_READY (0x01)
#define ICAP_CE (0x10000)
#define ICAP_WRITE (0x20000)
#define CSR_DBG_SCRATCHPAD MMPTR(0xe0001050)
#define CSR_DBG_CTRL MMPTR(0xe0001054)
#define DBG_CTRL_GDB_ROM_LOCK (0x01)
#define DBG_CTRL_BUS_ERR_EN (0x02)
#define CSR_FREQUENCY MMPTR(0xe0001074)
#define CSR_CAPABILITIES MMPTR(0xe0001078)
#define CSR_SYSTEM_ID MMPTR(0xe000107c)
#endif /* __HW_SYSCTL_H */

View File

@ -0,0 +1,39 @@
/*
* 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 __HW_UART_H
#define __HW_UART_H
#include <hw/common.h>
#define CSR_UART_RXTX MMPTR(0xe0000000)
#define CSR_UART_DIVISOR MMPTR(0xe0000004)
#define CSR_UART_STAT MMPTR(0xe0000008)
#define CSR_UART_CTRL MMPTR(0xe000000c)
#define CSR_UART_DEBUG MMPTR(0xe0000010)
#define UART_STAT_THRE (0x1)
#define UART_STAT_RX_EVT (0x2)
#define UART_STAT_TX_EVT (0x4)
#define UART_CTRL_RX_INT (0x1)
#define UART_CTRL_TX_INT (0x2)
#define UART_CTRL_THRU (0x4)
#define UART_DEBUG_BREAK_EN (0x1)
#endif /* __HW_UART_H */

15
software/libbase/Makefile Normal file
View File

@ -0,0 +1,15 @@
MMDIR=../..
include $(MMDIR)/software/include.mak
OBJECTS=divsi3.o libc.o console.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
all: libbase.a
libbase.a: $(OBJECTS)
$(AR) clr libbase.a $(OBJECTS)
$(RANLIB) libbase.a
.PHONY: clean
clean:
rm -f *.o libbase.a .*~ *~ Makefile.bak

84
software/libbase/atof.c Normal file
View File

@ -0,0 +1,84 @@
/* atof.c: converts an ASCII string to float
Copyright (C) 2003 Jesus Calvino-Fraga, jesusc@ieee.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <stdlib.h>
#include <ctype.h>
float atof(const char * s)
{
float value, fraction;
char iexp;
char sign;
//Skip leading blanks
while (isspace(*s)) s++;
//Get the sign
if (*s == '-')
{
sign=1;
s++;
}
else
{
sign=0;
if (*s == '+') s++;
}
//Get the integer part
for (value=0.0f; isdigit(*s); s++)
{
value=10.0f*value+(*s-'0');
}
//Get the fraction
if (*s == '.')
{
s++;
for (fraction=0.1f; isdigit(*s); s++)
{
value+=(*s-'0')*fraction;
fraction*=0.1f;
}
}
//Finally, the exponent (not very efficient, but enough for now)
if (toupper(*s)=='E')
{
s++;
iexp=(char)atoi(s);
{
while(iexp!=0)
{
if(iexp<0)
{
value*=0.1f;
iexp++;
}
else
{
value*=10.0f;
iexp--;
}
}
}
}
if(sign) value*=-1.0f;
return (value);
}

87
software/libbase/board.c Normal file
View File

@ -0,0 +1,87 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 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/>.
*/
#include <hw/sysctl.h>
#include <hw/gpio.h>
#include <stdio.h>
#include <stdlib.h>
#include <board.h>
static const struct board_desc boards[1] = {
{
.id = 0x4D31, /* M1 */
.name = "Milkymist One",
.ethernet_phyadr = 1
},
};
const struct board_desc *get_board_desc_id(unsigned short int id)
{
unsigned int i;
for(i=0;i<sizeof(boards)/sizeof(boards[0]);i++)
if(boards[i].id == id)
return &boards[i];
return NULL;
}
const struct board_desc *get_board_desc(void)
{
return get_board_desc_id(CSR_SYSTEM_ID & 0xffff);
}
int get_pcb_revision(void)
{
int r;
unsigned int io;
io = CSR_GPIO_IN;
r = 0;
if(io & GPIO_PCBREV0)
r |= 0x1;
if(io & GPIO_PCBREV1)
r |= 0x2;
if(io & GPIO_PCBREV2)
r |= 0x4;
if(io & GPIO_PCBREV3)
r |= 0x8;
return r;
}
void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
{
unsigned int id;
id = CSR_SYSTEM_ID;
*major = (id & 0xf0000000) >> 28;
*minor = (id & 0x0f000000) >> 24;
*subminor = (id & 0x00f00000) >> 20;
*rc = (id & 0x000f0000) >> 16;
}
void get_soc_version_formatted(char *version)
{
unsigned int major, minor, subminor, rc;
get_soc_version(&major, &minor, &subminor, &rc);
version += sprintf(version, "%u.%u", major, minor);
if(subminor != 0)
version += sprintf(version, ".%u", subminor);
if(rc != 0)
sprintf(version, "RC%u", rc);
}

108
software/libbase/console.c Normal file
View File

@ -0,0 +1,108 @@
/*
* 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/>.
*/
#include <uart.h>
#include <console.h>
#include <stdio.h>
#include <stdarg.h>
#include <irq.h>
#include <hw/interrupts.h>
static console_write_hook write_hook;
static console_read_hook read_hook;
static console_read_nonblock_hook read_nonblock_hook;
void console_set_write_hook(console_write_hook h)
{
write_hook = h;
}
void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn)
{
read_hook = r;
read_nonblock_hook = rn;
}
static void writechar(char c)
{
uart_write(c);
if(write_hook != NULL)
write_hook(c);
}
char readchar(void)
{
while(1) {
if(uart_read_nonblock())
return uart_read();
if((read_nonblock_hook != NULL) && read_nonblock_hook())
return read_hook();
}
}
int readchar_nonblock(void)
{
return (uart_read_nonblock()
|| ((read_nonblock_hook != NULL) && read_nonblock_hook()));
}
int puts(const char *s)
{
unsigned int oldmask;
oldmask = irq_getmask();
irq_setmask(IRQ_UART); // HACK: prevent UART data loss
while(*s) {
writechar(*s);
s++;
}
writechar('\n');
irq_setmask(oldmask);
return 1;
}
void putsnonl(const char *s)
{
unsigned int oldmask;
oldmask = irq_getmask();
irq_setmask(IRQ_UART); // HACK: prevent UART data loss
while(*s) {
writechar(*s);
s++;
}
irq_setmask(oldmask);
}
int printf(const char *fmt, ...)
{
va_list args;
int len;
char outbuf[256];
va_start(args, fmt);
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
va_end(args);
outbuf[len] = 0;
putsnonl(outbuf);
return len;
}

53
software/libbase/divsi3.c Normal file
View File

@ -0,0 +1,53 @@
#define divnorm(num, den, sign) \
{ \
if(num < 0) \
{ \
num = -num; \
sign = 1; \
} \
else \
{ \
sign = 0; \
} \
\
if(den < 0) \
{ \
den = - den; \
sign = 1 - sign; \
} \
}
#define exitdiv(sign, res) if (sign) { res = - res;} return res;
long __divsi3 (long numerator, long denominator)
{
int sign;
long dividend;
divnorm(numerator, denominator, sign);
dividend = (unsigned int)numerator/(unsigned int)denominator;
exitdiv(sign, dividend);
}
long __modsi3 (long numerator, long denominator)
{
int sign;
long res;
if(numerator < 0) {
numerator = -numerator;
sign = 1;
} else
sign = 0;
if(denominator < 0)
denominator = -denominator;
res = (unsigned int)numerator % (unsigned int)denominator;
if(sign)
return -res;
else
return res;
}

577
software/libbase/libc.c Normal file
View File

@ -0,0 +1,577 @@
/*
* Milkymist SoC (Software)
* Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
* Copyright (C) Linus Torvalds and 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/>.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
/**
* strchr - Find the first occurrence of a character in a string
* @s: The string to be searched
* @c: The character to search for
*/
char *strchr(const char *s, int c)
{
for (; *s != (char)c; ++s)
if (*s == '\0')
return NULL;
return (char *)s;
}
/**
* strrchr - Find the last occurrence of a character in a string
* @s: The string to be searched
* @c: The character to search for
*/
char *strrchr(const char *s, int c)
{
const char *p = s + strlen(s);
do {
if (*p == (char)c)
return (char *)p;
} while (--p >= s);
return NULL;
}
/**
* strnchr - Find a character in a length limited string
* @s: The string to be searched
* @count: The number of characters to be searched
* @c: The character to search for
*/
char *strnchr(const char *s, size_t count, int c)
{
for (; count-- && *s != '\0'; ++s)
if (*s == (char)c)
return (char *)s;
return NULL;
}
/**
* strcpy - Copy a %NUL terminated string
* @dest: Where to copy the string to
* @src: Where to copy the string from
*/
char *strcpy(char *dest, const char *src)
{
char *tmp = dest;
while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
/**
* strncpy - Copy a length-limited, %NUL-terminated string
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @count: The maximum number of bytes to copy
*
* The result is not %NUL-terminated if the source exceeds
* @count bytes.
*
* In the case where the length of @src is less than that of
* count, the remainder of @dest will be padded with %NUL.
*
*/
char *strncpy(char *dest, const char *src, size_t count)
{
char *tmp = dest;
while (count) {
if ((*tmp = *src) != 0)
src++;
tmp++;
count--;
}
return dest;
}
/**
* strcmp - Compare two strings
* @cs: One string
* @ct: Another string
*/
int strcmp(const char *cs, const char *ct)
{
signed char __res;
while (1) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
}
return __res;
}
/**
* strncmp - Compare two strings using the first characters only
* @cs: One string
* @ct: Another string
* @count: Number of characters
*/
int strncmp(const char *cs, const char *ct, size_t count)
{
signed char __res;
size_t n;
n = 0;
__res =