Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 574 → Rev 575

/kernel/trunk/generic/include/print.h
36,7 → 36,6
#define INT32 4
#define INT64 8
 
extern void putchar(const char c);
extern void printf(const char *fmt, ...);
 
#endif
/kernel/trunk/generic/include/interrupt.h
0,0 → 1,43
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 __INTERRUPT_H__
#define __INTERRUPT_H__
 
#include <arch/interrupt.h>
 
#ifndef IVT_ITEMS
# define IVT_ITEMS 1
#endif
 
typedef void (* iroutine)(int n, void *stack);
 
extern iroutine exc_register(int n, char *name, iroutine f);
extern void exc_dispatch(int n, void *stack);
 
#endif
/kernel/trunk/generic/include/console/chardev.h
36,10 → 36,14
 
#define CHARDEV_BUFLEN 512
 
struct chardev;
 
/* Character device operations interface. */
struct chardev_operations {
void (* suspend)(void); /**< Suspend pushing characters. */
void (* resume)(void); /**< Resume pushing characters. */
void (* suspend)(struct chardev *);/**< Suspend pushing characters. */
void (* resume)(struct chardev *); /**< Resume pushing characters. */
/** Write character to stream */
void (* write)(struct chardev *, char c);
};
 
typedef struct chardev_operations chardev_operations_t;
46,15 → 50,20
 
/** Character input device. */
struct chardev {
char *name;
waitq_t wq;
spinlock_t lock; /**< Protects everything below. */
__u8 buffer[CHARDEV_BUFLEN];
count_t counter;
chardev_operations_t *op; /**< Implementation of chardev operations. */
index_t index;
chardev_operations_t *op; /**< Implementation of chardev operations. */
void *data;
};
 
extern void chardev_initialize(chardev_t *chardev, chardev_operations_t *op);
extern void chardev_initialize(char *name,
chardev_t *chardev,
chardev_operations_t *op);
void chardev_push_character(chardev_t *chardev, __u8 ch);
 
#endif /* __CHARDEV_H__ */
/kernel/trunk/generic/include/console/console.h
33,8 → 33,10
#include <typedefs.h>
 
extern chardev_t *stdin;
extern chardev_t *stdout;
 
extern __u8 getc(chardev_t *chardev);
extern count_t gets(chardev_t *chardev, char *buf, size_t buflen);
extern void putchar(char c);
 
#endif /* __CHARDEV_H__ */
/kernel/trunk/generic/src/console/console.c
37,6 → 37,7
 
/** Standard input character device. */
chardev_t *stdin = NULL;
chardev_t *stdout = NULL;
 
