Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 575 → Rev 574

/kernel/trunk/arch/mips32/include/interrupt.h
31,15 → 31,13
 
#include <arch/exception.h>
 
#define IVT_ITEMS 32
 
#define IRQ2 2
#define IRQ3 3
#define IRQ7 7
 
#define KEYBOARD_IRQ IRQ2
#define TIMER_IRQ IRQ7
 
extern void interrupt(struct exception_regdump *pstate);
extern void interrupt_init(void);
 
#endif
/kernel/trunk/arch/mips32/include/drivers/serial.h
File deleted
/kernel/trunk/arch/mips32/include/drivers/msim.h
File deleted
/kernel/trunk/arch/mips32/include/drivers/keyboard.h
0,0 → 1,42
/*
* Copyright (C) 2005 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __mips32_KEYBOARD_H__
#define __mips32_KEYBOARD_H__
 
#include <arch/types.h>
#include <arch/interrupt.h>
 
/** Address of 'keyboard' device. */
#define KEYBOARD_ADDRESS 0xB0000000
 
extern void keyboard_init(void);
extern void keyboard(void);
extern void keyboard_poll(void);
 
#endif
/kernel/trunk/arch/mips32/include/drivers/arc.h
30,7 → 30,6
#define __mips32_ARC_H__
 
#include <arch/types.h>
#include <console/chardev.h>
 
#define ARC_BASE_ADDR 0x1000;
#define ARC_MAGIC 0x53435241
213,8 → 212,9
extern int arc_init(void);
extern void arc_print_memory_map(void);
extern int arc_enabled(void);
extern void arc_putchar(char ch);
extern void arc_print_devices(void);
extern int arc_getchar(void);
void arc_frame_init(void);
chardev_t * arc_console(void);
 
#endif
/kernel/trunk/arch/mips32/include/console.h
30,6 → 30,12
#define __mips32_CONSOLE_H__
 
 
#define VIDEORAM 0xB0000000
 
#define SERIAL_PORT_BASE ((char *) 0xB80003f8 )
#define SERIAL_LSR ((char *) (SERIAL_PORT_BASE + 5))
#define TRANSMIT_EMPTY_BIT 5
 
void console_init(void);
 
#endif
/kernel/trunk/arch/mips32/src/interrupt.c
26,7 → 26,6
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <interrupt.h>
#include <arch/interrupt.h>
#include <arch/types.h>
#include <arch.h>
36,6 → 35,7
#include <print.h>
#include <symtab.h>
#include <arch/drivers/arc.h>
#include <arch/drivers/keyboard.h>
 
static void print_regdump(struct exception_regdump *pstate)
{
93,31 → 93,6
return cp0_status_read();
}
 
static void unhandled_exception(int n, void *stack)
{
struct exception_regdump *pstate = (struct exception_regdump *)stack;
 
print_regdump(pstate);
panic("unhandled interrupt %d\n", n);
}
 
static void timer_exception(int n, void *stack)
{
cp0_compare_write(cp0_count_read() + cp0_compare_value);
clock();
}
 
static void swint0(int n, void *stack)
{
cp0_cause_write(cp0_cause_read() & ~(1 << 8)); /* clear SW0 interrupt */
}
 
static void swint1(int n, void *stack)
{
cp0_cause_write(cp0_cause_read() & ~(1 << 9)); /* clear SW1 interrupt */
}
 
/** Basic exception handler */
void interrupt(struct exception_regdump *pstate)
{
__u32 cause;
126,20 → 101,34
/* decode interrupt number and process the interrupt */
cause = (cp0_cause_read() >> 8) &0xff;
for (i = 0; i < 8; i++)
if (cause & (1 << i))
exc_dispatch(i, (void *)pstate);
}
for (i = 0; i < 8; i++) {
if (cause & (1 << i)) {
switch (i) {
case 0: /* SW0 - Software interrupt 0 */
cp0_cause_write(cp0_cause_read() & ~(1 << 8)); /* clear SW0 interrupt */
break;
case 1: /* SW1 - Software interrupt 1 */
cp0_cause_write(cp0_cause_read() & ~(1 << 9)); /* clear SW1 interrupt */
break;
case KEYBOARD_IRQ:
keyboard();
break;
case 3:
case 4: /* IRQ2 */
case 5: /* IRQ3 */
case 6: /* IRQ4 */
default:
print_regdump(pstate);
panic("unhandled interrupt %d\n", i);
break;
case TIMER_IRQ:
/* clear timer interrupt & set new */
cp0_compare_write(cp0_count_read() + cp0_compare_value);
clock();
keyboard_poll();
break;
}
}
}
 
