1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
8 * ----------------------------------------------------------------------- */
11 * Very simple screen and serial I/O
16 int early_serial_base
;
20 #define TXR 0 /* Transmit register (WRITE) */
21 #define LSR 5 /* Line Status */
24 * These functions are in .inittext so they can be used to signal
25 * error during initialization.
28 static void __attribute__((section(".inittext"))) serial_putchar(int ch
)
30 unsigned timeout
= 0xffff;
32 while ((inb(early_serial_base
+ LSR
) & XMTRDY
) == 0 && --timeout
)
35 outb(ch
, early_serial_base
+ TXR
);
38 static void __attribute__((section(".inittext"))) bios_putchar(int ch
)
47 intcall(0x10, &ireg
, NULL
);
50 void __attribute__((section(".inittext"))) putchar(int ch
)
53 putchar('\r'); /* \n -> \r\n */
57 if (early_serial_base
!= 0)
61 void __attribute__((section(".inittext"))) puts(const char *str
)
68 * Read the CMOS clock through the BIOS, and return the
72 static u8
gettime(void)
74 struct biosregs ireg
, oreg
;
78 intcall(0x1a, &ireg
, &oreg
);
84 * Read from the keyboard
88 struct biosregs ireg
, oreg
;
92 intcall(0x16, &ireg
, &oreg
);
97 static int kbd_pending(void)
99 struct biosregs ireg
, oreg
;
103 intcall(0x16, &ireg
, &oreg
);
105 return !(oreg
.eflags
& X86_EFLAGS_ZF
);
117 int getchar_timeout(void)
135 return 0; /* Timeout! */