Subversion Repositories HelenOS

Rev

Rev 2412 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2412 Rev 2414
1
/*
1
/*
2
 * Copyright (c) 2007 Michal Kebrt, Petr Stepan
2
 * Copyright (c) 2007 Michal Kebrt, Petr Stepan
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup arm32
29
/** @addtogroup arm32
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 *  @brief GXemul drivers.
33
 *  @brief GXemul drivers.
34
 */
34
 */
35
 
35
 
36
#include <interrupt.h>
36
#include <interrupt.h>
37
#include <ipc/irq.h>
37
#include <ipc/irq.h>
38
#include <console/chardev.h>
38
#include <console/chardev.h>
39
#include <arch/drivers/gxemul.h>
39
#include <arch/drivers/gxemul.h>
40
#include <console/console.h>
40
#include <console/console.h>
41
#include <sysinfo/sysinfo.h>
41
#include <sysinfo/sysinfo.h>
42
#include <print.h>
42
#include <print.h>
43
#include <ddi/device.h>
43
#include <ddi/device.h>
44
#include <mm/page.h>
44
#include <mm/page.h>
45
#include <arch/machine.h>
45
#include <arch/machine.h>
46
#include <arch/debug/print.h>
46
#include <arch/debug/print.h>
47
 
47
 
48
 
48
 
49
/** Addresses of devices. */
49
/* Addresses of devices. */
50
#define GXEMUL_VIDEORAM            0x10000000
50
#define GXEMUL_VIDEORAM            0x10000000
51
#define GXEMUL_KBD                 0x10000000
51
#define GXEMUL_KBD                 0x10000000
52
#define GXEMUL_HALT_OFFSET         0x10
52
#define GXEMUL_HALT_OFFSET         0x10
53
#define GXEMUL_RTC                 0x15000000
53
#define GXEMUL_RTC                 0x15000000
54
#define GXEMUL_RTC_FREQ_OFFSET     0x100
54
#define GXEMUL_RTC_FREQ_OFFSET     0x100
55
#define GXEMUL_RTC_ACK_OFFSET      0x110
55
#define GXEMUL_RTC_ACK_OFFSET      0x110
56
#define GXEMUL_IRQC                0x16000000
56
#define GXEMUL_IRQC                0x16000000
57
#define GXEMUL_IRQC_MASK_OFFSET    0x4
57
#define GXEMUL_IRQC_MASK_OFFSET    0x4
58
#define GXEMUL_IRQC_UNMASK_OFFSET  0x8
58
#define GXEMUL_IRQC_UNMASK_OFFSET  0x8
59
#define GXEMUL_MP                  0x11000000
59
#define GXEMUL_MP                  0x11000000
60
#define GXEMUL_MP_MEMSIZE_OFFSET   0x0090
60
#define GXEMUL_MP_MEMSIZE_OFFSET   0x0090
61
#define GXEMUL_FB                  0x12000000
61
#define GXEMUL_FB                  0x12000000
62
 
62
 
63
 
63
 
64
/** IRQs */
64
/* IRQs */
65
#define GXEMUL_KBD_IRQ      2
65
#define GXEMUL_KBD_IRQ      2
66
#define GXEMUL_TIMER_IRQ    4
66
#define GXEMUL_TIMER_IRQ    4
67
 
67
 
68
static gxemul_hw_map_t gxemul_hw_map;
68
static gxemul_hw_map_t gxemul_hw_map;
69
static chardev_t console;
69
static chardev_t console;
70
static irq_t gxemul_irq;
70
static irq_t gxemul_console_irq;
71
static irq_t gxemul_timer_irq;
71
static irq_t gxemul_timer_irq;
72
 
72
 
73
static bool hw_map_init_called = false;
73
static bool hw_map_init_called = false;
74
 
74
 
-
 
75
static void gxemul_kbd_enable(chardev_t *dev);
-
 
76
static void gxemul_kbd_disable(chardev_t *dev);
75
static void gxemul_write(chardev_t *dev, const char ch);
77
static void gxemul_write(chardev_t *dev, const char ch);
76
static void gxemul_enable(chardev_t *dev);
-
 
77
static void gxemul_disable(chardev_t *dev);
-
 
