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