Преглед изворни кода

Create a common directory for sources between esp32 and rv32

H. Peter Anvin пре 2 година
родитељ
комит
1b9f666c8e

+ 23 - 3
esp32/max80/compiler.h → common/compiler.h

@@ -3,11 +3,13 @@
 
 #ifndef __ASSEMBLY__
 
-#include <stdlib.h>
-#include <stdarg.h>
+#include <stddef.h>
+#include <errno.h>
 #include <inttypes.h>
-#include <stdbool.h>
 #include <limits.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdlib.h>
 
 #ifdef __cplusplus
 # define extern_c extern "C"
@@ -40,6 +42,23 @@ typedef union xcptr {
     size_t          a;
 } xcptr_t;
 
+/* Subword types */
+typedef union {
+    uint8_t  b[8];
+    uint16_t h[4];
+    uint32_t l[2];
+    uint64_t q;
+} qword_t;
+typedef union {
+    uint8_t  b[4];
+    uint16_t h[2];
+    uint32_t l;
+} lword_t;
+typedef union {
+    uint8_t  b[2];
+    uint16_t h;
+} hword_t;
+
 /* The container_of construct: if p is a pointer to member m of
    container class c, then return a pointer to the container of which
    *p is a member. */
@@ -50,6 +69,7 @@ typedef union xcptr {
 #define offset_diff(c, m1, m2) ((ptrdiff_t)offsetof(c,m2) - \
 				(ptrdiff_t)offsetof(c,m1))
 
+/* Type-safeish comparison macros */
 #define Min(a,b) ({				\
       __typeof__((a)*(b)) __a = (a);		\
       __typeof__((a)*(b)) __b = (b);		\

+ 0 - 0
esp32/max80/esplink.h → common/esplink.h


+ 1 - 1
esp32/Makefile

@@ -9,7 +9,7 @@ GENFILES      = www.zip
 WWW	      = www
 PORT	     ?= /dev/ttyACM2
 
-build_defines = -DBOARD_HAS_PSRAM
+build_defines = -DBOARD_HAS_PSRAM -I$(realpath ../common)
 
 BOARD	      = esp32:esp32:esp32s2usb
 ARDUINO_OPTS  = -b $(BOARD) \

BIN
esp32/output/max80.ino.bin


+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition
-# Date created = 01:03:43  June 05, 2022
+# Date created = 09:33:44  June 06, 2022
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "21.1"
-DATE = "01:03:43  June 05, 2022"
+DATE = "09:33:44  June 06, 2022"
 
 # Revisions
 

BIN
fpga/output/v1.fw


BIN
fpga/output/v1.jic


BIN
fpga/output/v1.rbf.gz


BIN
fpga/output/v1.rpd.gz


BIN
fpga/output/v1.sof


BIN
fpga/output/v1.svf.gz


BIN
fpga/output/v1.xsvf.gz


BIN
fpga/output/v2.fw


BIN
fpga/output/v2.jic


BIN
fpga/output/v2.rbf.gz


BIN
fpga/output/v2.rpd.gz


BIN
fpga/output/v2.sof


BIN
fpga/output/v2.svf.gz


BIN
fpga/output/v2.xsvf.gz


+ 1 - 1
rv32/Makefile

@@ -11,7 +11,7 @@ NM	  = $(CROSS)nm
 PERL      = perl
 GZIP	  = gzip
 
-INCLUDE   = -I. -I./include -I./zlib -I./fatfs/source
+INCLUDE   = -I. -I./include -I../common -I./zlib -I./fatfs/source
 include ../riscv-opts.mk
 CPPFLAGS  = $(INCLUDE) $(riscv_flags)
 CFLAGS    = $(CPPFLAGS) -W -Wextra

+ 27 - 18
rv32/common.h

@@ -1,26 +1,35 @@
-#ifndef FW_H
-#define FW_H
+#ifndef COMMON_H
+#define COMMON_H
 
 #include "compiler.h"
+#include "sections.h"
 #include "picorv32.h"
 #include "irq.h"
 
