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 | |
---|
17 | |
---|
18 | int putDebugChar(int ch); /* write a single character */ |
---|
19 | int getDebugChar(void); /* read and return a single char */ |
---|
20 | |
---|
21 | /* assign an exception handler */ |
---|
22 | void exceptionHandler(int, void (*handler)(void)); |
---|
23 | |
---|
24 | void BSP_loop(int uart); |
---|
25 | |
---|
26 | /* Current uart used by gdb stub */ |
---|
27 | static int uart_current = 0; |
---|
28 | |
---|
29 | /* |
---|
30 | * Initialize glue code linking i386-stub with the rest of |
---|
31 | * the system |
---|
32 | */ |
---|
33 | void |
---|
34 | i386_stub_glue_init(int uart) |
---|
35 | { |
---|
36 | assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); |
---|
37 | |
---|
38 | uart_current = uart; |
---|
39 | |
---|
40 | BSP_uart_init(uart, 38400, CHR_8_BITS, 0, 0, 0); |
---|
41 | } |
---|
42 | |
---|
43 | void BSP_uart_on(const rtems_raw_irq_connect_data* used) |
---|
44 | { |
---|
45 | BSP_irq_enable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE); |
---|
46 | } |
---|
47 | |
---|
48 | void BSP_uart_off(const rtems_raw_irq_connect_data* used) |
---|
49 | { |
---|
50 | BSP_irq_disable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE); |
---|
51 | } |
---|
52 | |
---|
53 | int BSP_uart_isOn(const rtems_raw_irq_connect_data* used) |
---|
54 | { |
---|
55 | return BSP_irq_enabled_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | /* |
---|
60 | * In order to have a possibility to break into |
---|
61 | * running program, one has to call this function |
---|
62 | */ |
---|
63 | void i386_stub_glue_init_breakin(void) |
---|
64 | { |
---|
65 | rtems_raw_irq_connect_data uart_raw_irq_data; |
---|
66 | |
---|
67 | assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2); |
---|
68 | |
---|
69 | if(uart_current == BSP_UART_COM1) |
---|
70 | { |
---|
71 | uart_raw_irq_data.idtIndex = BSP_UART_COM1_IRQ + BSP_IRQ_VECTOR_BASE; |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | uart_raw_irq_data.idtIndex = BSP_UART_COM2_IRQ + BSP_IRQ_VECTOR_BASE; |
---|
76 | } |
---|
77 | |
---|
78 | if(!i386_get_current_idt_entry(&uart_raw_irq_data)) |
---|
79 | { |
---|
80 | printk("cannot get idt entry\n"); |
---|
81 | rtems_fatal_error_occurred(1); |
---|
82 | } |
---|
83 | |
---|
84 | if(!i386_delete_idt_entry(&uart_raw_irq_data)) |
---|
85 | { |
---|
86 | printk("cannot delete idt entry\n"); |
---|
87 | rtems_fatal_error_occurred(1); |
---|
88 | } |
---|
89 | |
---|
90 | uart_raw_irq_data.on = BSP_uart_on; |
---|
91 | uart_raw_irq_data.off = BSP_uart_off; |
---|
92 | uart_raw_irq_data.isOn= BSP_uart_isOn; |
---|
93 | |
---|
94 | /* Install ISR */ |
---|
95 | if(uart_current == BSP_UART_COM1) |
---|
96 | { |
---|
97 | uart_raw_irq_data.idtIndex = BSP_UART_COM1_IRQ + BSP_IRQ_VECTOR_BASE; |
---|
98 | uart_raw_irq_data.hdl = BSP_uart_dbgisr_com1; |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | uart_raw_irq_data.idtIndex = BSP_UART_COM2_IRQ + BSP_IRQ_VECTOR_BASE; |
---|
103 | uart_raw_irq_data.hdl = BSP_uart_dbgisr_com2; |
---|
104 | } |
---|
105 | |
---|
106 | if (!i386_set_idt_entry (&uart_raw_irq_data)) |
---|
107 | { |
---|
108 | printk("raw exception handler connection failed\n"); |
---|
109 | rtems_fatal_error_occurred(1); |
---|
110 | } |
---|
111 | |
---|
112 | /* Enable interrupts */ |
---|
113 | BSP_uart_intr_ctrl(uart_current, BSP_UART_INTR_CTRL_GDB); |
---|
114 | |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | int |
---|
120 | putDebugChar(int ch) |
---|
121 | { |
---|
122 | assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2); |
---|
123 | |
---|
124 | BSP_uart_polled_write(uart_current, ch); |
---|
125 | |
---|
126 | return 1; |
---|
127 | } |
---|
128 | |
---|
129 | int getDebugChar(void) |
---|
130 | { |
---|
131 | int val; |
---|
132 | |
---|
133 | assert(uart_current == BSP_UART_COM1 || uart_current == BSP_UART_COM2); |
---|
134 | |
---|
135 | val = BSP_uart_polled_read(uart_current); |
---|
136 | |
---|
137 | return val; |
---|
138 | } |
---|
139 | |
---|
140 | static void nop(){} |
---|
141 | static int isOn() {return 1;} |
---|
142 | |
---|
143 | void exceptionHandler(int vector, void (*handler)(void)) |
---|
144 | { |
---|
145 | rtems_raw_irq_connect_data excep_raw_irq_data; |
---|
146 | |
---|
147 | excep_raw_irq_data.idtIndex = vector; |
---|
148 | |
---|
149 | if(!i386_get_current_idt_entry(&excep_raw_irq_data)) |
---|
150 | { |
---|
151 | printk("cannot get idt entry\n"); |
---|
152 | rtems_fatal_error_occurred(1); |
---|
153 | } |
---|
154 | |
---|
155 | if(!i386_delete_idt_entry(&excep_raw_irq_data)) |
---|
156 | { |
---|
157 | printk("cannot delete idt entry\n"); |
---|
158 | rtems_fatal_error_occurred(1); |
---|
159 | } |
---|
160 | |
---|
161 | excep_raw_irq_data.on = nop; |
---|
162 | excep_raw_irq_data.off = nop; |
---|
163 | excep_raw_irq_data.isOn = isOn; |
---|
164 | excep_raw_irq_data.hdl = handler; |
---|
165 | |
---|
166 | if (!i386_set_idt_entry (&excep_raw_irq_data)) { |
---|
167 | printk("raw exception handler connection failed\n"); |
---|
168 | rtems_fatal_error_occurred(1); |
---|
169 | } |
---|
170 | return; |
---|
171 | } |
---|