ppc: suppressed unneeded globals and headers - added explicit type for ppc nvram

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@723 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
bellard 2004-04-12 20:54:52 +00:00
parent a541f297a3
commit c5df018e56
5 changed files with 93 additions and 129 deletions

View File

@ -21,14 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <stdlib.h>
#include <stdio.h> /* needed by vl.h */
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "vl.h" #include "vl.h"
#include "m48t59.h"
//#define NVRAM_DEBUG //#define NVRAM_DEBUG
@ -38,7 +32,7 @@
#define NVRAM_PRINTF(fmt, args...) do { } while (0) #define NVRAM_PRINTF(fmt, args...) do { } while (0)
#endif #endif
typedef struct m48t59_t { struct m48t59_t {
/* Hardware parameters */ /* Hardware parameters */
int IRQ; int IRQ;
uint32_t io_base; uint32_t io_base;
@ -53,10 +47,7 @@ typedef struct m48t59_t {
/* NVRAM storage */ /* NVRAM storage */
uint16_t addr; uint16_t addr;
uint8_t *buffer; uint8_t *buffer;
} m48t59_t; };
static m48t59_t *NVRAMs;
static int nb_NVRAMs;
/* Fake timer functions */ /* Fake timer functions */
/* Generic helpers for BCD */ /* Generic helpers for BCD */
@ -185,9 +176,8 @@ static void set_up_watchdog (m48t59_t *NVRAM, uint8_t value)
} }
/* Direct access to NVRAM */ /* Direct access to NVRAM */
void m48t59_write (void *opaque, uint32_t val) void m48t59_write (m48t59_t *NVRAM, uint32_t val)
{ {
m48t59_t *NVRAM = opaque;
struct tm tm; struct tm tm;
int tmp; int tmp;
@ -333,9 +323,8 @@ void m48t59_write (void *opaque, uint32_t val)
} }
} }
uint32_t m48t59_read (void *opaque) uint32_t m48t59_read (m48t59_t *NVRAM)
{ {
m48t59_t *NVRAM = opaque;
struct tm tm; struct tm tm;
uint32_t retval = 0xFF; uint32_t retval = 0xFF;
@ -418,10 +407,8 @@ uint32_t m48t59_read (void *opaque)
return retval; return retval;
} }
void m48t59_set_addr (void *opaque, uint32_t addr) void m48t59_set_addr (m48t59_t *NVRAM, uint32_t addr)
{ {
m48t59_t *NVRAM = opaque;
NVRAM->addr = addr; NVRAM->addr = addr;
} }
@ -460,27 +447,25 @@ static uint32_t NVRAM_readb (void *opaque, uint32_t addr)
} }
/* Initialisation routine */ /* Initialisation routine */
void *m48t59_init (int IRQ, uint32_t io_base, uint16_t size) m48t59_t *m48t59_init (int IRQ, uint32_t io_base, uint16_t size)
{ {
m48t59_t *tmp; m48t59_t *s;
tmp = realloc(NVRAMs, (nb_NVRAMs + 1) * sizeof(m48t59_t)); s = qemu_mallocz(sizeof(m48t59_t));
if (tmp == NULL) if (!s)
return NULL; return NULL;
NVRAMs = tmp; s->buffer = qemu_mallocz(size);
tmp[nb_NVRAMs].buffer = malloc(size); if (!s->buffer) {
if (tmp[nb_NVRAMs].buffer == NULL) qemu_free(s);
return NULL; return NULL;
memset(tmp[nb_NVRAMs].buffer, 0, size); }
tmp[nb_NVRAMs].IRQ = IRQ; s->IRQ = IRQ;
tmp[nb_NVRAMs].size = size; s->size = size;
tmp[nb_NVRAMs].io_base = io_base; s->io_base = io_base;
tmp[nb_NVRAMs].addr = 0; s->addr = 0;
register_ioport_read(io_base, 0x04, 1, NVRAM_readb, &NVRAMs[nb_NVRAMs]); register_ioport_read(io_base, 0x04, 1, NVRAM_readb, s);
register_ioport_write(io_base, 0x04, 1, NVRAM_writeb, &NVRAMs[nb_NVRAMs]); register_ioport_write(io_base, 0x04, 1, NVRAM_writeb, s);
tmp[nb_NVRAMs].alrm_timer = qemu_new_timer(vm_clock, &alarm_cb, s->alrm_timer = qemu_new_timer(vm_clock, &alarm_cb, s);
&tmp[nb_NVRAMs]); s->wd_timer = qemu_new_timer(vm_clock, &watchdog_cb, s);
tmp[nb_NVRAMs].wd_timer = qemu_new_timer(vm_clock, &watchdog_cb, return s;
&tmp[nb_NVRAMs]);
return &NVRAMs[nb_NVRAMs++];
} }

