From patchwork Fri Feb 2 06:55:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 195658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp256738dyc; Thu, 1 Feb 2024 23:11:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEulg5KNt/n6N6xAGJ2POX6qZCkLB6Ac4hUnx7V5SrOZAEa5Gi4Eazn9JeiwjQu39FEWfR X-Received: by 2002:a17:90b:391:b0:295:f96c:e75a with SMTP id ga17-20020a17090b039100b00295f96ce75amr5809650pjb.14.1706857882520; Thu, 01 Feb 2024 23:11:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706857882; cv=pass; d=google.com; s=arc-20160816; b=RjU+rKAQ1GgNrfekJudqwswpgMXWjbLgX8+cYBwbvz59BrFfekPVz5uwrGdLYHHc8o alI2cXLB/Bkuf6SILzCiaLT6sPshvuEwllQvBQ7wLVP8aNwPK+n749nTIm9RNZIrsckW /JPKNNz6bQCNWAcWIBcKM1I0+jNg12TcZ6wtIBVALXRb98v+9bmG+SX+RrCWAc7oV+mI yS0mfUr0F1UDIU5KZ6kl0A8KaXSra5NK2kCTkqx0mMEbAGc2TOf9WvUN87sOh3CsDAnG +0p2vstxF8/e/9hQBRM0fdJwJqCjxft5e/nCi4kTQp+caubb75xFfZVqcIV2aTdR+hvA 41wQ== 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=LdQdMx8J86oWD8e5WvQuJF65re5wEZzL9DxS2VXXpow=; fh=MOT8GDHdkQgaV86HZSghw4n+TTxQ58/1qiYt05HKUtA=; b=i8fIR2MI96WNbhlT/jxZqCIv/OdIxAk1ByKMDqdc7Tgkw2ICxvUc+zzbUCii6AvqYs BE3tWy2Y1uo8Qq7bjjO8LMjTJzfTFap0W5mtsw0O7InCTzfq9KekKp//jyUzIR29030a pnfz8cThGiMboHVAzxymJrJiuaJaKFSPipgs18epfR3UvCG4gUGQZKatcOhZ/jIfrFBQ /lVTA1sV14ckz89qSVVNdyGbtiComuAXcN0y1tP4Lp8CFDrgjLHTbY1FEZB2AYNIYZrJ xj386haQckHLVrEBoLhUXbSEfxdulxjpH3LvIVlDww/XLRV95ZMC6XwKAYJypYJ+RKJq KXGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mmAdHWvh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49328-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUqjFoSeQbXKB1Bi5vRh2gBu7vyj5MxlQkbENOc/U+h5o/HgtKZv4subT7PSDr7GNiawOp/35AaJfHvkFTn8q9XBuvtgA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q65-20020a17090a754700b0029612f11aa1si3040166pjk.99.2024.02.01.23.11.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 23:11:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mmAdHWvh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49328-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AE62EB23AF9 for ; Fri, 2 Feb 2024 06:59:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BB104207B; Fri, 2 Feb 2024 06:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mmAdHWvh" 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 A88353FB14; Fri, 2 Feb 2024 06:56:30 +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=1706856990; cv=none; b=rFcZ0fem9FpWC85WQjPnrYPY8bCNDTVTCxR9LYbMKpUr6g995lYB0B6jEPl7jJNpiRBcoVF26G7UXOSA81U+zdp/71WO+paKFYBwEhrqlb8aDRvDvnUKQyQvR3iCmrNqPCYiWKKKeJjSCCujqCur3QN1qTEokxULvlVdU6t54n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856990; c=relaxed/simple; bh=dwhJ8tMD7utmbBdUx26kvWGDI4UoU+Gd4+oVhddQzgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O3O2oojnJ9h89H6YExhM1VSgHJybXxs9QJUbFbTjxTPpLI+nW24Ocb4tOorRDot/Ubyc3B2lAO6YOb3z8rVvAtXMFz9ok9zHsgapU2AtWiLB9LDloPBTvIjUof+3z9Wm1c6IXpJRluXya8kSA0GfSI0XcUtQQtpPD/WhpCUnT3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mmAdHWvh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05814C43394; Fri, 2 Feb 2024 06:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706856990; bh=dwhJ8tMD7utmbBdUx26kvWGDI4UoU+Gd4+oVhddQzgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmAdHWvhdhtg/J5rP85q53ofa/qN9bxxDAO2wfkpsuY2rWfapAMMM7o7mj6bZ8f2l DOtQ7ozjMU7hkPT/nz4H2OpIB6zE8d604cgJIDyL3hVK9KPJXdrCeG+C+OUVWmIxUU t9emzr1wV5Qo+7DezY0b9Jzu2nR5xu0iHIw2Qgmvfkk4FTB10VdmeiDotVF11ZfPPW 5B/GTowEvG22ZXeu0NlWAhqrAlcKIT2OJkbucTXgbmhUp/hUMBbsNBGNMhLwhCasL2 a8ZkM0nCYVWho1EsJarmzx45NtRZLEVNsVaAxXoPxsn1V9FTOdW+1HYwetHuxZnxTG E7XN0m5o5rvzQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 12/22] tty: vt: separate ESesc state handling into handle_esc() Date: Fri, 2 Feb 2024 07:55:58 +0100 Message-ID: <20240202065608.14019-13-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: 1789770210697540255 X-GMAIL-MSGID: 1789770210697540255 Similar to the ASCII handling, the ESC handling can be easily moved away from do_con_trol(). So create a new handle_esc() for that. And add a comment with an example. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/vt.c | 134 ++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 7cda1a958c5e..3dddb7128234 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -2267,6 +2267,77 @@ static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c) return false; } +/* + * Handle a character (@c) following an ESC (when @vc is in the ESesc state). + * E.g. previous ESC with @c == '[' here yields the ESsquare state (that is: + * CSI). + */ +static void handle_esc(struct tty_struct *tty, struct vc_data *vc, u8 c) +{ + vc->vc_state = ESnormal; + switch (c) { + case '[': + vc->vc_state = ESsquare; + break; + case ']': + vc->vc_state = ESnonstd; + break; + case '_': + vc->vc_state = ESapc; + break; + case '^': + vc->vc_state = ESpm; + break; + case '%': + vc->vc_state = ESpercent; + break; + case 'E': + cr(vc); + lf(vc); + break; + case 'M': + ri(vc); + break; + case 'D': + lf(vc); + break; + case 'H': + if (vc->state.x < VC_TABSTOPS_COUNT) + set_bit(vc->state.x, vc->vc_tab_stop); + break; + case 'P': + vc->vc_state = ESdcs; + break; + case 'Z': + respond_ID(tty); + break; + case '7': + save_cur(vc); + break; + case '8': + restore_cur(vc); + break; + case '(': + vc->vc_state = ESsetG0; + break; + case ')': + vc->vc_state = ESsetG1; + break; + case '#': + vc->vc_state = EShash; + break; + case 'c': + reset_terminal(vc, 1); + break; + case '>': /* Numeric keypad */ + clr_kbd(vc, kbdapplic); + break; + case '=': /* Appl. keypad */ + set_kbd(vc, kbdapplic); + break; + } +} + /* console_lock is held */ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) { @@ -2283,68 +2354,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) switch(vc->vc_state) { case ESesc: - vc->vc_state = ESnormal; - switch (c) { - case '[': - vc->vc_state = ESsquare; - return; - case ']': - vc->vc_state = ESnonstd; - return; - case '_': - vc->vc_state = ESapc; - return; - case '^': - vc->vc_state = ESpm; - return; - case '%': - vc->vc_state = ESpercent; - return; - case 'E': - cr(vc); - lf(vc); - return; - case 'M': - ri(vc); - return; - case 'D': - lf(vc); - return; - case 'H': - if (vc->state.x < VC_TABSTOPS_COUNT) - set_bit(vc->state.x, vc->vc_tab_stop); - return; - case 'P': - vc->vc_state = ESdcs; - return; - case 'Z': - respond_ID(tty); - return; - case '7': - save_cur(vc); - return; - case '8': - restore_cur(vc); - return; - case '(': - vc->vc_state = ESsetG0; - return; - case ')': - vc->vc_state = ESsetG1; - return; - case '#': - vc->vc_state = EShash; - return; - case 'c': - reset_terminal(vc, 1); - return; - case '>': /* Numeric keypad */ - clr_kbd(vc, kbdapplic); - return; - case '=': /* Appl. keypad */ - set_kbd(vc, kbdapplic); - return; - } + handle_esc(tty, vc, c); return; case ESnonstd: if (c=='P') { /* palette escape sequence */