]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/stdio.c
added Spanish (Latinoamérica) translation (#1865)
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / stdio.c
1 /*
2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 /**
21 * @file
22 *
23 * Standard Input/Output
24 *
25 */
26
27 #include <stdio.h>
28 #include <string.h>
29 #include "bootapp.h"
30 #include "wimboot.h"
31 #include "efi.h"
32
33 /**
34 * Print character to console
35 *
36 * @v character Character to print
37 */
38 int putchar ( int character ) {
39 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout;
40 struct bootapp_callback_params params;
41 wchar_t wbuf[2];
42
43 /* Convert LF to CR,LF */
44 if ( character == '\n' )
45 putchar ( '\r' );
46
47 /* Print character to bochs debug port */
48 __asm__ __volatile__ ( "outb %b0, $0xe9"
49 : : "a" ( character ) );
50
51 /* Print character to EFI/BIOS console as applicable */
52 if ( efi_systab ) {
53 conout = efi_systab->ConOut;
54 wbuf[0] = character;
55 wbuf[1] = 0;
56 conout->OutputString ( conout, wbuf );
57 } else {
58 memset ( &params, 0, sizeof ( params ) );
59 params.vector.interrupt = 0x10;
60 params.eax = ( 0x0e00 | character );
61 params.ebx = 0x0007;
62 call_interrupt ( &params );
63 }
64
65 return 0;
66 }
67
68 /**
69 * Get character from console
70 *
71 * @ret character Character
72 */
73 int getchar ( void ) {
74 EFI_BOOT_SERVICES *bs;
75 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin;
76 EFI_INPUT_KEY key;
77 UINTN index;
78 struct bootapp_callback_params params;
79 int character;
80
81 /* Get character */
82 if ( efi_systab ) {
83 bs = efi_systab->BootServices;
84 conin = efi_systab->ConIn;
85 bs->WaitForEvent ( 1, &conin->WaitForKey, &index );
86 conin->ReadKeyStroke ( conin, &key );
87 character = key.UnicodeChar;
88 } else {
89 memset ( &params, 0, sizeof ( params ) );
90 params.vector.interrupt = 0x16;
91 call_interrupt ( &params );
92 character = params.al;
93 }
94
95 return character;
96 }