46,7 → 46,7 |
#include <arch/debug/print.h> |
|
|
/** Addresses of devices. */ |
/* Addresses of devices. */ |
#define GXEMUL_VIDEORAM 0x10000000 |
#define GXEMUL_KBD 0x10000000 |
#define GXEMUL_HALT_OFFSET 0x10 |
61,25 → 61,25 |
#define GXEMUL_FB 0x12000000 |
|
|
/** IRQs */ |
/* IRQs */ |
#define GXEMUL_KBD_IRQ 2 |
#define GXEMUL_TIMER_IRQ 4 |
|
static gxemul_hw_map_t gxemul_hw_map; |
static chardev_t console; |
static irq_t gxemul_irq; |
static irq_t gxemul_console_irq; |
static irq_t gxemul_timer_irq; |
|
static bool hw_map_init_called = false; |
|
static void gxemul_kbd_enable(chardev_t *dev); |
static void gxemul_kbd_disable(chardev_t *dev); |
static void gxemul_write(chardev_t *dev, const char ch); |
static void gxemul_enable(chardev_t *dev); |
static void gxemul_disable(chardev_t *dev); |
static char gxemul_do_read(chardev_t *dev); |
|
static chardev_operations_t gxemul_ops = { |
.resume = gxemul_enable, |
.suspend = gxemul_disable, |
.resume = gxemul_kbd_enable, |
.suspend = gxemul_kbd_disable, |
.write = gxemul_write, |
.read = gxemul_do_read, |
}; |
129,7 → 129,11 |
} |
|
|
/** Putchar that works with gxemul */ |
/** Putchar that works with gxemul. |
* |
* @param dev Not used. |
* @param ch Characted to be printed. |
*/ |
static void gxemul_write(chardev_t *dev, const char ch) |
{ |
*((char *) gxemul_hw_map.videoram) = ch; |
136,15 → 140,25 |
} |
|
|
/* Called from getc(). */ |
static void gxemul_enable(chardev_t *dev) |
/** Enables gxemul keyboard (interrupt unmasked). |
* |
* @param dev Not used. |
* |
* Called from getc(). |
*/ |
static void gxemul_kbd_enable(chardev_t *dev) |
{ |
gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
} |
|
|
/* Called from getc(). */ |
static void gxemul_disable(chardev_t *dev) |
/** Disables gxemul keyboard (interrupt masked). |
* |
* @param dev not used |
* |
* Called from getc(). |
*/ |
static void gxemul_kbd_disable(chardev_t *dev) |
{ |
gxemul_irqc_mask(GXEMUL_KBD_IRQ); |
} |
171,7 → 185,11 |
} |
|
|
/** Process keyboard interrupt. */ |
/** Process keyboard interrupt. |
* |
* @param irq IRQ information. |
* @param arg Not used. |
*/ |
static void gxemul_irq_handler(irq_t *irq, void *arg, ...) |
{ |
if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) { |
201,9 → 219,9 |
void gxemul_grab_console(void) |
{ |
ipl_t ipl = interrupts_disable(); |
spinlock_lock(&gxemul_irq.lock); |
gxemul_irq.notif_cfg.notify = false; |
spinlock_unlock(&gxemul_irq.lock); |
spinlock_lock(&gxemul_console_irq.lock); |
gxemul_console_irq.notif_cfg.notify = false; |
spinlock_unlock(&gxemul_console_irq.lock); |
interrupts_restore(ipl); |
} |
|
212,11 → 230,11 |
void gxemul_release_console(void) |
{ |
ipl_t ipl = interrupts_disable(); |
spinlock_lock(&gxemul_irq.lock); |
if (gxemul_irq.notif_cfg.answerbox) { |
gxemul_irq.notif_cfg.notify = true; |
spinlock_lock(&gxemul_console_irq.lock); |
if (gxemul_console_irq.notif_cfg.answerbox) { |
gxemul_console_irq.notif_cfg.notify = true; |
} |
spinlock_unlock(&gxemul_irq.lock); |
spinlock_unlock(&gxemul_console_irq.lock); |
interrupts_restore(ipl); |
} |
|
231,12 → 249,12 |
stdin = &console; |
stdout = &console; |
|
irq_initialize(&gxemul_irq); |
gxemul_irq.devno = devno; |
gxemul_irq.inr = GXEMUL_KBD_IRQ; |
gxemul_irq.claim = gxemul_claim; |
gxemul_irq.handler = gxemul_irq_handler; |
irq_register(&gxemul_irq); |
irq_initialize(&gxemul_console_irq); |
gxemul_console_irq.devno = devno; |
gxemul_console_irq.inr = GXEMUL_KBD_IRQ; |
gxemul_console_irq.claim = gxemul_claim; |
gxemul_console_irq.handler = gxemul_irq_handler; |
irq_register(&gxemul_console_irq); |
|
gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
|
271,18 → 289,6 |
*/ |
static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...) |
{ |
/* TODO time drifts ?? |
unsigned long drift; |
|
drift = cp0_count_read() - nextcount; |
while (drift > cp0_compare_value) { |
drift -= cp0_compare_value; |
CPU->missed_clock_ticks++; |
} |
nextcount = cp0_count_read() + cp0_compare_value - drift; |
cp0_compare_write(nextcount); |
*/ |
|
/* |
* We are holding a lock which prevents preemption. |
* Release the lock, call clock() and reacquire the lock again. |
293,11 → 299,6 |
|
/* acknowledge tick */ |
*(uint32_t*) gxemul_hw_map.rtc_ack = 0; |
|
/* TODO what's that? * |
if (virtual_timer_fnc != NULL) |
virtual_timer_fnc(); |
*/ |
} |
|
|