Moved to using byte access to RTC memory

This commit is contained in:
Philip Gladstome 2016-01-02 11:34:09 -05:00
parent bcd7b09195
commit a6a54743d3
2 changed files with 36 additions and 11 deletions

View File

@ -6,7 +6,6 @@
#define RTC_MMIO_BASE 0x60000700
#define RTC_USER_MEM_BASE 0x60001200
#define RTC_USER_MEM_NUM_DWORDS 128
#define RTC_SYSTEM_MEM_NUM_DWORDS 64
#define RTC_TARGET_ADDR 0x04
#define RTC_COUNTER_ADDR 0x1c
@ -20,6 +19,19 @@ static inline void rtc_mem_write(uint32_t addr, uint32_t val)
((uint32_t*)RTC_USER_MEM_BASE)[addr]=val;
}
static inline unsigned char rtc_mem_read_byte(uint32_t addr)
{
return 0xff & (rtc_mem_read(addr >> 2) >> ((addr & 3) << 3));
}
static inline unsigned char rtc_mem_write_byte(uint32_t addr, unsigned char val)
{
uint32_t word = rtc_mem_read(addr >> 2);
int shift = (addr & 3) << 3;
word = (word & ~(0xff << shift)) | (val << shift);
rtc_mem_write(addr >> 2, word);
}
static inline uint64_t rtc_make64(uint32_t high, uint32_t low)
{
return (((uint64_t)high)<<32)|low;

View File

@ -45,6 +45,7 @@
#define LUA_USECCLOSURES 0
#define LUA_USELIGHTFUNCTIONS 1
// offset of the string, Marker is one before (if > 0)
static unsigned char panic_str_offset;
/*
@ -811,15 +812,23 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
LUALIB_API char *luaL_panicstr(int offset, char *buff, size_t bufflen) {
if (offset >= 0 && offset < RTC_USER_MEM_NUM_DWORDS - 1) {
panic_str_offset = offset + RTC_SYSTEM_MEM_NUM_DWORDS; // Reserved for system use
panic_str_offset = offset + 1; // Reserved for marker use
}
if (panic_str_offset && rtc_mem_read(panic_str_offset - RTC_SYSTEM_MEM_NUM_DWORDS) == 0x31415926) {
size_t avail = (RTC_SYSTEM_MEM_NUM_DWORDS + RTC_USER_MEM_NUM_DWORDS - panic_str_offset - 1) * 4;
if (panic_str_offset && rtc_mem_read(panic_str_offset - 1) == 0x31415926) {
size_t avail = (RTC_USER_MEM_NUM_DWORDS - panic_str_offset) * 4;
if (avail > bufflen) {
avail = bufflen;
}
system_rtc_mem_read(panic_str_offset + 1, buff, avail);
int i;
int addr = panic_str_offset * 4;
for (i = 0; i < avail; i++) {
char c = (char) rtc_mem_read_byte(addr + i);
buff[i] = c;
if (c == 0) {
break;
}
}
buff[bufflen - 1] = 0; // Ensure null terminated
if (buff[0]) {
@ -840,13 +849,17 @@ static int panic (lua_State *L) {
msg);
#endif
if (panic_str_offset != 0) {
size_t len = c_strlen(msg) + 1;
size_t avail = (RTC_SYSTEM_MEM_NUM_DWORDS + RTC_USER_MEM_NUM_DWORDS - panic_str_offset - 1) * 4;
if (len > avail) {
len = avail;
size_t avail = (RTC_USER_MEM_NUM_DWORDS - panic_str_offset) * 4;
int i;
int addr = panic_str_offset * 4;
for (i = 0; i < avail; i++) {
char c = msg[i];
rtc_mem_write_byte(addr + i, c);
if (c == 0) {
break;
}
system_rtc_mem_write(panic_str_offset + 1, msg, len);
rtc_mem_write(panic_str_offset - RTC_SYSTEM_MEM_NUM_DWORDS, 0x31415926);
}
rtc_mem_write(panic_str_offset - 1, 0x31415926);
}
while (1) {}
return 0;