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;
@ -115,8 +100,8 @@ gdb_reply(char const *fmt, ...)
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;
@ -125,7 +110,7 @@ gdb_regreply(int const *regs, int numregs)
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);
@ -140,8 +125,8 @@ gdb_regreply(int const *regs, int numregs)
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;
@ -150,7 +135,7 @@ gdb_memreply(char const *bytes, int numbytes)
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);
@ -170,8 +155,8 @@ 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;
@ -192,23 +177,18 @@ gdb_verify_checksum(void)
/* /*
* 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)
@ -216,11 +196,10 @@ gdb_parse_command(void)
* 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;
@ -243,19 +222,15 @@ gdb_parse_command(void)
* 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
@ -263,7 +238,7 @@ gdb_parse_command(void)
* 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':
{ {
@ -288,7 +263,8 @@ gdb_parse_command(void)
*/ */
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':
{ {
@ -309,18 +285,17 @@ gdb_parse_command(void)
address += parse_nibble(*ptr); address += parse_nibble(*ptr);
ptr += 1; ptr += 1;
} }
if(*ptr== ',') { if (*ptr == ',')
ptr+= 1; ptr+= 1;
}
while (ptr && *ptr) { while (ptr && *ptr) {
len <<= 4; len <<= 4;
len += parse_nibble(*ptr); len += parse_nibble(*ptr);
ptr += 1; 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,15 +303,14 @@ 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
@ -347,12 +321,10 @@ gdb_parse_command(void)
* 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,8 +335,8 @@ 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) {
@ -372,6 +344,7 @@ gdb_init_handler(int input)
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,13 +360,14 @@ 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;
@ -401,8 +375,8 @@ gdb_cmdread_handler(int input)
} }
} }
static
int static int
gdb_cksum1_handler(int input) gdb_cksum1_handler(int input)
{ {
int nibble = parse_nibble(input); int nibble = parse_nibble(input);
@ -426,8 +400,8 @@ gdb_cksum1_handler(int input)
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);
@ -451,8 +425,8 @@ gdb_cksum2_handler(int input)
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) {
@ -461,6 +435,7 @@ gdb_waitack_handler(int input)
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,22 +468,18 @@ 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;
@ -522,6 +493,7 @@ gdb_state_machine(void)
return 0; return 0;
} }
int int
cmd_gdb(int argc, char **argv) cmd_gdb(int argc, char **argv)
{ {