All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin O'Connor <kevin@koconnor.net>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: seabios@seabios.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [SeaBIOS] [RFC PATCH 2/2] serial console, input
Date: Fri, 1 Jul 2016 14:07:41 -0400	[thread overview]
Message-ID: <20160701180741.GA24801@morn.lan> (raw)
In-Reply-To: <20160701170739.GB11200@morn.lan>

On Fri, Jul 01, 2016 at 01:07:39PM -0400, Kevin O'Connor wrote:
> If I understand correctly, most keys are sent on the serial port as
> single bytes, but there are a few keys that are sent as multi-byte
> sequences.  There's a lot of complexity to implement buffering for
> that unusual case.  I wonder if the buffer could be avoided - I played
> with it a little and came up with the below (totally untested).  I'm
> not sure if it's an improvement.

The version below might be slightly easier to understand (still
totally untested).

-Kevin


u8 multibyte_read_count VARLOW;
u8 multibyte_read_pos VARLOW;

void
sercon_check_event(void)
{
    u16 addr = GET_LOW(sercon_port);
    ...

    // read and process data
    int readdata = 0;
    while (inb(addr + SEROFF_LSR) & 0x01) {
        u8 byte = inb(addr + SEROFF_DATA);
        readdata = 1;
        int ret = sercon_check_multibyte(byte);
        if (ret)
            // byte part of multi-byte sequence
            continue;
        if (byte == 0x1b) {
            // Start multi-byte sequence check
            SET_LOW(multibyte_read_count, 1);
            continue;
        }
        // Send normal key
        sercon_sendkey(GET_LOW(termchr[chr].scancode), GET_LOW(termchr[chr].flags));
    }

    if (!readdata && GET_LOW(multibyte_read_count))
        // Too long to read multi-byte sequence - must flush
        dump_multibyte_sequence();
}

static int
sercon_check_multibyte(u8 byte)
{
    int mb_count = GET_LOW(multibyte_read_count);
    if (!mb_count)
        // Not in a multi-byte sequence
        return 0;
    int mb_pos = GET_LOW(multibyte_read_pos);
    while (GET_GLOBAL(termseq[mb_pos].seq[mb_count-1]) != byte) {
        // Byte didn't match this sequence - find a sequence that does
        mb_pos++;
        if (mb_pos >= ARRAY_SIZE(termseq)
            || memcmp_far(GLOBAL_SEG, termseq[mb_pos-1].seq
                          , GLOBAL_SEG, termseq[mb_pos].seq, mb_count-1) != 0)
            // No match - must flush previusly queued keys
            dump_multibyte_sequence();
            return 0;
        }
    }
    mb_count++;
    if (!GET_GLOBAL(termseq[mb_pos].seq[mb_count-1])) {
        // sequence complete - send key
        sercon_sendkey(GET_GLOBAL(termseq[seq].scancode), 0);
        mb_count = mb_pos = 0;
    }
    SET_LOW(multibyte_read_count, mb_count);
    SET_LOW(multibyte_read_pos, mb_pos);
    return 1;
}

static void
dump_multibyte_sequence(void)
{
    sercon_sendkey(GET_LOW(termchr[0x1b].scancode), GET_LOW(termchr[0x1b].flags));
    int i, mb_count = GET_LOW(multibyte_read_count);
    for (i=0; i<mb_count-1; i++) {
        u8 key = GET_GLOBAL(termseq[mb_pos].seq[i]);
        sercon_sendkey(GET_LOW(termchr[key].scancode), GET_LOW(termchr[key].flags));
    }
    SET_LOW(multibyte_read_count, 0);
    SET_LOW(multibyte_read_pos, 0);
}

  reply	other threads:[~2016-07-01 18:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-01 10:54 [Qemu-devel] [RFC PATCH 0/2] seabios: add serial console support Gerd Hoffmann
2016-07-01 10:54 ` [Qemu-devel] [RFC PATCH 1/2] serial console, output Gerd Hoffmann
2016-07-01 15:47   ` [Qemu-devel] [SeaBIOS] " Kevin O'Connor
2016-07-04  8:16     ` Gerd Hoffmann
2016-07-04  9:11       ` [Qemu-devel] " Paolo Bonzini
2016-07-04 12:46         ` Gerd Hoffmann
2016-07-04 12:48           ` Paolo Bonzini
2016-07-04 15:26           ` Kevin O'Connor
2016-07-04 15:45             ` Paolo Bonzini
2016-07-04 20:10               ` Gerd Hoffmann
2016-07-04 16:00             ` Kevin O'Connor
2016-07-04 16:03               ` Paolo Bonzini
2016-07-04 17:28                 ` Kevin O'Connor
2016-07-04 20:18                   ` Gerd Hoffmann
2016-07-04 20:23             ` Gerd Hoffmann
2016-07-01 10:54 ` [Qemu-devel] [RFC PATCH 2/2] serial console, input Gerd Hoffmann
2016-07-01 17:07   ` [Qemu-devel] [SeaBIOS] " Kevin O'Connor
2016-07-01 18:07     ` Kevin O'Connor [this message]
2016-07-04  9:16     ` Gerd Hoffmann
2016-07-04 15:34       ` Kevin O'Connor
2016-07-04 20:03         ` Gerd Hoffmann
2016-07-01 15:47 ` [Qemu-devel] [RFC PATCH 0/2] seabios: add serial console support Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160701180741.GA24801@morn.lan \
    --to=kevin@koconnor.net \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.