OpenCores
URL https://opencores.org/ocsvn/mpx/mpx/trunk

Subversion Repositories mpx

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /mpx/trunk
    from Rev 4 to Rev 5
    Reverse comparison

Rev 4 → Rev 5

/sw/bootloader/xmodem.h
0,0 → 1,25
#ifndef __XMODEM_H__
#define __XMODEM_H__
 
//-----------------------------------------------------------------
// Defines
//-----------------------------------------------------------------
 
// Support 128 byte transfers
#define XMODEM_BUFFER_SIZE 128
 
// Support 1024 byte transfers
//#define XMODEM_BUFFER_SIZE 1024
 
// xmodem timeout/retry parameters
#define XMODEM_TIMEOUT_DELAY 1000
#define XMODEM_RETRY_LIMIT 16
 
//-----------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------
void xmodem_init(int (*sputc)(char c), int (*sgetc)(void));
int xmodem_receive( int (*write)(unsigned char* buffer, int size) );
 
#endif // __XMODEM_H__
 
/sw/bootloader/exception.c
0,0 → 1,65
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MPX 32-bit Soft-Core Processor
// V0.1
// Ultra-Embedded.com
// Copyright 2011 - 2012
//
// Email: admin@ultra-embedded.com
//
// License: GPL
// If you would like a version with a more permissive license for use in
// closed source commercial applications please contact me for details.
//-----------------------------------------------------------------------------
//
// This file is part of MPX 32-bit Soft-Core Processor.
//
// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or
// (at your option) any later version.
//
// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include "exception.h"
#include "assert.h"
 
volatile unsigned long * _currentTCB;
 
//-----------------------------------------------------------------
// cpu_handle_irq:
//-----------------------------------------------------------------
void cpu_handle_irq(unsigned cause)
{
switch (cause)
{
case 0x01:
panic("SYSCALL!");
break;
case 0x02:
panic("BREAK!");
break;
case 0x03:
panic("EXT_INT!");
break;
case 0x04:
panic("FAULT!");
break;
case 0x05:
case 0x06:
panic("MULT!");
break;
case 0x07:
case 0x08:
panic("DIV!");
break;
}
}
/sw/bootloader/boot_serial.c
0,0 → 1,129
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MPX 32-bit Soft-Core Processor
// V0.1
// Ultra-Embedded.com
// Copyright 2011 - 2012
//
// Email: admin@ultra-embedded.com
//
// License: GPL
// If you would like a version with a more permissive license for use in
// closed source commercial applications please contact me for details.
//-----------------------------------------------------------------------------
//
// This file is part of MPX 32-bit Soft-Core Processor.
//
// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or
// (at your option) any later version.
//
// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include "serial.h"
#include "boot_serial.h"
#include "xmodem.h"
 
//-----------------------------------------------------------------
// Defines:
//-----------------------------------------------------------------
#define FLASH_SECTOR_SIZE 128
 
//-----------------------------------------------------------------
// Locals:
//-----------------------------------------------------------------
static unsigned long xfer_offset = 0;
static unsigned long xfer_base;
static unsigned int xfer_sector_offset = 0;
static unsigned char flash_write_buffer[FLASH_SECTOR_SIZE];
 
//-----------------------------------------------------------------
// Prototypes:
//-----------------------------------------------------------------
static int xmodem_write(unsigned char* buffer, int size);
 
//-----------------------------------------------------------------
// boot_serial:
//-----------------------------------------------------------------
void boot_serial(unsigned long target)
{
int res;
 
// Load target memory address
xfer_base = target;
 
// Init X-Modem transfer
xmodem_init(serial_putchar, serial_getchar);
 
do
{
res = xmodem_receive( xmodem_write );
 
// Reset
xfer_offset = 0;
xfer_sector_offset = 0;
}
while (res < 0);
 
// Normal boot
{
int (*app_start)();
app_start = (unsigned long *)(xfer_base);
app_start();
 
while (1)
;
}
}
//-----------------------------------------------------------------
// xmodem_write:
//-----------------------------------------------------------------
static int xmodem_write(unsigned char* buffer, int size)
{
// Write to flash
int i;
int flush = 0;
 
// Flush final block
if (size == 0)
flush = 1;
 
// Write final (and already done!)
if (flush && xfer_sector_offset == 0)
return 0;
 
// We are relying on the Flash sector size to be a multiple
// of Xmodem transfer sizes (128 or 1024)...
 
// Copy to write buffer
for (i=0;i<size;i++)
flash_write_buffer[xfer_sector_offset + i] = buffer[i];
 
// Have we got enough data to write a sector?
if ((xfer_sector_offset + size) >= FLASH_SECTOR_SIZE || flush)
{
// Write to memory
unsigned char *ptr = (unsigned char *)(xfer_base + xfer_offset);
 
for (i=0;i<FLASH_SECTOR_SIZE;i++)
*ptr++ = flash_write_buffer[i];
 
// Reset to start of sector
xfer_sector_offset = 0;
}
else
xfer_sector_offset += size;
 
// Increment end point to include new data
xfer_offset += size;
return 0;
}
/sw/bootloader/exception.h
0,0 → 1,12
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
 
//-----------------------------------------------------------------
// Prototypes:
//-----------------------------------------------------------------
void exception_register_fault_handler(void (*func)(void));
void exception_register_break_handler(void (*func)(void));
void exception_register_extint_handler(void (*func)(void));
void exception_register_syscall_handler(void (*func)(void));
 
#endif // __EXCEPTION_H__
/sw/bootloader/assert.h
0,0 → 1,10
#ifndef __ASSERT_H__
#define __ASSERT_H__
 
extern void assert_handler(const char * type, const char *reason, const char *file, int line);
 
#define assert(exp) do { if (!(exp)) assert_handler("ASSERT", #exp, __FILE__, __LINE__ ); } while (0)
#define panic(reason) do { assert_handler("PANIC", #reason, __FILE__, __LINE__ ); } while (0)
 
#endif
 
/sw/bootloader/boot_serial.h
0,0 → 1,18
#ifndef __BOOT_SERIAL_H__
#define __BOOT_SERIAL_H__
 
//-----------------------------------------------------------------
// Defines
//-----------------------------------------------------------------
 
//-----------------------------------------------------------------
// Types
//-----------------------------------------------------------------
 