78
static char gxemul_do_read(chardev_t *dev);
78
static char gxemul_do_read(chardev_t *dev);
79
 
79
 
80
static chardev_operations_t gxemul_ops = {
80
static chardev_operations_t gxemul_ops = {
81
    .resume = gxemul_enable,
81
    .resume = gxemul_kbd_enable,
82
    .suspend = gxemul_disable,
82
    .suspend = gxemul_kbd_disable,
83
    .write = gxemul_write,
83
    .write = gxemul_write,
84
    .read = gxemul_do_read,
84
    .read = gxemul_do_read,
85
};
85
};
86
 
86
 
87
 
87
 
88
/** Returns the mask of active interrupts. */
88
/** Returns the mask of active interrupts. */
89
static inline uint32_t gxemul_irqc_get_sources(void)
89
static inline uint32_t gxemul_irqc_get_sources(void)
90
{
90
{
91
    return *(uint32_t*) gxemul_hw_map.irqc;
91
    return *(uint32_t*) gxemul_hw_map.irqc;
92
}
92
}
93
 
93
 
94
 
94
 
95
/** Masks interrupt.
95
/** Masks interrupt.
96
 *
96
 *
97
 * @param irq interrupt number
97
 * @param irq interrupt number
98
 */
98
 */
99
static inline void gxemul_irqc_mask(uint32_t irq)
99
static inline void gxemul_irqc_mask(uint32_t irq)
100
{
100
{
101
    *(uint32_t*) gxemul_hw_map.irqc_mask = irq;
101
    *(uint32_t*) gxemul_hw_map.irqc_mask = irq;
102
}
102
}
103
 
103
 
104
 
104
 
105
/** Unmasks interrupt.
105
/** Unmasks interrupt.
106
 *
106
 *
107
 * @param irq interrupt number
107
 * @param irq interrupt number
108
 */
108
 */
109
static inline void gxemul_irqc_unmask(uint32_t irq)
109
static inline void gxemul_irqc_unmask(uint32_t irq)
110
{
110
{
111
    *(uint32_t*) gxemul_hw_map.irqc_unmask = irq;
111
    *(uint32_t*) gxemul_hw_map.irqc_unmask = irq;
112
}
112
}
113
 
113
 
114
 
114
 
115
/** Initializes #gxemul_hw_map. */
115
/** Initializes #gxemul_hw_map. */
116
void gxemul_hw_map_init(void)
116
void gxemul_hw_map_init(void)
117
{
117
{
118
    gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE);
118
    gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE);
119
    gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE);
119
    gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE);
120
    gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE);
120
    gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE);
121
    gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE);
121
    gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE);
122
 
122
 
123
    gxemul_hw_map.rtc_freq = gxemul_hw_map.rtc + GXEMUL_RTC_FREQ_OFFSET;
123
    gxemul_hw_map.rtc_freq = gxemul_hw_map.rtc + GXEMUL_RTC_FREQ_OFFSET;
124
    gxemul_hw_map.rtc_ack = gxemul_hw_map.rtc + GXEMUL_RTC_ACK_OFFSET;
124
    gxemul_hw_map.rtc_ack = gxemul_hw_map.rtc + GXEMUL_RTC_ACK_OFFSET;
125
    gxemul_hw_map.irqc_mask = gxemul_hw_map.irqc + GXEMUL_IRQC_MASK_OFFSET;
125
    gxemul_hw_map.irqc_mask = gxemul_hw_map.irqc + GXEMUL_IRQC_MASK_OFFSET;
126
    gxemul_hw_map.irqc_unmask = gxemul_hw_map.irqc + GXEMUL_IRQC_UNMASK_OFFSET;
126
    gxemul_hw_map.irqc_unmask = gxemul_hw_map.irqc + GXEMUL_IRQC_UNMASK_OFFSET;
127
 
127
 
128
    hw_map_init_called = true;
128
    hw_map_init_called = true;
129
}
129
}
130
 
130
 
131
 
131
 
132
/** Putchar that works with gxemul */
132
/** Putchar that works with gxemul.
-
 
133
 *
-
 
134
 * @param dev Not used.
-
 
135
 * @param ch Characted to be printed.
-
 
136
 */