/** Get string from character device.
*
84,7 → 85,12
spinlock_unlock(&chardev->lock);
interrupts_restore(ipl);
 
chardev->op->resume();
chardev->op->resume(chardev);
 
return ch;
}
 
void putchar(char c)
{
stdout->op->write(stdout, c);
}
/kernel/trunk/generic/src/console/chardev.c
36,8 → 36,11
* @param chardev Character device.
* @param op Implementation of character device operations.
*/
void chardev_initialize(chardev_t *chardev, chardev_operations_t *op)
void chardev_initialize(char *name,chardev_t *chardev,
chardev_operations_t *op)
{
chardev->name = name;
 
waitq_initialize(&chardev->wq);
spinlock_initialize(&chardev->lock, "chardev");
chardev->counter = 0;
56,7 → 59,7
chardev->counter++;
if (chardev->counter == CHARDEV_BUFLEN - 1) {
/* buffer full => disable device interrupt */
chardev->op->suspend();
chardev->op->suspend(chardev);
}
 
putchar(ch);
/kernel/trunk/generic/src/interrupt/interrupt.c
0,0 → 1,59
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 <interrupt.h>
#include <debug.h>
 
static struct {
char *name;
iroutine f;
} ivt[IVT_ITEMS];
 
iroutine exc_register(int n, char *name, iroutine f)
{
ASSERT(n < IVT_ITEMS);
iroutine old;
old = ivt[n].f;
ivt[n].f = f;
ivt[n].name = name;
return old;
}
 
/*
* Called directly from the assembler code.
* CPU is interrupts_disable()'d.
*/
void exc_dispatch(int n, void *stack)
{
ASSERT(n < IVT_ITEMS);
ivt[n].f(n, stack);
}
/kernel/trunk/Makefile
101,6 → 101,7
generic/src/console/console.c \
generic/src/console/kconsole.c \
generic/src/cpu/cpu.c \
generic/src/interrupt/interrupt.c \
generic/src/main/main.c \
generic/src/main/kinit.c \
generic/src/main/uinit.c \
/kernel/trunk/arch/mips32/include/interrupt.h
31,13 → 31,15
 
#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/console.h
30,12 → 30,6
#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/include/drivers/keyboard.h
File deleted
/kernel/trunk/arch/mips32/include/drivers/serial.h
0,0 → 1,62
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 __DRV_SERIAL_H__
#define __DRV_SERIAL_H__
 
#include <console/chardev.h>
 
#define SERIAL_MAX 4
#define SERIAL_COM1 0x3f8
#define SERIAL_COM1_IRQ 4
#define SERIAL_COM2 0x2f8
#define SERIAL_COM2_IRQ 3
 
#define P_WRITEB(where,what) (*((volatile char *) (0xB8000000+where))=what)
#define P_READB(where) (*((volatile char *)(0xB8000000+where)))
 
#define SERIAL_READ(x) P_READB(x)
#define SERIAL_WRITE(x,c) P_WRITEB(x,c)
/* Interrupt enable register */
#define SERIAL_READ_IER(x) (P_READB((x) + 1))
#define SERIAL_WRITE_IER(x,c) (P_WRITEB((x)+1,c))
/* Interrupt identification register */
#define SERIAL_READ_IIR(x) (P_READB((x) + 2))
/* Line status register */
#define SERIAL_READ_LSR(x) (P_READB((x) + 5))
#define TRANSMIT_EMPTY_BIT 5
 
typedef struct {
int port;
int irq;
}serial_t;
 
chardev_t * serial_console(void);
int serial_init(void);
 
#endif
/kernel/trunk/arch/mips32/include/drivers/arc.h
30,6 → 30,7
#define __mips32_ARC_H__
 
#include <arch/types.h>
#include <console/chardev.h>
 
#define ARC_BASE_ADDR 0x1000;
#define ARC_MAGIC 0x53435241
212,9 → 213,8
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/drivers/msim.h
0,0 → 1,41
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 _MSIM_H_
#define _MSIM_H_
 
#include <console/chardev.h>
 
#define MSIM_VIDEORAM 0xB0000000
/** Address of 'keyboard' device. */
#define MSIM_KBD_ADDRESS 0xB0000000
#define MSIM_KBD_IRQ 2
 
chardev_t * msim_console(void);
 
#endif
/kernel/trunk/arch/mips32/Makefile.inc
108,4 → 108,5
arch/$(ARCH)/src/fpu_context.c \
arch/$(ARCH)/src/fmath.c \
arch/$(ARCH)/src/drivers/arc.c \
arch/$(ARCH)/src/drivers/keyboard.c
arch/$(ARCH)/src/drivers/msim.c \
arch/$(ARCH)/src/drivers/serial.c
/kernel/trunk/arch/mips32/src/console.c
26,48 → 26,23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <putchar.h>
#include <arch/types.h>
#include <arch/cp0.h>
#include <console/console.h>
#include <arch/console.h>
#include <arch.h>
#include <arch/drivers/arc.h>
#include <arch/arch.h>
#include <arch/drivers/serial.h>
#include <arch/drivers/msim.h>
 
/** Putchar that works with MSIM & gxemul */
static void cons_putchar(const char ch)
void console_init(void)
{
*((char *) VIDEORAM) = ch;
}
chardev_t *console;
 
/** Putchar that works with simics */
static void serial_putchar(const char ch)
{
int i;
if (arc_enabled()) {
console = arc_console();
} else if (serial_init()) {
console = serial_console();
} else
console = msim_console();
 
if (ch=='\n')
putchar('\r');
 
/* Wait until transmit buffer empty */
while (! ((*SERIAL_LSR) & (1<<TRANSMIT_EMPTY_BIT)))
;
*(SERIAL_PORT_BASE) = ch;
stdin = console;
stdout = console;
}
 
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/src/interrupt.c
26,6 → 26,7
* 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>
35,7 → 36,6
#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,6 → 93,31
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;
101,34 → 126,20
/* decode interrupt number and process the interrupt */
cause = (cp0_cause_read() >> 8) &0xff;
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;
}
}
}
for (i = 0; i < 8; i++)
if (cause & (1 << i))
exc_dispatch(i, (void *)pstate);
}
 
