static bool can_read_data(struct io *io, void *user_data) { struct bt_att *att = user_data; uint8_t opcode; uint8_t *pdu; ssize_t bytes_read; bytes_read = read(att->fd, att->buf, att->mtu); if (bytes_read < 0) return false; util_hexdump('>', att->buf, bytes_read, att->debug_callback, att->debug_data); if (bytes_read < ATT_MIN_PDU_LEN) return true; pdu = att->buf; opcode = pdu[0]; /* Act on the received PDU based on the opcode type */ switch (get_op_type(opcode)) { case ATT_OP_TYPE_RSP: util_debug(att->debug_callback, att->debug_data, "ATT response received: 0x%02x", opcode); handle_rsp(att, opcode, pdu + 1, bytes_read - 1); break; case ATT_OP_TYPE_CONF: util_debug(att->debug_callback, att->debug_data, "ATT opcode cannot be handled: 0x%02x", opcode); break; default: /* For all other opcodes notify the upper layer of the PDU and * let them act on it. */ util_debug(att->debug_callback, att->debug_data, "ATT PDU received: 0x%02x", opcode); handle_notify(att, opcode, pdu + 1, bytes_read - 1); break; } return true; }
static int main_2 ( int argc, char * argv[] ) { try { // This application does not output large number of text messages, // and, if logging is turned off, the user should see the log messages straight away. // Therefore, turn off buffering on stdout and stderr. Afterwards, there is no need // to call fflush( stdout/stderr ) any more. if ( 0 != setvbuf( stdout, NULL, _IONBF, 0 ) ) throw std::runtime_error( format_errno_msg( errno, "Cannot turn off buffering on stdout: " ) ); if ( 0 != setvbuf( stderr, NULL, _IONBF, 0 ) ) throw std::runtime_error( format_errno_msg( errno, "Cannot turn off buffering on stderr: " ) ); bsdl_init(); cable_setup(); if ( parse_args( argc, argv ) ) { config_set_trace( trace_jtag_bit_data ); char * server_port_first_err_char; const long int gdb_rsp_server_port = strtol( port, &server_port_first_err_char, 10 ); if ( *server_port_first_err_char ) { throw std::runtime_error( format_msg( "Failed to parse GDB RSP server port from the given parameter \"%s\".", port ) ); // This alternative code issues a warning and takes a default port number: // printf( "Failed to parse GDB RSP server port \'%s\', using default \'%s\'.\n", port, default_port ); // gdb_rsp_server_port = strtol( default_port, &server_port_first_err_char, 10 ); // if ( *server_port_first_err_char ) // throw std::runtime_error( "Error retrieving the TCP port for the GDB RSP server." ); } cable_init(); // Initialize a new connection to the or1k board, and make sure we are really connected. configure_chain(); #ifdef ENABLE_JSP long int jspserverport; jspserverport = strtol(jspport,&s,10); if(*s) { printf("Failed to get JSP server port \'%s\', using default \'%s\'.\n", jspport, default_jspport); serverPort = strtol(default_jspport,&s,10); if(*s) { printf("Failed to get default JSP port, exiting.\n"); return -1; } } jsp_init(jspserverport); jsp_server_start(); #endif printf("The GDB to JTAG bridge is up and running.\n"); // If you update the signal list, please update the help text too. install_signal_handler( SIGINT , exit_signal_handler ); install_signal_handler( SIGHUP , exit_signal_handler ); install_signal_handler( SIGPIPE, ignore_signal_handler ); // Otherwise, writing to a socket may kill us with a SIGPIPE signal. handle_rsp( gdb_rsp_server_port, listen_on_all_addrs ? false : true, trace_rsp ? true : false, trace_jtag_bit_data ? true : false, &s_exit_request ); if ( s_exit_request ) { printf( "Quitting after receiving signal number %d.\n", s_received_signal_number ); } cable_close(); } bsdl_terminate(); return 0; } catch ( ... ) { bsdl_terminate(); throw; } }
static bool can_read_data(struct io *io, void *user_data) { struct bt_att *att = user_data; uint8_t opcode; uint8_t *pdu; ssize_t bytes_read; bytes_read = read(att->fd, att->buf, att->mtu); if (bytes_read < 0) return false; util_hexdump('>', att->buf, bytes_read, att->debug_callback, att->debug_data); if (bytes_read < ATT_MIN_PDU_LEN) return true; pdu = att->buf; opcode = pdu[0]; bt_att_ref(att); /* Act on the received PDU based on the opcode type */ switch (get_op_type(opcode)) { case ATT_OP_TYPE_RSP: util_debug(att->debug_callback, att->debug_data, "ATT response received: 0x%02x", opcode); handle_rsp(att, opcode, pdu + 1, bytes_read - 1); break; case ATT_OP_TYPE_CONF: util_debug(att->debug_callback, att->debug_data, "ATT confirmation received: 0x%02x", opcode); handle_conf(att, pdu + 1, bytes_read - 1); break; case ATT_OP_TYPE_REQ: /* * If a request is currently pending, then the sequential * protocol was violated. Disconnect the bearer, which will * promptly notify the upper layer via disconnect handlers. */ if (att->in_req) { util_debug(att->debug_callback, att->debug_data, "Received request while another is " "pending: 0x%02x", opcode); io_shutdown(att->io); bt_att_unref(att); return false; } att->in_req = true; /* Fall through to the next case */ case ATT_OP_TYPE_CMD: case ATT_OP_TYPE_NOT: case ATT_OP_TYPE_UNKNOWN: case ATT_OP_TYPE_IND: default: /* For all other opcodes notify the upper layer of the PDU and * let them act on it. */ util_debug(att->debug_callback, att->debug_data, "ATT PDU received: 0x%02x", opcode); handle_notify(att, opcode, pdu + 1, bytes_read - 1); break; } bt_att_unref(att); return true; }
uint32_t run_soc(soc_t* soc) { cpu_t *cpu = soc->cpu[0]; if(config.gdb_debug){ LOG(LOG_DEBUG, "last pc is %x\n", cpu->run_info.last_pc); if(cpu->run_info.halting == MAYBE){ /* The break operation code is set by debugger. So the last operation code executed should be a break trap set by the debugger. That means we should re-execute the operation code in that address. Restore last PC value to the PC can do such thing.*/ if(is_sw_breakpoint(soc->stub, cpu->run_info.last_pc)){ cpu->run_info.halting = TRUE; cpu->set_raw_pc(cpu->run_info.last_pc, cpu); } // The break operation code is directly wrote in the program else{ cpu->run_info.halting = FALSE; } } if(soc->stub->status == RSP_STEP){ cpu->run_info.halting = TRUE; } /* cpu halting for debug */ while(cpu->run_info.halting){ handle_rsp(soc->stub, cpu); } } /* store last pc */ cpu->run_info.last_pc = cpu->get_raw_pc(cpu); /* basic steps to run a single operation code */ uint32_t opcode = cpu->fetch32(cpu); ins_t ins_info = cpu->decode(cpu, &opcode); cpu->excute(cpu, ins_info); add_cycle(cpu); check_timer(cpu); /* check peripheral input every 100 */ pmp_parsed_pkt_t pmp_pkt; int result; if(config.client && reach_check_point(cpu)){ core_connect_t *peri_connect = armue_get_peri_connect(cpu); bool_t has_input = pmp_check_input(peri_connect); if(has_input){ // start input parsing loop pmp_parse_loop(peri_connect){ result = pmp_parse_input(peri_connect, &pmp_pkt); if(result >= 0){ dispatch_peri_event(&pmp_pkt); } } peri_connect->recv_buf[peri_connect->recv_len] = '\0'; LOG(LOG_INFO, "Peripheral packet type[%d] received: %s\n", pmp_pkt.pkt_kind, peri_connect->recv_buf); } updata_check_point(cpu, 10); }