"tests/models/mbart/test_modeling_mbart.py" did not exist on "71356034232cfce20d8f24df1213944665e7fe08"
stdio.c 2.32 KB
Newer Older
longpanda's avatar
longpanda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * @file
 *
 * Standard Input/Output
 *
 */

#include <stdio.h>
#include <string.h>
#include "bootapp.h"
#include "wimboot.h"
#include "efi.h"

/**
 * Print character to console
 *
 * @v character		Character to print
 */
int putchar ( int character ) {
	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout;
	struct bootapp_callback_params params;
	wchar_t wbuf[2];

	/* Convert LF to CR,LF */
	if ( character == '\n' )
		putchar ( '\r' );

	/* Print character to bochs debug port */
	__asm__ __volatile__ ( "outb %b0, $0xe9"
			       : : "a" ( character ) );

	/* Print character to EFI/BIOS console as applicable */
	if ( efi_systab ) {
		conout = efi_systab->ConOut;
		wbuf[0] = character;
		wbuf[1] = 0;
		conout->OutputString ( conout, wbuf );
	} else {
		memset ( &params, 0, sizeof ( params ) );
		params.vector.interrupt = 0x10;
		params.eax = ( 0x0e00 | character );
		params.ebx = 0x0007;
		call_interrupt ( &params );
	}

	return 0;
}

/**
 * Get character from console
 *
 * @ret character	Character
 */
int getchar ( void ) {
	EFI_BOOT_SERVICES *bs;
	EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin;
	EFI_INPUT_KEY key;
	UINTN index;
	struct bootapp_callback_params params;
	int character;

	/* Get character */
	if ( efi_systab ) {
		bs = efi_systab->BootServices;
		conin = efi_systab->ConIn;
		bs->WaitForEvent ( 1, &conin->WaitForKey, &index );
		conin->ReadKeyStroke ( conin, &key );
		character = key.UnicodeChar;
	} else {
		memset ( &params, 0, sizeof ( params ) );
		params.vector.interrupt = 0x16;
		call_interrupt ( &params );
		character = params.al;
	}

	return character;
}