Linux 2.6.31.6
[linux/fpc-iii.git] / arch / x86 / boot / tty.c
blob01ec69c901c7a595e88748f24880a5104af553fe
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
13 * Very simple screen I/O
14 * XXX: Probably should add very simple serial I/O?
17 #include "boot.h"
20 * These functions are in .inittext so they can be used to signal
21 * error during initialization.
24 void __attribute__((section(".inittext"))) putchar(int ch)
26 struct biosregs ireg;
28 if (ch == '\n')
29 putchar('\r'); /* \n -> \r\n */
31 initregs(&ireg);
32 ireg.bx = 0x0007;
33 ireg.cx = 0x0001;
34 ireg.ah = 0x0e;
35 ireg.al = ch;
36 intcall(0x10, &ireg, NULL);
39 void __attribute__((section(".inittext"))) puts(const char *str)
41 while (*str)
42 putchar(*str++);
46 * Read the CMOS clock through the BIOS, and return the
47 * seconds in BCD.
50 static u8 gettime(void)
52 struct biosregs ireg, oreg;
54 initregs(&ireg);
55 ireg.ah = 0x02;
56 intcall(0x1a, &ireg, &oreg);
58 return oreg.dh;
62 * Read from the keyboard
64 int getchar(void)
66 struct biosregs ireg, oreg;
68 initregs(&ireg);
69 /* ireg.ah = 0x00; */
70 intcall(0x16, &ireg, &oreg);
72 return oreg.al;
75 static int kbd_pending(void)
77 struct biosregs ireg, oreg;
79 initregs(&ireg);
80 ireg.ah = 0x01;
81 intcall(0x16, &ireg, &oreg);
83 return !(oreg.eflags & X86_EFLAGS_ZF);
86 void kbd_flush(void)
88 for (;;) {
89 if (!kbd_pending())
90 break;
91 getchar();
95 int getchar_timeout(void)
97 int cnt = 30;
98 int t0, t1;
100 t0 = gettime();
102 while (cnt) {
103 if (kbd_pending())
104 return getchar();
106 t1 = gettime();
107 if (t0 != t1) {
108 cnt--;
109 t0 = t1;
113 return 0; /* Timeout! */