/* Initialize basic tables for exception dispatching */
void interrupt_init(void)
{
int i;
 
for (i=0;i < IVT_ITEMS; i++)
exc_register(i, "undef", unhandled_exception);
 
exc_register(TIMER_IRQ, "timer", timer_exception);
exc_register(0, "swint0", swint0);
exc_register(1, "swint1", swint1);
}
/kernel/trunk/arch/mips32/src/drivers/msim.c
File deleted
/kernel/trunk/arch/mips32/src/drivers/serial.c
File deleted
/kernel/trunk/arch/mips32/src/drivers/keyboard.c
0,0 → 1,117
/*
* Copyright (C) 2003 Josef Cejka
* Copyright (C) 2005 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <arch/drivers/keyboard.h>
#include <console/chardev.h>
#include <console/console.h>
#include <arch/cp0.h>
#include <putchar.h>
#include <synch/spinlock.h>
#include <synch/waitq.h>
#include <typedefs.h>
#include <arch/drivers/arc.h>
 
static void keyboard_enable(void);
static void keyboard_disable(void);
static void arc_kb_disable(void);
static void arc_kb_enable(void);
 
static chardev_t kbrd;
 
static chardev_operations_t arc_ops = {
.resume = arc_kb_enable,
.suspend = arc_kb_disable
};
 
static chardev_operations_t msim_ops = {
.resume = keyboard_enable,
.suspend = keyboard_disable
};
 
static int arc_kb_enabled;
 
/** Initialize keyboard subsystem. */
void keyboard_init(void)
{
if (arc_enabled()) {
chardev_initialize(&kbrd, &arc_ops);
arc_kb_enabled = 1;
} else {
cp0_unmask_int(KEYBOARD_IRQ);
chardev_initialize(&kbrd, &msim_ops);
}
stdin = &kbrd;
}
 
/** Process keyboard interrupt. */
void keyboard(void)
{
char ch;
 
ch = *((char *) KEYBOARD_ADDRESS);
if (ch =='\r')
ch = '\n';
chardev_push_character(&kbrd, ch);
}
 
/* Called from getc(). */
void keyboard_enable(void)
{
cp0_unmask_int(KEYBOARD_IRQ);
}
 
/* Called from getc(). */
void keyboard_disable(void)
{
cp0_mask_int(KEYBOARD_IRQ);
}
 
/*****************************/
/* Arc keyboard */
 
void keyboard_poll(void)
{
int ch;
 
if (!arc_enabled() || !arc_kb_enabled)
return;
while ((ch = arc_getchar()) != -1)
chardev_push_character(&kbrd, ch);
}
 
static void arc_kb_enable(void)
{
arc_kb_enabled = 1;
}
 
/* Called from getc(). */
static void arc_kb_disable(void)
{
arc_kb_enabled = 0;
}
/kernel/trunk/arch/mips32/src/drivers/arc.c
33,7 → 33,6
#include <arch/byteorder.h>
#include <arch/mm/frame.h>
#include <mm/frame.h>
#include <interrupt.h>
 
/* This is a good joke, SGI HAS different types than NT bioses... */
/* Here is the SGI type */
98,9 → 97,26
static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000);
static arc_func_vector_t *arc_entry;
 
static void _arc_putchar(char ch);
 
static void arc_putchar(char ch);
/** Initialize ARC structure
*
* @return 0 - ARC OK, -1 - ARC does not exist
*/
int arc_init(void)
{
if (sbp->signature != ARC_MAGIC) {
sbp = NULL;
return -1;
}
arc_entry = sbp->firmwarevector;
 
arc_putchar('A');
arc_putchar('R');
arc_putchar('C');
arc_putchar('\n');
}
 
