Subversion Repositories HelenOS

Rev

Rev 2261 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2261 Rev 2263
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2005-2007 Ondrej Palkovsky, 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:
Line 38... Line 38...
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
 
44
 
44
/** Address of devices. */
45
/** Address of devices. */
45
#define GXEMUL_VIDEORAM     0x10000000
46
#define GXEMUL_VIDEORAM            0x10000000
46
#define GXEMUL_KBD_ADDRESS  0x10000000
47
#define GXEMUL_KBD                 0x10000000
47
#define GXEMUL_RTC      0x15000000
48
#define GXEMUL_RTC                 0x15000000
48
#define GXEMUL_RTC_FREQ     0x15000100
49
#define GXEMUL_RTC_FREQ_OFFSET     0x100
49
#define GXEMUL_RTC_ACK      0x15000110
50
#define GXEMUL_RTC_ACK_OFFSET      0x110
50
#define GXEMUL_IRQC     0x16000000
51
#define GXEMUL_IRQC                0x16000000
51
#define GXEMUL_IRQC_MASK    0x16000004
52
#define GXEMUL_IRQC_MASK_OFFSET    0x4
52
#define GXEMUL_IRQC_UNMASK  0x16000008
53
#define GXEMUL_IRQC_UNMASK_OFFSET  0x8
-
 
54
#define GXEMUL_MP                  0x11000000
-
 
55
#define GXEMUL_MP_MEMSIZE_OFFSET   0x0090
-
 
56
 
53
 
57
 
54
/** IRQs */
58
/** IRQs */
55
#define GXEMUL_KBD_IRQ      2
59
#define GXEMUL_KBD_IRQ      2
56
#define GXEMUL_TIMER_IRQ    4
60
#define GXEMUL_TIMER_IRQ    4
57
 
61
 
-
 
62
static gxemul_hw_map_t gxemul_hw_map;
58
static chardev_t console;
63
static chardev_t console;
59
static irq_t gxemul_irq;
64
static irq_t gxemul_irq;
60
static irq_t gxemul_timer_irq;
65
static irq_t gxemul_timer_irq;
61
 
66
 
62
static void gxemul_write(chardev_t *dev, const char ch);
67
static void gxemul_write(chardev_t *dev, const char ch);
Line 69... Line 74...
69
    .suspend = gxemul_disable,
74
    .suspend = gxemul_disable,
70
    .write = gxemul_write,
75
    .write = gxemul_write,
71
    .read = gxemul_do_read,
76
    .read = gxemul_do_read,
72
};
77
};
73
 
78
 
-
 
79
 
-
 
80
/** Initializes #gxemul_hw_map. */
-
 
81
void gxemul_hw_map_init(void)
-
 
82
{
-
 
83
    gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE);
-
 
84
    gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE);
-
 
85
    gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE);
-
 
86
    gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE);
-
 
87
 
-
 
88
    gxemul_hw_map.rtc_freq = gxemul_hw_map.rtc + GXEMUL_RTC_FREQ_OFFSET;
-
 
89
    gxemul_hw_map.rtc_ack = gxemul_hw_map.rtc + GXEMUL_RTC_ACK_OFFSET;
-
 
90
    gxemul_hw_map.irqc_mask = gxemul_hw_map.irqc + GXEMUL_IRQC_MASK_OFFSET;
-
 
91
    gxemul_hw_map.irqc_unmask = gxemul_hw_map.irqc + GXEMUL_IRQC_UNMASK_OFFSET;
-
 
92
}
-
 
93
 
74
/** Putchar that works with gxemul */
94
/** Putchar that works with gxemul */
75
void gxemul_write(chardev_t *dev, const char ch)
95
void gxemul_write(chardev_t *dev, const char ch)
76
{
96
{
77
    *((char *) GXEMUL_VIDEORAM) = ch;
97
    *((char *) gxemul_hw_map.videoram) = ch;
78
}
98
}
79
 
