static int hvc_beat_get_chars(uint32_t vtermno, char *buf, int cnt) { static unsigned char q[sizeof(unsigned long) * 2] __attribute__((aligned(sizeof(unsigned long)))); static int qlen = 0; u64 got; again: if (qlen) { if (qlen > cnt) { memcpy(buf, q, cnt); qlen -= cnt; memmove(q + cnt, q, qlen); return cnt; } else { int r; memcpy(buf, q, qlen); r = qlen; qlen = 0; return r; } } if (beat_get_term_char(vtermno, &got, ((u64 *)q), ((u64 *)q) + 1) == 0) { qlen = got; goto again; } return 0; }
static int udbg_getc_poll_beat(void) { /* The interface is tricky because it may return up to 16 chars. * We save them statically for future calls to udbg_getc(). */ char ch, *buf = (char *)inbuf; int i; long rc; if (inbuflen == 0) { /* get some more chars. */ inbuflen = 0; rc = beat_get_term_char(celleb_vtermno, &inbuflen, inbuf+0, inbuf+1); if (rc != 0) inbuflen = 0; /* otherwise inbuflen is garbage */ } if (inbuflen <= 0 || inbuflen > 16) { /* Catch error case as well as other oddities (corruption) */ inbuflen = 0; return -1; } ch = buf[0]; for (i = 1; i < inbuflen; i++) /* shuffle them down. */ buf[i-1] = buf[i]; inbuflen--; return ch; }