536 |
/***********************************************************/ |
/***********************************************************/ |
537 |
/* 8259 pic emulation */ |
/* 8259 pic emulation */ |
538 |
|
|
539 |
|
//#define DEBUG_PIC |
540 |
|
|
541 |
typedef struct PicState { |
typedef struct PicState { |
542 |
uint8_t last_irr; /* edge detection */ |
uint8_t last_irr; /* edge detection */ |
543 |
uint8_t irr; /* interrupt request register */ |
uint8_t irr; /* interrupt request register */ |
632 |
int64_t irq_time[16]; |
int64_t irq_time[16]; |
633 |
int64_t cpu_get_ticks(void); |
int64_t cpu_get_ticks(void); |
634 |
#endif |
#endif |
635 |
|
#ifdef DEBUG_PIC |
636 |
|
int irq_level[16]; |
637 |
|
#endif |
638 |
|
|
639 |
void pic_set_irq(int irq, int level) |
void pic_set_irq(int irq, int level) |
640 |
{ |
{ |
641 |
|
#ifdef DEBUG_PIC |
642 |
|
if (level != irq_level[irq]) { |
643 |
|
printf("pic_set_irq: irq=%d level=%d\n", irq, level); |
644 |
|
irq_level[irq] = level; |
645 |
|
} |
646 |
|
#endif |
647 |
#ifdef DEBUG_IRQ_LATENCY |
#ifdef DEBUG_IRQ_LATENCY |
648 |
if (level) { |
if (level) { |
649 |
irq_time[irq] = cpu_get_ticks(); |
irq_time[irq] = cpu_get_ticks(); |
662 |
#ifdef DEBUG_IRQ_LATENCY |
#ifdef DEBUG_IRQ_LATENCY |
663 |
printf("IRQ%d latency=%Ld\n", irq, cpu_get_ticks() - irq_time[irq]); |
printf("IRQ%d latency=%Ld\n", irq, cpu_get_ticks() - irq_time[irq]); |
664 |
#endif |
#endif |
665 |
|
#ifdef DEBUG_PIC |
666 |
|
printf("pic_interrupt: irq=%d\n", irq); |
667 |
|
#endif |
668 |
|
|
669 |
if (irq >= 8) { |
if (irq >= 8) { |
670 |
irq2 = irq & 7; |
irq2 = irq & 7; |
685 |
PicState *s; |
PicState *s; |
686 |
int priority; |
int priority; |
687 |
|
|
688 |
|
#ifdef DEBUG_PIC |
689 |
|
printf("pic_write: addr=0x%02x val=0x%02x\n", addr, val); |
690 |
|
#endif |
691 |
s = &pics[addr >> 7]; |
s = &pics[addr >> 7]; |
692 |
addr &= 1; |
addr &= 1; |
693 |
if (addr == 0) { |
if (addr == 0) { |
760 |
} |
} |
761 |
} |
} |
762 |
|
|
763 |
uint32_t pic_ioport_read(CPUX86State *env, uint32_t addr) |
uint32_t pic_ioport_read(CPUX86State *env, uint32_t addr1) |
764 |
{ |
{ |
765 |
PicState *s; |
PicState *s; |
766 |
|
unsigned int addr; |
767 |
|
int ret; |
768 |
|
|
769 |
|
addr = addr1; |
770 |
s = &pics[addr >> 7]; |
s = &pics[addr >> 7]; |
771 |
addr &= 1; |
addr &= 1; |
772 |
if (addr == 0) { |
if (addr == 0) { |
773 |
if (s->read_reg_select) |
if (s->read_reg_select) |
774 |
return s->isr; |
ret = s->isr; |
775 |
else |
else |
776 |
return s->irr; |
ret = s->irr; |
777 |
} else { |
} else { |
778 |
return s->imr; |
ret = s->imr; |
779 |
} |
} |
780 |
|
#ifdef DEBUG_PIC |
781 |
|
printf("pic_read: addr=0x%02x val=0x%02x\n", addr1, ret); |
782 |
|
#endif |
783 |
|
return ret; |
784 |
} |
} |
785 |
|
|
786 |
void pic_init(void) |
void pic_init(void) |
2659 |
help(); |
help(); |
2660 |
|
|
2661 |
/* init debug */ |
/* init debug */ |
2662 |
|
setvbuf(stdout, NULL, _IOLBF, 0); |
2663 |
if (loglevel) { |
if (loglevel) { |
2664 |
logfile = fopen(DEBUG_LOGFILE, "w"); |
logfile = fopen(DEBUG_LOGFILE, "w"); |
2665 |
if (!logfile) { |
if (!logfile) { |