From nobody Tue Apr 7 02:37:28 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=1773737697; cv=none; d=zohomail.com; s=zohoarc; b=G7GV6YrL+vislYkb3m5kSLT/NWCJoLU4j9hne4m1YNKzwKFmLGZERHBmgVHncxuOVKSYqAfzbWX00i/MKYnaEDK7AuiMA/1+XBODZuXI7TCiQ5SQsBHE61y1WoCbyI22eaWtqa00gi+JolDqtJIjHFzhwrRHSEYCUmwBrNUwOzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773737697; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=9jm2AeQLeY/7PKyygV7fcEQuEoBhALKKz1KnR9T9Mnk=; b=lfyfAmEgbCWLaPwje8xe/BDw67FV2tXmk5g92xB+t170DfCw0feCSVyv21qUkjJrlUI4Q1vlrF+E7x1zv3zX6FnL14Q9SMe6DhVbF8FkQSz+CYBG1SEVR+7POitGjBsCI5CQnBD51aYK1BSbm//4MV/qvA9KpjmPE5v3wDaVJq8= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773737697504289.9079194343427; Tue, 17 Mar 2026 01:54:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2QBi-0000jO-As; Tue, 17 Mar 2026 04:54:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2QAy-0007Wb-Tk for qemu-devel@nongnu.org; Tue, 17 Mar 2026 04:53:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2QAv-0003D9-U3 for qemu-devel@nongnu.org; Tue, 17 Mar 2026 04:53:20 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-AB5_KiAeMOqh_lXwX5zkOw-1; Tue, 17 Mar 2026 04:53:15 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D814318005BD for ; Tue, 17 Mar 2026 08:53:14 +0000 (UTC) Received: from localhost (unknown [10.44.22.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 974691800576 for ; Tue, 17 Mar 2026 08:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773737597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9jm2AeQLeY/7PKyygV7fcEQuEoBhALKKz1KnR9T9Mnk=; b=TlI6oOQ+DE3u4Xrmfjp8mO7WjFcVqwnYGGZjHFUTjTCCK5FHUQ17iPtCT01Tg/71ebb+QQ PHBoPeSxosEYftuU6Tldr4joCMiqDUUSeHw93Cr8dASKS0YUcb9eQPjZUS7lLkAybeucWF EJP5/hTs8rD+mZjShU3cVwaA1UvDCzU= X-MC-Unique: AB5_KiAeMOqh_lXwX5zkOw-1 X-Mimecast-MFC-AGG-ID: AB5_KiAeMOqh_lXwX5zkOw_1773737595 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 17 Mar 2026 12:50:41 +0400 Subject: [PATCH 27/60] 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: <20260317-qemu-vnc-v1-27-48eb1dcf7b76@redhat.com> References: <20260317-qemu-vnc-v1-0-48eb1dcf7b76@redhat.com> In-Reply-To: <20260317-qemu-vnc-v1-0-48eb1dcf7b76@redhat.com> To: qemu-devel@nongnu.org X-Developer-Signature: v=1; a=openpgp-sha256; l=32824; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=FBZeB+mSYqwGVV6u9MQO/spZ7c8aebHEI6nlJf7L0k0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBpuRXbJRas4i/pFkySlhrvIilWjLpLfT7/T/Xx0 jDOAoTFKuOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCabkV2wAKCRDa6OEJdZac 5ZmcD/9iuGmsHbc98T+x/YdlVRZiUHHXb8Sum99DJoqd+nK2NzE5s+Dz7/xyIit3DnK5h931eq0 zx4qkaoYW2ZtUts38qExXAyVS8EJUhckwtJ20cmd6i6kJPrX5iUGa3H79XOt9ZVbmPHNSNqnznl N7fMskct8HZFuaTK/9Fn8cCxNoPpZ9s49YOVGBRtr+eKSZwaHWGVe8IxZmws9h6mQdLgmVD6wsP CIgiOIup9T6i1CGzhI6eGHg9AOS5fHbNTx/apCT6LeqYFIMwTEUxxBcq+vHN5AThHIBM6Ygn9aE /C6mrW0448LI/7UQ906FTupreM0pQzYRN5aGMzD9uH5KCbA2wdoc223zS+HJ25b4hhdc99nUmQv OSHxZBXnrBF+dDMMl1UDAZG5Ql86Q5oiSLG8byD+j7rMvUdimW9ObWywrWM9nabapBuExXtvi4H ohp8URG2Tkt3wF+4VaI6zLD4a9DWfr/nfzKR1t8YIKKrppAj6msuI/U8lJi8nY7HBFUntBGoUcD mSssGr/p8Qw3RhqFCmME4yci/OVPBcpvkb+z1HOxt4JM0jhsvbeiGMopU02SuC1SWSYE/KjkGZm 5W79QwMq5jFm3dOhNLzjm4MzQDRYlquQuf1XgUclDslXgfvWicb8T3mRvbIA5P/5xm6MdC0vMME vHG0IYvGcYqU2FA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, 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: 1773737698604154100 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- ui/console-vc.c | 433 ++++++++++++++++++++++++++++------------------------= ---- 1 file changed, 215 insertions(+), 218 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 8d4178f8cab..87881c072ee 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,30 +300,30 @@ 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 */ @@ -368,7 +369,7 @@ void qemu_text_console_handle_keysym(QemuTextConsole *s= , int keysym) 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; } } @@ -487,137 +488,135 @@ 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; TextCell *c; int y1, y2; =20 - s->vt.text_x[0] =3D MIN(s->vt.text_x[0], x); - s->vt.text_x[1] =3D MAX(s->vt.text_x[1], x); - s->vt.text_y[0] =3D MIN(s->vt.text_y[0], y); - s->vt.text_y[1] =3D MAX(s->vt.text_y[1], y); + vt->text_x[0] =3D MIN(vt->text_x[0], x); + vt->text_x[1] =3D MAX(vt->text_x[1], x); + vt->text_y[0] =3D MIN(vt->text_y[0], y); + vt->text_y[1] =3D MAX(vt->text_y[1], y); =20 - y1 =3D (s->vt.y_base + y) % s->vt.total_height; - y2 =3D y1 - s->vt.y_displayed; + y1 =3D (vt->y_base + y) % vt->total_height; + y2 =3D y1 - vt->y_displayed; if (y2 < 0) { - y2 +=3D s->vt.total_height; + y2 +=3D vt->total_height; } - if (y2 < s->vt.height) { - if (x >=3D s->vt.width) { - x =3D s->vt.width - 1; + if (y2 < vt->height) { + if (x >=3D vt->width) { + x =3D vt->width - 1; } - c =3D &s->vt.cells[y1 * s->vt.width + x]; - vt100_putcharxy(&s->vt, x, y2, c->ch, + 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; - int y1 =3D (s->vt.y_base + y) % s->vt.total_height; - if (x >=3D s->vt.width) { - x =3D s->vt.width - 1; + int y1 =3D (vt->y_base + y) % vt->total_height; + if (x >=3D vt->width) { + x =3D vt->width - 1; } - TextCell *c =3D &s->vt.cells[y1 * s->vt.width + x]; + 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 /* @@ -661,44 +660,41 @@ static uint32_t 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; TextCell *c; int y1; - if (s->vt.x >=3D s->vt.width) { + if (vt->x >=3D vt->width) { /* line wrap */ - s->vt.x =3D 0; - vt100_put_lf(&s->vt); + vt->x =3D 0; + vt100_put_lf(vt); } - y1 =3D (s->vt.y_base + s->vt.y) % s->vt.total_height; - c =3D &s->vt.cells[y1 * s->vt.width + s->vt.x]; + 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, s->vt.x, s->vt.y); - s->vt.x++; + 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; - if (x < 0) { x =3D 0; } if (y < 0) { y =3D 0; } - if (y >=3D s->vt.height) { - y =3D s->vt.height - 1; + if (y >=3D vt->height) { + y =3D vt->height - 1; } - if (x >=3D s->vt.width) { - x =3D s->vt.width - 1; + if (x >=3D vt->width) { + x =3D vt->width - 1; } =20 - s->vt.x =3D x; - s->vt.y =3D y; + vt->x =3D x; + vt->y =3D y; } =20 /** @@ -707,9 +703,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; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -717,28 +712,28 @@ static void vc_csi_P(struct VCChardev *vc, unsigned i= nt nr) if (!nr) { nr =3D 1; } - if (nr > s->vt.width - s->vt.x) { - nr =3D s->vt.width - s->vt.x; + if (nr > vt->width - vt->x) { + nr =3D vt->width - vt->x; if (!nr) { return; } } =20 - x1 =3D s->vt.x; - x2 =3D s->vt.x + nr; - len =3D s->vt.width - x2; + x1 =3D vt->x; + x2 =3D vt->x + nr; + len =3D vt->width - x2; if (len) { - y =3D (s->vt.y_base + s->vt.y) % s->vt.total_height; - c1 =3D &s->vt.cells[y * s->vt.width + x1]; - c2 =3D &s->vt.cells[y * s->vt.width + x2]; + y =3D (vt->y_base + vt->y) % vt->total_height; + c1 =3D &vt->cells[y * vt->width + x1]; + 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, s->vt.y); + vt100_update_xy(vt, x1, vt->y); } } /* Clear the rest */ - for (; x1 < s->vt.width; x1++) { - vc_clear_xy(vc, x1, s->vt.y); + for (; x1 < vt->width; x1++) { + vt100_clear_xy(vt, x1, vt->y); } } =20 @@ -748,9 +743,8 @@ static void vc_csi_P(struct VCChardev *vc, unsigned int= 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; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -758,74 +752,69 @@ static void vc_csi_at(struct VCChardev *vc, unsigned = int nr) if (!nr) { nr =3D 1; } - if (nr > s->vt.width - s->vt.x) { - nr =3D s->vt.width - s->vt.x; + if (nr > vt->width - vt->x) { + nr =3D vt->width - vt->x; if (!nr) { return; } } =20 - x1 =3D s->vt.x + nr; - x2 =3D s->vt.x; - len =3D s->vt.width - x1; + x1 =3D vt->x + nr; + x2 =3D vt->x; + len =3D vt->width - x1; if (len) { - y =3D (s->vt.y_base + s->vt.y) % s->vt.total_height; - c1 =3D &s->vt.cells[y * s->vt.width + x1]; - c2 =3D &s->vt.cells[y * s->vt.width + x2]; + y =3D (vt->y_base + vt->y) % vt->total_height; + c1 =3D &vt->cells[y * vt->width + x1]; + 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, s->vt.y); + vt100_update_xy(vt, x1, vt->y); } } /* Insert blanks */ - for (x1 =3D s->vt.x; x1 < s->vt.x + nr; x1++) { - vc_clear_xy(vc, x1, s->vt.y); + for (x1 =3D vt->x; x1 < vt->x + nr; x1++) { + 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; - - vc->x_saved =3D s->vt.x; - vc->y_saved =3D s->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; - - s->vt.x =3D vc->x_saved; - s->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; 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 (utf8_decode(&vc->utf8_state, &vc->utf8_codepoint, ch))= { + switch (utf8_decode(&vt->utf8_state, &vt->utf8_codepoint, ch))= { case UTF8_ACCEPT: - vc_put_one(vc, unicode_to_cp437(vc->utf8_codepoint)); + vt100_put_one(vt, unicode_to_cp437(vt->utf8_codepoint)); break; case UTF8_REJECT: /* Reset state so the decoder can resync */ - vc->utf8_state =3D UTF8_ACCEPT; + vt->utf8_state =3D UTF8_ACCEPT; break; default: /* Need more bytes */ @@ -834,24 +823,24 @@ static void vc_putchar(VCChardev *vc, int ch) break; } /* ASCII byte: abort any pending UTF-8 sequence */ - vc->utf8_state =3D UTF8_ACCEPT; + vt->utf8_state =3D UTF8_ACCEPT; switch(ch) { case '\r': /* carriage return */ - s->vt.x =3D 0; + vt->x =3D 0; break; case '\n': /* newline */ - vt100_put_lf(&s->vt); + vt100_put_lf(vt); break; case '\b': /* backspace */ - if (s->vt.x > 0) - s->vt.x--; + if (vt->x > 0) + vt->x--; break; case '\t': /* tabspace */ - if (s->vt.x + (8 - (s->vt.x % 8)) > s->vt.width) { - s->vt.x =3D 0; - vt100_put_lf(&s->vt); + if (vt->x + (8 - (vt->x % 8)) > vt->width) { + vt->x =3D 0; + vt100_put_lf(vt); } else { - s->vt.x =3D s->vt.x + (8 - (s->vt.x % 8)); + vt->x =3D vt->x + (8 - (vt->x % 8)); } break; case '\a': /* alert aka. bell */ @@ -864,177 +853,177 @@ 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, s->vt.x, s->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, s->vt.x, s->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, s->vt.x + vc->esc_params[0], s->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, s->vt.x - vc->esc_params[0], s->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, s->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 s->vt.y; y < s->vt.height; y++) { - for (x =3D 0; x < s->vt.width; x++) { - if (y =3D=3D s->vt.y && x < s->vt.x) { + for (y =3D vt->y; y < vt->height; y++) { + for (x =3D 0; x < vt->width; x++) { + if (y =3D=3D vt->y && x < vt->x) { continue; } - vc_clear_xy(vc, x, y); + vt100_clear_xy(vt, x, y); } } break; case 1: /* clear from beginning of screen */ - for (y =3D 0; y <=3D s->vt.y; y++) { - for (x =3D 0; x < s->vt.width; x++) { - if (y =3D=3D s->vt.y && x > s->vt.x) { + for (y =3D 0; y <=3D vt->y; y++) { + for (x =3D 0; x < vt->width; x++) { + if (y =3D=3D vt->y && x > vt->x) { break; } - vc_clear_xy(vc, x, y); + vt100_clear_xy(vt, x, y); } } break; case 2: /* clear entire screen */ - for (y =3D 0; y < s->vt.height; y++) { - for (x =3D 0; x < s->vt.width; x++) { - vc_clear_xy(vc, x, y); + for (y =3D 0; y < vt->height; y++) { + for (x =3D 0; x < vt->width; x++) { + 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 s->vt.x; x < s->vt.width; x++) { - vc_clear_xy(vc, x, s->vt.y); + for(x =3D vt->x; x < vt->width; x++) { + vt100_clear_xy(vt, x, vt->y); } break; case 1: /* clear from beginning of line */ - for (x =3D 0; x <=3D s->vt.x && x < s->vt.width; x++) { - vc_clear_xy(vc, x, s->vt.y); + for (x =3D 0; x <=3D vt->x && x < vt->width; x++) { + vt100_clear_xy(vt, x, vt->y); } break; case 2: /* clear entire line */ - for(x =3D 0; x < s->vt.width; x++) { - vc_clear_xy(vc, x, s->vt.y); + for(x =3D 0; x < vt->width; x++) { + 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", - s->vt.y + 1, s->vt.x + 1); - qemu_text_console_write(s, response, strlen(response)); + vt->y + 1, vt->x + 1); + 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); @@ -1046,10 +1035,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; @@ -1060,7 +1049,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; } } @@ -1081,7 +1070,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *= buf, int len) 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(&s->vt, 1); if (s->vt.update_x0 < s->vt.update_x1) { @@ -1156,9 +1145,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; } @@ -1182,7 +1168,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) @@ -1204,6 +1190,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; @@ -1233,24 +1226,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