99
 
80
/* Called from getc(). */
100
/* Called from getc(). */
81
void gxemul_enable(chardev_t *dev)
101
void gxemul_enable(chardev_t *dev)
82
{
102
{
Line 95... Line 115...
95
static char gxemul_do_read(chardev_t *dev)
115
static char gxemul_do_read(chardev_t *dev)
96
{
116
{
97
    char ch;
117
    char ch;
98
 
118
 
99
    while (1) {
119
    while (1) {
100
        ch = *((volatile char *) GXEMUL_KBD_ADDRESS);
120
        ch = *((volatile char *) gxemul_hw_map.kbd);
101
        if (ch) {
121
        if (ch) {
102
            if (ch == '\r')
122
            if (ch == '\r')
103
                return '\n';
123
                return '\n';
104
            if (ch == 0x7f)
124
            if (ch == 0x7f)
105
                return '\b';
125
                return '\b';
Line 114... Line 134...
114
    if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox))
134
    if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox))
115
        ipc_irq_send_notif(irq);
135
        ipc_irq_send_notif(irq);
116
    else {
136
    else {
117
        char ch = 0;
137
        char ch = 0;
118
       
138
       
119
            ch = *((char *) GXEMUL_KBD_ADDRESS);
139
            ch = *((char *) gxemul_hw_map.kbd);
120
            if (ch =='\r')
140
            if (ch =='\r')
121
                ch = '\n';
141
                ch = '\n';
122
            if (ch == 0x7f)
142
            if (ch == 0x7f)
123
                ch = '\b';
143
                ch = '\b';
124
            //chardev_push_character(&console, ch);
144
            //chardev_push_character(&console, ch);
Line 132... Line 152...
132
}
152
}
133
 
153
 
134
void gxemul_kbd_grab(void)
154
void gxemul_kbd_grab(void)
135
{
155
{
136
    ipl_t ipl = interrupts_disable();
156
    ipl_t ipl = interrupts_disable();
137
    spinlock_lock(&msim_irq.lock);
157
    spinlock_lock(&gxemul_irq.lock);
138
    gxemul_irq.notif_cfg.notify = false;
158
    gxemul_irq.notif_cfg.notify = false;
139
    spinlock_unlock(&gxemul_irq.lock);
159
    spinlock_unlock(&gxemul_irq.lock);
140
    interrupts_restore(ipl);
160
    interrupts_restore(ipl);
141
}
161
}
142
 
162
 
Line 149... Line 169...
149
    spinlock_unlock(&gxemul_irq.lock);
169
    spinlock_unlock(&gxemul_irq.lock);
150
    interrupts_restore(ipl);
170
    interrupts_restore(ipl);
151
}
171
}
152
 
172
 
153
 
173
 
154
/** Return console object representing msim console */
174
/** Return console object representing gxemul console */
155
void gxemul_console(devno_t devno)
175
void gxemul_console(devno_t devno)
156
{
176
{
157
    chardev_initialize("msim_console", &console, &gxemul_ops);
177
    chardev_initialize("gxemul_console", &console, &gxemul_ops);
158
    stdin = &console;
178
    stdin = &console;
159
    stdout = &console;
179
    stdout = &console;
160
   
180
   
161
    irq_initialize(&gxemul_irq);
181
    irq_initialize(&gxemul_irq);
162
    gxemul_irq.devno = devno;
182
    gxemul_irq.devno = devno;
Line 169... Line 189...
169
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
189
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
170
   
190
   
171
    sysinfo_set_item_val("kbd", NULL, true);
191
    sysinfo_set_item_val("kbd", NULL, true);
172
    sysinfo_set_item_val("kbd.devno", NULL, devno);
192
    sysinfo_set_item_val("kbd.devno", NULL, devno);
173
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
193
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
174
    sysinfo_set_item_val("kbd.address.virtual", NULL, GXEMUL_KBD_ADDRESS);
194
    sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd);
175
}
195
}
176
 
196
 
177
/** Return the mask of active interrupts. */
197
/** Return the mask of active interrupts. */
178
inline uint32_t gxemul_irqc_get_sources(void)
198
inline uint32_t gxemul_irqc_get_sources(void)
179
{
199
{
180
    return *(uint32_t*) GXEMUL_IRQC;
200
    return *(uint32_t*) gxemul_hw_map.irqc;
181
}
201
}
182
 
202
 
183
/** Masks interrupt.
203
/** Masks interrupt.
184
 *
204
 *
185
 * @param irq interrupt number
205
 * @param irq interrupt number
186
 */
206
 */
187
inline void gxemul_irqc_mask(uint32_t irq)
207
inline void gxemul_irqc_mask(uint32_t irq)
188
{
208
{
189
    *(uint32_t*) GXEMUL_IRQC_MASK = irq;
209
    *(uint32_t*) gxemul_hw_map.irqc_mask = irq;
190
}
210
}
191
 
211
 
192
/** Unmasks interrupt.
212
/** Unmasks interrupt.
193
 *
213
 *
194
 * @param irq interrupt number
214
 * @param irq interrupt number
195
 */
215
 */
196
inline void gxemul_irqc_unmask(uint32_t irq)
216
inline void gxemul_irqc_unmask(uint32_t irq)
197
{
217
{
198
    *(uint32_t*) GXEMUL_IRQC_UNMASK = irq;
218
    *(uint32_t*) gxemul_hw_map.irqc_unmask = irq;
199
}
219
}
200
 
220
 
201
 
221
 
202
/** Starts gxemul Real Time Clock device, which asserts regular interrupts.
222
/** Starts gxemul Real Time Clock device, which asserts regular interrupts.
203
 *
223
 *
204
 * @param frequency interrupts frequency (0 disables RTC)
224
 * @param frequency interrupts frequency (0 disables RTC)
205
 */
225
 */
206
void gxemul_timer_start(uint32_t frequency)
226
void gxemul_timer_start(uint32_t frequency)
207
{
227
{
208
    *(uint32_t*) GXEMUL_RTC_FREQ = frequency;
228
    *(uint32_t*) gxemul_hw_map.rtc_freq = frequency;
209
}
229
}
210
 
230
 
211
static irq_ownership_t gxemul_timer_claim(void)
231
static irq_ownership_t gxemul_timer_claim(void)
212
{
232
{
213
    return IRQ_ACCEPT;
233
    return IRQ_ACCEPT;
Line 235... Line 255...
235
    //clock();
255
    //clock();
236
    puts(" ");
256
    puts(" ");
237
    spinlock_lock(&irq->lock);
257
    spinlock_lock(&irq->lock);
238
 
258
 
239
    /* acknowledge tick */
259
    /* acknowledge tick */
240
    *(uint32_t*) GXEMUL_RTC_ACK = 0;
260
    *(uint32_t*) gxemul_hw_map.rtc_ack = 0;
241
   
261
   
242
    /* TODO what's that? *
262
    /* TODO what's that? *
243
    if (virtual_timer_fnc != NULL)
263
    if (virtual_timer_fnc != NULL)
244
        virtual_timer_fnc();
264
        virtual_timer_fnc();
245
    */
265
    */
Line 257... Line 277...
257
    gxemul_timer_irq.handler = gxemul_timer_irq_handler;
277
    gxemul_timer_irq.handler = gxemul_timer_irq_handler;
258
 
278
 
259
    irq_register(&gxemul_timer_irq);
279
    irq_register(&gxemul_timer_irq);
260
}
280
}
261
 
281
 
-
 
282
size_t gxemul_get_memory_size(void)
-
 
283
{
-
 
284
    return  *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET));
-
 
285
}
262
 
286
 
263
/** @}
287
/** @}
264
 */
288
 */