From nobody Sat Apr 11 13:59:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1775848922; cv=none; d=zohomail.com; s=zohoarc; b=mUwq/upvNZR622ZQvQM0G34/3ApnIyakOvKzUTXwO6J2tceWd2+HIcIEWFl4YdrU816Flt1SMln6imlHsoFBKwX5wCtFj4uT9MEprfbg6z1boXz6yIdtRVR3wgHYK9g2oXHBNXSJRExebH1SPTVe9PrlnbZiE5WFs1pNZZK2liQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775848922; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eev7ZgDt7TuG9zqc7JFbqu+7TfwNceZf9Sx5cioSKfc=; b=V/DzmFUVAv0pVhHMK6X2V+5QNqPaNDOwi1q3x3kplX03Wtc3tWwyKOGxZ+4laC5WREcBqIOQqObeOCBpKo+ss27DKr8VIATLGA37BSKbZA8JRLtotnJDaYXSid8aJtkm6e13AafvKJQiHn6wpm4oqO8OWsPMtLfefvvKeU0SBa8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775848922113156.0263822338983; Fri, 10 Apr 2026 12:22:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBHQH-0000MQ-LH; Fri, 10 Apr 2026 15:21:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBHQ3-0007s8-U8 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 15:21:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBHQ0-0001cS-JO for qemu-devel@nongnu.org; Fri, 10 Apr 2026 15:21:31 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-DmQzhfBQNziv3cF7vOBDoQ-1; Fri, 10 Apr 2026 15:21:26 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6AF2119560B7 for ; Fri, 10 Apr 2026 19:21:25 +0000 (UTC) Received: from localhost (unknown [10.44.22.4]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D747180057F; Fri, 10 Apr 2026 19:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775848887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eev7ZgDt7TuG9zqc7JFbqu+7TfwNceZf9Sx5cioSKfc=; b=jSGZMHO3WsMgtct5/YSdXpvnupM8zZBMRHTttw+9TCt7uZf9tGdaKOI4pWsKbNLnjbYzpI +Fa2NMOS6PAwkBjzfRJepxjBj/Zfv6QGDjxvNGMoHTHbJmnlok6Psaw95POW3sk0L/U3ug ucx8SSFML/QTy2YqB9vQLGo9C02povY= X-MC-Unique: DmQzhfBQNziv3cF7vOBDoQ-1 X-Mimecast-MFC-AGG-ID: DmQzhfBQNziv3cF7vOBDoQ_1775848885 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 10 Apr 2026 23:18:47 +0400 Subject: [PATCH v2 25/67] ui/console-vc: move VT100 state machine and output FIFO into QemuVT100 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260410-qemu-vnc-v2-25-231416f76dc3@redhat.com> References: <20260410-qemu-vnc-v2-0-231416f76dc3@redhat.com> In-Reply-To: <20260410-qemu-vnc-v2-0-231416f76dc3@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=32396; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=PUHVzwpUuSJhv3fv9Q/KSd6OQTNQ0Wo8/FtWCxla3rc=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBp2U0Uu5D6XB2ok14O8BvhaKHqEXFAu2YyAL0cT croY93vPcSJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCadlNFAAKCRDa6OEJdZac 5eG+EACzXd7JZWoWXB5zpPyFdEg0MOD3ZubOdc4UQ7HQKHzLGlnzUKyqcQJQN08ORbXKn9SuiWL 42phqXNu2HLgwdl6X/CVmzMOi1D2XI4WWOpd4Gxs2A7BQKSN86HzewdcTVc3oYzocgTlaoAA0nQ vOk510uNaTfg4bv9N6QUZzSmRpzjCp9CtsTaPJzkqTq7RF83kWkG5uwC1JtTNZ3Z5FRLz0k9XAf 8Q6JLwVFAooz5OMZQA4ZVr2jjOLDg46FjAtfyRdmv0wy5g4ycIw2JPcu77MEauO+nAzrfl+esdH 23BKMTh0rJ/yMVyqZFjVSlh98MfU0axDH8Shv0GJgll/ENA41SchqNmyaqgPjzXg1UZT9xhhtZp P37IVNOWyyOydir5BRIrtK3ZHp/2++2vvUQrsF3pI298oIImN5xB5hlWRjMFYpGdxoC0Ovbf1pP mk7io1PKdxvRzP2pg263EvZBhIzwg0fqqWy0xLg38lsAy9Mxmf1OM4A0h8px1vmMEZWhUXy7k/f xiDLa8SC6hTiQuRKcEiL5Fmr07O4n9eiWpnLpjnf5YVVYjWfigw5SlELLMU830//34GdmOCehzq RUiO/mRJmzUYdhBz6dsM0emqWSpfynI2ckciuoL3Li9NTPu5U0WGefN+m7OGbsMtxsl2YSsnPNX lOiYWbhSeMFEJWA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 7 X-Spam_score: 0.7 X-Spam_bar: / X-Spam_report: (0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1775848923224154100 Move the terminal escape sequence parser state (TTYState, esc_params, text attributes, saved cursor position) and the output FIFO from VCChardev/QemuTextConsole into QemuVT100. Rename the corresponding functions from vc_* to vt100_* to reflect they now operate on the VT100 layer directly, removing the indirection through vc->console->vt. Add an out_flush callback to QemuVT100 so vt100_write() can flush output without knowing about QemuTextConsole, and move FIFO/VT100 initialization from qemu_text_console_init() to vc_chr_open() where the callback can be wired up. This continues the decoupling of VT100 terminal emulation from the chardev layer, making QemuVT100 a self-contained terminal emulator. Signed-off-by: Marc-Andr=C3=A9 Lureau --- ui/console-vc.c | 375 +++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 180 insertions(+), 195 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index bba1fe614ef..5cfb3dfcf72 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -72,6 +72,18 @@ struct QemuVT100 { int update_x1; int update_y1; =20 + enum TTYState state; + int esc_params[MAX_ESC_PARAMS]; + int nb_esc_params; + uint32_t utf8_state; /* UTF-8 DFA decoder state */ + uint32_t utf8_codepoint; /* accumulated UTF-8 code point */ + TextAttributes t_attrib; /* currently active text attributes */ + TextAttributes t_attrib_saved; + int x_saved, y_saved; + /* fifo for key pressed */ + Fifo8 out_fifo; + void (*out_flush)(QemuVT100 *vt); + QTAILQ_ENTRY(QemuVT100) list; }; =20 @@ -83,8 +95,6 @@ typedef struct QemuTextConsole { =20 QemuVT100 vt; Chardev *chr; - /* fifo for key pressed */ - Fifo8 out_fifo; } QemuTextConsole; =20 typedef QemuConsoleClass QemuTextConsoleClass; @@ -102,15 +112,6 @@ OBJECT_DEFINE_TYPE(QemuFixedTextConsole, qemu_fixed_te= xt_console, QEMU_FIXED_TEX struct VCChardev { Chardev parent; QemuTextConsole *console; - - enum TTYState state; - int esc_params[MAX_ESC_PARAMS]; - int nb_esc_params; - uint32_t utf8_state; /* UTF-8 DFA decoder state */ - uint32_t utf8_codepoint; /* accumulated UTF-8 code point */ - TextAttributes t_attrib; /* currently active text attributes */ - TextAttributes t_attrib_saved; - int x_saved, y_saved; }; typedef struct VCChardev VCChardev; =20 @@ -299,36 +300,35 @@ static void vt100_scroll(QemuVT100 *vt, int ydelta) vt100_refresh(vt); } =20 -static void qemu_text_console_flush(QemuTextConsole *s) +static void qemu_text_console_out_flush(QemuTextConsole *s) { uint32_t len, avail; =20 len =3D qemu_chr_be_can_write(s->chr); - avail =3D fifo8_num_used(&s->out_fifo); + avail =3D fifo8_num_used(&s->vt.out_fifo); while (len > 0 && avail > 0) { const uint8_t *buf; uint32_t size; =20 - buf =3D fifo8_pop_bufptr(&s->out_fifo, MIN(len, avail), &size); + buf =3D fifo8_pop_bufptr(&s->vt.out_fifo, MIN(len, avail), &size); qemu_chr_be_write(s->chr, buf, size); len =3D qemu_chr_be_can_write(s->chr); avail -=3D size; } } =20 -static void qemu_text_console_write(QemuTextConsole *s, const void *buf, s= ize_t len) +static void vt100_write(QemuVT100 *vt, const void *buf, size_t len) { uint32_t num_free; =20 - num_free =3D fifo8_num_free(&s->out_fifo); - fifo8_push_all(&s->out_fifo, buf, MIN(num_free, len)); - qemu_text_console_flush(s); + num_free =3D fifo8_num_free(&vt->out_fifo); + fifo8_push_all(&vt->out_fifo, buf, MIN(num_free, len)); + vt->out_flush(vt); } =20 /* called when an ascii key is pressed */ void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym) { - QemuVT100 *vt =3D &s->vt; uint8_t buf[16], *q; int c; =20 @@ -360,16 +360,16 @@ void qemu_text_console_handle_keysym(QemuTextConsole = *s, int keysym) *q++ =3D '\033'; *q++ =3D '['; *q++ =3D keysym & 0xff; - } else if (vt->echo && (keysym =3D=3D '\r' || keysym =3D=3D '\n'))= { + } else if (s->vt.echo && (keysym =3D=3D '\r' || keysym =3D=3D '\n'= )) { qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true); *q++ =3D '\n'; } else { *q++ =3D keysym; } - if (vt->echo) { + if (s->vt.echo) { qemu_chr_write(s->chr, buf, q - buf, true); } - qemu_text_console_write(s, buf, q - buf); + vt100_write(&s->vt, buf, q - buf); break; } } @@ -377,30 +377,29 @@ void qemu_text_console_handle_keysym(QemuTextConsole = *s, int keysym) static void text_console_update(void *opaque, console_ch_t *chardata) { QemuTextConsole *s =3D QEMU_TEXT_CONSOLE(opaque); - QemuVT100 *vt =3D &s->vt; int i, j, src; =20 - if (vt->text_x[0] <=3D vt->text_x[1]) { - src =3D (vt->y_base + vt->text_y[0]) * vt->width; - chardata +=3D vt->text_y[0] * vt->width; - for (i =3D vt->text_y[0]; i <=3D vt->text_y[1]; i ++) - for (j =3D 0; j < vt->width; j++, src++) { + if (s->vt.text_x[0] <=3D s->vt.text_x[1]) { + src =3D (s->vt.y_base + s->vt.text_y[0]) * s->vt.width; + chardata +=3D s->vt.text_y[0] * s->vt.width; + for (i =3D s->vt.text_y[0]; i <=3D s->vt.text_y[1]; i ++) + for (j =3D 0; j < s->vt.width; j++, src++) { console_write_ch(chardata ++, - ATTR2CHTYPE(vt->cells[src].ch, - vt->cells[src].t_attrib.fgcol, - vt->cells[src].t_attrib.bgcol, - vt->cells[src].t_attrib.bold)= ); + ATTR2CHTYPE(s->vt.cells[src].ch, + s->vt.cells[src].t_attrib.fgc= ol, + s->vt.cells[src].t_attrib.bgc= ol, + s->vt.cells[src].t_attrib.bol= d)); } - dpy_text_update(QEMU_CONSOLE(s), vt->text_x[0], vt->text_y[0], - vt->text_x[1] - vt->text_x[0], i - vt->text_y[0]); - vt->text_x[0] =3D vt->width; - vt->text_y[0] =3D vt->height; - vt->text_x[1] =3D 0; - vt->text_y[1] =3D 0; + dpy_text_update(QEMU_CONSOLE(s), s->vt.text_x[0], s->vt.text_y[0], + s->vt.text_x[1] - s->vt.text_x[0], i - s->vt.text_= y[0]); + s->vt.text_x[0] =3D s->vt.width; + s->vt.text_y[0] =3D s->vt.height; + s->vt.text_x[1] =3D 0; + s->vt.text_y[1] =3D 0; } - if (vt->cursor_invalidate) { - dpy_text_cursor(QEMU_CONSOLE(s), vt->x, vt->y); - vt->cursor_invalidate =3D 0; + if (s->vt.cursor_invalidate) { + dpy_text_cursor(QEMU_CONSOLE(s), s->vt.x, s->vt.y); + s->vt.cursor_invalidate =3D 0; } } =20 @@ -489,103 +488,101 @@ static void vt100_put_lf(QemuVT100 *vt) * NOTE: I know this code is not very efficient (checking every color for = it * self) but it is more readable and better maintainable. */ -static void vc_handle_escape(VCChardev *vc) +static void vt100_handle_escape(QemuVT100 *vt) { int i; =20 - for (i =3D 0; i < vc->nb_esc_params; i++) { - switch (vc->esc_params[i]) { + for (i =3D 0; i < vt->nb_esc_params; i++) { + switch (vt->esc_params[i]) { case 0: /* reset all console attributes to default */ - vc->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; + vt->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; break; case 1: - vc->t_attrib.bold =3D 1; + vt->t_attrib.bold =3D 1; break; case 4: - vc->t_attrib.uline =3D 1; + vt->t_attrib.uline =3D 1; break; case 5: - vc->t_attrib.blink =3D 1; + vt->t_attrib.blink =3D 1; break; case 7: - vc->t_attrib.invers =3D 1; + vt->t_attrib.invers =3D 1; break; case 8: - vc->t_attrib.unvisible =3D 1; + vt->t_attrib.unvisible =3D 1; break; case 22: - vc->t_attrib.bold =3D 0; + vt->t_attrib.bold =3D 0; break; case 24: - vc->t_attrib.uline =3D 0; + vt->t_attrib.uline =3D 0; break; case 25: - vc->t_attrib.blink =3D 0; + vt->t_attrib.blink =3D 0; break; case 27: - vc->t_attrib.invers =3D 0; + vt->t_attrib.invers =3D 0; break; case 28: - vc->t_attrib.unvisible =3D 0; + vt->t_attrib.unvisible =3D 0; break; /* set foreground color */ case 30: - vc->t_attrib.fgcol =3D QEMU_COLOR_BLACK; + vt->t_attrib.fgcol =3D QEMU_COLOR_BLACK; break; case 31: - vc->t_attrib.fgcol =3D QEMU_COLOR_RED; + vt->t_attrib.fgcol =3D QEMU_COLOR_RED; break; case 32: - vc->t_attrib.fgcol =3D QEMU_COLOR_GREEN; + vt->t_attrib.fgcol =3D QEMU_COLOR_GREEN; break; case 33: - vc->t_attrib.fgcol =3D QEMU_COLOR_YELLOW; + vt->t_attrib.fgcol =3D QEMU_COLOR_YELLOW; break; case 34: - vc->t_attrib.fgcol =3D QEMU_COLOR_BLUE; + vt->t_attrib.fgcol =3D QEMU_COLOR_BLUE; break; case 35: - vc->t_attrib.fgcol =3D QEMU_COLOR_MAGENTA; + vt->t_attrib.fgcol =3D QEMU_COLOR_MAGENTA; break; case 36: - vc->t_attrib.fgcol =3D QEMU_COLOR_CYAN; + vt->t_attrib.fgcol =3D QEMU_COLOR_CYAN; break; case 37: - vc->t_attrib.fgcol =3D QEMU_COLOR_WHITE; + vt->t_attrib.fgcol =3D QEMU_COLOR_WHITE; break; /* set background color */ case 40: - vc->t_attrib.bgcol =3D QEMU_COLOR_BLACK; + vt->t_attrib.bgcol =3D QEMU_COLOR_BLACK; break; case 41: - vc->t_attrib.bgcol =3D QEMU_COLOR_RED; + vt->t_attrib.bgcol =3D QEMU_COLOR_RED; break; case 42: - vc->t_attrib.bgcol =3D QEMU_COLOR_GREEN; + vt->t_attrib.bgcol =3D QEMU_COLOR_GREEN; break; case 43: - vc->t_attrib.bgcol =3D QEMU_COLOR_YELLOW; + vt->t_attrib.bgcol =3D QEMU_COLOR_YELLOW; break; case 44: - vc->t_attrib.bgcol =3D QEMU_COLOR_BLUE; + vt->t_attrib.bgcol =3D QEMU_COLOR_BLUE; break; case 45: - vc->t_attrib.bgcol =3D QEMU_COLOR_MAGENTA; + vt->t_attrib.bgcol =3D QEMU_COLOR_MAGENTA; break; case 46: - vc->t_attrib.bgcol =3D QEMU_COLOR_CYAN; + vt->t_attrib.bgcol =3D QEMU_COLOR_CYAN; break; case 47: - vc->t_attrib.bgcol =3D QEMU_COLOR_WHITE; + vt->t_attrib.bgcol =3D QEMU_COLOR_WHITE; break; } } } =20 -static void vc_update_xy(VCChardev *vc, int x, int y) +static void vt100_update_xy(QemuVT100 *vt, int x, int y) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; TextCell *c; int y1, y2; =20 @@ -606,14 +603,12 @@ static void vc_update_xy(VCChardev *vc, int x, int y) c =3D &vt->cells[y1 * vt->width + x]; vt100_putcharxy(vt, x, y2, c->ch, &(c->t_attrib)); - vt100_invalidate_xy(&s->vt, x, y2); + vt100_invalidate_xy(vt, x, y2); } } =20 -static void vc_clear_xy(VCChardev *vc, int x, int y) +static void vt100_clear_xy(QemuVT100 *vt, int x, int y) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; int y1 =3D (vt->y_base + y) % vt->total_height; if (x >=3D vt->width) { x =3D vt->width - 1; @@ -621,7 +616,7 @@ static void vc_clear_xy(VCChardev *vc, int x, int y) TextCell *c =3D &vt->cells[y1 * vt->width + x]; c->ch =3D ' '; c->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; - vc_update_xy(vc, x, y); + vt100_update_xy(vt, x, y); } =20 /* @@ -664,10 +659,8 @@ static uint32_t bh_utf8_decode(uint32_t *state, uint32= _t *codep, uint32_t byte) return *state; } =20 -static void vc_put_one(VCChardev *vc, int ch) +static void vt100_put_one(QemuVT100 *vt, int ch) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; TextCell *c; int y1; if (vt->x >=3D vt->width) { @@ -678,17 +671,14 @@ static void vc_put_one(VCChardev *vc, int ch) y1 =3D (vt->y_base + vt->y) % vt->total_height; c =3D &vt->cells[y1 * vt->width + vt->x]; c->ch =3D ch; - c->t_attrib =3D vc->t_attrib; - vc_update_xy(vc, vt->x, vt->y); + c->t_attrib =3D vt->t_attrib; + vt100_update_xy(vt, vt->x, vt->y); vt->x++; } =20 /* set cursor, checking bounds */ -static void vc_set_cursor(VCChardev *vc, int x, int y) +static void vt100_set_cursor(QemuVT100 *vt, int x, int y) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; - if (x < 0) { x =3D 0; } @@ -712,10 +702,8 @@ static void vc_set_cursor(VCChardev *vc, int x, int y) * characters between the cursor and right margin move to the * left. Character attributes move with the characters. */ -static void vc_csi_P(struct VCChardev *vc, unsigned int nr) +static void vt100_csi_P(QemuVT100 *vt, unsigned int nr) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -739,12 +727,12 @@ static void vc_csi_P(struct VCChardev *vc, unsigned i= nt nr) c2 =3D &vt->cells[y * vt->width + x2]; memmove(c1, c2, len * sizeof(*c1)); for (end =3D x1 + len; x1 < end; x1++) { - vc_update_xy(vc, x1, vt->y); + vt100_update_xy(vt, x1, vt->y); } } /* Clear the rest */ for (; x1 < vt->width; x1++) { - vc_clear_xy(vc, x1, vt->y); + vt100_clear_xy(vt, x1, vt->y); } } =20 @@ -754,10 +742,8 @@ static void vc_csi_P(struct VCChardev *vc, unsigned in= t nr) * blank characters. Text between the cursor and right margin moves to * the right. Characters scrolled past the right margin are lost. */ -static void vc_csi_at(struct VCChardev *vc, unsigned int nr) +static void vt100_csi_at(QemuVT100 *vt, unsigned int nr) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -781,61 +767,53 @@ static void vc_csi_at(struct VCChardev *vc, unsigned = int nr) c2 =3D &vt->cells[y * vt->width + x2]; memmove(c1, c2, len * sizeof(*c1)); for (end =3D x1 + len; x1 < end; x1++) { - vc_update_xy(vc, x1, vt->y); + vt100_update_xy(vt, x1, vt->y); } } /* Insert blanks */ for (x1 =3D vt->x; x1 < vt->x + nr; x1++) { - vc_clear_xy(vc, x1, vt->y); + vt100_clear_xy(vt, x1, vt->y); } } =20 /** - * vc_save_cursor() - saves cursor position and character attributes. + * vt100_save_cursor() - saves cursor position and character attributes. */ -static void vc_save_cursor(VCChardev *vc) +static void vt100_save_cursor(QemuVT100 *vt) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; - - vc->x_saved =3D vt->x; - vc->y_saved =3D vt->y; - vc->t_attrib_saved =3D vc->t_attrib; + vt->x_saved =3D vt->x; + vt->y_saved =3D vt->y; + vt->t_attrib_saved =3D vt->t_attrib; } =20 /** - * vc_restore_cursor() - restores cursor position and character + * vt100_restore_cursor() - restores cursor position and character * attributes from saved state. */ -static void vc_restore_cursor(VCChardev *vc) +static void vt100_restore_cursor(QemuVT100 *vt) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; - - vt->x =3D vc->x_saved; - vt->y =3D vc->y_saved; - vc->t_attrib =3D vc->t_attrib_saved; + vt->x =3D vt->x_saved; + vt->y =3D vt->y_saved; + vt->t_attrib =3D vt->t_attrib_saved; } =20 -static void vc_putchar(VCChardev *vc, int ch) +static void vt100_putchar(QemuVT100 *vt, int ch) { - QemuTextConsole *s =3D vc->console; - QemuVT100 *vt =3D &s->vt; int i; int x, y; g_autofree char *response =3D NULL; =20 - switch(vc->state) { + switch (vt->state) { case TTY_STATE_NORM: /* Feed byte through the UTF-8 DFA decoder */ if (ch >=3D 0x80) { - switch (bh_utf8_decode(&vc->utf8_state, &vc->utf8_codepoint, c= h)) { + switch (bh_utf8_decode(&vt->utf8_state, &vt->utf8_codepoint, c= h)) { case BH_UTF8_ACCEPT: - vc_put_one(vc, unicode_to_cp437(vc->utf8_codepoint)); + vt100_put_one(vt, unicode_to_cp437(vt->utf8_codepoint)); break; case BH_UTF8_REJECT: /* Reset state so the decoder can resync */ - vc->utf8_state =3D BH_UTF8_ACCEPT; + vt->utf8_state =3D BH_UTF8_ACCEPT; break; default: /* Need more bytes */ @@ -844,13 +822,13 @@ static void vc_putchar(VCChardev *vc, int ch) break; } /* ASCII byte: abort any pending UTF-8 sequence */ - vc->utf8_state =3D BH_UTF8_ACCEPT; + vt->utf8_state =3D BH_UTF8_ACCEPT; switch(ch) { case '\r': /* carriage return */ vt->x =3D 0; break; case '\n': /* newline */ - vt100_put_lf(&s->vt); + vt100_put_lf(vt); break; case '\b': /* backspace */ if (vt->x > 0) @@ -874,95 +852,95 @@ static void vc_putchar(VCChardev *vc, int ch) /* SI (shift in), character set 0 (ignored) */ break; case 27: /* esc (introducing an escape sequence) */ - vc->state =3D TTY_STATE_ESC; + vt->state =3D TTY_STATE_ESC; break; default: - vc_put_one(vc, ch); + vt100_put_one(vt, ch); break; } break; case TTY_STATE_ESC: /* check if it is a terminal escape sequence */ if (ch =3D=3D '[') { for(i=3D0;iesc_params[i] =3D 0; - vc->nb_esc_params =3D 0; - vc->state =3D TTY_STATE_CSI; + vt->esc_params[i] =3D 0; + vt->nb_esc_params =3D 0; + vt->state =3D TTY_STATE_CSI; } else if (ch =3D=3D '(') { - vc->state =3D TTY_STATE_G0; + vt->state =3D TTY_STATE_G0; } else if (ch =3D=3D ')') { - vc->state =3D TTY_STATE_G1; + vt->state =3D TTY_STATE_G1; } else if (ch =3D=3D ']' || ch =3D=3D 'P' || ch =3D=3D 'X' || ch =3D=3D '^' || ch =3D=3D '_') { /* String sequences: OSC, DCS, SOS, PM, APC */ - vc->state =3D TTY_STATE_OSC; + vt->state =3D TTY_STATE_OSC; } else if (ch =3D=3D '7') { - vc_save_cursor(vc); - vc->state =3D TTY_STATE_NORM; + vt100_save_cursor(vt); + vt->state =3D TTY_STATE_NORM; } else if (ch =3D=3D '8') { - vc_restore_cursor(vc); - vc->state =3D TTY_STATE_NORM; + vt100_restore_cursor(vt); + vt->state =3D TTY_STATE_NORM; } else { - vc->state =3D TTY_STATE_NORM; + vt->state =3D TTY_STATE_NORM; } break; case TTY_STATE_CSI: /* handle escape sequence parameters */ if (ch >=3D '0' && ch <=3D '9') { - if (vc->nb_esc_params < MAX_ESC_PARAMS) { - int *param =3D &vc->esc_params[vc->nb_esc_params]; + if (vt->nb_esc_params < MAX_ESC_PARAMS) { + int *param =3D &vt->esc_params[vt->nb_esc_params]; int digit =3D (ch - '0'); =20 *param =3D (*param <=3D (INT_MAX - digit) / 10) ? *param * 10 + digit : INT_MAX; } } else { - if (vc->nb_esc_params < MAX_ESC_PARAMS) - vc->nb_esc_params++; + if (vt->nb_esc_params < MAX_ESC_PARAMS) + vt->nb_esc_params++; if (ch =3D=3D ';' || ch =3D=3D '?') { break; } - trace_console_putchar_csi(vc->esc_params[0], vc->esc_params[1], - ch, vc->nb_esc_params); - vc->state =3D TTY_STATE_NORM; + trace_console_putchar_csi(vt->esc_params[0], vt->esc_params[1], + ch, vt->nb_esc_params); + vt->state =3D TTY_STATE_NORM; switch(ch) { case 'A': /* move cursor up */ - if (vc->esc_params[0] =3D=3D 0) { - vc->esc_params[0] =3D 1; + if (vt->esc_params[0] =3D=3D 0) { + vt->esc_params[0] =3D 1; } - vc_set_cursor(vc, vt->x, vt->y - vc->esc_params[0]); + vt100_set_cursor(vt, vt->x, vt->y - vt->esc_params[0]); break; case 'B': /* move cursor down */ - if (vc->esc_params[0] =3D=3D 0) { - vc->esc_params[0] =3D 1; + if (vt->esc_params[0] =3D=3D 0) { + vt->esc_params[0] =3D 1; } - vc_set_cursor(vc, vt->x, vt->y + vc->esc_params[0]); + vt100_set_cursor(vt, vt->x, vt->y + vt->esc_params[0]); break; case 'C': /* move cursor right */ - if (vc->esc_params[0] =3D=3D 0) { - vc->esc_params[0] =3D 1; + if (vt->esc_params[0] =3D=3D 0) { + vt->esc_params[0] =3D 1; } - vc_set_cursor(vc, vt->x + vc->esc_params[0], vt->y); + vt100_set_cursor(vt, vt->x + vt->esc_params[0], vt->y); break; case 'D': /* move cursor left */ - if (vc->esc_params[0] =3D=3D 0) { - vc->esc_params[0] =3D 1; + if (vt->esc_params[0] =3D=3D 0) { + vt->esc_params[0] =3D 1; } - vc_set_cursor(vc, vt->x - vc->esc_params[0], vt->y); + vt100_set_cursor(vt, vt->x - vt->esc_params[0], vt->y); break; case 'G': /* move cursor to column */ - vc_set_cursor(vc, vc->esc_params[0] - 1, vt->y); + vt100_set_cursor(vt, vt->esc_params[0] - 1, vt->y); break; case 'f': case 'H': /* move cursor to row, column */ - vc_set_cursor(vc, vc->esc_params[1] - 1, vc->esc_params[0]= - 1); + vt100_set_cursor(vt, vt->esc_params[1] - 1, vt->esc_params= [0] - 1); break; case 'J': - switch (vc->esc_params[0]) { + switch (vt->esc_params[0]) { case 0: /* clear to end of screen */ for (y =3D vt->y; y < vt->height; y++) { @@ -970,7 +948,7 @@ static void vc_putchar(VCChardev *vc, int ch) if (y =3D=3D vt->y && x < vt->x) { continue; } - vc_clear_xy(vc, x, y); + vt100_clear_xy(vt, x, y); } } break; @@ -981,7 +959,7 @@ static void vc_putchar(VCChardev *vc, int ch) if (y =3D=3D vt->y && x > vt->x) { break; } - vc_clear_xy(vc, x, y); + vt100_clear_xy(vt, x, y); } } break; @@ -989,62 +967,62 @@ static void vc_putchar(VCChardev *vc, int ch) /* clear entire screen */ for (y =3D 0; y < vt->height; y++) { for (x =3D 0; x < vt->width; x++) { - vc_clear_xy(vc, x, y); + vt100_clear_xy(vt, x, y); } } break; } break; case 'K': - switch (vc->esc_params[0]) { + switch (vt->esc_params[0]) { case 0: /* clear to eol */ for(x =3D vt->x; x < vt->width; x++) { - vc_clear_xy(vc, x, vt->y); + vt100_clear_xy(vt, x, vt->y); } break; case 1: /* clear from beginning of line */ for (x =3D 0; x <=3D vt->x && x < vt->width; x++) { - vc_clear_xy(vc, x, vt->y); + vt100_clear_xy(vt, x, vt->y); } break; case 2: /* clear entire line */ for(x =3D 0; x < vt->width; x++) { - vc_clear_xy(vc, x, vt->y); + vt100_clear_xy(vt, x, vt->y); } break; } break; case 'P': - vc_csi_P(vc, vc->esc_params[0]); + vt100_csi_P(vt, vt->esc_params[0]); break; case 'm': - vc_handle_escape(vc); + vt100_handle_escape(vt); break; case 'n': - switch (vc->esc_params[0]) { + switch (vt->esc_params[0]) { case 5: /* report console status (always succeed)*/ - qemu_text_console_write(s, "\033[0n", 4); + vt100_write(vt, "\033[0n", 4); break; case 6: /* report cursor position */ response =3D g_strdup_printf("\033[%d;%dR", vt->y + 1, vt->x + 1); - qemu_text_console_write(s, response, strlen(response)); + vt100_write(vt, response, strlen(response)); break; } break; case 's': - vc_save_cursor(vc); + vt100_save_cursor(vt); break; case 'u': - vc_restore_cursor(vc); + vt100_restore_cursor(vt); break; case '@': - vc_csi_at(vc, vc->esc_params[0]); + vt100_csi_at(vt, vt->esc_params[0]); break; default: trace_console_putchar_unhandled(ch); @@ -1056,10 +1034,10 @@ static void vc_putchar(VCChardev *vc, int ch) case TTY_STATE_OSC: /* Operating System Command: ESC ] ... BEL/ST */ if (ch =3D=3D '\a') { /* BEL terminates OSC */ - vc->state =3D TTY_STATE_NORM; + vt->state =3D TTY_STATE_NORM; } else if (ch =3D=3D 27) { /* ESC might start ST (ESC \) */ - vc->state =3D TTY_STATE_ESC; + vt->state =3D TTY_STATE_ESC; } /* All other bytes are silently consumed */ break; @@ -1070,7 +1048,7 @@ static void vc_putchar(VCChardev *vc, int ch) /* Latin-1 map */ break; } - vc->state =3D TTY_STATE_NORM; + vt->state =3D TTY_STATE_NORM; break; } } @@ -1083,22 +1061,21 @@ static int vc_chr_write(Chardev *chr, const uint8_t= *buf, int len) { VCChardev *drv =3D VC_CHARDEV(chr); QemuTextConsole *s =3D drv->console; - QemuVT100 *vt =3D &s->vt; int i; =20 - vt->update_x0 =3D vt->width * FONT_WIDTH; - vt->update_y0 =3D vt->height * FONT_HEIGHT; - vt->update_x1 =3D 0; - vt->update_y1 =3D 0; - vt100_show_cursor(vt, 0); + s->vt.update_x0 =3D s->vt.width * FONT_WIDTH; + s->vt.update_y0 =3D s->vt.height * FONT_HEIGHT; + s->vt.update_x1 =3D 0; + s->vt.update_y1 =3D 0; + vt100_show_cursor(&s->vt, 0); for(i =3D 0; i < len; i++) { - vc_putchar(drv, buf[i]); + vt100_putchar(&s->vt, buf[i]); } - vt100_show_cursor(vt, 1); - if (vt->update_x0 < vt->update_x1) { - vt100_image_update(vt, vt->update_x0, vt->update_y0, - vt->update_x1 - vt->update_x0, - vt->update_y1 - vt->update_y0); + vt100_show_cursor(&s->vt, 1); + if (s->vt.update_x0 < s->vt.update_x1) { + vt100_image_update(&s->vt, s->vt.update_x0, s->vt.update_y0, + s->vt.update_x1 - s->vt.update_x0, + s->vt.update_y1 - s->vt.update_y0); } return len; } @@ -1167,9 +1144,6 @@ qemu_text_console_init(Object *obj) { QemuTextConsole *c =3D QEMU_TEXT_CONSOLE(obj); =20 - QTAILQ_INSERT_HEAD(&vt100s, &c->vt, list); - fifo8_create(&c->out_fifo, 16); - c->vt.total_height =3D DEFAULT_BACKSCROLL; QEMU_CONSOLE(c)->hw_ops =3D &text_console_ops; QEMU_CONSOLE(c)->hw =3D c; } @@ -1193,7 +1167,7 @@ static void vc_chr_accept_input(Chardev *chr) { VCChardev *drv =3D VC_CHARDEV(chr); =20 - qemu_text_console_flush(drv->console); + qemu_text_console_out_flush(drv->console); } =20 static void vc_chr_set_echo(Chardev *chr, bool echo) @@ -1215,6 +1189,13 @@ static void text_console_image_update(QemuVT100 *vt,= int x, int y, int width, in dpy_gfx_update(QEMU_CONSOLE(console), x, y, width, height); } =20 +static void text_console_out_flush(QemuVT100 *vt) +{ + QemuTextConsole *console =3D container_of(vt, QemuTextConsole, vt); + + qemu_text_console_out_flush(console); +} + static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **err= p) { ChardevVC *vc =3D backend->u.vc.data; @@ -1244,24 +1225,28 @@ static bool vc_chr_open(Chardev *chr, ChardevBacken= d *backend, Error **errp) s =3D QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_FIXED_TEXT_CONSOLE)); } =20 + QTAILQ_INSERT_HEAD(&vt100s, &s->vt, list); + fifo8_create(&s->vt.out_fifo, 16); + s->vt.total_height =3D DEFAULT_BACKSCROLL; dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(wi= dth, height)); s->vt.image_update =3D text_console_image_update; + s->vt.out_flush =3D text_console_out_flush; =20 s->chr =3D chr; drv->console =3D s; =20 /* set current text attributes to default */ - drv->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; + s->vt.t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image); =20 if (chr->label) { char *msg; =20 - drv->t_attrib.bgcol =3D QEMU_COLOR_BLUE; + s->vt.t_attrib.bgcol =3D QEMU_COLOR_BLUE; msg =3D g_strdup_printf("%s console\r\n", chr->label); qemu_chr_write(chr, (uint8_t *)msg, strlen(msg), true); g_free(msg); - drv->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; + s->vt.t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; } =20 qemu_chr_be_event(chr, CHR_EVENT_OPENED); --=20 2.53.0