source: rtems/c/src/lib/libbsp/i386/shared/comm/i386-stub-glue.c @ f05b2ac

4.104.114.84.9
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 21, 2004 at 4:01:48 PM

Remove duplicate white lines.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * This software is Copyright (C) 1998 by T.sqware - all rights limited
3 * It is provided in to the public domain "as is", can be freely modified
4 * as far as this copyight notice is kept unchanged, but does not imply
5 * an endorsement by T.sqware of the product in which it is included.
6 *
7 *  $Id$
8 */
9
10#include <rtems/system.h>
11#include <rtems/score/cpu.h>
12#include <bsp.h>
13#include <irq.h>
14#include <uart.h>
15#include <assert.h>
16
17int  putDebugChar(int ch);     /* write a single character      */
18int  getDebugChar(void);       /* read and return a single char */
19
20/* assign an exception handler */
21void exceptionHandler(int, void (*handler)(void));
22
23void BSP_loop(int uart);
24
25/* Current uart used by gdb stub */
26static int uart_current = 0;
27
28/*
29 * Initialize glue code linking i386-stub with the rest of
30 * the system
31 */
32void
33i386_stub_glue_init(int uart)
34{
35  assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
36
37  uart_current = uart;
38
39  BSP_uart_init(uart, 38400, CHR_8_BITS, 0, 0, 0);
40}
41
42void BSP_uart_on(const rtems_raw_irq_connect_data* used)
43{
44  BSP_irq_enable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE);
45}
46
47void BSP_uart_off(const rtems_raw_irq_connect_data* used)
48{
49  BSP_irq_disable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE);
50}
51
52int BSP_uart_isOn(const rtems_raw_irq_connect_data* used)
53{
54  return BSP_irq_enabled_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE);
55}
56
57/*
58 * In order to have a possibility to break into
59 * running program, one has to call this function
60 */
61void i386_stub_glue_init_breakin(void)
62{
63  rtems_raw_irq_connect_data uart_raw_irq_data;
64
65  assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2);
66
67  if(uart_current == BSP_UART_COM1)
68    {
69      uart_raw_irq_data.idtIndex = BSP_UART_COM1_IRQ + BSP_IRQ_VECTOR_BASE;
70    }
71  else
72    {
73      uart_raw_irq_data.idtIndex = BSP_UART_COM2_IRQ + BSP_IRQ_VECTOR_BASE;
74    }
75
76  if(!i386_get_current_idt_entry(&uart_raw_irq_data))
77    {
78      printk("cannot get idt entry\n");
79      rtems_fatal_error_occurred(1);
80    }
81
82  if(!i386_delete_idt_entry(&uart_raw_irq_data))
83    {
84      printk("cannot delete idt entry\n");
85      rtems_fatal_error_occurred(1);
86    }
87
88  uart_raw_irq_data.on  = BSP_uart_on;
89  uart_raw_irq_data.off = BSP_uart_off;
90  uart_raw_irq_data.isOn= BSP_uart_isOn;
91
92  /* Install ISR  */
93  if(uart_current == BSP_UART_COM1)
94    {
95      uart_raw_irq_data.idtIndex = BSP_UART_COM1_IRQ + BSP_IRQ_VECTOR_BASE;
96      uart_raw_irq_data.hdl = BSP_uart_dbgisr_com1;
97    }
98  else
99    {
100      uart_raw_irq_data.idtIndex = BSP_UART_COM2_IRQ + BSP_IRQ_VECTOR_BASE;
101      uart_raw_irq_data.hdl = BSP_uart_dbgisr_com2;
102    }
103
104  if (!i386_set_idt_entry (&uart_raw_irq_data))
105    {
106      printk("raw exception handler connection failed\n");
107      rtems_fatal_error_occurred(1);
108    }
109
110  /* Enable interrupts */
111  BSP_uart_intr_ctrl(uart_current, BSP_UART_INTR_CTRL_GDB);
112
113  return;
114}
115
116int
117putDebugChar(int ch)
118{
119  assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2);
120
121  BSP_uart_polled_write(uart_current, ch);
122
123  return 1;
124}
125
126int getDebugChar(void)
127{
128  int val;
129
130  assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2);
131
132  val = BSP_uart_polled_read(uart_current);
133
134  return val;
135}
136
137static void nop(){}
138static int isOn() {return 1;}
139
140void exceptionHandler(int vector, void (*handler)(void))
141{
142  rtems_raw_irq_connect_data excep_raw_irq_data;
143
144  excep_raw_irq_data.idtIndex = vector;
145
146  if(!i386_get_current_idt_entry(&excep_raw_irq_data))
147    {
148      printk("cannot get idt entry\n");
149      rtems_fatal_error_occurred(1);
150    }
151
152  if(!i386_delete_idt_entry(&excep_raw_irq_data))
153    {
154      printk("cannot delete idt entry\n");
155      rtems_fatal_error_occurred(1);
156    }
157
158  excep_raw_irq_data.on = nop;
159  excep_raw_irq_data.off = nop;
160  excep_raw_irq_data.isOn = isOn;
161  excep_raw_irq_data.hdl = handler;
162
163  if (!i386_set_idt_entry (&excep_raw_irq_data)) {
164      printk("raw exception handler connection failed\n");
165      rtems_fatal_error_occurred(1);
166    }
167  return;
168}
Note: See TracBrowser for help on using the repository browser.