--- qemu/roms/SLOF/lib/libnvram/nvram.c 2018/04/24 18:59:08 1.1.1.1 +++ qemu/roms/SLOF/lib/libnvram/nvram.c 2018/04/24 19:24:33 1.1.1.2 @@ -11,17 +11,14 @@ *****************************************************************************/ #include "cache.h" - -#include "../libc/include/stdio.h" -#include "../libc/include/string.h" -#include "../libc/include/stdlib.h" - #include "nvram.h" +#include #include #include #include #include +#include #ifndef NVRAM_LENGTH #define NVRAM_LENGTH 0x10000 @@ -30,22 +27,30 @@ void asm_cout(long Character,long UART,long NVRAM); #if defined(DISABLE_NVRAM) + static volatile uint8_t nvram[NVRAM_LENGTH]; /* FAKE */ -#else -static volatile uint8_t *nvram = (volatile uint8_t *)SB_NVRAM_adr; -#endif -/* This is extremely ugly, but still better than implementing - * another sbrk() around it. - */ -static char nvram_buffer[NVRAM_LENGTH]; -static uint8_t nvram_buffer_locked=0x00; +#define nvram_access(type,size,name) \ + type nvram_read_##name(unsigned int offset) \ + { \ + type *pos; \ + if (offset > (NVRAM_LENGTH - sizeof(type))) \ + return 0; \ + pos = (type *)(nvram+offset); \ + return *pos; \ + } \ + void nvram_write_##name(unsigned int offset, type data) \ + { \ + type *pos; \ + if (offset > (NVRAM_LENGTH - sizeof(type))) \ + return; \ + pos = (type *)(nvram+offset); \ + *pos = data; \ + } -/** - * producer for nvram access functions. Since these functions are - * basically all the same except for the used data types, produce - * them via the following macro to keep the code from bloating. - */ +#else /* DISABLE_NVRAM */ + +static volatile uint8_t *nvram = (volatile uint8_t *)SB_NVRAM_adr; #define nvram_access(type,size,name) \ type nvram_read_##name(unsigned int offset) \ @@ -65,11 +70,26 @@ static uint8_t nvram_buffer_locked=0x00; ci_write_##size(pos, data); \ } +#endif + +/* + * producer for nvram access functions. Since these functions are + * basically all the same except for the used data types, produce + * them via the nvram_access macro to keep the code from bloating. + */ + nvram_access(uint8_t, 8, byte) nvram_access(uint16_t, 16, word) nvram_access(uint32_t, 32, dword) nvram_access(uint64_t, 64, qword) +/* + * This is extremely ugly, but still better than implementing + * another sbrk() around it. + */ +static char nvram_buffer[NVRAM_LENGTH]; +static uint8_t nvram_buffer_locked=0x00; + /** * This function is a minimal abstraction for our temporary * buffer. It should have been malloced, but since there is no @@ -111,11 +131,11 @@ int nvramlog_printf(const char* fmt, ... char buff[256]; int count, i; va_list ap; - + va_start(ap, fmt); count = vsprintf(buff, fmt, ap); va_end(ap); - + for (i=0; i