File indexing completed on 2025-05-11 08:23:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #include <stdlib.h>
0042 #include <limits.h>
0043
0044 #include <bsp.h>
0045 #include <rtems/libio.h>
0046 #include <rtems/console.h>
0047 #include <rtems/termiostypes.h>
0048 #include <libchip/serial.h>
0049 #include <libchip/ns16550.h>
0050 #include <bsp/bspimpl.h>
0051
0052 #include "../../shared/dev/serial/legacy-console.h"
0053
0054
0055
0056
0057 int remote_debug;
0058
0059
0060
0061 void set_debug_traps(void);
0062
0063
0064
0065
0066
0067 int BSPBaseBaud;
0068
0069 static bool gdb_port_probe(int minor)
0070 {
0071
0072 return false;
0073 }
0074
0075 void pc386_parse_gdb_arguments(void)
0076 {
0077 static const char *opt;
0078
0079
0080
0081
0082 opt = bsp_cmdline_arg("--gdb=");
0083 if ( opt ) {
0084 const char *option;
0085 const char *comma;
0086 size_t length;
0087 size_t index;
0088 rtems_device_minor_number minor;
0089 uint32_t baudrate = 115200;
0090 bool halt = false;
0091 console_tbl *port;
0092
0093
0094
0095
0096 length = 0;
0097 while ((opt[length] != ' ') && (opt[length] != '\0')) {
0098 ++length;
0099 if (length > NAME_MAX) {
0100 printk("invalid option (--gdb): too long\n");
0101 return;
0102 }
0103 }
0104
0105
0106
0107
0108 index = 0;
0109 while ((opt[index] != '=') && (index < length)) {
0110 ++index;
0111 }
0112
0113 if (opt[index] != '=') {
0114 printk("invalid option (--gdb): no equals\n");
0115 return;
0116 }
0117
0118 ++index;
0119 option = &opt[index];
0120
0121 while ((opt[index] != ',') && (index < length)) {
0122 ++index;
0123 }
0124
0125 if (opt[index] == ',')
0126 comma = &opt[index];
0127 else
0128 comma = NULL;
0129
0130 length = &opt[index] - option;
0131
0132 port = console_find_console_entry( option, length, &minor );
0133
0134 if ( port == NULL ) {
0135 printk("invalid option (--gdb): port not found\n");
0136 return;
0137 }
0138
0139 if (comma) {
0140 option = comma + 1;
0141 baudrate = strtoul(option, 0, 10);
0142 switch (baudrate) {
0143 case 115200:
0144 case 57600:
0145 case 38400:
0146 case 19200:
0147 case 9600:
0148 case 4800:
0149 port->pDeviceParams = (void*) baudrate;
0150 BSPBaseBaud = baudrate;
0151 break;
0152 default:
0153 printk("invalid option (--gdb): bad baudrate\n");
0154 return;
0155 }
0156 }
0157
0158
0159
0160
0161
0162 port->deviceProbe = gdb_port_probe;
0163 port->pDeviceFns = &ns16550_fns_polled;
0164
0165 opt = bsp_cmdline_arg("--gdb-remote-debug");
0166 if ( opt ) {
0167 remote_debug = 1;
0168 }
0169
0170 opt = bsp_cmdline_arg("--gdb-break");
0171 if ( opt ) {
0172 halt = true;
0173 }
0174
0175 printk("GDB stub: enable %s%s%s\n",
0176 port->sDeviceName,
0177 remote_debug ? ", remote-debug" : "",
0178 halt ? ", halting" : "");
0179
0180 i386_stub_glue_init(minor);
0181 set_debug_traps();
0182 i386_stub_glue_init_breakin();
0183
0184 if ( halt ) {
0185 printk("GDB stub: waiting for remote connection..\n");
0186 breakpoint();
0187 }
0188 }
0189 }