├── misoc ├── __init__.py ├── cores │ ├── __init__.py │ ├── coaxpress │ │ ├── __init__.py │ │ ├── phy │ │ │ └── __init__.py │ │ ├── common.py │ │ └── core │ │ │ ├── idle.py │ │ │ └── crc.py │ ├── liteeth_mini │ │ ├── __init__.py │ │ ├── common.py │ │ ├── phy │ │ │ ├── __init__.py │ │ │ └── rgmii.py │ │ ├── mac │ │ │ ├── gap.py │ │ │ ├── last_be.py │ │ │ ├── __init__.py │ │ │ ├── wishbone.py │ │ │ └── padding.py │ │ ├── LICENSE │ │ └── README │ ├── lm32 │ │ ├── __init__.py │ │ └── core.py │ ├── mor1kx │ │ └── __init__.py │ ├── minicon │ │ └── __init__.py │ ├── uart │ │ └── __init__.py │ ├── vexriscv │ │ ├── __init__.py │ │ └── core.py │ ├── sdram_phy │ │ └── __init__.py │ ├── virtual_leds.py │ ├── identifier.py │ ├── timer.py │ ├── gpio.py │ └── dfii.py ├── test │ ├── __init__.py │ ├── test_cic.py │ └── test_sequencer.py ├── tools │ ├── __init__.py │ └── mkmscimg.py ├── targets │ ├── __init__.py │ └── simple.py ├── interconnect │ ├── __init__.py │ ├── wishbone2csr.py │ └── wishbone2lasmi.py ├── software │ ├── unwinder │ │ ├── test │ │ │ ├── libunwind │ │ │ │ ├── __init__.py │ │ │ │ └── test │ │ │ │ │ └── __init__.py │ │ │ ├── unw_getcontext.pass.cpp │ │ │ ├── lit.cfg.py │ │ │ ├── libunwind_02.pass.cpp │ │ │ ├── signal_frame.pass.cpp │ │ │ ├── alignment.compile.pass.cpp │ │ │ ├── libunwind_01.pass.cpp │ │ │ ├── signal_unwind.pass.cpp │ │ │ ├── unwind_leaffunction.pass.cpp │ │ │ ├── remember_state_leak.pass.sh.s │ │ │ ├── CMakeLists.txt │ │ │ ├── frameheadercache_test.pass.cpp │ │ │ └── lit.site.cfg.in │ │ ├── .clang-format │ │ ├── docs │ │ │ ├── CMakeLists.txt │ │ │ └── README.txt │ │ └── src │ │ │ ├── Unwind-EHABI.h │ │ │ └── libunwind_ext.h │ ├── libm │ │ ├── s_signgam.c │ │ ├── s_matherr.c │ │ ├── s_fabs.c │ │ ├── s_finite.c │ │ ├── s_ldexp.c │ │ ├── e_gamma.c │ │ ├── s_significand.c │ │ ├── e_lgamma.c │ │ ├── s_isnan.c │ │ ├── s_copysign.c │ │ ├── e_gamma_r.c │ │ ├── s_lib_version.c │ │ ├── w_sqrt.c │ │ ├── w_sinh.c │ │ ├── w_acos.c │ │ ├── w_acosh.c │ │ ├── w_asin.c │ │ ├── w_cosh.c │ │ ├── w_fmod.c │ │ ├── w_log.c │ │ ├── w_hypot.c │ │ ├── s_logb.c │ │ ├── w_atan2.c │ │ ├── w_remainder.c │ │ ├── w_log10.c │ │ ├── w_atanh.c │ │ ├── Makefile │ │ ├── w_exp.c │ │ ├── s_ilogb.c │ │ ├── w_gamma.c │ │ ├── w_gamma_r.c │ │ ├── w_lgamma.c │ │ ├── w_lgamma_r.c │ │ ├── e_scalb.c │ │ ├── w_scalb.c │ │ ├── s_frexp.c │ │ ├── w_pow.c │ │ ├── w_j1.c │ │ ├── w_j0.c │ │ ├── s_asinh.c │ │ ├── e_acosh.c │ │ ├── e_atanh.c │ │ ├── s_ceil.c │ │ ├── s_floor.c │ │ ├── s_scalbn.c │ │ ├── e_remainder.c │ │ ├── s_tan.c │ │ ├── s_modf.c │ │ ├── s_rint.c │ │ ├── s_sin.c │ │ ├── s_cos.c │ │ ├── s_nextafter.c │ │ ├── s_tanh.c │ │ ├── s_cbrt.c │ │ ├── e_sinh.c │ │ ├── k_sin.c │ │ └── w_jn.c │ ├── libunwind │ │ ├── __cxxabi_config.h │ │ └── Makefile │ ├── bios │ │ ├── boot-helper-lm32.S │ │ ├── boot-helper-vexriscv.S │ │ ├── boot-helper-vexriscv-g.S │ │ ├── boot-helper-or1k.S │ │ ├── boot.h │ │ ├── isr.c │ │ ├── sdram.h │ │ ├── Makefile │ │ ├── sfl.h │ │ └── bios.ld │ ├── include │ │ ├── basec++ │ │ │ ├── algorithm │ │ │ ├── cstdlib │ │ │ ├── cstddef │ │ │ └── new │ │ ├── base │ │ │ ├── assert.h │ │ │ ├── stdbool.h │ │ │ ├── math.h │ │ │ ├── csr-defs.h │ │ │ ├── id.h │ │ │ ├── time.h │ │ │ ├── crc.h │ │ │ ├── spiflash.h │ │ │ ├── uart.h │ │ │ ├── stddef.h │ │ │ ├── limits.h │ │ │ ├── console.h │ │ │ ├── endian.h │ │ │ ├── stdarg.h │ │ │ ├── pthread.h │ │ │ ├── stdint.h │ │ │ ├── system.h │ │ │ ├── float.h │ │ │ ├── ctype.h │ │ │ ├── stdio.h │ │ │ ├── string.h │ │ │ ├── irq.h │ │ │ └── stdlib.h │ │ ├── alloc.h │ │ ├── hw │ │ │ ├── common.h │ │ │ └── flags.h │ │ ├── net │ │ │ ├── tftp.h │ │ │ └── microudp.h │ │ └── dyld │ │ │ ├── link.h │ │ │ ├── dlfcn.h │ │ │ └── dyld.h │ ├── liballoc │ │ └── Makefile │ ├── libnet │ │ └── Makefile │ ├── memtest │ │ ├── isr.c │ │ └── Makefile │ ├── libdyld │ │ └── Makefile │ ├── libprintf │ │ ├── Makefile │ │ └── ctype.c │ ├── libbase │ │ ├── id.c │ │ ├── time.c │ │ ├── Makefile │ │ ├── linker-sdram.ld │ │ ├── crt0-vexriscv.S │ │ ├── crt0-vexriscv-g.S │ │ ├── console.c │ │ ├── system.c │ │ └── crc16.c │ └── libcompiler-rt │ │ └── Makefile └── integration │ └── __init__.py ├── .gitignore ├── MANIFEST.in ├── .gitmodules ├── CONTRIBUTING.rst ├── setup.py ├── LICENSE └── README /misoc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/cores/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/tools/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/targets/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/cores/coaxpress/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/interconnect/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/cores/coaxpress/phy/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/libunwind/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/libunwind/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /misoc/software/unwinder/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | 3 | -------------------------------------------------------------------------------- /misoc/cores/lm32/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.lm32.core import LM32 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.pyc 3 | *.egg-info 4 | *.vcd 5 | outgoing 6 | -------------------------------------------------------------------------------- /misoc/cores/mor1kx/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.mor1kx.core import MOR1KX 2 | -------------------------------------------------------------------------------- /misoc/software/libm/s_signgam.c: -------------------------------------------------------------------------------- 1 | #include "fdlibm.h" 2 | int signgam = 0; 3 | -------------------------------------------------------------------------------- /misoc/software/libunwind/__cxxabi_config.h: -------------------------------------------------------------------------------- 1 | #define LIBCXXABI_ARM_EHABI 0 2 | -------------------------------------------------------------------------------- /misoc/cores/minicon/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.minicon.core import Minicon 2 | -------------------------------------------------------------------------------- /misoc/cores/uart/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.uart.core import UART, RS232PHY 2 | -------------------------------------------------------------------------------- /misoc/cores/vexriscv/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.vexriscv.core import VexRiscv 2 | -------------------------------------------------------------------------------- /misoc/integration/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.integration.soc_core import SoCCore 2 | from misoc.integration.soc_sdram import SoCSDRAM 3 | -------------------------------------------------------------------------------- /misoc/software/bios/boot-helper-lm32.S: -------------------------------------------------------------------------------- 1 | .section .text, "ax", @progbits 2 | .global boot_helper 3 | boot_helper: 4 | call r4 5 | -------------------------------------------------------------------------------- /misoc/software/bios/boot-helper-vexriscv.S: -------------------------------------------------------------------------------- 1 | .section .text, "ax", @progbits 2 | .global boot_helper 3 | boot_helper: 4 | jr x13 5 | -------------------------------------------------------------------------------- /misoc/software/include/basec++/algorithm: -------------------------------------------------------------------------------- 1 | #ifndef __CXX_ALGORITHM 2 | #define __CXX_ALGORITHM 3 | 4 | #endif /* __CXX_ALGORITHM */ 5 | -------------------------------------------------------------------------------- /misoc/software/bios/boot-helper-vexriscv-g.S: -------------------------------------------------------------------------------- 1 | .section .text, "ax", @progbits 2 | .global boot_helper 3 | boot_helper: 4 | jr x13 5 | -------------------------------------------------------------------------------- /misoc/software/include/base/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASSERT_H 2 | #define __ASSERT_H 3 | 4 | #define assert(x) 5 | 6 | #endif /* __ASSERT_H */ 7 | -------------------------------------------------------------------------------- /misoc/software/bios/boot-helper-or1k.S: -------------------------------------------------------------------------------- 1 | .section .text, "ax", @progbits 2 | .global boot_helper 3 | boot_helper: 4 | l.jr r6 5 | l.nop 6 | -------------------------------------------------------------------------------- /misoc/software/include/basec++/cstdlib: -------------------------------------------------------------------------------- 1 | #ifndef __CXX_CSTDLIB 2 | #define __CXX_CSTDLIB 3 | 4 | #include 5 | 6 | #endif /* __CXX_CSTDLIB */ 7 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | graft misoc/software 2 | graft misoc/cores/lm32/verilog 3 | graft misoc/cores/mor1kx/verilog 4 | graft misoc/cores/vexriscv/verilog 5 | include misoc/cores/mxcrg.v 6 | -------------------------------------------------------------------------------- /misoc/software/include/base/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDBOOL_H 2 | #define __STDBOOL_H 3 | 4 | #define bool _Bool 5 | #define true 1 6 | #define false 0 7 | 8 | #endif /* __STDBOOL_H */ 9 | -------------------------------------------------------------------------------- /misoc/software/include/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef _ALLOC_H 2 | #define _ALLOC_H 3 | 4 | #include 5 | 6 | void alloc_give(void *addr, size_t size); 7 | void alloc_show(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /misoc/software/bios/boot.h: -------------------------------------------------------------------------------- 1 | #ifndef __BOOT_H 2 | #define __BOOT_H 3 | 4 | int serialboot(void); 5 | void netboot(void); 6 | void flashboot(void); 7 | void romboot(void); 8 | 9 | #endif /* __BOOT_H */ 10 | -------------------------------------------------------------------------------- /misoc/cores/sdram_phy/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.sdram_phy.gensdrphy import GENSDRPHY 2 | from misoc.cores.sdram_phy.s6ddrphy import S6HalfRateDDRPHY, S6QuarterRateDDRPHY 3 | from misoc.cores.sdram_phy.k7ddrphy import K7DDRPHY 4 | -------------------------------------------------------------------------------- /misoc/software/include/hw/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __HW_COMMON_H 2 | #define __HW_COMMON_H 3 | 4 | #ifdef __ASSEMBLER__ 5 | #define MMPTR(x) x 6 | #else 7 | #define MMPTR(x) (*((volatile unsigned int *)(x))) 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /misoc/software/include/basec++/cstddef: -------------------------------------------------------------------------------- 1 | #ifndef __CXX_CSTDDEF 2 | #define __CXX_CSTDDEF 3 | 4 | #include 5 | 6 | namespace std { 7 | using ::size_t; 8 | using ::ptrdiff_t; 9 | } 10 | 11 | #endif /* __CXX_CSTDDEF */ 12 | -------------------------------------------------------------------------------- /misoc/software/include/basec++/new: -------------------------------------------------------------------------------- 1 | #ifndef __CXX_NEW 2 | #define __CXX_NEW 3 | 4 | #include 5 | 6 | inline void* operator new (std::size_t size, void* ptr) noexcept 7 | { return ptr; } 8 | 9 | #endif /* __CXX_NEW */ 10 | -------------------------------------------------------------------------------- /misoc/software/unwinder/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FindSphinx) 2 | if (SPHINX_FOUND AND LLVM_ENABLE_SPHINX) 3 | include(AddSphinxTarget) 4 | if (${SPHINX_OUTPUT_HTML}) 5 | add_sphinx_target(html libunwind) 6 | endif() 7 | endif() 8 | -------------------------------------------------------------------------------- /misoc/software/include/base/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATH_H 2 | #define __MATH_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "../fdlibm/fdlibm.h" 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif /* __MATH_H */ 15 | -------------------------------------------------------------------------------- /misoc/software/liballoc/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | all:: liballoc.a 5 | 6 | liballoc.a: alloc.o 7 | $(archive) 8 | 9 | %.o: $(LIBALLOC_DIRECTORY)/%.c 10 | $(compile) 11 | -------------------------------------------------------------------------------- /misoc/software/libnet/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | all:: libnet.a 5 | 6 | libnet.a: microudp.o tftp.o 7 | $(archive) 8 | 9 | %.o: $(LIBNET_DIRECTORY)/%.c 10 | $(compile) 11 | -------------------------------------------------------------------------------- /misoc/software/include/base/csr-defs.h: -------------------------------------------------------------------------------- 1 | #ifndef CSR_DEFS__H 2 | #define CSR_DEFS__H 3 | 4 | #define CSR_MSTATUS_MIE 0x8 5 | 6 | #define CSR_IRQ_MASK 0xBC0 7 | #define CSR_IRQ_PENDING 0xFC0 8 | 9 | #define CSR_DCACHE_INFO 0xCC0 10 | 11 | #endif /* CSR_DEFS__H */ 12 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/unw_getcontext.pass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int, char**) { 5 | unw_context_t context; 6 | int ret = unw_getcontext(&context); 7 | assert(ret == UNW_ESUCCESS); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /misoc/software/include/base/id.h: -------------------------------------------------------------------------------- 1 | #ifndef __ID_H 2 | #define __ID_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define IDENT_SIZE 256 9 | void get_ident(char *ident); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* __ID_H */ 16 | -------------------------------------------------------------------------------- /misoc/software/include/base/time.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIME_H 2 | #define __TIME_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void time_init(void); 9 | int elapsed(int *last_event, int period); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* __TIME_H */ 16 | -------------------------------------------------------------------------------- /misoc/software/bios/isr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void isr(void); 6 | void isr(void) 7 | { 8 | unsigned int irqs; 9 | 10 | irqs = irq_pending() & irq_getmask(); 11 | 12 | if(irqs & (1 << UART_INTERRUPT)) 13 | uart_isr(); 14 | } 15 | -------------------------------------------------------------------------------- /misoc/software/include/net/tftp.h: -------------------------------------------------------------------------------- 1 | #ifndef __TFTP_H 2 | #define __TFTP_H 3 | 4 | #include 5 | 6 | int tftp_get(uint32_t ip, const char *filename, void *buffer); 7 | int tftp_put(uint32_t ip, const char *filename, const void *buffer, int size); 8 | 9 | #endif /* __TFTP_H */ 10 | 11 | -------------------------------------------------------------------------------- /misoc/software/memtest/isr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void isr(void); 6 | void isr(void) 7 | { 8 | unsigned int irqs; 9 | 10 | irqs = irq_pending() & irq_getmask(); 11 | 12 | if(irqs & (1 << UART_INTERRUPT)) 13 | uart_isr(); 14 | } 15 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/common.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | eth_mtu = 1530 4 | eth_min_len = 46 5 | eth_interpacket_gap = 12 6 | eth_preamble = 0xD555555555555555 7 | 8 | 9 | def eth_phy_layout(dw=8): 10 | return [ 11 | ("data", dw), 12 | ("last_be", dw//8), 13 | ("error", dw//8) 14 | ] 15 | -------------------------------------------------------------------------------- /misoc/software/include/base/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef __CRC_H 2 | #define __CRC_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | unsigned short crc16(const unsigned char *buffer, int len); 9 | unsigned int crc32(const unsigned char *buffer, unsigned int len); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /misoc/software/include/base/spiflash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPIFLASH_H 2 | #define __SPIFLASH_H 3 | 4 | void write_to_flash_page(unsigned int addr, const unsigned char *c, unsigned int len); 5 | void erase_flash_sector(unsigned int addr); 6 | void write_to_flash(unsigned int addr, const unsigned char *c, unsigned int len); 7 | 8 | #endif /* __SPIFLASH_H */ 9 | -------------------------------------------------------------------------------- /misoc/cores/virtual_leds.py: -------------------------------------------------------------------------------- 1 | from misoc.interconnect.csr import * 2 | 3 | 4 | class VirtualLeds(Module, AutoCSR): 5 | def __init__(self, max_leds=8): 6 | self.status = CSRStatus(max_leds) 7 | 8 | def get(self, n): 9 | virtual_led = Signal() 10 | self.comb += self.status.status[n].eq(virtual_led) 11 | return virtual_led 12 | -------------------------------------------------------------------------------- /misoc/software/include/base/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef __UART_H 2 | #define __UART_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void uart_init(void); 9 | void uart_isr(void); 10 | void uart_sync(void); 11 | 12 | void uart_write(char c); 13 | char uart_read(void); 14 | int uart_read_nonblock(void); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /misoc/software/libdyld/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | COMMONFLAGS += -I$(MISOC_DIRECTORY)/software/include/dyld 5 | 6 | # lm32 is not supported 7 | ifeq ($(CPU),or1k) 8 | all:: libdyld.a 9 | endif 10 | ifeq ($(CPU),vexriscv) 11 | all:: libdyld.a 12 | endif 13 | 14 | libdyld.a: dyld.o 15 | $(archive) 16 | 17 | %.o: $(LIBDYLD_DIRECTORY)/%.c 18 | $(compile) 19 | -------------------------------------------------------------------------------- /misoc/software/libprintf/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | all:: libprintf-float.a libprintf-nofloat.a 5 | 6 | libprintf-%.a: ctype.o printf-%.o 7 | $(archive) 8 | 9 | printf-float.o: $(LIBPRINTF_DIRECTORY)/printf.c 10 | $(compile) 11 | 12 | printf-nofloat.o: $(LIBPRINTF_DIRECTORY)/printf.c 13 | $(compile) -D_PRINTF_NO_FLOAT 14 | 15 | %.o: $(LIBPRINTF_DIRECTORY)/%.c 16 | $(compile) 17 | -------------------------------------------------------------------------------- /misoc/software/include/base/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDDEF_H 2 | #define __STDDEF_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #ifdef __cplusplus 9 | #define NULL 0 10 | #else 11 | #define NULL ((void *)0) 12 | #endif 13 | 14 | typedef __SIZE_TYPE__ size_t; 15 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 16 | 17 | #define offsetof(type, member) __builtin_offsetof(type, member) 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* __STDDEF_H */ 24 | -------------------------------------------------------------------------------- /misoc/software/unwinder/docs/README.txt: -------------------------------------------------------------------------------- 1 | libunwind Documentation 2 | ==================== 3 | 4 | The libunwind documentation is written using the Sphinx documentation generator. It is 5 | currently tested with Sphinx 1.1.3. 6 | 7 | To build the documents into html configure libunwind with the following cmake options: 8 | 9 | * -DLLVM_ENABLE_SPHINX=ON 10 | * -DLIBUNWIND_INCLUDE_DOCS=ON 11 | 12 | After configuring libunwind with these options the make rule `docs-libunwind-html` 13 | should be available. 14 | -------------------------------------------------------------------------------- /misoc/software/include/base/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIMITS_H 2 | #define __LIMITS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define ULONG_MAX 0xffffffff 9 | 10 | #define UINT_MAX 0xffffffff 11 | #define INT_MIN 0x80000000 12 | #define INT_MAX 0x7fffffff 13 | 14 | #define USHRT_MAX 0xffff 15 | #define SHRT_MIN 0x8000 16 | #define SHRT_MAX 0x7fff 17 | 18 | #define UCHAR_MAX 0xff 19 | 20 | #define CHAR_BIT 8 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* __LIMITS_H */ 27 | -------------------------------------------------------------------------------- /misoc/software/libbase/id.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | void get_ident(char *ident) 9 | { 10 | #ifdef CSR_IDENTIFIER_BASE 11 | int len, i; 12 | 13 | identifier_address_write(0); 14 | len = identifier_data_read(); 15 | for(i=0;i 5 | 6 | void sdrsw(void); 7 | void sdrhw(void); 8 | void sdrrow(char *_row); 9 | void sdrrdbuf(int dq); 10 | void sdrrd(char *startaddr, char *dq); 11 | void sdrrderr(char *count); 12 | void sdrwr(char *startaddr); 13 | 14 | #ifdef CSR_DDRPHY_BASE 15 | void sdrwlon(void); 16 | void sdrwloff(void); 17 | int sdrlevel(void); 18 | #endif 19 | 20 | int memtest_silent(void); 21 | int memtest(void); 22 | int sdrinit(void); 23 | 24 | #endif /* __SDRAM_H */ 25 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/lit.cfg.py: -------------------------------------------------------------------------------- 1 | # All the Lit configuration is handled in the site configs -- this file is only 2 | # left as a canary to catch invocations of Lit that do not go through llvm-lit. 3 | # 4 | # Invocations that go through llvm-lit will automatically use the right Lit 5 | # site configuration inside the build directory. 6 | 7 | lit_config.fatal( 8 | "You seem to be running Lit directly -- you should be running Lit through " 9 | "/bin/llvm-lit, which will ensure that the right Lit configuration " 10 | "file is used.") 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "misoc/cores/lm32/verilog/submodule"] 2 | path = misoc/cores/lm32/verilog/submodule 3 | url = https://github.com/m-labs/lm32.git 4 | [submodule "misoc/cores/mor1kx/verilog"] 5 | path = misoc/cores/mor1kx/verilog 6 | url = https://github.com/m-labs/mor1kx.git 7 | [submodule "misoc/software/compiler_rt"] 8 | path = misoc/software/compiler_rt 9 | url = https://github.com/llvm-mirror/compiler-rt.git 10 | [submodule "misoc/cores/vexriscv/verilog"] 11 | path = misoc/cores/vexriscv/verilog 12 | url = https://github.com/m-labs/VexRiscv-verilog.git 13 | -------------------------------------------------------------------------------- /misoc/software/include/base/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONSOLE_H 2 | #define __CONSOLE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef void (*console_write_hook)(char); 9 | typedef char (*console_read_hook)(void); 10 | typedef int (*console_read_nonblock_hook)(void); 11 | 12 | void console_set_write_hook(console_write_hook h); 13 | void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn); 14 | 15 | char readchar(void); 16 | int readchar_nonblock(void); 17 | 18 | void putsnonl(const char *s); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* __CONSOLE_H */ 25 | -------------------------------------------------------------------------------- /misoc/software/include/base/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENDIAN_H 2 | #define __ENDIAN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __LITTLE_ENDIAN 0 9 | #define __BIG_ENDIAN 1 10 | #define __BYTE_ORDER __BIG_ENDIAN 11 | 12 | static inline unsigned int le32toh(unsigned int val) 13 | { 14 | return (val & 0xff) << 24 | 15 | (val & 0xff00) << 8 | 16 | (val & 0xff0000) >> 8 | 17 | (val & 0xff000000) >> 24; 18 | } 19 | 20 | static inline unsigned short le16toh(unsigned short val) 21 | { 22 | return (val & 0xff) << 8 | 23 | (val & 0xff00) >> 8; 24 | } 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* __ENDIAN_H */ 31 | -------------------------------------------------------------------------------- /misoc/software/include/dyld/link.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINK_H 2 | #define __LINK_H 3 | 4 | #include 5 | #include 6 | 7 | #define ElfW(type) Elf32_##type 8 | 9 | struct dl_phdr_info { 10 | ElfW(Addr) dlpi_addr; 11 | const char *dlpi_name; 12 | const ElfW(Phdr) *dlpi_phdr; 13 | ElfW(Half) dlpi_phnum; 14 | }; 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *, 21 | size_t, void *), 22 | void *__data); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* __LINK_H */ 29 | -------------------------------------------------------------------------------- /misoc/software/bios/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | LDFLAGS += -L../libcompiler-rt \ 5 | -L../libbase \ 6 | -L../libnet 7 | 8 | all:: bios.bin 9 | 10 | %.bin: %.elf 11 | $(objcopy) -O binary 12 | ifeq ($(CPU_ENDIANNESS),LITTLE) 13 | $(MSCIMG) $@ --little 14 | else 15 | $(MSCIMG) $@ 16 | endif 17 | 18 | bios.elf: ../libbase/crt0-$(CPU).o isr.o sdram.o main.o boot-helper-$(CPU).o boot.o 19 | $(link) -T $(BIOS_DIRECTORY)/bios.ld \ 20 | -lnet -lbase-nofloat -lcompiler-rt 21 | 22 | %.o: $(BIOS_DIRECTORY)/%.S 23 | $(assemble) 24 | 25 | %.o: $(BIOS_DIRECTORY)/%.c 26 | $(compile) 27 | -------------------------------------------------------------------------------- /misoc/software/libbase/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void time_init(void) 5 | { 6 | int t; 7 | 8 | timer0_en_write(0); 9 | t = 2*CONFIG_CLOCK_FREQUENCY; 10 | timer0_reload_write(t); 11 | timer0_load_write(t); 12 | timer0_en_write(1); 13 | } 14 | 15 | int elapsed(int *last_event, int period) 16 | { 17 | int t, dt; 18 | 19 | timer0_update_value_write(1); 20 | t = timer0_reload_read() - timer0_value_read(); 21 | if(period < 0) { 22 | *last_event = t; 23 | return 1; 24 | } 25 | dt = t - *last_event; 26 | if(dt < 0) 27 | dt += timer0_reload_read(); 28 | if((dt > period) || (dt < 0)) { 29 | *last_event = t; 30 | return 1; 31 | } else 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /misoc/software/include/base/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDARG_H 2 | #define __STDARG_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define va_start(v, l) __builtin_va_start((v), l) 11 | #define va_arg(ap, type) __builtin_va_arg((ap), type) 12 | #define va_copy(aq, ap) __builtin_va_copy((aq), (ap)) 13 | #define va_end(ap) __builtin_va_end(ap) 14 | #define va_list __builtin_va_list 15 | 16 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); 17 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); 18 | int vsprintf(char *buf, const char *fmt, va_list args); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* __STDARG_H */ 25 | -------------------------------------------------------------------------------- /misoc/software/include/base/pthread.h: -------------------------------------------------------------------------------- 1 | #ifndef __PTHREAD_H 2 | #define __PTHREAD_H 3 | 4 | typedef int pthread_rwlock_t; 5 | 6 | #define PTHREAD_RWLOCK_INITIALIZER 0 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | inline int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) 13 | { return 0; } 14 | inline int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) 15 | { return 0; } 16 | inline int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) 17 | { return 0; } 18 | inline int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) 19 | { return 0; } 20 | int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) 21 | { return 0; } 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* __PTHREAD_H */ 28 | -------------------------------------------------------------------------------- /misoc/software/libbase/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | OBJECTS = libc.o ctype.o strtod.o qsort.o errno.o crc16.o crc32.o 5 | OBJECTS += id.o system.o uart.o console.o time.o spiflash.o exception.o 6 | 7 | all:: crt0-$(CPU).o libbase.a libbase-nofloat.a 8 | 9 | libbase.a: $(OBJECTS) printf.o 10 | $(archive) 11 | 12 | libbase-nofloat.a: $(OBJECTS) printf-nofloat.o 13 | $(archive) 14 | 15 | %.o: $(LIBBASE_DIRECTORY)/%.S 16 | $(assemble) 17 | 18 | %.o: $(LIBBASE_DIRECTORY)/%.c 19 | $(compile) 20 | 21 | %.o: $(LIBPRINTF_DIRECTORY)/%.c 22 | $(compile) 23 | 24 | printf-nofloat.o: $(LIBPRINTF_DIRECTORY)/printf.c 25 | $(compile) -D_PRINTF_NO_FLOAT 26 | -------------------------------------------------------------------------------- /misoc/software/libm/s_matherr.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_matherr.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | #include "fdlibm.h" 15 | 16 | #ifdef __STDC__ 17 | int matherr(struct exception *x) 18 | #else 19 | int matherr(x) 20 | struct exception *x; 21 | #endif 22 | { 23 | int n=0; 24 | if(x->arg1!=x->arg1) return 0; 25 | return n; 26 | } 27 | -------------------------------------------------------------------------------- /misoc/cores/identifier.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.interconnect.csr import * 4 | 5 | 6 | class Identifier(Module, AutoCSR): 7 | def __init__(self, ident): 8 | contents = list(ident.encode()) 9 | l = len(contents) 10 | if l > 255: 11 | raise ValueError("Identifier string must be 255 characters or less") 12 | contents.insert(0, l) 13 | 14 | self.address = CSRStorage(8) 15 | self.data = CSRStatus(8) 16 | 17 | mem = Memory(8, len(contents), init=contents) 18 | port = mem.get_port() 19 | self.specials += mem, port 20 | self.comb += [ 21 | port.adr.eq(self.address.storage), 22 | self.data.status.eq(port.dat_r) 23 | ] 24 | -------------------------------------------------------------------------------- /misoc/software/include/dyld/dlfcn.h: -------------------------------------------------------------------------------- 1 | #ifndef __DLFCN_H 2 | #define __DLFCN_H 3 | 4 | typedef struct 5 | { 6 | const char *dli_fname; /* File name of defining object. */ 7 | void *dli_fbase; /* Load address of that object. */ 8 | const char *dli_sname; /* Name of nearest symbol. */ 9 | void *dli_saddr; /* Exact value of nearest symbol. */ 10 | } Dl_info; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /* Fill in *INFO with the following information about ADDRESS. 17 | Returns 0 iff no shared object's segments contain that address. */ 18 | extern int dladdr (const void *__address, Dl_info *__info); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* __DLFCN_H */ 25 | -------------------------------------------------------------------------------- /misoc/software/libm/s_fabs.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_fabs.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * fabs(x) returns the absolute value of x. 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double fabs(double x) 22 | #else 23 | double fabs(x) 24 | double x; 25 | #endif 26 | { 27 | __HI(x) &= 0x7fffffff; 28 | return x; 29 | } 30 | -------------------------------------------------------------------------------- /misoc/software/include/net/microudp.h: -------------------------------------------------------------------------------- 1 | #ifndef __MICROUDP_H 2 | #define __MICROUDP_H 3 | 4 | #define IPTOINT(a, b, c, d) ((a << 24)|(b << 16)|(c << 8)|d) 5 | 6 | #define MICROUDP_BUFSIZE (5*1532) 7 | 8 | typedef void (*udp_callback)(unsigned int src_ip, unsigned short src_port, unsigned short dst_port, void *data, unsigned int length); 9 | 10 | void microudp_start(const unsigned char *macaddr, unsigned int ip); 11 | int microudp_arp_resolve(unsigned int ip); 12 | void *microudp_get_tx_buffer(void); 13 | int microudp_send(unsigned short src_port, unsigned short dst_port, unsigned int length); 14 | void microudp_set_callback(udp_callback callback); 15 | void microudp_service(void); 16 | 17 | void eth_init(void); 18 | void eth_mode(void); 19 | 20 | #endif /* __MICROUDP_H */ 21 | -------------------------------------------------------------------------------- /misoc/software/include/dyld/dyld.h: -------------------------------------------------------------------------------- 1 | #ifndef __DYLD_H 2 | #define __DYLD_H 3 | 4 | #include 5 | 6 | struct dyld_info { 7 | Elf32_Addr base; 8 | const char *strtab; 9 | const Elf32_Sym *symtab; 10 | struct { 11 | Elf32_Word nbucket; 12 | Elf32_Word nchain; 13 | const Elf32_Word *bucket; 14 | const Elf32_Word *chain; 15 | } hash; 16 | }; 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | int dyld_load(const void *shlib, Elf32_Addr base, 23 | Elf32_Addr (*resolve)(void *, const char *), void *resolve_data, 24 | struct dyld_info *info, const char **error_out); 25 | void *dyld_lookup(const char *symbol, struct dyld_info *info); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* __DYLD_H */ 32 | -------------------------------------------------------------------------------- /misoc/software/bios/sfl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SFL_H 2 | #define __SFL_H 3 | 4 | #define SFL_MAGIC_LEN 14 5 | #define SFL_MAGIC_REQ "sL5DdSMmkekro\n" 6 | #define SFL_MAGIC_ACK "z6IHG7cYDID6o\n" 7 | 8 | struct sfl_frame { 9 | unsigned char length; 10 | unsigned char crc[2]; 11 | unsigned char cmd; 12 | unsigned char payload[255]; 13 | } __attribute__((packed)); 14 | 15 | /* General commands */ 16 | #define SFL_CMD_ABORT 0x00 17 | #define SFL_CMD_LOAD 0x01 18 | #define SFL_CMD_JUMP 0x02 19 | 20 | /* Linux-specific commands */ 21 | #define SFL_CMD_CMDLINE 0x03 22 | #define SFL_CMD_INITRDSTART 0x04 23 | #define SFL_CMD_INITRDEND 0x05 24 | 25 | /* Replies */ 26 | #define SFL_ACK_SUCCESS 'K' 27 | #define SFL_ACK_CRCERROR 'C' 28 | #define SFL_ACK_UNKNOWN 'U' 29 | #define SFL_ACK_ERROR 'E' 30 | 31 | #endif /* __SFL_H */ 32 | -------------------------------------------------------------------------------- /misoc/software/libm/s_finite.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_finite.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * finite(x) returns 1 is x is finite, else 0; 16 | * no branching! 17 | */ 18 | 19 | #include "fdlibm.h" 20 | 21 | #ifdef __STDC__ 22 | int finite(double x) 23 | #else 24 | int finite(x) 25 | double x; 26 | #endif 27 | { 28 | int hx; 29 | hx = __HI(x); 30 | return (unsigned)((hx&0x7fffffff)-0x7ff00000)>>31; 31 | } 32 | -------------------------------------------------------------------------------- /misoc/software/libm/s_ldexp.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_ldexp.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | #include "fdlibm.h" 15 | #include 16 | 17 | #ifdef __STDC__ 18 | double ldexp(double value, int exp) 19 | #else 20 | double ldexp(value, exp) 21 | double value; int exp; 22 | #endif 23 | { 24 | if(!finite(value)||value==0.0) return value; 25 | value = scalbn(value,exp); 26 | if(!finite(value)||value==0.0) errno = ERANGE; 27 | return value; 28 | } 29 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/libunwind_02.pass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define EXPECTED_NUM_FRAMES 50 6 | #define NUM_FRAMES_UPPER_BOUND 100 7 | 8 | _Unwind_Reason_Code callback(_Unwind_Context *context, void *cnt) { 9 | (void)context; 10 | int *i = (int *)cnt; 11 | ++*i; 12 | if (*i > NUM_FRAMES_UPPER_BOUND) { 13 | abort(); 14 | } 15 | return _URC_NO_REASON; 16 | } 17 | 18 | void test_backtrace() { 19 | int n = 0; 20 | _Unwind_Backtrace(&callback, &n); 21 | if (n < EXPECTED_NUM_FRAMES) { 22 | abort(); 23 | } 24 | } 25 | 26 | int test(int i) { 27 | if (i == 0) { 28 | test_backtrace(); 29 | return 0; 30 | } else { 31 | return i + test(i - 1); 32 | } 33 | } 34 | 35 | int main(int, char**) { 36 | int total = test(50); 37 | assert(total == 1275); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/libm/e_gamma.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_gamma.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* __ieee754_gamma(x) 16 | * Return the logarithm of the Gamma function of x. 17 | * 18 | * Method: call __ieee754_gamma_r 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | extern int signgam; 24 | 25 | #ifdef __STDC__ 26 | double __ieee754_gamma(double x) 27 | #else 28 | double __ieee754_gamma(x) 29 | double x; 30 | #endif 31 | { 32 | return __ieee754_gamma_r(x,&signgam); 33 | } 34 | -------------------------------------------------------------------------------- /misoc/software/libm/s_significand.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_significand.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * significand(x) computes just 16 | * scalb(x, (double) -ilogb(x)), 17 | * for exercising the fraction-part(F) IEEE 754-1985 test vector. 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | #ifdef __STDC__ 23 | double significand(double x) 24 | #else 25 | double significand(x) 26 | double x; 27 | #endif 28 | { 29 | return __ieee754_scalb(x,(double) -ilogb(x)); 30 | } 31 | -------------------------------------------------------------------------------- /misoc/software/libm/e_lgamma.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_lgamma.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* __ieee754_lgamma(x) 16 | * Return the logarithm of the Gamma function of x. 17 | * 18 | * Method: call __ieee754_lgamma_r 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | extern int signgam; 24 | 25 | #ifdef __STDC__ 26 | double __ieee754_lgamma(double x) 27 | #else 28 | double __ieee754_lgamma(x) 29 | double x; 30 | #endif 31 | { 32 | return __ieee754_lgamma_r(x,&signgam); 33 | } 34 | -------------------------------------------------------------------------------- /misoc/software/libm/s_isnan.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_isnan.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * isnan(x) returns 1 is x is nan, else 0; 16 | * no branching! 17 | */ 18 | 19 | #include "fdlibm.h" 20 | 21 | #ifdef __STDC__ 22 | int isnan(double x) 23 | #else 24 | int isnan(x) 25 | double x; 26 | #endif 27 | { 28 | int hx,lx; 29 | hx = (__HI(x)&0x7fffffff); 30 | lx = __LO(x); 31 | hx |= (unsigned)(lx|(-lx))>>31; 32 | hx = 0x7ff00000 - hx; 33 | return ((unsigned)(hx))>>31; 34 | } 35 | -------------------------------------------------------------------------------- /misoc/software/libm/s_copysign.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_copysign.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * copysign(double x, double y) 16 | * copysign(x,y) returns a value with the magnitude of x and 17 | * with the sign bit of y. 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | #ifdef __STDC__ 23 | double copysign(double x, double y) 24 | #else 25 | double copysign(x,y) 26 | double x,y; 27 | #endif 28 | { 29 | __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000); 30 | return x; 31 | } 32 | -------------------------------------------------------------------------------- /misoc/software/libcompiler-rt/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | CFLAGS += -D_YUGA_LITTLE_ENDIAN=0 -D_YUGA_BIG_ENDIAN=1 -Wno-missing-prototypes 5 | 6 | OBJECTS = divsi3.o modsi3.o comparesf2.o comparedf2.o negsf2.o negdf2.o \ 7 | addsf3.o subsf3.o mulsf3.o divsf3.o lshrdi3.o muldi3.o divdi3.o ashldi3.o ashrdi3.o \ 8 | udivmoddi4.o floatsisf.o floatunsisf.o fixsfsi.o fixdfdi.o fixunssfsi.o fixunsdfdi.o \ 9 | adddf3.o subdf3.o muldf3.o divdf3.o floatsidf.o floatunsidf.o floatdidf.o fixdfsi.o \ 10 | fixunsdfsi.o clzsi2.o ctzsi2.o udivdi3.o umoddi3.o moddi3.o ucmpdi2.o \ 11 | powidf2.o powisf2.o mulodi4.o floatundisf.o floatundidf.o extendsfdf2.o truncdfsf2.o 12 | 13 | all:: libcompiler-rt.a 14 | 15 | libcompiler-rt.a: $(OBJECTS) 16 | $(archive) 17 | 18 | %.o: $(MISOC_DIRECTORY)/software/compiler_rt/lib/builtins/%.c 19 | $(compile) 20 | -------------------------------------------------------------------------------- /misoc/software/include/base/stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDINT_H 2 | #define __STDINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef int intptr_t; 9 | typedef unsigned int uintptr_t; 10 | 11 | typedef unsigned long long uint64_t; 12 | typedef unsigned int uint32_t; 13 | typedef unsigned short uint16_t; 14 | typedef unsigned char uint8_t; 15 | 16 | typedef long long int64_t; 17 | typedef int int32_t; 18 | typedef short int16_t; 19 | typedef char int8_t; 20 | 21 | #define __int_c_join(a, b) a ## b 22 | #define __int_c(v, suffix) __int_c_join(v, suffix) 23 | #define __uint_c(v, suffix) __int_c_join(v##U, suffix) 24 | 25 | #define INT64_C(v) __int_c(v, LL) 26 | #define UINT64_C(v) __uint_c(v, LL) 27 | #define INT32_C(v) v 28 | #define UINT32_C(v) v##U 29 | 30 | #define UINT32_MAX (4294967295U) 31 | #define UINTPTR_MAX UINT32_MAX 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* __STDINT_H */ 38 | -------------------------------------------------------------------------------- /misoc/software/libm/e_gamma_r.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_gamma_r.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* __ieee754_gamma_r(x, signgamp) 16 | * Reentrant version of the logarithm of the Gamma function 17 | * with user provide pointer for the sign of Gamma(x). 18 | * 19 | * Method: See __ieee754_lgamma_r 20 | */ 21 | 22 | #include "fdlibm.h" 23 | 24 | #ifdef __STDC__ 25 | double __ieee754_gamma_r(double x, int *signgamp) 26 | #else 27 | double __ieee754_gamma_r(x,signgamp) 28 | double x; int *signgamp; 29 | #endif 30 | { 31 | return __ieee754_lgamma_r(x,signgamp); 32 | } 33 | -------------------------------------------------------------------------------- /misoc/software/libm/s_lib_version.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_lib_version.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * MACRO for standards 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | /* 21 | * define and initialize _LIB_VERSION 22 | */ 23 | #ifdef _POSIX_MODE 24 | _LIB_VERSION_TYPE _LIB_VERSION = _POSIX_; 25 | #else 26 | #ifdef _XOPEN_MODE 27 | _LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_; 28 | #else 29 | #ifdef _SVID3_MODE 30 | _LIB_VERSION_TYPE _LIB_VERSION = _SVID_; 31 | #else /* default _IEEE_MODE */ 32 | _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_; 33 | #endif 34 | #endif 35 | #endif 36 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/signal_frame.pass.cpp: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | // Ensure that functions marked as signal frames are reported as such. 11 | 12 | // UNSUPPORTED: libunwind-arm-ehabi 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | void test() { 19 | asm(".cfi_signal_frame"); 20 | unw_cursor_t cursor; 21 | unw_context_t uc; 22 | unw_getcontext(&uc); 23 | unw_init_local(&cursor, &uc); 24 | assert(unw_step(&cursor) > 0); 25 | assert(unw_is_signal_frame(&cursor)); 26 | } 27 | 28 | int main(int, char**) { 29 | test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /misoc/software/libm/w_sqrt.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_sqrt.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper sqrt(x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double sqrt(double x) /* wrapper sqrt */ 22 | #else 23 | double sqrt(x) /* wrapper sqrt */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_sqrt(x); 29 | #else 30 | double z; 31 | z = __ieee754_sqrt(x); 32 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 33 | if(x<0.0) { 34 | return __kernel_standard(x,x,26); /* sqrt(negative) */ 35 | } else 36 | return z; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/phy/__init__.py: -------------------------------------------------------------------------------- 1 | from misoc.cores.liteeth_mini.common import * 2 | 3 | 4 | def LiteEthPHY(clock_pads, pads, clk_freq=None, **kwargs): 5 | # Autodetect PHY 6 | if hasattr(clock_pads, "gtx") and len(pads.tx_data) == 8: 7 | if hasattr(clock_pads, "tx"): 8 | # This is a 10/100/1G PHY 9 | from misoc.cores.liteeth_mini.phy.gmii_mii import LiteEthPHYGMIIMII 10 | return LiteEthPHYGMIIMII(clock_pads, pads, clk_freq=clk_freq, **kwargs) 11 | else: 12 | # This is a pure 1G PHY 13 | from misoc.cores.liteeth_mini.phy.gmii import LiteEthPHYGMII 14 | return LiteEthPHYGMII(clock_pads, pads, **kwargs) 15 | elif len(pads.tx_data) == 4: 16 | # This is a MII PHY 17 | from misoc.cores.liteeth_mini.phy.mii import LiteEthPHYMII 18 | return LiteEthPHYMII(clock_pads, pads, **kwargs) 19 | else: 20 | raise ValueError("Unable to autodetect PHY from platform file, use direct instantiation") 21 | -------------------------------------------------------------------------------- /misoc/software/libm/w_sinh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_sinh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper sinh(x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double sinh(double x) /* wrapper sinh */ 22 | #else 23 | double sinh(x) /* wrapper sinh */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_sinh(x); 29 | #else 30 | double z; 31 | z = __ieee754_sinh(x); 32 | if(_LIB_VERSION == _IEEE_) return z; 33 | if(!finite(z)&&finite(x)) { 34 | return __kernel_standard(x,x,25); /* sinh overflow */ 35 | } else 36 | return z; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /misoc/software/libm/w_acos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_acos.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrap_acos(x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double acos(double x) /* wrapper acos */ 23 | #else 24 | double acos(x) /* wrapper acos */ 25 | double x; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_acos(x); 30 | #else 31 | double z; 32 | z = __ieee754_acos(x); 33 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 34 | if(fabs(x)>1.0) { 35 | return __kernel_standard(x,x,1); /* acos(|x|>1) */ 36 | } else 37 | return z; 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/libm/w_acosh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_acosh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* 16 | * wrapper acosh(x) 17 | */ 18 | 19 | #include "fdlibm.h" 20 | 21 | #ifdef __STDC__ 22 | double acosh(double x) /* wrapper acosh */ 23 | #else 24 | double acosh(x) /* wrapper acosh */ 25 | double x; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_acosh(x); 30 | #else 31 | double z; 32 | z = __ieee754_acosh(x); 33 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 34 | if(x<1.0) { 35 | return __kernel_standard(x,x,29); /* acosh(x<1) */ 36 | } else 37 | return z; 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/libm/w_asin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_asin.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* 16 | * wrapper asin(x) 17 | */ 18 | 19 | 20 | #include "fdlibm.h" 21 | 22 | 23 | #ifdef __STDC__ 24 | double asin(double x) /* wrapper asin */ 25 | #else 26 | double asin(x) /* wrapper asin */ 27 | double x; 28 | #endif 29 | { 30 | #ifdef _IEEE_LIBM 31 | return __ieee754_asin(x); 32 | #else 33 | double z; 34 | z = __ieee754_asin(x); 35 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 36 | if(fabs(x)>1.0) { 37 | return __kernel_standard(x,x,2); /* asin(|x|>1) */ 38 | } else 39 | return z; 40 | #endif 41 | } 42 | -------------------------------------------------------------------------------- /misoc/software/libm/w_cosh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_cosh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper cosh(x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double cosh(double x) /* wrapper cosh */ 22 | #else 23 | double cosh(x) /* wrapper cosh */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_cosh(x); 29 | #else 30 | double z; 31 | z = __ieee754_cosh(x); 32 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 33 | if(fabs(x)>7.10475860073943863426e+02) { 34 | return __kernel_standard(x,x,5); /* cosh overflow */ 35 | } else 36 | return z; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /misoc/software/libm/w_fmod.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_fmod.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper fmod(x,y) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double fmod(double x, double y) /* wrapper fmod */ 23 | #else 24 | double fmod(x,y) /* wrapper fmod */ 25 | double x,y; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_fmod(x,y); 30 | #else 31 | double z; 32 | z = __ieee754_fmod(x,y); 33 | if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z; 34 | if(y==0.0) { 35 | return __kernel_standard(x,y,27); /* fmod(x,0) */ 36 | } else 37 | return z; 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/libm/w_log.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_log.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper log(x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double log(double x) /* wrapper log */ 23 | #else 24 | double log(x) /* wrapper log */ 25 | double x; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_log(x); 30 | #else 31 | double z; 32 | z = __ieee754_log(x); 33 | if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z; 34 | if(x==0.0) 35 | return __kernel_standard(x,x,16); /* log(0) */ 36 | else 37 | return __kernel_standard(x,x,17); /* log(x<0) */ 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/memtest/Makefile: -------------------------------------------------------------------------------- 1 | MSCDIR=../.. 2 | include $(MSCDIR)/software/common.mak 3 | 4 | OBJECTS=isr.o main.o 5 | 6 | all: memtest.bin 7 | 8 | %.bin: %.elf 9 | $(OBJCOPY) -O binary $< $@ 10 | chmod -x $@ 11 | 12 | memtest.elf: $(OBJECTS) libs 13 | 14 | %.elf: 15 | $(LD) $(LDFLAGS) \ 16 | -T $(MSCDIR)/software/libbase/linker-sdram.ld \ 17 | -N -o $@ \ 18 | $(MSCDIR)/software/libbase/crt0-$(CPU).o \ 19 | $(OBJECTS) \ 20 | -L$(MSCDIR)/software/libbase \ 21 | -L$(MSCDIR)/software/libcompiler-rt \ 22 | -lbase -lcompiler-rt 23 | chmod -x $@ 24 | 25 | main.o: main.c 26 | $(compile) 27 | 28 | %.o: %.c 29 | $(compile) 30 | 31 | %.o: %.S 32 | $(assemble) 33 | 34 | libs: 35 | $(MAKE) -C $(MSCDIR)/software/libcompiler-rt 36 | $(MAKE) -C $(MSCDIR)/software/libbase 37 | 38 | load: memtest.bin 39 | $(MAKE) -C $(MSCDIR)/tools 40 | $(MSCDIR)/tools/flterm --port /dev/ttyUSB0 --kernel memtest.bin 41 | 42 | 43 | clean: 44 | $(RM) $(OBJECTS) memtest.elf memtest.bin 45 | $(RM) .*~ *~ 46 | 47 | .PHONY: all main.o clean libs load 48 | -------------------------------------------------------------------------------- /misoc/cores/coaxpress/common.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | char_width = 8 4 | char_layout = [("data", char_width), ("k", char_width // 8)] 5 | 6 | word_width = 32 7 | word_layout = [("data", word_width), ("k", word_width // 8)] 8 | 9 | word_layout_dchar = [ 10 | ("data", word_width), 11 | ("k", word_width // 8), 12 | ("dchar", char_width), 13 | ("dchar_k", char_width // 8), 14 | ] 15 | 16 | 17 | def _K(x, y): 18 | return (y << 5) | x 19 | 20 | 21 | KCode = { 22 | "pak_start": C(_K(27, 7), char_width), 23 | "io_ack": C(_K(28, 6), char_width), 24 | "trig_indic_28_2": C(_K(28, 2), char_width), 25 | "stream_marker": C(_K(28, 3), char_width), 26 | "trig_indic_28_4": C(_K(28, 4), char_width), 27 | "pak_end": C(_K(29, 7), char_width), 28 | "idle_comma": C(_K(28, 5), char_width), 29 | "idle_alignment": C(_K(28, 1), char_width), 30 | } 31 | 32 | 33 | def switch_endianness(s): 34 | assert len(s) % 8 == 0 35 | char = [s[i * 8 : (i + 1) * 8] for i in range(len(s) // 8)] 36 | return Cat(char[::-1]) 37 | -------------------------------------------------------------------------------- /misoc/software/libm/w_hypot.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_hypot.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper hypot(x,y) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double hypot(double x, double y)/* wrapper hypot */ 23 | #else 24 | double hypot(x,y) /* wrapper hypot */ 25 | double x,y; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_hypot(x,y); 30 | #else 31 | double z; 32 | z = __ieee754_hypot(x,y); 33 | if(_LIB_VERSION == _IEEE_) return z; 34 | if((!finite(z))&&finite(x)&&finite(y)) 35 | return __kernel_standard(x,y,4); /* hypot overflow */ 36 | else 37 | return z; 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/alignment.compile.pass.cpp: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | // The Itanium ABI requires that _Unwind_Exception objects are "double-word 11 | // aligned". 12 | 13 | #include 14 | 15 | // EHABI : 8-byte aligned 16 | // itanium: largest supported alignment for the system 17 | #if defined(_LIBUNWIND_ARM_EHABI) 18 | static_assert(alignof(_Unwind_Control_Block) == 8, 19 | "_Unwind_Control_Block must be double-word aligned"); 20 | #else 21 | struct MaxAligned {} __attribute__((__aligned__)); 22 | static_assert(alignof(_Unwind_Exception) == alignof(MaxAligned), 23 | "_Unwind_Exception must be maximally aligned"); 24 | #endif 25 | -------------------------------------------------------------------------------- /misoc/interconnect/wishbone2csr.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | from migen.genlib.misc import timeline 3 | 4 | from misoc.interconnect import csr_bus, wishbone 5 | 6 | 7 | class WB2CSR(Module): 8 | def __init__(self, bus_wishbone=None, bus_csr=None, wb_bus_dw=32): 9 | if bus_wishbone is None: 10 | bus_wishbone = wishbone.Interface(data_width=wb_bus_dw, adr_width=32-log2_int(wb_bus_dw//8)) 11 | self.wishbone = bus_wishbone 12 | if bus_csr is None: 13 | bus_csr = csr_bus.Interface() 14 | self.csr = bus_csr 15 | 16 | ### 17 | 18 | self.sync += [ 19 | self.csr.we.eq(0), 20 | self.csr.dat_w.eq(self.wishbone.dat_w), 21 | self.csr.adr.eq(self.wishbone.adr), 22 | self.wishbone.dat_r.eq(self.csr.dat_r) 23 | ] 24 | self.sync += timeline(self.wishbone.cyc & self.wishbone.stb, [ 25 | (1, [self.csr.we.eq(self.wishbone.we)]), 26 | (2, [self.wishbone.ack.eq(1)]), 27 | (3, [self.wishbone.ack.eq(0)]) 28 | ]) 29 | -------------------------------------------------------------------------------- /misoc/software/libm/s_logb.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_logb.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * double logb(x) 16 | * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. 17 | * Use ilogb instead. 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | #ifdef __STDC__ 23 | double logb(double x) 24 | #else 25 | double logb(x) 26 | double x; 27 | #endif 28 | { 29 | int lx,ix; 30 | ix = (__HI(x))&0x7fffffff; /* high |x| */ 31 | lx = __LO(x); /* low x */ 32 | if((ix|lx)==0) return -1.0/fabs(x); 33 | if(ix>=0x7ff00000) return x*x; 34 | if((ix>>=20)==0) /* IEEE 754 logb */ 35 | return -1022.0; 36 | else 37 | return (double) (ix-1023); 38 | } 39 | -------------------------------------------------------------------------------- /misoc/software/libm/w_atan2.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_atan2.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* 16 | * wrapper atan2(y,x) 17 | */ 18 | 19 | #include "fdlibm.h" 20 | 21 | 22 | #ifdef __STDC__ 23 | double atan2(double y, double x) /* wrapper atan2 */ 24 | #else 25 | double atan2(y,x) /* wrapper atan2 */ 26 | double y,x; 27 | #endif 28 | { 29 | #ifdef _IEEE_LIBM 30 | return __ieee754_atan2(y,x); 31 | #else 32 | double z; 33 | z = __ieee754_atan2(y,x); 34 | if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z; 35 | if(x==0.0&&y==0.0) { 36 | return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */ 37 | } else 38 | return z; 39 | #endif 40 | } 41 | -------------------------------------------------------------------------------- /misoc/software/libm/w_remainder.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_remainder.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper remainder(x,p) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double remainder(double x, double y) /* wrapper remainder */ 22 | #else 23 | double remainder(x,y) /* wrapper remainder */ 24 | double x,y; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_remainder(x,y); 29 | #else 30 | double z; 31 | z = __ieee754_remainder(x,y); 32 | if(_LIB_VERSION == _IEEE_ || isnan(y)) return z; 33 | if(y==0.0) 34 | return __kernel_standard(x,y,28); /* remainder(x,0) */ 35 | else 36 | return z; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /misoc/software/libm/w_log10.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_log10.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper log10(X) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double log10(double x) /* wrapper log10 */ 23 | #else 24 | double log10(x) /* wrapper log10 */ 25 | double x; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_log10(x); 30 | #else 31 | double z; 32 | z = __ieee754_log10(x); 33 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 34 | if(x<=0.0) { 35 | if(x==0.0) 36 | return __kernel_standard(x,x,18); /* log10(0) */ 37 | else 38 | return __kernel_standard(x,x,19); /* log10(x<0) */ 39 | } else 40 | return z; 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /misoc/software/libm/w_atanh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_atanh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | /* 14 | * wrapper atanh(x) 15 | */ 16 | 17 | #include "fdlibm.h" 18 | 19 | 20 | #ifdef __STDC__ 21 | double atanh(double x) /* wrapper atanh */ 22 | #else 23 | double atanh(x) /* wrapper atanh */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_atanh(x); 29 | #else 30 | double z,y; 31 | z = __ieee754_atanh(x); 32 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 33 | y = fabs(x); 34 | if(y>=1.0) { 35 | if(y>1.0) 36 | return __kernel_standard(x,x,30); /* atanh(|x|>1) */ 37 | else 38 | return __kernel_standard(x,x,31); /* atanh(|x|==1) */ 39 | } else 40 | return z; 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /misoc/cores/timer.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.interconnect.csr import * 4 | from misoc.interconnect.csr_eventmanager import * 5 | 6 | 7 | class Timer(Module, AutoCSR): 8 | def __init__(self, width=64): 9 | self._load = CSRStorage(width) 10 | self._reload = CSRStorage(width) 11 | self._en = CSRStorage() 12 | self._update_value = CSR() 13 | self._value = CSRStatus(width) 14 | 15 | self.submodules.ev = EventManager() 16 | self.ev.zero = EventSourceProcess() 17 | self.ev.finalize() 18 | 19 | ### 20 | 21 | value = Signal(width) 22 | self.sync += [ 23 | If(self._en.storage, 24 | If(value == 0, 25 | # set reload to 0 to disable reloading 26 | value.eq(self._reload.storage) 27 | ).Else( 28 | value.eq(value - 1) 29 | ) 30 | ).Else( 31 | value.eq(self._load.storage) 32 | ), 33 | If(self._update_value.re, self._value.status.eq(value)) 34 | ] 35 | self.comb += self.ev.zero.trigger.eq(value != 0) 36 | -------------------------------------------------------------------------------- /misoc/software/include/hw/flags.h: -------------------------------------------------------------------------------- 1 | #ifndef __HW_FLAGS_H 2 | #define __HW_FLAGS_H 3 | 4 | #define UART_EV_TX 0x1 5 | #define UART_EV_RX 0x2 6 | 7 | #define DFII_CONTROL_SEL 0x01 8 | #define DFII_CONTROL_CKE 0x02 9 | #define DFII_CONTROL_ODT 0x04 10 | #define DFII_CONTROL_RESET_N 0x08 11 | 12 | #define DFII_COMMAND_CS 0x01 13 | #define DFII_COMMAND_WE 0x02 14 | #define DFII_COMMAND_CAS 0x04 15 | #define DFII_COMMAND_RAS 0x08 16 | #define DFII_COMMAND_WRDATA 0x10 17 | #define DFII_COMMAND_RDDATA 0x20 18 | 19 | #define ETHMAC_EV_SRAM_WRITER 0x1 20 | #define ETHMAC_EV_SRAM_READER 0x1 21 | 22 | #define CLKGEN_STATUS_BUSY 0x1 23 | #define CLKGEN_STATUS_PROGDONE 0x2 24 | #define CLKGEN_STATUS_LOCKED 0x4 25 | 26 | #define DVISAMPLER_TOO_LATE 0x1 27 | #define DVISAMPLER_TOO_EARLY 0x2 28 | 29 | #define DVISAMPLER_DELAY_MASTER_CAL 0x01 30 | #define DVISAMPLER_DELAY_MASTER_RST 0x02 31 | #define DVISAMPLER_DELAY_SLAVE_CAL 0x04 32 | #define DVISAMPLER_DELAY_SLAVE_RST 0x08 33 | #define DVISAMPLER_DELAY_INC 0x10 34 | #define DVISAMPLER_DELAY_DEC 0x20 35 | 36 | #define DVISAMPLER_SLOT_EMPTY 0 37 | #define DVISAMPLER_SLOT_LOADED 1 38 | #define DVISAMPLER_SLOT_PENDING 2 39 | 40 | #endif /* __HW_FLAGS_H */ 41 | -------------------------------------------------------------------------------- /misoc/software/libbase/linker-sdram.ld: -------------------------------------------------------------------------------- 1 | INCLUDE generated/output_format.ld 2 | ENTRY(_start) 3 | 4 | __DYNAMIC = 0; 5 | 6 | INCLUDE generated/regions.ld 7 | 8 | SECTIONS 9 | { 10 | .text : 11 | { 12 | _ftext = .; 13 | *(.text .stub .text.* .gnu.linkonce.t.*) 14 | _etext = .; 15 | } > main_ram 16 | 17 | .got : 18 | { 19 | _GLOBAL_OFFSET_TABLE_ = .; 20 | *(.got) 21 | } > main_ram 22 | 23 | .got.plt : 24 | { 25 | *(.got.plt) 26 | } > main_ram 27 | 28 | .rodata : 29 | { 30 | . = ALIGN(4); 31 | _frodata = .; 32 | *(.rodata .rodata.* .gnu.linkonce.r.*) 33 | *(.rodata1) 34 | _erodata = .; 35 | } > main_ram 36 | 37 | .data : 38 | { 39 | . = ALIGN(4); 40 | _fdata = .; 41 | *(.data .data.* .gnu.linkonce.d.*) 42 | *(.data1) 43 | *(.sdata .sdata.* .gnu.linkonce.s.*) 44 | _edata = .; 45 | } > main_ram 46 | 47 | .bss : 48 | { 49 | . = ALIGN(4); 50 | _fbss = .; 51 | *(.dynsbss) 52 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 53 | *(.scommon) 54 | *(.dynbss) 55 | *(.bss .bss.* .gnu.linkonce.b.*) 56 | *(COMMON) 57 | . = ALIGN(4); 58 | _ebss = .; 59 | . = ALIGN(8); 60 | _heapstart = .; 61 | } > main_ram 62 | } 63 | 64 | PROVIDE(_fstack = ORIGIN(main_ram) + LENGTH(main_ram) - 4); 65 | -------------------------------------------------------------------------------- /misoc/software/libm/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | COMMONFLAGS += -I$(MISOC_DIRECTORY)/software/include/fdlibm \ 5 | -D_IEEE_LIBM 6 | 7 | OBJECTS = k_standard.o k_rem_pio2.o \ 8 | k_cos.o k_sin.o k_tan.o \ 9 | e_acos.o e_acosh.o e_asin.o e_atan2.o \ 10 | e_atanh.o e_cosh.o e_exp.o e_fmod.o \ 11 | e_gamma.o e_gamma_r.o e_hypot.o e_j0.o \ 12 | e_j1.o e_jn.o e_lgamma.o e_lgamma_r.o \ 13 | e_log.o e_log10.o e_pow.o e_rem_pio2.o e_remainder.o \ 14 | e_scalb.o e_sinh.o e_sqrt.o \ 15 | w_acos.o w_acosh.o w_asin.o w_atan2.o \ 16 | w_atanh.o w_cosh.o w_exp.o w_fmod.o \ 17 | w_gamma.o w_gamma_r.o w_hypot.o w_j0.o \ 18 | w_j1.o w_jn.o w_lgamma.o w_lgamma_r.o \ 19 | w_log.o w_log10.o w_pow.o w_remainder.o \ 20 | w_scalb.o w_sinh.o w_sqrt.o \ 21 | s_asinh.o s_atan.o s_cbrt.o s_ceil.o s_copysign.o \ 22 | s_cos.o s_erf.o s_expm1.o s_fabs.o s_finite.o s_floor.o \ 23 | s_frexp.o s_ilogb.o s_isnan.o s_ldexp.o s_lib_version.o \ 24 | s_log1p.o s_logb.o s_matherr.o s_modf.o s_nextafter.o \ 25 | s_rint.o s_scalbn.o s_signgam.o s_significand.o s_sin.o \ 26 | s_tan.o s_tanh.o 27 | 28 | all:: libm.a 29 | 30 | libm.a: $(OBJECTS) 31 | $(archive) 32 | 33 | %.o: $(LIBM_DIRECTORY)/%.c 34 | $(compile) 35 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/mac/gap.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | from migen import * 4 | from migen.genlib.fsm import * 5 | 6 | from misoc.interconnect import stream 7 | from misoc.cores.liteeth_mini.common import eth_phy_layout, eth_interpacket_gap 8 | 9 | 10 | class LiteEthMACGap(Module): 11 | def __init__(self): 12 | self.sink = sink = stream.Endpoint(eth_phy_layout(8)) 13 | self.source = source = stream.Endpoint(eth_phy_layout(8)) 14 | 15 | # # # 16 | 17 | counter = Signal(max=eth_interpacket_gap) 18 | counter_reset = Signal() 19 | counter_ce = Signal() 20 | self.sync += \ 21 | If(counter_reset, 22 | counter.eq(0) 23 | ).Elif(counter_ce, 24 | counter.eq(counter + 1) 25 | ) 26 | 27 | self.submodules.fsm = fsm = FSM(reset_state="COPY") 28 | fsm.act("COPY", 29 | counter_reset.eq(1), 30 | sink.connect(source), 31 | If(sink.stb & sink.eop & sink.ack, 32 | NextState("GAP") 33 | ) 34 | ) 35 | fsm.act("GAP", 36 | counter_ce.eq(1), 37 | If(counter == eth_interpacket_gap - 1, 38 | NextState("COPY") 39 | ) 40 | ) 41 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/mac/last_be.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.interconnect import stream 4 | from misoc.cores.liteeth_mini.common import eth_phy_layout 5 | 6 | 7 | class LiteEthMACTXLastBE(Module): 8 | def __init__(self): 9 | self.sink = sink = stream.Endpoint(eth_phy_layout(8)) 10 | self.source = source = stream.Endpoint(eth_phy_layout(8)) 11 | 12 | # # # 13 | 14 | ongoing = Signal(reset=1) 15 | self.sync += \ 16 | If(sink.stb & sink.ack, 17 | If(sink.eop, 18 | ongoing.eq(1) 19 | ).Elif(sink.last_be, 20 | ongoing.eq(0) 21 | ) 22 | ) 23 | self.comb += [ 24 | source.stb.eq(sink.stb & ongoing), 25 | source.eop.eq(sink.last_be), 26 | source.data.eq(sink.data), 27 | sink.ack.eq(source.ack) 28 | ] 29 | 30 | 31 | class LiteEthMACRXLastBE(Module): 32 | def __init__(self): 33 | self.sink = sink = stream.Endpoint(eth_phy_layout(8)) 34 | self.source = source = stream.Endpoint(eth_phy_layout(8)) 35 | 36 | # # # 37 | 38 | self.comb += [ 39 | sink.connect(source), 40 | source.last_be.eq(sink.eop) 41 | ] 42 | -------------------------------------------------------------------------------- /misoc/software/libm/w_exp.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_exp.c 1.4 04/04/22 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | /* 14 | * wrapper exp(x) 15 | */ 16 | 17 | #include "fdlibm.h" 18 | 19 | #ifdef __STDC__ 20 | static const double 21 | #else 22 | static double 23 | #endif 24 | o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ 25 | u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ 26 | 27 | #ifdef __STDC__ 28 | double exp(double x) /* wrapper exp */ 29 | #else 30 | double exp(x) /* wrapper exp */ 31 | double x; 32 | #endif 33 | { 34 | #ifdef _IEEE_LIBM 35 | return __ieee754_exp(x); 36 | #else 37 | double z; 38 | z = __ieee754_exp(x); 39 | if(_LIB_VERSION == _IEEE_) return z; 40 | if(finite(x)) { 41 | if(x>o_threshold) 42 | return __kernel_standard(x,x,6); /* exp overflow */ 43 | else if(x0; lx<<=1) ix -=1; 39 | } else { 40 | for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; 41 | } 42 | return ix; 43 | } 44 | else if (hx<0x7ff00000) return (hx>>20)-1023; 45 | else return 0x7fffffff; 46 | } 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | Sending Patches 2 | =============== 3 | 4 | Patches for MiSoC may be sent via GitHub pull requests. Alternatively, if 5 | you prefer using mailing lists, they can also be sent to 6 | the `public mailing list `_ after 7 | `subscribing `_. 8 | 9 | Before sending patches, please read the rest of this guide and make sure your 10 | patch meets the following criteria; 11 | 12 | * Meets style guide requirements listed below. 13 | * Includes a suitable commit message. 14 | 15 | Help 16 | ---- 17 | 18 | If your submission is large and complex and/or you are not sure how to proceed, 19 | feel free to discuss it on the mailing list or IRC (#m-labs on Freenode) 20 | beforehand. 21 | 22 | Style Guide 23 | ----------- 24 | 25 | All code should be compliant with the 26 | `PEP8 style guide `_. 27 | 28 | You can use the `pep8 tool `_ to check 29 | compliance with ``pep8 myfile.py``. 30 | 31 | When modifying existing code **be consistent** with any existing code style. 32 | 33 | License 34 | ======= 35 | 36 | All new contributions should be under the same license as MiSoC. This is a very 37 | permissive two-clause BSD license; see `full license text `_. 38 | -------------------------------------------------------------------------------- /misoc/software/libm/w_gamma.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_gamma.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* double gamma(double x) 16 | * Return the logarithm of the Gamma function of x. 17 | * 18 | * Method: call gamma_r 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | extern int signgam; 24 | 25 | #ifdef __STDC__ 26 | double gamma(double x) 27 | #else 28 | double gamma(x) 29 | double x; 30 | #endif 31 | { 32 | #ifdef _IEEE_LIBM 33 | return __ieee754_gamma_r(x,&signgam); 34 | #else 35 | double y; 36 | y = __ieee754_gamma_r(x,&signgam); 37 | if(_LIB_VERSION == _IEEE_) return y; 38 | if(!finite(y)&&finite(x)) { 39 | if(floor(x)==x&&x<=0.0) 40 | return __kernel_standard(x,x,41); /* gamma pole */ 41 | else 42 | return __kernel_standard(x,x,40); /* gamma overflow */ 43 | } else 44 | return y; 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /misoc/software/libm/w_gamma_r.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_gamma_r.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper double gamma_r(double x, int *signgamp) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double gamma_r(double x, int *signgamp) /* wrapper lgamma_r */ 23 | #else 24 | double gamma_r(x,signgamp) /* wrapper lgamma_r */ 25 | double x; int *signgamp; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_gamma_r(x,signgamp); 30 | #else 31 | double y; 32 | y = __ieee754_gamma_r(x,signgamp); 33 | if(_LIB_VERSION == _IEEE_) return y; 34 | if(!finite(y)&&finite(x)) { 35 | if(floor(x)==x&&x<=0.0) 36 | return __kernel_standard(x,x,41); /* gamma pole */ 37 | else 38 | return __kernel_standard(x,x,40); /* gamma overflow */ 39 | } else 40 | return y; 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /misoc/software/libm/w_lgamma.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_lgamma.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* double lgamma(double x) 16 | * Return the logarithm of the Gamma function of x. 17 | * 18 | * Method: call __ieee754_lgamma_r 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | extern int signgam; 24 | 25 | #ifdef __STDC__ 26 | double lgamma(double x) 27 | #else 28 | double lgamma(x) 29 | double x; 30 | #endif 31 | { 32 | #ifdef _IEEE_LIBM 33 | return __ieee754_lgamma_r(x,&signgam); 34 | #else 35 | double y; 36 | y = __ieee754_lgamma_r(x,&signgam); 37 | if(_LIB_VERSION == _IEEE_) return y; 38 | if(!finite(y)&&finite(x)) { 39 | if(floor(x)==x&&x<=0.0) 40 | return __kernel_standard(x,x,15); /* lgamma pole */ 41 | else 42 | return __kernel_standard(x,x,14); /* lgamma overflow */ 43 | } else 44 | return y; 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /misoc/software/libm/w_lgamma_r.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_lgamma_r.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper double lgamma_r(double x, int *signgamp) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | 21 | #ifdef __STDC__ 22 | double lgamma_r(double x, int *signgamp) /* wrapper lgamma_r */ 23 | #else 24 | double lgamma_r(x,signgamp) /* wrapper lgamma_r */ 25 | double x; int *signgamp; 26 | #endif 27 | { 28 | #ifdef _IEEE_LIBM 29 | return __ieee754_lgamma_r(x,signgamp); 30 | #else 31 | double y; 32 | y = __ieee754_lgamma_r(x,signgamp); 33 | if(_LIB_VERSION == _IEEE_) return y; 34 | if(!finite(y)&&finite(x)) { 35 | if(floor(x)==x&&x<=0.0) 36 | return __kernel_standard(x,x,15); /* lgamma pole */ 37 | else 38 | return __kernel_standard(x,x,14); /* lgamma overflow */ 39 | } else 40 | return y; 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/libunwind_01.pass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void backtrace(int lower_bound) { 5 | unw_context_t context; 6 | unw_getcontext(&context); 7 | 8 | unw_cursor_t cursor; 9 | unw_init_local(&cursor, &context); 10 | 11 | int n = 0; 12 | do { 13 | ++n; 14 | if (n > 100) { 15 | abort(); 16 | } 17 | } while (unw_step(&cursor) > 0); 18 | 19 | if (n < lower_bound) { 20 | abort(); 21 | } 22 | } 23 | 24 | void test1(int i) { 25 | backtrace(i); 26 | } 27 | 28 | void test2(int i, int j) { 29 | backtrace(i); 30 | test1(j); 31 | } 32 | 33 | void test3(int i, int j, int k) { 34 | backtrace(i); 35 | test2(j, k); 36 | } 37 | 38 | void test_no_info() { 39 | unw_context_t context; 40 | unw_getcontext(&context); 41 | 42 | unw_cursor_t cursor; 43 | unw_init_local(&cursor, &context); 44 | 45 | unw_proc_info_t info; 46 | int ret = unw_get_proc_info(&cursor, &info); 47 | if (ret != UNW_ESUCCESS) 48 | abort(); 49 | 50 | // Set the IP to an address clearly outside any function. 51 | unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)0); 52 | 53 | ret = unw_get_proc_info(&cursor, &info); 54 | if (ret != UNW_ENOINFO) 55 | abort(); 56 | } 57 | 58 | int main(int, char**) { 59 | test1(1); 60 | test2(1, 2); 61 | test3(1, 2, 3); 62 | test_no_info(); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /misoc/software/bios/bios.ld: -------------------------------------------------------------------------------- 1 | INCLUDE generated/output_format.ld 2 | ENTRY(_start) 3 | 4 | INCLUDE generated/regions.ld 5 | 6 | SECTIONS 7 | { 8 | .text : 9 | { 10 | _ftext = .; 11 | *crt0*.o(.text) 12 | *(.text .stub .text.* .gnu.linkonce.t.*) 13 | _etext = .; 14 | } > rom 15 | 16 | .rodata : 17 | { 18 | . = ALIGN(4); 19 | _frodata = .; 20 | *(.rodata .rodata.* .gnu.linkonce.r.*) 21 | *(.rodata1) 22 | 23 | /* Make sure the file is aligned on disk as well as in memory; 24 | 1. CRC calculation requires 4-bytes alignment. 25 | 2. The ROM needs to be 8-bytes aligned overall. It is to 26 | convert the binary from big endian to little endian for 27 | little endian CPUs. (e.g. RISC-V). 28 | Solution: Misalign the CRC by exactly 4 bytes */ 29 | FILL(0); 30 | . = ALIGN(8) + 4; 31 | _erodata = .; 32 | } > rom 33 | 34 | .bss : 35 | { 36 | . = ALIGN(4); 37 | _fbss = .; 38 | *(.dynsbss) 39 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 40 | *(.scommon) 41 | *(.dynbss) 42 | *(.bss .bss.* .gnu.linkonce.b.*) 43 | *(COMMON) 44 | . = ALIGN(4); 45 | _ebss = .; 46 | _end = .; 47 | } > sram 48 | 49 | /DISCARD/ : 50 | { 51 | *(.eh_frame) 52 | *(.comment) 53 | *(.data .data.* .gnu.linkonce.d.*) 54 | *(.data1) 55 | *(.sdata .sdata.* .gnu.linkonce.s.*) 56 | } 57 | } 58 | 59 | PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 4); 60 | -------------------------------------------------------------------------------- /misoc/software/libm/e_scalb.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_scalb.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * __ieee754_scalb(x, fn) is provide for 16 | * passing various standard test suite. One 17 | * should use scalbn() instead. 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | #ifdef _SCALB_INT 23 | #ifdef __STDC__ 24 | double __ieee754_scalb(double x, int fn) 25 | #else 26 | double __ieee754_scalb(x,fn) 27 | double x; int fn; 28 | #endif 29 | #else 30 | #ifdef __STDC__ 31 | double __ieee754_scalb(double x, double fn) 32 | #else 33 | double __ieee754_scalb(x,fn) 34 | double x, fn; 35 | #endif 36 | #endif 37 | { 38 | #ifdef _SCALB_INT 39 | return scalbn(x,fn); 40 | #else 41 | if (isnan(x)||isnan(fn)) return x*fn; 42 | if (!finite(fn)) { 43 | if(fn>0.0) return x*fn; 44 | else return x/(-fn); 45 | } 46 | if (rint(fn)!=fn) return (fn-fn)/(fn-fn); 47 | if ( fn > 65000.0) return scalbn(x, 65000); 48 | if (-fn > 65000.0) return scalbn(x,-65000); 49 | return scalbn(x,(int)fn); 50 | #endif 51 | } 52 | -------------------------------------------------------------------------------- /misoc/software/libunwind/Makefile: -------------------------------------------------------------------------------- 1 | include ../include/generated/variables.mak 2 | include $(MISOC_DIRECTORY)/software/common.mak 3 | 4 | COMMONFLAGS += -integrated-as -I. \ 5 | -I$(MISOC_DIRECTORY)/software/include/dyld/ \ 6 | -I$(MISOC_DIRECTORY)/software/unwinder/include/ \ 7 | -I$(LIBUNWIND_DIRECTORY) \ 8 | -D__ELF__ -D__linux__ \ 9 | -D_LIBUNWIND_NO_HEAP -DNDEBUG 10 | 11 | ifeq ($(CPU),or1k) 12 | COMMONFLAGS += -D_LIBUNWIND_BUILD_ZERO_COST_APIS 13 | endif 14 | 15 | CFLAGS += -funwind-tables 16 | CXXFLAGS += -fno-exceptions -funwind-tables 17 | 18 | 19 | all:: libunwind-$(CPU)-bare.a libunwind-$(CPU)-libc.a 20 | 21 | libunwind-$(CPU)-%.a: UnwindRegistersSave-$(CPU)-%.o UnwindRegistersRestore-$(CPU)-%.o \ 22 | UnwindLevel1-$(CPU)-%.o UnwindLevel1-gcc-ext-$(CPU)-%.o libunwind-$(CPU)-%.o 23 | $(archive) 24 | 25 | 26 | %-$(CPU)-libc.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.S 27 | $(assemble) 28 | 29 | %-$(CPU)-libc.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.c 30 | $(compile) 31 | 32 | 33 | %-$(CPU)-libc.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.cpp 34 | $(compilexx) 35 | 36 | 37 | %-$(CPU)-bare.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.S 38 | $(assemble) 39 | 40 | %-$(CPU)-bare.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.c 41 | $(compile) -D_LIBUNWIND_IS_BAREMETAL 42 | 43 | %-$(CPU)-bare.o: $(MISOC_DIRECTORY)/software/unwinder/src/%.cpp 44 | $(compilexx) -D_LIBUNWIND_IS_BAREMETAL 45 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | from setuptools import setup 5 | from setuptools import find_packages 6 | 7 | 8 | if sys.version_info[:3] < (3, 5): 9 | raise SystemExit("You need Python 3.5+") 10 | 11 | 12 | setup( 13 | name="misoc", 14 | version="0.13", 15 | description="a high performance and small footprint SoC based on Migen", 16 | long_description=open("README").read(), 17 | author="Sebastien Bourdeauducq", 18 | author_email="sb@m-labs.hk", 19 | url="https://m-labs.hk", 20 | download_url="https://github.com/m-labs/misoc", 21 | license="BSD", 22 | platforms=["Any"], 23 | keywords="HDL ASIC FPGA hardware design", 24 | classifiers=[ 25 | "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)", 26 | "Environment :: Console", 27 | "Development Status :: Alpha", 28 | "Intended Audience :: Developers", 29 | "License :: OSI Approved :: BSD License", 30 | "Operating System :: OS Independent", 31 | "Programming Language :: Python", 32 | ], 33 | packages=find_packages(), 34 | install_requires=["pyserial", "asyncserial", "jinja2", "migen"], 35 | include_package_data=True, 36 | entry_points={ 37 | "console_scripts": [ 38 | "flterm = misoc.tools.flterm:main", 39 | "mkmscimg = misoc.tools.mkmscimg:main", 40 | ], 41 | }, 42 | ) 43 | -------------------------------------------------------------------------------- /misoc/tools/mkmscimg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import binascii 5 | 6 | 7 | def insert_crc(i_filename, fbi_mode=False, o_filename=None, little_endian=False): 8 | endian = "little" if little_endian else "big" 9 | 10 | if o_filename is None: 11 | o_filename = i_filename 12 | 13 | with open(i_filename, "rb") as f: 14 | fdata = f.read() 15 | fcrc = binascii.crc32(fdata).to_bytes(4, byteorder=endian) 16 | flength = len(fdata).to_bytes(4, byteorder=endian) 17 | 18 | with open(o_filename, "wb") as f: 19 | if fbi_mode: 20 | f.write(flength) 21 | f.write(fcrc) 22 | f.write(fdata) 23 | else: 24 | f.write(fdata) 25 | f.write(fcrc) 26 | 27 | 28 | def main(): 29 | parser = argparse.ArgumentParser(description="CRC32 computation tool and MiSoC image file writer.") 30 | parser.add_argument("input", help="input file") 31 | parser.add_argument("-o", "--output", default=None, help="output file (if not specified, use input file)") 32 | parser.add_argument("-f", "--fbi", default=False, action="store_true", help="build flash boot image (FBI) file") 33 | parser.add_argument("-l", "--little", default=False, action="store_true", help="Use little endian to write the CRC32") 34 | args = parser.parse_args() 35 | insert_crc(args.input, args.fbi, args.output, args.little) 36 | 37 | 38 | if __name__ == "__main__": 39 | main() 40 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/mac/__init__.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.interconnect.csr import * 4 | from misoc.cores.liteeth_mini.common import * 5 | from misoc.cores.liteeth_mini.mac.core import LiteEthMACCore 6 | from misoc.cores.liteeth_mini.mac.wishbone import LiteEthMACWishboneInterface 7 | 8 | 9 | class LiteEthMAC(Module, AutoCSR): 10 | def __init__(self, phy, dw, 11 | interface="wishbone", 12 | endianness="big", 13 | with_preamble_crc=True, 14 | nrxslots=2, 15 | ntxslots=2): 16 | self.submodules.core = LiteEthMACCore(phy, dw, endianness, with_preamble_crc) 17 | self.csrs = [] 18 | if interface == "wishbone": 19 | self.rx_slots = CSRConstant(nrxslots) 20 | self.tx_slots = CSRConstant(ntxslots) 21 | self.slot_size = CSRConstant(2**bits_for(eth_mtu)) 22 | 23 | self.submodules.interface = LiteEthMACWishboneInterface(dw, nrxslots, ntxslots, endianness) 24 | self.comb += [ 25 | self.interface.source.connect(self.core.sink), 26 | self.core.source.connect(self.interface.sink) 27 | ] 28 | self.ev, self.bus = self.interface.sram.ev, self.interface.bus 29 | self.csrs = self.interface.get_csrs() + self.core.get_csrs() 30 | else: 31 | raise NotImplementedError 32 | 33 | def get_csrs(self): 34 | return self.csrs 35 | -------------------------------------------------------------------------------- /misoc/software/libprintf/ctype.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From linux/lib/ctype.c, Copyright (C) 1991, 1992 Linus Torvalds */ 4 | const unsigned char _ctype[] = { 5 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 6 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 7 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 8 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 9 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 10 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 11 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 12 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 13 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 14 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 15 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 16 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 17 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 18 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 19 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 20 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ 23 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ 24 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ 25 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ 26 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ 27 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ 28 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ 29 | -------------------------------------------------------------------------------- /misoc/cores/gpio.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | from migen.genlib.cdc import MultiReg 3 | 4 | from misoc.interconnect.csr import * 5 | 6 | 7 | class GPIOIn(Module, AutoCSR): 8 | def __init__(self, signal): 9 | self._in = CSRStatus(len(signal)) 10 | self.specials += MultiReg(signal, self._in.status) 11 | 12 | 13 | class GPIOOut(Module, AutoCSR): 14 | def __init__(self, signal, reset_out=0): 15 | self._out = CSRStorage(len(signal), reset=reset_out) 16 | self.comb += signal.eq(self._out.storage) 17 | 18 | 19 | class GPIOTristate(Module, AutoCSR): 20 | def __init__(self, signals, reset_out=0, reset_oe=0): 21 | l = len(signals) 22 | self._in = CSRStatus(l) 23 | self._out = CSRStorage(l, reset=reset_out) 24 | self._oe = CSRStorage(l, reset=reset_oe) 25 | 26 | for n, signal in enumerate(signals): 27 | ts = TSTriple(1) 28 | self.specials += ts.get_tristate(signal) 29 | 30 | status = Signal() 31 | self.comb += self._in.status[n].eq(status) 32 | 33 | self.specials += MultiReg(ts.i, status) 34 | self.comb += [ 35 | ts.o.eq(self._out.storage[n]), 36 | ts.oe.eq(self._oe.storage[n]) 37 | ] 38 | 39 | 40 | class Blinker(Module): 41 | def __init__(self, signal, divbits=26): 42 | counter = Signal(divbits) 43 | self.comb += signal.eq(counter[divbits-1]) 44 | self.sync += counter.eq(counter + 1) 45 | -------------------------------------------------------------------------------- /misoc/interconnect/wishbone2lasmi.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | from migen.genlib.fsm import FSM, NextState 3 | 4 | 5 | class WB2LASMI(Module): 6 | def __init__(self, wishbone, lasmim): 7 | 8 | ### 9 | 10 | # Control FSM 11 | self.submodules.fsm = fsm = FSM(reset_state="IDLE") 12 | fsm.act("IDLE", 13 | If(wishbone.cyc & wishbone.stb, 14 | NextState("REQUEST") 15 | ) 16 | ) 17 | fsm.act("REQUEST", 18 | lasmim.stb.eq(1), 19 | lasmim.we.eq(wishbone.we), 20 | If(lasmim.req_ack, 21 | If(wishbone.we, 22 | NextState("WRITE_DATA") 23 | ).Else( 24 | NextState("READ_DATA") 25 | ) 26 | ) 27 | ) 28 | fsm.act("WRITE_DATA", 29 | If(lasmim.dat_w_ack, 30 | lasmim.dat_we.eq(wishbone.sel), 31 | wishbone.ack.eq(1), 32 | NextState("IDLE") 33 | ) 34 | ) 35 | fsm.act("READ_DATA", 36 | If(lasmim.dat_r_ack, 37 | wishbone.ack.eq(1), 38 | NextState("IDLE") 39 | ) 40 | ) 41 | 42 | # Address / Datapath 43 | self.comb += [ 44 | lasmim.adr.eq(wishbone.adr), 45 | If(lasmim.dat_w_ack, 46 | lasmim.dat_w.eq(wishbone.dat_w), 47 | ), 48 | wishbone.dat_r.eq(lasmim.dat_r) 49 | ] 50 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/signal_unwind.pass.cpp: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | // Ensure that the unwinder can cope with the signal handler. 11 | // REQUIRES: linux && (target={{aarch64-.+}} || target={{x86_64-.+}}) 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | _Unwind_Reason_Code frame_handler(struct _Unwind_Context* ctx, void* arg) { 24 | (void)arg; 25 | Dl_info info = { 0, 0, 0, 0 }; 26 | 27 | // Unwind util the main is reached, above frames depend on the platform and 28 | // architecture. 29 | if (dladdr(reinterpret_cast(_Unwind_GetIP(ctx)), &info) && 30 | info.dli_sname && !strcmp("main", info.dli_sname)) { 31 | _Exit(0); 32 | } 33 | return _URC_NO_REASON; 34 | } 35 | 36 | void signal_handler(int signum) { 37 | (void)signum; 38 | _Unwind_Backtrace(frame_handler, NULL); 39 | _Exit(-1); 40 | } 41 | 42 | int main(int, char**) { 43 | signal(SIGUSR1, signal_handler); 44 | kill(getpid(), SIGUSR1); 45 | return -2; 46 | } 47 | -------------------------------------------------------------------------------- /misoc/software/libm/w_scalb.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_scalb.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper scalb(double x, double fn) is provide for 16 | * passing various standard test suite. One 17 | * should use scalbn() instead. 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | #include 23 | 24 | #ifdef __STDC__ 25 | #ifdef _SCALB_INT 26 | double scalb(double x, int fn) /* wrapper scalb */ 27 | #else 28 | double scalb(double x, double fn) /* wrapper scalb */ 29 | #endif 30 | #else 31 | double scalb(x,fn) /* wrapper scalb */ 32 | #ifdef _SCALB_INT 33 | double x; int fn; 34 | #else 35 | double x,fn; 36 | #endif 37 | #endif 38 | { 39 | #ifdef _IEEE_LIBM 40 | return __ieee754_scalb(x,fn); 41 | #else 42 | double z; 43 | z = __ieee754_scalb(x,fn); 44 | if(_LIB_VERSION == _IEEE_) return z; 45 | if(!(finite(z)||isnan(z))&&finite(x)) { 46 | return __kernel_standard(x,(double)fn,32); /* scalb overflow */ 47 | } 48 | if(z==0.0&&z!=x) { 49 | return __kernel_standard(x,(double)fn,33); /* scalb underflow */ 50 | } 51 | #ifndef _SCALB_INT 52 | if(!finite(fn)) errno = ERANGE; 53 | #endif 54 | return z; 55 | #endif 56 | } 57 | -------------------------------------------------------------------------------- /misoc/software/libm/s_frexp.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_frexp.c 1.4 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * for non-zero x 16 | * x = frexp(arg,&exp); 17 | * return a double fp quantity x such that 0.5 <= |x| <1.0 18 | * and the corresponding binary exponent "exp". That is 19 | * arg = x*2^exp. 20 | * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg 21 | * with *exp=0. 22 | */ 23 | 24 | #include "fdlibm.h" 25 | 26 | #ifdef __STDC__ 27 | static const double 28 | #else 29 | static double 30 | #endif 31 | two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ 32 | 33 | #ifdef __STDC__ 34 | double frexp(double x, int *eptr) 35 | #else 36 | double frexp(x, eptr) 37 | double x; int *eptr; 38 | #endif 39 | { 40 | int hx, ix, lx; 41 | hx = __HI(x); 42 | ix = 0x7fffffff&hx; 43 | lx = __LO(x); 44 | *eptr = 0; 45 | if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ 46 | if (ix<0x00100000) { /* subnormal */ 47 | x *= two54; 48 | hx = __HI(x); 49 | ix = hx&0x7fffffff; 50 | *eptr = -54; 51 | } 52 | *eptr += (ix>>20)-1022; 53 | hx = (hx&0x800fffff)|0x3fe00000; 54 | __HI(x) = hx; 55 | return x; 56 | } 57 | -------------------------------------------------------------------------------- /misoc/software/libbase/crt0-vexriscv.S: -------------------------------------------------------------------------------- 1 | .global main 2 | .global isr 3 | .global _start 4 | 5 | _start: 6 | j crt_init 7 | nop 8 | nop 9 | nop 10 | nop 11 | nop 12 | nop 13 | nop 14 | 15 | .global trap_entry 16 | trap_entry: 17 | sw x1, - 1*4(sp) 18 | sw x5, - 2*4(sp) 19 | sw x6, - 3*4(sp) 20 | sw x7, - 4*4(sp) 21 | sw x10, - 5*4(sp) 22 | sw x11, - 6*4(sp) 23 | sw x12, - 7*4(sp) 24 | sw x13, - 8*4(sp) 25 | sw x14, - 9*4(sp) 26 | sw x15, -10*4(sp) 27 | sw x16, -11*4(sp) 28 | sw x17, -12*4(sp) 29 | sw x28, -13*4(sp) 30 | sw x29, -14*4(sp) 31 | sw x30, -15*4(sp) 32 | sw x31, -16*4(sp) 33 | addi sp,sp,-16*4 34 | call isr 35 | lw x1 , 15*4(sp) 36 | lw x5, 14*4(sp) 37 | lw x6, 13*4(sp) 38 | lw x7, 12*4(sp) 39 | lw x10, 11*4(sp) 40 | lw x11, 10*4(sp) 41 | lw x12, 9*4(sp) 42 | lw x13, 8*4(sp) 43 | lw x14, 7*4(sp) 44 | lw x15, 6*4(sp) 45 | lw x16, 5*4(sp) 46 | lw x17, 4*4(sp) 47 | lw x28, 3*4(sp) 48 | lw x29, 2*4(sp) 49 | lw x30, 1*4(sp) 50 | lw x31, 0*4(sp) 51 | addi sp,sp,16*4 52 | mret 53 | .text 54 | 55 | 56 | crt_init: 57 | la sp, _fstack + 4 58 | la a0, trap_entry 59 | csrw mtvec, a0 60 | 61 | bss_init: 62 | la a0, _fbss 63 | la a1, _ebss 64 | bss_loop: 65 | beq a0,a1,bss_done 66 | sw zero,0(a0) 67 | add a0,a0,4 68 | j bss_loop 69 | bss_done: 70 | 71 | li a0, 0x880 //880 enable timer + external interrupt sources (until mstatus.MIE is set, they will never trigger an interrupt) 72 | csrw mie,a0 73 | 74 | call main 75 | infinite_loop: 76 | j infinite_loop 77 | -------------------------------------------------------------------------------- /misoc/software/libbase/crt0-vexriscv-g.S: -------------------------------------------------------------------------------- 1 | .global main 2 | .global isr 3 | .global _start 4 | 5 | _start: 6 | j crt_init 7 | nop 8 | nop 9 | nop 10 | nop 11 | nop 12 | nop 13 | nop 14 | 15 | .global trap_entry 16 | trap_entry: 17 | sw x1, - 1*4(sp) 18 | sw x5, - 2*4(sp) 19 | sw x6, - 3*4(sp) 20 | sw x7, - 4*4(sp) 21 | sw x10, - 5*4(sp) 22 | sw x11, - 6*4(sp) 23 | sw x12, - 7*4(sp) 24 | sw x13, - 8*4(sp) 25 | sw x14, - 9*4(sp) 26 | sw x15, -10*4(sp) 27 | sw x16, -11*4(sp) 28 | sw x17, -12*4(sp) 29 | sw x28, -13*4(sp) 30 | sw x29, -14*4(sp) 31 | sw x30, -15*4(sp) 32 | sw x31, -16*4(sp) 33 | addi sp,sp,-16*4 34 | call isr 35 | lw x1 , 15*4(sp) 36 | lw x5, 14*4(sp) 37 | lw x6, 13*4(sp) 38 | lw x7, 12*4(sp) 39 | lw x10, 11*4(sp) 40 | lw x11, 10*4(sp) 41 | lw x12, 9*4(sp) 42 | lw x13, 8*4(sp) 43 | lw x14, 7*4(sp) 44 | lw x15, 6*4(sp) 45 | lw x16, 5*4(sp) 46 | lw x17, 4*4(sp) 47 | lw x28, 3*4(sp) 48 | lw x29, 2*4(sp) 49 | lw x30, 1*4(sp) 50 | lw x31, 0*4(sp) 51 | addi sp,sp,16*4 52 | mret 53 | .text 54 | 55 | 56 | crt_init: 57 | la sp, _fstack + 4 58 | la a0, trap_entry 59 | csrw mtvec, a0 60 | 61 | bss_init: 62 | la a0, _fbss 63 | la a1, _ebss 64 | bss_loop: 65 | beq a0,a1,bss_done 66 | sw zero,0(a0) 67 | add a0,a0,4 68 | j bss_loop 69 | bss_done: 70 | 71 | li a0, 0x880 //880 enable timer + external interrupt sources (until mstatus.MIE is set, they will never trigger an interrupt) 72 | csrw mie,a0 73 | 74 | call main 75 | infinite_loop: 76 | j infinite_loop 77 | -------------------------------------------------------------------------------- /misoc/cores/coaxpress/core/idle.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.cores.coaxpress.common import char_width, KCode, word_layout 4 | from misoc.interconnect.stream import Endpoint 5 | 6 | class IdleWordInserter(Module): 7 | def __init__(self): 8 | # Section 9.2.5 (CXP-001-2021) 9 | # Send K28.5, K28.1, K28.1, D21.5 as idle word 10 | self.submodules.fsm = fsm = FSM(reset_state="WRITE_IDLE") 11 | 12 | self.sink = Endpoint(word_layout) 13 | self.source = Endpoint(word_layout) 14 | 15 | # Section 9.2.5.1 (CXP-001-2021) 16 | # IDLE should be transmitter every 10000 words 17 | cnt = Signal(max=10000, reset=9999) 18 | 19 | fsm.act("WRITE_IDLE", 20 | self.source.stb.eq(1), 21 | self.source.data.eq(Cat(KCode["idle_comma"], KCode["idle_alignment"], KCode["idle_alignment"], C(0xB5, char_width))), 22 | self.source.k.eq(Cat(1, 1, 1, 0)), 23 | 24 | self.sink.ack.eq(1), 25 | If(self.sink.stb, 26 | self.sink.ack.eq(0), 27 | If(self.source.ack, 28 | NextValue(cnt, cnt.reset), 29 | NextState("COPY"), 30 | ) 31 | ), 32 | ) 33 | 34 | fsm.act("COPY", 35 | self.sink.connect(self.source), 36 | # increment when uphas data and got ack 37 | If(self.sink.stb & self.source.ack, NextValue(cnt, cnt - 1)), 38 | If((( (~self.sink.stb) | (self.sink.eop) | (cnt == 0) ) & self.source.ack), NextState("WRITE_IDLE")) 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /misoc/software/include/base/system.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_H 2 | #define __SYSTEM_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void flush_cpu_icache(void); 9 | void flush_cpu_dcache(void); 10 | void flush_l2_cache(void); 11 | 12 | #ifdef __or1k__ 13 | #include 14 | static inline unsigned long mfspr(unsigned long add) 15 | { 16 | unsigned long ret; 17 | 18 | __asm__ __volatile__ ("l.mfspr %0,%1,0" : "=r" (ret) : "r" (add)); 19 | 20 | return ret; 21 | } 22 | 23 | static inline void mtspr(unsigned long add, unsigned long val) 24 | { 25 | __asm__ __volatile__ ("l.mtspr %0,%1,0" : : "r" (add), "r" (val)); 26 | } 27 | #endif 28 | 29 | 30 | #if defined(__vexriscv__) 31 | #include 32 | #define csrr(reg) ({ unsigned long __tmp; \ 33 | asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ 34 | __tmp; }) 35 | 36 | #define csrw(reg, val) ({ \ 37 | if (__builtin_constant_p(val) && (unsigned long)(val) < 32) \ 38 | asm volatile ("csrw " #reg ", %0" :: "i"(val)); \ 39 | else \ 40 | asm volatile ("csrw " #reg ", %0" :: "r"(val)); }) 41 | 42 | #define csrs(reg, bit) ({ \ 43 | if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ 44 | asm volatile ("csrrs x0, " #reg ", %0" :: "i"(bit)); \ 45 | else \ 46 | asm volatile ("csrrs x0, " #reg ", %0" :: "r"(bit)); }) 47 | 48 | #define csrc(reg, bit) ({ \ 49 | if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ 50 | asm volatile ("csrrc x0, " #reg ", %0" :: "i"(bit)); \ 51 | else \ 52 | asm volatile ("csrrc x0, " #reg ", %0" :: "r"(bit)); }) 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* __SYSTEM_H */ 60 | -------------------------------------------------------------------------------- /misoc/software/libbase/console.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | FILE *stdin, *stdout, *stderr; 7 | 8 | static console_write_hook write_hook; 9 | static console_read_hook read_hook; 10 | static console_read_nonblock_hook read_nonblock_hook; 11 | 12 | void console_set_write_hook(console_write_hook h) 13 | { 14 | write_hook = h; 15 | } 16 | 17 | void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn) 18 | { 19 | read_hook = r; 20 | read_nonblock_hook = rn; 21 | } 22 | 23 | int putchar(int c) 24 | { 25 | uart_write(c); 26 | if(write_hook != NULL) 27 | write_hook(c); 28 | return c; 29 | } 30 | 31 | char readchar(void) 32 | { 33 | while(1) { 34 | if(uart_read_nonblock()) 35 | return uart_read(); 36 | if((read_nonblock_hook != NULL) && read_nonblock_hook()) 37 | return read_hook(); 38 | } 39 | } 40 | 41 | int readchar_nonblock(void) 42 | { 43 | return (uart_read_nonblock() 44 | || ((read_nonblock_hook != NULL) && read_nonblock_hook())); 45 | } 46 | 47 | int puts(const char *s) 48 | { 49 | while(*s) { 50 | putchar(*s); 51 | s++; 52 | } 53 | putchar('\n'); 54 | return 1; 55 | } 56 | 57 | void putsnonl(const char *s) 58 | { 59 | while(*s) { 60 | putchar(*s); 61 | s++; 62 | } 63 | } 64 | 65 | #define PRINTF_BUFFER_SIZE 256 66 | 67 | int printf(const char *fmt, ...) 68 | { 69 | va_list args; 70 | int len; 71 | char outbuf[PRINTF_BUFFER_SIZE]; 72 | 73 | va_start(args, fmt); 74 | len = vscnprintf(outbuf, sizeof(outbuf), fmt, args); 75 | va_end(args); 76 | outbuf[len] = 0; 77 | putsnonl(outbuf); 78 | 79 | return len; 80 | } 81 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/unwind_leaffunction.pass.cpp: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | // Ensure that leaf function can be unwund. 11 | // REQUIRES: linux && (target={{aarch64-.+}} || target={{x86_64-.+}}) 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | _Unwind_Reason_Code frame_handler(struct _Unwind_Context* ctx, void* arg) { 24 | (void)arg; 25 | Dl_info info = { 0, 0, 0, 0 }; 26 | 27 | // Unwind util the main is reached, above frames deeped on the platfrom and architecture. 28 | if (dladdr(reinterpret_cast(_Unwind_GetIP(ctx)), &info) && 29 | info.dli_sname && !strcmp("main", info.dli_sname)) { 30 | _Exit(0); 31 | } 32 | return _URC_NO_REASON; 33 | } 34 | 35 | void signal_handler(int signum) { 36 | (void)signum; 37 | _Unwind_Backtrace(frame_handler, NULL); 38 | _Exit(-1); 39 | } 40 | 41 | int* faultyPointer = NULL; 42 | 43 | __attribute__((noinline)) void crashing_leaf_func(void) { 44 | *faultyPointer = 0; 45 | } 46 | 47 | int main(int, char**) { 48 | signal(SIGSEGV, signal_handler); 49 | crashing_leaf_func(); 50 | return -2; 51 | } -------------------------------------------------------------------------------- /misoc/software/include/base/float.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLOAT_H 2 | #define __FLOAT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ 9 | #define FLT_ROUNDS (__builtin_flt_rounds()) 10 | #define FLT_RADIX __FLT_RADIX__ 11 | 12 | #define FLT_MANT_DIG __FLT_MANT_DIG__ 13 | #define DBL_MANT_DIG __DBL_MANT_DIG__ 14 | #define LDBL_MANT_DIG __LDBL_MANT_DIG__ 15 | 16 | #define DECIMAL_DIG __DECIMAL_DIG__ 17 | 18 | #define FLT_DIG __FLT_DIG__ 19 | #define DBL_DIG __DBL_DIG__ 20 | #define LDBL_DIG __LDBL_DIG__ 21 | 22 | #define FLT_MIN_EXP __FLT_MIN_EXP__ 23 | #define DBL_MIN_EXP __DBL_MIN_EXP__ 24 | #define LDBL_MIN_EXP __LDBL_MIN_EXP__ 25 | 26 | #define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ 27 | #define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ 28 | #define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ 29 | 30 | #define FLT_MAX_EXP __FLT_MAX_EXP__ 31 | #define DBL_MAX_EXP __DBL_MAX_EXP__ 32 | #define LDBL_MAX_EXP __LDBL_MAX_EXP__ 33 | 34 | #define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ 35 | #define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ 36 | #define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ 37 | 38 | #define FLT_MAX __FLT_MAX__ 39 | #define DBL_MAX __DBL_MAX__ 40 | #define LDBL_MAX __LDBL_MAX__ 41 | 42 | #define FLT_EPSILON __FLT_EPSILON__ 43 | #define DBL_EPSILON __DBL_EPSILON__ 44 | #define LDBL_EPSILON __LDBL_EPSILON__ 45 | 46 | #define FLT_MIN __FLT_MIN__ 47 | #define DBL_MIN __DBL_MIN__ 48 | #define LDBL_MIN __LDBL_MIN__ 49 | 50 | #define FLT_TRUE_MIN __FLT_DENORM_MIN__ 51 | #define DBL_TRUE_MIN __DBL_DENORM_MIN__ 52 | #define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __FLOAT_H */ 59 | -------------------------------------------------------------------------------- /misoc/software/unwinder/src/Unwind-EHABI.h: -------------------------------------------------------------------------------- 1 | //===------------------------- Unwind-EHABI.hpp ---------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef __UNWIND_EHABI_H__ 11 | #define __UNWIND_EHABI_H__ 12 | 13 | #include <__libunwind_config.h> 14 | 15 | #if defined(_LIBUNWIND_ARM_EHABI) 16 | 17 | #include 18 | #include 19 | 20 | // Unable to unwind in the ARM index table (section 5 EHABI). 21 | #define UNW_EXIDX_CANTUNWIND 0x1 22 | 23 | static inline uint32_t signExtendPrel31(uint32_t data) { 24 | return data | ((data & 0x40000000u) << 1); 25 | } 26 | 27 | static inline uint32_t readPrel31(const uint32_t *data) { 28 | return (((uint32_t)(uintptr_t)data) + signExtendPrel31(*data)); 29 | } 30 | 31 | #if defined(__cplusplus) 32 | extern "C" { 33 | #endif 34 | 35 | extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr0( 36 | _Unwind_State state, _Unwind_Control_Block *ucbp, _Unwind_Context *context); 37 | 38 | extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr1( 39 | _Unwind_State state, _Unwind_Control_Block *ucbp, _Unwind_Context *context); 40 | 41 | extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr2( 42 | _Unwind_State state, _Unwind_Control_Block *ucbp, _Unwind_Context *context); 43 | 44 | #if defined(__cplusplus) 45 | } // extern "C" 46 | #endif 47 | 48 | #endif // defined(_LIBUNWIND_ARM_EHABI) 49 | 50 | #endif // __UNWIND_EHABI_H__ 51 | -------------------------------------------------------------------------------- /misoc/software/libm/w_pow.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* @(#)w_pow.c 1.3 95/01/18 */ 4 | /* 5 | * ==================================================== 6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7 | * 8 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 9 | * Permission to use, copy, modify, and distribute this 10 | * software is freely granted, provided that this notice 11 | * is preserved. 12 | * ==================================================== 13 | */ 14 | 15 | /* 16 | * wrapper pow(x,y) return x**y 17 | */ 18 | 19 | #include "fdlibm.h" 20 | 21 | 22 | #ifdef __STDC__ 23 | double pow(double x, double y) /* wrapper pow */ 24 | #else 25 | double pow(x,y) /* wrapper pow */ 26 | double x,y; 27 | #endif 28 | { 29 | #ifdef _IEEE_LIBM 30 | return __ieee754_pow(x,y); 31 | #else 32 | double z; 33 | z=__ieee754_pow(x,y); 34 | if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; 35 | if(isnan(x)) { 36 | if(y==0.0) 37 | return __kernel_standard(x,y,42); /* pow(NaN,0.0) */ 38 | else 39 | return z; 40 | } 41 | if(x==0.0){ 42 | if(y==0.0) 43 | return __kernel_standard(x,y,20); /* pow(0.0,0.0) */ 44 | if(finite(y)&&y<0.0) 45 | return __kernel_standard(x,y,23); /* pow(0.0,negative) */ 46 | return z; 47 | } 48 | if(!finite(z)) { 49 | if(finite(x)&&finite(y)) { 50 | if(isnan(z)) 51 | return __kernel_standard(x,y,24); /* pow neg**non-int */ 52 | else 53 | return __kernel_standard(x,y,21); /* pow overflow */ 54 | } 55 | } 56 | if(z==0.0&&finite(x)&&finite(y)) 57 | return __kernel_standard(x,y,22); /* pow underflow */ 58 | return z; 59 | #endif 60 | } 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2007-2020 M-Labs Limited. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright notice, 9 | this list of conditions and the following disclaimer in the documentation 10 | and/or other materials provided with the distribution. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | 23 | 24 | Other authors retain ownership of their contributions. If a submission can 25 | reasonably be considered independently copyrightable, it's yours and we 26 | encourage you to claim it with appropriate copyright notices. This submission 27 | then falls under the "otherwise noted" category. All submissions are strongly 28 | encouraged to use the two-clause BSD license reproduced above. 29 | -------------------------------------------------------------------------------- /misoc/software/libm/w_j1.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_j1.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper of j1,y1 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double j1(double x) /* wrapper j1 */ 22 | #else 23 | double j1(x) /* wrapper j1 */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_j1(x); 29 | #else 30 | double z; 31 | z = __ieee754_j1(x); 32 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; 33 | if(fabs(x)>X_TLOSS) { 34 | return __kernel_standard(x,x,36); /* j1(|x|>X_TLOSS) */ 35 | } else 36 | return z; 37 | #endif 38 | } 39 | 40 | #ifdef __STDC__ 41 | double y1(double x) /* wrapper y1 */ 42 | #else 43 | double y1(x) /* wrapper y1 */ 44 | double x; 45 | #endif 46 | { 47 | #ifdef _IEEE_LIBM 48 | return __ieee754_y1(x); 49 | #else 50 | double z; 51 | z = __ieee754_y1(x); 52 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; 53 | if(x <= 0.0){ 54 | if(x==0.0) 55 | /* d= -one/(x-x); */ 56 | return __kernel_standard(x,x,10); 57 | else 58 | /* d = zero/(x-x); */ 59 | return __kernel_standard(x,x,11); 60 | } 61 | if(x>X_TLOSS) { 62 | return __kernel_standard(x,x,37); /* y1(x>X_TLOSS) */ 63 | } else 64 | return z; 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /misoc/software/libm/w_j0.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_j0.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper j0(double x), y0(double x) 16 | */ 17 | 18 | #include "fdlibm.h" 19 | 20 | #ifdef __STDC__ 21 | double j0(double x) /* wrapper j0 */ 22 | #else 23 | double j0(x) /* wrapper j0 */ 24 | double x; 25 | #endif 26 | { 27 | #ifdef _IEEE_LIBM 28 | return __ieee754_j0(x); 29 | #else 30 | double z = __ieee754_j0(x); 31 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 32 | if(fabs(x)>X_TLOSS) { 33 | return __kernel_standard(x,x,34); /* j0(|x|>X_TLOSS) */ 34 | } else 35 | return z; 36 | #endif 37 | } 38 | 39 | #ifdef __STDC__ 40 | double y0(double x) /* wrapper y0 */ 41 | #else 42 | double y0(x) /* wrapper y0 */ 43 | double x; 44 | #endif 45 | { 46 | #ifdef _IEEE_LIBM 47 | return __ieee754_y0(x); 48 | #else 49 | double z; 50 | z = __ieee754_y0(x); 51 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; 52 | if(x <= 0.0){ 53 | if(x==0.0) 54 | /* d= -one/(x-x); */ 55 | return __kernel_standard(x,x,8); 56 | else 57 | /* d = zero/(x-x); */ 58 | return __kernel_standard(x,x,9); 59 | } 60 | if(x>X_TLOSS) { 61 | return __kernel_standard(x,x,35); /* y0(x>X_TLOSS) */ 62 | } else 63 | return z; 64 | #endif 65 | } 66 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/LICENSE: -------------------------------------------------------------------------------- 1 | Unless otherwise noted, LiteEth is copyright (C) 2015 Florent Kermarrec. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright notice, 9 | this list of conditions and the following disclaimer in the documentation 10 | and/or other materials provided with the distribution. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | 23 | 24 | Other authors retain ownership of their contributions. If a submission can 25 | reasonably be considered independently copyrightable, it's yours and we 26 | encourage you to claim it with appropriate copyright notices. This submission 27 | then falls under the "otherwise noted" category. All submissions are strongly 28 | encouraged to use the two-clause BSD license reproduced above. 29 | -------------------------------------------------------------------------------- /misoc/test/test_cic.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import unittest 3 | from migen import * 4 | 5 | from misoc.cores import cic 6 | 7 | def feed(endpoint, x, rate): 8 | n, d = rate 9 | t = 0 10 | for i, xi in enumerate(x): 11 | while t*n < i*d: 12 | yield 13 | t += 1 14 | yield endpoint.data.eq(int(xi)) 15 | yield endpoint.stb.eq(1) 16 | yield 17 | t += 1 18 | while not (yield endpoint.ack): 19 | yield 20 | yield endpoint.stb.eq(0) 21 | 22 | 23 | @passive 24 | def retrieve(endpoint, o): 25 | yield 26 | while True: 27 | yield endpoint.ack.eq(1) 28 | yield 29 | while not (yield endpoint.stb): 30 | yield 31 | o.append(((yield endpoint.data0), (yield endpoint.data1))) 32 | yield endpoint.ack.eq(0) 33 | 34 | 35 | def cic_up(x, n, r): 36 | for _ in range(n): 37 | x = np.diff(np.r_[0, x]) 38 | x = np.c_[x, np.zeros((len(x), r - 1), np.int64)].ravel() 39 | for _ in range(n): 40 | x = np.cumsum(x) 41 | return x 42 | 43 | 44 | class TestCIC(unittest.TestCase): 45 | def setUp(self): 46 | self.dut = cic.SuperCIC(n=4, r=5, width=4) 47 | 48 | def test_init(self): 49 | self.assertEqual(len(self.dut.input.data), 4) 50 | self.assertEqual(len(self.dut.output.data0), 11) 51 | self.assertEqual(len(self.dut.output.data1), 11) 52 | 53 | def test_seq(self): 54 | x = [1, 7, -8, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 55 | y = [] 56 | run_simulation(self.dut, [feed(self.dut.input, x, (2, 5)), 57 | retrieve(self.dut.output, y)]) 58 | y = np.ravel(y)[39:] 59 | y0 = cic_up(x, n=4, r=5)[:len(y)] 60 | np.testing.assert_equal(y, y0) 61 | -------------------------------------------------------------------------------- /misoc/software/include/base/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef __CTYPE_H 2 | #define __CTYPE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * NOTE! This ctype does not handle EOF like the standard C 10 | * library is required to. 11 | */ 12 | 13 | #define _U 0x01 /* upper */ 14 | #define _L 0x02 /* lower */ 15 | #define _D 0x04 /* digit */ 16 | #define _C 0x08 /* cntrl */ 17 | #define _P 0x10 /* punct */ 18 | #define _S 0x20 /* white space (space/lf/tab) */ 19 | #define _X 0x40 /* hex digit */ 20 | #define _SP 0x80 /* hard space (0x20) */ 21 | 22 | extern const unsigned char _ctype[]; 23 | 24 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) 25 | 26 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) 27 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) 28 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0) 29 | #define isdigit(c) ((__ismask(c)&(_D)) != 0) 30 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) 31 | #define islower(c) ((__ismask(c)&(_L)) != 0) 32 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) 33 | #define ispunct(c) ((__ismask(c)&(_P)) != 0) 34 | /* Note: isspace() must return false for %NUL-terminator */ 35 | #define isspace(c) ((__ismask(c)&(_S)) != 0) 36 | #define isupper(c) ((__ismask(c)&(_U)) != 0) 37 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) 38 | 39 | #define isascii(c) (((unsigned char)(c))<=0x7f) 40 | #define toascii(c) (((unsigned char)(c))&0x7f) 41 | 42 | static inline unsigned char __tolower(unsigned char c) 43 | { 44 | if (isupper(c)) 45 | c -= 'A'-'a'; 46 | return c; 47 | } 48 | 49 | static inline unsigned char __toupper(unsigned char c) 50 | { 51 | if (islower(c)) 52 | c -= 'a'-'A'; 53 | return c; 54 | } 55 | 56 | #define tolower(c) __tolower(c) 57 | #define toupper(c) __toupper(c) 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __CTYPE_H */ 64 | -------------------------------------------------------------------------------- /misoc/software/include/base/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDIO_H 2 | #define __STDIO_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int putchar(int c); 11 | int puts(const char *s); 12 | 13 | int snprintf(char *buf, size_t size, const char *fmt, ...); 14 | int scnprintf(char *buf, size_t size, const char *fmt, ...); 15 | int sprintf(char *buf, const char *fmt, ...); 16 | 17 | int printf(const char *fmt, ...); 18 | 19 | /* Not sure this belongs here... */ 20 | typedef long long loff_t; 21 | typedef long off_t; 22 | typedef int mode_t; 23 | typedef int dev_t; 24 | 25 | /* 26 | * Note: this library does not provide FILE operations. 27 | * User code must implement them. 28 | */ 29 | 30 | #ifndef BUFSIZ 31 | #define BUFSIZ 1024 32 | #endif 33 | 34 | #ifndef EOF 35 | #define EOF -1 36 | #endif 37 | 38 | #ifndef SEEK_SET 39 | #define SEEK_SET 0 40 | #endif 41 | 42 | #ifndef SEEK_CUR 43 | #define SEEK_CUR 1 44 | #endif 45 | 46 | #ifndef SEEK_END 47 | #define SEEK_END 2 48 | #endif 49 | 50 | typedef int FILE; 51 | 52 | extern FILE *stdin; 53 | extern FILE *stdout; 54 | extern FILE *stderr; 55 | 56 | int fprintf(FILE *stream, const char *format, ...); 57 | int fflush(FILE *stream); 58 | 59 | FILE *fopen(const char *path, const char *mode); 60 | FILE *freopen(const char *path, const char *mode, FILE *stream); 61 | char *fgets(char *s, int size, FILE *stream); 62 | size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); 63 | size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); 64 | int getc(FILE *stream); 65 | int fputc(int c, FILE *stream); 66 | int ferror(FILE *stream); 67 | int feof(FILE *stream); 68 | int fclose(FILE *fp); 69 | 70 | int fseek(FILE *stream, long offset, int whence); 71 | long ftell(FILE *stream); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __STDIO_H */ 78 | -------------------------------------------------------------------------------- /misoc/software/libm/s_asinh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_asinh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* asinh(x) 15 | * Method : 16 | * Based on 17 | * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 18 | * we have 19 | * asinh(x) := x if 1+x*x=1, 20 | * := sign(x)*(log(x)+ln2)) for large |x|, else 21 | * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else 22 | * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) 23 | */ 24 | 25 | #include "fdlibm.h" 26 | 27 | #ifdef __STDC__ 28 | static const double 29 | #else 30 | static double 31 | #endif 32 | one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ 33 | ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ 34 | huge= 1.00000000000000000000e+300; 35 | 36 | #ifdef __STDC__ 37 | double asinh(double x) 38 | #else 39 | double asinh(x) 40 | double x; 41 | #endif 42 | { 43 | double t,w; 44 | int hx,ix; 45 | hx = __HI(x); 46 | ix = hx&0x7fffffff; 47 | if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ 48 | if(ix< 0x3e300000) { /* |x|<2**-28 */ 49 | if(huge+x>one) return x; /* return x inexact except 0 */ 50 | } 51 | if(ix>0x41b00000) { /* |x| > 2**28 */ 52 | w = __ieee754_log(fabs(x))+ln2; 53 | } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ 54 | t = fabs(x); 55 | w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t)); 56 | } else { /* 2.0 > |x| > 2**-28 */ 57 | t = x*x; 58 | w =log1p(fabs(x)+t/(one+sqrt(one+t))); 59 | } 60 | if(hx>0) return w; else return -w; 61 | } 62 | -------------------------------------------------------------------------------- /misoc/software/libm/e_acosh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_acosh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | /* __ieee754_acosh(x) 16 | * Method : 17 | * Based on 18 | * acosh(x) = log [ x + sqrt(x*x-1) ] 19 | * we have 20 | * acosh(x) := log(x)+ln2, if x is large; else 21 | * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else 22 | * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. 23 | * 24 | * Special cases: 25 | * acosh(x) is NaN with signal if x<1. 26 | * acosh(NaN) is NaN without signal. 27 | */ 28 | 29 | #include "fdlibm.h" 30 | 31 | #ifdef __STDC__ 32 | static const double 33 | #else 34 | static double 35 | #endif 36 | one = 1.0, 37 | ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */ 38 | 39 | #ifdef __STDC__ 40 | double __ieee754_acosh(double x) 41 | #else 42 | double __ieee754_acosh(x) 43 | double x; 44 | #endif 45 | { 46 | double t; 47 | int hx; 48 | hx = __HI(x); 49 | if(hx<0x3ff00000) { /* x < 1 */ 50 | return (x-x)/(x-x); 51 | } else if(hx >=0x41b00000) { /* x > 2**28 */ 52 | if(hx >=0x7ff00000) { /* x is inf of NaN */ 53 | return x+x; 54 | } else 55 | return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */ 56 | } else if(((hx-0x3ff00000)|__LO(x))==0) { 57 | return 0.0; /* acosh(1) = 0 */ 58 | } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ 59 | t=x*x; 60 | return __ieee754_log(2.0*x-one/(x+sqrt(t-one))); 61 | } else { /* 1=0.5 19 | * 1 2x x 20 | * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) 21 | * 2 1 - x 1 - x 22 | * 23 | * For x<0.5 24 | * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) 25 | * 26 | * Special cases: 27 | * atanh(x) is NaN if |x| > 1 with signal; 28 | * atanh(NaN) is that NaN with no signal; 29 | * atanh(+-1) is +-INF with signal. 30 | * 31 | */ 32 | 33 | #include "fdlibm.h" 34 | 35 | #ifdef __STDC__ 36 | static const double one = 1.0, huge = 1e300; 37 | #else 38 | static double one = 1.0, huge = 1e300; 39 | #endif 40 | 41 | static double zero = 0.0; 42 | 43 | #ifdef __STDC__ 44 | double __ieee754_atanh(double x) 45 | #else 46 | double __ieee754_atanh(x) 47 | double x; 48 | #endif 49 | { 50 | double t; 51 | int hx,ix; 52 | unsigned lx; 53 | hx = __HI(x); /* high word */ 54 | lx = __LO(x); /* low word */ 55 | ix = hx&0x7fffffff; 56 | if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ 57 | return (x-x)/(x-x); 58 | if(ix==0x3ff00000) 59 | return x/zero; 60 | if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ 61 | __HI(x) = ix; /* x <- |x| */ 62 | if(ix<0x3fe00000) { /* x < 0.5 */ 63 | t = x+x; 64 | t = 0.5*log1p(t+t*x/(one-x)); 65 | } else 66 | t = 0.5*log1p((x+x)/(one-x)); 67 | if(hx>=0) return t; else return -t; 68 | } 69 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/mac/wishbone.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | from migen.fhdl.simplify import FullMemoryWE 3 | 4 | from misoc.interconnect import wishbone 5 | from misoc.interconnect.csr import * 6 | from misoc.interconnect import stream 7 | from misoc.cores.liteeth_mini.common import eth_phy_layout, eth_mtu 8 | from misoc.cores.liteeth_mini.mac import sram 9 | 10 | 11 | class LiteEthMACWishboneInterface(Module, AutoCSR): 12 | def __init__(self, dw, nrxslots=2, ntxslots=2, endianness="big"): 13 | self.sink = stream.Endpoint(eth_phy_layout(dw)) 14 | self.source = stream.Endpoint(eth_phy_layout(dw)) 15 | self.bus = wishbone.Interface(data_width=dw, adr_width=32-log2_int(dw//8)) 16 | 17 | # # # 18 | 19 | # storage in SRAM 20 | sram_depth = eth_mtu//(dw//8) 21 | self.submodules.sram = sram.LiteEthMACSRAM(dw, sram_depth, nrxslots, ntxslots, endianness) 22 | self.comb += [ 23 | self.sink.connect(self.sram.sink), 24 | self.sram.source.connect(self.source) 25 | ] 26 | 27 | # Wishbone interface 28 | wb_rx_sram_ifs = [wishbone.SRAM(self.sram.writer.mems[n], read_only=True, data_width=dw) 29 | for n in range(nrxslots)] 30 | # TODO: FullMemoryWE should move to Mibuild 31 | wb_tx_sram_ifs = [FullMemoryWE()(wishbone.SRAM(self.sram.reader.mems[n], read_only=False, data_width=dw)) 32 | for n in range(ntxslots)] 33 | wb_sram_ifs = wb_rx_sram_ifs + wb_tx_sram_ifs 34 | 35 | wb_slaves = [] 36 | decoderoffset = log2_int(sram_depth, need_pow2=False) 37 | decoderbits = log2_int(len(wb_sram_ifs)) 38 | for n, wb_sram_if in enumerate(wb_sram_ifs): 39 | def slave_filter(a, v=n): 40 | return a[decoderoffset:decoderoffset+decoderbits] == v 41 | wb_slaves.append((slave_filter, wb_sram_if.bus)) 42 | self.submodules += wb_sram_if 43 | wb_con = wishbone.Decoder(self.bus, wb_slaves, register=True) 44 | self.submodules += wb_con 45 | -------------------------------------------------------------------------------- /misoc/software/include/base/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MiSoC 3 | * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq 4 | * Copyright (C) Linus Torvalds and Linux kernel developers 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __STRING_H 20 | #define __STRING_H 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | char *strchr(const char *s, int c); 29 | char *strpbrk(const char *,const char *); 30 | char *strrchr(const char *s, int c); 31 | char *strnchr(const char *s, size_t count, int c); 32 | char *strcpy(char *dest, const char *src); 33 | char *strncpy(char *dest, const char *src, size_t count); 34 | int strcmp(const char *cs, const char *ct); 35 | int strncmp(const char *cs, const char *ct, size_t count); 36 | char *strcat(char *dest, const char *src); 37 | char *strncat(char *dest, const char *src, size_t n); 38 | size_t strlen(const char *s); 39 | size_t strnlen(const char *s, size_t count); 40 | size_t strspn(const char *s, const char *accept); 41 | int memcmp(const void *cs, const void *ct, size_t count); 42 | void *memset(void *s, int c, size_t count); 43 | void *memcpy(void *to, const void *from, size_t n); 44 | void *memmove(void *dest, const void *src, size_t count); 45 | char *strstr(const char *s1, const char *s2); 46 | void *memchr(const void *s, int c, size_t n); 47 | 48 | char *strerror(int errnum); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STRING_H */ 55 | -------------------------------------------------------------------------------- /misoc/software/libm/s_ceil.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_ceil.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * ceil(x) 16 | * Return x rounded toward -inf to integral value 17 | * Method: 18 | * Bit twiddling. 19 | * Exception: 20 | * Inexact flag raised if x not equal to ceil(x). 21 | */ 22 | 23 | #include "fdlibm.h" 24 | 25 | #ifdef __STDC__ 26 | static const double huge = 1.0e300; 27 | #else 28 | static double huge = 1.0e300; 29 | #endif 30 | 31 | #ifdef __STDC__ 32 | double ceil(double x) 33 | #else 34 | double ceil(x) 35 | double x; 36 | #endif 37 | { 38 | int i0,i1,j0; 39 | unsigned i,j; 40 | i0 = __HI(x); 41 | i1 = __LO(x); 42 | j0 = ((i0>>20)&0x7ff)-0x3ff; 43 | if(j0<20) { 44 | if(j0<0) { /* raise inexact if x != 0 */ 45 | if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ 46 | if(i0<0) {i0=0x80000000;i1=0;} 47 | else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} 48 | } 49 | } else { 50 | i = (0x000fffff)>>j0; 51 | if(((i0&i)|i1)==0) return x; /* x is integral */ 52 | if(huge+x>0.0) { /* raise inexact flag */ 53 | if(i0>0) i0 += (0x00100000)>>j0; 54 | i0 &= (~i); i1=0; 55 | } 56 | } 57 | } else if (j0>51) { 58 | if(j0==0x400) return x+x; /* inf or NaN */ 59 | else return x; /* x is integral */ 60 | } else { 61 | i = ((unsigned)(0xffffffff))>>(j0-20); 62 | if((i1&i)==0) return x; /* x is integral */ 63 | if(huge+x>0.0) { /* raise inexact flag */ 64 | if(i0>0) { 65 | if(j0==20) i0+=1; 66 | else { 67 | j = i1 + (1<<(52-j0)); 68 | if(j>20)&0x7ff)-0x3ff; 43 | if(j0<20) { 44 | if(j0<0) { /* raise inexact if x != 0 */ 45 | if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ 46 | if(i0>=0) {i0=i1=0;} 47 | else if(((i0&0x7fffffff)|i1)!=0) 48 | { i0=0xbff00000;i1=0;} 49 | } 50 | } else { 51 | i = (0x000fffff)>>j0; 52 | if(((i0&i)|i1)==0) return x; /* x is integral */ 53 | if(huge+x>0.0) { /* raise inexact flag */ 54 | if(i0<0) i0 += (0x00100000)>>j0; 55 | i0 &= (~i); i1=0; 56 | } 57 | } 58 | } else if (j0>51) { 59 | if(j0==0x400) return x+x; /* inf or NaN */ 60 | else return x; /* x is integral */ 61 | } else { 62 | i = ((unsigned)(0xffffffff))>>(j0-20); 63 | if((i1&i)==0) return x; /* x is integral */ 64 | if(huge+x>0.0) { /* raise inexact flag */ 65 | if(i0<0) { 66 | if(j0==20) i0+=1; 67 | else { 68 | j = i1+(1<<(52-j0)); 69 | if(j Features 12 | ----------- 13 | * Multiple CPU options: 14 | * VexRiscV. 15 | * mor1kx (a better OpenRISC implementation). 16 | * LatticeMico32, modified to include an optional MMU (experimental). 17 | * Supports SDR, DDR, LPDDR, DDR2 and DDR3. 18 | * Provided peripherals: UART, GPIO, timer, NOR flash controller, SPI flash 19 | controller, Ethernet MAC, and more. 20 | * High performance: on Kintex-7, 125MHz system clock frequencies, 21 | 64Gbps DDR3 SDRAM bandwidth. 22 | * Low resource usage: basic implementation fits easily in Spartan-6 LX9. 23 | * Portable and easy to customize thanks to Python- and Migen-based 24 | architecture. 25 | * Design new peripherals using Migen and benefit from automatic CSR maps 26 | and logic, etc. 27 | * Possibility to encapsulate legacy Verilog/VHDL code. 28 | 29 | MiSoC comes with built-in targets for a few boards. Support for other boards can 30 | easily be added as external modules. 31 | 32 | [> License 33 | ---------- 34 | MiSoC is released under the very permissive two-clause BSD license. Under 35 | the terms of this license, you are authorized to use MiSoC for 36 | closed-source proprietary designs. 37 | Even though we do not require you to do so, those things are awesome, so please 38 | do them if possible: 39 | * tell us that you are using MiSoC 40 | * cite MiSoC in publications related to research it has helped 41 | * send us feedback and suggestions for improvements 42 | * send us bug reports when something goes wrong 43 | * send us the modifications and improvements you have done to MiSoC. 44 | 45 | See LICENSE file for full copyright and license info. 46 | 47 | [> Links 48 | -------- 49 | Web: 50 | https://m-labs.hk 51 | 52 | Public forum: 53 | https://forum.m-labs.hk 54 | -------------------------------------------------------------------------------- /misoc/software/libm/s_scalbn.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_scalbn.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * scalbn (double x, int n) 16 | * scalbn(x,n) returns x* 2**n computed by exponent 17 | * manipulation rather than by actually performing an 18 | * exponentiation or a multiplication. 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | #ifdef __STDC__ 24 | static const double 25 | #else 26 | static double 27 | #endif 28 | two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ 29 | twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ 30 | huge = 1.0e+300, 31 | tiny = 1.0e-300; 32 | 33 | #ifdef __STDC__ 34 | double scalbn (double x, int n) 35 | #else 36 | double scalbn (x,n) 37 | double x; int n; 38 | #endif 39 | { 40 | int k,hx,lx; 41 | hx = __HI(x); 42 | lx = __LO(x); 43 | k = (hx&0x7ff00000)>>20; /* extract exponent */ 44 | if (k==0) { /* 0 or subnormal x */ 45 | if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ 46 | x *= two54; 47 | hx = __HI(x); 48 | k = ((hx&0x7ff00000)>>20) - 54; 49 | if (n< -50000) return tiny*x; /*underflow*/ 50 | } 51 | if (k==0x7ff) return x+x; /* NaN or Inf */ 52 | k = k+n; 53 | if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ 54 | if (k > 0) /* normal result */ 55 | {__HI(x) = (hx&0x800fffff)|(k<<20); return x;} 56 | if (k <= -54) 57 | if (n > 50000) /* in case integer overflow in n+k */ 58 | return huge*copysign(huge,x); /*overflow*/ 59 | else return tiny*copysign(tiny,x); /*underflow*/ 60 | k += 54; /* subnormal result */ 61 | __HI(x) = (hx&0x800fffff)|(k<<20); 62 | return x*twom54; 63 | } 64 | -------------------------------------------------------------------------------- /misoc/software/libm/e_remainder.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_remainder.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* __ieee754_remainder(x,p) 15 | * Return : 16 | * returns x REM p = x - [x/p]*p as if in infinite 17 | * precise arithmetic, where [x/p] is the (infinite bit) 18 | * integer nearest x/p (in half way case choose the even one). 19 | * Method : 20 | * Based on fmod() return x-[x/p]chopped*p exactlp. 21 | */ 22 | 23 | #include "fdlibm.h" 24 | 25 | #ifdef __STDC__ 26 | static const double zero = 0.0; 27 | #else 28 | static double zero = 0.0; 29 | #endif 30 | 31 | 32 | #ifdef __STDC__ 33 | double __ieee754_remainder(double x, double p) 34 | #else 35 | double __ieee754_remainder(x,p) 36 | double x,p; 37 | #endif 38 | { 39 | int hx,hp; 40 | unsigned sx,lx,lp; 41 | double p_half; 42 | 43 | hx = __HI(x); /* high word of x */ 44 | lx = __LO(x); /* low word of x */ 45 | hp = __HI(p); /* high word of p */ 46 | lp = __LO(p); /* low word of p */ 47 | sx = hx&0x80000000; 48 | hp &= 0x7fffffff; 49 | hx &= 0x7fffffff; 50 | 51 | /* purge off exception values */ 52 | if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ 53 | if((hx>=0x7ff00000)|| /* x not finite */ 54 | ((hp>=0x7ff00000)&& /* p is NaN */ 55 | (((hp-0x7ff00000)|lp)!=0))) 56 | return (x*p)/(x*p); 57 | 58 | 59 | if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */ 60 | if (((hx-hp)|(lx-lp))==0) return zero*x; 61 | x = fabs(x); 62 | p = fabs(p); 63 | if (hp<0x00200000) { 64 | if(x+x>p) { 65 | x-=p; 66 | if(x+x>=p) x -= p; 67 | } 68 | } else { 69 | p_half = 0.5*p; 70 | if(x>p_half) { 71 | x-=p; 72 | if(x>=p_half) x -= p; 73 | } 74 | } 75 | __HI(x) ^= sx; 76 | return x; 77 | } 78 | -------------------------------------------------------------------------------- /misoc/software/libm/s_tan.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_tan.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* tan(x) 15 | * Return tangent function of x. 16 | * 17 | * kernel function: 18 | * __kernel_tan ... tangent function on [-pi/4,pi/4] 19 | * __ieee754_rem_pio2 ... argument reduction routine 20 | * 21 | * Method. 22 | * Let S,C and T denote the sin, cos and tan respectively on 23 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 24 | * in [-pi/4 , +pi/4], and let n = k mod 4. 25 | * We have 26 | * 27 | * n sin(x) cos(x) tan(x) 28 | * ---------------------------------------------------------- 29 | * 0 S C T 30 | * 1 C -S -1/T 31 | * 2 -S -C T 32 | * 3 -C S -1/T 33 | * ---------------------------------------------------------- 34 | * 35 | * Special cases: 36 | * Let trig be any of sin, cos, or tan. 37 | * trig(+-INF) is NaN, with signals; 38 | * trig(NaN) is that NaN; 39 | * 40 | * Accuracy: 41 | * TRIG(x) returns trig(x) nearly rounded 42 | */ 43 | 44 | #include "fdlibm.h" 45 | 46 | #ifdef __STDC__ 47 | double tan(double x) 48 | #else 49 | double tan(x) 50 | double x; 51 | #endif 52 | { 53 | double y[2],z=0.0; 54 | int n, ix; 55 | 56 | /* High word of x. */ 57 | ix = __HI(x); 58 | 59 | /* |x| ~< pi/4 */ 60 | ix &= 0x7fffffff; 61 | if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); 62 | 63 | /* tan(Inf or NaN) is NaN */ 64 | else if (ix>=0x7ff00000) return x-x; /* NaN */ 65 | 66 | /* argument reduction needed */ 67 | else { 68 | n = __ieee754_rem_pio2(x,y); 69 | return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even 70 | -1 -- n odd */ 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /misoc/software/libm/s_modf.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_modf.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * modf(double x, double *iptr) 16 | * return fraction part of x, and return x's integral part in *iptr. 17 | * Method: 18 | * Bit twiddling. 19 | * 20 | * Exception: 21 | * No exception. 22 | */ 23 | 24 | #include "fdlibm.h" 25 | 26 | #ifdef __STDC__ 27 | static const double one = 1.0; 28 | #else 29 | static double one = 1.0; 30 | #endif 31 | 32 | #ifdef __STDC__ 33 | double modf(double x, double *iptr) 34 | #else 35 | double modf(x, iptr) 36 | double x,*iptr; 37 | #endif 38 | { 39 | int i0,i1,j0; 40 | unsigned i; 41 | i0 = __HI(x); /* high x */ 42 | i1 = __LO(x); /* low x */ 43 | j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ 44 | if(j0<20) { /* integer part in high x */ 45 | if(j0<0) { /* |x|<1 */ 46 | __HIp(iptr) = i0&0x80000000; 47 | __LOp(iptr) = 0; /* *iptr = +-0 */ 48 | return x; 49 | } else { 50 | i = (0x000fffff)>>j0; 51 | if(((i0&i)|i1)==0) { /* x is integral */ 52 | *iptr = x; 53 | __HI(x) &= 0x80000000; 54 | __LO(x) = 0; /* return +-0 */ 55 | return x; 56 | } else { 57 | __HIp(iptr) = i0&(~i); 58 | __LOp(iptr) = 0; 59 | return x - *iptr; 60 | } 61 | } 62 | } else if (j0>51) { /* no fraction part */ 63 | *iptr = x*one; 64 | __HI(x) &= 0x80000000; 65 | __LO(x) = 0; /* return +-0 */ 66 | return x; 67 | } else { /* fraction part in low x */ 68 | i = ((unsigned)(0xffffffff))>>(j0-20); 69 | if((i1&i)==0) { /* x is integral */ 70 | *iptr = x; 71 | __HI(x) &= 0x80000000; 72 | __LO(x) = 0; /* return +-0 */ 73 | return x; 74 | } else { 75 | __HIp(iptr) = i0; 76 | __LOp(iptr) = i1&(~i); 77 | return x - *iptr; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /misoc/cores/coaxpress/core/crc.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | from misoc.interconnect.stream import Endpoint 3 | from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine 4 | from misoc.cores.coaxpress.common import word_layout_dchar, word_width 5 | 6 | 7 | @ResetInserter() 8 | @CEInserter() 9 | class CXPCRC32(Module): 10 | # Section 9.2.2.2 (CXP-001-2021) 11 | width = 32 12 | polynom = 0x04C11DB7 13 | seed = 2**width - 1 14 | check = 0x00000000 15 | 16 | def __init__(self, data_width): 17 | self.data = Signal(data_width) 18 | self.value = Signal(self.width) 19 | self.error = Signal() 20 | 21 | # # # 22 | 23 | self.submodules.engine = LiteEthMACCRCEngine( 24 | data_width, self.width, self.polynom 25 | ) 26 | reg = Signal(self.width, reset=self.seed) 27 | self.sync += reg.eq(self.engine.next) 28 | self.comb += [ 29 | self.engine.data.eq(self.data), 30 | self.engine.last.eq(reg), 31 | self.value.eq(reg[::-1]), 32 | self.error.eq(reg != self.check), 33 | ] 34 | 35 | 36 | class CXPCRC32Checker(Module): 37 | def __init__(self): 38 | self.error = Signal() 39 | 40 | self.sink = Endpoint(word_layout_dchar) 41 | self.source = Endpoint(word_layout_dchar) 42 | 43 | # # # 44 | 45 | self.submodules.crc = crc = CXPCRC32(word_width) 46 | self.comb += crc.data.eq(self.sink.data) 47 | 48 | self.submodules.fsm = fsm = FSM(reset_state="INIT") 49 | fsm.act("INIT", 50 | crc.reset.eq(1), 51 | NextState("CHECKING"), 52 | ) 53 | 54 | fsm.act("RESET", 55 | crc.reset.eq(1), 56 | self.error.eq(crc.error), 57 | NextState("CHECKING"), 58 | ) 59 | 60 | fsm.act("CHECKING", 61 | If(self.sink.stb & self.sink.eop, 62 | # discard the crc 63 | self.sink.ack.eq(1), 64 | NextState("RESET"), 65 | ).Else( 66 | self.sink.connect(self.source), 67 | ), 68 | crc.ce.eq(self.sink.stb & self.source.ack), 69 | ) 70 | 71 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(AddLLVM) # for add_lit_testsuite 2 | macro(pythonize_bool var) 3 | if (${var}) 4 | set(${var} True) 5 | else() 6 | set(${var} False) 7 | endif() 8 | endmacro() 9 | 10 | if (NOT DEFINED LIBCXX_ENABLE_SHARED) 11 | set(LIBCXX_ENABLE_SHARED ON) 12 | endif() 13 | 14 | pythonize_bool(LIBUNWIND_BUILD_32_BITS) 15 | pythonize_bool(LIBCXX_ENABLE_SHARED) 16 | pythonize_bool(LIBUNWIND_ENABLE_SHARED) 17 | pythonize_bool(LIBUNWIND_ENABLE_THREADS) 18 | pythonize_bool(LIBUNWIND_USES_ARM_EHABI) 19 | pythonize_bool(LIBUNWIND_USE_COMPILER_RT) 20 | pythonize_bool(LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY) 21 | set(LIBUNWIND_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING 22 | "TargetInfo to use when setting up test environment.") 23 | set(LIBUNWIND_EXECUTOR "${Python3_EXECUTABLE} ${LIBUNWIND_LIBCXX_PATH}/utils/run.py" CACHE STRING 24 | "Executor to use when running tests.") 25 | 26 | set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not edit!") 27 | set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n") 28 | 29 | macro(serialize_lit_param param value) 30 | string(APPEND SERIALIZED_LIT_PARAMS "config.${param} = ${value}\n") 31 | endmacro() 32 | 33 | serialize_lit_param(enable_experimental False) 34 | 35 | if (LLVM_USE_SANITIZER) 36 | serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"") 37 | endif() 38 | 39 | if (LIBUNWIND_TARGET_TRIPLE) 40 | serialize_lit_param(target_triple "\"${LIBUNWIND_TARGET_TRIPLE}\"") 41 | endif() 42 | 43 | if (LIBUNWIND_BUILD_32_BITS) 44 | serialize_lit_param(enable_32bit True) 45 | endif() 46 | 47 | foreach(param IN LISTS LIBUNWIND_TEST_PARAMS) 48 | string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}") 49 | string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}") 50 | serialize_lit_param("${name}" "\"${value}\"") 51 | endforeach() 52 | 53 | configure_lit_site_cfg( 54 | "${LIBUNWIND_TEST_CONFIG}" 55 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg 56 | MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py") 57 | 58 | add_lit_testsuite(check-unwind "Running libunwind tests" 59 | ${CMAKE_CURRENT_BINARY_DIR} 60 | DEPENDS unwind ${LIBUNWIND_TEST_DEPS}) 61 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/mac/padding.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | from migen import * 4 | 5 | from misoc.interconnect import stream 6 | from misoc.cores.liteeth_mini.common import eth_phy_layout 7 | 8 | 9 | class LiteEthMACPaddingInserter(Module): 10 | def __init__(self, padding): 11 | self.sink = sink = stream.Endpoint(eth_phy_layout(8)) 12 | self.source = source = stream.Endpoint(eth_phy_layout(8)) 13 | 14 | # # # 15 | 16 | counter = Signal(16, reset=1) 17 | counter_done = Signal() 18 | counter_reset = Signal() 19 | counter_ce = Signal() 20 | self.sync += \ 21 | If(counter_reset, 22 | counter.eq(0) 23 | ).Elif(counter_ce, 24 | counter.eq(counter + 1) 25 | ) 26 | self.comb += counter_done.eq(counter >= padding-1) 27 | 28 | self.submodules.fsm = fsm = FSM(reset_state="IDLE") 29 | fsm.act("IDLE", 30 | sink.connect(source), 31 | If(source.stb & source.ack, 32 | counter_ce.eq(1), 33 | If(sink.eop, 34 | If(~counter_done, 35 | source.eop.eq(0), 36 | NextState("PADDING") 37 | ).Else( 38 | counter_reset.eq(1) 39 | ) 40 | ) 41 | ) 42 | ) 43 | fsm.act("PADDING", 44 | source.stb.eq(1), 45 | source.eop.eq(counter_done), 46 | source.data.eq(0), 47 | If(source.stb & source.ack, 48 | counter_ce.eq(1), 49 | If(counter_done, 50 | counter_reset.eq(1), 51 | NextState("IDLE") 52 | ) 53 | ) 54 | ) 55 | 56 | 57 | class LiteEthMACPaddingChecker(Module): 58 | def __init__(self, packet_min_length): 59 | self.sink = sink = stream.Endpoint(eth_phy_layout(8)) 60 | self.source = source = stream.Endpoint(eth_phy_layout(8)) 61 | 62 | # # # 63 | 64 | # TODO: see if we should drop the packet when 65 | # payload size < minimum ethernet payload size 66 | self.comb += sink.connect(source) 67 | 68 | -------------------------------------------------------------------------------- /misoc/software/libm/s_rint.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_rint.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * rint(x) 16 | * Return x rounded to integral value according to the prevailing 17 | * rounding mode. 18 | * Method: 19 | * Using floating addition. 20 | * Exception: 21 | * Inexact flag raised if x not equal to rint(x). 22 | */ 23 | 24 | #include "fdlibm.h" 25 | 26 | #ifdef __STDC__ 27 | static const double 28 | #else 29 | static double 30 | #endif 31 | TWO52[2]={ 32 | 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ 33 | -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ 34 | }; 35 | 36 | #ifdef __STDC__ 37 | double rint(double x) 38 | #else 39 | double rint(x) 40 | double x; 41 | #endif 42 | { 43 | int i0,j0,sx; 44 | unsigned i,i1; 45 | double w,t; 46 | i0 = __HI(x); 47 | sx = (i0>>31)&1; 48 | i1 = __LO(x); 49 | j0 = ((i0>>20)&0x7ff)-0x3ff; 50 | if(j0<20) { 51 | if(j0<0) { 52 | if(((i0&0x7fffffff)|i1)==0) return x; 53 | i1 |= (i0&0x0fffff); 54 | i0 &= 0xfffe0000; 55 | i0 |= ((i1|-i1)>>12)&0x80000; 56 | __HI(x)=i0; 57 | w = TWO52[sx]+x; 58 | t = w-TWO52[sx]; 59 | i0 = __HI(t); 60 | __HI(t) = (i0&0x7fffffff)|(sx<<31); 61 | return t; 62 | } else { 63 | i = (0x000fffff)>>j0; 64 | if(((i0&i)|i1)==0) return x; /* x is integral */ 65 | i>>=1; 66 | if(((i0&i)|i1)!=0) { 67 | if(j0==19) i1 = 0x40000000; else 68 | i0 = (i0&(~i))|((0x20000)>>j0); 69 | } 70 | } 71 | } else if (j0>51) { 72 | if(j0==0x400) return x+x; /* inf or NaN */ 73 | else return x; /* x is integral */ 74 | } else { 75 | i = ((unsigned)(0xffffffff))>>(j0-20); 76 | if((i1&i)==0) return x; /* x is integral */ 77 | i>>=1; 78 | if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); 79 | } 80 | __HI(x) = i0; 81 | __LO(x) = i1; 82 | w = TWO52[sx]+x; 83 | return w-TWO52[sx]; 84 | } 85 | -------------------------------------------------------------------------------- /misoc/software/libbase/system.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifdef __or1k__ 4 | #include 5 | #endif 6 | 7 | #ifdef __vexriscv__ 8 | #include 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void flush_cpu_icache(void) 16 | { 17 | #if defined (__lm32__) 18 | asm volatile( 19 | "wcsr ICC, r0\n" 20 | "nop\n" 21 | "nop\n" 22 | "nop\n" 23 | "nop\n" 24 | ); 25 | #elif defined (__or1k__) 26 | unsigned long iccfgr; 27 | unsigned long cache_set_size; 28 | unsigned long cache_ways; 29 | unsigned long cache_block_size; 30 | unsigned long cache_size; 31 | int i; 32 | 33 | iccfgr = mfspr(SPR_ICCFGR); 34 | cache_ways = 1 << (iccfgr & SPR_ICCFGR_NCW); 35 | cache_set_size = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); 36 | cache_block_size = (iccfgr & SPR_ICCFGR_CBS) ? 32 : 16; 37 | cache_size = cache_set_size * cache_ways * cache_block_size; 38 | 39 | for (i = 0; i < cache_size; i += cache_block_size) 40 | mtspr(SPR_ICBIR, i); 41 | #elif defined (__vexriscv__) 42 | asm volatile( 43 | "fence.i\n" 44 | "nop\n" 45 | "nop\n" 46 | "nop\n" 47 | "nop\n" 48 | "nop\n" 49 | ); 50 | #else 51 | #error Unsupported architecture 52 | #endif 53 | } 54 | 55 | void flush_cpu_dcache(void) 56 | { 57 | #if defined (__lm32__) 58 | asm volatile( 59 | "wcsr DCC, r0\n" 60 | "nop\n" 61 | ); 62 | #elif defined (__or1k__) 63 | unsigned long dccfgr; 64 | unsigned long cache_set_size; 65 | unsigned long cache_ways; 66 | unsigned long cache_block_size; 67 | unsigned long cache_size; 68 | int i; 69 | 70 | dccfgr = mfspr(SPR_DCCFGR); 71 | cache_ways = 1 << (dccfgr & SPR_ICCFGR_NCW); 72 | cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3); 73 | cache_block_size = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16; 74 | cache_size = cache_set_size * cache_ways * cache_block_size; 75 | 76 | for (i = 0; i < cache_size; i += cache_block_size) 77 | mtspr(SPR_DCBIR, i); 78 | #elif defined (__vexriscv__) 79 | asm volatile(".word(0x500F)\n"); 80 | #else 81 | #error Unsupported architecture 82 | #endif 83 | } 84 | 85 | #ifdef CONFIG_L2_SIZE 86 | void flush_l2_cache(void) 87 | { 88 | unsigned int i; 89 | for(i=0;i<2*CONFIG_L2_SIZE/4;i++) { 90 | ((volatile unsigned int *) MAIN_RAM_BASE)[i]; 91 | } 92 | } 93 | #endif 94 | -------------------------------------------------------------------------------- /misoc/software/libm/s_sin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_sin.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* sin(x) 15 | * Return sine function of x. 16 | * 17 | * kernel function: 18 | * __kernel_sin ... sine function on [-pi/4,pi/4] 19 | * __kernel_cos ... cose function on [-pi/4,pi/4] 20 | * __ieee754_rem_pio2 ... argument reduction routine 21 | * 22 | * Method. 23 | * Let S,C and T denote the sin, cos and tan respectively on 24 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 25 | * in [-pi/4 , +pi/4], and let n = k mod 4. 26 | * We have 27 | * 28 | * n sin(x) cos(x) tan(x) 29 | * ---------------------------------------------------------- 30 | * 0 S C T 31 | * 1 C -S -1/T 32 | * 2 -S -C T 33 | * 3 -C S -1/T 34 | * ---------------------------------------------------------- 35 | * 36 | * Special cases: 37 | * Let trig be any of sin, cos, or tan. 38 | * trig(+-INF) is NaN, with signals; 39 | * trig(NaN) is that NaN; 40 | * 41 | * Accuracy: 42 | * TRIG(x) returns trig(x) nearly rounded 43 | */ 44 | 45 | #include "fdlibm.h" 46 | 47 | #ifdef __STDC__ 48 | double sin(double x) 49 | #else 50 | double sin(x) 51 | double x; 52 | #endif 53 | { 54 | double y[2],z=0.0; 55 | int n, ix; 56 | 57 | /* High word of x. */ 58 | ix = __HI(x); 59 | 60 | /* |x| ~< pi/4 */ 61 | ix &= 0x7fffffff; 62 | if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); 63 | 64 | /* sin(Inf or NaN) is NaN */ 65 | else if (ix>=0x7ff00000) return x-x; 66 | 67 | /* argument reduction needed */ 68 | else { 69 | n = __ieee754_rem_pio2(x,y); 70 | switch(n&3) { 71 | case 0: return __kernel_sin(y[0],y[1],1); 72 | case 1: return __kernel_cos(y[0],y[1]); 73 | case 2: return -__kernel_sin(y[0],y[1],1); 74 | default: 75 | return -__kernel_cos(y[0],y[1]); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/frameheadercache_test.pass.cpp: -------------------------------------------------------------------------------- 1 | // The other libunwind tests don't test internal interfaces, so the include path 2 | // is a little wonky. 3 | #include "../src/config.h" 4 | 5 | // Only run this test under supported configurations. 6 | 7 | #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ 8 | defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) 9 | 10 | #include 11 | #include 12 | 13 | // This file defines several of the data structures needed here, 14 | // and includes FrameHeaderCache.hpp as well. 15 | #include "../src/AddressSpace.hpp" 16 | 17 | #define kBaseAddr 0xFFF000 18 | #define kTextSegmentLength 0xFF 19 | 20 | using namespace libunwind; 21 | 22 | int main(int, char**) { 23 | FrameHeaderCache FHC; 24 | struct dl_phdr_info PInfo; 25 | memset(&PInfo, 0, sizeof(PInfo)); 26 | // The cache itself should only care about these two fields--they 27 | // tell the cache to invalidate or not; everything else is handled 28 | // by AddressSpace.hpp. 29 | PInfo.dlpi_adds = 6; 30 | PInfo.dlpi_subs = 7; 31 | 32 | UnwindInfoSections UIS; 33 | UIS.dso_base = kBaseAddr; 34 | UIS.text_segment_length = kTextSegmentLength; 35 | dl_iterate_cb_data CBData; 36 | // Unused by the cache. 37 | CBData.addressSpace = nullptr; 38 | CBData.sects = &UIS; 39 | CBData.targetAddr = kBaseAddr + 1; 40 | 41 | // Nothing present, shouldn't find. 42 | if (FHC.find(&PInfo, 0, &CBData)) 43 | abort(); 44 | FHC.add(&UIS); 45 | // Just added. Should find. 46 | if (!FHC.find(&PInfo, 0, &CBData)) 47 | abort(); 48 | // Cache is invalid. Shouldn't find. 49 | PInfo.dlpi_adds++; 50 | if (FHC.find(&PInfo, 0, &CBData)) 51 | abort(); 52 | 53 | FHC.add(&UIS); 54 | CBData.targetAddr = kBaseAddr - 1; 55 | // Shouldn't find something outside of the addresses. 56 | if (FHC.find(&PInfo, 0, &CBData)) 57 | abort(); 58 | // Add enough things to the cache that the entry is evicted. 59 | for (int i = 0; i < 9; i++) { 60 | UIS.dso_base = kBaseAddr + (kTextSegmentLength * i); 61 | FHC.add(&UIS); 62 | } 63 | CBData.targetAddr = kBaseAddr; 64 | // Should have been evicted. 65 | if (FHC.find(&PInfo, 0, &CBData)) 66 | abort(); 67 | return 0; 68 | } 69 | 70 | #else 71 | int main(int, char**) { return 0;} 72 | #endif 73 | -------------------------------------------------------------------------------- /misoc/software/libm/s_cos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_cos.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* cos(x) 15 | * Return cosine function of x. 16 | * 17 | * kernel function: 18 | * __kernel_sin ... sine function on [-pi/4,pi/4] 19 | * __kernel_cos ... cosine function on [-pi/4,pi/4] 20 | * __ieee754_rem_pio2 ... argument reduction routine 21 | * 22 | * Method. 23 | * Let S,C and T denote the sin, cos and tan respectively on 24 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 25 | * in [-pi/4 , +pi/4], and let n = k mod 4. 26 | * We have 27 | * 28 | * n sin(x) cos(x) tan(x) 29 | * ---------------------------------------------------------- 30 | * 0 S C T 31 | * 1 C -S -1/T 32 | * 2 -S -C T 33 | * 3 -C S -1/T 34 | * ---------------------------------------------------------- 35 | * 36 | * Special cases: 37 | * Let trig be any of sin, cos, or tan. 38 | * trig(+-INF) is NaN, with signals; 39 | * trig(NaN) is that NaN; 40 | * 41 | * Accuracy: 42 | * TRIG(x) returns trig(x) nearly rounded 43 | */ 44 | 45 | #include "fdlibm.h" 46 | 47 | #ifdef __STDC__ 48 | double cos(double x) 49 | #else 50 | double cos(x) 51 | double x; 52 | #endif 53 | { 54 | double y[2],z=0.0; 55 | int n, ix; 56 | 57 | /* High word of x. */ 58 | ix = __HI(x); 59 | 60 | /* |x| ~< pi/4 */ 61 | ix &= 0x7fffffff; 62 | if(ix <= 0x3fe921fb) return __kernel_cos(x,z); 63 | 64 | /* cos(Inf or NaN) is NaN */ 65 | else if (ix>=0x7ff00000) return x-x; 66 | 67 | /* argument reduction needed */ 68 | else { 69 | n = __ieee754_rem_pio2(x,y); 70 | switch(n&3) { 71 | case 0: return __kernel_cos(y[0],y[1]); 72 | case 1: return -__kernel_sin(y[0],y[1],1); 73 | case 2: return -__kernel_cos(y[0],y[1]); 74 | default: 75 | return __kernel_sin(y[0],y[1],1); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /misoc/software/libm/s_nextafter.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_nextafter.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* IEEE functions 15 | * nextafter(x,y) 16 | * return the next machine floating-point number of x in the 17 | * direction toward y. 18 | * Special cases: 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | #ifdef __STDC__ 24 | double nextafter(double x, double y) 25 | #else 26 | double nextafter(x,y) 27 | double x,y; 28 | #endif 29 | { 30 | int hx,hy,ix,iy; 31 | unsigned lx,ly; 32 | 33 | hx = __HI(x); /* high word of x */ 34 | lx = __LO(x); /* low word of x */ 35 | hy = __HI(y); /* high word of y */ 36 | ly = __LO(y); /* low word of y */ 37 | ix = hx&0x7fffffff; /* |x| */ 38 | iy = hy&0x7fffffff; /* |y| */ 39 | 40 | if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ 41 | ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ 42 | return x+y; 43 | if(x==y) return x; /* x=y, return x */ 44 | if((ix|lx)==0) { /* x == 0 */ 45 | __HI(x) = hy&0x80000000; /* return +-minsubnormal */ 46 | __LO(x) = 1; 47 | y = x*x; 48 | if(y==x) return y; else return x; /* raise underflow flag */ 49 | } 50 | if(hx>=0) { /* x > 0 */ 51 | if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ 52 | if(lx==0) hx -= 1; 53 | lx -= 1; 54 | } else { /* x < y, x += ulp */ 55 | lx += 1; 56 | if(lx==0) hx += 1; 57 | } 58 | } else { /* x < 0 */ 59 | if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ 60 | if(lx==0) hx -= 1; 61 | lx -= 1; 62 | } else { /* x > y, x += ulp */ 63 | lx += 1; 64 | if(lx==0) hx += 1; 65 | } 66 | } 67 | hy = hx&0x7ff00000; 68 | if(hy>=0x7ff00000) return x+x; /* overflow */ 69 | if(hy<0x00100000) { /* underflow */ 70 | y = x*x; 71 | if(y!=x) { /* raise underflow flag */ 72 | __HI(y) = hx; __LO(y) = lx; 73 | return y; 74 | } 75 | } 76 | __HI(x) = hx; __LO(x) = lx; 77 | return x; 78 | } 79 | -------------------------------------------------------------------------------- /misoc/software/libm/s_tanh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_tanh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* Tanh(x) 15 | * Return the Hyperbolic Tangent of x 16 | * 17 | * Method : 18 | * x -x 19 | * e - e 20 | * 0. tanh(x) is defined to be ----------- 21 | * x -x 22 | * e + e 23 | * 1. reduce x to non-negative by tanh(-x) = -tanh(x). 24 | * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) 25 | * -t 26 | * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x) 27 | * t + 2 28 | * 2 29 | * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x) 30 | * t + 2 31 | * 22.0 < x <= INF : tanh(x) := 1. 32 | * 33 | * Special cases: 34 | * tanh(NaN) is NaN; 35 | * only tanh(0)=0 is exact for finite argument. 36 | */ 37 | 38 | #include "fdlibm.h" 39 | 40 | #ifdef __STDC__ 41 | static const double one=1.0, two=2.0, tiny = 1.0e-300; 42 | #else 43 | static double one=1.0, two=2.0, tiny = 1.0e-300; 44 | #endif 45 | 46 | #ifdef __STDC__ 47 | double tanh(double x) 48 | #else 49 | double tanh(x) 50 | double x; 51 | #endif 52 | { 53 | double t,z; 54 | int jx,ix; 55 | 56 | /* High word of |x|. */ 57 | jx = __HI(x); 58 | ix = jx&0x7fffffff; 59 | 60 | /* x is INF or NaN */ 61 | if(ix>=0x7ff00000) { 62 | if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ 63 | else return one/x-one; /* tanh(NaN) = NaN */ 64 | } 65 | 66 | /* |x| < 22 */ 67 | if (ix < 0x40360000) { /* |x|<22 */ 68 | if (ix<0x3c800000) /* |x|<2**-55 */ 69 | return x*(one+x); /* tanh(small) = small */ 70 | if (ix>=0x3ff00000) { /* |x|>=1 */ 71 | t = expm1(two*fabs(x)); 72 | z = one - two/(t+two); 73 | } else { 74 | t = expm1(-two*fabs(x)); 75 | z= -t/(t+two); 76 | } 77 | /* |x| > 22, return +-1 */ 78 | } else { 79 | z = one - tiny; /* raised inexact flag */ 80 | } 81 | return (jx>=0)? z: -z; 82 | } 83 | -------------------------------------------------------------------------------- /misoc/cores/liteeth_mini/README: -------------------------------------------------------------------------------- 1 | __ _ __ ______ __ __ ____ _ 2 | / / (_) /____ / __/ /_/ / / |/ (_)__ (_) 3 | / /__/ / __/ -_) _// __/ _ \/ /|_/ / / _ \/ / 4 | /____/_/\__/\__/___/\__/_//_/_/ /_/_/_//_/_/ 5 | 6 | Copyright 2012-2015 / EnjoyDigital / M-Labs Ltd 7 | 8 | A small footprint and configurable minimal Ethernet core 9 | powered by Migen 10 | 11 | [> Intro 12 | --------- 13 | LiteEthMini is a subset of LiteEth (https://github.com/enjoy-digital/liteeth) 14 | intended to be used with a CPU and a software stack. 15 | 16 | [> Features 17 | ----------- 18 | - Ethernet MAC with various PHYs (GMII, MII, RGMII, Loopback) 19 | - SRAM storage and wishbone interface 20 | 21 | [> Possible improvements 22 | ------------------------- 23 | - add DMA interface to MAC 24 | - add SGMII PHY 25 | - ... See below Support and consulting :) 26 | 27 | If you want to support these features, please contact us at florent [AT] 28 | enjoy-digital.fr. You can also contact our partner on the public mailing list 29 | devel [AT] lists.m-labs.hk. 30 | 31 | [> License 32 | ----------- 33 | LiteEthMini is released under the very permissive two-clause BSD license. Under 34 | the terms of this license, you are authorized to use LiteEthMini for closed-source 35 | proprietary designs. 36 | Even though we do not require you to do so, those things are awesome, so please 37 | do them if possible: 38 | - tell us that you are using LiteEthMini 39 | - cite LiteEthMini in publications related to research it has helped 40 | - send us feedback and suggestions for improvements 41 | - send us bug reports when something goes wrong 42 | - send us the modifications and improvements you have done to LiteEthMini. 43 | 44 | [> Support and consulting 45 | -------------------------- 46 | We love open-source hardware and like sharing our designs with others. 47 | 48 | LiteEthMini is mainly developed and maintained by EnjoyDigital. 49 | 50 | If you would like to know more about LiteEthMini or if you are already a happy 51 | user and would like to extend it for your needs, EnjoyDigital can provide standard 52 | commercial support as well as consulting services. 53 | 54 | So feel free to contact us, we'd love to work with you! (and eventually shorten 55 | the list of the possible improvements :) 56 | 57 | [> Contact 58 | E-mail: florent [AT] enjoy-digital.fr -------------------------------------------------------------------------------- /misoc/software/include/base/irq.h: -------------------------------------------------------------------------------- 1 | #ifndef __IRQ_H 2 | #define __IRQ_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | static inline unsigned int irq_getie(void) 11 | { 12 | #if defined (__lm32__) 13 | unsigned int ie; 14 | __asm__ __volatile__("rcsr %0, IE" : "=r" (ie)); 15 | return ie; 16 | #elif defined (__or1k__) 17 | return !!(mfspr(SPR_SR) & SPR_SR_IEE); 18 | #elif defined (__vexriscv__) 19 | return (csrr(mstatus) & CSR_MSTATUS_MIE) != 0; 20 | #else 21 | #error Unsupported architecture 22 | #endif 23 | } 24 | 25 | static inline void irq_setie(unsigned int ie) 26 | { 27 | #if defined (__lm32__) 28 | __asm__ __volatile__("wcsr IE, %0" : : "r" (ie)); 29 | #elif defined (__or1k__) 30 | if (ie & 0x1) 31 | mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE); 32 | else 33 | mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE); 34 | #elif defined (__vexriscv__) 35 | if(ie) csrs(mstatus,CSR_MSTATUS_MIE); else csrc(mstatus,CSR_MSTATUS_MIE); 36 | #else 37 | #error Unsupported architecture 38 | #endif 39 | } 40 | 41 | static inline unsigned int irq_getmask(void) 42 | { 43 | #if defined (__lm32__) 44 | unsigned int mask; 45 | __asm__ __volatile__("rcsr %0, IM" : "=r" (mask)); 46 | return mask; 47 | #elif defined (__or1k__) 48 | return mfspr(SPR_PICMR); 49 | #elif defined (__vexriscv__) 50 | unsigned int mask; 51 | asm volatile ("csrr %0, %1" : "=r"(mask) : "i"(CSR_IRQ_MASK)); 52 | return mask; 53 | #else 54 | #error Unsupported architecture 55 | #endif 56 | } 57 | 58 | static inline void irq_setmask(unsigned int mask) 59 | { 60 | #if defined (__lm32__) 61 | __asm__ __volatile__("wcsr IM, %0" : : "r" (mask)); 62 | #elif defined (__or1k__) 63 | mtspr(SPR_PICMR, mask); 64 | #elif defined (__vexriscv__) 65 | asm volatile ("csrw %0, %1" :: "i"(CSR_IRQ_MASK), "r"(mask)); 66 | #else 67 | #error Unsupported architecture 68 | #endif 69 | } 70 | 71 | static inline unsigned int irq_pending(void) 72 | { 73 | #if defined (__lm32__) 74 | unsigned int pending; 75 | __asm__ __volatile__("rcsr %0, IP" : "=r" (pending)); 76 | return pending; 77 | #elif defined (__or1k__) 78 | return mfspr(SPR_PICSR); 79 | #elif defined (__vexriscv__) 80 | unsigned int pending; 81 | asm volatile ("csrr %0, %1" : "=r"(pending) : "i"(CSR_IRQ_PENDING)); 82 | return pending; 83 | #else 84 | #error Unsupported architecture 85 | #endif 86 | } 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __IRQ_H */ 93 | -------------------------------------------------------------------------------- /misoc/test/test_sequencer.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from migen import * 4 | 5 | from misoc.cores.sequencer import * 6 | 7 | 8 | class TestSequencer(unittest.TestCase): 9 | def test_sequencer(self): 10 | program = [ 11 | InstWrite(0, 0xaa), 12 | InstWrite(1, 0x55), 13 | InstWait(0, 0x01), 14 | InstWait(0, 0x10), 15 | InstEnd() 16 | ] 17 | dut = Sequencer(program) 18 | 19 | def wait(): 20 | timeout = 0 21 | while not ((yield dut.bus.cyc) and (yield dut.bus.stb)): 22 | timeout += 1 23 | assert timeout < 20 24 | yield 25 | return ( 26 | (yield dut.bus.we), 27 | (yield dut.bus.adr), 28 | (yield dut.bus.dat_w)) 29 | 30 | def ack(data=None): 31 | if data is not None: 32 | yield dut.bus.dat_r.eq(data) 33 | yield dut.bus.ack.eq(1) 34 | yield 35 | yield dut.bus.ack.eq(0) 36 | yield 37 | 38 | def check(): 39 | for inst_ip, inst in enumerate(program): 40 | if isinstance(inst, InstWrite): 41 | we, a, d = yield from wait() 42 | self.assertTrue(we) 43 | self.assertEqual(a, inst.address) 44 | self.assertEqual(d, inst.data) 45 | yield from ack() 46 | elif isinstance(inst, InstWait): 47 | pos_val = inst.mask 48 | neg_val = 0x00 49 | for _ in range(3): 50 | we, a, d = yield from wait() 51 | self.assertFalse(we) 52 | self.assertEqual(a, inst.address) 53 | yield from ack(neg_val) 54 | we, a, d = yield from wait() 55 | self.assertFalse(we) 56 | self.assertEqual(a, inst.address) 57 | yield from ack(pos_val) 58 | elif isinstance(inst, InstEnd): 59 | for _ in range(20): 60 | self.assertFalse(((yield dut.bus.cyc) 61 | and (yield dut.bus.stb))) 62 | return 63 | else: 64 | raise ValueError 65 | 66 | run_simulation(dut, check()) 67 | -------------------------------------------------------------------------------- /misoc/software/libm/s_cbrt.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)s_cbrt.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | #include "fdlibm.h" 16 | 17 | /* cbrt(x) 18 | * Return cube root of x 19 | */ 20 | #ifdef __STDC__ 21 | static const unsigned 22 | #else 23 | static unsigned 24 | #endif 25 | B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */ 26 | B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */ 27 | 28 | #ifdef __STDC__ 29 | static const double 30 | #else 31 | static double 32 | #endif 33 | C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */ 34 | D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */ 35 | E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */ 36 | F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */ 37 | G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */ 38 | 39 | #ifdef __STDC__ 40 | double cbrt(double x) 41 | #else 42 | double cbrt(x) 43 | double x; 44 | #endif 45 | { 46 | int hx; 47 | double r,s,t=0.0,w; 48 | unsigned sign; 49 | 50 | 51 | hx = __HI(x); /* high word of x */ 52 | sign=hx&0x80000000; /* sign= sign(x) */ 53 | hx ^=sign; 54 | if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ 55 | if((hx|__LO(x))==0) 56 | return(x); /* cbrt(0) is itself */ 57 | 58 | __HI(x) = hx; /* x <- |x| */ 59 | /* rough cbrt to 5 bits */ 60 | if(hx<0x00100000) /* subnormal number */ 61 | {__HI(t)=0x43500000; /* set t= 2**54 */ 62 | t*=x; __HI(t)=__HI(t)/3+B2; 63 | } 64 | else 65 | __HI(t)=hx/3+B1; 66 | 67 | 68 | /* new cbrt to 23 bits, may be implemented in single precision */ 69 | r=t*t/x; 70 | s=C+r*t; 71 | t*=G+F/(s+E+D/s); 72 | 73 | /* chopped to 20 bits and make it larger than cbrt(x) */ 74 | __LO(t)=0; __HI(t)+=0x00000001; 75 | 76 | 77 | /* one step newton iteration to 53 bits with error less than 0.667 ulps */ 78 | s=t*t; /* t*t is exact */ 79 | r=x/s; 80 | w=t+t; 81 | r=(r-t)/(w+r); /* r-s is exact */ 82 | t=t+t*r; 83 | 84 | /* retore the sign bit */ 85 | __HI(t) |= sign; 86 | return(t); 87 | } 88 | -------------------------------------------------------------------------------- /misoc/software/unwinder/src/libunwind_ext.h: -------------------------------------------------------------------------------- 1 | //===------------------------ libunwind_ext.h -----------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | // 8 | // Extensions to libunwind API. 9 | // 10 | //===----------------------------------------------------------------------===// 11 | 12 | #ifndef __LIBUNWIND_EXT__ 13 | #define __LIBUNWIND_EXT__ 14 | 15 | #include "config.h" 16 | #include 17 | #include 18 | 19 | #define UNW_STEP_SUCCESS 1 20 | #define UNW_STEP_END 0 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | extern int __unw_getcontext(unw_context_t *); 27 | extern int __unw_init_local(unw_cursor_t *, unw_context_t *); 28 | extern int __unw_step(unw_cursor_t *); 29 | extern int __unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *); 30 | extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *); 31 | extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t); 32 | extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t); 33 | extern int __unw_resume(unw_cursor_t *); 34 | 35 | #ifdef __arm__ 36 | /* Save VFP registers in FSTMX format (instead of FSTMD). */ 37 | extern void __unw_save_vfp_as_X(unw_cursor_t *); 38 | #endif 39 | 40 | extern const char *__unw_regname(unw_cursor_t *, unw_regnum_t); 41 | extern int __unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *); 42 | extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t); 43 | extern int __unw_is_signal_frame(unw_cursor_t *); 44 | extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *); 45 | 46 | // SPI 47 | extern void __unw_iterate_dwarf_unwind_cache(void (*func)( 48 | unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)); 49 | 50 | // IPI 51 | extern void __unw_add_dynamic_fde(unw_word_t fde); 52 | extern void __unw_remove_dynamic_fde(unw_word_t fde); 53 | 54 | #if defined(_LIBUNWIND_ARM_EHABI) 55 | extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); 56 | extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, 57 | const uint32_t *data, 58 | size_t offset, size_t len); 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif // __LIBUNWIND_EXT__ 66 | -------------------------------------------------------------------------------- /misoc/cores/lm32/core.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from migen import * 4 | 5 | from misoc.interconnect import wishbone 6 | 7 | 8 | class LM32(Module): 9 | def __init__(self, platform, eba_reset): 10 | self.ibus = i = wishbone.Interface() 11 | self.dbus = d = wishbone.Interface() 12 | self.interrupt = Signal(32) 13 | self.endianness = "big" 14 | 15 | ### 16 | 17 | i_adr_o = Signal(32) 18 | d_adr_o = Signal(32) 19 | self.specials += Instance("lm32_cpu", 20 | p_eba_reset=Instance.PreformattedParam("32'h{:08x}".format(eba_reset)), 21 | 22 | i_clk_i=ClockSignal(), 23 | i_rst_i=ResetSignal(), 24 | 25 | i_interrupt=self.interrupt, 26 | 27 | o_I_ADR_O=i_adr_o, 28 | o_I_DAT_O=i.dat_w, 29 | o_I_SEL_O=i.sel, 30 | o_I_CYC_O=i.cyc, 31 | o_I_STB_O=i.stb, 32 | o_I_WE_O=i.we, 33 | o_I_CTI_O=i.cti, 34 | o_I_BTE_O=i.bte, 35 | i_I_DAT_I=i.dat_r, 36 | i_I_ACK_I=i.ack, 37 | i_I_ERR_I=i.err, 38 | i_I_RTY_I=0, 39 | 40 | o_D_ADR_O=d_adr_o, 41 | o_D_DAT_O=d.dat_w, 42 | o_D_SEL_O=d.sel, 43 | o_D_CYC_O=d.cyc, 44 | o_D_STB_O=d.stb, 45 | o_D_WE_O=d.we, 46 | o_D_CTI_O=d.cti, 47 | o_D_BTE_O=d.bte, 48 | i_D_DAT_I=d.dat_r, 49 | i_D_ACK_I=d.ack, 50 | i_D_ERR_I=d.err, 51 | i_D_RTY_I=0) 52 | 53 | self.comb += [ 54 | self.ibus.adr.eq(i_adr_o[2:]), 55 | self.dbus.adr.eq(d_adr_o[2:]) 56 | ] 57 | 58 | # add Verilog sources 59 | vdir = os.path.join( 60 | os.path.abspath(os.path.dirname(__file__)), "verilog") 61 | platform.add_source_dir(os.path.join(vdir, "submodule", "rtl")) 62 | -------------------------------------------------------------------------------- /misoc/software/libbase/crc16.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static const unsigned int crc16_table[256] = { 4 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 5 | 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 6 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 7 | 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 8 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 9 | 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 10 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 11 | 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 12 | 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 13 | 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, 14 | 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 15 | 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, 16 | 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 17 | 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 18 | 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 19 | 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 20 | 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 21 | 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, 22 | 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 23 | 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, 24 | 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 25 | 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 26 | 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 27 | 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, 28 | 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 29 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, 30 | 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 31 | 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 32 | 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 33 | 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 34 | 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 35 | 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 36 | }; 37 | 38 | unsigned short crc16(const unsigned char *buffer, int len) 39 | { 40 | unsigned short crc; 41 | 42 | crc = 0; 43 | while(len-- > 0) 44 | crc = crc16_table[((crc >> 8) ^ (*buffer++)) & 0xFF] ^ (crc << 8); 45 | 46 | return crc; 47 | } 48 | -------------------------------------------------------------------------------- /misoc/software/libm/e_sinh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_sinh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* __ieee754_sinh(x) 15 | * Method : 16 | * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 17 | * 1. Replace x by |x| (sinh(-x) = -sinh(x)). 18 | * 2. 19 | * E + E/(E+1) 20 | * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) 21 | * 2 22 | * 23 | * 22 <= x <= lnovft : sinh(x) := exp(x)/2 24 | * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) 25 | * ln2ovft < x : sinh(x) := x*shuge (overflow) 26 | * 27 | * Special cases: 28 | * sinh(x) is |x| if x is +INF, -INF, or NaN. 29 | * only sinh(0)=0 is exact for finite x. 30 | */ 31 | 32 | #include "fdlibm.h" 33 | 34 | #ifdef __STDC__ 35 | static const double one = 1.0, shuge = 1.0e307; 36 | #else 37 | static double one = 1.0, shuge = 1.0e307; 38 | #endif 39 | 40 | #ifdef __STDC__ 41 | double __ieee754_sinh(double x) 42 | #else 43 | double __ieee754_sinh(x) 44 | double x; 45 | #endif 46 | { 47 | double t,w,h; 48 | int ix,jx; 49 | unsigned lx; 50 | 51 | /* High word of |x|. */ 52 | jx = __HI(x); 53 | ix = jx&0x7fffffff; 54 | 55 | /* x is INF or NaN */ 56 | if(ix>=0x7ff00000) return x+x; 57 | 58 | h = 0.5; 59 | if (jx<0) h = -h; 60 | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ 61 | if (ix < 0x40360000) { /* |x|<22 */ 62 | if (ix<0x3e300000) /* |x|<2**-28 */ 63 | if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ 64 | t = expm1(fabs(x)); 65 | if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); 66 | return h*(t+t/(t+one)); 67 | } 68 | 69 | /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ 70 | if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); 71 | 72 | /* |x| in [log(maxdouble), overflowthresold] */ 73 | lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x); 74 | if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) { 75 | w = __ieee754_exp(0.5*fabs(x)); 76 | t = h*w; 77 | return t*w; 78 | } 79 | 80 | /* |x| > overflowthresold, sinh(x) overflow */ 81 | return x*shuge; 82 | } 83 | -------------------------------------------------------------------------------- /misoc/targets/simple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import importlib 5 | 6 | from migen import * 7 | from migen.genlib.io import CRG 8 | 9 | from misoc.cores.liteeth_mini.phy import LiteEthPHY 10 | from misoc.cores.liteeth_mini.mac import LiteEthMAC 11 | from misoc.integration.soc_core import * 12 | from misoc.integration.builder import * 13 | 14 | 15 | class BaseSoC(SoCCore): 16 | def __init__(self, platform, **kwargs): 17 | SoCCore.__init__(self, platform, 18 | clk_freq=int((1/(platform.default_clk_period))*1000000000), 19 | integrated_rom_size=0x8000, 20 | integrated_main_ram_size=16*1024, 21 | **kwargs) 22 | self.submodules.crg = CRG(platform.request(platform.default_clk_name)) 23 | 24 | 25 | class MiniSoC(BaseSoC): 26 | mem_map = { 27 | "ethmac": 0x30000000, # (shadow @0xb0000000) 28 | } 29 | mem_map.update(BaseSoC.mem_map) 30 | 31 | def __init__(self, platform, **kwargs): 32 | BaseSoC.__init__(self, platform, **kwargs) 33 | 34 | self.submodules.ethphy = LiteEthPHY(platform.request("eth_clocks"), 35 | platform.request("eth")) 36 | self.submodules.ethmac = LiteEthMAC(phy=self.ethphy, dw=self.cpu_dw, 37 | interface="wishbone", 38 | endianness=self.cpu.endianness, 39 | with_preamble_crc=False) 40 | self.add_wb_slave(self.mem_map["ethmac"], 0x2000, self.ethmac.bus) 41 | self.add_memory_region("ethmac", self.mem_map["ethmac"] | self.shadow_base, 0x2000) 42 | self.csr_devices += ["ethphy", "ethmac"] 43 | self.interrupt_devices.append("ethmac") 44 | 45 | 46 | def main(): 47 | parser = argparse.ArgumentParser(description="Generic MiSoC port") 48 | builder_args(parser) 49 | soc_core_args(parser) 50 | parser.add_argument("--with-ethernet", action="store_true", 51 | help="enable Ethernet support") 52 | parser.add_argument("platform", 53 | help="module name of the Migen platform to build for") 54 | args = parser.parse_args() 55 | 56 | platform_module = importlib.import_module(args.platform) 57 | platform = platform_module.Platform() 58 | cls = MiniSoC if args.with_ethernet else BaseSoC 59 | soc = cls(platform, **soc_core_argdict(args)) 60 | builder = Builder(soc, **builder_argdict(args)) 61 | builder.build() 62 | 63 | 64 | if __name__ == "__main__": 65 | main() 66 | -------------------------------------------------------------------------------- /misoc/software/unwinder/test/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | @AUTO_GEN_COMMENT@ 2 | 3 | @SERIALIZED_LIT_PARAMS@ 4 | 5 | import os 6 | import site 7 | 8 | config.cxx_under_test = "@CMAKE_CXX_COMPILER@" 9 | config.project_obj_root = "@CMAKE_BINARY_DIR@" 10 | config.libunwind_src_root = "@LIBUNWIND_SOURCE_DIR@" 11 | config.libunwind_obj_root = "@LIBUNWIND_BINARY_DIR@" 12 | config.abi_library_root = "@LIBUNWIND_LIBRARY_DIR@" 13 | config.libcxx_src_root = "@LIBUNWIND_LIBCXX_PATH@" 14 | config.libunwind_headers = "@LIBUNWIND_SOURCE_DIR@/include" 15 | config.cxx_library_root = "@LIBUNWIND_LIBCXX_LIBRARY_PATH@" 16 | config.llvm_unwinder = True 17 | config.builtins_library = "@LIBUNWIND_BUILTINS_LIBRARY@" 18 | config.enable_threads = @LIBUNWIND_ENABLE_THREADS@ 19 | config.target_info = "@LIBUNWIND_TARGET_INFO@" 20 | config.test_linker_flags = "@LIBUNWIND_TEST_LINKER_FLAGS@" 21 | config.test_compiler_flags = "@LIBUNWIND_TEST_COMPILER_FLAGS@" 22 | config.executor = "@LIBUNWIND_EXECUTOR@" 23 | config.libunwind_shared = @LIBUNWIND_ENABLE_SHARED@ 24 | config.enable_shared = @LIBCXX_ENABLE_SHARED@ 25 | config.arm_ehabi = @LIBUNWIND_USES_ARM_EHABI@ 26 | config.host_triple = "@LLVM_HOST_TRIPLE@" 27 | config.sysroot = "@LIBUNWIND_SYSROOT@" 28 | config.gcc_toolchain = "@LIBUNWIND_GCC_TOOLCHAIN@" 29 | config.cxx_ext_threads = @LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY@ 30 | 31 | site.addsitedir(os.path.join(config.libunwind_src_root, 'test')) 32 | site.addsitedir(os.path.join(config.libcxx_src_root, 'utils')) 33 | 34 | # name: The name of this test suite. 35 | config.name = 'libunwind' 36 | 37 | # suffixes: A list of file extensions to treat as test files. 38 | config.suffixes = ['.cpp', '.s'] 39 | 40 | # test_source_root: The root path where tests are located. 41 | config.test_source_root = os.path.join(config.libunwind_src_root, 'test') 42 | 43 | # Allow expanding substitutions that are based on other substitutions 44 | config.recursiveExpansionLimit = 10 45 | 46 | # Infer the test_exec_root from the build directory. 47 | config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test') 48 | 49 | import libcxx.test.format 50 | config.test_format = libcxx.test.format.CxxStandardLibraryTest() 51 | 52 | lit_config.note('Using configuration variant: libunwind') 53 | import libunwind.test.config 54 | configuration = libunwind.test.config.Configuration(lit_config, config) 55 | configuration.configure() 56 | configuration.print_config_info() 57 | -------------------------------------------------------------------------------- /misoc/software/include/base/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MiSoC 3 | * Copyright (C) 2007, 2008, 2009, 2011 Sebastien Bourdeauducq 4 | * Copyright (C) Linux kernel developers 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __STDLIB_H 20 | #define __STDLIB_H 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define PRINTF_ZEROPAD 1 /* pad with zero */ 29 | #define PRINTF_SIGN 2 /* unsigned/signed long */ 30 | #define PRINTF_PLUS 4 /* show plus */ 31 | #define PRINTF_SPACE 8 /* space if plus */ 32 | #define PRINTF_LEFT 16 /* left justified */ 33 | #define PRINTF_SPECIAL 32 /* 0x */ 34 | #define PRINTF_LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ 35 | 36 | #define likely(x) x 37 | #define unlikely(x) x 38 | 39 | static inline int abs(int x) 40 | { 41 | return x > 0 ? x : -x; 42 | } 43 | 44 | static inline long int labs(long int x) 45 | { 46 | return x > 0 ? x : -x; 47 | } 48 | 49 | unsigned long strtoul(const char *nptr, char **endptr, int base); 50 | long strtol(const char *nptr, char **endptr, int base); 51 | double strtod(const char *str, char **endptr); 52 | 53 | static inline int atoi(const char *nptr) { 54 | return strtol(nptr, NULL, 10); 55 | } 56 | static inline long atol(const char *nptr) { 57 | return (long)atoi(nptr); 58 | } 59 | 60 | #define RAND_MAX 2147483647 61 | 62 | unsigned int rand(void); 63 | void srand(unsigned int seed); 64 | void abort(void) __attribute__((noreturn)); 65 | 66 | void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); 67 | 68 | /* 69 | * The following functions are not provided by this library. 70 | */ 71 | 72 | char *getenv(const char *name); 73 | 74 | #ifdef __GNUC__ 75 | #define alloca(size) __builtin_alloca (size) 76 | #endif 77 | 78 | void *malloc(size_t size); 79 | void *calloc(size_t nmemb, size_t size); 80 | void free(void *ptr); 81 | void *realloc(void *ptr, size_t size); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* __STDLIB_H */ 88 | -------------------------------------------------------------------------------- /misoc/cores/dfii.py: -------------------------------------------------------------------------------- 1 | from migen import * 2 | 3 | from misoc.interconnect import dfi 4 | from misoc.interconnect.csr import * 5 | 6 | 7 | class PhaseInjector(Module, AutoCSR): 8 | def __init__(self, phase): 9 | self._command = CSRStorage(6) # cs, we, cas, ras, wren, rden 10 | self._command_issue = CSR() 11 | self._address = CSRStorage(len(phase.address)) 12 | self._baddress = CSRStorage(len(phase.bank)) 13 | self._wrdata = CSRStorage(len(phase.wrdata)) 14 | self._rddata = CSRStatus(len(phase.rddata)) 15 | 16 | ### 17 | 18 | self.comb += [ 19 | If(self._command_issue.re, 20 | phase.cs_n.eq(~self._command.storage[0]), 21 | phase.we_n.eq(~self._command.storage[1]), 22 | phase.cas_n.eq(~self._command.storage[2]), 23 | phase.ras_n.eq(~self._command.storage[3]) 24 | ).Else( 25 | phase.cs_n.eq(1), 26 | phase.we_n.eq(1), 27 | phase.cas_n.eq(1), 28 | phase.ras_n.eq(1) 29 | ), 30 | phase.address.eq(self._address.storage), 31 | phase.bank.eq(self._baddress.storage), 32 | phase.wrdata_en.eq(self._command_issue.re & self._command.storage[4]), 33 | phase.rddata_en.eq(self._command_issue.re & self._command.storage[5]), 34 | phase.wrdata.eq(self._wrdata.storage), 35 | phase.wrdata_mask.eq(0) 36 | ] 37 | self.sync += If(phase.rddata_valid, self._rddata.status.eq(phase.rddata)) 38 | 39 | 40 | class DFIInjector(Module, AutoCSR): 41 | def __init__(self, addressbits, bankbits, databits, nphases=1): 42 | inti = dfi.Interface(addressbits, bankbits, databits, nphases) 43 | self.slave = dfi.Interface(addressbits, bankbits, databits, nphases) 44 | self.master = dfi.Interface(addressbits, bankbits, databits, nphases) 45 | 46 | self._control = CSRStorage(4) # sel, cke, odt, reset_n 47 | 48 | for n, phase in enumerate(inti.phases): 49 | setattr(self.submodules, "pi" + str(n), PhaseInjector(phase)) 50 | 51 | ### 52 | 53 | self.comb += If(self._control.storage[0], 54 | self.slave.connect(self.master) 55 | ).Else( 56 | inti.connect(self.master) 57 | ) 58 | self.comb += [phase.cke.eq(self._control.storage[1]) for phase in inti.phases] 59 | self.comb += [phase.odt.eq(self._control.storage[2]) for phase in inti.phases if hasattr(phase, "odt")] 60 | self.comb += [phase.reset_n.eq(self._control.storage[3]) for phase in inti.phases if hasattr(phase, "reset_n")] 61 | -------------------------------------------------------------------------------- /misoc/software/libm/k_sin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)k_sin.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* __kernel_sin( x, y, iy) 15 | * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 16 | * Input x is assumed to be bounded by ~pi/4 in magnitude. 17 | * Input y is the tail of x. 18 | * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). 19 | * 20 | * Algorithm 21 | * 1. Since sin(-x) = -sin(x), we need only to consider positive x. 22 | * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. 23 | * 3. sin(x) is approximated by a polynomial of degree 13 on 24 | * [0,pi/4] 25 | * 3 13 26 | * sin(x) ~ x + S1*x + ... + S6*x 27 | * where 28 | * 29 | * |sin(x) 2 4 6 8 10 12 | -58 30 | * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 31 | * | x | 32 | * 33 | * 4. sin(x+y) = sin(x) + sin'(x')*y 34 | * ~ sin(x) + (1-x*x/2)*y 35 | * For better accuracy, let 36 | * 3 2 2 2 2 37 | * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) 38 | * then 3 2 39 | * sin(x) = x + (S1*x + (x *(r-y/2)+y)) 40 | */ 41 | 42 | #include "fdlibm.h" 43 | 44 | #ifdef __STDC__ 45 | static const double 46 | #else 47 | static double 48 | #endif 49 | half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ 50 | S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ 51 | S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ 52 | S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ 53 | S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ 54 | S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ 55 | S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ 56 | 57 | #ifdef __STDC__ 58 | double __kernel_sin(double x, double y, int iy) 59 | #else 60 | double __kernel_sin(x, y, iy) 61 | double x,y; int iy; /* iy=0 if y is zero */ 62 | #endif 63 | { 64 | double z,r,v; 65 | int ix; 66 | ix = __HI(x)&0x7fffffff; /* high word of x */ 67 | if(ix<0x3e400000) /* |x| < 2**-27 */ 68 | {if((int)x==0) return x;} /* generate inexact */ 69 | z = x*x; 70 | v = z*x; 71 | r = S2+z*(S3+z*(S4+z*(S5+z*S6))); 72 | if(iy==0) return x+v*(S1+z*r); 73 | else return x-((z*(half*y-v*r)-y)-v*S1); 74 | } 75 | -------------------------------------------------------------------------------- /misoc/cores/vexriscv/core.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from migen import * 4 | 5 | from misoc.interconnect import wishbone 6 | 7 | 8 | class VexRiscv(Module): 9 | def __init__(self, platform, cpu_reset_address, variant="VexRiscv_IMA"): 10 | cpu_dw = { 11 | "VexRiscv_G" : 64, 12 | "VexRiscv_IMA" : 32, 13 | "VexRiscv_IMA_wide" : 64 14 | }[variant] 15 | adr_width = 32-log2_int(cpu_dw//8) 16 | 17 | self.ibus = i = wishbone.Interface(data_width=cpu_dw, adr_width=adr_width) 18 | self.dbus = d = wishbone.Interface(data_width=cpu_dw, adr_width=adr_width) 19 | self.endianness = "little" 20 | 21 | self.interrupt = Signal(32) 22 | 23 | self.specials += Instance(variant, 24 | i_clk=ClockSignal(), 25 | i_reset=ResetSignal(), 26 | 27 | i_externalResetVector=cpu_reset_address, 28 | i_externalInterruptArray=self.interrupt, 29 | i_timerInterrupt=0, 30 | 31 | o_iBusWishbone_ADR=i.adr, 32 | o_iBusWishbone_DAT_MOSI=i.dat_w, 33 | o_iBusWishbone_SEL=i.sel, 34 | o_iBusWishbone_CYC=i.cyc, 35 | o_iBusWishbone_STB=i.stb, 36 | o_iBusWishbone_WE=i.we, 37 | o_iBusWishbone_CTI=i.cti, 38 | o_iBusWishbone_BTE=i.bte, 39 | i_iBusWishbone_DAT_MISO=i.dat_r, 40 | i_iBusWishbone_ACK=i.ack, 41 | i_iBusWishbone_ERR=i.err, 42 | 43 | o_dBusWishbone_ADR=d.adr, 44 | o_dBusWishbone_DAT_MOSI=d.dat_w, 45 | o_dBusWishbone_SEL=d.sel, 46 | o_dBusWishbone_CYC=d.cyc, 47 | o_dBusWishbone_STB=d.stb, 48 | o_dBusWishbone_WE=d.we, 49 | o_dBusWishbone_CTI=d.cti, 50 | o_dBusWishbone_BTE=d.bte, 51 | i_dBusWishbone_DAT_MISO=d.dat_r, 52 | i_dBusWishbone_ACK=d.ack, 53 | i_dBusWishbone_ERR=d.err) 54 | 55 | # add Verilog sources 56 | vdir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "verilog") 57 | platform.add_source(os.path.join(vdir, variant+".v")) 58 | -------------------------------------------------------------------------------- /misoc/software/libm/w_jn.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)w_jn.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | */ 13 | 14 | /* 15 | * wrapper jn(int n, double x), yn(int n, double x) 16 | * floating point Bessel's function of the 1st and 2nd kind 17 | * of order n 18 | * 19 | * Special cases: 20 | * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; 21 | * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. 22 | * Note 2. About jn(n,x), yn(n,x) 23 | * For n=0, j0(x) is called, 24 | * for n=1, j1(x) is called, 25 | * for nx, a continued fraction approximation to 28 | * j(n,x)/j(n-1,x) is evaluated and then backward 29 | * recursion is used starting from a supposed value 30 | * for j(n,x). The resulting value of j(0,x) is 31 | * compared with the actual value to correct the 32 | * supposed value of j(n,x). 33 | * 34 | * yn(n,x) is similar in all respects, except 35 | * that forward recursion is used for all 36 | * values of n>1. 37 | * 38 | */ 39 | 40 | #include "fdlibm.h" 41 | 42 | #ifdef __STDC__ 43 | double jn(int n, double x) /* wrapper jn */ 44 | #else 45 | double jn(n,x) /* wrapper jn */ 46 | double x; int n; 47 | #endif 48 | { 49 | #ifdef _IEEE_LIBM 50 | return __ieee754_jn(n,x); 51 | #else 52 | double z; 53 | z = __ieee754_jn(n,x); 54 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; 55 | if(fabs(x)>X_TLOSS) { 56 | return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */ 57 | } else 58 | return z; 59 | #endif 60 | } 61 | 62 | #ifdef __STDC__ 63 | double yn(int n, double x) /* wrapper yn */ 64 | #else 65 | double yn(n,x) /* wrapper yn */ 66 | double x; int n; 67 | #endif 68 | { 69 | #ifdef _IEEE_LIBM 70 | return __ieee754_yn(n,x); 71 | #else 72 | double z; 73 | z = __ieee754_yn(n,x); 74 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; 75 | if(x <= 0.0){ 76 | if(x==0.0) 77 | /* d= -one/(x-x); */ 78 | return __kernel_standard((double)n,x,12); 79 | else 80 | /* d = zero/(x-x); */ 81 | return __kernel_standard((double)n,x,13); 82 | } 83 | if(x>X_TLOSS) { 84 | return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */ 85 | } else 86 | return z; 87 | #endif 88 | } 89 | --------------------------------------------------------------------------------