Skip to content

Clean up code to build under GCC7, fix pgm_read_unaligned #6270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;
#ifdef __cplusplus

#include <algorithm>
#include <cmath>
#include <pgmspace.h>

#include "WCharacter.h"
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/core_esp8266_app_entry_noextra4k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" void call_user_start();
/* this is the default NONOS-SDK user's heap location */
static cont_t g_cont __attribute__ ((aligned (16)));

extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
extern "C" void app_entry_redefinable(void)
{
g_pcont = &g_cont;

Expand Down
8 changes: 4 additions & 4 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ void init_done() {

*/

extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) __attribute__((weak));
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
extern "C" void app_entry_redefinable(void) __attribute__((weak));
extern "C" void app_entry_redefinable(void)
{
/* Allocate continuation context on this SYS stack,
and save pointer to it. */
Expand All @@ -248,9 +248,9 @@ extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
call_user_start();
}

static void ICACHE_RAM_ATTR app_entry_custom (void) __attribute__((weakref("app_entry_redefinable")));
static void app_entry_custom (void) __attribute__((weakref("app_entry_redefinable")));

extern "C" void ICACHE_RAM_ATTR app_entry (void)
extern "C" void app_entry (void)
{
return app_entry_custom();
}
Expand Down
8 changes: 3 additions & 5 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ class UdpContext

void unref()
{
if(this != 0) {
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
delete this;
}
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
delete this;
}
}

Expand Down
2 changes: 2 additions & 0 deletions tools/sdk/ld/eagle.app.v6.common.ld.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ SECTIONS
*(.init.literal)
*(.init)

*(.text.app_entry*) /* The main startup code */

/* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */
*(.text._ZNKSt8functionIF*EE*) /* std::function<any(...)>::operator()() const */
} >iram1_0_seg :iram1_0_phdr
Expand Down
42 changes: 20 additions & 22 deletions tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,23 @@ extern "C" {
asm("extui %0, %1, 0, 2\n" /* Extract offset within word (in bytes) */ \
"sub %1, %1, %0\n" /* Subtract offset from addr, yielding an aligned address */ \
"l32i.n %1, %1, 0x0\n" /* Load word from aligned address */ \
"slli %0, %0, 3\n" /* Mulitiply offset by 8, yielding an offset in bits */ \
"ssr %0\n" /* Prepare to shift by offset (in bits) */ \
"srl %0, %1\n" /* Shift right; now the requested byte is the first one */ \
"ssa8l %0\n" /* Prepare to shift by offset (in bits) */ \
"src %0, %1, %1\n" /* Shift right; now the requested byte is the first one */ \
:"=r"(res), "=r"(addr) \
:"1"(addr) \
:);

#define pgm_read_dword_with_offset(addr, res) \
asm("extui %0, %1, 0, 2\n" /* Extract offset within word (in bytes) */ \
"sub %1, %1, %0\n" /* Subtract offset from addr, yielding an aligned address */ \
"l32i a15, %1, 0\n" \
"l32i %1, %1, 4\n" \
"ssa8l %0\n" \
"src %0, %1, a15\n" \
:"=r"(res), "=r"(addr) \
:"1"(addr) \
:"a15");

static inline uint8_t pgm_read_byte_inlined(const void* addr) {
register uint32_t res;
pgm_read_with_offset(addr, res);
Expand All @@ -68,8 +78,6 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) {
return (uint16_t) res; /* This masks the lower half-word from the returned word */
}



#define pgm_read_byte(addr) pgm_read_byte_inlined(addr)
#define pgm_read_word_aligned(addr) pgm_read_word_inlined(addr)
#ifdef __cplusplus
Expand All @@ -82,26 +90,16 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) {
#define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr))
#endif

__attribute__((optimize("-O3"), always_inline)) static inline uint32_t pgm_read_dword_unaligned(const void *addr) {
if (!(((int)addr)&3)) return *(const uint32_t *)addr;
int off = (((int)addr) & 3) << 3;
const uint32_t *p = (const uint32_t *)((int)addr & (~3));
uint32_t a = *p++;
uint32_t b = *p;
return (a>>off) | (b <<(32-off));
static inline uint32_t pgm_read_dword_unaligned(const void *addr) {
uint32_t res;
pgm_read_dword_with_offset(addr, res);
return res;
}

__attribute__((optimize("-O3"), always_inline)) static inline float pgm_read_float_unaligned(const void *addr) {
return (float)pgm_read_dword_unaligned(addr);
}
#define pgm_read_float_unaligned(addr) ((float)pgm_read_dword_unaligned(addr))
#define pgm_read_ptr_unaligned(addr) ((void*)pgm_read_dword_unaligned(addr))
#define pgm_read_word_unaligned(addr) ((uint16_t)(pgm_read_dword_unaligned(addr) & 0xffff))

__attribute__((optimize("-O3"), always_inline)) static inline void *pgm_read_ptr_unaligned(const void *addr) {
return (void *)pgm_read_dword_unaligned(addr);
}

__attribute__((optimize("-O3"), always_inline)) static inline uint16_t pgm_read_word_unaligned(const void *addr) {
return pgm_read_dword_unaligned(addr) & 0xffff;
}

// Allow selection of _aligned or _unaligned, but default to _unaligned for Arduino compatibility
// Add -DPGM_READ_UNALIGNED=0 or "#define PGM_READ_UNALIGNED 0" to code to use aligned-only (faster) macros by default
Expand Down