From b285860989cc2e4002e32005ce7e9005744bffa5 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 31 Aug 1998 23:03:45 +0000 Subject: Patch from Eric Valette : Eric> NB : there is still a bug on PC386 serial line : exit does not Eric> flush the remaining output queue. As this is not a bug in the Eric> driver itself but somewhere in PC386 initialization/termios Eric> relationship it will be part of another patch. Eric> NB2 : As Emmanuel excerced the exception hanlder code, while Eric> porting the SMC driver to the new BSD stack, we found a bug Eric> in the exception handler : it shall not delete the current Eric> thread in case we are running at interrupt level. This will Eric> be part of another patch... So here is the patch. This patch fixes the two problems mentionned above + it use vpath mechanism intead of copying the irq related files in the right directory. This avoid to compile them each time and is more homogenous with other Makefiles. --- c/src/exec/score/cpu/i386/cpu.c | 23 ++++++--- c/src/lib/libbsp/i386/pc386/console/Makefile.in | 9 +--- c/src/lib/libbsp/i386/pc386/console/console.c | 27 ++++++++-- c/src/lib/libbsp/i386/pc386/startup/Makefile.in | 12 ++--- c/src/lib/libbsp/i386/pc386/startup/exit.c | 69 ++++--------------------- 5 files changed, 56 insertions(+), 84 deletions(-) (limited to 'c/src') diff --git a/c/src/exec/score/cpu/i386/cpu.c b/c/src/exec/score/cpu/i386/cpu.c index 1f0900fceb..90473bdb14 100644 --- a/c/src/exec/score/cpu/i386/cpu.c +++ b/c/src/exec/score/cpu/i386/cpu.c @@ -104,12 +104,23 @@ void _defaultExcHandler (CPU_Exception_frame *ctx) printk("Error code pushed by processor itself (if not 0) = %x\n", ctx->faultCode); printk("----------------------------------------------------------\n\n"); - printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); - /* - * OK I could probably use a simplified version but at least this - * should work. - */ - rtems_task_delete(_Thread_Executing->Object.id); + if (_ISR_Nest_level > 0) { + /* + * In this case we shall not delete the task interrupted as + * it has nothing to do with the fault. We cannot return either + * because the eip points to the faulty instruction so... + */ + printk("Exception while executing ISR!!!. System locked\n"); + while(1); + } + else { + /* + * OK I could probably use a simplified version but at least this + * should work. + */ + printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); + rtems_task_delete(_Thread_Executing->Object.id); + } } cpuExcHandlerType _currentExcHandler = _defaultExcHandler; diff --git a/c/src/lib/libbsp/i386/pc386/console/Makefile.in b/c/src/lib/libbsp/i386/pc386/console/Makefile.in index 02a701c539..fa09ab4c80 100644 --- a/c/src/lib/libbsp/i386/pc386/console/Makefile.in +++ b/c/src/lib/libbsp/i386/pc386/console/Makefile.in @@ -4,14 +4,12 @@ @SET_MAKE@ srcdir = @srcdir@ -VPATH = @srcdir@ +VPATH = @srcdir@:@srcdir@/../../shared/io RTEMS_ROOT = @top_srcdir@ PROJECT_ROOT = @PROJECT_ROOT@ PGM=${ARCH}/console.rel -IMPORT_SRC=$(srcdir)/../../shared/io/printk.c - # C source names, if any, go here -- minus the .c C_PIECES=console inch outch printk C_FILES=$(C_PIECES:%=%.c) @@ -52,13 +50,10 @@ LDFLAGS += CLEAN_ADDITIONS += CLOBBER_ADDITIONS += -preinstall: - ${CP} ${IMPORT_SRC} . - ${PGM}: ${SRCS} ${OBJS} $(make-rel) -all: ${ARCH} preinstall $(SRCS) $(PGM) +all: ${ARCH} $(SRCS) $(PGM) # the .rel file built here will be put into libbsp.a by ../wrapup/Makefile install: all diff --git a/c/src/lib/libbsp/i386/pc386/console/console.c b/c/src/lib/libbsp/i386/pc386/console/console.c index e3851b1d40..b0426b5fe8 100644 --- a/c/src/lib/libbsp/i386/pc386/console/console.c +++ b/c/src/lib/libbsp/i386/pc386/console/console.c @@ -49,7 +49,7 @@ * PC386_UART_COM2 */ -int PC386ConsolePort = PC386_UART_COM2; +int PC386ConsolePort = PC386_CONSOLE_PORT_CONSOLE; static int conSetAttr(int minor, const struct termios *); extern BSP_polling_getchar_function_type BSP_poll_char; @@ -91,6 +91,13 @@ void __assert(const char *file, int line, const char *msg) * Note we cannot call exit or printf from here, * assert can fail inside ISR too */ + /* + * Close console + */ + __rtems_close(2); + __rtems_close(1); + __rtems_close(0); + printk("\nassert failed: %s: ", file); printk("%d: ", line); printk("%s\n\n", msg); @@ -205,6 +212,13 @@ console_initialize(rtems_device_major_number major, } /* console_initialize */ +static int console_open_count = 0; + +static void console_last_close() +{ + pc386_remove_rtems_irq_handler (&console_isr_data); +} + /*-------------------------------------------------------------------------+ | Console device driver OPEN entry point +--------------------------------------------------------------------------*/ @@ -217,7 +231,7 @@ console_open(rtems_device_major_number major, static rtems_termios_callbacks cb = { NULL, /* firstOpen */ - NULL, /* lastClose */ + console_last_close, /* lastClose */ NULL, /* pollRead */ PC386_uart_termios_write_com1, /* write */ conSetAttr, /* setAttributes */ @@ -228,6 +242,7 @@ console_open(rtems_device_major_number major, if(PC386ConsolePort == PC386_CONSOLE_PORT_CONSOLE) { + ++console_open_count; return RTEMS_SUCCESSFUL; } @@ -265,12 +280,16 @@ console_close(rtems_device_major_number major, void *arg) { rtems_device_driver res = RTEMS_SUCCESSFUL; - + if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE) { res = rtems_termios_close (arg); } - pc386_remove_rtems_irq_handler (&console_isr_data); + else { + if (--console_open_count == 0) { + console_last_close(); + } + } return res; } /* console_close */ diff --git a/c/src/lib/libbsp/i386/pc386/startup/Makefile.in b/c/src/lib/libbsp/i386/pc386/startup/Makefile.in index 3ac6b77792..b59323c6ff 100644 --- a/c/src/lib/libbsp/i386/pc386/startup/Makefile.in +++ b/c/src/lib/libbsp/i386/pc386/startup/Makefile.in @@ -4,17 +4,14 @@ @SET_MAKE@ srcdir = @srcdir@ -VPATH = @srcdir@:@srcdir@/../../../shared +VPATH = @srcdir@:@srcdir@/../../../shared:@srcdir@/../../shared/irq RTEMS_ROOT = @top_srcdir@ PROJECT_ROOT = @PROJECT_ROOT@ PGM=${ARCH}/startup.rel -IMPORT_SRC=$(srcdir)/../../shared/irq/irq.c \ - $(srcdir)/../../shared/irq/irq_init.c $(srcdir)/../../shared/irq/irq_asm.s - # C source names, if any, go here -- minus the .c -C_PIECES=bspclean bsplibc bsppost bspstart exit irq irq_init main sbrk +C_PIECES=bsplibc bsppost bspstart exit irq irq_init main sbrk C_FILES=$(C_PIECES:%=%.c) C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) @@ -53,12 +50,9 @@ LDFLAGS += CLEAN_ADDITIONS += CLOBBER_ADDITIONS += -preinstall: - ${CP} ${IMPORT_SRC} . - ${PGM}: ${SRCS} ${OBJS} $(make-rel) -all: ${ARCH} preinstall $(SRCS) $(PGM) +all: ${ARCH} $(SRCS) $(PGM) $(INSTALL) $(srcdir)/linkcmds ${PROJECT_RELEASE}/lib # the .rel file built here will be put into libbsp.a by ../wrapup/Makefile diff --git a/c/src/lib/libbsp/i386/pc386/startup/exit.c b/c/src/lib/libbsp/i386/pc386/startup/exit.c index 5166049d34..6e72e4bbd8 100644 --- a/c/src/lib/libbsp/i386/pc386/startup/exit.c +++ b/c/src/lib/libbsp/i386/pc386/startup/exit.c @@ -37,67 +37,20 @@ #include #include -/*-------------------------------------------------------------------------+ - | Which console is in use: either (-1) which means normal console or - | uart id if uart was used - +-------------------------------------------------------------------------*/ -extern int PC386ConsolePort; - -/*-------------------------------------------------------------------------+ -| External Prototypes -+--------------------------------------------------------------------------*/ -extern rtems_boolean _IBMPC_scankey(char *); /* defined in 'inch.c' */ - -/*-------------------------------------------------------------------------+ -| Function: _exit -| Description: Shutdown the PC. Called from libc's 'exit'. -| Global Variables: None. -| Arguments: status - exit status (ignored). -| Returns: Nothing. -+--------------------------------------------------------------------------*/ -void _exit(int status) +void bsp_cleanup() { - unsigned char ch, *cp; + unsigned char ch; static char line[]="EXECUTIVE SHUTDOWN! Any key to reboot..."; - - if(PC386ConsolePort == PC386_CONSOLE_PORT_CONSOLE) - { - - printk("\n"); - printk(line); - while(!_IBMPC_scankey(&ch)) - ; - printk("\n\n"); - } - else - { - /* Close console */ - __rtems_close(2); - __rtems_close(1); - __rtems_close(0); - - PC386_uart_intr_ctrl(PC386ConsolePort, PC386_UART_INTR_CTRL_DISABLE); - - PC386_uart_polled_write(PC386ConsolePort, '\r'); - PC386_uart_polled_write(PC386ConsolePort, '\n'); - - for(cp=line; *cp != 0; cp++) - { - PC386_uart_polled_write(PC386ConsolePort, *cp); - } - - PC386_uart_polled_read(PC386ConsolePort); - - PC386_uart_polled_write(PC386ConsolePort, '\r'); - PC386_uart_polled_write(PC386ConsolePort, '\n'); - PC386_uart_polled_write(PC386ConsolePort, '\r'); - PC386_uart_polled_write(PC386ConsolePort, '\n'); - } - + /* + * AT this point, the console driver is disconnected => we must + * use polled output/input. This is exactly what printk + * does. + */ + printk("\n"); + printk(line); + ch = BSP_poll_char(); rtemsReboot(); -} /* _exit */ - - +} -- cgit v1.2.3