From patchwork Fri Feb 2 06:56:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 195647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp251938dyc; Thu, 1 Feb 2024 23:00:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzqrRvhut/nCM2jONRTXJpJgPvvJgBKyuUoeaddePcSKQcmgjOW0pH1bMeSADSFgriX8B/ X-Received: by 2002:a05:6808:1289:b0:3bd:36fc:1c1e with SMTP id a9-20020a056808128900b003bd36fc1c1emr1485253oiw.44.1706857233800; Thu, 01 Feb 2024 23:00:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706857233; cv=pass; d=google.com; s=arc-20160816; b=gP9mbEzc1pEP13o7t7g2bo1FXhXjw7Qj4lw5fjYyjEaBhoB3VaZ7Ixn6uGxS1ship2 mX2xdhw2A9ZsGvNtX1D/HoxLl8AjhmjeYZj+bU40PDTvWVi4sf33AW2NIAEu1rgCVC7G 3FkoRiGS6ddhYcXatfDzFbBeXLB//Dh+3FJdGs8/AqEFRMEelaA/tbC5xkN1qqLPLNsd rAFEIanY8TxwaDZdY7uRjbTk/+cFiyevYLEApiIsXqQ4k0yBy2OKr2FkNWAbIL0vSNSF 51MQJX8k64zRllfIeqLu6FSfmTj7FQGGDAmRRgJOWv9dYqddAJsbAhXkfR4Wr2QAStzB Gf8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=A3FN0v+b1+yprubsR5ZF0UFk06RD9LjcpeoCz5/Nl5A=; fh=5wL9Jnx2aYTorMXAe9zEx9HWRZ40x0vl7LAFVm0Punk=; b=xF2g4jrSaLU/LHI28C9oE/KTQi2Uf0+3fGRlCBjJ/xUmHc/yyj38jc+vYNGrRi4EL/ fHIklVtgSb6UTdPcOVMMOnvRuzMIzIzXEpV++xQYlICdpIQxinFTRKaKguzZWVOj8WpP LSUh09XB3e79T5kTUH2tesvN7YxoR0qOibAdOBlvjeIJap0OMLSGzfxYDA0dwI3tWqvm hlulD3EE+Ci/yVe/pb150qlpq8rQ9N8ruvX8tedVYsdx6Arls8738V3ZceMLv0hBSu69 EJr1A/q+WUX4YusBMqhe+uDYhr/2vnnxY/D1SaRs1EKV0l6QOnGBz6cAoW5zwWrCrTBM T5XQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tWApjrEh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49330-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49330-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWPnBkywp3UaYwsBWwvKt/c88XUebjKXX17WK7zKapOM/E5lPQblFVuG2xTN8/Bjw6OoiZQ4MFCjrlex+Dirpq30OD8Tg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p16-20020a05622a00d000b0042bff035730si1371834qtw.162.2024.02.01.23.00.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 23:00:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49330-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tWApjrEh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49330-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49330-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 84B2A1C21E9F for ; Fri, 2 Feb 2024 07:00:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1240481BD; Fri, 2 Feb 2024 06:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tWApjrEh" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7769342A8C; Fri, 2 Feb 2024 06:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856993; cv=none; b=EMjy/K6BU+4ySmZL564kcr7nW1gpGZQqTtGWF5OIyn+8mwOoRI9iYOMWhTlMPYJ2u5H79I369WDQdzru+JtflzLQPmaSds95qwCgZGUVNWSW9eE9XhCvQc4cckjVnKxVT3luLz0ohQZhGYQGPp5QJmmgmewnj7DWVISjUSnvyUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856993; c=relaxed/simple; bh=2KcL2ijyRKHlKaD+KC9TeZ0POGrQVYsHbeWSN8pgPQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Am2AyS4mE8KaBdc5SC7FC2AS/ERqv551FZglKxBhWG4CSp/27v11Idik/Au6Pyhu3FWKTu6Z0vGDJNgdFJ2hG+PRmIYQQxGYS5k3ruFwB9e0AWViC0OOPuzKHbsA2FSKp9GetOpZkm/rRO7gbN+GUg69sTvP8LpNBQfiJn3Rq2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tWApjrEh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0772CC433F1; Fri, 2 Feb 2024 06:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706856993; bh=2KcL2ijyRKHlKaD+KC9TeZ0POGrQVYsHbeWSN8pgPQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tWApjrEhNdAFoMhUQ5jOlLTZ8nZVO9Hnwzqy/IQfCJ+ZJvbHHypYV67Q9q5KS20PL XcmGX1GFlKt7VsJCVjgW5S4lLSZWIGhz+Bn3j9U5WwJMqRU9kNZuJd6PgBzkHU9SiU Gh+FS+BO5iOuP5Oz9tCOa/SBVkIfau2NCLpGi5YNh3KsY5okVcEv0n/dWoLFdh13JU MvT/nDLGUOrm5VjuyE8MZgRvCj3TtFQ5UQOyIVQrHAcZz7letqa2cqG0iss7xZWnL7 sNzMPybXhLrqVrgCQWS2J5pjtsSEsR6rqSETPrmhYhrheE++c4e4FC9SetN1YuR4gj 4K7sksHHxAffg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 14/22] tty: vt: move CSI ECMA handling to a separate function Date: Fri, 2 Feb 2024 07:56:00 +0100 Message-ID: <20240202065608.14019-15-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202065608.14019-1-jirislaby@kernel.org> References: <20240202065608.14019-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789769530783796649 X-GMAIL-MSGID: 1789769530783796649 Similar to previous moves, move also "CSI ..." (i.e. vc_priv == EPecma) handling to a separate function. This is the last large move of code out of do_con_trol(). And despite it is still 151 lines of code (down from 407!), it is now quite easy to folllow the transitions of the state machine in there. ESnonstd and ESpalette handling still can be moved away, but it won't improve that much. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/vt.c | 269 +++++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 130 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 7cdd0eb1e423..1c832d04c0dc 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -2375,6 +2375,143 @@ static void csi_DEC(struct tty_struct *tty, struct vc_data *vc, u8 c) } } +/* + * Handle Control Sequence Introducer control characters. That is + * "ESC [ parameters char". Parameters are in @vc->vc_par and the char is in + * @c here. + */ +static void csi_ECMA(struct tty_struct *tty, struct vc_data *vc, u8 c) +{ + switch (c) { + case 'G': + case '`': + if (vc->vc_par[0]) + vc->vc_par[0]--; + gotoxy(vc, vc->vc_par[0], vc->state.y); + break; + case 'A': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]); + break; + case 'B': + case 'e': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]); + break; + case 'C': + case 'a': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y); + break; + case 'D': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y); + break; + case 'E': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, 0, vc->state.y + vc->vc_par[0]); + break; + case 'F': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, 0, vc->state.y - vc->vc_par[0]); + break; + case 'd': + if (vc->vc_par[0]) + vc->vc_par[0]--; + gotoxay(vc, vc->state.x ,vc->vc_par[0]); + break; + case 'H': + case 'f': + if (vc->vc_par[0]) + vc->vc_par[0]--; + if (vc->vc_par[1]) + vc->vc_par[1]--; + gotoxay(vc, vc->vc_par[1], vc->vc_par[0]); + break; + case 'J': + csi_J(vc, vc->vc_par[0]); + break; + case 'K': + csi_K(vc); + break; + case 'L': + csi_L(vc); + break; + case 'M': + csi_M(vc); + break; + case 'P': + csi_P(vc); + break; + case 'c': + if (!vc->vc_par[0]) + respond_ID(tty); + break; + case 'g': + if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT) + set_bit(vc->state.x, vc->vc_tab_stop); + else if (vc->vc_par[0] == 3) + bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); + break; + case 'h': + csi_hl(vc, true); + break; + case 'l': + csi_hl(vc, false); + break; + case 'm': + csi_m(vc); + break; + case 'n': + if (vc->vc_par[0] == 5) + status_report(tty); + else if (vc->vc_par[0] == 6) + cursor_report(vc, tty); + break; + case 'q': /* DECLL - but only 3 leds */ + /* map 0,1,2,3 to 0,1,2,4 */ + if (vc->vc_par[0] < 4) + vt_set_led_state(vc->vc_num, + (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); + break; + case 'r': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + if (!vc->vc_par[1]) + vc->vc_par[1] = vc->vc_rows; + /* Minimum allowed region is 2 lines */ + if (vc->vc_par[0] < vc->vc_par[1] && + vc->vc_par[1] <= vc->vc_rows) { + vc->vc_top = vc->vc_par[0] - 1; + vc->vc_bottom = vc->vc_par[1]; + gotoxay(vc, 0, 0); + } + break; + case 's': + save_cur(vc); + break; + case 'u': + restore_cur(vc); + break; + case 'X': + csi_X(vc); + break; + case '@': + csi_at(vc, vc->vc_par[0]); + break; + case ']': + csi_RSB(vc); + break; + } + +} + /* console_lock is held */ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) { @@ -2470,139 +2607,11 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) csi_DEC(tty, vc, c); return; case EPecma: - break; - default: - return; - } - - switch(c) { - case 'G': - case '`': - if (vc->vc_par[0]) - vc->vc_par[0]--; - gotoxy(vc, vc->vc_par[0], vc->state.y); - return; - case 'A': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]); - return; - case 'B': - case 'e': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]); - return; - case 'C': - case 'a': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y); - return; - case 'D': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y); - return; - case 'E': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, 0, vc->state.y + vc->vc_par[0]); + csi_ECMA(tty, vc, c); return; - case 'F': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - gotoxy(vc, 0, vc->state.y - vc->vc_par[0]); - return; - case 'd': - if (vc->vc_par[0]) - vc->vc_par[0]--; - gotoxay(vc, vc->state.x ,vc->vc_par[0]); - return; - case 'H': - case 'f': - if (vc->vc_par[0]) - vc->vc_par[0]--; - if (vc->vc_par[1]) - vc->vc_par[1]--; - gotoxay(vc, vc->vc_par[1], vc->vc_par[0]); - return; - case 'J': - csi_J(vc, vc->vc_par[0]); - return; - case 'K': - csi_K(vc); - return; - case 'L': - csi_L(vc); - return; - case 'M': - csi_M(vc); - return; - case 'P': - csi_P(vc); - return; - case 'c': - if (!vc->vc_par[0]) - respond_ID(tty); - return; - case 'g': - if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT) - set_bit(vc->state.x, vc->vc_tab_stop); - else if (vc->vc_par[0] == 3) - bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); - return; - case 'h': - csi_hl(vc, true); - return; - case 'l': - csi_hl(vc, false); - return; - case 'm': - csi_m(vc); - return; - case 'n': - if (vc->vc_par[0] == 5) - status_report(tty); - else if (vc->vc_par[0] == 6) - cursor_report(vc, tty); - return; - case 'q': /* DECLL - but only 3 leds */ - /* map 0,1,2,3 to 0,1,2,4 */ - if (vc->vc_par[0] < 4) - vt_set_led_state(vc->vc_num, - (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); - return; - case 'r': - if (!vc->vc_par[0]) - vc->vc_par[0]++; - if (!vc->vc_par[1]) - vc->vc_par[1] = vc->vc_rows; - /* Minimum allowed region is 2 lines */ - if (vc->vc_par[0] < vc->vc_par[1] && - vc->vc_par[1] <= vc->vc_rows) { - vc->vc_top = vc->vc_par[0] - 1; - vc->vc_bottom = vc->vc_par[1]; - gotoxay(vc, 0, 0); - } - return; - case 's': - save_cur(vc); - return; - case 'u': - restore_cur(vc); - return; - case 'X': - csi_X(vc); - return; - case '@': - csi_at(vc, vc->vc_par[0]); - return; - case ']': - csi_RSB(vc); + default: return; } - return; case EScsiignore: if (c >= ASCII_CSI_IGNORE_FIRST && c <= ASCII_CSI_IGNORE_LAST) return;