View File

@ -1,9 +1,11 @@
#if !defined (__M48T59_H__) #if !defined (__M48T59_H__)
#define __M48T59_H__ #define __M48T59_H__
void m48t59_write (void *opaque, uint32_t val); typedef struct m48t59_t m48t59_t;
uint32_t m48t59_read (void *opaque);
void m48t59_set_addr (void *opaque, uint32_t addr); void m48t59_write (m48t59_t *NVRAM, uint32_t val);
void *m48t59_init (int IRQ, uint32_t io_base, uint16_t size); uint32_t m48t59_read (m48t59_t *NVRAM);
void m48t59_set_addr (m48t59_t *NVRAM, uint32_t addr);
m48t59_t *m48t59_init (int IRQ, uint32_t io_base, uint16_t size);
#endif /* !defined (__M48T59_H__) */ #endif /* !defined (__M48T59_H__) */

View File

@ -21,8 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <stdio.h>
#include "vl.h" #include "vl.h"
void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device, void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device,

View File

@ -21,26 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <getopt.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <malloc.h>
#include <termios.h>
#include <sys/poll.h>
#include <errno.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include "cpu.h"
#include "vl.h" #include "vl.h"
#include "m48t59.h" #include "m48t59.h"
@ -209,8 +189,6 @@ static CPUReadMemoryFunc *PPC_io_read[] = {
&PPC_io_readl, &PPC_io_readl,
}; };
uint32_t pic_intack_read(CPUState *env);
/* Read-only register (?) */ /* Read-only register (?) */
static void _PPC_ioB_write (uint32_t addr, uint32_t value, uint32_t vaddr) static void _PPC_ioB_write (uint32_t addr, uint32_t value, uint32_t vaddr)
{ {
@ -368,63 +346,63 @@ static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)
#define NVRAM_OSAREA_SIZE 512 #define NVRAM_OSAREA_SIZE 512
#define NVRAM_CONFSIZE 1024 #define NVRAM_CONFSIZE 1024
static inline void NVRAM_set_byte (void *opaque, uint32_t addr, uint8_t value) static inline void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value)
{ {
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
m48t59_write(opaque, value); m48t59_write(nvram, value);
} }
static inline uint8_t NVRAM_get_byte (void *opaque, uint32_t addr) static inline uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr)
{ {
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
return m48t59_read(opaque); return m48t59_read(nvram);
} }
static inline void NVRAM_set_word (void *opaque, uint32_t addr, uint16_t value) static inline void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value)
{ {
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
m48t59_write(opaque, value >> 8); m48t59_write(nvram, value >> 8);
m48t59_set_addr(opaque, addr + 1); m48t59_set_addr(nvram, addr + 1);
m48t59_write(opaque, value & 0xFF); m48t59_write(nvram, value & 0xFF);
} }
static inline uint16_t NVRAM_get_word (void *opaque, uint32_t addr) static inline uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr)
{ {
uint16_t tmp; uint16_t tmp;
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
tmp = m48t59_read(opaque) << 8; tmp = m48t59_read(nvram) << 8;
m48t59_set_addr(opaque, addr + 1); m48t59_set_addr(nvram, addr + 1);
tmp |= m48t59_read(opaque); tmp |= m48t59_read(nvram);
return tmp; return tmp;
} }
static inline void NVRAM_set_lword (void *opaque, uint32_t addr, static inline void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr,
uint32_t value) uint32_t value)
{ {
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
m48t59_write(opaque, value >> 24); m48t59_write(nvram, value >> 24);
m48t59_set_addr(opaque, addr + 1); m48t59_set_addr(nvram, addr + 1);
m48t59_write(opaque, (value >> 16) & 0xFF); m48t59_write(nvram, (value >> 16) & 0xFF);
m48t59_set_addr(opaque, addr + 2); m48t59_set_addr(nvram, addr + 2);
m48t59_write(opaque, (value >> 8) & 0xFF); m48t59_write(nvram, (value >> 8) & 0xFF);
m48t59_set_addr(opaque, addr + 3); m48t59_set_addr(nvram, addr + 3);
m48t59_write(opaque, value & 0xFF); m48t59_write(nvram, value & 0xFF);
} }
static inline uint32_t NVRAM_get_lword (void *opaque, uint32_t addr) static inline uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr)
{ {
uint32_t tmp; uint32_t tmp;
m48t59_set_addr(opaque, addr); m48t59_set_addr(nvram, addr);
tmp = m48t59_read(opaque) << 24; tmp = m48t59_read(nvram) << 24;
m48t59_set_addr(opaque, addr + 1); m48t59_set_addr(nvram, addr + 1);
tmp |= m48t59_read(opaque) << 16; tmp |= m48t59_read(nvram) << 16;
m48t59_set_addr(opaque, addr + 2); m48t59_set_addr(nvram, addr + 2);
tmp |= m48t59_read(opaque) << 8; tmp |= m48t59_read(nvram) << 8;
m48t59_set_addr(opaque, addr + 3); m48t59_set_addr(nvram, addr + 3);
tmp |= m48t59_read(opaque); tmp |= m48t59_read(nvram);
return tmp; return tmp;
} }
@ -444,7 +422,7 @@ static uint16_t NVRAM_crc_update (uint16_t prev, uint16_t value)
return tmp; return tmp;
} }
static void NVRAM_set_crc (void *opaque, uint32_t addr, static void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
uint32_t start, uint32_t count) uint32_t start, uint32_t count)
{ {
uint32_t i; uint32_t i;
@ -455,74 +433,74 @@ static void NVRAM_set_crc (void *opaque, uint32_t addr,
odd = 1; odd = 1;
count &= ~1; count &= ~1;
for (i = 0; i != count; i++) { for (i = 0; i != count; i++) {
crc = NVRAM_crc_update(crc, NVRAM_get_word(opaque, start + i)); crc = NVRAM_crc_update(crc, NVRAM_get_word(nvram, start + i));
} }
if (odd) { if (odd) {
crc = NVRAM_crc_update(crc, NVRAM_get_byte(opaque, start + i) << 8); crc = NVRAM_crc_update(crc, NVRAM_get_byte(nvram, start + i) << 8);
} }
NVRAM_set_word(opaque, addr, crc); NVRAM_set_word(nvram, addr, crc);
} }
static void prep_NVRAM_init (void) static void prep_NVRAM_init (void)
{ {
void *opaque; m48t59_t *nvram;
opaque = m48t59_init(8, 0x0074, NVRAM_SIZE); nvram = m48t59_init(8, 0x0074, NVRAM_SIZE);
/* NVRAM header */ /* NVRAM header */
/* 0x00: NVRAM size in kB */ /* 0x00: NVRAM size in kB */
NVRAM_set_word(opaque, 0x00, NVRAM_SIZE >> 10); NVRAM_set_word(nvram, 0x00, NVRAM_SIZE >> 10);
/* 0x02: NVRAM version */ /* 0x02: NVRAM version */
NVRAM_set_byte(opaque, 0x02, 0x01); NVRAM_set_byte(nvram, 0x02, 0x01);
/* 0x03: NVRAM revision */ /* 0x03: NVRAM revision */
NVRAM_set_byte(opaque, 0x03, 0x01); NVRAM_set_byte(nvram, 0x03, 0x01);
/* 0x08: last OS */ /* 0x08: last OS */
NVRAM_set_byte(opaque, 0x08, 0x00); /* Unknown */ NVRAM_set_byte(nvram, 0x08, 0x00); /* Unknown */
/* 0x09: endian */ /* 0x09: endian */
NVRAM_set_byte(opaque, 0x09, 'B'); /* Big-endian */ NVRAM_set_byte(nvram, 0x09, 'B'); /* Big-endian */
/* 0x0A: OSArea usage */ /* 0x0A: OSArea usage */
NVRAM_set_byte(opaque, 0x0A, 0x00); /* Empty */ NVRAM_set_byte(nvram, 0x0A, 0x00); /* Empty */
/* 0x0B: PM mode */ /* 0x0B: PM mode */
NVRAM_set_byte(opaque, 0x0B, 0x00); /* Normal */ NVRAM_set_byte(nvram, 0x0B, 0x00); /* Normal */
/* Restart block description record */ /* Restart block description record */
/* 0x0C: restart block version */ /* 0x0C: restart block version */
NVRAM_set_word(opaque, 0x0C, 0x01); NVRAM_set_word(nvram, 0x0C, 0x01);
/* 0x0E: restart block revision */ /* 0x0E: restart block revision */
NVRAM_set_word(opaque, 0x0E, 0x01); NVRAM_set_word(nvram, 0x0E, 0x01);
/* 0x20: restart address */ /* 0x20: restart address */
NVRAM_set_lword(opaque, 0x20, 0x00); NVRAM_set_lword(nvram, 0x20, 0x00);
/* 0x24: save area address */ /* 0x24: save area address */
NVRAM_set_lword(opaque, 0x24, 0x00); NVRAM_set_lword(nvram, 0x24, 0x00);
/* 0x28: save area length */ /* 0x28: save area length */
NVRAM_set_lword(opaque, 0x28, 0x00); NVRAM_set_lword(nvram, 0x28, 0x00);
/* 0x1C: checksum of restart block */ /* 0x1C: checksum of restart block */
NVRAM_set_crc(opaque, 0x1C, 0x0C, 32); NVRAM_set_crc(nvram, 0x1C, 0x0C, 32);
/* Security section */ /* Security section */
/* Set all to zero */ /* Set all to zero */
/* 0xC4: pointer to global environment area */ /* 0xC4: pointer to global environment area */
NVRAM_set_lword(opaque, 0xC4, 0x0100); NVRAM_set_lword(nvram, 0xC4, 0x0100);
/* 0xC8: size of global environment area */ /* 0xC8: size of global environment area */
NVRAM_set_lword(opaque, 0xC8, NVRAM_set_lword(nvram, 0xC8,
NVRAM_END - NVRAM_OSAREA_SIZE - NVRAM_CONFSIZE - 0x0100); NVRAM_END - NVRAM_OSAREA_SIZE - NVRAM_CONFSIZE - 0x0100);
/* 0xD4: pointer to configuration area */ /* 0xD4: pointer to configuration area */
NVRAM_set_lword(opaque, 0xD4, NVRAM_END - NVRAM_CONFSIZE); NVRAM_set_lword(nvram, 0xD4, NVRAM_END - NVRAM_CONFSIZE);
/* 0xD8: size of configuration area */ /* 0xD8: size of configuration area */
NVRAM_set_lword(opaque, 0xD8, NVRAM_CONFSIZE); NVRAM_set_lword(nvram, 0xD8, NVRAM_CONFSIZE);
/* 0xE8: pointer to OS specific area */ /* 0xE8: pointer to OS specific area */
NVRAM_set_lword(opaque, 0xE8, NVRAM_set_lword(nvram, 0xE8,
NVRAM_END - NVRAM_CONFSIZE - NVRAM_OSAREA_SIZE); NVRAM_END - NVRAM_CONFSIZE - NVRAM_OSAREA_SIZE);
/* 0xD8: size of OS specific area */ /* 0xD8: size of OS specific area */
NVRAM_set_lword(opaque, 0xEC, NVRAM_OSAREA_SIZE); NVRAM_set_lword(nvram, 0xEC, NVRAM_OSAREA_SIZE);
/* Configuration area */ /* Configuration area */
/* RTC init */ /* RTC init */
// NVRAM_set_lword(opaque, 0x1FFC, 0x50); // NVRAM_set_lword(nvram, 0x1FFC, 0x50);
/* 0x04: checksum 0 => OS area */ /* 0x04: checksum 0 => OS area */
NVRAM_set_crc(opaque, 0x04, 0x00, NVRAM_set_crc(nvram, 0x04, 0x00,
NVRAM_END - NVRAM_CONFSIZE - NVRAM_OSAREA_SIZE); NVRAM_END - NVRAM_CONFSIZE - NVRAM_OSAREA_SIZE);
/* 0x06: checksum of config area */ /* 0x06: checksum of config area */
NVRAM_set_crc(opaque, 0x06, NVRAM_END - NVRAM_CONFSIZE, NVRAM_CONFSIZE); NVRAM_set_crc(nvram, 0x06, NVRAM_END - NVRAM_CONFSIZE, NVRAM_CONFSIZE);
} }
int load_initrd (const char *filename, uint8_t *addr) int load_initrd (const char *filename, uint8_t *addr)

1
vl.h
View File

@ -416,6 +416,7 @@ void serial_receive_break(SerialState *s);
void pic_set_irq(int irq, int level); void pic_set_irq(int irq, int level);
void pic_init(void); void pic_init(void);
uint32_t pic_intack_read(CPUState *env);
/* i8254.c */ /* i8254.c */