URL
https://opencores.org/ocsvn/openarty/openarty/trunk
Subversion Repositories openarty
Compare Revisions
- This comparison shows the changes necessary to convert path
/openarty/trunk/sw
- from Rev 53 to Rev 54
- ↔ Reverse comparison
Rev 53 → Rev 54
/zlib/Makefile
0,0 → 1,82
################################################################################ |
## |
## Filename: Makefile |
## |
## Project: OpenArty, an entirely open SoC based upon the Arty platform |
## |
## Purpose: |
## |
## Creator: Dan Gisselquist, Ph.D. |
## Gisselquist Technology, LLC |
## |
################################################################################ |
## |
## Copyright (C) 2017, Gisselquist Technology, LLC |
## |
## This program is free software (firmware): 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 3 of the License, or (at |
## your option) any later version. |
## |
## This program is distributed in the hope that it will be useful, but WITHOUT |
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
## target there if the PDF file isn't present.) If not, see |
## <http://www.gnu.org/licenses/> for a copy. |
## |
## License: GPL, v3, as defined and found on www.gnu.org, |
## http://www.gnu.org/licenses/gpl.html |
## |
## |
################################################################################ |
## |
## |
CC := zip-gcc |
AR := zip-ar |
OBJDIR := obj-zip |
CFLAGS := -O3 |
LIBSRCS := udiv.c umod.c artyboard.c crt0.c |
LIBOBJS := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(LIBSRCS))) |
all: libarty.a |
|
$(OBJDIR)/%.o: %.c |
$(CC) $(CFLAGS) -c $< -o $@ |
|
$(OBJDIR)/%.s: %.c |
$(CC) $(CFLAGS) -fdump-rtl-all -S $< -o $@ |
|
$(OBJDIR)/crt0.o: crt0.c |
$(CC) $(CFLAGS) -ffreestanding -c $< -o $@ |
|
libarty.a: $(LIBOBJS) |
$(AR) -cru libarty.a $(LIBOBJS) |
|
clean: |
rm -rf libarty.a libarty.a $(OBJDIR)/ |
|
define build-depends |
@echo "Building dependency file(s)" |
@$(CC) $(CFLAGS) -MM $(LIBSRCS) > $(OBJDIR)/xdepends.txt |
@sed -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdepends.txt > $(OBJDIR)/depends.txt |
@rm $(OBJDIR)/xdepends.txt |
endef |
|
tags: $(LIBSRCS) $(HEADERS) |
@echo "Generating tags" |
@ctags $(LIBSRCS) $(HEADERS) |
|
$(OBJDIR)/depends.txt: $(OBJDIR)/ |
$(build-depends) |
|
.PHONY: depends |
depends: |
$(build-depends) |
|
$(OBJDIR)/: |
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR)/; fi" |
|
-include $(OBJDIR)/depends.txt |
/zlib/artyboard.c
0,0 → 1,40
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: artyboard.c |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2017, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include "artyboard.h" |
#include "syscalls.c" |
|
/zlib/artyboard.h
0,0 → 1,329
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: artyboard.h |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: A description of the hardware and I/O parts and pieces specific |
// to the OpenArty distribution, for the purpose of writing |
// ZipCPU software that will run on the board. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#ifndef ARTYBOARD_H |
#define ARTYBOARD_H |
|
#include <stdint.h> |
|
// We have the full ZIP System installed |
#define _HAVE_ZIPSYS_PERFORMANCE_COUNTERS |
#define _HAVE_ZIPSYS_DMA |
#include "zipsys.h" |
|
#define GPIO_SET(X) (X |(X<<16)) |
#define GPIO_CLEAR(X) (X<<16) |
typedef struct { |
uint32_t i_version; |
uint32_t i_pic; |
uint32_t *i_buserr; |
uint32_t i_pwrcount; |
uint32_t i_btnsw, i_leds; |
uint32_t i_rtcdate; |
uint32_t i_gpio; |
uint32_t i_clrled[4]; |
union { |
unsigned long now; |
struct { uint32_t sec; uint32_t sub; }; |
} i_tim; |
|
unsigned i_gps_step; |
uint32_t i_unused[32-15]; |
} BASICIO; |
|
#define SD_SETAUX 0x0ff |
#define SD_READAUX 0x0bf |
#define SD_CMD 0x040 |
#define SD_FIFO_OP 0x0800 // Read only |
#define SD_WRITEOP 0x0c00 // Write to the FIFO |
#define SD_ALTFIFO 0x1000 |
#define SD_BUSY 0x4000 |
#define SD_ERROR 0x8000 |
#define SD_CLEARERR 0x8000 |
#define SD_READ_SECTOR ((SD_CMD|SD_CLEARERR|SD_FIFO_OP)+17) |
#define SD_WRITE_SECTOR ((SD_CMD|SD_CLEARERR|SD_WRITEOP)+24) |
|
typedef struct { |
unsigned sd_ctrl, sd_data, sd_fifo[2]; |
} SDCARD; |
|
|
typedef struct RTCLIGHT_S { |
unsigned r_clock, r_stopwatch, r_timer, r_alarm; |
} RTCLIGHT; |
|
typedef struct { |
unsigned g_alpha, g_beta, g_gamma, g_step; |
} GPSTRACKER; |
|
#define ENET_TXGO 0x004000 |
#define ENET_TXBUSY 0x004000 |
#define ENET_NOHWCRC 0x008000 |
#define ENET_NOHWMAC 0x010000 |
#define ENET_RESET 0x020000 |
#define ENET_NOHWIPCHK 0x040000 |
#define ENET_TXCMD(LEN) ((LEN)|ENET_TXGO) |
#define ENET_TXCLR 0x038000 |
#define ENET_TXCANCEL 0x000000 |
#define ENET_RXAVAIL 0x004000 |
#define ENET_RXBUSY 0x008000 |
#define ENET_RXMISS 0x010000 |
#define ENET_RXERR 0x020000 |
#define ENET_RXCRC 0x040000 // Set on a CRC error |
#define ENET_RXLEN rxcmd & 0x0ffff |
#define ENET_RXCLR 0x004000 |
#define ENET_RXBROADCAST 0x080000 |
#define ENET_RXCLRERR 0x078000 |
#define ENET_TXBUFLN(NET) (1<<(NET.txcmd>>24)) |
#define ENET_RXBUFLN(NET) (1<<(NET.rxcmd>>24)) |
typedef struct { |
unsigned n_rxcmd, n_txcmd; |
unsigned long n_mac; |
unsigned n_rxmiss, n_rxerr, n_rxcrc, n_txcol; |
} ENETPACKET; |
|
|
#define OLED_PMODEN 0x0010001 |
#define OLED_PMODEN_OFF 0x0010000 |
#define OLED_IOPWR OLED_PMODEN |
#define OLED_VCCEN 0x0020002 |
#define OLED_VCC_DISABLE 0x0020000 |
#define OLED_RESET 0x0040000 |
#define OLED_RESET_CLR 0x0040004 |
#define OLED_FULLPOWER (OLED_PMODEN|OLED_VCCEN|OLED_RESET_CLR) |
#define OLED_POWER_DOWN (OLED_PMODEN_OFF|OLED_VCCEN|OLED_RESET_CLR) |
#define OLED_BUSY(dev) (dev.o_ctrl & 1) |
#define OLED_DISPLAYON 0x0af // To be sent over the control channel |
typedef struct { |
unsigned o_ctrl, o_a, o_b, o_data; |
} OLEDRGB; |
|
typedef struct { |
unsigned tb_maxcount, tb_jump; |
unsigned long tb_err, tb_count, tb_step; |
} GPSTB; |
|
#define MDIO_BMCR 0x00 |
#define MDIO_BMSR 0x01 |
#define MDIO_PHYIDR1 0x02 |
#define MDIO_PHYIDR2 0x03 |
#define MDIO_ANAR 0x04 |
#define MDIO_ANLPAR 0x05 |
#define MDIO_ANLPARNP 0x05 // Duplicate register address |
#define MDIO_ANER 0x06 |
#define MDIO_ANNPTR 0x07 |
#define MDIO_PHYSTS 0x10 |
#define MDIO_FCSCR 0x14 |
#define MDIO_RECR 0x15 |
#define MDIO_PCSR 0x16 |
#define MDIO_RBR 0x17 |
#define MDIO_LEDCR 0x18 |
#define MDIO_PHYCR 0x19 |
#define MDIO_BTSCR 0x1a |
#define MDIO_CDCTRL 0x1b |
#define MDIO_EDCR 0x1d |
|
typedef struct { |
unsigned e_v[32]; |
} ENETMDIO; |
|
typedef struct { |
unsigned f_ereg, f_status, f_nvconfig, f_vconfig, |
f_evconfig, f_flags, f_lock, f_; |
unsigned f_id[5], f_unused[2]; |
unsigned f_otpc, f_otp[16]; |
} EFLASHCTRL; |
|
#define EQSPI_SZPAGE 64 |
#define EQSPI_NPAGES 256 |
#define EQSPI_NSECTORS 256 |
#define EQSPI_SECTORSZ (EQSPI_SZPAGE * EQSPI_NPAGES) |
#define EQSPI_SECTOROF(A) ((A)& (-EQSPI_SECTORSZ)) |
#define EQSPI_SUBSECTOROF(A) ((A)& (-1<<10)) |
#define EQSPI_PAGEOF(A) ((A)& (-SZPAGE)) |
#define EQSPI_ERASEFLAG 0xc00001be |
#define EQSPI_ERASECMD(A) (EQSPI_ERASEFLAG | EQSPI_SECTOROF(A)) |
#define EQSPI_ENABLEWP 0x00000000 |
#define EQSPI_DISABLEWP 0x40000000 |
|
#define UART_PARITY_NONE 0 |
#define UART_HWFLOW_OFF 0x40000000 |
#define UART_PARITY_ODD 0x04000000 |
#define UART_PARITY_EVEN 0x05000000 |
#define UART_PARITY_SPACE 0x06000000 |
#define UART_PARITY_MARK 0x07000000 |
#define UART_STOP_ONEBIT 0 |
#define UART_STOP_TWOBITS 0x08000000 |
#define UART_DATA_8BITS 0 |
#define UART_DATA_7BITS 0x10000000 |
#define UART_DATA_6BITS 0x20000000 |
#define UART_DATA_5BITS 0x30000000 |
#define UART_RX_BREAK 0x0800 |
#define UART_RX_FRAMEERR 0x0400 |
#define UART_RX_PARITYERR 0x0200 |
#define UART_RX_NOTREADY 0x0100 |
#define UART_RX_ERR (-256) |
#define UART_TX_BUSY 0x0100 |
#define UART_TX_BREAK 0x0200 |
|
typedef struct WBUART_S { |
unsigned u_setup; |
unsigned u_fifo; |
unsigned u_rx, u_tx; |
} WBUART; |
|
|
#define WBSCOPE_NO_RESET 0x80000000 |
#define WBSCOPE_TRIGGER (WBSCOPE_NO_RESET|0x08000000) |
#define WBSCOPE_MANUAL WBSCOPE_TRIGGER |
#define WBSCOPE_DISABLE 0x04000000 // Disable the scope trigger |
typedef struct WBSCOPE_S { |
unsigned s_ctrl, s_data; |
} WBSCOPE; |
|
|
|
typedef struct ARTYBOARD_S { |
BASICIO io_b; |
WBSCOPE io_scope[4]; |
RTCLIGHT io_rtc; |
OLEDRGB io_oled; |
WBUART io_uart; |
WBUART io_gpsu; |
SDCARD io_sd; |
unsigned io_ignore_0[4]; |
GPSTRACKER io_gps; |
unsigned io_ignore_1[4]; |
GPSTB io_gpstb; |
ENETPACKET io_enet; |
unsigned io_ignore_2[8]; |
ENETMDIO io_netmdio; |
EFLASHCTRL io_eflash; // 32 positions |
unsigned io_icape2[32]; |
unsigned io_ignore_3[0x800-(0x700>>2)]; |
unsigned io_enet_rx[1024]; |
unsigned io_enet_tx[1024]; |
} ARTYBOARD; |
|
#define PERIPHERAL_ADDR 0x400 |
|
static volatile ARTYBOARD *const _sys = (ARTYBOARD *)PERIPHERAL_ADDR; |
#define _ZIP_HAS_WBUART |
static volatile WBUART *const _uart = &((ARTYBOARD *)PERIPHERAL_ADDR)->io_uart; |
#define _ZIP_HAS_WBUARTX |
#define _uarttx _uart->u_tx |
#define _ZIP_HAS_WBUARTRX |
#define _uartrx _uart->u_rx |
#define _ZIP_HAS_UARTSETUP |
#define _uartsetup _uart->u_setup |
|
#define _ZIP_HAS_RTC |
static volatile RTCLIGHT *const _rtcdev = &((ARTYBOARD *)PERIPHERAL_ADDR)->io_rtc; |
#define _ZIP_HAS_RTDATE |
static volatile uint32_t *const _rtdate = &((ARTYBOARD *)PERIPHERAL_ADDR)->io_b.i_rtcdate; |
#define _ZIP_HAS_SDCARD |
static volatile SDCARD *const _sdcard = &((ARTYBOARD *)PERIPHERAL_ADDR)->io_sd; |
|
#define SYSTIMER zip->z_tma |
#define SYSPIC zip->z_pic |
#define ALTPIC zip->z_zpic |
#define COUNTER zip->z_m.ac_ck |
|
#define BKRAM (void *)0x00020000 |
#define FLASH (void *)0x01000000 |
#define SDRAM (void *)0x10000000 |
#define CLOCKFREQHZ 81250000 |
#define CLOCKFREQ_HZ CLOCKFREQHZ |
// |
#define MEMLEN 0x00020000 |
#define FLASHLEN 0x01000000 |
#define SDRAMLEN 0x10000000 |
|
// Finally, let's assign some of our interrupts: |
// |
// We're allowed nine interrupts to the master interrupt controller in the |
// ZipSys |
#define SYSINT_PPS SYSINT(6) |
#define SYSINT_ENETRX SYSINT(7) |
#define SYSINT_ENETTX SYSINT(8) |
#define SYSINT_UARTRXF SYSINT(9) |
#define SYSINT_UARTTXF SYSINT(10) |
#define SYSINT_GPSRXF SYSINT(11) |
#define SYSINT_GPSTXF SYSINT(12) |
#define SYSINT_BUS SYSINT(13) |
#define SYSINT_OLED SYSINT(14) |
// |
#define ALTINT_PPD ALTINT(8) |
#define ALTINT_UARTRX ALTINT(9) |
#define ALTINT_UARTTX ALTINT(10) |
#define ALTINT_GPSRX ALTINT(11) |
#define ALTINT_GPSTX ALTINT(12) |
// |
|
|
// BUS Interrupts |
#define BUS_BUTTON SYSINT(0) |
#define BUS_SWITCH SYSINT(1) |
#define BUS_PPS SYSINT(2) |
#define BUS_RTC SYSINT(3) |
#define BUS_NETRX SYSINT(4) |
#define BUS_NETTX SYSINT(5) |
#define BUS_UARTRX SYSINT(6) |
#define BUS_UARTTX SYSINT(7) |
#define BUS_GPIO SYSINT(8) |
#define BUS_FLASH SYSINT(9) |
#define BUS_SCOPE SYSINT(10) |
#define BUS_GPSRX SYSINT(11) |
#define BUS_SDCARD SYSINT(12) |
#define BUS_OLED SYSINT(13) |
// #define BUS_ZIP SYSINT(14) |
|
|
// DMA Interrupt parameters |
#define DMA_ONPPS DMA_ONINT(6) |
#define DMA_ONNETRX DMA_ONINT(7) |
#define DMA_ONNETTX DMA_ONINT(8) |
#define DMA_ONUARTRXF DMA_ONINT(9) |
#define DMA_ONUARTTXF DMA_ONINT(10) |
#define DMA_ONGPSRXF DMA_ONINT(11) |
#define DMA_ONGPSTXF DMA_ONINT(12) |
#define DMA_ONBUS DMA_ONINT(13) |
#define DMA_ONOLED DMA_ONINT(14) |
|
#endif // define ARTYBOARD_H |
/zlib/bootloader.h
0,0 → 1,46
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: bootloader.h |
// |
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core |
// |
// Purpose: |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#ifndef BOOTLOADER_H |
#define BOOTLOADER_H |
|
extern int _top_of_heap[1], _top_of_stack[1]; |
|
extern int _sdram[1], _flash[1], _blkram[1]; |
|
extern int _boot_address[1], |
_kernel_image_start[1], _kernel_image_end[1], |
_sdram_image_start[1], _sdram_image_end[1], |
_bss_image_end[1]; |
|
#endif |
/zlib/crt0.c
0,0 → 1,292
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: crt0.c |
// |
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core |
// |
// Purpose: To start a program from flash, loading its various components |
// into on-chip block RAM, or off-chip DDR3 SDRAM, as indicated |
// by the symbols/pointers within the program itself. As you will notice |
// by the names of the symbols, it is assumed that a kernel will be placed |
// into block RAM. |
// |
// This particular implementation depends upon the following symbols |
// being defined: |
// |
// int main(int argc, char **argv) |
// The location where your program will start from, once fully |
// loaded. argc will always be set to zero, and ARGV to a pointer |
// to zero. |
// |
// _top_of_stack: |
// A pointer to a location in memory which we can use for a stack. |
// The bootloader doesn't use much of this memory, although it does |
// use it. It then resets the stack to this location and calls |
// your program. |
// |
// _top_of_heap: |
// While not used by this program, this is assumed to be defined |
// by the linker as the lowest memory address in a space that can |
// be used by a malloc/free restore capability. |
// |
// _flash: |
// The address of the beginning of physical FLASH device. This is |
// not the first usable address on that device, as that is often |
// reserved for the first two FPGA configurations. |
// |
// _blkram: |
// The first address of the block RAM memory within the FPGA. |
// |
// _sdram: |
// The address of the beginning of physical SDRAM. |
// |
// _kernel_image_start: |
// The address of that location within FLASH where the sections |
// needing to be moved begin at. |
// |
// _kernel_image_end: |
// The last address within block RAM that needs to be filled in. |
// |
// _sdram_image_start: |
// This address is more confusing. This is equal to one past the |
// last used block RAM address, or the last used flash address if |
// no block RAM is used. It is used for determining whether or not |
// block RAM was used at all. |
// |
// _sdram_image_end: |
// This is one past the last address in SDRAM that needs to be |
// set with valid data. |
// |
// This pointer is made even more confusing by the fact that, |
// if there is nothing allocated in SDRAM, this pointer will |
// still point to block RAM. To make matters worse, the MAP |
// file won't match the pointer in memory. (I spent three days |
// trying to chase this down, and came up empty. Basically, |
// the BFD structures may set this to point to block RAM, whereas |
// the MAP--which uses different data and different methods of |
// computation--may leave this pointing to SDRAM. Go figure.) |
// |
// _bss_image_end: |
// This is the last address of memory that must be cleared upon |
// startup, for which the program is assuming that it is zero. |
// While it may not be necessary to clear the BSS memory, since |
// BSS memory is always zero on power up, this bootloader does so |
// anyway--since we might be starting from a reset instead of power |
// up. |
// |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2017, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include "zipcpu.h" |
#include "artyboard.h" // Our current board support file |
#include "bootloader.h" |
|
// A bootloader is about nothing more than copying memory from a couple |
// particular locations (Flash/ROM) to other locations in memory (BLKRAM |
// and SDRAM). Our DMA is a hardware accelerator that does nothing but |
// copy memory from one location to another. Why not use the DMA for this |
// purpose then? |
// |
// Here, we have a USE_DMA #define. When this is defined, the memory copy |
// will be done using the DMA hardware accelerator. This is a good thing, |
// and this should be defined. There are two problems with defining this |
// however: 1) It obscures for any readers of this code what is actually |
// happening, and 2) it makes the code dependent upon yet another piece of the |
// hardware design working. For these reasons, we allow you to turn it off. |
#ifdef _HAS_ZIPSYS_DMA |
#define USE_DMA |
#endif |
|
// |
// _start: |
// |
// Every computer needs to start processing from somewhere on reboot, and every |
// program needs some entry point. For the ZipCPU, that starting place is the |
// routine with the _start symbol. It is important that this start symbol be |
// placed at the boot address for the CPU. This is the very first address of |
// program memory, and (currently) on the Arty board it is placed in Flash at |
// _start = 0x4e0000. To make certain this routine goes into the very first |
// address in flash, we place it into it's own special section, the .start |
// section, and then tell the linker that the .start section is the first |
// section where it needs to start placing code. |
// |
// If you read through this short assembly routine below, you'll find that it |
// does only a small number of tasks. It sets the stack pointer to point to |
// the top of the stack (a symbol defined in the linker file), calls the |
// bootloader, resets the stack pointer, clears any data cache, and then calls |
// the kernel entry function. It also sets up a return address for the kernel |
// entry function so that, should the kernel ever exit, it wouldn't exit on |
// any error but rather it would exit by halting the CPU. |
// |
asm("\t.section\t.start,\"ax\",@progbits\n" |
"\t.global\t_start\n" |
"_start:" "\t; Here's the global ZipCPU entry point upon reset/reboot\n" |
"\tLDI\t_top_of_stack,SP" "\t; Set up our supervisor stack ptr\n" |
"\tMOV\t_kernel_is_dead(PC),uPC" "\t; Set user PC pointer to somewhere valid\n" |
#ifndef SKIP_BOOTLOADER |
"\tMOV\t_after_bootloader(PC),R0" " ; JSR to the bootloader routine\n" |
"\tBRA\t_bootloader\n" |
"_after_bootloader:\n" |
"\tLDI\t_top_of_stack,SP" "\t; Set up our supervisor stack ptr\n" |
"\tOR\t0x4000,CC" "\t; Clear the data cache\n" |
#endif |
#ifdef __USE_INIT_FINIT |
"\tJSR\tinit" "\t; Initialize any constructor code\n" |
// |
"\tLDI\tfini,R1" "\t; \n" |
"\tJSR\t_atexit" "\t; Initialize any constructor code\n" |
#endif |
// |
"\tCLR\tR1" "\t; argc = 0\n" |
"\tMOV\t_argv(PC),R2" "\t; argv = &0\n" |
"\tLDI\t__env,R3" "\t; env = NULL\n" |
"\tJSR\tmain" "\t; Call the user main() function\n" |
// |
"_graceful_kernel_exit:" "\t; Halt on any return from main--gracefully\n" |
"\tJSR\texit\n" "\t; Call the _exit as part of exiting\n" |
"\t.global\t_exit\n" |
"_exit:\n" |
#ifdef _HAS_WBUART |
"\tLW 0x45c,R2\n" |
"\tTEST 0xffc,R2\n" |
"\tBNZ _exit\n" |
"\tLSR 16,R2\n" |
"\tTEST 0xffc,R2\n" |
"\tBNZ _exit\n" |
#endif |
"\tNEXIT\tR1\n" "\t; If in simulation, call an exit function\n" |
"_kernel_is_dead:" "\t; Halt the CPU\n" |
"\tHALT\n" "\t; We should *never* continue following a\n" |
"\tBRA\t_kernel_is_dead" "\t; halt, do something useful if so ??\n" |
"_argv:\n" |
"\t.WORD\t0,0\n" |
"\t.section\t.text"); |
|
// |
// We need to insist that the bootloader be kept in Flash, else it would depend |
// upon running a routine from memory that ... wasn't in memory yet. For this |
// purpose, we place the bootloader in a special .boot section. We'll also tell |
// the linker, via the linker script, that this .boot section needs to be placed |
// into flash. |
// |
extern void _bootloader(void) __attribute__ ((section (".boot"))); |
|
// |
// bootloader() |
// |
// Here's the actual boot loader itself. It copies three areas from flash: |
// 1. An area from flash to block RAM |
// 2. A second area from flash to SDRAM |
// 3. The third area isn't copied from flash, but rather it is just set to |
// zero. This is sometimes called the BSS segment. |
// |
#ifndef SKIP_BOOTLOADER |
void _bootloader(void) { |
int *sdend = _sdram_image_end, *bsend = _bss_image_end; |
if (sdend < _sdram) |
sdend = _sdram; // R7 |
if (bsend < sdend) |
bsend = sdend; // R6 |
|
#ifdef USE_DMA |
zip->z_dma.d_ctrl= DMACLEAR; |
zip->z_dma.d_rd = _kernel_image_start; |
if (_kernel_image_end != _blkram) { |
zip->z_dma.d_len = _kernel_image_end - _blkram; |
zip->z_dma.d_wr = _blkram; |
zip->z_dma.d_ctrl= DMACCOPY; |
|
zip->z_pic = SYSINT_DMAC; |
while((zip->z_pic & SYSINT_DMAC)==0) |
; |
} |
|
// zip->z_dma.d_rd // Keeps the same value |
zip->z_dma.d_wr = _sdram; |
if (sdend != _sdram) { |
zip->z_dma.d_len = sdend - _sdram; |
zip->z_dma.d_ctrl= DMACCOPY; |
|
zip->z_pic = SYSINT_DMAC; |
while((zip->z_pic & SYSINT_DMAC)==0) |
; |
} |
|
if (bsend != sdend) { |
volatile int zero = 0; |
|
zip->z_dma.d_len = bsend - sdend; |
zip->z_dma.d_rd = (unsigned *)&zero; |
// zip->z_dma.wr // Keeps the same value |
zip->z_dma.d_ctrl = DMACCOPY|DMA_CONSTSRC; |
|
zip->z_pic = SYSINT_DMAC; |
while((zip->z_pic & SYSINT_DMAC)==0) |
; |
} |
#else |
int *rdp = _kernel_image_start, *wrp = _blkram; |
|
if ((((int)wrp) & -4)==0) |
wrp = _sdram; |
|
// |
// Load any part of the image into block RAM, but *only* if there's a |
// block RAM section in the image. Based upon our LD script, the |
// block RAM should be filled from _blkram to _kernel_image_end. |
// It starts at _kernel_image_start --- our last valid address within |
// the flash address region. |
// |
if (_kernel_image_end != _kernel_image_start) { |
while(wrp < _kernel_image_end) |
*wrp++ = *rdp++; |
if (_kernel_image_end < _sdram) |
wrp = _sdram; |
} |
|
// |
// Now, we move on to the SDRAM image. We'll here load into SDRAM |
// memory up to the end of the SDRAM image, _sdram_image_end. |
// As with the last pointer, this one is also created for us by the |
// linker. |
// |
// while(wrp < sdend) // Could also be done this way ... |
for(int i=0; i< sdend - _sdram; i++) |
*wrp++ = *rdp++; |
|
// |
// Finally, we load BSS. This is the segment that only needs to be |
// cleared to zero. It is available for global variables, but some |
// initialization is expected within it. We start writing where |
// the valid SDRAM context, i.e. the non-zero contents, end. |
// |
for(int i=0; i<bsend - sdend; i++) |
*wrp++ = 0; |
|
#endif |
} |
#endif |
|
/zlib/syscalls.c
0,0 → 1,376
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: syscalls.c |
// |
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core |
// |
// Purpose: |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <sys/errno.h> |
#include <stdint.h> |
#include <sys/unistd.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/times.h> |
#include <reent.h> |
#include <stdio.h> |
#include "artyboard.h" |
#include "bootloader.h" |
#include "zipcpu.h" |
|
void |
_outbyte(char v) { |
#ifdef _ZIP_HAS_WBUART |
if (v == '\n') { |
// Depend upon the WBUART, not the PIC |
while(_uart->u_fifo & 0x010000) |
; |
_uarttx = (unsigned)'\r'; |
} |
|
// Depend upon the WBUART, not the PIC |
while(_uart->u_fifo & 0x010000) |
; |
uint8_t c = v; |
_uarttx = (unsigned)c; |
#else |
#ifdef _ZIP_HAS_UARTTX |
// Depend upon the WBUART, not the PIC |
while(UARTTX & 0x100) |
; |
uint8_t c = v; |
UARTTX = (unsigned)c; |
#endif |
#endif |
} |
|
int |
_inbyte(void) { |
#ifdef _ZIP_HAS_WBUARTRX |
const int echo = 1, cr_into_nl = 1; |
static int last_was_cr = 0; |
int rv; |
|
// Character translations: |
// 1. All characters should be echoed |
// 2. \r's should quietly be turned into \n's |
// 3. \r\n's should quietly be turned into \n's |
// 4. \n's should be passed as is |
// Insist on at least one character |
rv = _uartrx; |
if (rv & 0x0100) |
rv = -1; |
else if ((cr_into_nl)&&(rv == '\r')) { |
rv = '\n'; |
last_was_cr = 1; |
} else if ((cr_into_nl)&&(rv == '\n')) { |
if (last_was_cr) { |
rv = -1; |
last_was_cr = 0; |
} |
} else |
last_was_cr = 0; |
|
if ((rv != -1)&&(echo)) |
_outbyte(rv); |
return rv; |
#else |
return -1; |
#endif |
} |
|
int |
_close_r(struct _reent *reent, int file) { |
reent->_errno = EBADF; |
|
return -1; /* Always fails */ |
} |
|
char *__env[1] = { 0 }; |
char **environ = __env; |
|
int |
_execve_r(struct _reent *reent, const char *name, char * const *argv, char * const *env) |
{ |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_fork_r(struct _reent *reent) |
{ |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_fstat_r(struct _reent *reent, int file, struct stat *st) |
{ |
if ((STDOUT_FILENO == file)||(STDERR_FILENO == file) |
||(STDIN_FILENO == file)) { |
st->st_mode = S_IFCHR; |
return 0; |
#ifdef _ZIP_HAS_SDCARD_NOTYET |
} else if (SDCARD_FILENO == file) { |
st->st_mode = S_IFBLK; |
#endif |
} else { |
reent->_errno = EBADF; |
return -1; |
} |
} |
|
int |
_getpid_r(struct _reent *reent) |
{ |
return 1; |
} |
|
int |
_gettimeofday_r(struct _reent *reent, struct timeval *ptimeval, void *ptimezone) |
{ |
#ifdef _ZIP_HAS_RTC |
if (ptimeval) { |
uint32_t now, date; |
unsigned s, m, h, tod; |
|
now = _rtcdev->r_clock; |
|
#ifdef _ZIP_HAS_RTDATE |
unsigned d, y, c, yy, days_since_epoch; |
int ly; |
|
date= *_rtdate; |
|
d = ( date &0x0f)+((date>> 4)&0x0f)*10; |
m = ((date>> 8)&0x0f)+((date>>12)&0x0f)*10; |
y = ((date>>16)&0x0f)+((date>>20)&0x0f)*10; |
c = ((date>>24)&0x0f)+((date>>28)&0x0f)*10; |
|
ly = 0; |
if ((y&3)==0) { |
if (y!=0) |
ly = 1; |
else if ((y&3)==0) |
ly = 1; |
} |
|
days_since_epoch = d; |
if (m>1) { |
days_since_epoch += 31; |
if (m>2) { |
days_since_epoch += 28; |
if (ly) days_since_epoch++; |
if (m>3) { days_since_epoch += 31; |
if (m>4) { days_since_epoch += 30; |
if (m>5) { days_since_epoch += 31; |
if (m>6) { days_since_epoch += 30; |
if (m>7) { days_since_epoch += 31; |
if (m>8) { days_since_epoch += 31; |
if (m>9) { days_since_epoch += 30; |
if (m>10) { days_since_epoch += 31; |
if (m>11) days_since_epoch += 30; |
}}}}}}}}}} |
|
for(yy=1970; yy<(c*100+y); yy++) { |
if ((yy&3)==0) |
days_since_epoch += 366; |
else |
days_since_epoch += 365; |
} |
|
ptimeval->tv_sec = days_since_epoch * 86400l; |
#else |
ptimeval->tv_sec = 0; |
#endif |
|
s = ( now &0x0f)+((now>> 4)&0x0f)*10; |
m = ((now>> 8)&0x0f)+((now>>12)&0x0f)*10; |
h = ((now>>16)&0x0f)+((now>>20)&0x0f)*10; |
tod = (h * 60 + m) * 60; |
ptimeval->tv_sec += tod; |
|
ptimeval->tv_usec = 0; |
} |
return 0; |
#else |
reent->_errno = ENOSYS; |
return -1; |
#endif |
} |
|
int |
_isatty_r(struct _reent *reent, int file) |
{ |
if ((STDIN_FILENO == file) |
||(STDOUT_FILENO == file) |
||(STDERR_FILENO==file)) |
return 1; |
return 0; |
} |
|
int |
_kill_r(struct _reent *reent, int pid, int sig) |
{ |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_link_r(struct _reent *reent, const char *existing, const char *new) |
{ |
reent->_errno = ENOSYS; |
return -1; |
} |
|
_off_t |
_lseek_r(struct _reent *reent, int file, _off_t ptr, int dir) |
{ |
#ifdef _ZIP_HAS_SDCARD_NOTYET |
if (SDCARD_FILENO == file) { |
switch(dir) { |
case SEEK_SET: rootfs_offset = ptr; |
case SEEK_CUR: rootfs_offset += ptr; |
case SEEK_END: rootfs_offset = rootfs->nsectors * rootfs->sectorsize - ptr; |
default: |
reent->_errno = EINVAL; return -1; |
} return rootfs_offset; |
} |
#endif |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_open_r(struct _reent *reent, const char *file, int flags, int mode) |
{ |
#ifdef _ZIP_HAS_SDCARD_NOTYET |
if (strcmp(file, "/dev/sdcard")==0) { |
return SDCARD_FILENO; |
} else { |
reent->_errno = EACCES; |
return -1; |
} |
#endif |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_read_r(struct _reent *reent, int file, void *ptr, size_t len) |
{ |
#ifdef _ZIP_HAS_WBUARTRX |
if (STDIN_FILENO == file) |
{ |
int nr = 0, rv; |
char *chp = ptr; |
|
while((rv=_inbyte()) &0x0100) |
; |
*chp++ = (char)rv; |
nr++; |
|
// Now read out anything left in the FIFO |
while((nr < len)&&(((rv=_inbyte()) & 0x0100)==0)) { |
*chp++ = (char)rv; |
nr++; |
} |
|
// if (rv & 0x01000) _uartrx = 0x01000; |
return nr; |
} |
#endif |
#ifdef _ZIP_HAS_SDCARD_NOTYET |
if (SDCARD_FILENO == file) |
{ |
} |
#endif |
errno = ENOSYS; |
return -1; |
} |
|
int |
_readlink_r(struct _reent *reent, const char *path, char *buf, size_t bufsize) |
{ |
reent->_errno = ENOSYS; |
return -1; |
} |
|
int |
_stat_r(struct _reent *reent, const char *path, struct stat *buf) { |
reent->_errno = EIO; |
return -1; |
} |
|
int |
_unlink_r(struct _reent *reent, const char *path) |
{ |
reent->_errno = EIO; |
return -1; |
} |
|
int |
_times(struct tms *buf) { |
errno = EACCES; |
return -1; |
} |
|
int |
_write_r(struct _reent * reent, int fd, const void *buf, size_t nbytes) { |
if ((STDOUT_FILENO == fd)||(STDERR_FILENO == fd)) { |
const char *cbuf = buf; |
for(int i=0; i<nbytes; i++) |
_outbyte(cbuf[i]); |
return nbytes; |
} |
#ifdef _ZIP_HAS_SDCARD_NOTYET |
if (SDCARD_FILENO == file) |
{ |
} |
#endif |
|
reent->_errno = EBADF; |
return -1; |
} |
|
int |
_wait(int *status) { |
errno = ECHILD; |
return -1; |
} |
|
int *heap = _top_of_heap; |
|
void * |
_sbrk_r(struct _reent *reent, int sz) { |
int *prev = heap; |
|
heap += sz; |
return prev; |
} |
|
/zlib/udiv.c
0,0 → 1,227
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: udiv.c |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: This is a temporary file--a crutch if you will--until a similar |
// capability is merged into GCC. Right now, GCC has no way of |
// dividing two 64-bit numbers, and this routine provides that capability. |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <stdint.h> |
|
|
|
#ifdef __ZIPCPU__ |
#include "zipcpu.h" |
#else |
uint32_t zip_bitrev(const uint32_t a) { |
uint32_t r, b = a; |
r = 0; |
for(int i=0; i<32; i++) { |
r = (r<<1) | (b&1); |
b >>= 1; |
} return r; |
} |
#endif |
|
extern int cltz(unsigned long); |
|
#ifdef __ZIPCPU__ |
#define ASMCLTZ |
#endif |
|
#ifdef ASMCLTZ |
asm("\t.section\t.text\n\t.global\tcltz\n" |
"\t.type\tcltz,@function\n" |
"cltz:\n" |
"\tMOV R1,R3\n" |
"\tCLR R1\n" |
"\tCMP 0,R3\n" |
"\tMOV.Z R2,R3\n" |
"\tADD.Z 32,R1\n" |
"\tBREV R3\n" |
"\tTEST 0x0ffff,R3\n" |
"\tADD.Z 16,R1\n" |
"\tLSR.Z 16,R3\n" |
"\tTEST 0x0ff,R3\n" |
"\tADD.Z 8,R1\n" |
"\tLSR.Z 8,R3\n" |
"\tTEST 0x0f,R3\n" |
"\tADD.Z 4,R1\n" |
"\tLSR.Z 4,R3\n" |
"\tTEST 0x03,R3\n" |
"\tADD.Z 2,R1\n" |
"\tLSR.Z 2,R3\n" |
"\tTEST 0x01,R3\n" |
"\tADD.Z 1,R1\n" |
"\tRETN\n"); |
#else |
int |
cltz(unsigned long v) { |
uint32_t hv; |
int cnt = 0; |
|
hv = v >> 32; |
if (hv == 0) { |
cnt += 32; |
hv = v & 0x0ffffffff; |
} |
|
hv = zip_bitrev(hv); |
if ((hv & 0x0ffff)==0) { |
cnt += 16; |
hv = hv >> 16; |
} |
if ((hv & 0x0ff)==0) { |
cnt += 8; |
hv = hv >> 8; |
} |
if ((hv & 0x0f)==0) { |
cnt += 4; |
hv = hv >> 4; |
} |
if ((hv & 0x03)==0) { |
cnt += 2; |
hv = hv >> 2; |
} |
if ((hv & 0x01)==0) |
cnt ++; |
return cnt; |
} |
#endif |
|
unsigned long |
__udivdi3(unsigned long a, unsigned long b) { |
unsigned long r; |
|
if (a < b) |
return 0; |
if (((b>>32)==0)&&((a>>32)==0)) { |
uint32_t ia, ib, ir; |
|
ia = (uint32_t) a; |
ib = (uint32_t) b; |
ir = ia / ib; |
r = (unsigned long)ir; |
return r; |
} |
|
int la = cltz(a), lb = cltz(b); |
a <<= la; |
unsigned long m; |
if ((lb - la < 32)&&(((b<<la)&0x0ffffffff)==0)) { |
// Problem is now to divide |
// [a * 2^(la-32)] / [b * 2^(la-32)] * 2^(la-la) |
// |
uint32_t ia, ib, ir; |
b <<= la; |
ia = (uint32_t)(a>>32); |
ib = (uint32_t)(b>>32); |
ir = ia / ib; |
r = ir; |
return r; |
} else { |
// Problem is now to divide |
// [a * 2^(la)] / [b * 2^(lb)] * 2^(lb-la) |
// |
r = 0; |
b <<= lb; |
m = (1ul<<(lb-la)); |
while(m > 0) { |
if (a >= b) { |
r |= m; |
a -= b; |
} |
m>>= 1; |
b >>= 1; |
} return r; |
} |
} |
|
// |
// A possible assembly version of __divdi3 |
// |
// SUB 8,SP |
// SW R0,(SP) |
// SW R5,4(SP) |
// LDI 0,R5 |
// CMP 0,R1 |
// BGE .La_is_nonneg |
// XOR 1,R5 |
// XOR -1,R1 |
// XOR -1,R2 |
// ADD 1,R2 |
// ADD.C 1,R1 |
//.La_is_nonneg |
// CMP 0,R3 |
// BGE .Lb_is_nonneg |
// XOR 1,R5 |
// XOR -1,R3 |
// XOR -1,R3 |
// ADD 1,R4 |
// ADD.C 1,R3 |
//.Lb_is_nonneg |
// TEST R5 |
// MOV .Lnegate_upon_return(PC),R0 |
// MOV.Z .Lsimple_return(PC),R0 |
// BRA __udivdi3 |
//.Lnegate_upon_return |
// XOR -1,R2 |
// XOR -1,R1 |
// ADD 1,R2 |
// ADD.C 1,R1 |
//.Lsimple_return |
// |
// LW (SP),R0,(SP) |
// LW 4(SP),R5) |
// ADD 8,SP |
// RETN |
// |
long __divdi3(long a, long b) { |
int s = 0; |
long r; |
|
if (a < 0) { |
s = 1; a = -a; |
} |
|
if (b < 0) { |
s ^= 1; b = -b; |
} |
|
r = (long)__udivdi3((unsigned long)a, (unsigned long)b); |
if (s) |
r = -r; |
return r; |
} |
/zlib/umod.c
0,0 → 1,62
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: umod.c |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: This is a temporary file--a crutch if you will--until a similar |
// capability is merged into GCC. Right now, GCC has no way of |
// taking the module of two 64-bit numbers, and this routine provides that |
// capability. |
// |
// This routine is required by and used by newlib's printf in order to |
// print decimal numbers (%d) to an IO stream. |
// |
// Once gcc is properly patched, this will be removed from the |
// repository. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2017, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <stdint.h> |
|
|
unsigned long __udivdi3(unsigned long, unsigned long); |
|
__attribute((noinline)) |
unsigned long __umoddi3(unsigned long a, unsigned long b) { |
unsigned long r; |
|
// Return a modulo b, or a%b in C syntax |
r = __udivdi3(a, b); |
r = r * b; |
r = a - r; |
return r; |
} |
|
/zlib/zipcpu.h
0,0 → 1,85
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: zipsys.h |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: Declare the capabilities and memory structure of the ZipSystem |
// for programs that must interact with it. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#ifndef ZIPCPU_H |
#define ZIPCPU_H |
|
#define CC_Z 0x0001 |
#define CC_C 0x0002 |
#define CC_N 0x0004 |
#define CC_V 0x0008 |
#define CC_SLEEP 0x0010 |
#define CC_GIE 0x0020 |
#define CC_STEP 0x0040 |
#define CC_BREAK 0x0080 |
#define CC_ILL 0x0100 |
#define CC_TRAP 0x0200 |
#define CC_BUSERR 0x0400 |
#define CC_DIVERR 0x0800 |
#define CC_FPUERR 0x1000 |
#define CC_IPHASE 0x2000 |
#define CC_MMUERR 0x8000 |
#define CC_FAULT (CC_ILL|CC_BUSERR|CC_DIVERR|CC_FPUERR) |
#define CC_EXCEPTION (CC_BREAK|CC_FAULT|CC_MMUERR) |
|
// extern void zip_break(void); |
#define zip_break() asm("BREAK\n") |
// #define BREAK(ID) asm("BREAK " ##ID "\n") |
#define GETUREG(A,ID) asm("MOV " ID ",%0" : "=r"(A)) |
#define SETUREG(A,ID) asm("MOV %0," ID : : "r"(A)) |
extern void zip_rtu(void); |
extern void zip_halt(void); |
extern void zip_idle(void); |
extern void zip_syscall(void); |
extern void zip_restore_context(int *); |
extern void zip_save_context(int *); |
extern int zip_bitrev(int v); |
extern unsigned zip_cc(void); |
extern unsigned zip_ucc(void); |
|
extern void save_context(int *); |
extern void restore_context(int *); |
extern int syscall(int,int,int,int); |
|
#ifndef NULL |
#define NULL ((void *)0) |
#endif |
|
#define ASMFNSTR(A) "\t.section\t.text\n\t.global\t" A "\n\t.type\t" A ",@function\n" A ":\n" |
|
#endif |
/zlib/zipsys.h
0,0 → 1,135
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: zipsys.h |
// |
// Project: OpenArty, an entirely open SoC based upon the Arty platform |
// |
// Purpose: Declare the capabilities and memory structure of the ZipSystem |
// for programs that must interact with it. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): 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 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#ifndef ZIPSYS_H |
#define ZIPSYS_H |
|
typedef struct { |
unsigned ac_ck, ac_mem, ac_pf, ac_icnt; |
} ZIPTASKCTRS; |
|
typedef struct { |
int d_ctrl, d_len; |
int *d_rd, *d_wr; |
} ZIPDMA; |
|
#define DMA_TRIGGER 0x00008000 |
#define DMACABORT 0xffed0000 |
#define DMACLEAR 0xafed0000 |
#define DMACCOPY 0x0fed0000 |
#define DMACERR 0x40000000 |
#define DMA_CONSTSRC 0x20000000 |
#define DMA_CONSTDST 0x10000000 |
#define DMAONEATATIME 0x0fed0001 |
#define DMA_BUSY 0x80000000 |
#define DMA_ERR 0x40000000 |
#define DMA_ONINT(INT) (DMA_TRIGGER|(((INT)&15)<<10)) |
#define DMA_ONJIFFIES DMA_ONINT(1) |
#define DMA_ONTMC DMA_ONINT(2) |
#define DMA_ONTMB DMA_ONINT(3) |
#define DMA_ONTMA DMA_ONINT(4) |
#define DMA_ONAUX DMA_ONINT(5) |
|
#define TMR_INTERVAL 0x80000000 |
typedef struct { |
int z_pic, z_wdt, z_wbus, z_apic, z_tma, z_tmb, z_tmc, |
z_jiffies; |
#ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS |
ZIPTASKCTRS z_m, z_u; |
#else |
unsigned z_nocounters[8]; |
#endif |
#ifdef _HAVE_ZIPSYS_DMA |
ZIPDMA z_dma; |
#else |
unsigned z_nodma[4]; |
#endif |
} ZIPSYS; |
|
#define ZIPSYS_ADDR 0xff000000 |
|
#define SYSINT_DMAC 0x0001 |
#define SYSINT_JIFFIES 0x0002 |
#define SYSINT_TMC 0x0004 |
#define SYSINT_TMB 0x0008 |
#define SYSINT_TMA 0x0010 |
#define SYSINT_AUX 0x0020 |
// |
#define SYSINT(INTID) (1<<(INTID)) |
#define ALTINT(INTID) (1<<(INTID)) |
|
#ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS |
#define ALTINT_UIC ALTINT(0) |
#define ALTINT_UTC ALTINT(3) |
#define ALTINT_MIC ALTINT(4) |
#define ALTINT_MTC ALTINT(7) |
#endif |
|
#define INT_ENABLE 0x80000000 |
#define EINT(A) (INT_ENABLE|((A)<<16)) |
#define DINT(A) ((A)<<16) |
#define CLEARPIC 0x7fff7fff |
#define DALLPIC 0x7fff0000 // Disable all PIC interrupt sources |
#define INTNOW 0x08000 |
|
static volatile ZIPSYS *const zip = (ZIPSYS *)(ZIPSYS_ADDR); |
|
static inline void DISABLE_INTS(void) { |
zip->z_pic = 0; |
} |
|
static inline void ENABLE_INTS(void) { |
zip->z_pic = 0x80000000; |
} |
|
typedef struct { |
int c_r[16]; |
#ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS |
unsigned long c_ck, c_mem, c_pf, c_icnt; |
#endif |
} ZSYSCONTEXT; |
|
#ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS |
void save_contextncntrs(ZSYSCONTEXT *c); |
void restore_contextncntrs(ZSYSCONTEXT *c); |
#else |
#define save_contextncntrs(CONTEXT) save_context((int *)CONTEXT) |
#define restore_contextncntrs(CONTEXT) restore_context((int *)CONTEXT) |
#endif |
|
#endif |
zlib
Property changes :
Added: svn:ignore
## -0,0 +1 ##
+obj-zip