//-----------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------
void boot_serial(unsigned long target);
 
 
#endif //__BOOT_SERIAL_H__
/sw/bootloader/libstd.a Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
sw/bootloader/libstd.a Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: sw/bootloader/serial.c =================================================================== --- sw/bootloader/serial.c (nonexistent) +++ sw/bootloader/serial.c (revision 5) @@ -0,0 +1,159 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "mem_map.h" +#include "serial.h" + +//----------------------------------------------------------------- +// Registers +//----------------------------------------------------------------- + +// Dual port RAM serial port +#ifdef SERIAL_DPRAM + #define UART_TX_DATA (*(REG32 (EXT_BASE + 0))) + #define UART_RX_DATA (*(REG32 (EXT_BASE + 4))) +#else + #define UART_RX_AVAIL (1<<0) + #define UART_TX_AVAIL (1<<1) + #define UART_RX_FULL (1<<2) + #define UART_TX_BUSY (1<<3) + #define UART_RX_ERROR (1<<4) +#endif + +//------------------------------------------------------------- +// serial_init: +//------------------------------------------------------------- +void serial_init (void) +{ + +} +//------------------------------------------------------------- +// serial_putchar: Write character to Serial Port (used by printf) +//------------------------------------------------------------- +int serial_putchar(char ch) +{ + if (ch == '\n') + serial_putchar('\r'); + +#ifndef SERIAL_DPRAM + while (UART_USR & UART_TX_BUSY); + UART_UDR = ch; +#else + UART_TX_DATA = ch; + while (UART_TX_DATA != 0) + ; +#endif + + return 0; +} +//------------------------------------------------------------- +// serial_getchar: Read character from Serial Port +//------------------------------------------------------------- +int serial_getchar (void) +{ + // Read character in from UART0 Recieve Buffer and return + if (serial_haschar()) + { +#ifndef SERIAL_DPRAM + return UART_UDR; +#else + int ch = UART_RX_DATA; + UART_RX_DATA = 0; + return ch; +#endif + } + else + return -1; +} +//------------------------------------------------------------- +// serial_haschar: +//------------------------------------------------------------- +int serial_haschar() +{ +#ifndef SERIAL_DPRAM + return (UART_USR & UART_RX_AVAIL); +#else + unsigned int ch = UART_RX_DATA; + return ((ch != 0) && ((ch >> 8) == 0)); +#endif +} +//------------------------------------------------------------- +// serial_putstr: +//------------------------------------------------------------- +void serial_putstr(char *str) +{ + while (*str) + serial_putchar(*str++); +} +//------------------------------------------------------------- +// serial_putnum: +//------------------------------------------------------------- +void serial_putnum( int n ) +{ + char* cp; + int negative; + char outbuf[32]; + const char digits[] = "0123456789ABCDEF"; + unsigned long num; + + /* Check if number is negative */ + if (n < 0L) { + negative = 1; + num = -(n); + } + else{ + num = (n); + negative = 0; + } + + /* Build number (backwards) in outbuf */ + cp = outbuf; + do { + *cp++ = digits[(int)(num % 16)]; + } while ((num /= 16) > 0); + if (negative) + *cp++ = '-'; + *cp-- = 0; + + while (cp >= outbuf) + serial_putchar(*cp--); +} +//------------------------------------------------------------- +// serial_printstrnum: +//------------------------------------------------------------- +void serial_printstrnum(char *str1, unsigned int hexnum, char *str2) +{ + if (str1) + serial_putstr(str1); + serial_putnum(hexnum); + if (str2) + serial_putstr(str2); +} Index: sw/bootloader/timer.c =================================================================== --- sw/bootloader/timer.c (nonexistent) +++ sw/bootloader/timer.c (revision 5) @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "timer.h" + +//-------------------------------------------------------------------------- +// timer_init: +//-------------------------------------------------------------------------- +void timer_init(void) +{ + +} +//-------------------------------------------------------------------------- +// timer_sleep: +//-------------------------------------------------------------------------- +void timer_sleep(int timeMs) +{ + t_time t = timer_now(); + + while (timer_diff(timer_now(), t) < timeMs) + ; +} Index: sw/bootloader/mem_map.h =================================================================== --- sw/bootloader/mem_map.h (nonexistent) +++ sw/bootloader/mem_map.h (revision 5) @@ -0,0 +1,145 @@ +#ifndef __MEM_MAP_H__ +#define __MEM_MAP_H__ + +//----------------------------------------------------------------- +// Defines: +//----------------------------------------------------------------- +#define INT_BASE 0x00000000 +#define INT_APP_BASE 0x00002000 +#define EXT_BASE 0x10000000 +#define IO_BASE 0x20000000 +#define EXT_IO_BASE 0x30000000 +#define EXT_DP_BASE 0x40000000 + +#define REGION_INTERNAL 0 +#define REGION_EXTERNAL 1 +#define REGION_CORE_IO 2 +#define REGION_EXT_IO 3 +#define REGION_DPRAM 4 + +#define REGION_OFFSET 28 +#define REGION_MASK 0x7 + +#define IMEM __attribute__ ((section (".fastmem"))) + +//----------------------------------------------------------------- +// Macros: +//----------------------------------------------------------------- +#define REG8 (volatile unsigned char*) +#define REG16 (volatile unsigned short*) +#define REG32 (volatile unsigned int*) + +//----------------------------------------------------------------- +// I/O: +//----------------------------------------------------------------- + +// General +#define CORE_ID (*(REG32 (IO_BASE + 0x0))) + +// Basic Peripherals +#define UART_USR (*(REG32 (IO_BASE + 0x4))) +#define UART_UDR (*(REG32 (IO_BASE + 0x8))) +#define TIMER_VAL (*(REG32 (IO_BASE + 0x10))) +#define IRQ_MASK_SET (*(REG32 (IO_BASE + 0x14))) +#define IRQ_MASK_STATUS (*(REG32 (IO_BASE + 0x14))) +#define IRQ_MASK_CLR (*(REG32 (IO_BASE + 0x18))) +#define IRQ_STATUS (*(REG32 (IO_BASE + 0x1C))) + #define IRQ_SYSTICK (0) + #define IRQ_UART_RX_AVAIL (1) + #define IRQ_SW (2) + #define IRQ_GPIO1 (3) + #define IRQ_SPI_UEXT (5) + #define IRQ_PIT (6) + #define EXT_INT_OFFSET (8) + #define IRQ_SPI_SD (EXT_INT_OFFSET + 0) + #define IRQ_IR (EXT_INT_OFFSET + 1) + #define IRQ_AUDIO_FIFO (EXT_INT_OFFSET + 2) + #define IRQ_UEXT2_5 (EXT_INT_OFFSET + 3) + #define IRQ_DMA (EXT_INT_OFFSET + 4) + +#define WATCHDOG_CTRL (*(REG32 (IO_BASE + 0x20))) + #define WATCHDOG_EXPIRED (16) + +#define SYS_CLK_COUNT (*(REG32 (IO_BASE + 0x60))) + +// SPI Configuration PROM +#define SPI_PROM_CTRL (*(REG32 (IO_BASE + 0x70))) + #define SPI_PROM_CS (1 << 0) +#define SPI_PROM_STAT (*(REG32 (IO_BASE + 0x70))) + #define SPI_PROM_BUSY (1 << 0) +#define SPI_PROM_DATA (*(REG32 (IO_BASE + 0x74))) + +// Extended Peripherals + +// Simple SPI Interface +#define SPI_EXT_CTRL (*(REG32 (EXT_IO_BASE + 0x10))) + #define SPI_EXT_CS (1 << 0) +#define SPI_EXT_STAT (*(REG32 (EXT_IO_BASE + 0x10))) + #define SPI_EXT_BUSY (1 << 0) +#define SPI_EXT_DATA (*(REG32 (EXT_IO_BASE + 0x14))) + +// Secondary Core Control +#define CPU2_CTRL (*(REG32 (EXT_IO_BASE + 0x20))) + #define CPU2_CTRL_RESET (1 << 0) + #define CPU2_INTERRUPT (1 << 1) +#define CPU2_STAT (*(REG32 (EXT_IO_BASE + 0x20))) + #define CPU2_STAT_ENABLED (1 << 0) + #define CPU2_STAT_FAULT (1 << 1) + +// UEXTx +#define UEXT_GPIO_OUT(x) (*(REG32 (EXT_IO_BASE + 0x20 + (16 * x)))) +#define UEXT_GPIO_IN(x) (*(REG32 (EXT_IO_BASE + 0x24 + (16 * x)))) +#define UEXT_GPIO_DDR(x) (*(REG32 (EXT_IO_BASE + 0x28 + (16 * x)))) + +// UEXT 1 +#define GPIO_OUT (*(REG32 (EXT_IO_BASE + 0x20))) +#define GPIO_IN (*(REG32 (EXT_IO_BASE + 0x24))) +#define GPIO_DDR (*(REG32 (EXT_IO_BASE + 0x28))) + +// UEXT 2 / SD +#define UEXT2_GPIO_OUT (*(REG32 (EXT_IO_BASE + 0x30))) +#define UEXT2_GPIO_IN (*(REG32 (EXT_IO_BASE + 0x34))) +#define UEXT2_GPIO_DDR (*(REG32 (EXT_IO_BASE + 0x38))) + #define UEXT2_SD_CS (8) + +// SPI DMA +#define SPI_DMA_CTRL(x) (*(REG32 (EXT_IO_BASE + 0x40 + (16 * x)))) +#define SPI_DMA_STAT(x) (*(REG32 (EXT_IO_BASE + 0x40 + (16 * x)))) +#define SPI_DMA_ADDR(x) (*(REG32 (EXT_IO_BASE + 0x44 + (16 * x)))) +#define SPI_DMA_DATA(x) (*(REG32 (EXT_IO_BASE + 0x48 + (16 * x)))) + +// Multiplier +#define MULT_OPERAND_A (*(REG32 (EXT_IO_BASE + 0x60))) +#define MULT_OPERAND_B (*(REG32 (EXT_IO_BASE + 0x64))) +#define MULT_RESULT_HI (*(REG32 (EXT_IO_BASE + 0x60))) +#define MULT_RESULT_LO (*(REG32 (EXT_IO_BASE + 0x64))) + +// Audio FIFO +#define FIFO_WRITE (*(REG32 (EXT_IO_BASE + 0x70))) +#define FIFO_UNDERUNS (*(REG32 (EXT_IO_BASE + 0x70))) +#define FIFO_STATUS (*(REG32 (EXT_IO_BASE + 0x74))) + #define FIFO_STAT_EMPTY (1 << 0) + #define FIFO_STAT_FULL (1 << 1) + #define FIFO_STAT_LOW (1 << 2) + #define FIFO_STAT_CNT_SHIFT 8 +#define FIFO_IRQ_THRESH (*(REG32 (EXT_IO_BASE + 0x74))) + +// IR Decoder +#define IR_CTRL (*(REG32 (EXT_IO_BASE + 0x80))) +#define IR_STAT (*(REG32 (EXT_IO_BASE + 0x80))) + #define IR_STAT_IR_IN (1 << 0) + #define IR_STAT_BUSY (1 << 1) +#define IR_DATA (*(REG32 (EXT_IO_BASE + 0x84))) + +// DMA Controller +#define DMA_CTRL (*(REG32 (EXT_IO_BASE + 0xA0))) +#define DMA_STAT (*(REG32 (EXT_IO_BASE + 0xA0))) + #define DMA_STAT_RDY (1 << 0) + #define DMA_STAT_BUSY (1 << 1) +#define DMA_SRC_ADDR (*(REG32 (EXT_IO_BASE + 0xA4))) +#define DMA_DST_ADDR (*(REG32 (EXT_IO_BASE + 0xA8))) +#define DMA_COUNT (*(REG32 (EXT_IO_BASE + 0xAC))) + +#define RAM_TIMING (*(REG32 (EXT_IO_BASE + 0xE0))) + +#endif Index: sw/bootloader/boot.s =================================================================== --- sw/bootloader/boot.s (nonexistent) +++ sw/bootloader/boot.s (revision 5) @@ -0,0 +1,52 @@ + .text + .align 2 + .global entry + .extern cpu_handle_irq + +#------------------------------------------------------------- +# entry: +#------------------------------------------------------------- + .ent entry +entry: + .set noreorder + + la $gp, _gp # initialize global pointer + la $5, _edata # $5 = .sbss_start + la $4, _end # $2 = .bss_end + la $sp, _sp # initialize stack pointer + +$BSS_CLEAR: + sw $0, 0($5) # Write 0x00 to mem[$5] + slt $3, $5, $4 # $3 = $5 < $4 + bnez $3, $BSS_CLEAR # If $3 != 0, jump to BSS_CLEAR + addiu $5, $5, 4 # $5 += 4 + + jal main + nop +$L1: + j $L1 + + .end entry + +#------------------------------------------------------------- +# asm_handle_irq: +#------------------------------------------------------------- + .global asm_handle_irq + .ent asm_handle_irq + +asm_handle_irq: + .set noreorder + + nop + nop + + # Get cause into first arg register + mfc0 $a0, $13 # C0_CAUSE + + # Jump to irq handling function + jal cpu_handle_irq + nop + + .set reorder + .end asm_handle_irq + Index: sw/bootloader/serial.h =================================================================== --- sw/bootloader/serial.h (nonexistent) +++ sw/bootloader/serial.h (revision 5) @@ -0,0 +1,15 @@ +#ifndef __SERIAL_H__ +#define __SERIAL_H__ + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- +void serial_init (void); +int serial_putchar(char ch); +int serial_getchar(void); +int serial_haschar(); +void serial_putstr(char *str); +void serial_putnum( int n ); +void serial_printstrnum(char *str1, unsigned int hexnum, char *str2); + +#endif // __SERIAL_H__ Index: sw/bootloader/main.c =================================================================== --- sw/bootloader/main.c (nonexistent) +++ sw/bootloader/main.c (revision 5) @@ -0,0 +1,59 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "serial.h" +#include "boot_serial.h" +#include "mem_map.h" + +//----------------------------------------------------------------- +// Defines: +//----------------------------------------------------------------- +#define BOOT_TIMEOUT 5000 +#define BOOT_FLASH_TARGET INT_APP_BASE + +//----------------------------------------------------------------- +// main: +//----------------------------------------------------------------- +int main(void) +{ + // Disable interrupts + asm volatile ("mtc0 $0, $12\n\t"); + + serial_putstr("\nBootROM\n"); + boot_serial(INT_APP_BASE); +} +//----------------------------------------------------------------- +// assert_handler: +//----------------------------------------------------------------- +void assert_handler(const char * type, const char *reason, const char *file, int line) +{ + while (1); +} Index: sw/bootloader/timer.h =================================================================== --- sw/bootloader/timer.h (nonexistent) +++ sw/bootloader/timer.h (revision 5) @@ -0,0 +1,21 @@ +#ifndef __TIMER_H__ +#define __TIMER_H__ + +#include "mem_map.h" + +//----------------------------------------------------------------- +// Defines: +//----------------------------------------------------------------- +typedef unsigned long t_time; + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- + +// General timer +void timer_init(void); +static t_time timer_now(void) { return TIMER_VAL; } +static long timer_diff(t_time a, t_time b) { return (long)(a - b); } +void timer_sleep(int timeMs); + +#endif Index: sw/bootloader/linker_script =================================================================== --- sw/bootloader/linker_script (nonexistent) +++ sw/bootloader/linker_script (revision 5) @@ -0,0 +1,61 @@ +GROUP(-lgcc) + +MEMORY +{ + sram (rwx) : ORIGIN = 0x00000000, LENGTH = 8K +} + +SECTIONS +{ + /* first section is .text which is used for code */ + .text : + { + *(.text .text.*) /* remaining code */ + *(.rodata) /* read-only data (constants) */ + *(.rodata*) + *(.rdata*) + . = ALIGN(4); + } > sram + + /* .data section which is used for initialized data */ + .data : + { + *(.got.plt) *(.got) + *(.shdata) + *(.data .data.* .gnu.linkonce.d.*) + . = ALIGN(16); + _gp = . + 0x7FF0; + *(.lit8) + *(.lit4) + *(.sdata .sdata.* .gnu.linkonce.s.*) + . = ALIGN (8); + *(.ram) + . = ALIGN (8); + _edata = .; + } > sram + + .sbss : + { + . = ALIGN(4); + _sbss_start = . ; + + *(.sbss*) + *(.scommon*) + } > sram + + .bss : + { + . = ALIGN(4); + _bss_start = . ; + + *(.bss*) + *(COMMON) + /* Allocate room for stack */ + . = ALIGN(8) ; + . += 512 ; + _sp = . - 16; + } > sram + + . = ALIGN(4); + _end = . ; +} Index: sw/bootloader/xmodem.c =================================================================== --- sw/bootloader/xmodem.c (nonexistent) +++ sw/bootloader/xmodem.c (revision 5) @@ -0,0 +1,323 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include +#include "xmodem.h" +#include "timer.h" + +//----------------------------------------------------------------- +// Defines +//----------------------------------------------------------------- +#define XMODEM_HDR_SIZE 6 + +// Control character codes +#define SOH 0x01 +#define STX 0x02 +#define EOT 0x04 +#define ACK 0x06 +#define NAK 0x15 +#define CAN 0x18 +#define CTRLZ 0x1A + +#define XMODEM_CRC_REQ 'C' + +//----------------------------------------------------------------- +// Locals +//----------------------------------------------------------------- + +// Serial IO function pointers +static int (*_serial_putc)(char c) = 0; +static int (*_serial_getc)(void) = 0; + +// Xmodem buffer +static unsigned char xbuffer[XMODEM_BUFFER_SIZE+XMODEM_HDR_SIZE]; + +//----------------------------------------------------------------- +// Prototypes +//----------------------------------------------------------------- +static unsigned short calc_crc_16(unsigned char *data, int length); +static unsigned char calc_checksum(unsigned char *data, int length); +static int xmodem_verify_checksum(unsigned char *buffer, int size, int useCRC); +static int xmodem_getc(unsigned int timeout); +static void xmodem_flush(void); + +//----------------------------------------------------------------- +// xmodem_init: Initialise X-Modem module +//----------------------------------------------------------------- +void xmodem_init(int (*sputc)(char c), int (*sgetc)(void)) +{ + _serial_putc = sputc; + _serial_getc = sgetc; +} +//----------------------------------------------------------------- +// xmodem_receive: Receive a X-Modem transfer +//----------------------------------------------------------------- +int xmodem_receive( int (*write)(unsigned char* buffer, int size) ) +{ + unsigned char seq_num = 1; + unsigned short packet_length = 128; + unsigned char response; + char retry = XMODEM_RETRY_LIMIT; + unsigned char useCrc = 0; + int totalbytes = 0; + int i, c; + + // No I/O functions? No transfer! + if (!_serial_putc || !_serial_getc) + return -1; + + // Start by requesting CRC transfer + response = XMODEM_CRC_REQ; + + while(retry > 0) + { + // solicit a connection/packet + _serial_putc(response); + + // wait for start of packet + if( (c = xmodem_getc(XMODEM_TIMEOUT_DELAY)) >= 0) + { + switch(c) + { + // Start of transfer (128 bytes) + case SOH: + packet_length = 128; + break; + + // Start of transfer (1024 bytes) + #if(XMODEM_BUFFER_SIZE>=1024) + case STX: + packet_length = 1024; + break; + #endif + + // End of transfer + case EOT: + xmodem_flush(); + _serial_putc(ACK); + // Inform app layer of end of transfer + write(0, 0); + return totalbytes; + + // Cancel transfer + case CAN: + if((c = xmodem_getc(XMODEM_TIMEOUT_DELAY)) == CAN) + { + xmodem_flush(); + _serial_putc(ACK); + return -1; + } + default: + break; + } + } + // No response, retry + else + { + retry--; + continue; + } + + // Using CRC mode (as requested) + if(response == 'C') + useCrc = 1; + + // Add header character to buffer (SOH/STX) + xbuffer[0] = c; + + // Wait for rest of packet + for(i=0; i<(packet_length+useCrc+4-1); i++) + { + // Get a byte of data + if((c = xmodem_getc(XMODEM_TIMEOUT_DELAY)) >= 0) + xbuffer[1+i] = c; + // Timeout while expecting data + else + { + retry--; + xmodem_flush(); + response = NAK; + break; + } + } + + // If timeout, retry + if( i < (packet_length+useCrc+4-1) ) + continue; + // Packet received, check checksum & sequence number + else if( (xbuffer[1] == (unsigned char)(~xbuffer[2])) && xmodem_verify_checksum(&xbuffer[3], packet_length, useCrc)) + { + // Is this the sequence number waited on? + if(xbuffer[1] == seq_num) + { + // Pass data to user call-back + write(&xbuffer[3], packet_length); + + // Increment receive count + totalbytes += packet_length; + + // Next sequence number + seq_num++; + + // Reset retries + retry = XMODEM_RETRY_LIMIT; + + // ACK packet + response = ACK; + + continue; + } + // Last packet resent? + else if(xbuffer[1] == (unsigned char)(seq_num-1)) + { + // Just ACK it + response = ACK; + continue; + } + // Some other failure! + else + { + xmodem_flush(); + _serial_putc(CAN); + _serial_putc(CAN); + _serial_putc(CAN); + + return -1; + } + } + // Checksum / sequence number check byte are wrong + else + { + // Send NAK + retry--; + xmodem_flush(); + response = NAK; + continue; + } + } + + // Retries count exceeded + xmodem_flush(); + _serial_putc(CAN); + _serial_putc(CAN); + _serial_putc(CAN); + + return -1; +} +//----------------------------------------------------------------- +// calc_crc_16: Calculate 16 bit CRC used by XModem(CRC) +// Polynomial x^16 + x^12 + x^5 + 1 (0x1021) +//----------------------------------------------------------------- +static unsigned short calc_crc_16(unsigned char *data, int length) +{ + unsigned char c; + unsigned short crc = 0; + int i; + + while (length) + { + c = *data++; + crc = crc ^ ((unsigned short)c << 8); + for (i=0; i<8; i++) + { + if(crc & 0x8000) + crc = (crc << 1) ^ 0x1021; + else + crc <<= 1; + } + + length--; + } + + return crc; +} +//----------------------------------------------------------------- +// calc_checksum: Calculate standard (summation) checksum used by +// older XModem protocol versions +//----------------------------------------------------------------- +static unsigned char calc_checksum(unsigned char *data, int length) +{ + unsigned char sum = 0; + + while (length) + { + sum += *data++; + length--; + } + + return sum; +} +//----------------------------------------------------------------- +// xmodem_verify_checksum: Verify the checksum for the received packet +//----------------------------------------------------------------- +static int xmodem_verify_checksum(unsigned char *buffer, int size, int useCRC) +{ + int res = 0; + + // CRC-16 + if(useCRC) + { + unsigned short crc = (buffer[size]<<8) + buffer[size+1]; + + if(calc_crc_16((unsigned char*)buffer, size) == crc) + res = 1; + } + // Old sum checksum + else + { + // check checksum against packet + if(calc_checksum(buffer, size) == buffer[size]) + res = 1; + } + + return res; +} +//----------------------------------------------------------------- +// xmodem_getc: Get a character from serial port within timeout +//----------------------------------------------------------------- +static int xmodem_getc(unsigned int timeout) +{ + int c = -1; + t_time startTime = timer_now(); + + while ( (c = _serial_getc()) < 0 ) + if (timer_diff(timer_now(), startTime) >= timeout) + break; + + return c; +} +//----------------------------------------------------------------- +// xmodem_flush: Flush serial port +//----------------------------------------------------------------- +static void xmodem_flush(void) +{ + while(xmodem_getc(XMODEM_TIMEOUT_DELAY) >= 0); +} Index: sw/bootloader/Makefile =================================================================== --- sw/bootloader/Makefile (nonexistent) +++ sw/bootloader/Makefile (revision 5) @@ -0,0 +1,62 @@ +############################################################################### +## MIPS Makefile +############################################################################### + +# Tools +MIPS_PREFIX = mips-elf +GCC_MIPS = $(MIPS_PREFIX)-gcc $(CFLAGS) +AS_MIPS = $(MIPS_PREFIX)-as +LD_MIPS = $(MIPS_PREFIX)-ld +DUMP_MIPS = $(MIPS_PREFIX)-objdump +OBJCOPY = $(MIPS_PREFIX)-objcopy + +# Target +TARGET = bootloader + +# Options +LDSCRIPT = linker_script +CFLAGS = -G 0 -O2 -g -Wall +CFLAGS += -march=mips1 -mpatfree -mnohwdiv -mnohwmult +CFLAGS += -nostartfiles -nodefaultlibs -nostdlib -lgcc +CFLAGS += -L ./ -L ../common/ -lstd -T$(LDSCRIPT) +ASFLAGS = -Wa +LDFLAGS = + +OBJ += boot.o +OBJ += exception.o +OBJ += main.o +OBJ += boot_serial.o +OBJ += xmodem.o +OBJ += serial.o +OBJ += timer.o + +CFLAGS += -I. -I./../common + + +############################################################################### +# Rules +############################################################################### +all: $(TARGET).elf lst bin + +clean: + -rm *.o *.map *.lst *.hex *.txt *.elf + +%.o : %.s + $(GCC_MIPS) -c $(ASFLAGS) $< -o $@ + +%.o : %.c + $(GCC_MIPS) -c $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJ) $(LDSCRIPT) makefile + $(GCC_MIPS) $(LDFLAGS) $(LIBS) $(OBJ) -o $@ + +lst: $(TARGET).lst + +%.lst: $(TARGET).elf + $(DUMP_MIPS) -h -d -S $< > $@ + +bin: $(TARGET).bin + +%.bin: %.elf + $(OBJCOPY) -O binary $< $@ + Index: sw/bootloader =================================================================== --- sw/bootloader (nonexistent) +++ sw/bootloader (revision 5)
sw/bootloader Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: sw/helloworld/exception.c =================================================================== --- sw/helloworld/exception.c (nonexistent) +++ sw/helloworld/exception.c (revision 5) @@ -0,0 +1,121 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "exception.h" +#include "assert.h" +#include "printf.h" + +//----------------------------------------------------------------- +// Globals: +//----------------------------------------------------------------- +volatile unsigned long * _currentTCB; + +//----------------------------------------------------------------- +// Locals: +//----------------------------------------------------------------- +static void (*func_fault)(void) = 0; +static void (*func_break)(void) = 0; +static void (*func_extint)(void) = 0; +static void (*func_syscall)(void) = 0; +static volatile int in_interrupt = 0; + +//----------------------------------------------------------------- +// exception_register: +//----------------------------------------------------------------- +void exception_register_fault_handler(void (*func)(void)) { func_fault = func; } +void exception_register_break_handler(void (*func)(void)) { func_break = func; } +void exception_register_extint_handler(void (*func)(void)) { func_extint = func; } +void exception_register_syscall_handler(void (*func)(void)) { func_syscall = func; } + +//----------------------------------------------------------------- +// cpu_handle_irq: +//----------------------------------------------------------------- +void cpu_handle_irq(unsigned cause) +{ + int recursive_int = (in_interrupt != 0); + + in_interrupt = 1; + + switch (cause) + { + case EXCEPTION_SYSCALL: + if (func_syscall) + func_syscall(); + else + panic("SYSCALL!"); + break; + + case EXCEPTION_BREAK: + if (func_break) + func_break(); + else + panic("BREAK!"); + break; + + case EXCEPTION_EXTINT: + if (func_extint) + func_extint(); + else + panic("EXT_INT!"); + break; + + case EXCEPTION_FAULT: + if (func_fault) + func_fault(); + else + panic("FAULT"); + break; + + case EXCEPTION_MULT: + panic("MULT!"); + break; + + case EXCEPTION_UMULT: + panic("UMULT!"); + break; + + case EXCEPTION_DIV: + panic("DIV!"); + break; + + case EXCEPTION_UDIV: + panic("UDIV!"); + break; + + default: + panic("UNKNOWN"); + break; + } + + assert(recursive_int == 0); + + in_interrupt = 0; +} Index: sw/helloworld/exception.h =================================================================== --- sw/helloworld/exception.h (nonexistent) +++ sw/helloworld/exception.h (revision 5) @@ -0,0 +1,38 @@ +#ifndef __EXCEPTION_H__ +#define __EXCEPTION_H__ + +//----------------------------------------------------------------- +// Structures +//----------------------------------------------------------------- + +// Exception Fault SRC ID +enum +{ + EXCEPTION_SYSCALL = 0x01, + EXCEPTION_BREAK = 0x02, + EXCEPTION_EXTINT = 0x03, + EXCEPTION_FAULT = 0x04, + EXCEPTION_MULT = 0x05, + EXCEPTION_UMULT = 0x06, + EXCEPTION_DIV = 0x07, + EXCEPTION_UDIV = 0x08, +}; + +//----------------------------------------------------------------- +// Macros: +//----------------------------------------------------------------- +static inline void asm_set_isr_vector(unsigned val) +{ + asm volatile ("mtc0 %0, $15" : /* no outputs */ : "r" (val) ); +} + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- +void exception_register_fault_handler(void (*func)(void)); +void exception_register_break_handler(void (*func)(void)); +void exception_register_extint_handler(void (*func)(void)); +void exception_register_syscall_handler(void (*func)(void)); +void asm_save_context(void); + +#endif // __EXCEPTION_H__ Index: sw/helloworld/assert.h =================================================================== --- sw/helloworld/assert.h (nonexistent) +++ sw/helloworld/assert.h (revision 5) @@ -0,0 +1,10 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ + +#include "serial.h" + +#define assert(exp) do { if (!(exp)) { serial_putstr(#exp); while (1) ; } } while (0) +#define panic(reason) do { serial_putstr(#reason); while (1) ; } while (0) + +#endif + Index: sw/helloworld/printf.h =================================================================== --- sw/helloworld/printf.h (nonexistent) +++ sw/helloworld/printf.h (revision 5) @@ -0,0 +1,41 @@ +#ifndef __PRINTF_H__ +#define __PRINTF_H__ + +#include "stdarg.h" + +//----------------------------------------------------------------- +// Types: +//----------------------------------------------------------------- +typedef int (*FP_OUTCHAR)(char c); + +#ifdef LIBSTD_SIZE_T_2 + typedef long unsigned int libsize_t; +#else + typedef unsigned int libsize_t; +#endif + +//----------------------------------------------------------------- +// Structures +//----------------------------------------------------------------- +struct vbuf +{ + FP_OUTCHAR function; + char * buffer; + int offset; + int max_length; +}; + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- +int printf(const char* ctrl1, ... ); +void printf_register(FP_OUTCHAR f); +int vsprintf(char *s, const char *format, va_list arg); +int vsnprintf(char *s, libsize_t maxlen, const char *format, va_list arg); +int sprintf(char *s, const char *format, ...); +int snprintf(char *s, libsize_t maxlen, const char *format, ...); +int vbuf_printf(struct vbuf *buf, const char* ctrl1, va_list argp); + +#define PRINTF printf + +#endif // __PRINTF_H__ Index: sw/helloworld/sources.inc =================================================================== --- sw/helloworld/sources.inc (nonexistent) +++ sw/helloworld/sources.inc (revision 5) @@ -0,0 +1,5 @@ +OBJ += boot.o +OBJ += main.o +OBJ += serial.o +OBJ += timer.o +OBJ += exception.o Index: sw/helloworld/serial.c =================================================================== --- sw/helloworld/serial.c (nonexistent) +++ sw/helloworld/serial.c (revision 5) @@ -0,0 +1,130 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "mem_map.h" +#include "serial.h" + +//----------------------------------------------------------------- +// Define: +//----------------------------------------------------------------- +#define UART_RX_AVAIL (1<<0) +#define UART_TX_BUSY (1<<3) + +//------------------------------------------------------------- +// serial_init: +//------------------------------------------------------------- +void serial_init (void) +{ + +} +//------------------------------------------------------------- +// serial_putchar: Write character to Serial Port (used by printf) +//------------------------------------------------------------- +int serial_putchar(char ch) +{ + if (ch == '\n') + serial_putchar('\r'); + + UART_UDR = ch; + while (UART_USR & UART_TX_BUSY); + + return 0; +} +//------------------------------------------------------------- +// serial_getchar: Read character from Serial Port +//------------------------------------------------------------- +int serial_getchar (void) +{ + // Read character in from UART0 Recieve Buffer and return + if (serial_haschar()) + return UART_UDR; + else + return -1; +} +//------------------------------------------------------------- +// serial_haschar: +//------------------------------------------------------------- +int serial_haschar() +{ + return (UART_USR & UART_RX_AVAIL); +} +//------------------------------------------------------------- +// serial_putstr: +//------------------------------------------------------------- +void serial_putstr(char *str) +{ + while (*str) + serial_putchar(*str++); +} +//------------------------------------------------------------- +// serial_putnum: +//------------------------------------------------------------- +void serial_putnum( int n ) +{ + char* cp; + int negative; + char outbuf[32]; + const char digits[] = "0123456789ABCDEF"; + unsigned long num; + + /* Check if number is negative */ + if (n < 0L) { + negative = 1; + num = -(n); + } + else{ + num = (n); + negative = 0; + } + + /* Build number (backwards) in outbuf */ + cp = outbuf; + do { + *cp++ = digits[(int)(num % 16)]; + } while ((num /= 16) > 0); + if (negative) + *cp++ = '-'; + *cp-- = 0; + + while (cp >= outbuf) + serial_putchar(*cp--); +} +//------------------------------------------------------------- +// serial_printstrnum: +//------------------------------------------------------------- +void serial_printstrnum(char *str1, unsigned int hexnum, char *str2) +{ + if (str1) + serial_putstr(str1); + serial_putnum(hexnum); + if (str2) + serial_putstr(str2); +} Index: sw/helloworld/libstd.a =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: sw/helloworld/libstd.a =================================================================== --- sw/helloworld/libstd.a (nonexistent) +++ sw/helloworld/libstd.a (revision 5)
sw/helloworld/libstd.a Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: sw/helloworld/mem_map.h =================================================================== --- sw/helloworld/mem_map.h (nonexistent) +++ sw/helloworld/mem_map.h (revision 5) @@ -0,0 +1,42 @@ +#ifndef __MEM_MAP_H__ +#define __MEM_MAP_H__ + +//----------------------------------------------------------------- +// Defines: +//----------------------------------------------------------------- +#define INT_BASE 0x10000000 +#define IO_BASE 0x20000000 +#define EXT_IO_BASE 0x30000000 + +//----------------------------------------------------------------- +// Macros: +//----------------------------------------------------------------- +#define REG8 (volatile unsigned char*) +#define REG16 (volatile unsigned short*) +#define REG32 (volatile unsigned int*) + +//----------------------------------------------------------------- +// I/O: +//----------------------------------------------------------------- + +// General +#define CORE_ID (*(REG32 (IO_BASE + 0x0))) + +// Basic Peripherals +#define UART_USR (*(REG32 (IO_BASE + 0x4))) +#define UART_UDR (*(REG32 (IO_BASE + 0x8))) +#define TIMER_VAL (*(REG32 (IO_BASE + 0x10))) +#define IRQ_MASK_SET (*(REG32 (IO_BASE + 0x14))) +#define IRQ_MASK_STATUS (*(REG32 (IO_BASE + 0x14))) +#define IRQ_MASK_CLR (*(REG32 (IO_BASE + 0x18))) +#define IRQ_STATUS (*(REG32 (IO_BASE + 0x1C))) + #define IRQ_SYSTICK (0) + #define IRQ_UART_RX_AVAIL (1) + #define IRQ_SW (2) + #define IRQ_PIT (6) + #define EXT_INT_OFFSET (8) + + +#define SYS_CLK_COUNT (*(REG32 (IO_BASE + 0x60))) + +#endif Index: sw/helloworld/timer.c =================================================================== --- sw/helloworld/timer.c (nonexistent) +++ sw/helloworld/timer.c (revision 5) @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "timer.h" + +//-------------------------------------------------------------------------- +// timer_init: +//-------------------------------------------------------------------------- +void timer_init(void) +{ + +} +//-------------------------------------------------------------------------- +// timer_sleep: +//-------------------------------------------------------------------------- +void timer_sleep(int timeMs) +{ + t_time t = timer_now(); + + while (timer_diff(timer_now(), t) < timeMs) + ; +} Index: sw/helloworld/boot.s =================================================================== --- sw/helloworld/boot.s (nonexistent) +++ sw/helloworld/boot.s (revision 5) @@ -0,0 +1,194 @@ + .text + .align 2 + .global entry + .extern cpu_handle_irq + .extern _currentTCB + +#------------------------------------------------------------- +# entry: +#------------------------------------------------------------- + .ent entry +entry: + .set noreorder + + la $gp, _gp # initialize global pointer + la $5, _edata # $5 = .sbss_start + la $4, _end # $2 = .bss_end + la $sp, _sp # initialize stack pointer + +$BSS_CLEAR: + sw $0, 0($5) # Write 0x00 to mem[$5] + slt $3, $5, $4 # $3 = $5 < $4 + bnez $3, $BSS_CLEAR # If $3 != 0, jump to BSS_CLEAR + addiu $5, $5, 4 # $5 += 4 + + jal main + nop +$L1: + j $L1 + + .end entry + +#------------------------------------------------------------- +# asm_save_context: +#------------------------------------------------------------- + .global asm_save_context + .ent asm_save_context + +asm_save_context: + .set noreorder + .set noat + + nop + nop + + # Adjust SP + addi $sp, $sp, -144 + + # Save register set to stack + sw $ra, 136($sp) + sw $fp, 132($sp) + # Ignore $gp as it will not be changing + #sw $gp, 128($sp) + # Don't bother saving k0 & k1 + #sw $27, 124($sp) + #sw $26, 120($sp) + sw $25, 116($sp) + sw $24, 112($sp) + sw $23, 108($sp) + sw $22, 104($sp) + sw $21, 100($sp) + sw $20, 96($sp) + sw $19, 92($sp) + sw $18, 88($sp) + sw $17, 84($sp) + sw $16, 80($sp) + sw $15, 76($sp) + sw $14, 72($sp) + sw $13, 68($sp) + sw $12, 64($sp) + sw $11, 60($sp) + sw $10, 56($sp) + sw $9, 52($sp) + sw $8, 48($sp) + sw $7, 44($sp) + sw $6, 40($sp) + sw $5, 36($sp) + sw $4, 32($sp) + sw $3, 28($sp) + sw $2, 24($sp) + sw $1, 20($sp) + + # Save LO & HI + mfhi $t0 + sw $t0, 16($sp) + mflo $t0 + sw $t0, 12($sp) + + # Save EPC (PC of non-exception code) + mfc0 $t0, $14 # C0_EPC + sw $t0, 0($sp) + + # Save stack pointer to TCB + la $t0, _currentTCB + sw $sp, ($t0) + + .set reorder + .end asm_save_context + +#------------------------------------------------------------- +# asm_handle_irq: +#------------------------------------------------------------- + .global asm_handle_irq + .ent asm_handle_irq + +asm_handle_irq: + .set noreorder + + # Get cause into first arg register + mfc0 $a0, $13 # C0_CAUSE + + # Jump to irq handling function + jal cpu_handle_irq + nop + + .set reorder + .end asm_handle_irq + +#------------------------------------------------------------- +# asm_load_context: +#------------------------------------------------------------- + .global asm_load_context + .ent asm_load_context + +asm_load_context: + .set noreorder + .set noat + + # TODO: restore sp? + + # Restore EPC (PC of non-exception code) to $k0 + lw $k0, 0($sp) + # Load delay slot + nop + mtc0 $k0, $14 # C0_EPC + + # Restore LO & HI + lw $t0, 12($sp) + # Load delay slot + nop + mtlo $t0 + lw $t0, 16($sp) + # Load delay slot + nop + mthi $t0 + + # Restore register set + lw $1, 20($sp) + lw $2, 24($sp) + lw $3, 28($sp) + lw $4, 32($sp) + lw $5, 36($sp) + lw $6, 40($sp) + lw $7, 44($sp) + lw $8, 48($sp) + lw $9, 52($sp) + lw $10, 56($sp) + lw $11, 60($sp) + lw $12, 64($sp) + lw $13, 68($sp) + lw $14, 72($sp) + lw $15, 76($sp) + lw $16, 80($sp) + lw $17, 84($sp) + lw $18, 88($sp) + lw $19, 92($sp) + lw $20, 96($sp) + lw $21, 100($sp) + lw $22, 104($sp) + lw $23, 108($sp) + lw $24, 112($sp) + lw $25, 116($sp) + # Don't bother restoring k0 & k1 + #lw $26, 120($sp) + #lw $27, 124($sp) + # Ignore $gp as it will not be changing + #lw $gp, 128($sp) + lw $fp, 132($sp) + lw $ra, 136($sp) + + # Adjust SP past register set + addi $sp, $sp, +144 + + # Leave external interrupts disabled + la $k1, 0 + # Load delay slot + nop + + # Return from exception + jr $26 + mtc0 $k1, $12 # $k1 -> status register (ints enable / disable) + nop + + .set reorder + .end asm_load_context Index: sw/helloworld/serial.h =================================================================== --- sw/helloworld/serial.h (nonexistent) +++ sw/helloworld/serial.h (revision 5) @@ -0,0 +1,15 @@ +#ifndef __SERIAL_H__ +#define __SERIAL_H__ + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- +void serial_init (void); +int serial_putchar(char ch); +int serial_getchar(void); +int serial_haschar(); +void serial_putstr(char *str); +void serial_putnum( int n ); +void serial_printstrnum(char *str1, unsigned int hexnum, char *str2); + +#endif // __SERIAL_H__ Index: sw/helloworld/main.c =================================================================== --- sw/helloworld/main.c (nonexistent) +++ sw/helloworld/main.c (revision 5) @@ -0,0 +1,48 @@ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// MPX 32-bit Soft-Core Processor +// V0.1 +// Ultra-Embedded.com +// Copyright 2011 - 2012 +// +// Email: admin@ultra-embedded.com +// +// License: GPL +// If you would like a version with a more permissive license for use in +// closed source commercial applications please contact me for details. +//----------------------------------------------------------------------------- +// +// This file is part of MPX 32-bit Soft-Core Processor. +// +// MPX 32-bit Soft-Core Processor 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; either version 2 of the License, or +// (at your option) any later version. +// +// MPX 32-bit Soft-Core Processor 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 MPX 32-bit Soft-Core Processor; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#include "serial.h" +#include "timer.h" +#include "assert.h" +#include "string.h" +#include "printf.h" +#include "exception.h" + +int main(void) +{ + asm_set_isr_vector(asm_save_context); + + printf_register(serial_putchar); + printf("Hello world!\n"); + + while (1) + ; +} Index: sw/helloworld/timer.h =================================================================== --- sw/helloworld/timer.h (nonexistent) +++ sw/helloworld/timer.h (revision 5) @@ -0,0 +1,21 @@ +#ifndef __TIMER_H__ +#define __TIMER_H__ + +#include "mem_map.h" + +//----------------------------------------------------------------- +// Defines: +//----------------------------------------------------------------- +typedef unsigned long t_time; + +//----------------------------------------------------------------- +// Prototypes: +//----------------------------------------------------------------- + +// General timer +void timer_init(void); +static t_time timer_now(void) { return TIMER_VAL; } +static long timer_diff(t_time a, t_time b) { return (long)(a - b); } +void timer_sleep(int timeMs); + +#endif Index: sw/helloworld/linker_script =================================================================== --- sw/helloworld/linker_script (nonexistent) +++ sw/helloworld/linker_script (revision 5) @@ -0,0 +1,62 @@ +GROUP("libgcc.a" + "libstd.a") + +MEMORY +{ + sram (rwx) : ORIGIN = 0x00002000, LENGTH = 16K +} + +SECTIONS +{ + /* first section is .text which is used for code */ + .text : + { + *(.text .text.*) /* remaining code */ + *(.rodata) /* read-only data (constants) */ + *(.rodata*) + *(.rdata*) + . = ALIGN(4); + } > sram + + /* .data section which is used for initialized data */ + .data : + { + *(.got.plt) *(.got) + *(.shdata) + *(.data .data.* .gnu.linkonce.d.*) + . = ALIGN(16); + _gp = . + 0x7FF0; + *(.lit8) + *(.lit4) + *(.sdata .sdata.* .gnu.linkonce.s.*) + . = ALIGN (8); + *(.ram) + . = ALIGN (8); + _edata = .; + } > sram + + .sbss : + { + . = ALIGN(4); + _sbss_start = . ; + + *(.sbss*) + *(.scommon*) + } > sram + + .bss : + { + . = ALIGN(4); + _bss_start = . ; + + *(.bss*) + *(COMMON) + /* Allocate room for stack */ + . = ALIGN(8) ; + . += 256 ; + _sp = . - 16; + } > sram + + . = ALIGN(4); + _end = . ; +} Index: sw/helloworld/stdarg.h =================================================================== --- sw/helloworld/stdarg.h (nonexistent) +++ sw/helloworld/stdarg.h (revision 5) @@ -0,0 +1,22 @@ +#ifndef _MIPS_STDARG_H_ +#define _MIPS_STDARG_H_ + +#define _BSD_VA_LIST_ char * /* va_list */ + +typedef _BSD_VA_LIST_ va_list; + +#define va_start(ap, last) \ + ((ap) = (va_list)__builtin_next_arg(last)) + + +#define va_arg(ap, T) \ + (((T *)( \ + (ap) += (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \ + ? sizeof(int) : ((long)(ap) & 4) + sizeof(T)) \ + ))[-1]) + +#define va_end(ap) + +#define __va_copy(dest, src) ((dest) = (src)) + +#endif /* !_MIPS_STDARG_H_ */ \ No newline at end of file Index: sw/helloworld/makefile =================================================================== --- sw/helloworld/makefile (nonexistent) +++ sw/helloworld/makefile (revision 5) @@ -0,0 +1,56 @@ +############################################################################### +## MIPS Makefile +############################################################################### + +# Tools +MIPS_DIR = D:/mips-elf/bin +MIPS_PREFIX = mips-elf +GCC_MIPS = $(MIPS_DIR)/$(MIPS_PREFIX)-gcc $(CFLAGS) +AS_MIPS = $(MIPS_DIR)/$(MIPS_PREFIX)-as +LD_MIPS = $(MIPS_DIR)/$(MIPS_PREFIX)-ld +DUMP_MIPS = $(MIPS_DIR)/$(MIPS_PREFIX)-objdump +OBJCOPY = $(MIPS_DIR)/$(MIPS_PREFIX)-objcopy + +# Target +TARGET = test + +# Options +LDSCRIPT = linker_script +#CFLAGS = -G 0 -Os -g -Wall -DMIPS -march=mips1 -mpatfree -mnohwdiv -mnohwmult -nostartfiles -T$(LDSCRIPT) +CFLAGS = -G 0 -O2 -g -Wall -march=mips1 -mpatfree -mnohwdiv -mnohwmult -nostartfiles -nodefaultlibs -nostdlib -lgcc -L ./ -lstd -T$(LDSCRIPT) +ASFLAGS = -Wa +LDFLAGS = + +# Source Files +OBJ = +include sources.inc + +CFLAGS += -I. $(INCLUDE_DIRS) + +############################################################################### +# Rules +############################################################################### +all: $(TARGET).elf lst bin + +clean: + -del *.o *.obj *.map *.lst *.hex *.txt *.axf *.elf + +%.o : %.s + $(GCC_MIPS) -c $(ASFLAGS) $< -o $@ + +%.o : %.c + $(GCC_MIPS) -c $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJ) $(LDSCRIPT) makefile + $(GCC_MIPS) $(LDFLAGS) $(LIBS) $(OBJ) -o $@ + +lst: $(TARGET).lst + +%.lst: $(TARGET).elf + #$(DUMP_MIPS) -h -d -S $< > $@ + +bin: $(TARGET).bin + +%.bin: %.elf + $(OBJCOPY) -O binary $< $@ + \ No newline at end of file Index: sw/helloworld =================================================================== --- sw/helloworld (nonexistent) +++ sw/helloworld (revision 5)
sw/helloworld Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: sw =================================================================== --- sw (nonexistent) +++ sw (revision 5)
sw Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.