Removed superfluous htons()/htonl() functions (we already have the

standard byte order functions in the kernel).
Small cleanup.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7705 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-05-31 22:49:06 +00:00
parent 78f42e3f33
commit 38e937ca8e

View File

@ -29,35 +29,20 @@ static char safe_mem[512];
/* /*
* utility functions * utility functions
*/ */
static
int
htons(short value)
{
return ((value>>8)&0xff) | ((value&0xff)<<8);
}
static static int
int
htonl(int value)
{
return htons((value>>16)&0xffff) | (htons(value&0xffff)<<16);
}
static
int
parse_nibble(int input) parse_nibble(int input)
{ {
int nibble= 0xff; int nibble = 0xff;
if((input>= '0') && (input<= '9')) { if (input >= '0' && input <= '9')
nibble= input-'0'; nibble = input - '0';
}
if((input>= 'A') && (input<= 'F')) { if (input >= 'A' && input <= 'F')
nibble= 0x0a+(input-'A'); nibble = 0x0a + input - 'A';
}
if((input>= 'a') && (input<= 'f')) { if (input >= 'a' && input <= 'f')
nibble= 0x0a+(input-'a'); nibble = 0x0a + input - 'a';
}
return nibble; return nibble;
} }
@ -68,29 +53,29 @@ parse_nibble(int input)
* GDB protocol ACK & NAK & Reply * GDB protocol ACK & NAK & Reply
* *
*/ */
static
void static void
gdb_ack(void) gdb_ack(void)
{ {
dbg_putch('+'); dbg_putch('+');
} }
static
void static void
gdb_nak(void) gdb_nak(void)
{ {
dbg_putch('-'); dbg_putch('-');
} }
static
void static void
gdb_resend_reply(void) gdb_resend_reply(void)
{ {
dbg_puts(reply); dbg_puts(reply);
} }
static
void static void
gdb_reply(char const *fmt, ...) gdb_reply(char const *fmt, ...)
{ {
int i; int i;
@ -99,68 +84,68 @@ gdb_reply(char const *fmt, ...)
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
reply[0]= '$'; reply[0] = '$';
vsprintf(reply+1, fmt, args); vsprintf(reply + 1, fmt, args);
va_end(args); va_end(args);
len= strlen(reply); len = strlen(reply);
sum= 0; sum = 0;
for(i= 1; i< len; i++) { for (i = 1; i < len; i++) {
sum+= reply[i]; sum += reply[i];
} }
sum%= 256; sum %= 256;
sprintf(reply+len, "#%02x", sum); sprintf(reply + len, "#%02x", sum);
gdb_resend_reply(); gdb_resend_reply();
} }
static
void static void
gdb_regreply(int const *regs, int numregs) gdb_regreply(int const *regs, int numregs)
{ {
int i; int i;
int len; int len;
int sum; int sum;
reply[0]= '$'; reply[0] = '$';
for(i= 0; i< numregs; i++) { for (i = 0; i < numregs; i++) {
sprintf(reply+1+8*i, "%08x", htonl(regs[i])); sprintf(reply+1+8*i, "%08lx", B_HOST_TO_BENDIAN_INT32(regs[i]));
} }
len= strlen(reply); len = strlen(reply);
sum= 0; sum = 0;
for(i= 1; i< len; i++) { for (i = 1; i < len; i++) {
sum+= reply[i]; sum += reply[i];
} }
sum%= 256; sum %= 256;
sprintf(reply+len, "#%02x", sum); sprintf(reply + len, "#%02x", sum);
gdb_resend_reply(); gdb_resend_reply();
} }
static
void static void
gdb_memreply(char const *bytes, int numbytes) gdb_memreply(char const *bytes, int numbytes)
{ {
int i; int i;
int len; int len;
int sum; int sum;
reply[0]= '$'; reply[0] = '$';
for(i= 0; i< numbytes; i++) { for (i = 0; i < numbytes; i++) {
sprintf(reply+1+2*i, "%02x", (unsigned char)bytes[i]); sprintf(reply+1+2*i, "%02x", (uint8)bytes[i]);
} }
len= strlen(reply); len = strlen(reply);
sum= 0; sum = 0;
for(i= 1; i< len; i++) { for (i = 1; i < len; i++) {
sum+= reply[i]; sum += reply[i];
} }
sum%= 256; sum %= 256;
sprintf(reply+len, "#%02x", sum); sprintf(reply + len, "#%02x", sum);
gdb_resend_reply(); gdb_resend_reply();
} }
@ -170,57 +155,51 @@ gdb_memreply(char const *bytes, int numbytes)
/* /*
* checksum verification * checksum verification
*/ */
static
int static int
gdb_verify_checksum(void) gdb_verify_checksum(void)
{ {
int i; int i;
int len; int len;
int sum; int sum;
len= strlen(cmd); len = strlen(cmd);
sum= 0; sum = 0;
for(i= 0; i< len; i++) { for (i = 0; i < len; i++) {
sum+= cmd[i]; sum += cmd[i];
} }
sum%= 256; sum %= 256;
return (sum==checksum)?1:0; return (sum == checksum) ? 1 : 0;
} }
/* /*
* command parsing an dispatching * command parsing an dispatching
*/ */
static
int static int
gdb_parse_command(void) gdb_parse_command(void)
{ {
// int retval; if (!gdb_verify_checksum()) {
if(!gdb_verify_checksum()) {
gdb_nak(); gdb_nak();
return INIT; return INIT;
} else { } else
gdb_ack(); gdb_ack();
}
switch(cmd[0]) {
switch (cmd[0]) {
case 'H': case 'H':
{ /*
/* * Command H (actually Hct) is used to select
* Command H (actually Hct) is used to select * the current thread (-1 meaning all threads)
* the current thread (-1 meaning all threads) * We just fake we recognize the the command
* We just fake we recognize the the command * and send an 'OK' response.
* and send an 'OK' response. */
*/ gdb_reply("OK");
gdb_reply("OK"); break;
} break;
case 'q': case 'q':
{ {
// extern unsigned _start;
extern unsigned __data_start; extern unsigned __data_start;
extern unsigned __bss_start; extern unsigned __bss_start;
@ -242,28 +221,24 @@ gdb_parse_command(void)
* pre-links at 0x80000000. To keep gdb * pre-links at 0x80000000. To keep gdb
* gdb happy we just substract that amount. * gdb happy we just substract that amount.
*/ */
if(strcmp(cmd+1, "Offsets")== 0) { if (strcmp(cmd+1, "Offsets") == 0) {
gdb_reply( gdb_reply("Text=%x;Data=%x;Bss=%x", 0,
"Text=%x;Data=%x;Bss=%x",
0,
((unsigned)(&__data_start))-0x80000000, ((unsigned)(&__data_start))-0x80000000,
((unsigned)(&__bss_start))-0x80000000 ((unsigned)(&__bss_start))-0x80000000);
); } else
} else {
gdb_reply("ENS"); gdb_reply("ENS");
} }
} break; break;
case '?': case '?':
{ /*
/* * command '?' is used for retrieving the signal
* command '?' is used for retrieving the signal * that stopped the program. Fully implemeting
* that stopped the program. Fully implemeting * this command requires help from the debugger,
* this command requires help from the debugger, * by now we just fake a SIGKILL
* by now we just fake a SIGKILL */
*/ gdb_reply("S09"); /* SIGKILL = 9 */
gdb_reply("S09"); /* SIGKILL = 9 */ break;
} break;
case 'g': case 'g':
{ {
@ -286,9 +261,10 @@ gdb_parse_command(void)
* reason (unknown to me) gdb wants the register * reason (unknown to me) gdb wants the register
* dump in *big endian* format. * dump in *big endian* format.
*/ */
cpu= smp_get_current_cpu(); cpu = smp_get_current_cpu();
gdb_regreply(dbg_register_file[cpu], 14); gdb_regreply(dbg_register_file[cpu], 14);
} break; }
break;
case 'm': case 'm':
{ {
@ -301,26 +277,25 @@ gdb_parse_command(void)
* where AAA is the address and LLL is the * where AAA is the address and LLL is the
* number of bytes. * number of bytes.
*/ */
ptr= cmd+1; ptr = cmd+1;
address= 0; address = 0;
len= 0; len = 0;
while(ptr && *ptr && (*ptr!= ',')) { while (ptr && *ptr && (*ptr != ',')) {
address<<= 4; address <<= 4;
address+= parse_nibble(*ptr); address += parse_nibble(*ptr);
ptr+= 1; ptr += 1;
} }
if(*ptr== ',') { if (*ptr == ',')
ptr+= 1;
}
while(ptr && *ptr) {
len<<= 4;
len+= parse_nibble(*ptr);
ptr+= 1; ptr+= 1;
while (ptr && *ptr) {
len <<= 4;
len += parse_nibble(*ptr);
ptr += 1;
} }
if(len> 128) { if (len> 128)
len= 128; len = 128;
}
/* /*
* We cannot directly access the requested memory * We cannot directly access the requested memory
@ -328,31 +303,28 @@ gdb_parse_command(void)
* We copy the memory to a safe buffer using * We copy the memory to a safe buffer using
* the bulletproof user_memcpy(). * the bulletproof user_memcpy().
*/ */
if(user_memcpy(safe_mem, (char*)address, len)< 0) { if (user_memcpy(safe_mem, (char *)address, len) < 0)
gdb_reply("E02"); gdb_reply("E02");
} else { else
gdb_memreply(safe_mem, len); gdb_memreply(safe_mem, len);
} }
} break; break;
case 'k': case 'k':
{ /*
/* * Command 'k' actual semantics is 'kill the damn thing'.
* Command 'k' actual semantics is 'kill the damn thing'. * However gdb sends that command when you disconnect
* However gdb sends that command when you disconnect * from a debug session. I guess that 'kill' for the
* from a debug session. I guess that 'kill' for the * kernel would map to reboot... however that's a
* kernel would map to reboot... however that's a * a very mean thing to do, instead we just quit
* a very mean thing to do, instead we just quit * the gdb state machine and fallback to the regular
* the gdb state machine and fallback to the regular * kernel debugger command prompt.
* kernel debugger command prompt. */
*/ return QUIT;
return QUIT;
} break;
default: default:
{ gdb_reply("E01");
gdb_reply("E01"); break;
} break;
} }
return WAITACK; return WAITACK;
@ -363,15 +335,16 @@ gdb_parse_command(void)
/* /*
* GDB protocol state machine * GDB protocol state machine
*/ */
static
int static int
gdb_init_handler(int input) gdb_init_handler(int input)
{ {
switch(input) { switch (input) {
case '$': case '$':
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
cmd_ptr= 0; cmd_ptr = 0;
return CMDREAD; return CMDREAD;
default: default:
#if 0 #if 0
gdb_nak(); gdb_nak();
@ -387,27 +360,28 @@ gdb_init_handler(int input)
} }
} }
static
int static int
gdb_cmdread_handler(int input) gdb_cmdread_handler(int input)
{ {
switch(input) { switch (input) {
case '#': case '#':
return CKSUM1; return CKSUM1;
default: default:
cmd[cmd_ptr]= input; cmd[cmd_ptr] = input;
cmd_ptr+= 1; cmd_ptr += 1;
return CMDREAD; return CMDREAD;
} }
} }
static
int static int
gdb_cksum1_handler(int input) gdb_cksum1_handler(int input)
{ {
int nibble= parse_nibble(input); int nibble = parse_nibble(input);
if(nibble== 0xff) { if (nibble == 0xff) {
#if 0 #if 0
gdb_nak(); gdb_nak();
return INIT; return INIT;
@ -421,18 +395,18 @@ gdb_cksum1_handler(int input)
#endif #endif
} }
checksum= nibble<< 4; checksum = nibble << 4;
return CKSUM2; return CKSUM2;
} }
static
int static int
gdb_cksum2_handler(int input) gdb_cksum2_handler(int input)
{ {
int nibble= parse_nibble(input); int nibble = parse_nibble(input);
if(nibble== 0xff) { if (nibble == 0xff) {
#if 0 #if 0
gdb_nak(); gdb_nak();
return INIT; return INIT;
@ -446,21 +420,22 @@ gdb_cksum2_handler(int input)
#endif #endif
} }
checksum+= nibble; checksum += nibble;
return gdb_parse_command(); return gdb_parse_command();
} }
static
int static int
gdb_waitack_handler(int input) gdb_waitack_handler(int input)
{ {
switch(input) { switch (input) {
case '+': case '+':
return INIT; return INIT;
case '-': case '-':
gdb_resend_reply(); gdb_resend_reply();
return WAITACK; return WAITACK;
default: default:
/* /*
* looks like gdb and us are out of synch, * looks like gdb and us are out of synch,
@ -471,8 +446,8 @@ gdb_waitack_handler(int input)
} }
} }
static
int static int
gdb_quit_handler(int input) gdb_quit_handler(int input)
{ {
(void)(input); (void)(input);
@ -483,8 +458,8 @@ gdb_quit_handler(int input)
return QUIT; return QUIT;
} }
static int (*dispatch_table[GDBSTATES])(int)=
{ static int (*dispatch_table[GDBSTATES])(int) = {
&gdb_init_handler, &gdb_init_handler,
&gdb_cmdread_handler, &gdb_cmdread_handler,
&gdb_cksum1_handler, &gdb_cksum1_handler,
@ -493,35 +468,32 @@ static int (*dispatch_table[GDBSTATES])(int)=
&gdb_quit_handler &gdb_quit_handler
}; };
static
int static int
gdb_state_dispatch(int curr, int input) gdb_state_dispatch(int curr, int input)
{ {
if(curr< INIT) { if (curr < INIT || curr >= GDBSTATES)
return QUIT; return QUIT;
}
if(curr>= GDBSTATES) {
return QUIT;
}
return dispatch_table[curr](input); return dispatch_table[curr](input);
} }
static
int static int
gdb_state_machine(void) gdb_state_machine(void)
{ {
int state= INIT; int state = INIT;
int c; int c;
while(state!= QUIT) { while (state != QUIT) {
c= arch_dbg_con_read(); c = arch_dbg_con_read();
state= gdb_state_dispatch(state, c); state = gdb_state_dispatch(state, c);
} }
return 0; return 0;
} }
int int
cmd_gdb(int argc, char **argv) cmd_gdb(int argc, char **argv)
{ {