-/* Sometimes useful combination types */
-typedef union {
-    uint8_t  b[8];
-    uint16_t h[4];
-    uint32_t l[2];
-    uint64_t q;
-} qword_t;
-typedef union {
-    uint8_t  b[4];
-    uint16_t h[2];
-    uint32_t l;
-} lword_t;
-typedef union {
-    uint8_t  b[2];
-    uint16_t h;
-} hword_t;
+#define min(a,b) Min(a,b)
+#define max(a,b) Max(a,b)
+
+/* memcpy() variants */
+
+/* Use builtin memcpy and memset optimizations */
+#define memset(s,c,n)	__builtin_memset(s,c,n)
+#define memcpy(d,s,n)	__builtin_memcpy(d,s,n)
+#define mempcpy(d,s,n)	__builtin_mempcpy(d,s,n)
+#define memmove(d,s,n)	__builtin_memmove(d,s,n)
+
+extern volatile void *memcpy_bytewise(volatile void *dst,
+				      const volatile void *src, size_t len);
+/*
+ * The odd argument order allows memcpy() and mempcpy() to be implemented
+ * as tail calls
+ */
+extern void *__memxcpy_aligned(void *retval,
+			      const void * restrict src, size_t len,
+			      void * restrict dst);
+extern void *__memxcpy_bytewise(void *retval,
+				const volatile void * restrict src, size_t len,
+				void * restrict dst);
+
 
 extern const size_t __rom_offset;
 extern const uint32_t __dram_checksum;

+ 0 - 115
rv32/compiler.h

@@ -1,115 +0,0 @@
-#ifndef COMPILER_H
-#define COMPILER_H
-
-#ifndef __ASSEMBLY__
-
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <errno.h>
-
-/* Use builtin memcpy and memset optimizations */
-#define memset(s,c,n)	__builtin_memset(s,c,n)
-#define memcpy(d,s,n)	__builtin_memcpy(d,s,n)
-#define mempcpy(d,s,n)	__builtin_mempcpy(d,s,n)
-#define memmove(d,s,n)	__builtin_memmove(d,s,n)
-
-extern volatile void *memcpy_bytewise(volatile void *dst,
-				      const volatile void *src, size_t len);
-
-/*
- * The odd argument order allows memcpy() and mempcpy() to be implemented
- * as tail calls
- */
-extern void *__memxcpy_aligned(void *retval,
-			      const void * restrict src, size_t len,
-			      void * restrict dst);
-extern void *__memxcpy_bytewise(void *retval,
-				const volatile void * restrict src, size_t len,
-				void * restrict dst);
-
-#define likely(x)	__builtin_expect(!!(x), 1)
-#define unlikely(x)	__builtin_expect(!!(x), 0)
-
-/* Handy composite pointer types */
-typedef union xptr {
-    uint32_t *l;
-    uint16_t *w;
-    uint8_t  *b;
-    void     *v;
-    size_t    a;
-} xptr_t;
-typedef union xcptr {
-    const uint32_t *l;
-    const uint16_t *w;
-    const uint8_t  *b;
-    const void     *v;
-    size_t          a;
-} xcptr_t;
-
-/* The container_of construct: if p is a pointer to member m of
-   container class c, then return a pointer to the container of which
-   *p is a member. */
-#ifndef container_of
-# define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m)))
-#endif
-
-#define offset_diff(c, m1, m2) ((ptrdiff_t)offsetof(c,m2) - \
-				(ptrdiff_t)offsetof(c,m1))
-
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-
-#define ARRAY_SIZE (sizeof(a)/sizeof(a[0]))
-
-#define alignof(a) __alignof__(a)
-
-#define no_return void __attribute__((noreturn))
-
-#define ___section(s,a,...) __attribute__((__section__(s)))
-
-#define __hot		__attribute__((__hot__))
-#define __cold		__attribute__((__cold__))
-#define __aligned(x)	__attribute__((__aligned__(x)))
-#define __unused	__attribute__((__unused__))
-#define __must_inline	__attribute__((__always_inline__))
-#define __noinline	__attribute__ ((__noinline__))
-#define __constfunc	__attribute__((__const__))
-#define __purefunc	__attribute__((__pure__))
-
-#define __fmt_printf(fstr,farg)	__attribute__((__format__(__printf__,fstr,farg)))
-
-#define __is_constant(expr)	__builtin_constant_p(expr)
-
-#else /* __ASSEMBLY__ */
-
-#define ___section(s,a,...)	.pushsection s, a, ## __VA_ARGS__
-
-#endif /* __ASSEMBLY__ */
-
-#define __text_hot	___section(".text.hot","ax")
-#define __rodata_hot	___section(".rodata.hot","a")
-#define __data_hot	___section(".data.hot","aw")
-#define __rwtext	___section(".rwtext","awx")
-#define __sdata		___section(".sdata","aw")
-#define __string_hot	___section(".rodata.hot.str","aMS")
-#define __sbss		___section(".sbss.hot","aw",@nobits)
-#define __bss_hot	___section(".bss.hot","aw",@nobits)
-#define __esplink_head	___section(".dram.esplink.head","aw",@nobits)
-#define __esplink	___section(".dram.bss.esplink","aw",@nobits)
-#define __dram_text	___section(".dram.text","ax")
-#define __dram_rodata	___section(".dram.rodata","a")
-#define __dram_string	___section(".dram.rodata.str","aMS")
-#define __dram_data	___section(".dram.data","aw")
-#define __dram_bss	___section(".dram.bss","aw",@nobits)
-#define __dram_noinit	___section(".dram.noinit","aw",@nobits)
-
-#ifndef __ASSEMBLY__
-
-#define hotstr(x) ({ static __string_hot const char _str[] = (x); _str; })
-
-#endif /* __ASSEMBLY__ */
-
-#endif /* COMPILER_H */