133
static void gxemul_write(chardev_t *dev, const char ch)
137
static void gxemul_write(chardev_t *dev, const char ch)
134
{
138
{
135
    *((char *) gxemul_hw_map.videoram) = ch;
139
    *((char *) gxemul_hw_map.videoram) = ch;
136
}
140
}
137
 
141
 
138
 
142
 
-
 
143
/** Enables gxemul keyboard (interrupt unmasked).
-
 
144
 *
-
 
145
 * @param dev Not used.
-
 
146
 *
139
/* Called from getc(). */
147
 * Called from getc().
-
 
148
 */
140
static void gxemul_enable(chardev_t *dev)
149
static void gxemul_kbd_enable(chardev_t *dev)
141
{
150
{
142
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
151
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
143
}
152
}
144
 
153
 
145
 
154
 
-
 
155
/** Disables gxemul keyboard (interrupt masked).
-
 
156
 *
-
 
157
 * @param dev not used
-
 
158
 *
146
/* Called from getc(). */
159
 * Called from getc().
-
 
160
 */
147
static void gxemul_disable(chardev_t *dev)
161
static void gxemul_kbd_disable(chardev_t *dev)
148
{
162
{
149
    gxemul_irqc_mask(GXEMUL_KBD_IRQ);
163
    gxemul_irqc_mask(GXEMUL_KBD_IRQ);
150
}
164
}
151
 
165
 
152
 
166
 
153
/** Read character using polling, assume interrupts disabled.
167
/** Read character using polling, assume interrupts disabled.
154
 *
168
 *
155
 *  @param dev Not used.
169
 *  @param dev Not used.
156
 */
170
 */
157
static char gxemul_do_read(chardev_t *dev)
171
static char gxemul_do_read(chardev_t *dev)
158
{
172
{
159
    char ch;
173
    char ch;
160
 
174
 
161
    while (1) {
175
    while (1) {
162
        ch = *((volatile char *) gxemul_hw_map.kbd);
176
        ch = *((volatile char *) gxemul_hw_map.kbd);
163
        if (ch) {
177
        if (ch) {
164
            if (ch == '\r')
178
            if (ch == '\r')
165
                return '\n';
179
                return '\n';
166
            if (ch == 0x7f)
180
            if (ch == 0x7f)
167
                return '\b';
181
                return '\b';
168
            return ch;
182
            return ch;
169
        }
183
        }
170
    }
184
    }
171
}
185
}
172
 
186
 
173
 
187
 
174
/** Process keyboard interrupt. */
188
/** Process keyboard interrupt.
-
 
189
 *  
-
 
190
 *  @param irq IRQ information.
-
 
191
 *  @param arg Not used.
-
 
192
 */
175
static void gxemul_irq_handler(irq_t *irq, void *arg, ...)
193
static void gxemul_irq_handler(irq_t *irq, void *arg, ...)
176
{
194
{
177
    if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) {
195
    if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) {
178
        ipc_irq_send_notif(irq);
196
        ipc_irq_send_notif(irq);
179
    } else {
197
    } else {
180
        char ch = 0;
198
        char ch = 0;
181
       
199
       
182
        ch = *((char *) gxemul_hw_map.kbd);
200
        ch = *((char *) gxemul_hw_map.kbd);
183
        if (ch == '\r') {
201
        if (ch == '\r') {
184
            ch = '\n';
202
            ch = '\n';
185
        }
203
        }
186
        if (ch == 0x7f) {
204
        if (ch == 0x7f) {
187
            ch = '\b';
205
            ch = '\b';
188
        }
206
        }
189
        chardev_push_character(&console, ch);
207
        chardev_push_character(&console, ch);
190
    }
208
    }
191
}
209
}
192
 
210
 
193
 
211
 
194
static irq_ownership_t gxemul_claim(void)
212
static irq_ownership_t gxemul_claim(void)
195
{
213
{
196
    return IRQ_ACCEPT;
214
    return IRQ_ACCEPT;
197
}
215
}
198
 
216
 
199
 
217
 
