Skip to contentSkip to conversation

Creating a simple

Qemu-devel Alessandro Corradi 1 participant 1 message Jun 12, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,

I'm trying to write a simple virtual hardware for QEMU. This hw must only return the value 0 every time I read at 0x6f8 address.
It looks like simple but I'm not sure... this is what I do...
I wrote a file in hw dir called hwfitt.c and implements hwfitt_ioport_read and *hwfitt_init functions.
In hwfitt_ioport_read must be a function that implements the hardware read control right?
I take for instance parallel.c code and I write hwfitt function call in files where parallel's function are called (pc.c vl.c vl.h) and modified make file. I didn't implement hwupdate_update_irq as in parallel code. Is an error?
This is my hwfitt.c code. Can you support me?

Thanks

Alessandro

#include "vl.h"

#define HW_STS_READY 0x10
#define HW_STS_BUSY 0x80

#define HW_CTR_INIT 0x01

struct HwFittState {
uint8_t data;
uint8_t status;
uint8_t control;
int irq;
int irq_pending;
CharDriverState *chr;
int hw_driver;
};

/*static void hwupdate_update_irq(ParallelState *s) {
if (s->irq_pending)

       pic_set_irq(s->irq, 1);
   else
       pic_set_irq(s->irq, 0);
}*/

static uint32_t hwfitt_ioport_read(void *opaque, uint32_t addr) {
HwFittState *s = opaque;
uint32_t ret= 0xff;

addr &= 7;
switch(addr) {
case 0:

       if(s->hw_driver) {
           s->data=0;
       }
       ret = s->data;
       break;
   case 1:
       if(s->hw_driver) {
           ret=s->status;
       }
       break;
   case 2:
       if(s->hw_driver) {
           s->control=0x10;
       }
       ret = s->control;
       break;

}
#ifdef DEBUG_PARALLEL
printf("hwfitt: read addr=0x%02x val=0x%02x\n", addr, ret);
#endif
return ret;
}

HwFittState *hwfitt_init(int base, int irq, CharDriverState *chr){
HwFittState *s;

   s=qemu_mallocz(sizeof(HwFittState));
   s->chr = chr;
   s->hw_driver = 1;
   s->irq = irq;
   s->data = 1;
   s->status = HW_STS_READY;
   s->status |= HW_STS_BUSY;
   s->control = HW_CTR_INIT;

register_ioport_read(base, 8, 1, hwfitt_ioport_read, s); return s;
}