/** Return true if ARC is available */
int arc_enabled(void)
{
113,8 → 129,8
 
printf("%s: ",ctypes[c->type]);
for (i=0;i < c->identifier_len;i++)
arc_putchar(c->identifier[i]);
arc_putchar('\n');
putchar(c->identifier[i]);
putchar('\n');
}
 
void arc_print_devices(void)
158,7 → 174,7
}
 
/** Print charactor to console */
static void arc_putchar(char ch)
void arc_putchar(char ch)
{
__u32 cnt;
ipl_t ipl;
170,89 → 186,25
}
 
/** Initialize ARC structure
*
* @return 0 - ARC OK, -1 - ARC does not exist
*/
int arc_init(void)
{
if (sbp->signature != ARC_MAGIC) {
sbp = NULL;
return -1;
}
arc_entry = sbp->firmwarevector;
 
arc_putchar('A');
arc_putchar('R');
arc_putchar('C');
arc_putchar('\n');
}
 
static int kbd_polling_enabled;
static chardev_t console;
 
/** Try to get character, return character or -1 if not available */
static void arc_keyboard_poll(void)
int arc_getchar(void)
{
char ch;
__u32 count;
long result;
if (! kbd_polling_enabled)
return;
 
if (arc_entry->getreadstatus(0))
return;
return -1;
result = arc_entry->read(0, &ch, 1, &count);
if (result || count!=1) {
return;
cpu_halt();
return -1;
}
if (ch == '\r')
ch = '\n';
 
chardev_push_character(&console, ch);
return '\n';
return ch;
}
 
static void arc_write(chardev_t *dev, const char ch)
{
arc_putchar(ch);
}
 
static void arc_enable(chardev_t *dev)
{
kbd_polling_enabled = 1;
}
 
static void arc_disable(chardev_t *dev)
{
kbd_polling_enabled = 0;
}
 
static chardev_operations_t arc_ops = {
.resume = arc_enable,
.suspend = arc_disable,
.write = arc_write
};
 
iroutine old_timer;
/** Do polling on timer interrupt */
static void timer_replace(int n, void *stack)
{
arc_keyboard_poll();
old_timer(n, stack);
arc_keyboard_poll();
}
 
 
chardev_t * arc_console(void)
{
kbd_polling_enabled = 1;
chardev_initialize("arc_console", &console, &arc_ops);
old_timer = exc_register(TIMER_IRQ, "arc_kb_poll", timer_replace);
return &console;
}
 
/* Initialize frame zones from ARC firmware.
* In the future we may use even the FirmwareTemporary regions,
* currently we use the FreeMemory (what about the LoadedProgram?)
/kernel/trunk/arch/mips32/src/mips32.c
26,25 → 26,21
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
 
#include <arch.h>
#include <arch/cp0.h>
#include <arch/exception.h>
#include <arch/asm/regname.h>
#include <arch/asm.h>
#include <mm/vm.h>
 
#include <userspace.h>
#include <arch/console.h>
#include <memstr.h>
#include <arch/interrupt.h>
#include <arch/drivers/arc.h>
#include <arch/drivers/keyboard.h>
#include <proc/thread.h>
#include <print.h>
 
#include <arch/interrupt.h>
#include <arch/drivers/arc.h>
#include <console/chardev.h>
 
#include <arch/asm/regname.h>
 
/* Size of the code jumping to the exception handler code
* - J+NOP
*/
58,9 → 54,6
{
/* It is not assumed by default */
interrupts_disable();
/* Initialize dispatch table */
interrupt_init();
 
arc_init();
 
90,6 → 83,7
cp0_compare_write(cp0_compare_value + cp0_count_read());
 
console_init();
keyboard_init();
arc_print_memory_map();
arc_print_devices();
}
/kernel/trunk/arch/mips32/src/console.c
26,23 → 26,48
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <console/console.h>
#include <putchar.h>
#include <arch/types.h>
#include <arch/cp0.h>
#include <arch/console.h>
#include <arch.h>
#include <arch/drivers/arc.h>
#include <arch/drivers/serial.h>
#include <arch/drivers/msim.h>
#include <arch/arch.h>
 
