From nobody Mon May 20 04:08:49 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VjPFZ092jz5LhQx; Mon, 20 May 2024 04:08:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VjPFY4PBgz4D6L; Mon, 20 May 2024 04:08:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716178129; 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; bh=rXTGZsUyL6UQIRWta+luiDoqz38a+V9p/xUveJlm+z0=; b=rPHpcGl1Ps8wKX/Yu/G2fD7E+FPFtWiX584tlp+M9EbZpAzgS4SEJOTeN0A1J3gr6O4mJ8 F5ywiffXYJfZDQ6AN2rclXwo/NyZW9IeQws0AlAPFDx3y+Al0JbbH3HWWla45jE23XVv2t KfiBZf3zpeaD9bv6QMxdgfA1HP1iQr2ve8OAfnznLSsNLJ3HkW7SlWl8urKBSk6og+GfkN 8SRFhPcOrvy5zSrgWgkMyZgQ6m552RE+lCmZkXCLcowoGkdnBa2UX6OA3cuUxCU80TD1AK 1oaLIlyiJyajGrMxJWMne4wml33m2riOSYlFGE6lasAQpRy/K+aoT5hRqFQXLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716178129; a=rsa-sha256; cv=none; b=q5gIs/gI+yj22rHHNa8Fm5+wjfERvP/EJ/A9XySD+MpcP2jqRKSig8QBmJrlC2xtLL+6Iw BQq6mN1T/mn4h0u6cG9T5p/9wAIfz3qCeG5tyrbKT1DB4IeW+spMCwPKUtJ0UOS2r4odjb g2Uvdp7+EZJjgESaYc+kWETLT3gQhUBEdW3ERYMsiXCH8pxyAEnmD7Atev8ZSGSD4Z69Mq 2uBGneGOM5w4TAO/UPeS65qYOlg2/1OKx24iIzfHmcdkx0u0xCJOcsVy+ch1DalipN7Qki S5btbnfaDwM7fc1jHaKv9Jl5nR1Qjz0Y6xJUft/x9xtLo6Pa1PhiZR6gZG6GUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716178129; 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; bh=rXTGZsUyL6UQIRWta+luiDoqz38a+V9p/xUveJlm+z0=; b=CobJfdheyn9k9/rPRO2SQHXY+1AggkteA6AokWQnoOKe68Td5GimmIQkWNhNnAeYg8TDzw HuJL9hsb8S7zUQXt1ORsK4XXewZLykkKcDheinTi8oY5NGzgSVn5BJeA7uhgm7aEGre23h QAD0NYf+Btf0TE24r3iXEOWytM7d8abGE92v3EdPyF4H0fAAQlpL60/dwzKpDLJIT3Xeyw lG2KdzrCQMd3JG/lGeqIbgMctLS90sIpwgd4WVjtd5Jl0AT8CQEOetim2sAMBvr6NFYMPj IXrYfZIYuRjXV5sc6MaWppzxn+teqJqrrArU63CitN/GdvFXQzb0uqL/SRMx6w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VjPFY3zyZzNB9; Mon, 20 May 2024 04:08:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44K48noB081723; Mon, 20 May 2024 04:08:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44K48n1f081720; Mon, 20 May 2024 04:08:49 GMT (envelope-from git) Date: Mon, 20 May 2024 04:08:49 GMT Message-Id: <202405200408.44K48n1f081720@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 861f802b3eba - main - textvidc: Reindent List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 861f802b3ebaf05075c6dd8be25f802c3e6527b6 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=861f802b3ebaf05075c6dd8be25f802c3e6527b6 commit 861f802b3ebaf05075c6dd8be25f802c3e6527b6 Author: Warner Losh AuthorDate: 2024-05-19 21:18:58 +0000 Commit: Warner Losh CommitDate: 2024-05-20 04:05:43 +0000 textvidc: Reindent Since this is now 'new code' go ahead and reindent for modern project preferences. Sponsored by: Netflix --- stand/i386/libi386/textvidc.c | 683 +++++++++++++++++++++--------------------- 1 file changed, 343 insertions(+), 340 deletions(-) diff --git a/stand/i386/libi386/textvidc.c b/stand/i386/libi386/textvidc.c index 75d498930119..1dd950bc4021 100644 --- a/stand/i386/libi386/textvidc.c +++ b/stand/i386/libi386/textvidc.c @@ -82,112 +82,112 @@ struct console textvidc = { static void vidc_probe(struct console *cp) { - /* look for a keyboard */ + /* look for a keyboard */ #if KEYBOARD_PROBE - if (probe_keyboard()) + if (probe_keyboard()) #endif - { - cp->c_flags |= C_PRESENTIN; - } + { + cp->c_flags |= C_PRESENTIN; + } - /* XXX for now, always assume we can do BIOS screen output */ - cp->c_flags |= C_PRESENTOUT; + /* XXX for now, always assume we can do BIOS screen output */ + cp->c_flags |= C_PRESENTOUT; } static int vidc_init(int arg) { - int i; + int i; - if (vidc_started && arg == 0) - return (0); - vidc_started = 1; + if (vidc_started && arg == 0) + return (0); + vidc_started = 1; #ifdef TERM_EMU - /* Init terminal emulator */ - end_term(); - get_pos(&curx, &cury); - curs_move(&curx, &cury, curx, cury); - fg_c = DEFAULT_FGCOLOR; - bg_c = DEFAULT_BGCOLOR; + /* Init terminal emulator */ + end_term(); + get_pos(&curx, &cury); + curs_move(&curx, &cury, curx, cury); + fg_c = DEFAULT_FGCOLOR; + bg_c = DEFAULT_BGCOLOR; #endif - for (i = 0; i < 10 && vidc_ischar(); i++) - (void)vidc_getchar(); - return (0); /* XXX reinit? */ + for (i = 0; i < 10 && vidc_ischar(); i++) + (void)vidc_getchar(); + return (0); /* XXX reinit? */ } static void vidc_biosputchar(int c) { - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0xe00 | (c & 0xff); - v86.ebx = 0x7; - v86int(); + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0xe00 | (c & 0xff); + v86.ebx = 0x7; + v86int(); } static void vidc_rawputchar(int c) { - int i; + int i; - if (c == '\t') { - int n; + if (c == '\t') { + int n; #ifndef TERM_EMU - int curx, cury; + int curx, cury; - get_pos(&curx, &cury); + get_pos(&curx, &cury); #endif - n = 8 - ((curx + 8) % 8); - for (i = 0; i < n; i++) - vidc_rawputchar(' '); - } else { + n = 8 - ((curx + 8) % 8); + for (i = 0; i < n; i++) + vidc_rawputchar(' '); + } else { #ifndef TERM_EMU - vidc_biosputchar(c); + vidc_biosputchar(c); #else - /* Emulate AH=0eh (teletype output) */ - switch(c) { - case '\a': - vidc_biosputchar(c); - return; - case '\r': - curx = 0; - curs_move(&curx, &cury, curx, cury); - return; - case '\n': - cury++; - if (cury > 24) { - scroll_up(1, fg_c, bg_c); - cury--; - } else { - curs_move(&curx, &cury, curx, cury); - } - return; - case '\b': - if (curx > 0) { - curx--; + /* Emulate AH=0eh (teletype output) */ + switch(c) { + case '\a': + vidc_biosputchar(c); + return; + case '\r': + curx = 0; + curs_move(&curx, &cury, curx, cury); + return; + case '\n': + cury++; + if (cury > 24) { + scroll_up(1, fg_c, bg_c); + cury--; + } else { + curs_move(&curx, &cury, curx, cury); + } + return; + case '\b': + if (curx > 0) { + curx--; + curs_move(&curx, &cury, curx, cury); + /* write_char(' ', fg_c, bg_c); XXX destructive(!) */ + return; + } + return; + default: + write_char(c, fg_c, bg_c); + curx++; + if (curx > 79) { + curx = 0; + cury++; + } + if (cury > 24) { + curx = 0; + scroll_up(1, fg_c, bg_c); + cury--; + } + } curs_move(&curx, &cury, curx, cury); - /* write_char(' ', fg_c, bg_c); XXX destructive(!) */ - return; - } - return; - default: - write_char(c, fg_c, bg_c); - curx++; - if (curx > 79) { - curx = 0; - cury++; - } - if (cury > 24) { - curx = 0; - scroll_up(1, fg_c, bg_c); - cury--; - } - } - curs_move(&curx, &cury, curx, cury); #endif - } + } } /* Get cursor position on the screen. Result is in edx. Sets @@ -197,13 +197,13 @@ void get_pos(int *x, int *y) { - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0300; - v86.ebx = 0x0; - v86int(); - *x = v86.edx & 0x00ff; - *y = (v86.edx & 0xff00) >> 8; + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0300; + v86.ebx = 0x0; + v86int(); + *x = v86.edx & 0x00ff; + *y = (v86.edx & 0xff00) >> 8; } #ifdef TERM_EMU @@ -213,26 +213,26 @@ void curs_move(int *_x, int *_y, int x, int y) { - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0200; - v86.ebx = 0x0; - v86.edx = ((0x00ff & y) << 8) + (0x00ff & x); - v86int(); - *_x = x; - *_y = y; - /* If there is ctrl char at this position, cursor would be invisible. - * Make it a space instead. - */ - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0800; - v86.ebx = 0x0; - v86int(); + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0200; + v86.ebx = 0x0; + v86.edx = ((0x00ff & y) << 8) + (0x00ff & x); + v86int(); + *_x = x; + *_y = y; + /* If there is ctrl char at this position, cursor would be invisible. + * Make it a space instead. + */ + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0800; + v86.ebx = 0x0; + v86int(); #define isvisible(c) (((c) >= 32) && ((c) < 255)) - if (!isvisible(v86.eax & 0x00ff)) { - write_char(' ', fg_c, bg_c); - } + if (!isvisible(v86.eax & 0x00ff)) { + write_char(' ', fg_c, bg_c); + } } /* Scroll up the whole window by a number of rows. If rows==0, @@ -243,15 +243,15 @@ void scroll_up(int rows, int fgcol, int bgcol) { - if (rows == 0) - rows = 25; - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0600 + (0x00ff & rows); - v86.ebx = (bgcol << 12) + (fgcol << 8); - v86.ecx = 0x0; - v86.edx = 0x184f; - v86int(); + if (rows == 0) + rows = 25; + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0600 + (0x00ff & rows); + v86.ebx = (bgcol << 12) + (fgcol << 8); + v86.ecx = 0x0; + v86.edx = 0x184f; + v86int(); } /* Write character and attribute at cursor position. */ @@ -259,12 +259,12 @@ void write_char(int c, int fgcol, int bgcol) { - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0900 + (0x00ff & c); - v86.ebx = (bgcol << 4) + fgcol; - v86.ecx = 0x1; - v86int(); + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0900 + (0x00ff & c); + v86.ebx = (bgcol << 4) + fgcol; + v86.ecx = 0x1; + v86int(); } /**************************************************************/ @@ -279,28 +279,28 @@ void CD(void) { - get_pos(&curx, &cury); - if (curx > 0) { + get_pos(&curx, &cury); + if (curx > 0) { + v86.ctl = 0; + v86.addr = 0x10; + v86.eax = 0x0600; + v86.ebx = (bg_c << 4) + fg_c; + v86.ecx = (cury << 8) + curx; + v86.edx = (cury << 8) + 79; + v86int(); + if (++cury > 24) { + end_term(); + return; + } + } v86.ctl = 0; v86.addr = 0x10; v86.eax = 0x0600; v86.ebx = (bg_c << 4) + fg_c; - v86.ecx = (cury << 8) + curx; - v86.edx = (cury << 8) + 79; + v86.ecx = (cury << 8) + 0; + v86.edx = (24 << 8) + 79; v86int(); - if (++cury > 24) { - end_term(); - return; - } - } - v86.ctl = 0; - v86.addr = 0x10; - v86.eax = 0x0600; - v86.ebx = (bg_c << 4) + fg_c; - v86.ecx = (cury << 8) + 0; - v86.edx = (24 << 8) + 79; - v86int(); - end_term(); + end_term(); } /* Absolute cursor move to args[0] rows and args[1] columns @@ -310,12 +310,12 @@ void CM(void) { - if (args[0] > 0) - args[0]--; - if (args[1] > 0) - args[1]--; - curs_move(&curx, &cury, args[1], args[0]); - end_term(); + if (args[0] > 0) + args[0]--; + if (args[1] > 0) + args[1]--; + curs_move(&curx, &cury, args[1], args[0]); + end_term(); } /* Home cursor (left top corner) */ @@ -323,9 +323,9 @@ void HO(void) { - argc = 1; - args[0] = args[1] = 1; - CM(); + argc = 1; + args[0] = args[1] = 1; + CM(); } /* Clear internal state of the terminal emulation code */ @@ -333,162 +333,162 @@ void end_term(void) { - esc = 0; - argc = -1; + esc = 0; + argc = -1; } /* Gracefully exit ESC-sequence processing in case of misunderstanding */ void bail_out(int c) { - char buf[16], *ch; - int i; - - if (esc) { - vidc_rawputchar('\033'); - if (esc != '\033') - vidc_rawputchar(esc); - for (i = 0; i <= argc; ++i) { - sprintf(buf, "%d", args[i]); - ch = buf; - while (*ch) - vidc_rawputchar(*ch++); + char buf[16], *ch; + int i; + + if (esc) { + vidc_rawputchar('\033'); + if (esc != '\033') + vidc_rawputchar(esc); + for (i = 0; i <= argc; ++i) { + sprintf(buf, "%d", args[i]); + ch = buf; + while (*ch) + vidc_rawputchar(*ch++); + } } - } - vidc_rawputchar(c); - end_term(); + vidc_rawputchar(c); + end_term(); } static void get_arg(int c) { - if (argc < 0) - argc = 0; - args[argc] *= 10; - args[argc] += c - '0'; + if (argc < 0) + argc = 0; + args[argc] *= 10; + args[argc] += c - '0'; } /* Emulate basic capabilities of cons25 terminal */ void vidc_term_emu(int c) { - static int ansi_col[] = { - 0, 4, 2, 6, 1, 5, 3, 7, - }; - int t; - int i; - - switch (esc) { - case 0: - switch (c) { + static int ansi_col[] = { + 0, 4, 2, 6, 1, 5, 3, 7, + }; + int t; + int i; + + switch (esc) { + case 0: + switch (c) { + case '\033': + esc = c; + break; + default: + vidc_rawputchar(c); + break; + } + break; + case '\033': - esc = c; - break; - default: - vidc_rawputchar(c); - break; - } - break; + switch (c) { + case '[': + esc = c; + args[0] = 0; + argc = -1; + break; + default: + bail_out(c); + break; + } + break; - case '\033': - switch (c) { case '[': - esc = c; - args[0] = 0; - argc = -1; - break; - default: - bail_out(c); - break; - } - break; - - case '[': - switch (c) { - case ';': - if (argc < 0) /* XXX */ - argc = 0; - else if (argc + 1 >= MAXARGS) - bail_out(c); - else - args[++argc] = 0; - break; - case 'H': - if (argc < 0) - HO(); - else if (argc == 1) - CM(); - else - bail_out(c); - break; - case 'J': - if (argc < 0) - CD(); - else - bail_out(c); - break; - case 'm': - if (argc < 0) { - fg_c = DEFAULT_FGCOLOR; - bg_c = DEFAULT_BGCOLOR; - } - for (i = 0; i <= argc; ++i) { - switch (args[i]) { - case 0: /* back to normal */ - fg_c = DEFAULT_FGCOLOR; - bg_c = DEFAULT_BGCOLOR; - break; - case 1: /* bold */ - fg_c |= 0x8; - break; - case 4: /* underline */ - case 5: /* blink */ - bg_c |= 0x8; - break; - case 7: /* reverse */ - t = fg_c; - fg_c = bg_c; - bg_c = t; - break; - case 22: /* normal intensity */ - fg_c &= ~0x8; - break; - case 24: /* not underline */ - case 25: /* not blinking */ - bg_c &= ~0x8; - break; - case 30: case 31: case 32: case 33: - case 34: case 35: case 36: case 37: - fg_c = ansi_col[args[i] - 30]; - break; - case 39: /* normal */ - fg_c = DEFAULT_FGCOLOR; - break; - case 40: case 41: case 42: case 43: - case 44: case 45: case 46: case 47: - bg_c = ansi_col[args[i] - 40]; - break; - case 49: /* normal */ - bg_c = DEFAULT_BGCOLOR; - break; + switch (c) { + case ';': + if (argc < 0) /* XXX */ + argc = 0; + else if (argc + 1 >= MAXARGS) + bail_out(c); + else + args[++argc] = 0; + break; + case 'H': + if (argc < 0) + HO(); + else if (argc == 1) + CM(); + else + bail_out(c); + break; + case 'J': + if (argc < 0) + CD(); + else + bail_out(c); + break; + case 'm': + if (argc < 0) { + fg_c = DEFAULT_FGCOLOR; + bg_c = DEFAULT_BGCOLOR; + } + for (i = 0; i <= argc; ++i) { + switch (args[i]) { + case 0: /* back to normal */ + fg_c = DEFAULT_FGCOLOR; + bg_c = DEFAULT_BGCOLOR; + break; + case 1: /* bold */ + fg_c |= 0x8; + break; + case 4: /* underline */ + case 5: /* blink */ + bg_c |= 0x8; + break; + case 7: /* reverse */ + t = fg_c; + fg_c = bg_c; + bg_c = t; + break; + case 22: /* normal intensity */ + fg_c &= ~0x8; + break; + case 24: /* not underline */ + case 25: /* not blinking */ + bg_c &= ~0x8; + break; + case 30: case 31: case 32: case 33: + case 34: case 35: case 36: case 37: + fg_c = ansi_col[args[i] - 30]; + break; + case 39: /* normal */ + fg_c = DEFAULT_FGCOLOR; + break; + case 40: case 41: case 42: case 43: + case 44: case 45: case 46: case 47: + bg_c = ansi_col[args[i] - 40]; + break; + case 49: /* normal */ + bg_c = DEFAULT_BGCOLOR; + break; + } + } + end_term(); + break; + default: + if (isdigit(c)) + get_arg(c); + else + bail_out(c); + break; } - } - end_term(); - break; + break; + default: - if (isdigit(c)) - get_arg(c); - else bail_out(c); - break; + break; } - break; - - default: - bail_out(c); - break; - } } #endif @@ -496,9 +496,9 @@ static void vidc_putchar(int c) { #ifdef TERM_EMU - vidc_term_emu(c); + vidc_term_emu(c); #else - vidc_rawputchar(c); + vidc_rawputchar(c); #endif } @@ -506,26 +506,26 @@ static int vidc_getchar(void) { - if (vidc_ischar()) { - v86.ctl = 0; - v86.addr = 0x16; - v86.eax = 0x0; - v86int(); - return (v86.eax & 0xff); - } else { - return (-1); - } + if (vidc_ischar()) { + v86.ctl = 0; + v86.addr = 0x16; + v86.eax = 0x0; + v86int(); + return (v86.eax & 0xff); + } else { + return (-1); + } } static int vidc_ischar(void) { - v86.ctl = V86_FLAGS; - v86.addr = 0x16; - v86.eax = 0x100; - v86int(); - return (!V86_ZR(v86.efl)); + v86.ctl = V86_FLAGS; + v86.addr = 0x16; + v86.eax = 0x100; + v86int(); + return (!V86_ZR(v86.efl)); } #if KEYBOARD_PROBE @@ -550,13 +550,16 @@ vidc_ischar(void) static void delay7(void) { - /* - * I know this is broken, but no timer is available yet at this stage... - * See also comments in `delay1ms()'. - */ - inb(IO_DUMMY); inb(IO_DUMMY); - inb(IO_DUMMY); inb(IO_DUMMY); - inb(IO_DUMMY); inb(IO_DUMMY); + /* + * I know this is broken, but no timer is available yet at this stage... + * See also comments in `delay1ms()'. + */ + inb(IO_DUMMY); + inb(IO_DUMMY); + inb(IO_DUMMY); + inb(IO_DUMMY); + inb(IO_DUMMY); + inb(IO_DUMMY); } /* @@ -571,9 +574,9 @@ delay7(void) static void delay1ms(void) { - int i = 800; - while (--i >= 0) - (void)inb(0x84); + int i = 800; + while (--i >= 0) + (void)inb(0x84); } /* @@ -587,55 +590,55 @@ delay1ms(void) static int probe_keyboard(void) { - int retry = PROBE_MAXRETRY; - int wait; - int i; - - while (--retry >= 0) { - /* flush any noise */ - while (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) { - delay7(); - inb(IO_KBD + KBD_DATA_PORT); - delay1ms(); - } + int retry = PROBE_MAXRETRY; + int wait; + int i; + + while (--retry >= 0) { + /* flush any noise */ + while (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) { + delay7(); + inb(IO_KBD + KBD_DATA_PORT); + delay1ms(); + } - /* wait until the controller can accept a command */ - for (wait = PROBE_MAXWAIT; wait > 0; --wait) { - if (((i = inb(IO_KBD + KBD_STATUS_PORT)) - & (KBDS_INPUT_BUFFER_FULL | KBDS_ANY_BUFFER_FULL)) == 0) - break; - if (i & KBDS_ANY_BUFFER_FULL) { - delay7(); - inb(IO_KBD + KBD_DATA_PORT); - } - delay1ms(); - } - if (wait <= 0) - continue; + /* wait until the controller can accept a command */ + for (wait = PROBE_MAXWAIT; wait > 0; --wait) { + if (((i = inb(IO_KBD + KBD_STATUS_PORT)) + & (KBDS_INPUT_BUFFER_FULL | KBDS_ANY_BUFFER_FULL)) == 0) + break; + if (i & KBDS_ANY_BUFFER_FULL) { + delay7(); + inb(IO_KBD + KBD_DATA_PORT); + } + delay1ms(); + } + if (wait <= 0) + continue; - /* send the ECHO command */ - outb(IO_KBD + KBD_DATA_PORT, KBDC_ECHO); + /* send the ECHO command */ + outb(IO_KBD + KBD_DATA_PORT, KBDC_ECHO); - /* wait for a response */ - for (wait = PROBE_MAXWAIT; wait > 0; --wait) { - if (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) - break; - delay1ms(); - } - if (wait <= 0) - continue; + /* wait for a response */ + for (wait = PROBE_MAXWAIT; wait > 0; --wait) { + if (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) + break; + delay1ms(); + } + if (wait <= 0) + continue; - delay7(); - i = inb(IO_KBD + KBD_DATA_PORT); + delay7(); + i = inb(IO_KBD + KBD_DATA_PORT); #ifdef PROBE_KBD_BEBUG - printf("probe_keyboard: got 0x%x.\n", i); + printf("probe_keyboard: got 0x%x.\n", i); #endif - if (i == KBD_ECHO) { - /* got the right answer */ - return (1); + if (i == KBD_ECHO) { + /* got the right answer */ + return (1); + } } - } - return (0); + return (0); } #endif /* KEYBOARD_PROBE */