Rev 2358 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2358 | Rev 2360 | ||
---|---|---|---|
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 | */ |
33 | */ |
34 | 34 | ||
35 | #include <interrupt.h> |
35 | #include <interrupt.h> |
36 | #include <ipc/irq.h> |
36 | #include <ipc/irq.h> |
37 | #include <console/chardev.h> |
37 | #include <console/chardev.h> |
38 | #include <arch/drivers/gxemul.h> |
38 | #include <arch/drivers/gxemul.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
41 | #include <print.h> |
41 | #include <print.h> |
42 | #include <ddi/device.h> |
42 | #include <ddi/device.h> |
43 | #include <mm/page.h> |
43 | #include <mm/page.h> |
44 | #include <arch/machine.h> |
44 | #include <arch/machine.h> |
45 | #include <arch/debug/print.h> |
45 | #include <arch/debug/print.h> |
46 | 46 | ||
47 | 47 | ||
48 | /** Addresses of devices. */ |
48 | /** Addresses of devices. */ |
49 | #define GXEMUL_VIDEORAM 0x10000000 |
49 | #define GXEMUL_VIDEORAM 0x10000000 |
50 | #define GXEMUL_KBD 0x10000000 |
50 | #define GXEMUL_KBD 0x10000000 |
51 | #define GXEMUL_HALT_OFFSET 0x10 |
51 | #define GXEMUL_HALT_OFFSET 0x10 |
52 | #define GXEMUL_RTC 0x15000000 |
52 | #define GXEMUL_RTC 0x15000000 |
53 | #define GXEMUL_RTC_FREQ_OFFSET 0x100 |
53 | #define GXEMUL_RTC_FREQ_OFFSET 0x100 |
54 | #define GXEMUL_RTC_ACK_OFFSET 0x110 |
54 | #define GXEMUL_RTC_ACK_OFFSET 0x110 |
55 | #define GXEMUL_IRQC 0x16000000 |
55 | #define GXEMUL_IRQC 0x16000000 |
56 | #define GXEMUL_IRQC_MASK_OFFSET 0x4 |
56 | #define GXEMUL_IRQC_MASK_OFFSET 0x4 |
57 | #define GXEMUL_IRQC_UNMASK_OFFSET 0x8 |
57 | #define GXEMUL_IRQC_UNMASK_OFFSET 0x8 |
58 | #define GXEMUL_MP 0x11000000 |
58 | #define GXEMUL_MP 0x11000000 |
59 | #define GXEMUL_MP_MEMSIZE_OFFSET 0x0090 |
59 | #define GXEMUL_MP_MEMSIZE_OFFSET 0x0090 |
60 | #define GXEMUL_FB 0x12000000 |
60 | #define GXEMUL_FB 0x12000000 |
61 | 61 | ||
62 | 62 | ||
63 | /** IRQs */ |
63 | /** IRQs */ |
64 | #define GXEMUL_KBD_IRQ 2 |
64 | #define GXEMUL_KBD_IRQ 2 |
65 | #define GXEMUL_TIMER_IRQ 4 |
65 | #define GXEMUL_TIMER_IRQ 4 |
66 | 66 | ||
67 | static gxemul_hw_map_t gxemul_hw_map; |
67 | static gxemul_hw_map_t gxemul_hw_map; |
68 | static chardev_t console; |
68 | static chardev_t console; |
69 | static irq_t gxemul_irq; |
69 | static irq_t gxemul_irq; |
70 | static irq_t gxemul_timer_irq; |
70 | static irq_t gxemul_timer_irq; |
71 | 71 | ||
72 | static bool hw_map_init_called = false; |
72 | static bool hw_map_init_called = false; |
73 | 73 | ||
74 | static void gxemul_write(chardev_t *dev, const char ch); |
74 | static void gxemul_write(chardev_t *dev, const char ch); |
75 | static void gxemul_enable(chardev_t *dev); |
75 | static void gxemul_enable(chardev_t *dev); |
76 | static void gxemul_disable(chardev_t *dev); |
76 | static void gxemul_disable(chardev_t *dev); |
77 | static char gxemul_do_read(chardev_t *dev); |
77 | static char gxemul_do_read(chardev_t *dev); |
78 | 78 | ||
79 | static chardev_operations_t gxemul_ops = { |
79 | static chardev_operations_t gxemul_ops = { |
80 | .resume = gxemul_enable, |
80 | .resume = gxemul_enable, |
81 | .suspend = gxemul_disable, |
81 | .suspend = gxemul_disable, |
82 | .write = gxemul_write, |
82 | .write = gxemul_write, |
83 | .read = gxemul_do_read, |
83 | .read = gxemul_do_read, |
84 | }; |
84 | }; |
85 | 85 | ||
86 | 86 | ||
87 | /** Returns the mask of active interrupts. */ |
87 | /** Returns the mask of active interrupts. */ |
88 | static inline uint32_t gxemul_irqc_get_sources(void) |
88 | static inline uint32_t gxemul_irqc_get_sources(void) |
89 | { |
89 | { |
90 | return *(uint32_t*) gxemul_hw_map.irqc; |
90 | return *(uint32_t*) gxemul_hw_map.irqc; |
91 | } |
91 | } |
92 | 92 | ||
93 | 93 | ||
94 | /** Masks interrupt. |
94 | /** Masks interrupt. |
95 | * |
95 | * |
96 | * @param irq interrupt number |
96 | * @param irq interrupt number |
97 | */ |
97 | */ |
98 | static inline void gxemul_irqc_mask(uint32_t irq) |
98 | static inline void gxemul_irqc_mask(uint32_t irq) |
99 | { |
99 | { |
100 | *(uint32_t*) gxemul_hw_map.irqc_mask = irq; |
100 | *(uint32_t*) gxemul_hw_map.irqc_mask = irq; |
101 | } |
101 | } |
102 | 102 | ||
103 | 103 | ||
104 | /** Unmasks interrupt. |
104 | /** Unmasks interrupt. |
105 | * |
105 | * |
106 | * @param irq interrupt number |
106 | * @param irq interrupt number |
107 | */ |
107 | */ |
108 | static inline void gxemul_irqc_unmask(uint32_t irq) |
108 | static inline void gxemul_irqc_unmask(uint32_t irq) |
109 | { |
109 | { |
110 | *(uint32_t*) gxemul_hw_map.irqc_unmask = irq; |
110 | *(uint32_t*) gxemul_hw_map.irqc_unmask = irq; |
111 | } |
111 | } |
112 | 112 | ||
113 | 113 | ||
114 | /** Initializes #gxemul_hw_map. */ |
114 | /** Initializes #gxemul_hw_map. */ |
115 | void gxemul_hw_map_init(void) |
115 | void gxemul_hw_map_init(void) |
116 | { |
116 | { |
117 | gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE); |
117 | gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE); |
118 | gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE); |
118 | gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE); |
119 | gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE); |
119 | gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE); |
120 | gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE); |
120 | gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE); |
121 | gxemul_hw_map.fb = hw_map(GXEMUL_FB, PAGE_SIZE); |
- | |
122 | 121 | ||
123 | gxemul_hw_map.rtc_freq = gxemul_hw_map.rtc + GXEMUL_RTC_FREQ_OFFSET; |
122 | 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; |
123 | 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; |
124 | 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; |
125 | gxemul_hw_map.irqc_unmask = gxemul_hw_map.irqc + GXEMUL_IRQC_UNMASK_OFFSET; |
127 | 126 | ||
128 | hw_map_init_called = true; |
127 | hw_map_init_called = true; |
129 | } |
128 | } |
130 | 129 | ||
131 | 130 | ||
132 | /** Putchar that works with gxemul */ |
131 | /** Putchar that works with gxemul */ |
133 | static void gxemul_write(chardev_t *dev, const char ch) |
132 | static void gxemul_write(chardev_t *dev, const char ch) |
134 | { |
133 | { |
135 | *((char *) gxemul_hw_map.videoram) = ch; |
134 | *((char *) gxemul_hw_map.videoram) = ch; |
136 | } |
135 | } |
137 | 136 | ||
138 | 137 | ||
139 | /* Called from getc(). */ |
138 | /* Called from getc(). */ |
140 | static void gxemul_enable(chardev_t *dev) |
139 | static void gxemul_enable(chardev_t *dev) |
141 | { |
140 | { |
142 | gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
141 | gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
143 | } |
142 | } |
144 | 143 | ||
145 | 144 | ||
146 | /* Called from getc(). */ |
145 | /* Called from getc(). */ |
147 | static void gxemul_disable(chardev_t *dev) |
146 | static void gxemul_disable(chardev_t *dev) |
148 | { |
147 | { |
149 | gxemul_irqc_mask(GXEMUL_KBD_IRQ); |
148 | gxemul_irqc_mask(GXEMUL_KBD_IRQ); |
150 | } |
149 | } |
151 | 150 | ||
152 | 151 | ||
153 | /** Read character using polling, assume interrupts disabled. |
152 | /** Read character using polling, assume interrupts disabled. |
154 | * |
153 | * |
155 | * @param dev Not used. |
154 | * @param dev Not used. |
156 | */ |
155 | */ |
157 | static char gxemul_do_read(chardev_t *dev) |
156 | static char gxemul_do_read(chardev_t *dev) |
158 | { |
157 | { |
159 | char ch; |
158 | char ch; |
160 | 159 | ||
161 | while (1) { |
160 | while (1) { |
162 | ch = *((volatile char *) gxemul_hw_map.kbd); |
161 | ch = *((volatile char *) gxemul_hw_map.kbd); |
163 | if (ch) { |
162 | if (ch) { |
164 | if (ch == '\r') |
163 | if (ch == '\r') |
165 | return '\n'; |
164 | return '\n'; |
166 | if (ch == 0x7f) |
165 | if (ch == 0x7f) |
167 | return '\b'; |
166 | return '\b'; |
168 | return ch; |
167 | return ch; |
169 | } |
168 | } |
170 | } |
169 | } |
171 | } |
170 | } |
172 | 171 | ||
173 | 172 | ||
174 | /** Process keyboard interrupt. */ |
173 | /** Process keyboard interrupt. */ |
175 | static void gxemul_irq_handler(irq_t *irq, void *arg, ...) |
174 | static void gxemul_irq_handler(irq_t *irq, void *arg, ...) |
176 | { |
175 | { |
177 | if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) { |
176 | if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) { |
178 | ipc_irq_send_notif(irq); |
177 | ipc_irq_send_notif(irq); |
179 | } else { |
178 | } else { |
180 | char ch = 0; |
179 | char ch = 0; |
181 | 180 | ||
182 | ch = *((char *) gxemul_hw_map.kbd); |
181 | ch = *((char *) gxemul_hw_map.kbd); |
183 | if (ch == '\r') { |
182 | if (ch == '\r') { |
184 | ch = '\n'; |
183 | ch = '\n'; |
185 | } |
184 | } |
186 | if (ch == 0x7f) { |
185 | if (ch == 0x7f) { |
187 | ch = '\b'; |
186 | ch = '\b'; |
188 | } |
187 | } |
189 | chardev_push_character(&console, ch); |
188 | chardev_push_character(&console, ch); |
190 | } |
189 | } |
191 | } |
190 | } |
192 | 191 | ||
193 | 192 | ||
194 | static irq_ownership_t gxemul_claim(void) |
193 | static irq_ownership_t gxemul_claim(void) |
195 | { |
194 | { |
196 | return IRQ_ACCEPT; |
195 | return IRQ_ACCEPT; |
197 | } |
196 | } |
198 | 197 | ||
199 | 198 | ||
200 | void gxemul_grab_console(void) |
199 | void gxemul_grab_console(void) |
201 | { |
200 | { |
202 | ipl_t ipl = interrupts_disable(); |
201 | ipl_t ipl = interrupts_disable(); |
203 | spinlock_lock(&gxemul_irq.lock); |
202 | spinlock_lock(&gxemul_irq.lock); |
204 | gxemul_irq.notif_cfg.notify = false; |
203 | gxemul_irq.notif_cfg.notify = false; |
205 | spinlock_unlock(&gxemul_irq.lock); |
204 | spinlock_unlock(&gxemul_irq.lock); |
206 | interrupts_restore(ipl); |
205 | interrupts_restore(ipl); |
207 | } |
206 | } |
208 | 207 | ||
209 | 208 | ||
210 | void gxemul_release_console(void) |
209 | void gxemul_release_console(void) |
211 | { |
210 | { |
212 | ipl_t ipl = interrupts_disable(); |
211 | ipl_t ipl = interrupts_disable(); |
213 | spinlock_lock(&gxemul_irq.lock); |
212 | spinlock_lock(&gxemul_irq.lock); |
214 | if (gxemul_irq.notif_cfg.answerbox) { |
213 | if (gxemul_irq.notif_cfg.answerbox) { |
215 | gxemul_irq.notif_cfg.notify = true; |
214 | gxemul_irq.notif_cfg.notify = true; |
216 | } |
215 | } |
217 | spinlock_unlock(&gxemul_irq.lock); |
216 | spinlock_unlock(&gxemul_irq.lock); |
218 | interrupts_restore(ipl); |
217 | interrupts_restore(ipl); |
219 | } |
218 | } |
220 | 219 | ||
221 | 220 | ||
222 | /** Initializes console object representing gxemul console. |
221 | /** Initializes console object representing gxemul console. |
223 | * |
222 | * |
224 | * @param Console device number. |
223 | * @param Console device number. |
225 | */ |
224 | */ |
226 | void gxemul_console_init(devno_t devno) |
225 | void gxemul_console_init(devno_t devno) |
227 | { |
226 | { |
228 | chardev_initialize("gxemul_console", &console, &gxemul_ops); |
227 | chardev_initialize("gxemul_console", &console, &gxemul_ops); |
229 | stdin = &console; |
228 | stdin = &console; |
230 | stdout = &console; |
229 | stdout = &console; |
231 | 230 | ||
232 | irq_initialize(&gxemul_irq); |
231 | irq_initialize(&gxemul_irq); |
233 | gxemul_irq.devno = devno; |
232 | gxemul_irq.devno = devno; |
234 | gxemul_irq.inr = GXEMUL_KBD_IRQ; |
233 | gxemul_irq.inr = GXEMUL_KBD_IRQ; |
235 | gxemul_irq.claim = gxemul_claim; |
234 | gxemul_irq.claim = gxemul_claim; |
236 | gxemul_irq.handler = gxemul_irq_handler; |
235 | gxemul_irq.handler = gxemul_irq_handler; |
237 | irq_register(&gxemul_irq); |
236 | irq_register(&gxemul_irq); |
238 | 237 | ||
239 | gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
238 | gxemul_irqc_unmask(GXEMUL_KBD_IRQ); |
240 | 239 | ||
241 | sysinfo_set_item_val("kbd", NULL, true); |
240 | sysinfo_set_item_val("kbd", NULL, true); |
242 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
241 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
243 | sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ); |
242 | sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ); |
244 | sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd); |
243 | sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd); |
245 | } |
244 | } |
246 | 245 | ||
247 | 246 | ||
248 | 247 | ||
249 | /** Starts gxemul Real Time Clock device, which asserts regular interrupts. |
248 | /** Starts gxemul Real Time Clock device, which asserts regular interrupts. |
250 | * |
249 | * |
251 | * @param frequency Interrupts frequency (0 disables RTC). |
250 | * @param frequency Interrupts frequency (0 disables RTC). |
252 | */ |
251 | */ |
253 | static void gxemul_timer_start(uint32_t frequency) |
252 | static void gxemul_timer_start(uint32_t frequency) |
254 | { |
253 | { |
255 | *(uint32_t*) gxemul_hw_map.rtc_freq = frequency; |
254 | *(uint32_t*) gxemul_hw_map.rtc_freq = frequency; |
256 | } |
255 | } |
257 | 256 | ||
258 | 257 | ||
259 | static irq_ownership_t gxemul_timer_claim(void) |
258 | static irq_ownership_t gxemul_timer_claim(void) |
260 | { |
259 | { |
261 | return IRQ_ACCEPT; |
260 | return IRQ_ACCEPT; |
262 | } |
261 | } |
263 | 262 | ||
264 | 263 | ||
265 | /** Timer interrupt handler. |
264 | /** Timer interrupt handler. |
266 | * |
265 | * |
267 | * @param irq Interrupt information. |
266 | * @param irq Interrupt information. |
268 | * @param arg Not used. |
267 | * @param arg Not used. |
269 | */ |
268 | */ |
270 | static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...) |
269 | static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...) |
271 | { |
270 | { |
272 | /* TODO time drifts ?? |
271 | /* TODO time drifts ?? |
273 | unsigned long drift; |
272 | unsigned long drift; |
274 | 273 | ||
275 | drift = cp0_count_read() - nextcount; |
274 | drift = cp0_count_read() - nextcount; |
276 | while (drift > cp0_compare_value) { |
275 | while (drift > cp0_compare_value) { |
277 | drift -= cp0_compare_value; |
276 | drift -= cp0_compare_value; |
278 | CPU->missed_clock_ticks++; |
277 | CPU->missed_clock_ticks++; |
279 | } |
278 | } |
280 | nextcount = cp0_count_read() + cp0_compare_value - drift; |
279 | nextcount = cp0_count_read() + cp0_compare_value - drift; |
281 | cp0_compare_write(nextcount); |
280 | cp0_compare_write(nextcount); |
282 | */ |
281 | */ |
283 | 282 | ||
284 | /* |
283 | /* |
285 | * We are holding a lock which prevents preemption. |
284 | * We are holding a lock which prevents preemption. |
286 | * Release the lock, call clock() and reacquire the lock again. |
285 | * Release the lock, call clock() and reacquire the lock again. |
287 | */ |
286 | */ |
288 | spinlock_unlock(&irq->lock); |
287 | spinlock_unlock(&irq->lock); |
289 | clock(); |
288 | clock(); |
290 | spinlock_lock(&irq->lock); |
289 | spinlock_lock(&irq->lock); |
291 | 290 | ||
292 | /* acknowledge tick */ |
291 | /* acknowledge tick */ |
293 | *(uint32_t*) gxemul_hw_map.rtc_ack = 0; |
292 | *(uint32_t*) gxemul_hw_map.rtc_ack = 0; |
294 | 293 | ||
295 | /* TODO what's that? * |
294 | /* TODO what's that? * |
296 | if (virtual_timer_fnc != NULL) |
295 | if (virtual_timer_fnc != NULL) |
297 | virtual_timer_fnc(); |
296 | virtual_timer_fnc(); |
298 | */ |
297 | */ |
299 | } |
298 | } |
300 | 299 | ||
301 | 300 | ||
302 | /** Initializes and registers timer interrupt handler. */ |
301 | /** Initializes and registers timer interrupt handler. */ |
303 | static void gxemul_timer_irq_init() |
302 | static void gxemul_timer_irq_init() |
304 | { |
303 | { |
305 | irq_initialize(&gxemul_timer_irq); |
304 | irq_initialize(&gxemul_timer_irq); |
306 | gxemul_timer_irq.devno = device_assign_devno(); |
305 | gxemul_timer_irq.devno = device_assign_devno(); |
307 | gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ; |
306 | gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ; |
308 | gxemul_timer_irq.claim = gxemul_timer_claim; |
307 | gxemul_timer_irq.claim = gxemul_timer_claim; |
309 | gxemul_timer_irq.handler = gxemul_timer_irq_handler; |
308 | gxemul_timer_irq.handler = gxemul_timer_irq_handler; |
310 | 309 | ||
311 | irq_register(&gxemul_timer_irq); |
310 | irq_register(&gxemul_timer_irq); |
312 | } |
311 | } |
313 | 312 | ||
314 | 313 | ||
315 | /** Starts timer. |
314 | /** Starts timer. |
316 | * |
315 | * |
317 | * Initiates regular timer interrupts after initializing |
316 | * Initiates regular timer interrupts after initializing |
318 | * corresponding interrupt handler. |
317 | * corresponding interrupt handler. |
319 | */ |
318 | */ |
320 | void gxemul_timer_irq_start() |
319 | void gxemul_timer_irq_start() |
321 | { |
320 | { |
322 | gxemul_timer_irq_init(); |
321 | gxemul_timer_irq_init(); |
323 | gxemul_timer_start(GXEMUL_TIMER_FREQ); |
322 | gxemul_timer_start(GXEMUL_TIMER_FREQ); |
324 | } |
323 | } |
325 | 324 | ||
326 | 325 | ||
327 | /** Returns the size of emulated memory. |
326 | /** Returns the size of emulated memory. |
328 | * |
327 | * |
329 | * @return Size in bytes. |
328 | * @return Size in bytes. |
330 | */ |
329 | */ |
331 | size_t gxemul_get_memory_size(void) |
330 | size_t gxemul_get_memory_size(void) |
332 | { |
331 | { |
333 | return *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET)); |
332 | return *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET)); |
334 | } |
333 | } |
335 | 334 | ||
336 | 335 | ||
337 | void gxemul_debug_putc(char ch) |
336 | void gxemul_debug_putc(char ch) |
338 | { |
337 | { |
339 | char * addr = 0; |
338 | char * addr = 0; |
340 | if (!hw_map_init_called) { |
339 | if (!hw_map_init_called) { |
341 | addr = (char *) GXEMUL_KBD; |
340 | addr = (char *) GXEMUL_KBD; |
342 | } else { |
341 | } else { |
343 | addr = (char *) gxemul_hw_map.videoram; |
342 | addr = (char *) gxemul_hw_map.videoram; |
344 | } |
343 | } |
345 | 344 | ||
346 | *(addr) = ch; |
345 | *(addr) = ch; |
347 | } |
346 | } |
348 | 347 | ||
349 | 348 | ||
350 | /** Stops gxemul. */ |
349 | /** Stops gxemul. */ |
351 | void gxemul_cpu_halt(void) |
350 | void gxemul_cpu_halt(void) |
352 | { |
351 | { |
353 | char * addr = 0; |
352 | char * addr = 0; |
354 | if (!hw_map_init_called) { |
353 | if (!hw_map_init_called) { |
355 | addr = (char *) GXEMUL_KBD; |
354 | addr = (char *) GXEMUL_KBD; |
356 | } else { |
355 | } else { |
357 | addr = (char *) gxemul_hw_map.videoram; |
356 | addr = (char *) gxemul_hw_map.videoram; |
358 | } |
357 | } |
359 | 358 | ||
360 | *(addr + GXEMUL_HALT_OFFSET) = '\0'; |
359 | *(addr + GXEMUL_HALT_OFFSET) = '\0'; |
361 | } |
360 | } |
362 | 361 | ||
363 | 362 | ||
364 | /** Gxemul specific interrupt exception handler. |
363 | /** Gxemul specific interrupt exception handler. |
365 | * |
364 | * |
366 | * Determines sources of the interrupt from interrupt controller and |
365 | * Determines sources of the interrupt from interrupt controller and |
367 | * calls high-level handlers for them. |
366 | * calls high-level handlers for them. |
368 | * |
367 | * |
369 | * @param exc_no Interrupt exception number. |
368 | * @param exc_no Interrupt exception number. |
370 | * @param istate Saved processor state. |
369 | * @param istate Saved processor state. |
371 | */ |
370 | */ |
372 | void gxemul_irq_exception(int exc_no, istate_t *istate) |
371 | void gxemul_irq_exception(int exc_no, istate_t *istate) |
373 | { |
372 | { |
374 | uint32_t sources = gxemul_irqc_get_sources(); |
373 | uint32_t sources = gxemul_irqc_get_sources(); |
375 | int i = 0; |
374 | int i = 0; |
376 | for (; i < GXEMUL_IRQC_MAX_IRQ; i++) { |
375 | for (; i < GXEMUL_IRQC_MAX_IRQ; i++) { |
377 | if (sources & (1 << i)) { |
376 | if (sources & (1 << i)) { |
378 | irq_t *irq = irq_dispatch_and_lock(i); |
377 | irq_t *irq = irq_dispatch_and_lock(i); |
379 | if (irq) { |
378 | if (irq) { |
380 | /* The IRQ handler was found. */ |
379 | /* The IRQ handler was found. */ |
381 | irq->handler(irq, irq->arg); |
380 | irq->handler(irq, irq->arg); |
382 | spinlock_unlock(&irq->lock); |
381 | spinlock_unlock(&irq->lock); |
383 | } else { |
382 | } else { |
384 | /* Spurious interrupt.*/ |
383 | /* Spurious interrupt.*/ |
385 | dprintf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, i); |
384 | dprintf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, i); |
386 | } |
385 | } |
387 | } |
386 | } |
388 | } |
387 | } |
389 | } |
388 | } |
390 | 389 | ||
391 | 390 | ||
392 | uintptr_t gxemul_get_fb_address(void) |
391 | uintptr_t gxemul_get_fb_address(void) |
393 | { |
392 | { |
394 | return gxemul_hw_map.fb; |
393 | return (uintptr_t) GXEMUL_FB; |
395 | } |
394 | } |
396 | 395 | ||
397 | /** @} |
396 | /** @} |
398 | */ |
397 | */ |
399 | 398 |