b0bee1ab0b34b22d974c7f9dfc1a3dfcb7c26841
[people/balajirrao/gpxe.git] / src / arch / i386 / firmware / pcbios / bios_console.c
1 /* Etherboot routines for PCBIOS firmware.
2  *
3  * Body of routines taken from old pcbios.S
4  */
5
6 #include "compiler.h"
7 #include "realmode.h"
8 #include "console.h"
9
10 #define ZF ( 1 << 6 )
11
12 /**************************************************************************
13 bios_putchar - Print a character on console
14 **************************************************************************/
15 static void bios_putchar ( int character ) {
16         REAL_EXEC ( rm_console_putc,
17                     "sti\n\t"
18                     "movb $0x0e, %%ah\n\t"
19                     "movl $1, %%ebx\n\t"
20                     "int $0x10\n\t"
21                     "cli\n\t",
22                     1,
23                     OUT_CONSTRAINTS ( "=a" ( character ) ),
24                     IN_CONSTRAINTS ( "a" ( character ) ),
25                     CLOBBER ( "ebx", "ecx", "edx", "ebp", "esi", "edi" ) );
26
27         /* NOTE: %eax may be clobbered, so must be specified as an output
28          * parameter, even though we don't then do anything with it.
29          */
30 }
31
32 /**************************************************************************
33 bios_getchar - Get a character from console
34 **************************************************************************/
35 static int bios_getchar ( void ) {
36         uint16_t character;
37         
38         REAL_EXEC ( rm_console_getc,
39                     "sti\n\t"
40                     "xorw %%ax, %%ax\n\t"
41                     "int $0x16\n\t"
42                     "cli\n\t",
43                     1,
44                     OUT_CONSTRAINTS ( "=a" ( character ) ),
45                     IN_CONSTRAINTS (),
46                     CLOBBER ( "ebx", "ecx", "edx", "ebp", "esi", "edi" ) );
47         
48         return ( character & 0xff );
49 }
50
51 /**************************************************************************
52 bios_iskey - Check for keyboard interrupt
53 **************************************************************************/
54 static int bios_iskey ( void ) {
55         uint16_t flags;
56         
57         REAL_EXEC ( rm_console_ischar,
58                     "sti\n\t"
59                     "movb $1, %%ah\n\t"
60                     "int $0x16\n\t"
61                     "pushfw\n\t"
62                     "popw %%ax\n\t"
63                     "cli\n\t",
64                     1,
65                     OUT_CONSTRAINTS ( "=a" ( flags ) ),
66                     IN_CONSTRAINTS (),
67                     CLOBBER ( "ebx", "ecx", "edx", "ebp", "esi", "edi" ) );
68         
69         return ( ( flags & ZF ) == 0 );
70 }
71
72 static struct console_driver bios_console __console_driver = {
73         .putchar = bios_putchar,
74         .getchar = bios_getchar,
75         .iskey = bios_iskey,
76 };