lockd: push lock_flocks down
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / boot / tty.c
blobdef2451f46aefe70fe38d5ed3554a380f710a6e2
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 and serial I/O
16 #include "boot.h"
18 int early_serial_base;
20 #define XMTRDY 0x20
22 #define TXR 0 /* Transmit register (WRITE) */
23 #define LSR 5 /* Line Status */
26 * These functions are in .inittext so they can be used to signal
27 * error during initialization.
30 static void __attribute__((section(".inittext"))) serial_putchar(int ch)
32 unsigned timeout = 0xffff;
34 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
35 cpu_relax();
37 outb(ch, early_serial_base + TXR);
40 static void __attribute__((section(".inittext"))) bios_putchar(int ch)
42 struct biosregs ireg;
44 initregs(&ireg);
45 ireg.bx = 0x0007;
46 ireg.cx = 0x0001;
47 ireg.ah = 0x0e;
48 ireg.al = ch;
49 intcall(0x10, &ireg, NULL);
52 void __attribute__((section(".inittext"))) putchar(int ch)
54 if (ch == '\n')
55 putchar('\r'); /* \n -> \r\n */
57 bios_putchar(ch);
59 if (early_serial_base != 0)
60 serial_putchar(ch);
63 void __attribute__((section(".inittext"))) puts(const char *str)
65 while (*str)
66 putchar(*str++);
70 * Read the CMOS clock through the BIOS, and return the
71 * seconds in BCD.
74 static u8 gettime(void)
76 struct biosregs ireg, oreg;
78 initregs(&ireg);
79 ireg.ah = 0x02;
80 intcall(0x1a, &ireg, &oreg);
82 return oreg.dh;
86 * Read from the keyboard
88 int getchar(void)
90 struct biosregs ireg, oreg;
92 initregs(&ireg);
93 /* ireg.ah = 0x00; */
94 intcall(0x16, &ireg, &oreg);
96 return oreg.al;
99 static int kbd_pending(void)
101 struct biosregs ireg, oreg;
103 initregs(&ireg);
104 ireg.ah = 0x01;
105 intcall(0x16, &ireg, &oreg);
107 return !(oreg.eflags & X86_EFLAGS_ZF);
110 void kbd_flush(void)
112 for (;;) {
113 if (!kbd_pending())
114 break;
115 getchar();
119 int getchar_timeout(void)
121 int cnt = 30;
122 int t0, t1;
124 t0 = gettime();
126 while (cnt) {
127 if (kbd_pending())
128 return getchar();
130 t1 = gettime();
131 if (t0 != t1) {
132 cnt--;
133 t0 = t1;
137 return 0; /* Timeout! */