Subversion Repositories HelenOS

Rev

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

Rev 2215 Rev 2245
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2005-2007 Ondrej Palkovsky, Michal Kebrt
2
 * Copyright (c) 2005-2007 Ondrej Palkovsky, 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 37... Line 37...
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
 
43
 
43
/** Address of devices. */
44
/** Address of devices. */
44
#define GXEMUL_VIDEORAM     0x10000000
45
#define GXEMUL_VIDEORAM     0x10000000
45
#define GXEMUL_KBD_ADDRESS  0x10000000
46
#define GXEMUL_KBD_ADDRESS  0x10000000
-
 
47
#define GXEMUL_RTC      0x15000000
-
 
48
#define GXEMUL_RTC_FREQ     0x15000100
-
 
49
#define GXEMUL_RTC_ACK      0x15000110
-
 
50
#define GXEMUL_IRQC     0x16000000
-
 
51
#define GXEMUL_IRQC_MASK    0x16000004
-
 
52
#define GXEMUL_IRQC_UNMASK  0x16000008
-
 
53
 
-
 
54
/** IRQs */
46
#define GXEMUL_KBD_IRQ      0
55
#define GXEMUL_KBD_IRQ      2
-
 
56
#define GXEMUL_TIMER_IRQ    4
47
 
57
 
48
static chardev_t console;
58
static chardev_t console;
49
static irq_t gxemul_irq;
59
static irq_t gxemul_irq;
-
 
60
static irq_t gxemul_timer_irq;
50
 
61
 
51
static void gxemul_write(chardev_t *dev, const char ch);
62
static void gxemul_write(chardev_t *dev, const char ch);
52
static void gxemul_enable(chardev_t *dev);
63
static void gxemul_enable(chardev_t *dev);
53
static void gxemul_disable(chardev_t *dev);
64
static void gxemul_disable(chardev_t *dev);
54
static char gxemul_do_read(chardev_t *dev);
65
static char gxemul_do_read(chardev_t *dev);
Line 68... Line 79...
68
 
79
 
69
/* Called from getc(). */
80
/* Called from getc(). */
70
void gxemul_enable(chardev_t *dev)
81
void gxemul_enable(chardev_t *dev)
71
{
82
{
72
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
83
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
-
 
84
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
73
}
85
}
74
 
86
 
75
/* Called from getc(). */
87
/* Called from getc(). */
76
void gxemul_disable(chardev_t *dev)
88
void gxemul_disable(chardev_t *dev)
77
{
89
{
78
//  cp0_mask_int(GXEMUL_KBD_IRQ);
90
//  cp0_mask_int(GXEMUL_KBD_IRQ);
-
 
91
    gxemul_irqc_mask(GXEMUL_KBD_IRQ);
79
}
92
}
80
 
93
 
81
/** Read character using polling, assume interrupts disabled */
94
/** Read character using polling, assume interrupts disabled */
82
static char gxemul_do_read(chardev_t *dev)
95
static char gxemul_do_read(chardev_t *dev)
83
{
96
{
Line 106... Line 119...
106
            ch = *((char *) GXEMUL_KBD_ADDRESS);
119
            ch = *((char *) GXEMUL_KBD_ADDRESS);
107
            if (ch =='\r')
120
            if (ch =='\r')
108
                ch = '\n';
121
                ch = '\n';
109
            if (ch == 0x7f)
122
            if (ch == 0x7f)
110
                ch = '\b';
123
                ch = '\b';
111
            chardev_push_character(&console, ch);
124
            //chardev_push_character(&console, ch);
-
 
125
            printf("%c", ch);
112
    }
126
    }
113
}
127
}
114
 
128
 
115
static irq_ownership_t gxemul_claim(void)
129
static irq_ownership_t gxemul_claim(void)
116
{
130
{
Line 135... Line 149...
135
    spinlock_unlock(&gxemul_irq.lock);
149
    spinlock_unlock(&gxemul_irq.lock);
136
    interrupts_restore(ipl);
150
    interrupts_restore(ipl);
137
}
151
}
138
 
152
 
139
 
153
 
