diff options
Diffstat (limited to 'c/src/lib/libbsp/i386/shared/comm')
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/GDB.HOWTO | 84 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/gdb_glue.c | 61 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/i386-stub-glue.c | 273 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/i386-stub.c | 1171 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/tty_drv.c | 413 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/shared/comm/uart.c | 959 |
6 files changed, 0 insertions, 2961 deletions
diff --git a/c/src/lib/libbsp/i386/shared/comm/GDB.HOWTO b/c/src/lib/libbsp/i386/shared/comm/GDB.HOWTO deleted file mode 100644 index d5e0326781..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/GDB.HOWTO +++ /dev/null @@ -1,84 +0,0 @@ -i386/pc386 GDB Stub - -The i386 GDB stub has been updated to use the libchip drivers for the -NS16550. Make sure you have detect the device and you have added a console -entry. On the PC the legacy and PCI boards are supported. - -This GDB stub glue code is specific to the UART protocol defined in libbchip. - -The pc386 BSP has boot command line options to manage GDB support. - -a) Find the minor number of the console device: - - #include <console_private.h> - - rtems_device_minor_number minor = 0; - - if (console_find_console_entry("/dev/com1", - strlen("/dev/com1") - 1, &minor) == NULL) - error("driver not found\n"); - -Note, this call is part of the private console API and may change. - -b) To start GDB stub, run this: - - #include <bsp.h> - - /* Init GDB glue */ - i386_stub_glue_init(minor); - - /* Init GDB stub itself */ - set_debug_traps(); - - /* - * Init GDB break in capability, - * has to be called after - * set_debug_traps - */ - i386_stub_glue_init_breakin(); - - /* Put breakpoint in */ - breakpoint(); - -c) To run use GDB: - - $ i386-rtems4.12-gdb hello.exe - GNU gdb (GDB) 7.11 - Copyright (C) 2016 Free Software Foundation, Inc. - License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> - This is free software: you are free to change and redistribute it. - There is NO WARRANTY, to the extent permitted by law. Type "show copying" - and "show warranty" for details. - This GDB was configured as "--host=x86_64-freebsd10.1 --target=i386-rtems4.12". - Type "show configuration" for configuration details. - For bug reporting instructions, please see: - <http://www.gnu.org/software/gdb/bugs/>. - Find the GDB manual and other documentation resources online at: - <http://www.gnu.org/software/gdb/documentation/>. - For help, type "help". - Type "apropos word" to search for commands related to "word"... - Reading symbols from hello.exe...done. - (gdb) target remote /dev/cuaU5 - Remote debugging using /dev/cuaU5 - 0x00103fda in breakpoint () at i386-stub.c:1004 - 1004 BREAKPOINT (); - (gdb) b Init - Breakpoint 1 at 0x1001e0: file init.c, line 29. - (gdb) c - Continuing. - - Breakpoint 1, Init (ignored=1269800) at init.c:29 - 29 { - (gdb) - -Pressing ^C works and if running the board should halt when GDB connects. - -e) Use ser2net to provide reomve access over a network to a board. Install the -ser2net package and add a configuration for the port GDB connects to. For -example: - - 0005:raw:0:/dev/cuaU5:115200 - -Start ser2net running then connect GDB using: - - (gdb) target remote myhost:30005 diff --git a/c/src/lib/libbsp/i386/shared/comm/gdb_glue.c b/c/src/lib/libbsp/i386/shared/comm/gdb_glue.c deleted file mode 100644 index aededea7e8..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/gdb_glue.c +++ /dev/null @@ -1,61 +0,0 @@ -/* gdb_glue - * - * Interface to initialize the GDB. - * - * COPYRIGHT (c) 1989-1998. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#include <bsp.h> -#include <stdio.h> -#include <uart.h> - -#define BREAKPOINT() __asm__ (" int $3"); - -extern int BSPConsolePort; -void i386_stub_glue_init(int); -void i386_stub_glue_init_breakin(void); -void set_debug_traps(void); - - /* Init GDB glue */ -void init_remote_gdb( void ) -{ - if(BSPConsolePort != BSP_UART_COM2) - { - /* - * If com2 is not used as console use it for - * debugging - */ - - i386_stub_glue_init(BSP_UART_COM2); - printf( "Remote GDB using COM2...\n" ); - - } - else - { - /* Otherwise use com1 */ - i386_stub_glue_init(BSP_UART_COM1); - printf( "Remote GDB using COM1...\n" ); - } - - printf( "Remote GDB: setting traps...\n" ); - /* Init GDB stub itself */ - set_debug_traps(); - - printf( "Remote GDB: waiting remote connection....\n" ); - - /* - * Init GDB break in capability, - * has to be called after - * set_debug_traps - */ - i386_stub_glue_init_breakin(); - - /* Put breakpoint in */ - /* breakpoint(); */ - /* BREAKPOINT(); */ -} diff --git a/c/src/lib/libbsp/i386/shared/comm/i386-stub-glue.c b/c/src/lib/libbsp/i386/shared/comm/i386-stub-glue.c deleted file mode 100644 index 96105e8a21..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/i386-stub-glue.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2016. - * Chris Johns <chrisj@rtems.org> - * - * This software is Copyright (C) 1998 by T.sqware - all rights limited - * It is provided in to the public domain "as is", can be freely modified - * as far as this copyight notice is kept unchanged, but does not imply - * an endorsement by T.sqware of the product in which it is included. - */ - -#include <bsp.h> -#include <bsp/irq-generic.h> -#include <libchip/serial.h> - -#include "../../../../../../../bsps/shared/dev/serial/legacy-console.h" - -int putDebugChar(int ch); /* write a single character */ -int getDebugChar(void); /* read and return a single char */ - -/* Check is any characters received are a ^C */ -int i386_gdb_uart_ctrl_c_check(void); - -/* Raw interrupt handler. */ -void i386_gdb_uart_isr(void); - -/* assign an exception handler */ -void exceptionHandler(int, void (*handler)(void)); - -/* User supplied remote debug option. */ -extern int remote_debug; - -/* Current uart and port used by the gdb stub */ -static int uart_current; -static int uart_vector; -static console_tbl* port_current; - -/* - * Interrupt service routine for all, it does it check whether ^C is received - * if yes it will flip TF bit before returning. - * - * Note: it should be installed as raw interrupt handler. - * - * Warning: I do not like the use of the global data, I am not - * sure if this is SMP safe. - */ -int i386_gdb_uart_isr_regsav[4] RTEMS_UNUSED; -__asm__ (".p2align 4"); -__asm__ (".text"); -__asm__ (".globl i386_gdb_uart_isr"); -__asm__ ("i386_gdb_uart_isr:"); -__asm__ (" pusha"); /* Push all */ -__asm__ (" call i386_gdb_uart_ctrl_c_check"); /* Look for ^C */ -__asm__ (" movl %eax, i386_gdb_uart_isr_regsav"); /* Save eax */ -__asm__ (" popa"); /* Pop all */ -__asm__ (" xchgl %eax, i386_gdb_uart_isr_regsav"); /* Exchange eax */ -__asm__ (" cmpl $0, %eax"); /* 1 == ^C */ -__asm__ (" je i386_gdb_uart_isr_1"); /* branch if 0 */ -__asm__ (" movl %ebx, i386_gdb_uart_isr_regsav + 4"); /* Save ebx */ -__asm__ (" movl %edx, i386_gdb_uart_isr_regsav + 8"); /* Save edx */ -__asm__ (" popl %ebx"); /* Pop eip */ -__asm__ (" popl %edx"); /* Pop cs */ -__asm__ (" popl %eax"); /* Pop flags */ -__asm__ (" orl $0x100, %eax"); /* Modify it */ -__asm__ (" pushl %eax"); /* Push it back */ -__asm__ (" pushl %edx"); /* Push cs */ -__asm__ (" pushl %ebx"); /* Push eip */ -__asm__ (" movl i386_gdb_uart_isr_regsav + 4, %ebx"); /* Restore ebx */ -__asm__ (" movl i386_gdb_uart_isr_regsav + 8, %edx"); /* Restore edx */ -__asm__ ("i386_gdb_uart_isr_1:"); -__asm__ (" movl i386_gdb_uart_isr_regsav, %eax"); /* Restore eax */ -__asm__ (" iret"); /* Done */ - -static int gdb_hello_index; -static const char *const gdb_hello = "+"; - -static inline uint8_t BSP_i8259a_irq_in_service_reg(uint32_t ioport) -{ - uint8_t isr; - outport_byte(ioport, PIC_OCW3_SEL | PIC_OCW3_RR | PIC_OCW3_RIS); - inport_byte(ioport, isr); - outport_byte(ioport, PIC_OCW3_SEL | PIC_OCW3_RR); - return isr; -} - -static inline void BSP_irq_ack_at_i8259a(const int irqLine) -{ - uint8_t slave_isr = 0; - if (irqLine >= 8) { - outport_byte(PIC_SLAVE_COMMAND_IO_PORT, PIC_EOI); - slave_isr = BSP_i8259a_irq_in_service_reg(PIC_SLAVE_COMMAND_IO_PORT); - } - - /* - * Only issue the EOI to the master if there are no more interrupts in - * service for the slave. i8259a data sheet page 18, The Special Fully Nested - * Mode, b. - */ - if (slave_isr == 0) - outport_byte(PIC_MASTER_COMMAND_IO_PORT, PIC_EOI); -} - -int i386_gdb_uart_ctrl_c_check(void) -{ - BSP_irq_ack_at_i8259a(uart_vector); - if (port_current) { - int c = 0; - while (c >= 0) { - c = port_current->pDeviceFns->deviceRead(uart_current); - if (c == 3) { - gdb_hello_index = 0; - return 1; - } else if (gdb_hello[gdb_hello_index] == (char) c) { - ++gdb_hello_index; - if (gdb_hello[gdb_hello_index] == '\0') { - gdb_hello_index = 0; - return 1; - } - } else { - gdb_hello_index = 0; - } - } - } - return 0; -} - -static void -nop(const rtems_raw_irq_connect_data* notused) -{ -} - -static int -isOn(const rtems_raw_irq_connect_data* notused) -{ - return 1; -} - -int i386_stub_glue_uart(void) -{ - if (port_current == NULL) - return -1; - return uart_current; -} - -/* - * Initialize glue code linking i386-stub with the rest of - * the system - */ -void -i386_stub_glue_init(int uart) -{ - rtems_device_minor_number minor = (rtems_device_minor_number) uart; - - port_current = console_find_console_entry(NULL, 0, &minor); - - if (port_current == NULL) { - printk("GDB: invalid minor number for UART\n"); - return; - } - - uart_current = uart; - - /* Intialise the UART, assuming polled drivers */ - port_current->pDeviceFns->deviceInitialize(uart); -} - -static void BSP_uart_on(const rtems_raw_irq_connect_data* used) -{ - bsp_interrupt_vector_enable(used->idtIndex - BSP_IRQ_VECTOR_BASE); -} - -static void BSP_uart_off(const rtems_raw_irq_connect_data* used) -{ - bsp_interrupt_vector_disable(used->idtIndex - BSP_IRQ_VECTOR_BASE); -} - -/* - * In order to have a possibility to break into - * running program, one has to call this function - */ -void i386_stub_glue_init_breakin(void) -{ - rtems_raw_irq_connect_data uart_raw_irq_data; - - if (port_current == NULL) { - printk("GDB: no port initialised\n"); - return; - } - - if ((port_current->ulIntVector == 0) || (port_current->ulIntVector > 16)) { - printk("GDB: no UART interrupt support\n"); - } - else { - uart_vector = port_current->ulIntVector; - uart_raw_irq_data.idtIndex = port_current->ulIntVector + BSP_IRQ_VECTOR_BASE; - - if (!i386_get_current_idt_entry(&uart_raw_irq_data)) { - printk("GBD: cannot get idt entry\n"); - rtems_fatal_error_occurred(1); - } - - if (!i386_delete_idt_entry(&uart_raw_irq_data)) { - printk("GDB: cannot delete idt entry\n"); - rtems_fatal_error_occurred(1); - } - - uart_raw_irq_data.on = BSP_uart_on; - uart_raw_irq_data.off = BSP_uart_off; - - /* Install ISR */ - uart_raw_irq_data.idtIndex = port_current->ulIntVector + BSP_IRQ_VECTOR_BASE; - uart_raw_irq_data.hdl = i386_gdb_uart_isr; - - if (!i386_set_idt_entry (&uart_raw_irq_data)) { - printk("GDB: raw exception handler connection failed\n"); - rtems_fatal_error_occurred(1); - } - - /* Enable interrupts, this is a bit of a hack because we - * have to know the device but there is no other call. */ - (*port_current->setRegister)(port_current->ulCtrlPort1, 1, 0x01); - } -} - -int -putDebugChar(int ch) -{ - if (port_current != NULL) { - port_current->pDeviceFns->deviceWritePolled(uart_current, ch); - } - return 1; -} - -int getDebugChar(void) -{ - int c = -1; - - if (port_current != NULL) { - while (c < 0) - c = port_current->pDeviceFns->deviceRead(uart_current); - } - - return c; -} - -void exceptionHandler(int vector, void (*handler)(void)) -{ - rtems_raw_irq_connect_data excep_raw_irq_data; - - excep_raw_irq_data.idtIndex = vector; - - if(!i386_get_current_idt_entry(&excep_raw_irq_data)) - { - printk("GDB: cannot get idt entry\n"); - rtems_fatal_error_occurred(1); - } - - if(!i386_delete_idt_entry(&excep_raw_irq_data)) - { - printk("GDB: cannot delete idt entry\n"); - rtems_fatal_error_occurred(1); - } - - excep_raw_irq_data.on = nop; - excep_raw_irq_data.off = nop; - excep_raw_irq_data.isOn = isOn; - excep_raw_irq_data.hdl = handler; - - if (!i386_set_idt_entry (&excep_raw_irq_data)) { - printk("GDB: raw exception handler connection failed\n"); - rtems_fatal_error_occurred(1); - } - return; -} diff --git a/c/src/lib/libbsp/i386/shared/comm/i386-stub.c b/c/src/lib/libbsp/i386/shared/comm/i386-stub.c deleted file mode 100644 index 1eff100e9e..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/i386-stub.c +++ /dev/null @@ -1,1171 +0,0 @@ -/* - * This is the gdb i386 remote debug stub from gdb 4.XX. - */ - -/**************************************************************************** - - THIS SOFTWARE IS NOT COPYRIGHTED - - HP offers the following for use in the public domain. HP makes no - warranty with regard to the software or it's performance and the - user accepts the software "AS IS" with all faults. - - HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD - TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - - ****************************************************************************/ - -/**************************************************************************** - * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $ - * - * Module name: remcom.c $ - * Revision: 1.34 $ - * Date: 91/03/09 12:29:49 $ - * Contributor: Lake Stevens Instrument Division$ - * - * Description: low level support for gdb debugger. $ - * - * Considerations: only works on target hardware $ - * - * Written by: Glenn Engel $ - * ModuleState: Experimental $ - * - * NOTES: See Below $ - * - * Modified for 386 by Jim Kingdon, Cygnus Support. - * Modified for RTEMS by Aleksey Romanov, Quality Quorum, Inc. - * - * To enable debugger support, two things need to happen. One, a - * call to set_debug_traps() is necessary in order to allow any breakpoints - * or error conditions to be properly intercepted and reported to gdb. - * Two, a breakpoint needs to be generated to begin communication. This - * is most easily accomplished by a call to breakpoint(). Breakpoint() - * simulates a breakpoint by executing a trap #1. - * - * The external function exceptionHandler() is - * used to attach a specific handler to a specific 386 vector number. - * It should use the same privilege level it runs at. It should - * install it as an interrupt gate so that interrupts are masked - * while the handler runs. - * Also, need to assign exceptionHook and oldExceptionHook. - * - * Because gdb will sometimes write to the stack area to execute function - * calls, this program cannot rely on using the supervisor stack so it - * uses it's own stack area reserved in the int array remcomStack. - * - ************* - * - * The following gdb commands are supported: - * - * command function Return value - * - * g return the value of the CPU registers hex data or ENN - * G set the value of the CPU registers OK or ENN - * - * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN - * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN - * - * c Resume at current address SNN ( signal NN) - * cAA..AA Continue at address AA..AA SNN - * - * s Step one instruction SNN - * sAA..AA Step one instruction from AA..AA SNN - * - * k kill - * - * ? What was the last sigval ? SNN (signal NN) - * - * All commands and responses are sent with a packet which includes a - * checksum. A packet consists of - * - * $<packet info>#<checksum>. - * - * where - * <packet info> :: <characters representing the command or response> - * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>> - * - * When a packet is received, it is first acknowledged with either '+' or '-'. - * '+' indicates a successful transfer. '-' indicates a failed transfer. - * - * Example: - * - * Host: Reply: - * $m0,10#2a +$00010203040506070809101112131415#42 - * - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdbool.h> - -#include <bsp.h> - -/* - * Number of debug registers. - */ -#define NUM_DEBUG_REGISTERS 4 - -/* - * Prototypes we need to avoid warnings but not going into public space. - */ -void bsp_reset(void); -void breakpoint (void); -void set_debug_traps(void); -void set_mem_err(void); -void _returnFromException(void); -void exceptionHandler (int, void (*handler) (void)); - -/************************************************************************ - * - * external low-level support routines - */ -extern int putDebugChar (int ch); /* write a single character */ -extern int getDebugChar (void); /* read and return a single char */ - - -/************************************************************************/ -/* BUFMAX defines the maximum number of characters in inbound/outbound buffers */ -/* at least NUMREGBYTES*2 are needed for register packets */ -#define BUFMAX 400 - -static bool initialized = false; /* boolean flag. != 0 means we've been initialized */ - -extern int remote_debug; -/* debug > 0 prints ill-formed commands in valid packets & checksum errors */ - -extern void waitabit (void); - -static const char hexchars[] = "0123456789abcdef"; - -/* Number of registers. */ -#define NUMREGS 16 - -/* Number of bytes per register. */ -#define REGBYTES 4 - -/* Number of bytes of registers. */ -#define NUMREGBYTES (NUMREGS * REGBYTES) - -enum regnames - { - EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, - PC /* also known as eip */ , - PS /* also known as eflags */ , - CS, SS, DS, ES, FS, GS - }; - -/* - * these should not be static cuz they can be used outside this module - */ - -int i386_gdb_registers[NUMREGS]; - -#define STACKSIZE 10000 -int i386_gdb_remcomStack[STACKSIZE / sizeof (int)]; -int *i386_gdb_stackPtr = &i386_gdb_remcomStack[STACKSIZE / sizeof (int) - 1]; - -static int gdb_connected; - -/*************************** ASSEMBLY CODE MACROS *************************/ -/* */ - -extern void - return_to_prog (void); - -/* Restore the program's registers (including the stack pointer, which - means we get the right stack and don't have to worry about popping our - return address and any stack frames and so on) and return. */ -__asm__ (".text"); -__asm__ (".globl return_to_prog"); -__asm__ ("return_to_prog:"); -__asm__ (" movw i386_gdb_registers+44, %ss"); -__asm__ (" movl i386_gdb_registers+16, %esp"); -__asm__ (" movl i386_gdb_registers+4, %ecx"); -__asm__ (" movl i386_gdb_registers+8, %edx"); -__asm__ (" movl i386_gdb_registers+12, %ebx"); -__asm__ (" movl i386_gdb_registers+20, %ebp"); -__asm__ (" movl i386_gdb_registers+24, %esi"); -__asm__ (" movl i386_gdb_registers+28, %edi"); -__asm__ (" movw i386_gdb_registers+48, %ds"); -__asm__ (" movw i386_gdb_registers+52, %es"); -__asm__ (" movw i386_gdb_registers+56, %fs"); -__asm__ (" movw i386_gdb_registers+60, %gs"); -__asm__ (" movl i386_gdb_registers+36, %eax"); -__asm__ (" pushl %eax"); /* saved eflags */ -__asm__ (" movl i386_gdb_registers+40, %eax"); -__asm__ (" pushl %eax"); /* saved cs */ -__asm__ (" movl i386_gdb_registers+32, %eax"); -__asm__ (" pushl %eax"); /* saved eip */ -__asm__ (" movl i386_gdb_registers, %eax"); -/* use iret to restore pc and flags together so - that trace flag works right. */ -__asm__ (" iret"); - -#define BREAKPOINT() __asm__ (" int $3"); - -/* Put the error code here just in case the user cares. */ -int gdb_i386errcode; -/* Likewise, the vector number here (since GDB only gets the signal - number through the usual means, and that's not very specific). */ -int gdb_i386vector = -1; - -/* GDB stores segment registers in 32-bit words (that's just the way - m-i386v.h is written). So zero the appropriate areas in registers. */ -#define SAVE_REGISTERS1() \ - __asm__ ("movl %eax, i386_gdb_registers"); \ - __asm__ ("movl %ecx, i386_gdb_registers+4"); \ - __asm__ ("movl %edx, i386_gdb_registers+8"); \ - __asm__ ("movl %ebx, i386_gdb_registers+12"); \ - __asm__ ("movl %ebp, i386_gdb_registers+20"); \ - __asm__ ("movl %esi, i386_gdb_registers+24"); \ - __asm__ ("movl %edi, i386_gdb_registers+28"); \ - __asm__ ("movw $0, %ax"); \ - __asm__ ("movw %ds, i386_gdb_registers+48"); \ - __asm__ ("movw %ax, i386_gdb_registers+50"); \ - __asm__ ("movw %es, i386_gdb_registers+52"); \ - __asm__ ("movw %ax, i386_gdb_registers+54"); \ - __asm__ ("movw %fs, i386_gdb_registers+56"); \ - __asm__ ("movw %ax, i386_gdb_registers+58"); \ - __asm__ ("movw %gs, i386_gdb_registers+60"); \ - __asm__ ("movw %ax, i386_gdb_registers+62"); -#define SAVE_ERRCODE() \ - __asm__ ("popl %ebx"); \ - __asm__ ("movl %ebx, gdb_i386errcode"); -#define SAVE_REGISTERS2() \ - __asm__ ("popl %ebx"); /* old eip */ \ - __asm__ ("movl %ebx, i386_gdb_registers+32"); \ - __asm__ ("popl %ebx"); /* old cs */ \ - __asm__ ("movl %ebx, i386_gdb_registers+40"); \ - __asm__ ("movw %ax, i386_gdb_registers+42"); \ - __asm__ ("popl %ebx"); /* old eflags */ \ - __asm__ ("movl %ebx, i386_gdb_registers+36"); \ - /* Now that we've done the pops, we can save the stack pointer."); */ \ - __asm__ ("movw %ss, i386_gdb_registers+44"); \ - __asm__ ("movw %ax, i386_gdb_registers+46"); \ - __asm__ ("movl %esp, i386_gdb_registers+16"); - -/* See if mem_fault_routine is set, if so just IRET to that address. */ -#define CHECK_FAULT() \ - __asm__ ("cmpl $0, mem_fault_routine"); \ - __asm__ ("jne mem_fault"); - -__asm__ (".text"); -__asm__ ("mem_fault:"); -/* OK to clobber temp registers; we're just going to end up in set_mem_err. */ -/* Pop error code from the stack and save it. */ -__asm__ (" popl %eax"); -__asm__ (" movl %eax, gdb_i386errcode"); - -__asm__ (" popl %eax"); /* eip */ -/* We don't want to return there, we want to return to the function - pointed to by mem_fault_routine instead. */ -__asm__ (" movl mem_fault_routine, %eax"); -__asm__ (" popl %ecx"); /* cs (low 16 bits; junk in hi 16 bits). */ -__asm__ (" popl %edx"); /* eflags */ - -/* Remove this stack frame; when we do the iret, we will be going to - the start of a function, so we want the stack to look just like it - would after a "call" instruction. */ -__asm__ (" leave"); - -/* Push the stuff that iret wants. */ -__asm__ (" pushl %edx"); /* eflags */ -__asm__ (" pushl %ecx"); /* cs */ -__asm__ (" pushl %eax"); /* eip */ - -/* Zero mem_fault_routine. */ -__asm__ (" movl $0, %eax"); -__asm__ (" movl %eax, mem_fault_routine"); - -__asm__ ("iret"); - -#define CALL_HOOK() __asm__ ("call _remcomHandler"); - -/* This function is called when a i386 exception occurs. It saves - * all the cpu regs in the registers array, munges the stack a bit, - * and invokes an exception handler (remcom_handler). - * - * stack on entry: stack on exit: - * old eflags vector number - * old cs (zero-filled to 32 bits) - * old eip - * - */ -extern void _catchException3 (void); -__asm__ (".text"); -__asm__ (".globl _catchException3"); -__asm__ ("_catchException3:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $3"); -CALL_HOOK (); - -/* Same thing for exception 1. */ -extern void _catchException1 (void); -__asm__ (".text"); -__asm__ (".globl _catchException1"); -__asm__ ("_catchException1:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $1"); -CALL_HOOK (); - -/* Same thing for exception 0. */ -extern void _catchException0 (void); -__asm__ (".text"); -__asm__ (".globl _catchException0"); -__asm__ ("_catchException0:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $0"); -CALL_HOOK (); - -/* Same thing for exception 4. */ -extern void _catchException4 (void); -__asm__ (".text"); -__asm__ (".globl _catchException4"); -__asm__ ("_catchException4:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $4"); -CALL_HOOK (); - -/* Same thing for exception 5. */ -extern void _catchException5 (void); -__asm__ (".text"); -__asm__ (".globl _catchException5"); -__asm__ ("_catchException5:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $5"); -CALL_HOOK (); - -/* Same thing for exception 6. */ -extern void _catchException6 (void); -__asm__ (".text"); -__asm__ (".globl _catchException6"); -__asm__ ("_catchException6:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $6"); -CALL_HOOK (); - -/* Same thing for exception 7. */ -extern void _catchException7 (void); -__asm__ (".text"); -__asm__ (".globl _catchException7"); -__asm__ ("_catchException7:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $7"); -CALL_HOOK (); - -/* Same thing for exception 8. */ -extern void _catchException8 (void); -__asm__ (".text"); -__asm__ (".globl _catchException8"); -__asm__ ("_catchException8:"); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $8"); -CALL_HOOK (); - -/* Same thing for exception 9. */ -extern void _catchException9 (void); -__asm__ (".text"); -__asm__ (".globl _catchException9"); -__asm__ ("_catchException9:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $9"); -CALL_HOOK (); - -/* Same thing for exception 10. */ -extern void _catchException10 (void); -__asm__ (".text"); -__asm__ (".globl _catchException10"); -__asm__ ("_catchException10:"); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $10"); -CALL_HOOK (); - -/* Same thing for exception 12. */ -extern void _catchException12 (void); -__asm__ (".text"); -__asm__ (".globl _catchException12"); -__asm__ ("_catchException12:"); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $12"); -CALL_HOOK (); - -/* Same thing for exception 16. */ -extern void _catchException16 (void); -__asm__ (".text"); -__asm__ (".globl _catchException16"); -__asm__ ("_catchException16:"); -SAVE_REGISTERS1 (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $16"); -CALL_HOOK (); - -/* For 13, 11, and 14 we have to deal with the CHECK_FAULT stuff. */ - -/* Same thing for exception 13. */ -extern void _catchException13 (void); -__asm__ (".text"); -__asm__ (".globl _catchException13"); -__asm__ ("_catchException13:"); -CHECK_FAULT (); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $13"); -CALL_HOOK (); - -/* Same thing for exception 11. */ -extern void _catchException11 (void); -__asm__ (".text"); -__asm__ (".globl _catchException11"); -__asm__ ("_catchException11:"); -CHECK_FAULT (); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $11"); -CALL_HOOK (); - -/* Same thing for exception 14. */ -extern void _catchException14 (void); -__asm__ (".text"); -__asm__ (".globl _catchException14"); -__asm__ ("_catchException14:"); -CHECK_FAULT (); -SAVE_REGISTERS1 (); -SAVE_ERRCODE (); -SAVE_REGISTERS2 (); -__asm__ ("pushl $14"); -CALL_HOOK (); - -/* - * remcomHandler is a front end for handle_exception. It moves the - * stack pointer into an area reserved for debugger use. - */ -extern void remcomHandler (void); -__asm__ ("_remcomHandler:"); -__asm__ (" popl %eax"); /* pop off return address */ -__asm__ (" popl %eax"); /* get the exception number */ -__asm__ (" movl i386_gdb_stackPtr, %esp"); /* move to remcom stack area */ -__asm__ (" pushl %eax"); /* push exception onto stack */ -__asm__ (" call handle_exception"); /* this never returns */ - -void -_returnFromException (void) -{ - return_to_prog (); -} - -static int -hex (char ch) -{ - if ((ch >= 'a') && (ch <= 'f')) - return (ch - 'a' + 10); - if ((ch >= '0') && (ch <= '9')) - return (ch - '0'); - if ((ch >= 'A') && (ch <= 'F')) - return (ch - 'A' + 10); - return (-1); -} - -/* scan for the sequence $<data>#<checksum> */ -static void -getpacket (char *buffer) -{ - unsigned char checksum; - unsigned char xmitcsum; - int i; - int count; - char ch; - - do - { - /* wait around for the start character, ignore all other characters */ - while ((ch = (getDebugChar () & 0x7f)) != '$'); - checksum = 0; - xmitcsum = -1; - - count = 0; - - /* now, read until a # or end of buffer is found */ - while (count < BUFMAX) - { - ch = getDebugChar () & 0x7f; - if (ch == '#') - break; - checksum = checksum + ch; - buffer[count] = ch; - count = count + 1; - } - buffer[count] = 0; - - if (ch == '#') - { - xmitcsum = hex (getDebugChar () & 0x7f) << 4; - xmitcsum += hex (getDebugChar () & 0x7f); - if ((remote_debug) && (checksum != xmitcsum)) - { - printk ("bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", - checksum, xmitcsum, buffer); - } - - if (remote_debug) { - printk("GETP: $%s...%s\n", buffer, - checksum == xmitcsum ? "Ack" : "Nack"); - } - - if (checksum != xmitcsum) - putDebugChar ('-'); /* failed checksum */ - else - { - putDebugChar ('+'); /* successful transfer */ - /* if a sequence char is present, reply the sequence ID */ - if (buffer[2] == ':') - { - putDebugChar (buffer[0]); - putDebugChar (buffer[1]); - /* remove sequence chars from buffer */ - count = strlen (buffer); - for (i = 3; i <= count; i++) - buffer[i - 3] = buffer[i]; - } - } - } - } - while (checksum != xmitcsum); - -} - -/* send the packet in buffer. */ - -static void -putpacket (char *buffer) -{ - /* $<packet info>#<checksum>. */ - while (true) - { - unsigned char checksum; - int count; - char ch; - - if (remote_debug) - printk("PUTP: $%s", buffer); - - putDebugChar ('$'); - checksum = 0; - count = 0; - - while ((ch = buffer[count])) - { - if (!putDebugChar (ch)) - return; - checksum += ch; - count += 1; - } - - putDebugChar ('#'); - putDebugChar (hexchars[checksum >> 4]); - putDebugChar (hexchars[checksum % 16]); - - if (remote_debug) - printk("#%c%c...", hexchars[checksum >> 4], hexchars[checksum % 16]); - - ch = getDebugChar () & 0x7f; - if (ch == '+') { - if (remote_debug) - printk("Ack\n"); - break; - } - if (remote_debug) - printk("Nack(%c)\n", ch); - } -} - -char remcomInBuffer[BUFMAX]; -char remcomOutBuffer[BUFMAX]; -static short error; - -static void -debug_error ( - char *format, - char *parm -) -{ - if (remote_debug) - printk (format, parm); -} - -/* Address of a routine to RTE to if we get a memory fault. */ -static void (*volatile mem_fault_routine) (void) = NULL; - -/* Indicate to caller of mem2hex or hex2mem that there has been an - error. */ -static volatile int mem_err = 0; - -void -set_mem_err (void) -{ - mem_err = 1; -} - -/* These are separate functions so that they are so short and sweet - that the compiler won't save any registers (if there is a fault - to mem_fault, they won't get restored, so there better not be any - saved). */ -static int -get_char (char *addr) -{ - return *addr; -} - -static void -set_char (char *addr, int val) -{ - *addr = val; -} - -/* convert the memory pointed to by mem into hex, placing result in buf */ -/* return a pointer to the last char put in buf (null) */ -/* If MAY_FAULT is non-zero, then we should set mem_err in response to - a fault; if zero treat a fault like any other fault in the stub. */ -static char * -mem2hex (char *mem, char *buf, int count, int may_fault) -{ - int i; - unsigned char ch; - - if (may_fault) - mem_fault_routine = set_mem_err; - for (i = 0; i < count; i++) - { - ch = get_char (mem++); - if (may_fault && mem_err) - return (buf); - *buf++ = hexchars[ch >> 4]; - *buf++ = hexchars[ch % 16]; - } - *buf = 0; - if (may_fault) - mem_fault_routine = NULL; - return (buf); -} - -/* convert the hex array pointed to by buf into binary to be placed in mem */ -/* return a pointer to the character AFTER the last byte written */ -static char * -hex2mem (char *buf, char *mem, int count, int may_fault) -{ - int i; - unsigned char ch; - - if (may_fault) - mem_fault_routine = set_mem_err; - for (i = 0; i < count; i++) - { - ch = hex (*buf++) << 4; - ch = ch + hex (*buf++); - set_char (mem++, ch); - if (may_fault && mem_err) - return (mem); - } - if (may_fault) - mem_fault_routine = NULL; - return (mem); -} - -/* this function takes the 386 exception vector and attempts to - translate this number into a unix compatible signal value */ -static int -computeSignal (int exceptionVector) -{ - int sigval; - switch (exceptionVector) - { - case 0: - sigval = 8; - break; /* divide by zero */ - case 1: - sigval = 5; - break; /* debug exception */ - case 3: - sigval = 5; - break; /* breakpoint */ - case 4: - sigval = 16; - break; /* into instruction (overflow) */ - case 5: - sigval = 16; - break; /* bound instruction */ - case 6: - sigval = 4; - break; /* Invalid opcode */ - case 7: - sigval = 8; - break; /* coprocessor not available */ - case 8: - sigval = 7; - break; /* double fault */ - case 9: - sigval = 11; - break; /* coprocessor segment overrun */ - case 10: - sigval = 11; - break; /* Invalid TSS */ - case 11: - sigval = 11; - break; /* Segment not present */ - case 12: - sigval = 11; - break; /* stack exception */ - case 13: - sigval = 11; - break; /* general protection */ - case 14: - sigval = 11; - break; /* page fault */ - case 16: - sigval = 7; - break; /* coprocessor error */ - default: - sigval = 7; /* "software generated" */ - } - return (sigval); -} - -/**********************************************/ -/* WHILE WE FIND NICE HEX CHARS, BUILD AN INT */ -/* RETURN NUMBER OF CHARS PROCESSED */ -/**********************************************/ -static int -hexToInt (char **ptr, int *intValue) -{ - int numChars = 0; - int hexValue; - - *intValue = 0; - - while (**ptr) - { - hexValue = hex (**ptr); - if (hexValue >= 0) - { - *intValue = (*intValue << 4) | hexValue; - numChars++; - } - else - break; - - (*ptr)++; - } - - return (numChars); -} - -/* - * Get/Set the DR registers. - */ -static uint32_t getDR7(void) -{ - uint32_t value = 0; - asm volatile (" movl %%dr7, %0;" : "=r" (value) : : ); - return value; -} - -static void setDR7(uint32_t value) -{ - asm volatile (" movl %0, %%dr7;" : : "r" (value) : ); -} - -static uint32_t getDR(int reg) -{ - uint32_t value = 0; - switch (reg) - { - case 0: - asm volatile (" movl %%dr0, %0;" : "=r" (value) : : ); - break; - case 1: - asm volatile (" movl %%dr1, %0;" : "=r" (value) : : ); - break; - case 2: - asm volatile (" movl %%dr2, %0;" : "=r" (value) : : ); - break; - case 3: - asm volatile (" movl %%dr3, %0;" : "=r" (value) : : ); - break; - default: - break; - } - return value; -} - -static void setDR(int reg, uint32_t addr) -{ - switch (reg) - { - case 0: - asm volatile (" movl %0, %%dr0;" : : "r" (addr) : ); - break; - case 1: - asm volatile (" movl %0, %%dr1;" : : "r" (addr) : ); - break; - case 2: - asm volatile (" movl %0, %%dr2;" : : "r" (addr) : ); - break; - case 3: - asm volatile (" movl %0, %%dr3;" : : "r" (addr) : ); - break; - default: - break; - } -} - -/* - * This function does all command procesing for interfacing to gdb. - * - * NOTE: This method is called from assembly code so must be marked - * as used. - */ -static void handle_exception (int exceptionVector) __attribute__((used)); -static void -handle_exception (int exceptionVector) -{ - int sigval; - int addr, length, reg; - char *ptr; - - gdb_i386vector = exceptionVector; - - if (remote_debug) - printk ("GDB: EXECPTION: vector=%d, sr=0x%x, pc=0x%x\n", - exceptionVector, - i386_gdb_registers[PS], - i386_gdb_registers[PC]); - - /* Reply to host that an exception has occurred. Always return the - PC, SP, and FP, since gdb always wants them. */ - ptr = remcomOutBuffer; - *ptr++ = 'T'; - sigval = computeSignal (exceptionVector); - *ptr++ = hexchars[sigval >> 4]; - *ptr++ = hexchars[sigval % 16]; - - *ptr++ = hexchars[ESP]; - *ptr++ = ':'; - mem2hex ((char *) &i386_gdb_registers[ESP], ptr, REGBYTES, 0); - ptr += REGBYTES * 2; - *ptr++ = ';'; - - *ptr++ = hexchars[EBP]; - *ptr++ = ':'; - mem2hex ((char *) &i386_gdb_registers[EBP], ptr, REGBYTES, 0); - ptr += REGBYTES * 2; - *ptr++ = ';'; - - *ptr++ = hexchars[PC]; - *ptr++ = ':'; - mem2hex ((char *) &i386_gdb_registers[PC], ptr, REGBYTES, 0); - ptr += REGBYTES * 2; - *ptr++ = ';'; - - *ptr = '\0'; - - if (gdb_connected) - putpacket (remcomOutBuffer); - - while (1 == 1) - { - error = 0; - remcomOutBuffer[0] = 0; - getpacket (remcomInBuffer); - gdb_connected = 1; - switch (remcomInBuffer[0]) - { - case '?': - remcomOutBuffer[0] = 'S'; - remcomOutBuffer[1] = hexchars[sigval >> 4]; - remcomOutBuffer[2] = hexchars[sigval % 16]; - remcomOutBuffer[3] = 0; - break; - case 'd': /* remove */ - remote_debug = !(remote_debug); /* toggle debug flag */ - break; - case 'g': /* return the value of the CPU registers */ - mem2hex ((char *) i386_gdb_registers, remcomOutBuffer, NUMREGBYTES, 0); - break; - case 'G': /* set the value of the CPU registers - return OK */ - hex2mem (&remcomInBuffer[1], (char *) i386_gdb_registers, NUMREGBYTES, 0); - strcpy (remcomOutBuffer, "OK"); - break; - - case 'P': /* Set specific register */ - ptr = &remcomInBuffer[1]; - if (hexToInt (&ptr, ®) - && *ptr++ == '=') - { - hex2mem (ptr, (char *) &i386_gdb_registers[reg], REGBYTES, 0); - strcpy (remcomOutBuffer, "OK"); - } - else - { - strcpy (remcomOutBuffer, "E01"); - debug_error ("malformed register set command; %s", - remcomInBuffer); - } - break; - - /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ - case 'm': - /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ - ptr = &remcomInBuffer[1]; - if (hexToInt (&ptr, &addr)) - if (*(ptr++) == ',') - if (hexToInt (&ptr, &length)) - { - ptr = 0; - mem_err = 0; - mem2hex ((char *) addr, remcomOutBuffer, length, 1); - if (mem_err) - { - strcpy (remcomOutBuffer, "E03"); - debug_error ("memory fault", 0); - } - } - - if (ptr) - { - strcpy (remcomOutBuffer, "E01"); - debug_error ("malformed read memory command: %s", remcomInBuffer); - } - break; - - /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ - case 'M': - /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ - ptr = &remcomInBuffer[1]; - if (hexToInt (&ptr, &addr)) - if (*(ptr++) == ',') - if (hexToInt (&ptr, &length)) - if (*(ptr++) == ':') - { - mem_err = 0; - hex2mem (ptr, (char *) addr, length, 1); - - if (mem_err) - { - strcpy (remcomOutBuffer, "E03"); - debug_error ("memory fault", 0); - } - else - { - strcpy (remcomOutBuffer, "OK"); - } - - ptr = 0; - } - if (ptr) - { - strcpy (remcomOutBuffer, "E02"); - debug_error ("malformed write memory command: %s", remcomInBuffer); - } - break; - - /* cAA..AA Continue at address AA..AA(optional) */ - /* sAA..AA Step one instruction from AA..AA(optional) */ - case 'c': - case 's': - /* try to read optional parameter, pc unchanged if no parm */ - ptr = &remcomInBuffer[1]; - if (hexToInt (&ptr, &addr)) - i386_gdb_registers[PC] = addr; - - /* clear the trace bit */ - i386_gdb_registers[PS] &= 0xfffffeff; - - /* set the trace bit if we're stepping */ - if (remcomInBuffer[0] == 's') - i386_gdb_registers[PS] |= 0x100; - - _returnFromException (); /* this is a jump */ - break; - - case 'Z': - case 'z': - /* - * Z1 = execute (00b) - * Z2 = write (01b) - * Z3 = read (??, need to use 11b)) - * Z4 = read/write (11b) - */ - ptr = &remcomInBuffer[1]; - reg = *(ptr++); - if (reg == '0') - break; - printk("hbreak\n"); - switch ((char) reg) - { - case '1': - reg = 0; - break; - case '2': - reg = 1; - case '3': - case '4': - default: - reg = 3; - break; - } - if (*(ptr++) == ',') - { - bool insert = remcomInBuffer[0] == 'Z'; - if (hexToInt (&ptr, &addr)) - { - if (*(ptr++) == ',') - { - uint32_t dr7; - int i; - hexToInt(&ptr, &length); - dr7 = getDR7(); - for (i = 0; i < NUM_DEBUG_REGISTERS; ++i) - { - if ((dr7 & (2 << (i * 2))) == 0) - { - if (insert) - { - setDR(i, addr); - dr7 |= - ((length - 1) << ((i * 2) + 18)) | - (reg << ((i * 2) + 16)) | - (2 << (i * 2)); - setDR7(dr7); - printk("set DR%i to %08x\n", i, addr); - break; - } - } - else if (!insert) - { - uint32_t dra = getDR(i); - if (dra == addr) - { - dr7 &= ~(2 << (i * 2)); - setDR7(dr7); - printk("clear DR%i\n", i); - break; - } - } - } - if (insert && (i == NUM_DEBUG_REGISTERS)) - { - ptr = 0; - } - } - else - { - ptr = 0; - } - } - else - { - ptr = 0; - } - } - else - { - ptr = 0; - } - - if (ptr) - strcpy (remcomOutBuffer, "OK"); - else - strcpy (remcomOutBuffer, "E1"); - break; - - /* Detach. */ - case 'D': - putpacket (remcomOutBuffer); - i386_gdb_registers[PS] &= 0xfffffeff; - _returnFromException (); /* this is a jump */ - break; - - /* kill the program */ - case 'k': /* do nothing */ - bsp_reset(); - continue; - - default: - break; - } /* switch */ - - /* reply to the request */ - putpacket (remcomOutBuffer); - } -} - -/* this function is used to set up exception handlers for tracing and - breakpoints */ -void -set_debug_traps (void) -{ - i386_gdb_stackPtr = &i386_gdb_remcomStack[STACKSIZE / sizeof (int) - 1]; - - exceptionHandler (0, _catchException0); - exceptionHandler (1, _catchException1); - exceptionHandler (3, _catchException3); - exceptionHandler (4, _catchException4); - exceptionHandler (5, _catchException5); - exceptionHandler (6, _catchException6); - exceptionHandler (7, _catchException7); - exceptionHandler (8, _catchException8); - exceptionHandler (9, _catchException9); - exceptionHandler (10, _catchException10); - exceptionHandler (11, _catchException11); - exceptionHandler (12, _catchException12); - exceptionHandler (13, _catchException13); - exceptionHandler (14, _catchException14); - exceptionHandler (16, _catchException16); - - /* In case GDB is started before us, ack any packets (presumably - "$?#xx") sitting there. */ - putDebugChar ('+'); - - initialized = true; - -} - -/* This function will generate a breakpoint exception. It is used at the - beginning of a program to sync up with a debugger and can be used - otherwise as a quick means to stop program execution and "break" into - the debugger. */ - -void -breakpoint (void) -{ - if (initialized) - { - BREAKPOINT (); - } - waitabit (); -} - -int waitlimit = 1000000; - -void -waitabit (void) -{ - int i; - for (i = 0; i < waitlimit; i++); -} diff --git a/c/src/lib/libbsp/i386/shared/comm/tty_drv.c b/c/src/lib/libbsp/i386/shared/comm/tty_drv.c deleted file mode 100644 index 121820061a..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/tty_drv.c +++ /dev/null @@ -1,413 +0,0 @@ -/*************************************************************************** - * - * MODULE DESCRIPTION: - * This module implements the RTEMS drivers for the PC serial ports - * as /dev/ttyS1 for COM1 and /dev/ttyS2 as COM2. If one of the ports - * is used as the console, this driver would fail to initialize. - * - * This code was based on the console driver. It is based on the - * current termios framework. This is just a shell around the - * termios support. - * - * by: Rosimildo da Silva: - * rdasilva@connecttel.com - * http://www.connecttel.com - * - ****************************************************************************/ - - -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#include <bsp.h> -#include <bsp/irq.h> -#include <rtems/bspIo.h> -#include <rtems/libio.h> -#include <rtems/termiostypes.h> -#include <termios.h> -#include <uart.h> -#include <libcpu/cpuModel.h> -#include <bsp/tty_drv.h> - -int BSP_poll_read(int); - -/* Internal routines */ -static int tty1_conSetAttr( int minor, const struct termios *t); -static int tty2_conSetAttr( int minor, const struct termios *t); - -extern BSP_polling_getchar_function_type BSP_poll_char; -extern int BSPConsolePort; -extern void rtems_set_waiting_id_comx( int port, rtems_id id, rtems_event_set event ); - -/* - * TTYS1 - device driver INITIALIZE entry point. - */ -rtems_device_driver -tty1_initialize(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - rtems_status_code status; - - /* Check if this port is not been used as console */ - if( BSPConsolePort == BSP_UART_COM1 ) - { - status = -1; - printk("TTYS1: port selected as console.\n"); - rtems_fatal_error_occurred( status ); - } - - /* - * Set up TERMIOS - */ - rtems_termios_initialize(); - - /* - * Do device-specific initialization - */ - /* 9600-8-N-1, without hardware flow control */ - BSP_uart_init( BSP_UART_COM1, 9600, CHR_8_BITS, 0, 0, 0 ); - status = rtems_interrupt_handler_install( - BSP_UART_COM1_IRQ, - "tty_drv", - RTEMS_INTERRUPT_UNIQUE, - BSP_uart_termios_isr_com1, - NULL - ); - assert(status == RTEMS_SUCCESSFUL); - /* - * Register the device - */ - status = rtems_io_register_name ("/dev/ttyS1", major, 0); - if (status != RTEMS_SUCCESSFUL) - { - printk("Error registering ttyS1 device!\n"); - rtems_fatal_error_occurred (status); - } - printk("Device: /dev/ttyS1 initialized.\n"); - return RTEMS_SUCCESSFUL; -} /* tty_initialize */ - -static int tty1_last_close(int major, int minor, void *arg) -{ - rtems_status_code status; - - status = rtems_interrupt_handler_remove( - BSP_UART_COM1_IRQ, - BSP_uart_termios_isr_com1, - NULL - ); - assert(status == RTEMS_SUCCESSFUL); - return 0; -} - -/* - * TTY1 - device driver OPEN entry point - */ -rtems_device_driver -tty1_open(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - rtems_status_code status; -#ifndef USE_TASK_DRIVEN - static rtems_termios_callbacks cb = - { - NULL, /* firstOpen */ - tty1_last_close, /* lastClose */ - NULL, /* poll read */ - BSP_uart_termios_write_com1, /* write */ - tty1_conSetAttr, /* setAttributes */ - NULL, /* stopRemoteTx */ - NULL, /* startRemoteTx */ - TERMIOS_IRQ_DRIVEN /* outputUsesInterrupts */ - }; -#else - static rtems_termios_callbacks cb = - { - NULL, /* firstOpen */ - NULL, /* lastClose */ - BSP_uart_termios_read_com1, /* poll read */ - BSP_uart_termios_write_com1, /* write */ - tty1_conSetAttr, /* setAttributes */ - NULL, /* stopRemoteTx */ - NULL, /* startRemoteTx */ - TERMIOS_TASK_DRIVEN /* outputUsesInterrupts */ - }; -#endif - - status = rtems_termios_open( major, minor, arg, &cb ); - if(status != RTEMS_SUCCESSFUL) - { - printk("Error openning tty1 device\n"); - return status; - } - - /* - * Pass data area info down to driver - */ - BSP_uart_termios_set( BSP_UART_COM1, - ((rtems_libio_open_close_args_t *)arg)->iop->data1 ); - /* Enable interrupts on channel */ - BSP_uart_intr_ctrl( BSP_UART_COM1, BSP_UART_INTR_CTRL_TERMIOS); - return RTEMS_SUCCESSFUL; -} - -/* - * TTY - device driver CLOSE entry point - */ -rtems_device_driver -tty_close(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - - return (rtems_termios_close (arg)); - -} /* tty_close */ - -/* - * TTY device driver READ entry point. - * Read characters from the tty device. - */ -rtems_device_driver -tty_read(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - return rtems_termios_read (arg); -} /* tty_read */ - -/* - * TTY device driver WRITE entry point. - * Write characters to the tty device. - */ -rtems_device_driver -tty_write(rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - return rtems_termios_write (arg); - -} /* tty_write */ - -/* - * Handle ioctl request. This is a generic internal - * routine to handle both devices. - */ -static rtems_device_driver tty_control( int port, void *arg ) -{ - rtems_libio_ioctl_args_t *args = arg; - switch( args->command ) - { - default: - return rtems_termios_ioctl (arg); - break; - } - args->ioctl_return = 0; - return RTEMS_SUCCESSFUL; -} - -/* - * Handle ioctl request for ttyS1. - */ -rtems_device_driver -tty1_control(rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return tty_control( BSP_UART_COM1, arg ); -} - -static int -conSetAttr(int port, int minor, const struct termios *t) -{ - unsigned long baud, databits, parity, stopbits; - - baud = rtems_termios_baud_to_number(t->c_ospeed); - if ( baud > 115200 ) - rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); - - if (t->c_cflag & PARENB) { - /* Parity is enabled */ - if (t->c_cflag & PARODD) { - /* Parity is odd */ - parity = PEN; - } - else { - /* Parity is even */ - parity = PEN | EPS; - } - } - else { - /* No parity */ - parity = 0; - } - - switch (t->c_cflag & CSIZE) { - case CS5: databits = CHR_5_BITS; break; - case CS6: databits = CHR_6_BITS; break; - case CS7: databits = CHR_7_BITS; break; - default: /* just to avoid warnings -- all cases are covered */ - case CS8: databits = CHR_8_BITS; break; - } - - if (t->c_cflag & CSTOPB) { - /* 2 stop bits */ - stopbits = STB; - } - else { - /* 1 stop bit */ - stopbits = 0; - } - - printk("Setting attributes, port=%X, baud=%" PRId32 ", linemode = 0x%02" PRIx32 "\n", - port, baud, databits | parity | stopbits ); - BSP_uart_set_attributes(port, baud, databits, parity, stopbits); - return 0; -} - -/* - * Handle ioctl request for ttyS2. - */ -static int -tty1_conSetAttr( int minor, const struct termios *t) -{ - return conSetAttr( BSP_UART_COM1, minor, t ); -} - -/* - * TTY2 device driver INITIALIZE entry point. - */ -rtems_device_driver -tty2_initialize(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - rtems_status_code status; - - /* Check if this port is not been used as console */ - if( BSPConsolePort == BSP_UART_COM2 ) - { - status = -1; - printk("TTY2: port selected as console.\n"); - rtems_fatal_error_occurred( status ); - } - - /* - * Set up TERMIOS - */ - rtems_termios_initialize(); - - /* - * Do device-specific initialization - */ - /* 9600-8-N-1, without hardware flow control */ - BSP_uart_init( BSP_UART_COM2, 9600, CHR_8_BITS, 0, 0, 0); - status = rtems_interrupt_handler_install( - BSP_UART_COM2_IRQ, - "tty_drv", - RTEMS_INTERRUPT_UNIQUE, - BSP_uart_termios_isr_com2, - NULL - ); - assert(status == RTEMS_SUCCESSFUL); - - /* - * Register the device - */ - status = rtems_io_register_name ("/dev/ttyS2", major, 0); - if (status != RTEMS_SUCCESSFUL) - { - printk("Error registering tty2 device!\n"); - rtems_fatal_error_occurred (status); - } - printk("Device: /dev/ttyS2 initialized.\n"); - return RTEMS_SUCCESSFUL; -} /* tty_initialize */ - -static int tty2_last_close(int major, int minor, void *arg) -{ - rtems_status_code status; - - status = rtems_interrupt_handler_remove( - BSP_UART_COM2_IRQ, - BSP_uart_termios_isr_com2, - NULL - ); - assert(status == RTEMS_SUCCESSFUL); - return 0; -} - -/* - * TTY2 device driver OPEN entry point - */ -rtems_device_driver -tty2_open(rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - rtems_status_code status; -#ifndef USE_TASK_DRIVEN - static rtems_termios_callbacks cb = - { - NULL, /* firstOpen */ - tty2_last_close, /* lastClose */ - NULL, /* poll read */ - BSP_uart_termios_write_com2, /* write */ - tty2_conSetAttr, /* setAttributes */ - NULL, /* stopRemoteTx */ - NULL, /* startRemoteTx */ - TERMIOS_IRQ_DRIVEN /* outputUsesInterrupts */ - }; -#else - static rtems_termios_callbacks cb = - { - NULL, /* firstOpen */ - NULL, /* lastClose */ - BSP_uart_termios_read_com2, /* poll read */ - BSP_uart_termios_write_com2, /* write */ - tty2_conSetAttr, /* setAttributes */ - NULL, /* stopRemoteTx */ - NULL, /* startRemoteTx */ - TERMIOS_TASK_DRIVEN /* outputUsesInterrupts */ - }; -#endif - - status = rtems_termios_open (major, minor, arg, &cb); - if(status != RTEMS_SUCCESSFUL) - { - printk("Error openning tty1 device\n"); - return status; - } - - /* - * Pass data area info down to driver - */ - BSP_uart_termios_set( BSP_UART_COM2, - ((rtems_libio_open_close_args_t *)arg)->iop->data1 ); - /* Enable interrupts on channel */ - BSP_uart_intr_ctrl( BSP_UART_COM2, BSP_UART_INTR_CTRL_TERMIOS); - return RTEMS_SUCCESSFUL; -} - -/* - * Handle ioctl request for TTY2 - */ -rtems_device_driver -tty2_control(rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return tty_control( BSP_UART_COM2, arg ); -} - -static int -tty2_conSetAttr( int minor, const struct termios *t) -{ - return conSetAttr( BSP_UART_COM2, minor, t ); -} diff --git a/c/src/lib/libbsp/i386/shared/comm/uart.c b/c/src/lib/libbsp/i386/shared/comm/uart.c deleted file mode 100644 index 5d2dd64854..0000000000 --- a/c/src/lib/libbsp/i386/shared/comm/uart.c +++ /dev/null @@ -1,959 +0,0 @@ -/* - * This software is Copyright (C) 1998 by T.sqware - all rights limited - * It is provided in to the public domain "as is", can be freely modified - * as far as this copyight notice is kept unchanged, but does not imply - * an endorsement by T.sqware of the product in which it is included. - */ - -#include <stdio.h> -#include <bsp.h> -#include <bsp/irq.h> -#include <uart.h> -#include <rtems/libio.h> -#include <rtems/termiostypes.h> -#include <termios.h> -#include <assert.h> - -/* - * Basic 16552 driver - */ - -struct uart_data -{ - int ioMode; - int hwFlow; - unsigned int ier; - unsigned long baud; - unsigned long databits; - unsigned long parity; - unsigned long stopbits; -}; - -static struct uart_data uart_data[2]; - -/* - * Macros to read/write register of uart, if configuration is - * different just rewrite these macros - */ - -static inline unsigned char -uread(int uart, unsigned int reg) -{ - register unsigned char val; - - if (uart == 0) { - inport_byte(COM1_BASE_IO+reg, val); - } else { - inport_byte(COM2_BASE_IO+reg, val); - } - - return val; -} - -static inline void -uwrite(int uart, int reg, unsigned int val) -{ - if (uart == 0) { - outport_byte(COM1_BASE_IO+reg, val); - } else { - outport_byte(COM2_BASE_IO+reg, val); - } -} - -static void -uartError(int uart) -{ - unsigned char uartStatus, dummy; - - uartStatus = uread(uart, LSR); - (void) uartStatus; /* avoid set but not used warning */ - dummy = uread(uart, RBR); - (void) dummy; /* avoid set but not used warning */ - -#ifdef UARTDEBUG - if (uartStatus & OE) - printk("********* Over run Error **********\n"); - if (uartStatus & PE) - printk("********* Parity Error **********\n"); - if (uartStatus & FE) - printk("********* Framing Error **********\n"); - if (uartStatus & BI) - printk("********* Parity Error **********\n"); - if (uartStatus & ERFIFO) - printk("********* Error receive Fifo **********\n"); -#endif -} - -/* - * Uart initialization, it is hardcoded to 8 bit, no parity, - * one stop bit, FIFO, things to be changed - * are baud rate and nad hw flow control, - * and longest rx fifo setting - */ -void -BSP_uart_init -( - int uart, - unsigned long baud, - unsigned long databits, - unsigned long parity, - unsigned long stopbits, - int hwFlow -) -{ - /* Sanity check */ - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - switch(baud) - { - case 50: - case 75: - case 110: - case 134: - case 300: - case 600: - case 1200: - case 2400: - case 9600: - case 19200: - case 38400: - case 57600: - case 115200: - break; - default: - assert(0); - return; - } - - /* Set DLAB bit to 1 */ - uwrite(uart, LCR, DLAB); - - /* Set baud rate */ - uwrite(uart, DLL, (BSPBaseBaud/baud) & 0xff); - uwrite(uart, DLM, ((BSPBaseBaud/baud) >> 8) & 0xff); - - /* 8-bit, no parity , 1 stop */ - uwrite(uart, LCR, databits | parity | stopbits); - - /* Set DTR, RTS and OUT2 high */ - uwrite(uart, MCR, DTR | RTS | OUT_2); - - /* Enable FIFO */ - uwrite(uart, FCR, FIFO_EN | XMIT_RESET | RCV_RESET | RECEIVE_FIFO_TRIGGER12); - - /* Disable Interrupts */ - uwrite(uart, IER, 0); - - /* Read status to clear them */ - uread(uart, LSR); - uread(uart, RBR); - uread(uart, MSR); - - /* Remember state */ - uart_data[uart].baud = baud; - uart_data[uart].databits = databits; - uart_data[uart].parity = parity; - uart_data[uart].stopbits = stopbits; - uart_data[uart].hwFlow = hwFlow; - return; -} - -/* - * Set baud - */ - -void -BSP_uart_set_baud( - int uart, - unsigned long baud -) -{ - /* Sanity check */ - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - BSP_uart_set_attributes( uart, baud, uart_data[uart].databits, - uart_data[uart].parity, uart_data[uart].stopbits ); -} - -/* - * Set all attributes - */ - -void -BSP_uart_set_attributes -( - int uart, - unsigned long baud, - unsigned long databits, - unsigned long parity, - unsigned long stopbits -) -{ - unsigned char mcr, ier; - - /* Sanity check */ - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - /* - * This function may be called whenever TERMIOS parameters - * are changed, so we have to make sure that baud change is - * indeed required - */ - - if( (baud == uart_data[uart].baud) && - (databits == uart_data[uart].databits) && - (parity == uart_data[uart].parity) && - (stopbits == uart_data[uart].stopbits) ) - { - return; - } - - mcr = uread(uart, MCR); - ier = uread(uart, IER); - - BSP_uart_init(uart, baud, databits, parity, stopbits, uart_data[uart].hwFlow); - - uwrite(uart, MCR, mcr); - uwrite(uart, IER, ier); - - return; -} - -/* - * Enable/disable interrupts - */ -void -BSP_uart_intr_ctrl(int uart, int cmd) -{ - int iStatus = (int)INTERRUPT_DISABLE; - - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - switch(cmd) - { - case BSP_UART_INTR_CTRL_ENABLE: - iStatus |= (RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE | TRANSMIT_ENABLE); - if ( uart_data[uart].hwFlow ) { - iStatus |= MODEM_ENABLE; - } - break; - case BSP_UART_INTR_CTRL_TERMIOS: - iStatus |= (RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE); - if ( uart_data[uart].hwFlow ) { - iStatus |= MODEM_ENABLE; - } - break; - case BSP_UART_INTR_CTRL_GDB: - iStatus |= RECEIVE_ENABLE; - break; - } - - uart_data[uart].ier = iStatus; - uwrite(uart, IER, iStatus); - - return; -} - -void -BSP_uart_throttle(int uart) -{ - unsigned int mcr; - - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - if(!uart_data[uart].hwFlow) - { - /* Should not happen */ - assert(0); - return; - } - mcr = uread (uart, MCR); - /* RTS down */ - mcr &= ~RTS; - uwrite(uart, MCR, mcr); - - return; -} - -void -BSP_uart_unthrottle(int uart) -{ - unsigned int mcr; - - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - if(!uart_data[uart].hwFlow) - { - /* Should not happen */ - assert(0); - return; - } - mcr = uread (uart, MCR); - /* RTS up */ - mcr |= RTS; - uwrite(uart, MCR, mcr); - - return; -} - -/* - * Status function, -1 if error - * detected, 0 if no received chars available, - * 1 if received char available, 2 if break - * is detected, it will eat break and error - * chars. It ignores overruns - we cannot do - * anything about - it execpt count statistics - * and we are not counting it. - */ -int -BSP_uart_polled_status(int uart) -{ - unsigned char val; - - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - val = uread(uart, LSR); - - if(val & BI) - { - /* BREAK found, eat character */ - uread(uart, RBR); - return BSP_UART_STATUS_BREAK; - } - - if((val & (DR | OE | FE)) == 1) - { - /* No error, character present */ - return BSP_UART_STATUS_CHAR; - } - - if((val & (DR | OE | FE)) == 0) - { - /* Nothing */ - return BSP_UART_STATUS_NOCHAR; - } - - /* - * Framing or parity error - * eat character - */ - uread(uart, RBR); - - return BSP_UART_STATUS_ERROR; -} - -/* - * Polled mode write function - */ -void -BSP_uart_polled_write(int uart, int val) -{ - unsigned char val1; - - /* Sanity check */ - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - for(;;) - { - if((val1=uread(uart, LSR)) & THRE) - { - break; - } - } - - if(uart_data[uart].hwFlow) - { - for(;;) - { - if(uread(uart, MSR) & CTS) - { - break; - } - } - } - - uwrite(uart, THR, val & 0xff); - - /* - * Wait for character to be transmitted. - * This ensures that printk and printf play nicely together - * when using the same serial port. - * Yes, there's a performance hit here, but if we're doing - * polled writes to a serial port we're probably not that - * interested in efficiency anyway..... - */ - for(;;) - { - if((val1=uread(uart, LSR)) & THRE) - { - break; - } - } - - return; -} - -void -BSP_output_char_via_serial(char val) -{ - BSP_uart_polled_write(BSPConsolePort, val); -} - -/* - * Polled mode read function - */ -int -BSP_uart_polled_read(int uart) -{ - unsigned char val; - - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - for(;;) - { - if(uread(uart, LSR) & DR) - { - break; - } - } - - val = uread(uart, RBR); - - return (int)(val & 0xff); -} - -int -BSP_poll_char_via_serial(void) -{ - return BSP_uart_polled_read(BSPConsolePort); -} - -/* ================ Termios support =================*/ - -static volatile int termios_stopped_com1 = 0; -static volatile int termios_tx_active_com1 = 0; -static void* termios_ttyp_com1 = NULL; -static char termios_tx_hold_com1 = 0; -static volatile char termios_tx_hold_valid_com1 = 0; - -static volatile int termios_stopped_com2 = 0; -static volatile int termios_tx_active_com2 = 0; -static void* termios_ttyp_com2 = NULL; -static char termios_tx_hold_com2 = 0; -static volatile char termios_tx_hold_valid_com2 = 0; - -static void ( *driver_input_handler_com1 )( void *, char *, int ) = 0; -static void ( *driver_input_handler_com2 )( void *, char *, int ) = 0; - -/* - * Set channel parameters - */ -void -BSP_uart_termios_set(int uart, void *ttyp) -{ - struct rtems_termios_tty *p = (struct rtems_termios_tty *)ttyp; - unsigned char val; - assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); - - if(uart == BSP_UART_COM1) - { - uart_data[uart].ioMode = p->device.outputUsesInterrupts; - if(uart_data[uart].hwFlow) - { - val = uread(uart, MSR); - - termios_stopped_com1 = (val & CTS) ? 0 : 1; - } - else - { - termios_stopped_com1 = 0; - } - termios_tx_active_com1 = 0; - termios_ttyp_com1 = ttyp; - termios_tx_hold_com1 = 0; - termios_tx_hold_valid_com1 = 0; - } - else - { - uart_data[uart].ioMode = p->device.outputUsesInterrupts; - if(uart_data[uart].hwFlow) - { - val = uread(uart, MSR); - - termios_stopped_com2 = (val & CTS) ? 0 : 1; - } - else - { - termios_stopped_com2 = 0; - } - termios_tx_active_com2 = 0; - termios_ttyp_com2 = ttyp; - termios_tx_hold_com2 = 0; - termios_tx_hold_valid_com2 = 0; - } - - return; -} - -int -BSP_uart_termios_read_com1(int uart) -{ - int off = (int)0; - char buf[40]; - - /* read bytes */ - while (( off < sizeof(buf) ) && ( uread(BSP_UART_COM1, LSR) & DR )) { - buf[off++] = uread(BSP_UART_COM1, RBR); - } - - /* write out data */ - if ( off > 0 ) { - rtems_termios_enqueue_raw_characters(termios_ttyp_com1, buf, off); - } - - /* enable receive interrupts */ - uart_data[BSP_UART_COM1].ier |= (RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE); - uwrite(BSP_UART_COM1, IER, uart_data[BSP_UART_COM1].ier); - - return ( EOF ); -} - -int -BSP_uart_termios_read_com2(int uart) -{ - int off = (int)0; - char buf[40]; - - /* read current byte */ - while (( off < sizeof(buf) ) && ( uread(BSP_UART_COM2, LSR) & DR )) { - buf[off++] = uread(BSP_UART_COM2, RBR); - } - - /* write out data */ - if ( off > 0 ) { - rtems_termios_enqueue_raw_characters(termios_ttyp_com2, buf, off); - } - - /* enable receive interrupts */ - uart_data[BSP_UART_COM2].ier |= (RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE); - uwrite(BSP_UART_COM2, IER, uart_data[BSP_UART_COM2].ier); - - return ( EOF ); -} - -ssize_t -BSP_uart_termios_write_com1(int minor, const char *buf, size_t len) -{ - if(len <= 0) - { - return 0; - } - - assert(buf != NULL); - - /* If there TX buffer is busy - something is royally screwed up */ - assert((uread(BSP_UART_COM1, LSR) & THRE) != 0); - - if(termios_stopped_com1) - { - /* CTS low */ - termios_tx_hold_com1 = *buf; - termios_tx_hold_valid_com1 = 1; - return 0; - } - - /* Write character */ - uwrite(BSP_UART_COM1, THR, *buf & 0xff); - - /* Enable interrupts if necessary */ - if ( !termios_tx_active_com1 ) { - termios_tx_active_com1 = 1; - uart_data[BSP_UART_COM1].ier |= TRANSMIT_ENABLE; - uwrite(BSP_UART_COM1, IER, uart_data[BSP_UART_COM1].ier); - } - - return 1; -} - -ssize_t -BSP_uart_termios_write_com2(int minor, const char *buf, size_t len) -{ - if(len <= 0) - { - return 0; - } - - assert(buf != NULL); - - /* If there TX buffer is busy - something is royally screwed up */ - assert((uread(BSP_UART_COM2, LSR) & THRE) != 0); - - if(termios_stopped_com2) - { - /* CTS low */ - termios_tx_hold_com2 = *buf; - termios_tx_hold_valid_com2 = 1; - return 0; - } - - /* Write character */ - uwrite(BSP_UART_COM2, THR, *buf & 0xff); - - /* Enable interrupts if necessary */ - if ( !termios_tx_active_com2 ) { - termios_tx_active_com2 = 1; - uart_data[BSP_UART_COM2].ier |= TRANSMIT_ENABLE; - uwrite(BSP_UART_COM2, IER, uart_data[BSP_UART_COM2].ier); - } - - return 1; -} - -void -BSP_uart_termios_isr_com1(void *ignored) -{ - unsigned char buf[40]; - unsigned char val; - int off, ret, vect; - - off = 0; - - for(;;) - { - vect = uread(BSP_UART_COM1, IIR) & 0xf; - - switch(vect) - { - case MODEM_STATUS : - val = uread(BSP_UART_COM1, MSR); - if(uart_data[BSP_UART_COM1].hwFlow) - { - if(val & CTS) - { - /* CTS high */ - termios_stopped_com1 = 0; - if(termios_tx_hold_valid_com1) - { - termios_tx_hold_valid_com1 = 0; - BSP_uart_termios_write_com1(0, &termios_tx_hold_com1, - 1); - } - } - else - { - /* CTS low */ - termios_stopped_com1 = 1; - } - } - break; - case NO_MORE_INTR : - /* No more interrupts */ - if(off != 0) - { - /* Update rx buffer */ - if( driver_input_handler_com1 ) - { - driver_input_handler_com1( termios_ttyp_com1, (char *)buf, off ); - } - else - { - /* Update rx buffer */ - rtems_termios_enqueue_raw_characters(termios_ttyp_com1, (char *)buf, off ); - } - } - return; - case TRANSMITTER_HODING_REGISTER_EMPTY : - /* - * TX holding empty: we have to disable these interrupts - * if there is nothing more to send. - */ - - /* If nothing else to send disable interrupts */ - ret = rtems_termios_dequeue_characters(termios_ttyp_com1, 1); - if ( ret == 0 ) { - termios_tx_active_com1 = 0; - uart_data[BSP_UART_COM1].ier &= ~(TRANSMIT_ENABLE); - uwrite(BSP_UART_COM1, IER, uart_data[BSP_UART_COM1].ier); - } - break; - case RECEIVER_DATA_AVAIL : - case CHARACTER_TIMEOUT_INDICATION: - if ( uart_data[BSP_UART_COM1].ioMode == TERMIOS_TASK_DRIVEN ) { - /* ensure interrupts are enabled */ - if ( uart_data[BSP_UART_COM1].ier & RECEIVE_ENABLE ) { - /* disable interrupts and notify termios */ - uart_data[BSP_UART_COM1].ier &= ~(RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE); - uwrite(BSP_UART_COM1, IER, uart_data[BSP_UART_COM1].ier); - rtems_termios_rxirq_occured(termios_ttyp_com1); - } - } - else { - /* RX data ready */ - assert(off < sizeof(buf)); - buf[off++] = uread(BSP_UART_COM1, RBR); - } - break; - case RECEIVER_ERROR: - /* RX error: eat character */ - uartError(BSP_UART_COM1); - break; - default: - /* Should not happen */ - assert(0); - return; - } - } -} - -void -BSP_uart_termios_isr_com2(void *ignored) -{ - unsigned char buf[40]; - unsigned char val; - int off, ret, vect; - - off = 0; - - for(;;) - { - vect = uread(BSP_UART_COM2, IIR) & 0xf; - - switch(vect) - { - case MODEM_STATUS : - val = uread(BSP_UART_COM2, MSR); - if(uart_data[BSP_UART_COM2].hwFlow) - { - if(val & CTS) - { - /* CTS high */ - termios_stopped_com2 = 0; - if(termios_tx_hold_valid_com2) - { - termios_tx_hold_valid_com2 = 0; - BSP_uart_termios_write_com2(0, &termios_tx_hold_com2, - 1); - } - } - else - { - /* CTS low */ - termios_stopped_com2 = 1; - } - } - break; - case NO_MORE_INTR : - /* No more interrupts */ - if(off != 0) - { - /* Update rx buffer */ - if( driver_input_handler_com2 ) - { - driver_input_handler_com2( termios_ttyp_com2, (char *)buf, off ); - } - else - { - rtems_termios_enqueue_raw_characters(termios_ttyp_com2, (char *)buf, off); - } - } - return; - case TRANSMITTER_HODING_REGISTER_EMPTY : - /* - * TX holding empty: we have to disable these interrupts - * if there is nothing more to send. - */ - - /* If nothing else to send disable interrupts */ - ret = rtems_termios_dequeue_characters(termios_ttyp_com2, 1); - if ( ret == 0 ) { - termios_tx_active_com2 = 0; - uart_data[BSP_UART_COM2].ier &= ~(TRANSMIT_ENABLE); - uwrite(BSP_UART_COM2, IER, uart_data[BSP_UART_COM2].ier); - } - break; - case RECEIVER_DATA_AVAIL : - case CHARACTER_TIMEOUT_INDICATION: - if ( uart_data[BSP_UART_COM2].ioMode == TERMIOS_TASK_DRIVEN ) { - /* ensure interrupts are enabled */ - if ( uart_data[BSP_UART_COM2].ier & RECEIVE_ENABLE ) { - /* disable interrupts and notify termios */ - uart_data[BSP_UART_COM2].ier &= ~(RECEIVE_ENABLE | RECEIVER_LINE_ST_ENABLE); - uwrite(BSP_UART_COM2, IER, uart_data[BSP_UART_COM2].ier); - rtems_termios_rxirq_occured(termios_ttyp_com2); - } - } - else { - /* RX data ready */ - assert(off < sizeof(buf)); - buf[off++] = uread(BSP_UART_COM2, RBR); - } - break; - case RECEIVER_ERROR: - /* RX error: eat character */ - uartError(BSP_UART_COM2); - break; - default: - /* Should not happen */ - assert(0); - return; - } - } -} - -/* ================= GDB support ===================*/ -int BSP_uart_dbgisr_com_regsav[4] RTEMS_UNUSED; - -/* - * Interrupt service routine for COM1 - all, - * it does it check whether ^C is received - * if yes it will flip TF bit before returning - * Note: it should be installed as raw interrupt - * handler - */ - -__asm__ (".p2align 4"); -__asm__ (".text"); -__asm__ (".globl BSP_uart_dbgisr_com1"); -__asm__ ("BSP_uart_dbgisr_com1:"); -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav"); /* Save eax */ -__asm__ (" movl %ebx, BSP_uart_dbgisr_com_regsav + 4"); /* Save ebx */ -__asm__ (" movl %edx, BSP_uart_dbgisr_com_regsav + 8"); /* Save edx */ - -__asm__ (" movl $0, %ebx"); /* Clear flag */ - -/* - * We know that only receive related interrupts - * are available, eat chars - */ -__asm__ ("uart_dbgisr_com1_1:"); -__asm__ (" movw $0x3FD, %dx"); -__asm__ (" inb %dx, %al"); /* Read LSR */ -__asm__ (" andb $1, %al"); -__asm__ (" cmpb $0, %al"); -__asm__ (" je uart_dbgisr_com1_2"); -__asm__ (" movw $0x3F8, %dx"); -__asm__ (" inb %dx, %al"); /* Get input character */ -__asm__ (" cmpb $3, %al"); -__asm__ (" jne uart_dbgisr_com1_1"); - -/* ^C received, set flag */ -__asm__ (" movl $1, %ebx"); -__asm__ (" jmp uart_dbgisr_com1_1"); - -/* All chars read */ -__asm__ ("uart_dbgisr_com1_2:"); - -/* If flag is set we have to tweak TF */ -__asm__ (" cmpl $0, %ebx"); -__asm__ (" je uart_dbgisr_com1_3"); - -/* Flag is set */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %ebx"); /* Restore ebx */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %edx"); /* Restore edx */ - -/* Set TF bit */ -__asm__ (" popl %eax"); /* Pop eip */ -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav + 4"); /* Save it */ -__asm__ (" popl %eax"); /* Pop cs */ -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav + 8"); /* Save it */ -__asm__ (" popl %eax"); /* Pop flags */ -__asm__ (" orl $0x100, %eax"); /* Modify it */ -__asm__ (" pushl %eax"); /* Push it back */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %eax"); /* Put back cs */ -__asm__ (" pushl %eax"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %eax"); /* Put back eip */ -__asm__ (" pushl %eax"); - -/* Acknowledge IRQ */ -__asm__ (" movb $0x20, %al"); -__asm__ (" outb %al, $0x20"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav, %eax"); /* Restore eax */ -__asm__ (" iret"); /* Done */ - -/* Flag is not set */ -__asm__ ("uart_dbgisr_com1_3:"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %ebx"); /* Restore ebx */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %edx"); /* Restore edx */ - -/* Acknowledge irq */ -__asm__ (" movb $0x20, %al"); -__asm__ (" outb %al, $0x20"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav, %eax"); /* Restore eax */ -__asm__ (" iret"); /* Done */ - -/* - * Interrupt service routine for COM2 - all, - * it does it check whether ^C is received - * if yes it will flip TF bit before returning - * Note: it has to be installed as raw interrupt - * handler - */ -__asm__ (".p2align 4"); -__asm__ (".text"); -__asm__ (".globl BSP_uart_dbgisr_com2"); -__asm__ ("BSP_uart_dbgisr_com2:"); -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav"); /* Save eax */ -__asm__ (" movl %ebx, BSP_uart_dbgisr_com_regsav + 4"); /* Save ebx */ -__asm__ (" movl %edx, BSP_uart_dbgisr_com_regsav + 8"); /* Save edx */ - -__asm__ (" movl $0, %ebx"); /* Clear flag */ - -/* - * We know that only receive related interrupts - * are available, eat chars - */ -__asm__ ("uart_dbgisr_com2_1:"); -__asm__ (" movw $0x2FD, %dx"); -__asm__ (" inb %dx, %al"); /* Read LSR */ -__asm__ (" andb $1, %al"); -__asm__ (" cmpb $0, %al"); -__asm__ (" je uart_dbgisr_com2_2"); -__asm__ (" movw $0x2F8, %dx"); -__asm__ (" inb %dx, %al"); /* Get input character */ -__asm__ (" cmpb $3, %al"); -__asm__ (" jne uart_dbgisr_com2_1"); - -/* ^C received, set flag */ -__asm__ (" movl $1, %ebx"); -__asm__ (" jmp uart_dbgisr_com2_1"); - -/* All chars read */ -__asm__ ("uart_dbgisr_com2_2:"); - -/* If flag is set we have to tweak TF */ -__asm__ (" cmpl $0, %ebx"); -__asm__ (" je uart_dbgisr_com2_3"); - -/* Flag is set */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %ebx"); /* Restore ebx */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %edx"); /* Restore edx */ - -/* Set TF bit */ -__asm__ (" popl %eax"); /* Pop eip */ -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav + 4"); /* Save it */ -__asm__ (" popl %eax"); /* Pop cs */ -__asm__ (" movl %eax, BSP_uart_dbgisr_com_regsav + 8"); /* Save it */ -__asm__ (" popl %eax"); /* Pop flags */ -__asm__ (" orl $0x100, %eax"); /* Modify it */ -__asm__ (" pushl %eax"); /* Push it back */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %eax"); /* Put back cs */ -__asm__ (" pushl %eax"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %eax"); /* Put back eip */ -__asm__ (" pushl %eax"); - -/* Acknowledge IRQ */ -__asm__ (" movb $0x20, %al"); -__asm__ (" outb %al, $0x20"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav, %eax"); /* Restore eax */ -__asm__ (" iret"); /* Done */ - -/* Flag is not set */ -__asm__ ("uart_dbgisr_com2_3:"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav+4, %ebx"); /* Restore ebx */ -__asm__ (" movl BSP_uart_dbgisr_com_regsav+8, %edx"); /* Restore edx */ - -/* Acknowledge irq */ -__asm__ (" movb $0x20, %al"); -__asm__ (" outb %al, $0x20"); -__asm__ (" movl BSP_uart_dbgisr_com_regsav, %eax"); /* Restore eax */ -__asm__ (" iret"); /* Done */ |