200
/** Acquire console back for kernel. */
218
/** Acquire console back for kernel. */
201
void gxemul_grab_console(void)
219
void gxemul_grab_console(void)
202
{
220
{
203
    ipl_t ipl = interrupts_disable();
221
    ipl_t ipl = interrupts_disable();
204
    spinlock_lock(&gxemul_irq.lock);
222
    spinlock_lock(&gxemul_console_irq.lock);
205
    gxemul_irq.notif_cfg.notify = false;
223
    gxemul_console_irq.notif_cfg.notify = false;
206
    spinlock_unlock(&gxemul_irq.lock);
224
    spinlock_unlock(&gxemul_console_irq.lock);
207
    interrupts_restore(ipl);
225
    interrupts_restore(ipl);
208
}
226
}
209
 
227
 
210
 
228
 
211
/** Return console to userspace. */
229
/** Return console to userspace. */
212
void gxemul_release_console(void)
230
void gxemul_release_console(void)
213
{
231
{
214
    ipl_t ipl = interrupts_disable();
232
    ipl_t ipl = interrupts_disable();
215
    spinlock_lock(&gxemul_irq.lock);
233
    spinlock_lock(&gxemul_console_irq.lock);
216
    if (gxemul_irq.notif_cfg.answerbox) {
234
    if (gxemul_console_irq.notif_cfg.answerbox) {
217
        gxemul_irq.notif_cfg.notify = true;
235
        gxemul_console_irq.notif_cfg.notify = true;
218
    }
236
    }
219
    spinlock_unlock(&gxemul_irq.lock);
237
    spinlock_unlock(&gxemul_console_irq.lock);
220
    interrupts_restore(ipl);
238
    interrupts_restore(ipl);
221
}
239
}
222
 
240
 
223
 
241
 
224
/** Initializes console object representing gxemul console.
242
/** Initializes console object representing gxemul console.
225
 *
243
 *
226
 *  @param Console device number.
244
 *  @param Console device number.
227
 */
245
 */
228
void gxemul_console_init(devno_t devno)
246
void gxemul_console_init(devno_t devno)
229
{
247
{
230
    chardev_initialize("gxemul_console", &console, &gxemul_ops);
248
    chardev_initialize("gxemul_console", &console, &gxemul_ops);
231
    stdin = &console;
249
    stdin = &console;
232
    stdout = &console;
250
    stdout = &console;
233
   
251
   
234
    irq_initialize(&gxemul_irq);
252
    irq_initialize(&gxemul_console_irq);
235
    gxemul_irq.devno = devno;
253
    gxemul_console_irq.devno = devno;
236
    gxemul_irq.inr = GXEMUL_KBD_IRQ;
254
    gxemul_console_irq.inr = GXEMUL_KBD_IRQ;
237
    gxemul_irq.claim = gxemul_claim;
255
    gxemul_console_irq.claim = gxemul_claim;
238
    gxemul_irq.handler = gxemul_irq_handler;
256
    gxemul_console_irq.handler = gxemul_irq_handler;
239
    irq_register(&gxemul_irq);
257
    irq_register(&gxemul_console_irq);
240
   
258
   
241
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
259
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
242
   
260
   
243
    sysinfo_set_item_val("kbd", NULL, true);
261
    sysinfo_set_item_val("kbd", NULL, true);
244
    sysinfo_set_item_val("kbd.devno", NULL, devno);
262
    sysinfo_set_item_val("kbd.devno", NULL, devno);
245
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
263
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
246
    sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd);
264
    sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd);
247
}
265
}
248
 
266
 
249
 
267
 
250
 
268
 
251
/** Starts gxemul Real Time Clock device, which asserts regular interrupts.
269
/** Starts gxemul Real Time Clock device, which asserts regular interrupts.
252
 *
270
 *
253
 * @param frequency Interrupts frequency (0 disables RTC).
271
 * @param frequency Interrupts frequency (0 disables RTC).
254
 */
272
 */
255
static void gxemul_timer_start(uint32_t frequency)
273
static void gxemul_timer_start(uint32_t frequency)
256
{
274
{
257
    *(uint32_t*) gxemul_hw_map.rtc_freq = frequency;
275
    *(uint32_t*) gxemul_hw_map.rtc_freq = frequency;
258
}
276
}
259
 
277
 
260
 
278
 
261
static irq_ownership_t gxemul_timer_claim(void)
279
static irq_ownership_t gxemul_timer_claim(void)
262
{
280
{
263
    return IRQ_ACCEPT;
281
    return IRQ_ACCEPT;
264
}
282
}
265
 