140
/* Return console object representing msim console */
154
/** Return console object representing msim console */
141
void gxemul_console(devno_t devno)
155
void gxemul_console(devno_t devno)
142
{
156
{
143
    chardev_initialize("msim_console", &console, &gxemul_ops);
157
    chardev_initialize("msim_console", &console, &gxemul_ops);
144
    stdin = &console;
158
    stdin = &console;
145
    stdout = &console;
159
    stdout = &console;
Line 150... Line 164...
150
    gxemul_irq.claim = gxemul_claim;
164
    gxemul_irq.claim = gxemul_claim;
151
    gxemul_irq.handler = gxemul_irq_handler;
165
    gxemul_irq.handler = gxemul_irq_handler;
152
    irq_register(&gxemul_irq);
166
    irq_register(&gxemul_irq);
153
   
167
   
154
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
168
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
-
 
169
    gxemul_irqc_unmask(GXEMUL_KBD_IRQ);
155
   
170
   
156
    sysinfo_set_item_val("kbd", NULL, true);
171
    sysinfo_set_item_val("kbd", NULL, true);
157
    sysinfo_set_item_val("kbd.devno", NULL, devno);
172
    sysinfo_set_item_val("kbd.devno", NULL, devno);
158
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
173
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
159
    sysinfo_set_item_val("kbd.address.virtual", NULL, GXEMUL_KBD_ADDRESS);
174
    sysinfo_set_item_val("kbd.address.virtual", NULL, GXEMUL_KBD_ADDRESS);
160
}
175
}
161
 
176
 
-
 
177
/** Return the mask of active interrupts. */
-
 
178
inline uint32_t gxemul_irqc_get_sources(void)
-
 
179
{
-
 
180
    return *(uint32_t*) GXEMUL_IRQC;
-
 
181
}
-
 
182
 
-
 
183
/** Masks interrupt.
-
 
184
 *
-
 
185
 * @param irq interrupt number
-
 
186
 */
-
 
187
inline void gxemul_irqc_mask(uint32_t irq)
-
 
188
{
-
 
189
    *(uint32_t*) GXEMUL_IRQC_MASK = irq;
-
 
190
}
-
 
191
 
-
 
192
/** Unmasks interrupt.
-
 
193
 *
-
 
194
 * @param irq interrupt number
-
 
195
 */
-
 
196
inline void gxemul_irqc_unmask(uint32_t irq)
-
 
197
{
-
 
198
    *(uint32_t*) GXEMUL_IRQC_UNMASK = irq;
-
 
199
}
-
 
200
 
-
 
201
 
-
 
202
/** Starts gxemul Real Time Clock device, which asserts regular interrupts.
-
 
203
 *
-
 
204
 * @param frequency interrupts frequency (0 disables RTC)
-
 
205
 */
-
 
206
void gxemul_timer_start(uint32_t frequency)
-
 
207
{
-
 
208
    *(uint32_t*) GXEMUL_RTC_FREQ = frequency;
-
 
209
}
-
 
210
 
-
 
211
static irq_ownership_t gxemul_timer_claim(void)
-
 
212
{
-
 
213
    return IRQ_ACCEPT;
-
 
214
}
-
 
215
 
-
 
216
static void gxemul_timer_irq_handler(irq_t *irq, void *arg, ...)
-
 
217
{
-
 
218
    /* TODO time drifts ??
-
 
219
    unsigned long drift;
-
 
220
 
-
 
221
    drift = cp0_count_read() - nextcount;
-
 
222
    while (drift > cp0_compare_value) {
-
 
223
        drift -= cp0_compare_value;
-
 
224
        CPU->missed_clock_ticks++;
-
 
225
    }
-
 
226
    nextcount = cp0_count_read() + cp0_compare_value - drift;
-
 
227
    cp0_compare_write(nextcount);
-
 
228
    */
-
 
229
 
-
 
230
    /*
-
 
231
    * We are holding a lock which prevents preemption.
-
 
232
    * Release the lock, call clock() and reacquire the lock again.
-
 
233
    */
-
 
234
    spinlock_unlock(&irq->lock);
-
 
235
    //clock();
-
 
236
    puts(" ");
-
 
237
    spinlock_lock(&irq->lock);
-
 
238
   
-
 
239
    /* TODO what's that? *
-
 
240
    if (virtual_timer_fnc != NULL)
-
 
241
        virtual_timer_fnc();
-
 
242
    */
-
 
243
}
-
 
244
 
-
 
245
/**
-
 
246
 * Initializes and registers timer interrupt handler.
-
 
247
 */
-
 
248
void gxemul_timer_irq_init()
-
 
249
{
-
 
250
    irq_initialize(&gxemul_timer_irq);
-
 
251
    gxemul_timer_irq.devno = device_assign_devno();
-
 
252
    gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ;
-
 
253
    gxemul_timer_irq.claim = gxemul_timer_claim;
-
 
254
    gxemul_timer_irq.handler = gxemul_timer_irq_handler;
-
 
255
    irq_register(&gxemul_timer_irq);
-
 
256
}
-
 
257
 
-
 
258
 
162
/** @}
259
/** @}
163
 */
260
 */