From a3b6a64fda80861281904bee674290e1108c3acb Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 27 Jun 2005 01:24:42 +0000 Subject: [PATCH] fixes; prints out command interpretation; sensible selectors --- hostside/.cvsignore | 1 + hostside/Makefile | 7 ++++-- hostside/client.c | 6 ++--- hostside/commands.c | 28 ++++++++++++++---------- hostside/hostside.h | 5 +++-- hostside/output.c | 47 +++++++++++++++++++++++++++------------- hostside/parseutils.c | 11 +++++----- hostside/selectors.h.gen | 9 ++++++++ 8 files changed, 76 insertions(+), 38 deletions(-) create mode 100755 hostside/selectors.h.gen diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 9f85dda..e285fdd 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -7,3 +7,4 @@ layoutinfo.h proto-expanded auproto-* gui-plan-bot +selectors.h diff --git a/hostside/Makefile b/hostside/Makefile index c097ed4..8a31acf 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -32,12 +32,15 @@ auproto-%: parse-proto-spec proto-expanded skelproto-% layoutinfo.h: ../layout/ours.layout-data.c Makefile sed -e '/^#include/,$$d' $< $o -%.c: layoutinfo.h +selectors.h: selectors.h.gen + ./$< $o + +%.c: layoutinfo.h selectors.h safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o $(LINK) clean: - rm -f *.o *.d $(TARGETS) + rm -f *.o *.d $(TARGETS) selectors.h include $(wildcard *.d) diff --git a/hostside/client.c b/hostside/client.c index e3625ba..989f782 100644 --- a/hostside/client.c +++ b/hostside/client.c @@ -81,13 +81,13 @@ static void *client_exception(oop_source *evts, int fd, } static void new_client(int fd, OutBufferError error, - char *desc, const char *default_selectors) { + char *desc, Selector default_selectors) { Client *cl; int r; cl= mmalloc(sizeof(*cl)); - cl->selectors= mstrdup(default_selectors); + cl->sel= default_selectors; cl->ch.desc= desc; cl->ch.fd= fd; cl->ch.error= error; @@ -113,5 +113,5 @@ static void stdin_error(OutBufferChain *ch, const char *e1, const char *e2) { } void stdin_client(void) { - new_client(0, stdin_error, (char*)"stdin", "pP"); + new_client(0, stdin_error, (char*)"stdin", sel_picio|sel_picioh); } diff --git a/hostside/commands.c b/hostside/commands.c index c2e5d24..b14ed03 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -162,20 +162,26 @@ static void cmd_pic(ParseState *ps, const CmdInfo *ci) { const PicInsnInfo *pii; PicInsn pi; long arg; + + if (ps->remain && ps->remain[0]=='=') { + ps->remain++; + pi.l= sizeof(pi.d); + if (!ps_needhextoend(ps, pi.d, &pi.l)) return; + } else { + pii= some_needword_lookup(ps,pic_command_infos,"pic command"); + if (!pii) return; - pii= some_needword_lookup(ps,pic_command_infos,"pic command"); - if (!pii) return; - - if (pii->argbits) { - if (!ps_neednumber(ps, &arg, 0, (1L << pii->argbits) - 1, - "pic object number")) + if (pii->argbits) { + if (!ps_neednumber(ps, &arg, 0, (1L << pii->argbits) - 1, + "pic object number")) + return; + } else { + arg= 0; + } + if (!ps_neednoargs(ps)) return; - } else { - arg= 0; + enco_pic_anyinsn(&pi, pii, arg); } - if (!ps_neednoargs(ps)) - return; - enco_pic_anyinsn(&pi, pii, arg); serial_transmit(&pi); } diff --git a/hostside/hostside.h b/hostside/hostside.h index 3216edc..db981f5 100644 --- a/hostside/hostside.h +++ b/hostside/hostside.h @@ -41,7 +41,8 @@ void owrite(OutBufferChain *ch, const char *data, int l); /*---------- from output.c ----------*/ -typedef char Selector; +typedef unsigned long Selector; +#include "selectors.h" void oovprintf(Selector sel, const char *fmt, va_list al) __attribute__((format(printf,2,0))); @@ -75,7 +76,7 @@ extern struct ClientList clients; struct Client { OutBufferChain ch; Client *back, *next; - char *selectors; + Selector sel; oop_read *rd; }; diff --git a/hostside/output.c b/hostside/output.c index e6d8bd3..b432222 100644 --- a/hostside/output.c +++ b/hostside/output.c @@ -8,16 +8,16 @@ #include "hostside.h" #include "auproto-pic.h" -#define FOR_OOS(s) do{ \ - Client *cl, *next_cl; \ - for (cl= clients.head; \ - cl; \ - cl= next_cl) { \ - OutBufferChain *ch= &cl->ch; \ - next_cl= cl->next; \ - if (!strchr(cl->selectors, sel)) continue; \ - s; \ - } \ +#define FOR_OOS(s) do{ \ + Client *cl, *next_cl; \ + for (cl= clients.head; \ + cl; \ + cl= next_cl) { \ + OutBufferChain *ch= &cl->ch; \ + next_cl= cl->next; \ + if (!(sel & cl->sel)) continue; \ + s; \ + } \ }while(0) void oovprintf(Selector sel, const char *fmt, va_list al) { @@ -43,11 +43,28 @@ void output_hex(Selector sel, const char *word, void serial_transmit(const PicInsn *pi) { const PicInsnInfo *pii; - pii= lookup_byopcode(pi->d[0], pic_command_infos); - if (!pii) { - ooprintf('p', "pic-out unknown\n"); - } else { + unsigned val; + + pii= pi->l > 0 ? lookup_byopcode(pi->d[0], pic_command_infos) : 0; + + if (pii) { + val= pi->d[0]; + if (pii->argbits <= 6) { + if (pi->l != 1) pii= 0; + } else { + if (pi->l == 2) { val <<= 8; val |= pi->d[1]; } + else pii= 0; + } } - output_hex('P', "pic-out-h", pi->d, pi->l); + + if (!pii) + ooprintf(sel_picio, "picio out unknown\n"); + else if (!pii->argbits) + ooprintf(sel_picio, "picio out %s\n", pii->name); + else + ooprintf(sel_picio, "picio out %s %u\n", pii->name, + val & ((1u << pii->argbits) - 1)); + + output_hex(sel_picioh, "picioh out", pi->d, pi->l); serial_transmit_now(pi->d, pi->l); } diff --git a/hostside/parseutils.c b/hostside/parseutils.c index 3c23454..99e1385 100644 --- a/hostside/parseutils.c +++ b/hostside/parseutils.c @@ -60,16 +60,17 @@ int ps_neednoargs(ParseState *ps) { return 1; } -int ps_needhextoend(ParseState *ps, Byte *d, int *remain_io) { - Byte *d_end; +int ps_needhextoend(ParseState *ps, Byte *d, int *len_io) { + Byte *d_begin, *d_end; char buf[3], *ep; - d_end= d + *remain_io; + d_begin= d; + d_end= d + *len_io; buf[2]= 0; if (!ps->remain) { badcmd(ps,"need hex data block"); return 0; } for (;;) { - if (!ps_word(ps)) return 0; + if (!ps_word(ps)) break; while (ps->lthisword > 0) { if (ps->lthisword & 1) { badcmd(ps,"hex data block with odd number of digits in part"); @@ -85,7 +86,7 @@ int ps_needhextoend(ParseState *ps, Byte *d, int *remain_io) { } } - *remain_io= d_end - d; + *len_io= d - d_begin; return 1; } diff --git a/hostside/selectors.h.gen b/hostside/selectors.h.gen new file mode 100755 index 0000000..ec5dbb7 --- /dev/null +++ b/hostside/selectors.h.gen @@ -0,0 +1,9 @@ +#!/usr/bin/perl +$bit= 1; +foreach $f (qw( + picio + picioh + )) { + printf "#define sel_%-10s 0x%08lxLU\n", $f, $bit; + $bit <<= 1; +} -- 2.30.2