283
 
266
 
284
 
267
/** Timer interrupt handler.
285
/** Timer interrupt handler.
268
 *
286
 *
269
 * @param irq Interrupt information.
287
 * @param irq Interrupt information.
270
 * @param arg Not used.
288
 * @param arg Not used.
271
 */
289
 */
272
static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...)
290
static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...)
273
{
291
{
274
    /* TODO time drifts ??
-
 
275
    unsigned long drift;
-
 
276
 
-
 
277
    drift = cp0_count_read() - nextcount;
-
 
278
    while (drift > cp0_compare_value) {
-
 
279
        drift -= cp0_compare_value;
-
 
280
        CPU->missed_clock_ticks++;
-
 
281
    }
-
 
282
    nextcount = cp0_count_read() + cp0_compare_value - drift;
-
 
283
    cp0_compare_write(nextcount);
-
 
284
    */
-
 
285
 
-
 
286
    /*
292
    /*
287
    * We are holding a lock which prevents preemption.
293
    * We are holding a lock which prevents preemption.
288
    * Release the lock, call clock() and reacquire the lock again.
294
    * Release the lock, call clock() and reacquire the lock again.
289
    */
295
    */
290
    spinlock_unlock(&irq->lock);
296
    spinlock_unlock(&irq->lock);
291
    clock();
297
    clock();
292
    spinlock_lock(&irq->lock);
298
    spinlock_lock(&irq->lock);
293
 
299
 
294
    /* acknowledge tick */
300
    /* acknowledge tick */
295
    *(uint32_t*) gxemul_hw_map.rtc_ack = 0;
301
    *(uint32_t*) gxemul_hw_map.rtc_ack = 0;
296
   
-
 
297
    /* TODO what's that? *
-
 
298
    if (virtual_timer_fnc != NULL)
-
 
299
        virtual_timer_fnc();
-
 
300
    */
-
 
301
}
302
}
302
 
303
 
303
 
304
 
304
/** Initializes and registers timer interrupt handler. */
305
/** Initializes and registers timer interrupt handler. */
305
static void gxemul_timer_irq_init()
306
static void gxemul_timer_irq_init()
306
{
307
{
307
    irq_initialize(&gxemul_timer_irq);
308
    irq_initialize(&gxemul_timer_irq);
308
    gxemul_timer_irq.devno = device_assign_devno();
309
    gxemul_timer_irq.devno = device_assign_devno();
309
    gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ;
310
    gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ;
310
    gxemul_timer_irq.claim = gxemul_timer_claim;
311
    gxemul_timer_irq.claim = gxemul_timer_claim;
311
    gxemul_timer_irq.handler = gxemul_timer_irq_handler;
312
    gxemul_timer_irq.handler = gxemul_timer_irq_handler;
312
 
313
 
313
    irq_register(&gxemul_timer_irq);
314
    irq_register(&gxemul_timer_irq);
314
}
315
}
315
 
316
 
316
 
317
 
317
/** Starts timer.
318
/** Starts timer.
318
 *
319
 *
319
 * Initiates regular timer interrupts after initializing
320
 * Initiates regular timer interrupts after initializing
320
 * corresponding interrupt handler.
321
 * corresponding interrupt handler.
321
 */
322
 */
322
void gxemul_timer_irq_start()
323
void gxemul_timer_irq_start()
323
{
324
{
324
    gxemul_timer_irq_init();
325
    gxemul_timer_irq_init();
325
    gxemul_timer_start(GXEMUL_TIMER_FREQ);
326
    gxemul_timer_start(GXEMUL_TIMER_FREQ);
326
}
327
}
327
 
328
 
328
 
329
 
329
/** Returns the size of emulated memory.
330
/** Returns the size of emulated memory.
330
 *
331
 *
331
 * @return Size in bytes.
332
 * @return Size in bytes.
332
 */
333
 */
333
size_t gxemul_get_memory_size(void)
334
size_t gxemul_get_memory_size(void)
334
{
335
{
335
    return  *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET));
336
    return  *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET));
336
}
337
}
337
 
338
 
338
 
339
 
