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