-
Notifications
You must be signed in to change notification settings - Fork 0
/
guest4.c
45 lines (38 loc) · 1017 Bytes
/
guest4.c
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
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
static void outb(uint16_t port, uint8_t value) {
asm volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
}
static uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
void
__attribute__((noreturn))
__attribute__((section(".start"))) _start(void) {
uint16_t port = 0xE9;
char input[100];
int i = 0;
// Read data from mini-hypervisor via port 0xE9
while (1) {
char value = inb(port);
if (value == 'x' || i >= sizeof(input) - 1) {
break;
}
input[i++] = value;
// Echo back each character to indicate reception
}
// Null-terminate the input string
input[i] = '\0';
// Print the received data
for (int j = 0; j < i; j++) {
outb(0xE9, input[j]);
}
outb(0xE9, '\n');
// Enter an infinite loop to halt execution
for (;;) {
asm("hlt");
}
}