m68knommu: remove local gettimeofday code
[wrt350n-kernel.git] / arch / x86 / boot / tty.c
blobf3f14bd2637191ca7a87faf8f69785f87dce2aef
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/tty.c
14 * Very simple screen I/O
15 * XXX: Probably should add very simple serial I/O?
18 #include "boot.h"
21 * These functions are in .inittext so they can be used to signal
22 * error during initialization.
25 void __attribute__((section(".inittext"))) putchar(int ch)
27 unsigned char c = ch;
29 if (c == '\n')
30 putchar('\r'); /* \n -> \r\n */
32 /* int $0x10 is known to have bugs involving touching registers
33 it shouldn't. Be extra conservative... */
34 asm volatile("pushal; pushw %%ds; int $0x10; popw %%ds; popal"
35 : : "b" (0x0007), "c" (0x0001), "a" (0x0e00|ch));
38 void __attribute__((section(".inittext"))) puts(const char *str)
40 int n = 0;
41 while (*str) {
42 putchar(*str++);
43 n++;
48 * Read the CMOS clock through the BIOS, and return the
49 * seconds in BCD.
52 static u8 gettime(void)
54 u16 ax = 0x0200;
55 u16 cx, dx;
57 asm volatile("int $0x1a"
58 : "+a" (ax), "=c" (cx), "=d" (dx)
59 : : "ebx", "esi", "edi");
61 return dx >> 8;
65 * Read from the keyboard
67 int getchar(void)
69 u16 ax = 0;
70 asm volatile("int $0x16" : "+a" (ax));
72 return ax & 0xff;
75 static int kbd_pending(void)
77 u8 pending;
78 asm volatile("int $0x16; setnz %0"
79 : "=rm" (pending)
80 : "a" (0x0100));
81 return pending;
84 void kbd_flush(void)
86 for (;;) {
87 if (!kbd_pending())
88 break;
89 getchar();
93 int getchar_timeout(void)
95 int cnt = 30;
96 int t0, t1;
98 t0 = gettime();
100 while (cnt) {
101 if (kbd_pending())
102 return getchar();
104 t1 = gettime();
105 if (t0 != t1) {
106 cnt--;
107 t0 = t1;
111 return 0; /* Timeout! */