void console_init(void)
/** Putchar that works with MSIM & gxemul */
static void cons_putchar(const char ch)
{
chardev_t *console;
*((char *) VIDEORAM) = ch;
}
 
if (arc_enabled()) {
console = arc_console();
} else if (serial_init()) {
console = serial_console();
} else
console = msim_console();
/** Putchar that works with simics */
static void serial_putchar(const char ch)
{
int i;
 
stdin = console;
stdout = console;
if (ch=='\n')
putchar('\r');
 
/* Wait until transmit buffer empty */
while (! ((*SERIAL_LSR) & (1<<TRANSMIT_EMPTY_BIT)))
;
*(SERIAL_PORT_BASE) = ch;
}
 
static void (*putchar_func)(const char ch) = cons_putchar;
 
void console_init(void)
{
if (arc_enabled())
putchar_func = arc_putchar;
/* The LSR on the start usually contains this value */
else if (*SERIAL_LSR == 0x60)
putchar_func = serial_putchar;
else
putchar_func = cons_putchar;
}
 
void putchar(const char ch)
{
putchar_func(ch);
}
/kernel/trunk/arch/mips32/Makefile.inc
108,5 → 108,4
arch/$(ARCH)/src/fpu_context.c \
arch/$(ARCH)/src/fmath.c \
arch/$(ARCH)/src/drivers/arc.c \
arch/$(ARCH)/src/drivers/msim.c \
arch/$(ARCH)/src/drivers/serial.c
arch/$(ARCH)/src/drivers/keyboard.c
/kernel/trunk/arch/ia32/include/ega.h
35,5 → 35,6
#define SCREEN (ROW*ROWS)
 
extern void ega_init(void);
extern void ega_putchar(const char ch);
 
#endif
/kernel/trunk/arch/ia32/src/drivers/i8042.c
66,8 → 66,8
static volatile int keyflags; /**< Tracking of multiple keypresses. */
static volatile int lockflags; /**< Tracking of multiple keys lockings. */
 
static void i8042_suspend(chardev_t *);
static void i8042_resume(chardev_t *);
static void i8042_suspend(void);
static void i8042_resume(void);
 
static chardev_t kbrd;
static chardev_operations_t ops = {
241,7 → 241,7
trap_register(VECTOR_KBD, i8042_interrupt);
trap_virtual_enable_irqs(1<<IRQ_KBD);
spinlock_initialize(&keylock, "i8042_lock");
chardev_initialize("i8042_kbd", &kbrd, &ops);
chardev_initialize(&kbrd, &ops);
stdin = &kbrd;
}
 
322,11 → 322,11
}
 
/* Called from getc(). */
void i8042_resume(chardev_t *d)
void i8042_resume(void)
{
}
 
/* Called from getc(). */
void i8042_suspend(chardev_t *d)
void i8042_suspend(void)
{
}
/kernel/trunk/arch/ia32/src/drivers/ega.c
34,8 → 34,6
#include <arch/types.h>
#include <arch/asm.h>
#include <memstr.h>
#include <console/chardev.h>
#include <console/console.h>
 
/*
* The EGA driver.
45,13 → 43,6
static spinlock_t egalock;
static __u32 ega_cursor;
 
static void ega_putchar(chardev_t *d, const char ch);
 
chardev_t ega_console;
static chardev_operations_t ega_ops = {
.write = ega_putchar
};
 
void ega_move_cursor(void);
 
void ega_init(void)
64,11 → 55,7
outb(0x3d4,0xf);
lo = inb(0x3d5);
ega_cursor = (hi<<8)|lo;
 
chardev_initialize("ega_out", &ega_console, &ega_ops);
stdout = &ega_console;
 
putchar('\n');
ega_putchar('\n');
}
 
static void ega_display_char(char ch)
91,7 → 78,7
ega_cursor = ega_cursor - ROW;
}
 
void ega_putchar(chardev_t *d, const char ch)
void ega_putchar(const char ch)
{
ipl_t ipl;
 
124,3 → 111,8
outb(0x3d4,0xf);
outb(0x3d5,ega_cursor&0xff);
}
 
void putchar(const char ch)
{
ega_putchar(ch);
}