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