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