339
/** Prints a character.
340
/** Prints a character.
340
 *
341
 *
341
 *  @param ch Character to be printed.
342
 *  @param ch Character to be printed.
342
 */
343
 */
343
void gxemul_debug_putc(char ch)
344
void gxemul_debug_putc(char ch)
344
{
345
{
345
    char * addr = 0;
346
    char * addr = 0;
346
    if (!hw_map_init_called) {
347
    if (!hw_map_init_called) {
347
        addr = (char *) GXEMUL_KBD;
348
        addr = (char *) GXEMUL_KBD;
348
    } else {
349
    } else {
349
        addr = (char *) gxemul_hw_map.videoram;
350
        addr = (char *) gxemul_hw_map.videoram;
350
    }
351
    }
351
 
352
 
352
    *(addr) = ch;
353
    *(addr) = ch;
353
}
354
}
354
 
355
 
355
 
356
 
356
/** Stops gxemul. */
357
/** Stops gxemul. */
357
void gxemul_cpu_halt(void)
358
void gxemul_cpu_halt(void)
358
{
359
{
359
    char * addr = 0;
360
    char * addr = 0;
360
    if (!hw_map_init_called) {
361
    if (!hw_map_init_called) {
361
        addr = (char *) GXEMUL_KBD;
362
        addr = (char *) GXEMUL_KBD;
362
    } else {
363
    } else {
363
        addr = (char *) gxemul_hw_map.videoram;
364
        addr = (char *) gxemul_hw_map.videoram;
364
    }
365
    }
365
   
366
   
366
    *(addr + GXEMUL_HALT_OFFSET) = '\0';
367
    *(addr + GXEMUL_HALT_OFFSET) = '\0';
367
}
368
}
368
 
369
 
369
 
370
 
370
/** Gxemul specific interrupt exception handler.
371
/** Gxemul specific interrupt exception handler.
371
 *
372
 *
372
 * Determines sources of the interrupt from interrupt controller and
373
 * Determines sources of the interrupt from interrupt controller and
373
 * calls high-level handlers for them.
374
 * calls high-level handlers for them.
374
 *
375
 *
375
 * @param exc_no Interrupt exception number.
376
 * @param exc_no Interrupt exception number.
376
 * @param istate Saved processor state.
377
 * @param istate Saved processor state.
377
 */
378
 */
378
void gxemul_irq_exception(int exc_no, istate_t *istate)
379
void gxemul_irq_exception(int exc_no, istate_t *istate)
379
{
380
{
380
    uint32_t sources = gxemul_irqc_get_sources();
381
    uint32_t sources = gxemul_irqc_get_sources();
381
    int i = 0;
382
    int i = 0;
382
    for (; i < GXEMUL_IRQC_MAX_IRQ; i++) {
383
    for (; i < GXEMUL_IRQC_MAX_IRQ; i++) {
383
        if (sources & (1 << i)) {
384
        if (sources & (1 << i)) {
384
            irq_t *irq = irq_dispatch_and_lock(i);
385
            irq_t *irq = irq_dispatch_and_lock(i);
385
            if (irq) {
386
            if (irq) {
386
                /* The IRQ handler was found. */
387
                /* The IRQ handler was found. */
387
                irq->handler(irq, irq->arg);
388
                irq->handler(irq, irq->arg);
388
                spinlock_unlock(&irq->lock);
389
                spinlock_unlock(&irq->lock);
389
            } else {
390
            } else {
390
                /* Spurious interrupt.*/
391
                /* Spurious interrupt.*/
391
                dprintf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, i);
392
                dprintf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, i);
392
            }
393
            }
393
        }
394
        }
394
    }
395
    }
395
}
396
}
396
 
397
 
397
/** Returns address of framebuffer device.
398
/** Returns address of framebuffer device.
398
 *
399
 *
399
 *  @return Address of framebuffer device.
400
 *  @return Address of framebuffer device.
400
 */
401
 */
401
uintptr_t gxemul_get_fb_address(void)
402
uintptr_t gxemul_get_fb_address(void)
402
{
403
{
403
    return (uintptr_t) GXEMUL_FB;
404
    return (uintptr_t) GXEMUL_FB;
404
}
405
}
405
 
406
 
406
/** @}
407
/** @}
407
 */
408
 */
408
 
409