From patchwork Wed Jul 8 00:44:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 50853 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 820CF229FC for ; Wed, 8 Jul 2015 00:45:00 +0000 (UTC) Received: by lbcpe5 with SMTP id pe5sf19796521lbc.3 for ; Tue, 07 Jul 2015 17:44:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=QEU6fXTKJGUkTZi/5OjrMllXmc2UdMe3ynEs/tSV7As=; b=SAQVOLAVk6u0vikpoBVvJ2Z2O2eH1M9vKjM0XS2QjF3f3cqMr7DtaMf8wj65AcH9Pe 0ZhjM5JY9gWfVQpy+QqYCvT2IlM4mkFmmglMn2lNiQOY58wrW+cpEXUKuJlfWRrBq1Hx Gpflqr0Nw3Ej1QlqyIoSFTVJ3RfAGFVSCsm8d17YEWsOxBAc/57kwUwvthqwBoCC5lck ROgXq74jZljIx0h2CIT9LxcetYZi4yiiKca/PUiEx1v49k1as+mXAHly29cQGipFbeIz gcKCu1YHdkSyOTHcXZFipLvhswoEhbcFhpKl8pRCfB6Cfb+ABeCpK82F+Qx4FiMxlKzH pklA== X-Gm-Message-State: ALoCoQmDyGpif1NHikIu+pZ7fPrpNFqvh1pWbatKj4ed8KUXvLZCl5hbmcgmy7TXSnXZ3zWT8wVe X-Received: by 10.152.120.69 with SMTP id la5mr3393172lab.7.1436316299471; Tue, 07 Jul 2015 17:44:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.201 with SMTP id t9ls821006laa.95.gmail; Tue, 07 Jul 2015 17:44:59 -0700 (PDT) X-Received: by 10.152.1.66 with SMTP id 2mr4788431lak.56.1436316299314; Tue, 07 Jul 2015 17:44:59 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id z10si268131lal.8.2015.07.07.17.44.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 17:44:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbcpe5 with SMTP id pe5so46672511lbc.2 for ; Tue, 07 Jul 2015 17:44:58 -0700 (PDT) X-Received: by 10.152.88.77 with SMTP id be13mr6367031lab.112.1436316298510; Tue, 07 Jul 2015 17:44:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2725750lbb; Tue, 7 Jul 2015 17:44:57 -0700 (PDT) X-Received: by 10.50.33.18 with SMTP id n18mr18911372igi.26.1436316293428; Tue, 07 Jul 2015 17:44:53 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id p128si915782ioe.59.2015.07.07.17.44.52 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jul 2015 17:44:53 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCdTf-00073G-Vz; Wed, 08 Jul 2015 00:44:44 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCdTe-000733-Dc for edk2-devel@lists.sourceforge.net; Wed, 08 Jul 2015 00:44:42 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.220.47 as permitted sender) client-ip=209.85.220.47; envelope-from=roy.franz@linaro.org; helo=mail-pa0-f47.google.com; Received: from mail-pa0-f47.google.com ([209.85.220.47]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ZCdTd-0001wQ-7a for edk2-devel@lists.sourceforge.net; Wed, 08 Jul 2015 00:44:42 +0000 Received: by pabvl15 with SMTP id vl15so121457431pab.1 for ; Tue, 07 Jul 2015 17:44:35 -0700 (PDT) X-Received: by 10.70.88.43 with SMTP id bd11mr14165440pdb.7.1436316275593; Tue, 07 Jul 2015 17:44:35 -0700 (PDT) Received: from localhost.localdomain (c-73-41-93-56.hsd1.ca.comcast.net. [73.41.93.56]) by smtp.gmail.com with ESMTPSA id tm3sm337917pac.44.2015.07.07.17.44.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jul 2015 17:44:34 -0700 (PDT) From: Roy Franz To: edk2-devel@lists.sourceforge.net, feng.tian@intel.com, lersek@redhat.com, ard.biesheuvel@linaro.org Date: Tue, 7 Jul 2015 17:44:16 -0700 Message-Id: <1436316258-19655-4-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436316258-19655-1-git-send-email-roy.franz@linaro.org> References: <1436316258-19655-1-git-send-email-roy.franz@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1ZCdTd-0001wQ-7a Subject: [edk2] [PATCH V3 3/5] Accept VT220 DEL and function keys for TTY terminal type X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Accept the VT220 escape code [3~ as backspace for TtyTerm terminals. This is sent by many Linux terminals by default. Also accept VT220 function keys F1-F12, and VT100 F1-F4 keys as these are commonly sent by Linux terminals. The VT220 escape codes are longer, and variable length so a new state is added to the state machine along with a variable to construct the multibyte escape sequence. There are currently no ambiguous escape sequence prefixes accepted, so the TTY terminal accepts escape sequences for a variety of terminals. The goal is to 'just work' with as many terminals as possible, rather than properly emulating any specific terminal. Backspace, Del, and F10 have been tested on xterm, rxvt, tmux, and screen. Note: The existing vt100 function key handling does not match the vt100 documentation that I found, so I added the TTY terminal handling of VT100 F1-F4 (really PF1-PF4 on vt100) separately. The vt100 has no F5-F10 keys, so I don't know what the current vt100 code is based on. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Roy Franz --- MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c | 6 ++ MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h | 3 + MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c | 93 +++++++++++++++++++- 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c index babb097..597b15d 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -81,6 +81,12 @@ TERMINAL_DEV mTerminalDevTemplate = { NULL, // TwoSecondTimeOut INPUT_STATE_DEFAULT, RESET_STATE_DEFAULT, + { + 0, + 0, + 0 + }, + 0, FALSE, { // SimpleTextInputEx TerminalConInResetEx, diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h index 03542a4..269d2ae 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h @@ -99,6 +99,8 @@ typedef struct { EFI_EVENT TwoSecondTimeOut; UINT32 InputState; UINT32 ResetState; + UINT16 TtyEscapeStr[3]; + INTN TtyEscapeIndex; // // Esc could not be output to the screen by user, @@ -118,6 +120,7 @@ typedef struct { #define INPUT_STATE_LEFTOPENBRACKET 0x04 #define INPUT_STATE_O 0x08 #define INPUT_STATE_2 0x10 +#define INPUT_STATE_LEFTOPENBRACKET_2 0x20 #define RESET_STATE_DEFAULT 0x00 #define RESET_STATE_ESC_R 0x01 diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c index 227df85..fbaf33b 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c @@ -1223,7 +1223,8 @@ UnicodeToEfiKey ( continue; } - if (UnicodeChar == 'O' && TerminalDevice->TerminalType == VT100TYPE) { + if (UnicodeChar == 'O' && (TerminalDevice->TerminalType == VT100TYPE || + TerminalDevice->TerminalType == TTYTERMTYPE)) { TerminalDevice->InputState |= INPUT_STATE_O; TerminalDevice->ResetState = RESET_STATE_DEFAULT; continue; @@ -1371,6 +1372,22 @@ UnicodeToEfiKey ( default : break; } + } else if (TerminalDevice->TerminalType == TTYTERMTYPE) { + /* Also accept VT100 escape codes for F1-F4 for TTY term */ + switch (UnicodeChar) { + case 'P': + Key.ScanCode = SCAN_F1; + break; + case 'Q': + Key.ScanCode = SCAN_F2; + break; + case 'R': + Key.ScanCode = SCAN_F3; + break; + case 'S': + Key.ScanCode = SCAN_F4; + break; + } } if (Key.ScanCode != SCAN_NULL) { @@ -1514,6 +1531,21 @@ UnicodeToEfiKey ( } } + /* + * The VT220 escape codes that the TTY terminal accepts all have + * numeric codes, and there are no ambiguous prefixes shared with + * other terminal types. + */ + if (TerminalDevice->TerminalType == TTYTERMTYPE && + Key.ScanCode == SCAN_NULL && + UnicodeChar >= '0' && + UnicodeChar <= '9') { + TerminalDevice->TtyEscapeStr[0] = UnicodeChar; + TerminalDevice->TtyEscapeIndex = 1; + TerminalDevice->InputState |= INPUT_STATE_LEFTOPENBRACKET_2; + continue; + } + if (Key.ScanCode != SCAN_NULL) { Key.UnicodeChar = 0; EfiKeyFiFoInsertOneKey (TerminalDevice, &Key); @@ -1527,6 +1559,65 @@ UnicodeToEfiKey ( break; + case INPUT_STATE_ESC | INPUT_STATE_LEFTOPENBRACKET | INPUT_STATE_LEFTOPENBRACKET_2: + /* + * Here we handle the VT220 escape codes that we accept. This + * state is only used by the TTY terminal type. + */ + Key.ScanCode = SCAN_NULL; + if (TerminalDevice->TerminalType == TTYTERMTYPE) { + + if (UnicodeChar == '~' && TerminalDevice->TtyEscapeIndex <= 2) { + UINTN EscCode; + TerminalDevice->TtyEscapeStr[TerminalDevice->TtyEscapeIndex] = 0; /* Terminate string */ + EscCode = StrDecimalToUintn(TerminalDevice->TtyEscapeStr); + switch (EscCode) { + case 3: + Key.ScanCode = SCAN_DELETE; + break; + case 11: + case 12: + case 13: + case 14: + case 15: + Key.ScanCode = SCAN_F1 + EscCode - 11; + break; + case 17: + case 18: + case 19: + case 20: + case 21: + Key.ScanCode = SCAN_F6 + EscCode - 17; + break; + case 23: + case 24: + Key.ScanCode = SCAN_F11 + EscCode - 23; + break; + default: + break; + } + } else if (TerminalDevice->TtyEscapeIndex == 1){ + /* 2 character escape code */ + TerminalDevice->TtyEscapeStr[TerminalDevice->TtyEscapeIndex++] = UnicodeChar; + continue; + } + else { + DEBUG ((EFI_D_ERROR, "Unexpected state in escape2\n")); + } + } + TerminalDevice->ResetState = RESET_STATE_DEFAULT; + + if (Key.ScanCode != SCAN_NULL) { + Key.UnicodeChar = 0; + EfiKeyFiFoInsertOneKey (TerminalDevice, &Key); + TerminalDevice->InputState = INPUT_STATE_DEFAULT; + UnicodeToEfiKeyFlushState (TerminalDevice); + continue; + } + + UnicodeToEfiKeyFlushState (TerminalDevice); + break; + default: // // Invalid state. This should never happen.