/* 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/keyboard.c
File deleted
/kernel/trunk/arch/mips32/src/drivers/serial.c
0,0 → 1,120
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 <interrupt.h>
#include <arch/cp0.h>
#include <arch/drivers/serial.h>
#include <console/chardev.h>
#include <console/console.h>
 
static chardev_t console;
 
static serial_t sconf[SERIAL_MAX];
 
static void serial_write(chardev_t *d, const char ch)
{
int i;
serial_t *sd = (serial_t *)d->data;
 
if (ch == '\n')
serial_write(d, '\r');
/* Wait until transmit buffer empty */
while (! (SERIAL_READ_LSR(sd->port) & (1<<TRANSMIT_EMPTY_BIT)))
;
SERIAL_WRITE(sd->port, ch);
}
 
static void serial_enable(chardev_t *d)
{
}
 
static void serial_disable(chardev_t *d)
{
}
 
int serial_init(void)
{
int i = 0;
if (SERIAL_READ_LSR(SERIAL_COM1) == 0x60) {
sconf[i].port = SERIAL_COM1;
sconf[i].irq = SERIAL_COM1_IRQ;
/* Enable interrupt on available data */
i++;
}
return i;
}
 
static chardev_operations_t serial_ops = {
.resume = serial_enable,
.suspend = serial_disable,
.write = serial_write
};
 
/** Process keyboard interrupt. Does not work in simics? */
static void serial_interrupt(int n, void *stack)
{
serial_t *sd = (serial_t *)console.data;
char ch;
 
if (!(SERIAL_READ_LSR(sd->port) & 1))
return;
ch = SERIAL_READ(sd->port);
 
if (ch =='\r')
ch = '\n';
chardev_push_character(&console, ch);
}
 
 
iroutine old_timer;
/** Do polling on timer interrupt */
static void timer_replace(int n, void *stack)
{
old_timer(n, stack);
serial_interrupt(n, stack);
}
 
#include <print.h>
chardev_t * serial_console(void)
{
serial_t *sd = &sconf[0];
 
 
chardev_initialize("serial_console", &console, &serial_ops);
console.data = sd;
 
// exc_register(2, "serial_drvr", serial_interrupt);
/* I don't know why, but the serial interrupts simply
* don't work on simics
*/
old_timer = exc_register(TIMER_IRQ, "serial_drvr_poll", timer_replace);
 
return &console;
}
/kernel/trunk/arch/mips32/src/drivers/arc.c
33,6 → 33,7
#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 */
97,26 → 98,9
static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000);
static arc_func_vector_t *arc_entry;
 
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;
static void arc_putchar(char ch);
 
arc_putchar('A');
arc_putchar('R');
arc_putchar('C');
arc_putchar('\n');
}
 
/** Return true if ARC is available */
int arc_enabled(void)
{
129,8 → 113,8
 
printf("%s: ",ctypes[c->type]);
for (i=0;i < c->identifier_len;i++)
putchar(c->identifier[i]);
putchar('\n');
arc_putchar(c->identifier[i]);
arc_putchar('\n');
}
 
void arc_print_devices(void)
174,7 → 158,7
}
 
/** Print charactor to console */
void arc_putchar(char ch)
static void arc_putchar(char ch)
{
__u32 cnt;
ipl_t ipl;
186,25 → 170,89
}
 
