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
*/
static
int
htons(short value)
{
return ((value>>8)&0xff) | ((value&0xff)<<8);
}
static
int
htonl(int value)
{
return htons((value>>16)&0xffff) | (htons(value&0xffff)<<16);
}
static
int
static int
parse_nibble(int input)
{
int nibble = 0xff;
if((input>= '0') && (input<= '9')) {
if (input >= '0' && input <= '9')
nibble = input - '0';
}
if((input>= 'A') && (input<= 'F')) {
nibble= 0x0a+(input-'A');
}
if((input>= 'a') && (input<= 'f')) {
nibble= 0x0a+(input-'a');
}
if (input >= 'A' && input <= 'F')
nibble = 0x0a + input - 'A';
if (input >= 'a' && input <= 'f')
nibble = 0x0a + input - 'a';
return nibble;
}
@ -68,29 +53,29 @@ parse_nibble(int input)
* GDB protocol ACK & NAK & Reply
*
*/
static
void
static void
gdb_ack(void)
{
dbg_putch('+');
}
static
void
static void
gdb_nak(void)
{
dbg_putch('-');
}
static
void
static void
gdb_resend_reply(void)
{
dbg_puts(reply);
}
static
void
static void
gdb_reply(char const *fmt, ...)
{
int i;
@ -115,8 +100,8 @@ gdb_reply(char const *fmt, ...)
gdb_resend_reply();
}
static
void
static void
gdb_regreply(int const *regs, int numregs)
{
int i;
@ -125,7 +110,7 @@ gdb_regreply(int const *regs, int numregs)
reply[0] = '$';
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);
@ -140,8 +125,8 @@ gdb_regreply(int const *regs, int numregs)
gdb_resend_reply();
}
static
void
static void
gdb_memreply(char const *bytes, int numbytes)
{
int i;
@ -150,7 +135,7 @@ gdb_memreply(char const *bytes, int numbytes)
reply[0] = '$';
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);
@ -170,8 +155,8 @@ gdb_memreply(char const *bytes, int numbytes)
/*
* checksum verification
*/
static
int
static int
gdb_verify_checksum(void)
{
int i;
@ -192,23 +177,18 @@ gdb_verify_checksum(void)
/*
* command parsing an dispatching
*/
static
int
static int
gdb_parse_command(void)
{
// int retval;
if (!gdb_verify_checksum()) {
gdb_nak();
return INIT;
} else {
} else
gdb_ack();
}
switch (cmd[0]) {
case 'H':
{
/*
* Command H (actually Hct) is used to select
* the current thread (-1 meaning all threads)
@ -216,11 +196,10 @@ gdb_parse_command(void)
* and send an 'OK' response.
*/
gdb_reply("OK");
} break;
break;
case 'q':
{
// extern unsigned _start;
extern unsigned __data_start;
extern unsigned __bss_start;
@ -243,19 +222,15 @@ gdb_parse_command(void)
* gdb happy we just substract that amount.
*/
if (strcmp(cmd+1, "Offsets") == 0) {
gdb_reply(
"Text=%x;Data=%x;Bss=%x",
0,
gdb_reply("Text=%x;Data=%x;Bss=%x", 0,
((unsigned)(&__data_start))-0x80000000,
((unsigned)(&__bss_start))-0x80000000
);
} else {
((unsigned)(&__bss_start))-0x80000000);
} else
gdb_reply("ENS");
}
} break;
break;
case '?':
{
/*
* command '?' is used for retrieving the signal
* that stopped the program. Fully implemeting
@ -263,7 +238,7 @@ gdb_parse_command(void)
* by now we just fake a SIGKILL
*/
gdb_reply("S09"); /* SIGKILL = 9 */
} break;
break;
case 'g':
{
@ -288,7 +263,8 @@ gdb_parse_command(void)
*/
cpu = smp_get_current_cpu();
gdb_regreply(dbg_register_file[cpu], 14);
} break;
}
break;
case 'm':
{
@ -309,18 +285,17 @@ gdb_parse_command(void)
address += parse_nibble(*ptr);
ptr += 1;
}
if(*ptr== ',') {
if (*ptr == ',')
ptr+= 1;
}
while (ptr && *ptr) {
len <<= 4;
len += parse_nibble(*ptr);
ptr += 1;
}
if(len> 128) {
if (len> 128)
len = 128;
}
/*
* We cannot directly access the requested memory
@ -328,15 +303,14 @@ gdb_parse_command(void)
* We copy the memory to a safe buffer using
* 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");
} else {
else
gdb_memreply(safe_mem, len);
}
} break;
break;
case 'k':
{
/*
* Command 'k' actual semantics is 'kill the damn thing'.
* However gdb sends that command when you disconnect
@ -347,12 +321,10 @@ gdb_parse_command(void)
* kernel debugger command prompt.
*/
return QUIT;
} break;
default:
{
gdb_reply("E01");
} break;
break;
}
return WAITACK;
@ -363,8 +335,8 @@ gdb_parse_command(void)
/*
* GDB protocol state machine
*/
static
int
static int
gdb_init_handler(int input)
{
switch (input) {
@ -372,6 +344,7 @@ gdb_init_handler(int input)
memset(cmd, 0, sizeof(cmd));
cmd_ptr = 0;
return CMDREAD;
default:
#if 0
gdb_nak();
@ -387,13 +360,14 @@ gdb_init_handler(int input)
}
}
static
int
static int
gdb_cmdread_handler(int input)
{
switch (input) {
case '#':
return CKSUM1;
default:
cmd[cmd_ptr] = input;
cmd_ptr += 1;
@ -401,8 +375,8 @@ gdb_cmdread_handler(int input)
}
}
static
int
static int
gdb_cksum1_handler(int input)
{
int nibble = parse_nibble(input);
@ -426,8 +400,8 @@ gdb_cksum1_handler(int input)
return CKSUM2;
}
static
int
static int
gdb_cksum2_handler(int input)
{
int nibble = parse_nibble(input);
@ -451,8 +425,8 @@ gdb_cksum2_handler(int input)
return gdb_parse_command();
}
static
int
static int
gdb_waitack_handler(int input)
{
switch (input) {
@ -461,6 +435,7 @@ gdb_waitack_handler(int input)
case '-':
gdb_resend_reply();
return WAITACK;
default:
/*
* 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)
{
(void)(input);
@ -483,8 +458,8 @@ gdb_quit_handler(int input)
return QUIT;
}
static int (*dispatch_table[GDBSTATES])(int)=
{
static int (*dispatch_table[GDBSTATES])(int) = {
&gdb_init_handler,
&gdb_cmdread_handler,
&gdb_cksum1_handler,
@ -493,22 +468,18 @@ static int (*dispatch_table[GDBSTATES])(int)=
&gdb_quit_handler
};
static
int
static int
gdb_state_dispatch(int curr, int input)
{
if(curr< INIT) {
if (curr < INIT || curr >= GDBSTATES)
return QUIT;
}
if(curr>= GDBSTATES) {
return QUIT;
}
return dispatch_table[curr](input);
}
static
int
static int
gdb_state_machine(void)
{
int state = INIT;
@ -522,6 +493,7 @@ gdb_state_machine(void)
return 0;
}
int
cmd_gdb(int argc, char **argv)
{