+ 1 - 1
rv32/esp.c

@@ -2,7 +2,7 @@
 #include "common.h"
 #include "io.h"
 #include "console.h"
-#include "esplink.h"
+#include "esp.h"
 
 struct esplink_head __esplink_head esplink_head;
 static volatile __esplink struct esplink_timesync tsync;

+ 4 - 4
rv32/esplink.h → rv32/esp.h

@@ -1,8 +1,8 @@
-#ifndef RV32_ESPLINK_H
-#define RV32_ESPLINK_H
+#ifndef RV32_ESP_H
+#define RV32_ESP_H
 
 #include "compiler.h"
-#include "../esp32/max80/esplink.h"
+#include "esplink.h"
 
 extern void esp_init(void);
 extern void esp_ota(const void *, size_t);
@@ -13,4 +13,4 @@ extern size_t esp_rb_write(enum esplink_ringbuf_user ring,
 extern int esp_rb_getc(enum esplink_ringbuf_user ring);
 extern int esp_rb_putc(enum esplink_ringbuf_user ring, uint8_t data);
 
-#endif /* RV32_ESPLINK_H */
+#endif /* RV32_ESP_H */

+ 1 - 0
rv32/head.S

@@ -1,4 +1,5 @@
 #include "sys.h"
+#include "sections.h"
 #include "picorv32.h"
 
 #define GP_IS_ZERO 1

+ 0 - 7
rv32/include/compiler.h

@@ -1,7 +0,0 @@
-#ifndef COMPILER_H
-#define COMPILER_H
-
-#define likely(x)   __builtin_expect(!!(x),1)
-#define unlikely(x) __builtin_expect(!!(x),0)
-
-#endif /* COMPILER_H */

+ 1 - 0
rv32/irqasm.S

@@ -1,4 +1,5 @@
 #include "compiler.h"
+#include "sections.h"
 #include "picorv32.h"
 #include "ioregs.h"
 

+ 1 - 0
rv32/irqtable.S

@@ -1,4 +1,5 @@
 #include "compiler.h"
+#include "sections.h"
 #include "picorv32.h"
 #include "iodevs.h"
 

+ 29 - 0
rv32/sections.h

@@ -0,0 +1,29 @@
+#ifndef SECTIONS_H
+#define SECTIONS_H
+
+#include "compiler.h"
+
+#define __text_hot	___section(".text.hot","ax")
+#define __rodata_hot	___section(".rodata.hot","a")
+#define __data_hot	___section(".data.hot","aw")
+#define __rwtext	___section(".rwtext","awx")
+#define __sdata		___section(".sdata","aw")
+#define __string_hot	___section(".rodata.hot.str","aMS")
+#define __sbss		___section(".sbss.hot","aw",@nobits)
+#define __bss_hot	___section(".bss.hot","aw",@nobits)
+#define __esplink_head	___section(".dram.esplink.head","aw",@nobits)
+#define __esplink	___section(".dram.bss.esplink","aw",@nobits)
+#define __dram_text	___section(".dram.text","ax")
+#define __dram_rodata	___section(".dram.rodata","a")
+#define __dram_string	___section(".dram.rodata.str","aMS")
+#define __dram_data	___section(".dram.data","aw")
+#define __dram_bss	___section(".dram.bss","aw",@nobits)
+#define __dram_noinit	___section(".dram.noinit","aw",@nobits)
+
+#ifndef __ASSEMBLY__
+
+#define hotstr(x) ({ static __string_hot const char _str[] = (x); _str; })
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* SECTIONS_H */

+ 1 - 1
rv32/spiflash.c

@@ -1,4 +1,4 @@
-#include "compiler.h"
+#include "common.h"
 #include "zlib.h"
 #include "spiflash.h"
 

+ 1 - 1
rv32/system.c

@@ -4,7 +4,7 @@
 #include "abcio.h"
 #include "sys.h"
 #include "console.h"
-#include "esplink.h"
+#include "esp.h"
 
 #define DEBUG     0
 #define MINITESTS 1