From patchwork Wed Jul 8 19:02:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 50908 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DCF7213FD for ; Wed, 8 Jul 2015 19:03:36 +0000 (UTC) Received: by wgbbj7 with SMTP id bj7sf73342683wgb.2 for ; Wed, 08 Jul 2015 12:03:35 -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=Z+itYgBaPVpSHwB4nVbejKidoZrChK/I6MxLGrDg0aliumbFk1aCpIQlnUJjEvvPdH mGftvTd8FrrOzu+CALK+N1bFcW8tV5sQca2oSkX4+BhdcbTIGwy+uOMacVNKrdV+Qe8P zMjrSvBGedxVJLEEFhB/l4z8/ibsUFSFYe3ZliNvxAC8Bd6dhUkPsR4FTy8XCg/URfew 7H8Ak2FThUXCyNwxmZIZWPkaK4R/grTFkJfykxI1MzA8SxlOuV21dAeQpoJTi1hLoSis 5t1tkV8t58zRuWCXWBaAzfp+wVrA7mr/9GJ+kowANMhYT/BAQi6+g1+mx7HLHmxaB6S8 atPQ== X-Gm-Message-State: ALoCoQmk8Vxk/3O81PueLqYyRySsuCZHVz61knWc6VtE/sH1SBAO2Pk6V06N2g92c+vVLJz/BZFt X-Received: by 10.180.83.33 with SMTP id n1mr16641885wiy.4.1436382215760; Wed, 08 Jul 2015 12:03:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.73 with SMTP id j9ls252674lag.73.gmail; Wed, 08 Jul 2015 12:03:35 -0700 (PDT) X-Received: by 10.152.27.197 with SMTP id v5mr11060559lag.64.1436382215583; Wed, 08 Jul 2015 12:03:35 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id dx9si2372701lac.160.2015.07.08.12.03.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2015 12:03:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lagc2 with SMTP id c2so228833803lag.3 for ; Wed, 08 Jul 2015 12:03:35 -0700 (PDT) X-Received: by 10.112.220.7 with SMTP id ps7mr10942848lbc.72.1436382215283; Wed, 08 Jul 2015 12:03:35 -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 hn6csp153118lbb; Wed, 8 Jul 2015 12:03:34 -0700 (PDT) X-Received: by 10.107.132.153 with SMTP id o25mr4597154ioi.36.1436382209740; Wed, 08 Jul 2015 12:03:29 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id z20si20864729igq.11.2015.07.08.12.03.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 Jul 2015 12:03:29 -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-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCuco-0002U0-3w; Wed, 08 Jul 2015 19:03:18 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCucm-0002Tr-Vv for edk2-devel@lists.sourceforge.net; Wed, 08 Jul 2015 19:03:16 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.192.180 as permitted sender) client-ip=209.85.192.180; envelope-from=roy.franz@linaro.org; helo=mail-pd0-f180.google.com; Received: from mail-pd0-f180.google.com ([209.85.192.180]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ZCucl-0006o2-Ms for edk2-devel@lists.sourceforge.net; Wed, 08 Jul 2015 19:03:16 +0000 Received: by pdrg1 with SMTP id g1so18859747pdr.2 for ; Wed, 08 Jul 2015 12:03:10 -0700 (PDT) X-Received: by 10.70.49.73 with SMTP id s9mr23104180pdn.149.1436382190059; Wed, 08 Jul 2015 12:03:10 -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 nk1sm3322254pdb.36.2015.07.08.12.03.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jul 2015 12:03:08 -0700 (PDT) From: Roy Franz To: edk2-devel@lists.sourceforge.net, feng.tian@intel.com, lersek@redhat.com, ard.biesheuvel@linaro.org Date: Wed, 8 Jul 2015 12:02:50 -0700 Message-Id: <1436382172-27491-4-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436382172-27491-1-git-send-email-roy.franz@linaro.org> References: <1436382172-27491-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 -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1ZCucl-0006o2-Ms Subject: [edk2] [PATCH V4 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.215.42 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.