/** 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 */
int arc_getchar(void)
static void arc_keyboard_poll(void)
{
char ch;
__u32 count;
long result;
if (! kbd_polling_enabled)
return;
 
if (arc_entry->getreadstatus(0))
return -1;
return;
result = arc_entry->read(0, &ch, 1, &count);
if (result || count!=1) {
cpu_halt();
return -1;
return;
}
if (ch == '\r')
return '\n';
return ch;
ch = '\n';
 
chardev_push_character(&console, 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/drivers/msim.c
0,0 → 1,86
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 <interrupt.h>
#include <console/chardev.h>
#include <arch/drivers/msim.h>
#include <arch/cp0.h>
 
static chardev_t console;
 
static void msim_write(chardev_t *dev, const char ch);
static void msim_enable(chardev_t *dev);
static void msim_disable(chardev_t *dev);
 
static chardev_operations_t msim_ops = {
.resume = msim_enable,
.suspend = msim_disable,
.write = msim_write
};
 
/** Putchar that works with MSIM & gxemul */
void msim_write(chardev_t *dev, const char ch)
{
*((char *) MSIM_VIDEORAM) = ch;
}
 
/* Called from getc(). */
void msim_enable(chardev_t *dev)
{
cp0_unmask_int(MSIM_KBD_IRQ);
}
 
/* Called from getc(). */
void msim_disable(chardev_t *dev)
{
cp0_mask_int(MSIM_KBD_IRQ);
}
 
/** Process keyboard interrupt. */
static void msim_interrupt(int n, void *stack)
{
char ch;
 
ch = *((char *) MSIM_KBD_ADDRESS);
if (ch =='\r')
ch = '\n';
chardev_push_character(&console, ch);
}
 
 
/* Return console object representing msim console */
chardev_t * msim_console(void)
{
chardev_initialize("msim_console", &console, &msim_ops);
 
exc_register(MSIM_KBD_IRQ, "msim_kbd", msim_interrupt);
 
cp0_unmask_int(MSIM_KBD_IRQ);
 
return &console;
}
/kernel/trunk/arch/mips32/src/mips32.c
26,21 → 26,25
* 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
*/
54,6 → 58,9
{
/* It is not assumed by default */
interrupts_disable();
/* Initialize dispatch table */
interrupt_init();
 
arc_init();
 
83,7 → 90,6
cp0_compare_write(cp0_compare_value + cp0_count_read());
 
console_init();
keyboard_init();
arc_print_memory_map();
arc_print_devices();
}
/kernel/trunk/arch/ia32/include/ega.h
35,6 → 35,5
#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(void);
static void i8042_resume(void);
static void i8042_suspend(chardev_t *);
static void i8042_resume(chardev_t *);
 
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(&kbrd, &ops);
chardev_initialize("i8042_kbd", &kbrd, &ops);
stdin = &kbrd;
}
 
322,11 → 322,11
}
 
/* Called from getc(). */
void i8042_resume(void)
void i8042_resume(chardev_t *d)
{
}
 
/* Called from getc(). */
void i8042_suspend(void)
void i8042_suspend(chardev_t *d)
{
}
/kernel/trunk/arch/ia32/src/drivers/ega.c
34,6 → 34,8
#include <arch/types.h>
#include <arch/asm.h>
#include <memstr.h>
#include <console/chardev.h>
#include <console/console.h>
 
/*
* The EGA driver.
43,6 → 45,13
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)
55,7 → 64,11
outb(0x3d4,0xf);
lo = inb(0x3d5);
ega_cursor = (hi<<8)|lo;
ega_putchar('\n');
 
chardev_initialize("ega_out", &ega_console, &ega_ops);
stdout = &ega_console;
 
putchar('\n');
}
 
static void ega_display_char(char ch)
78,7 → 91,7
ega_cursor = ega_cursor - ROW;
}
 
void ega_putchar(const char ch)
void ega_putchar(chardev_t *d, const char ch)
{
ipl_t ipl;
 
111,8 → 124,3
outb(0x3d4,0xf);
outb(0x3d5,ega_cursor&0xff);
}
 
void putchar(const char ch)
{
ega_putchar(ch);
}