embox

Форк
0
81 строка · 1.9 Кб
1
/**
2
 * @file
3
 * @brief
4
 *
5
 * @date 17.03.2012
6
 * @author Andrey Golikov
7
 * @author Anton Kozlov
8
 */
9

10
#include <drivers/diag.h>
11

12
#include <stdint.h>
13
#include <xen/xen.h>
14
#include <xen/io/console.h>
15
#include <xen_hypercall-x86_32.h>
16

17
#include <barrier.h>
18

19
#include <assert.h>
20

21
static evtchn_port_t console_evt;
22
extern char _text_vma;
23
struct xencons_interface * console;
24

25
static int diag_xen_init(const struct diag *diag) {
26
	extern start_info_t *xen_start_info_global;
27
	console = (struct xencons_interface*)
28
		((machine_to_phys_mapping[xen_start_info_global->console.domU.mfn] << 12)
29
		 +
30
		((unsigned long)&_text_vma));
31
	console_evt = xen_start_info_global->console.domU.evtchn;
32
	/* TODO: Set up the event channel */
33
	return 0;
34
}
35

36
static void diag_xen_putc(const struct diag *diag, char ch) {
37
	struct evtchn_send event;
38
	event.port = console_evt;
39
	char message[1];
40
	message[0] = ch;
41
	{
42
		/* Wait for the back end to clear enough space in the buffer */
43
		XENCONS_RING_IDX data;
44
		do
45
		{
46
			data = console->out_prod - console->out_cons;
47
			HYPERVISOR_event_channel_op(EVTCHNOP_send, &event);
48
			mb();
49
		} while (data >= sizeof(console->out));
50
		/* Copy the byte */
51
		int ring_index = MASK_XENCONS_IDX(console->out_prod, console->out);
52
		console->out[ring_index] = *message;
53
		/* Ensure that the data really is in the ring before continuing */
54
		wmb();
55
		/* Increment input and output pointers */
56
		console->out_prod++;
57
	}
58
	HYPERVISOR_event_channel_op(EVTCHNOP_send, &event);
59
}
60

61
static char diag_xen_getc(const struct diag *diag) {
62
	assert(console->in_prod != console->in_cons);
63

64
	int ring_index = MASK_XENCONS_IDX(console->in_cons, console->in);
65
	char ch = console->in[ring_index];
66
	rmb();
67
	console->in_cons++;
68

69
	return ch;
70
}
71

72
static int diag_xen_kbhit(const struct diag *diag) {
73
	return console->in_prod != console->in_cons;
74
}
75

76
DIAG_OPS_DEF(
77
	.init = diag_xen_init,
78
	.putc = diag_xen_putc,
79
	.getc = diag_xen_getc,
80
	.kbhit = diag_xen_kbhit,
81
);
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.