• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

FreeBSD bhyve keyboard layout patch


Commit MetaInfo

Révisionf066ef71db54cd95ef438eaa955f9385f174ef06 (tree)
l'heure2021-01-02 13:17:36
AuteurKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Message de Log

kbdlayout: Cut out the QEMU extended keyboard event message function part into another patch.
kbdlayout: Add patch file for vmrun.sh.
qemuextkey: Split from keyboard option patch file.

Change Summary

Modification

--- /dev/null
+++ b/kbdlayout_option/bhyve_kbdlayout_option_fbsd121r.patch
@@ -0,0 +1,248 @@
1+diff -upN bhyve_base/Makefile bhyve/Makefile
2+--- bhyve_base/Makefile 2020-06-02 20:16:51.532368000 +0900
3++++ bhyve/Makefile 2020-06-02 20:35:48.179160000 +0900
4+@@ -95,4 +95,6 @@ CFLAGS+=-DGDB_LOG
5+
6+ WARNS?= 2
7+
8++SUBDIR= kbdlayout
9++
10+ .include <bsd.prog.mk>
11+diff -upN bhyve_base/bhyve.8 bhyve/bhyve.8
12+--- bhyve_base/bhyve.8 2020-06-02 20:16:51.487013000 +0900
13++++ bhyve/bhyve.8 2020-06-02 20:35:48.180745000 +0900
14+@@ -44,6 +44,7 @@
15+ .Op Ar ,threads=n
16+ .Oc
17+ .Op Fl g Ar gdbport
18++.Op Fl k Ar layout
19+ .Op Fl l Ar help|lpcdev Ns Op , Ns Ar conf
20+ .Op Fl m Ar memsize Ns Op Ar K|k|M|m|G|g|T|t
21+ .Op Fl p Ar vcpu:hostcpu
22+@@ -144,6 +145,13 @@ Print help message and exit.
23+ .It Fl H
24+ Yield the virtual CPU thread when a HLT instruction is detected.
25+ If this option is not specified, virtual CPUs will use 100% of a host CPU.
26++.It Fl k Ar layout
27++Specify the keyboard layout.
28++The value that can be specified sets the file name in
29++.Ar /usr/share/bhyve/kbdlayout .
30++This specification only works when loaded with UEFI mode.(Not working via console or SSH)
31++If you are using a VNC client that supports QEMU Extended Key Event Message (e.g. TigerVNC), don't need to specify this option.
32++If you are using a VNC client that doesn't support it(e.g. tightVNC), and you don't specify this option, the US keyboard layout(default) is specified.
33+ .It Fl l Op Ar help|lpcdev Ns Op , Ns Ar conf
34+ Allow devices behind the LPC PCI-ISA bridge to be configured.
35+ The only supported devices are the TTY-class devices
36+diff -upN bhyve_base/bhyverun.c bhyve/bhyverun.c
37+--- bhyve_base/bhyverun.c 2020-06-02 20:16:51.456344000 +0900
38++++ bhyve/bhyverun.c 2020-06-02 20:35:48.181837000 +0900
39+@@ -165,6 +165,8 @@ char *vmname;
40+ int guest_ncpus;
41+ uint16_t cores, maxcpus, sockets, threads;
42+
43++char *kbdlayout_name;
44++
45+ char *guest_uuid_str;
46+
47+ static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
48+@@ -211,7 +213,7 @@ usage(int code)
49+ fprintf(stderr,
50+ "Usage: %s [-abehuwxACHPSWY]\n"
51+ " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n"
52+- " %*s [-g <gdb port>] [-l <lpc>]\n"
53++ " %*s [-g <gdb port>] [-k layout] [-l <lpc>]\n"
54+ " %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
55+ " -a: local apic is in xAPIC mode (deprecated)\n"
56+ " -A: create ACPI tables\n"
57+@@ -221,6 +223,7 @@ usage(int code)
58+ " -g: gdb port\n"
59+ " -h: help\n"
60+ " -H: vmexit from the guest on hlt\n"
61++ " -k: PS2 keyboard layout\n"
62+ " -l: LPC device configuration\n"
63+ " -m: memory size in MB\n"
64+ " -p: pin 'vcpu' to 'hostcpu'\n"
65+@@ -996,8 +999,9 @@ main(int argc, char *argv[])
66+ mptgen = 1;
67+ rtc_localtime = 1;
68+ memflags = 0;
69++ kbdlayout_name = NULL;
70+
71+- optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:";
72++ optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:k:U:";
73+ while ((c = getopt(argc, argv, optstr)) != -1) {
74+ switch (c) {
75+ case 'a':
76+@@ -1033,6 +1037,9 @@ main(int argc, char *argv[])
77+ optarg++;
78+ }
79+ gdb_port = atoi(optarg);
80++ break;
81++ case 'k':
82++ kbdlayout_name = optarg;
83+ break;
84+ case 'l':
85+ if (strncmp(optarg, "help", strlen(optarg)) == 0) {
86+diff -upN bhyve_base/bhyverun.h bhyve/bhyverun.h
87+--- bhyve_base/bhyverun.h 2020-06-02 20:16:51.511202000 +0900
88++++ bhyve/bhyverun.h 2020-06-02 20:35:48.182282000 +0900
89+@@ -39,6 +39,7 @@ extern int guest_ncpus;
90+ extern uint16_t cores, sockets, threads;
91+ extern char *guest_uuid_str;
92+ extern char *vmname;
93++extern char *kbdlayout_name;
94+
95+ void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
96+
97+diff -upN bhyve_base/ps2kbd.c bhyve/ps2kbd.c
98+--- bhyve_base/ps2kbd.c 2020-06-02 20:29:26.881702000 +0900
99++++ bhyve/ps2kbd.c 2020-06-02 20:35:48.184181000 +0900
100+@@ -31,15 +31,20 @@
101+ __FBSDID("$FreeBSD: releng/12.1/usr.sbin/bhyve/ps2kbd.c 341757 2018-12-09 06:41:57Z araujo $");
102+
103+ #include <sys/types.h>
104++#include <sys/stat.h>
105+
106+ #include <assert.h>
107+ #include <stdbool.h>
108+ #include <stdio.h>
109+ #include <stdlib.h>
110++#include <string.h>
111+ #include <strings.h>
112+ #include <pthread.h>
113+ #include <pthread_np.h>
114++#include <unistd.h>
115++#include <fcntl.h>
116+
117++#include "bhyverun.h"
118+ #include "atkbdc.h"
119+ #include "console.h"
120+
121+@@ -58,6 +63,8 @@ __FBSDID("$FreeBSD: releng/12.1/usr.sbin/bhyve/ps2kbd.
122+
123+ #define PS2KBD_FIFOSZ 16
124+
125++#define PS2KBD_LAYOUT_BASEDIR "/usr/share/bhyve/kbdlayout/"
126++
127+ struct fifo {
128+ uint8_t buf[PS2KBD_FIFOSZ];
129+ uint8_t trans[PS2KBD_FIFOSZ];
130+@@ -87,7 +94,7 @@ struct extended_translation {
131+ /*
132+ * FIXME: Pause/break and Print Screen/SysRq require special handling.
133+ */
134+-static const struct extended_translation extended_translations[] = {
135++static struct extended_translation extended_translations[128] = {
136+ {0xff08, 0x66}, /* Back space */
137+ {0xff09, 0x0d}, /* Tab */
138+ {0xff0d, 0x5a}, /* Return */
139+@@ -159,7 +166,7 @@ static const struct extended_translation extended_tran
140+ };
141+
142+ /* ASCII to type 2 scancode lookup table */
143+-static const uint8_t ascii_translations[128] = {
144++static uint8_t ascii_translations[128] = {
145+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148+@@ -319,7 +326,7 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
149+ assert(pthread_mutex_isowned_np(&sc->mtx));
150+ int e0_prefix, found;
151+ uint8_t code;
152+- const struct extended_translation *trans;
153++ struct extended_translation *trans;
154+
155+ if (keycode) {
156+ code = (uint8_t)(keycode & 0x7f);
157+@@ -375,10 +382,91 @@ ps2kbd_event(int down, uint32_t keysym, uint32_t keyco
158+ atkbdc_event(sc->atkbdc_sc, 1);
159+ }
160+
161++static void
162++ps2kbd_update_extended_translation(uint32_t keycode, uint32_t scancode, uint32_t prefix)
163++{
164++ int i = 0;
165++
166++ do {
167++ if (extended_translations[i].keysym == keycode)
168++ break;
169++ } while(extended_translations[++i].keysym);
170++
171++ if (i == (sizeof(extended_translations) / sizeof(struct extended_translation) - 1))
172++ return;
173++
174++ if (!extended_translations[i].keysym) {
175++ extended_translations[i].keysym = keycode;
176++
177++ extended_translations[i+1].keysym = 0;
178++ extended_translations[i+1].scancode = 0;
179++ extended_translations[i+1].flags = 0;
180++ }
181++
182++ extended_translations[i].scancode = (uint8_t)(scancode & 0xff);
183++ extended_translations[i].flags = (prefix ? SCANCODE_E0_PREFIX : 0);
184++}
185++
186++static void
187++ps2kbd_setkbdlayout(void)
188++{
189++ int err;
190++ int fd;
191++ char path[256];
192++ char *buf, *next, *line;
193++ struct stat sb;
194++ size_t sz;
195++ uint8_t ascii;
196++ uint32_t keycode, scancode, prefix;
197++
198++ strcpy(path, PS2KBD_LAYOUT_BASEDIR);
199++ strncat(path, kbdlayout_name, (sizeof(path) - strlen(PS2KBD_LAYOUT_BASEDIR) - 1));
200++
201++ err = stat(path, &sb);
202++ if (err)
203++ return;
204++
205++ buf = (char *)malloc(sizeof(char) * sb.st_size);
206++ if (buf == NULL)
207++ return;
208++
209++ fd = open(path, O_RDONLY);
210++ if (fd == -1)
211++ goto out;
212++
213++ sz = read(fd, buf, sb.st_size );
214++
215++ close(fd);
216++
217++ if (sz != sb.st_size )
218++ goto out;
219++
220++ next = buf;
221++ while ((line = strsep(&next, "\n")) != NULL) {
222++ if (sscanf(line, "'%c',%x;", &ascii, &scancode) == 2) {
223++ if (ascii < 0x80)
224++ ascii_translations[ascii] = (uint8_t)(scancode & 0xff);
225++ } else if (sscanf(line, "%x,%x,%x;", &keycode, &scancode, &prefix) == 3 ) {
226++ ps2kbd_update_extended_translation(keycode, scancode, prefix);
227++ } else if (sscanf(line, "%x,%x;", &keycode, &scancode) == 2) {
228++ if (keycode < 0x80)
229++ ascii_translations[(uint8_t)(keycode & 0xff)] = (uint8_t)(scancode & 0xff);
230++ else
231++ ps2kbd_update_extended_translation(keycode, scancode, 0);
232++ }
233++ }
234++
235++out:
236++ free(buf);
237++}
238++
239+ struct ps2kbd_softc *
240+ ps2kbd_init(struct atkbdc_softc *atkbdc_sc)
241+ {
242+ struct ps2kbd_softc *sc;
243++
244++ if (kbdlayout_name != NULL)
245++ ps2kbd_setkbdlayout();
246+
247+ sc = calloc(1, sizeof (struct ps2kbd_softc));
248+ pthread_mutex_init(&sc->mtx, NULL);
--- /dev/null
+++ b/kbdlayout_option/bhyve_kbdlayout_option_fbsd13c.patch
@@ -0,0 +1,251 @@
1+diff -upN bhyve_base/Makefile bhyve/Makefile
2+--- bhyve_base/Makefile 2020-06-03 10:29:29.352291000 +0900
3++++ bhyve/Makefile 2020-06-03 18:14:34.462454000 +0900
4+@@ -121,4 +121,6 @@ CFLAGS+=-DGDB_LOG
5+
6+ WARNS?= 2
7+
8++SUBDIR= kbdlayout
9++
10+ .include <bsd.prog.mk>
11+diff -upN bhyve_base/bhyve.8 bhyve/bhyve.8
12+--- bhyve_base/bhyve.8 2020-06-03 10:29:29.331537000 +0900
13++++ bhyve/bhyve.8 2020-06-03 18:14:34.464867000 +0900
14+@@ -47,6 +47,7 @@
15+ .Sm on
16+ .Op Fl G Ar port
17+ .Op Fl g Ar gdbport
18++.Op Fl k Ar layout
19+ .Oo Fl l
20+ .Sm off
21+ .Cm help | Ar lpcdev Op Cm \&, Ar conf
22+@@ -162,6 +163,13 @@ Print help message and exit.
23+ .It Fl H
24+ Yield the virtual CPU thread when a HLT instruction is detected.
25+ If this option is not specified, virtual CPUs will use 100% of a host CPU.
26++.It Fl k Ar layout
27++Specify the keyboard layout.
28++The value that can be specified sets the file name in
29++.Ar /usr/share/bhyve/kbdlayout .
30++This specification only works when loaded with UEFI mode.(Not working via console or SSH)
31++If you are using a VNC client that supports QEMU Extended Key Event Message (e.g. TigerVNC), don't need to specify this option.
32++If you are using a VNC client that doesn't support it(e.g. tightVNC), and you don't specify this option, the US keyboard layout(default) is specified.
33+ .It Fl l Op Ar help|lpcdev Ns Op , Ns Ar conf
34+ Allow devices behind the LPC PCI-ISA bridge to be configured.
35+ The only supported devices are the TTY-class devices
36+diff -upN bhyve_base/bhyverun.c bhyve/bhyverun.c
37+--- bhyve_base/bhyverun.c 2020-06-03 10:29:29.370019000 +0900
38++++ bhyve/bhyverun.c 2020-06-03 18:19:50.608647000 +0900
39+@@ -188,6 +188,8 @@ const char *vmname;
40+ int guest_ncpus;
41+ uint16_t cores, maxcpus, sockets, threads;
42+
43++char *kbdlayout_name;
44++
45+ char *guest_uuid_str;
46+
47+ int raw_stdio = 0;
48+@@ -237,7 +239,7 @@ usage(int code)
49+ fprintf(stderr,
50+ "Usage: %s [-abehuwxACHPSWY]\n"
51+ " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n"
52+- " %*s [-g <gdb port>] [-l <lpc>]\n"
53++ " %*s [-g <gdb port>] [-k layout] [-l <lpc>]\n"
54+ " %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
55+ " -a: local apic is in xAPIC mode (deprecated)\n"
56+ " -A: create ACPI tables\n"
57+@@ -247,6 +249,7 @@ usage(int code)
58+ " -g: gdb port\n"
59+ " -h: help\n"
60+ " -H: vmexit from the guest on hlt\n"
61++ " -k: PS2 keyboard layout\n"
62+ " -l: LPC device configuration\n"
63+ " -m: memory size in MB\n"
64+ #ifdef BHYVE_SNAPSHOT
65+@@ -1084,11 +1087,12 @@ main(int argc, char *argv[])
66+ mptgen = 1;
67+ rtc_localtime = 1;
68+ memflags = 0;
69++ kbdlayout_name = NULL;
70+
71+ #ifdef BHYVE_SNAPSHOT
72+- optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:r:";
73++ optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:k:U:r:";
74+ #else
75+- optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:";
76++ optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:k:U:";
77+ #endif
78+ while ((c = getopt(argc, argv, optstr)) != -1) {
79+ switch (c) {
80+@@ -1125,6 +1129,9 @@ main(int argc, char *argv[])
81+ optarg++;
82+ }
83+ gdb_port = atoi(optarg);
84++ break;
85++ case 'k':
86++ kbdlayout_name = optarg;
87+ break;
88+ case 'l':
89+ if (strncmp(optarg, "help", strlen(optarg)) == 0) {
90+diff -upN bhyve_base/bhyverun.h bhyve/bhyverun.h
91+--- bhyve_base/bhyverun.h 2020-06-03 10:29:29.289487000 +0900
92++++ bhyve/bhyverun.h 2020-06-03 18:18:13.198204000 +0900
93+@@ -39,6 +39,7 @@ extern int guest_ncpus;
94+ extern uint16_t cores, sockets, threads;
95+ extern char *guest_uuid_str;
96+ extern const char *vmname;
97++extern char *kbdlayout_name;
98+
99+ void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
100+ #ifdef BHYVE_SNAPSHOT
101+Common subdirectories: bhyve_base/kbdlayout and bhyve/kbdlayout
102+diff -upN bhyve_base/ps2kbd.c bhyve/ps2kbd.c
103+--- bhyve_base/ps2kbd.c 2020-06-03 10:31:37.339319000 +0900
104++++ bhyve/ps2kbd.c 2020-06-03 18:17:01.983386000 +0900
105+@@ -31,6 +31,7 @@
106+ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 360648 2020-05-05 00:02:04Z jhb $");
107+
108+ #include <sys/types.h>
109++#include <sys/stat.h>
110+
111+ #include <machine/vmm_snapshot.h>
112+
113+@@ -42,7 +43,10 @@ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 36064
114+ #include <strings.h>
115+ #include <pthread.h>
116+ #include <pthread_np.h>
117++#include <unistd.h>
118++#include <fcntl.h>
119+
120++#include "bhyverun.h"
121+ #include "atkbdc.h"
122+ #include "debug.h"
123+ #include "console.h"
124+@@ -62,6 +66,8 @@ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 36064
125+
126+ #define PS2KBD_FIFOSZ 16
127+
128++#define PS2KBD_LAYOUT_BASEDIR "/usr/share/bhyve/kbdlayout/"
129++
130+ struct fifo {
131+ uint8_t buf[PS2KBD_FIFOSZ];
132+ uint8_t trans[PS2KBD_FIFOSZ];
133+@@ -91,7 +97,7 @@ struct extended_translation {
134+ /*
135+ * FIXME: Pause/break and Print Screen/SysRq require special handling.
136+ */
137+-static const struct extended_translation extended_translations[] = {
138++static struct extended_translation extended_translations[128] = {
139+ {0xff08, 0x66}, /* Back space */
140+ {0xff09, 0x0d}, /* Tab */
141+ {0xff0d, 0x5a}, /* Return */
142+@@ -163,7 +169,7 @@ static const struct extended_translation extended_tran
143+ };
144+
145+ /* ASCII to type 2 scancode lookup table */
146+-static const uint8_t ascii_translations[128] = {
147++static uint8_t ascii_translations[128] = {
148+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151+@@ -323,7 +329,7 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
152+ assert(pthread_mutex_isowned_np(&sc->mtx));
153+ int e0_prefix, found;
154+ uint8_t code;
155+- const struct extended_translation *trans;
156++ struct extended_translation *trans;
157+
158+ if (keycode) {
159+ code = (uint8_t)(keycode & 0x7f);
160+@@ -379,10 +385,91 @@ ps2kbd_event(int down, uint32_t keysym, uint32_t keyco
161+ atkbdc_event(sc->atkbdc_sc, 1);
162+ }
163+
164++static void
165++ps2kbd_update_extended_translation(uint32_t keycode, uint32_t scancode, uint32_t prefix)
166++{
167++ int i = 0;
168++
169++ do {
170++ if (extended_translations[i].keysym == keycode)
171++ break;
172++ } while(extended_translations[++i].keysym);
173++
174++ if (i == (sizeof(extended_translations) / sizeof(struct extended_translation) - 1))
175++ return;
176++
177++ if (!extended_translations[i].keysym) {
178++ extended_translations[i].keysym = keycode;
179++
180++ extended_translations[i+1].keysym = 0;
181++ extended_translations[i+1].scancode = 0;
182++ extended_translations[i+1].flags = 0;
183++ }
184++
185++ extended_translations[i].scancode = (uint8_t)(scancode & 0xff);
186++ extended_translations[i].flags = (prefix ? SCANCODE_E0_PREFIX : 0);
187++}
188++
189++static void
190++ps2kbd_setkbdlayout(void)
191++{
192++ int err;
193++ int fd;
194++ char path[256];
195++ char *buf, *next, *line;
196++ struct stat sb;
197++ size_t sz;
198++ uint8_t ascii;
199++ uint32_t keycode, scancode, prefix;
200++
201++ strcpy(path, PS2KBD_LAYOUT_BASEDIR);
202++ strncat(path, kbdlayout_name, (sizeof(path) - strlen(PS2KBD_LAYOUT_BASEDIR) - 1));
203++
204++ err = stat(path, &sb);
205++ if (err)
206++ return;
207++
208++ buf = (char *)malloc(sizeof(char) * sb.st_size);
209++ if (buf == NULL)
210++ return;
211++
212++ fd = open(path, O_RDONLY);
213++ if (fd == -1)
214++ goto out;
215++
216++ sz = read(fd, buf, sb.st_size );
217++
218++ close(fd);
219++
220++ if (sz != sb.st_size )
221++ goto out;
222++
223++ next = buf;
224++ while ((line = strsep(&next, "\n")) != NULL) {
225++ if (sscanf(line, "'%c',%x;", &ascii, &scancode) == 2) {
226++ if (ascii < 0x80)
227++ ascii_translations[ascii] = (uint8_t)(scancode & 0xff);
228++ } else if (sscanf(line, "%x,%x,%x;", &keycode, &scancode, &prefix) == 3 ) {
229++ ps2kbd_update_extended_translation(keycode, scancode, prefix);
230++ } else if (sscanf(line, "%x,%x;", &keycode, &scancode) == 2) {
231++ if (keycode < 0x80)
232++ ascii_translations[(uint8_t)(keycode & 0xff)] = (uint8_t)(scancode & 0xff);
233++ else
234++ ps2kbd_update_extended_translation(keycode, scancode, 0);
235++ }
236++ }
237++
238++out:
239++ free(buf);
240++}
241++
242+ struct ps2kbd_softc *
243+ ps2kbd_init(struct atkbdc_softc *atkbdc_sc)
244+ {
245+ struct ps2kbd_softc *sc;
246++
247++ if (kbdlayout_name != NULL)
248++ ps2kbd_setkbdlayout();
249+
250+ sc = calloc(1, sizeof (struct ps2kbd_softc));
251+ pthread_mutex_init(&sc->mtx, NULL);
--- /dev/null
+++ b/kbdlayout_option/bhyve_kbdlayout_vmrunsh_fbsd121r.patch
@@ -0,0 +1,41 @@
1+diff -upN examples/bhyve_orig/vmrun.sh examples/bhyve/vmrun.sh
2+--- examples/bhyve_orig/vmrun.sh 2019-11-01 09:01:57.000000000 +0900
3++++ examples/bhyve/vmrun.sh 2020-05-30 20:39:06.066218000 +0900
4+@@ -59,8 +59,8 @@ usage() {
5+ echo " [-e <name=value>] [-f <path of firmware>]" \
6+ "[-F <size>]"
7+ echo " [-g <gdbport> ] [-H <directory>]"
8+- echo " [-I <location of installation iso>] [-l <loader>]"
9+- echo " [-L <VNC IP for UEFI framebuffer>]"
10++ echo " [-I <location of installation iso>] [-k <layout>]"
11++ echo " [-l <loader>] [-L <VNC IP for UEFI framebuffer>]"
12+ echo " [-m <memsize>]" \
13+ "[-n <network adapter emulation type>]"
14+ echo " [-P <port>] [-t <tapdev>] <vmname>"
15+@@ -81,6 +81,7 @@ usage() {
16+ echo " -i: force boot of the Installation CDROM image"
17+ echo " -I: Installation CDROM image location" \
18+ "(default: ${DEFAULT_ISOFILE})"
19++ echo " -k: Specify the keyboard layout"
20+ echo " -l: the OS loader to use (default: /boot/userboot.so)"
21+ echo " -L: IP address for UEFI GOP VNC server" \
22+ "(default: ${DEFAULT_VNCHOST}"
23+@@ -134,7 +135,7 @@ vncport=${DEFAULT_VNCPORT}
24+ vncsize=${DEFAULT_VNCSIZE}
25+ tablet=""
26+
27+-while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:L:m:n:p:P:t:Tuvw c ; do
28++while getopts aAc:C:d:e:Ef:F:g:hH:iI:k:l:L:m:n:p:P:t:Tuvw c ; do
29+ case $c in
30+ a)
31+ bhyverun_opt="${bhyverun_opt} -a"
32+@@ -178,6 +179,9 @@ while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:L:m:n:p:P:t:Tuv
33+ ;;
34+ I)
35+ isofile=${OPTARG}
36++ ;;
37++ k)
38++ bhyverun_opt="${bhyverun_opt} -k ${OPTARG}"
39+ ;;
40+ l)
41+ loader_opt="${loader_opt} -l ${OPTARG}"
--- /dev/null
+++ b/kbdlayout_option/bhyve_kbdlayout_vmrunsh_fbsd13c.patch
@@ -0,0 +1,41 @@
1+diff -upN examples/bhyve_orig/vmrun.sh examples/bhyve/vmrun.sh
2+--- examples/bhyve_orig/vmrun.sh 2020-05-28 09:02:55.000000000 +0900
3++++ examples/bhyve/vmrun.sh 2020-06-03 19:37:56.271282000 +0900
4+@@ -59,8 +59,8 @@ usage() {
5+ echo " [-e <name=value>] [-f <path of firmware>]" \
6+ "[-F <size>]"
7+ echo " [-g <gdbport> ] [-H <directory>]"
8+- echo " [-I <location of installation iso>] [-l <loader>]"
9+- echo " [-L <VNC IP for UEFI framebuffer>]"
10++ echo " [-I <location of installation iso>] [-k <layout>]"
11++ echo " [-l <loader>] [-L <VNC IP for UEFI framebuffer>]"
12+ echo " [-m <memsize>]" \
13+ "[-n <network adapter emulation type>]"
14+ echo " [-P <port>] [-t <tapdev>] <vmname>"
15+@@ -81,6 +81,7 @@ usage() {
16+ echo " -i: force boot of the Installation CDROM image"
17+ echo " -I: Installation CDROM image location" \
18+ "(default: ${DEFAULT_ISOFILE})"
19++ echo " -k: Specify the keyboard layout"
20+ echo " -l: the OS loader to use (default: /boot/userboot.so)"
21+ echo " -L: IP address for UEFI GOP VNC server" \
22+ "(default: ${DEFAULT_VNCHOST}"
23+@@ -134,7 +135,7 @@ vncport=${DEFAULT_VNCPORT}
24+ vncsize=${DEFAULT_VNCSIZE}
25+ tablet=""
26+
27+-while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:L:m:n:p:P:t:Tuvw c ; do
28++while getopts aAc:C:d:e:Ef:F:g:hH:iI:k:l:L:m:n:p:P:t:Tuvw c ; do
29+ case $c in
30+ a)
31+ bhyverun_opt="${bhyverun_opt} -a"
32+@@ -178,6 +179,9 @@ while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:L:m:n:p:P:t:Tuv
33+ ;;
34+ I)
35+ isofile=${OPTARG}
36++ ;;
37++ k)
38++ bhyverun_opt="${bhyverun_opt} -k ${OPTARG}"
39+ ;;
40+ l)
41+ loader_opt="${loader_opt} -l ${OPTARG}"
--- a/kbdlayout_option/bhyve_kbdlayout_fbsd121r.patch
+++ b/qemu_ext_keyevent_msg/bhyve_qemu_ext_key_event_msg_fbsd121r.patch
@@ -1,16 +1,6 @@
1-diff -upN bhyve_orig/Makefile bhyve/Makefile
2---- bhyve_orig/Makefile 2020-05-01 11:25:57.446272000 +0900
3-+++ bhyve/Makefile 2020-05-28 09:25:47.142698000 +0900
4-@@ -95,4 +95,6 @@ CFLAGS+=-DGDB_LOG
5-
6- WARNS?= 2
7-
8-+SUBDIR= kbdlayout
9-+
10- .include <bsd.prog.mk>
111 diff -upN bhyve_orig/atkbdc.c bhyve/atkbdc.c
122 --- bhyve_orig/atkbdc.c 2020-05-01 11:25:57.441270000 +0900
13-+++ bhyve/atkbdc.c 2020-05-28 16:28:56.411057000 +0900
3++++ bhyve/atkbdc.c 2020-06-02 20:27:26.516809000 +0900
144 @@ -211,24 +211,25 @@ atkbdc_kbd_read(struct atkbdc_softc *sc)
155 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
166 };
@@ -40,95 +30,9 @@ diff -upN bhyve_orig/atkbdc.c bhyve/atkbdc.c
4030 atkbdc_kbd_queue_data(sc, val);
4131 else
4232 break;
43-diff -upN bhyve_orig/bhyve.8 bhyve/bhyve.8
44---- bhyve_orig/bhyve.8 2020-05-01 11:25:57.441891000 +0900
45-+++ bhyve/bhyve.8 2020-05-28 14:26:02.139585000 +0900
46-@@ -44,6 +44,7 @@
47- .Op Ar ,threads=n
48- .Oc
49- .Op Fl g Ar gdbport
50-+.Op Fl k Ar layout
51- .Op Fl l Ar help|lpcdev Ns Op , Ns Ar conf
52- .Op Fl m Ar memsize Ns Op Ar K|k|M|m|G|g|T|t
53- .Op Fl p Ar vcpu:hostcpu
54-@@ -144,6 +145,13 @@ Print help message and exit.
55- .It Fl H
56- Yield the virtual CPU thread when a HLT instruction is detected.
57- If this option is not specified, virtual CPUs will use 100% of a host CPU.
58-+.It Fl k Ar layout
59-+Specify the keyboard layout.
60-+The value that can be specified sets the file name in
61-+.Ar /usr/share/bhyve/kbdlayout .
62-+This specification only works when loaded with UEFI mode.(Not working via console or SSH)
63-+If you are using a VNC client that supports QEMU Extended Key Event Message (e.g. TigerVNC), don't need to specify this option.
64-+If you are using a VNC client that doesn't support it(e.g. tightVNC), and you don't specify this option, the US keyboard layout(default) is specified.
65- .It Fl l Op Ar help|lpcdev Ns Op , Ns Ar conf
66- Allow devices behind the LPC PCI-ISA bridge to be configured.
67- The only supported devices are the TTY-class devices
68-diff -upN bhyve_orig/bhyverun.c bhyve/bhyverun.c
69---- bhyve_orig/bhyverun.c 2020-05-01 11:25:57.439138000 +0900
70-+++ bhyve/bhyverun.c 2020-05-28 09:25:47.144660000 +0900
71-@@ -165,6 +165,8 @@ char *vmname;
72- int guest_ncpus;
73- uint16_t cores, maxcpus, sockets, threads;
74-
75-+char *kbdlayout_name;
76-+
77- char *guest_uuid_str;
78-
79- static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
80-@@ -211,7 +213,7 @@ usage(int code)
81- fprintf(stderr,
82- "Usage: %s [-abehuwxACHPSWY]\n"
83- " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n"
84-- " %*s [-g <gdb port>] [-l <lpc>]\n"
85-+ " %*s [-g <gdb port>] [-k layout] [-l <lpc>]\n"
86- " %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
87- " -a: local apic is in xAPIC mode (deprecated)\n"
88- " -A: create ACPI tables\n"
89-@@ -221,6 +223,7 @@ usage(int code)
90- " -g: gdb port\n"
91- " -h: help\n"
92- " -H: vmexit from the guest on hlt\n"
93-+ " -k: PS2 keyboard layout\n"
94- " -l: LPC device configuration\n"
95- " -m: memory size in MB\n"
96- " -p: pin 'vcpu' to 'hostcpu'\n"
97-@@ -996,8 +999,9 @@ main(int argc, char *argv[])
98- mptgen = 1;
99- rtc_localtime = 1;
100- memflags = 0;
101-+ kbdlayout_name = NULL;
102-
103-- optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:";
104-+ optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:k:U:";
105- while ((c = getopt(argc, argv, optstr)) != -1) {
106- switch (c) {
107- case 'a':
108-@@ -1033,6 +1037,9 @@ main(int argc, char *argv[])
109- optarg++;
110- }
111- gdb_port = atoi(optarg);
112-+ break;
113-+ case 'k':
114-+ kbdlayout_name = optarg;
115- break;
116- case 'l':
117- if (strncmp(optarg, "help", strlen(optarg)) == 0) {
118-diff -upN bhyve_orig/bhyverun.h bhyve/bhyverun.h
119---- bhyve_orig/bhyverun.h 2020-05-01 11:25:57.444136000 +0900
120-+++ bhyve/bhyverun.h 2020-05-28 09:25:47.145111000 +0900
121-@@ -39,6 +39,7 @@ extern int guest_ncpus;
122- extern uint16_t cores, sockets, threads;
123- extern char *guest_uuid_str;
124- extern char *vmname;
125-+extern char *kbdlayout_name;
126-
127- void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
128-
12933 diff -upN bhyve_orig/console.c bhyve/console.c
13034 --- bhyve_orig/console.c 2020-05-01 11:25:57.441001000 +0900
131-+++ bhyve/console.c 2020-05-28 10:47:10.699395000 +0900
35++++ bhyve/console.c 2020-06-02 20:27:26.517334000 +0900
13236 @@ -106,10 +106,10 @@ console_ptr_register(ptr_event_func_t event_cb, void *
13337 }
13438
@@ -144,7 +48,7 @@ diff -upN bhyve_orig/console.c bhyve/console.c
14448 void
14549 diff -upN bhyve_orig/console.h bhyve/console.h
14650 --- bhyve_orig/console.h 2020-05-01 11:25:57.446732000 +0900
147-+++ bhyve/console.h 2020-05-28 10:47:47.290438000 +0900
51++++ bhyve/console.h 2020-06-02 20:27:26.517796000 +0900
14852 @@ -34,7 +34,7 @@
14953 struct bhyvegc;
15054
@@ -163,62 +67,18 @@ diff -upN bhyve_orig/console.h bhyve/console.h
16367
16468 void console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri);
16569 void console_ptr_event(uint8_t button, int x, int y);
166-Common subdirectories: bhyve_orig/kbdlayout and bhyve/kbdlayout
16770 diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
16871 --- bhyve_orig/ps2kbd.c 2020-05-01 11:25:57.446548000 +0900
169-+++ bhyve/ps2kbd.c 2020-05-28 16:28:16.325233000 +0900
170-@@ -31,15 +31,20 @@
171- __FBSDID("$FreeBSD: releng/12.1/usr.sbin/bhyve/ps2kbd.c 341757 2018-12-09 06:41:57Z araujo $");
172-
173- #include <sys/types.h>
174-+#include <sys/stat.h>
175-
176- #include <assert.h>
177- #include <stdbool.h>
178- #include <stdio.h>
179- #include <stdlib.h>
180-+#include <string.h>
181- #include <strings.h>
182- #include <pthread.h>
183- #include <pthread_np.h>
184-+#include <unistd.h>
185-+#include <fcntl.h>
186-
187-+#include "bhyverun.h"
188- #include "atkbdc.h"
189- #include "console.h"
190-
191-@@ -58,8 +63,11 @@ __FBSDID("$FreeBSD: releng/12.1/usr.sbin/bhyve/ps2kbd.
72++++ bhyve/ps2kbd.c 2020-06-02 20:29:26.881702000 +0900
73+@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD: releng/12.1/usr.sbin/bhyve/ps2kbd.
19274
193- #define PS2KBD_FIFOSZ 16
194-
195-+#define PS2KBD_LAYOUT_BASEDIR "/usr/share/bhyve/kbdlayout/"
196-+
19775 struct fifo {
19876 uint8_t buf[PS2KBD_FIFOSZ];
19977 + uint8_t trans[PS2KBD_FIFOSZ];
20078 int rindex; /* index to read from */
20179 int windex; /* index to write to */
20280 int num; /* number of bytes in the fifo */
203-@@ -86,7 +94,7 @@ struct extended_translation {
204- /*
205- * FIXME: Pause/break and Print Screen/SysRq require special handling.
206- */
207--static const struct extended_translation extended_translations[] = {
208-+static struct extended_translation extended_translations[128] = {
209- {0xff08, 0x66}, /* Back space */
210- {0xff09, 0x0d}, /* Tab */
211- {0xff0d, 0x5a}, /* Return */
212-@@ -158,7 +166,7 @@ static const struct extended_translation extended_tran
213- };
214-
215- /* ASCII to type 2 scancode lookup table */
216--static const uint8_t ascii_translations[128] = {
217-+static uint8_t ascii_translations[128] = {
218- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221-@@ -197,26 +205,28 @@ fifo_reset(struct ps2kbd_softc *sc)
81+@@ -197,26 +198,28 @@ fifo_reset(struct ps2kbd_softc *sc)
22282 }
22383
22484 static void
@@ -249,7 +109,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
249109 fifo->rindex = (fifo->rindex + 1) % fifo->size;
250110 fifo->num--;
251111 return (0);
252-@@ -226,12 +236,12 @@ fifo_get(struct ps2kbd_softc *sc, uint8_t *val)
112+@@ -226,12 +229,12 @@ fifo_get(struct ps2kbd_softc *sc, uint8_t *val)
253113 }
254114
255115 int
@@ -264,7 +124,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
264124 pthread_mutex_unlock(&sc->mtx);
265125
266126 return (retval);
267-@@ -244,13 +254,13 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
127+@@ -244,13 +247,13 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
268128 if (sc->curcmd) {
269129 switch (sc->curcmd) {
270130 case PS2KC_SET_TYPEMATIC:
@@ -281,7 +141,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
281141 break;
282142 default:
283143 fprintf(stderr, "Unhandled ps2 keyboard current "
284-@@ -261,41 +271,41 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
144+@@ -261,41 +264,41 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
285145 } else {
286146 switch (val) {
287147 case 0x00:
@@ -335,7 +195,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
335195 break;
336196 default:
337197 fprintf(stderr, "Unhandled ps2 keyboard command "
338-@@ -311,26 +321,32 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
198+@@ -311,26 +314,32 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
339199 */
340200 static void
341201 ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
@@ -345,8 +205,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
345205 assert(pthread_mutex_isowned_np(&sc->mtx));
346206 int e0_prefix, found;
347207 uint8_t code;
348-- const struct extended_translation *trans;
349-+ struct extended_translation *trans;
208+ const struct extended_translation *trans;
350209
351210 - found = 0;
352211 - if (keysym < 0x80) {
@@ -381,7 +240,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
381240 }
382241 }
383242 }
384-@@ -341,14 +357,14 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
243+@@ -341,14 +350,14 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
385244 }
386245
387246 if (e0_prefix)
@@ -400,7 +259,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
400259 {
401260 struct ps2kbd_softc *sc = arg;
402261 int fifo_full;
403-@@ -359,17 +375,98 @@ ps2kbd_event(int down, uint32_t keysym, void *arg)
262+@@ -359,7 +368,7 @@ ps2kbd_event(int down, uint32_t keysym, void *arg)
404263 return;
405264 }
406265 fifo_full = sc->fifo.num == PS2KBD_FIFOSZ;
@@ -409,100 +268,9 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
409268 pthread_mutex_unlock(&sc->mtx);
410269
411270 if (!fifo_full)
412- atkbdc_event(sc->atkbdc_sc, 1);
413- }
414-
415-+static void
416-+ps2kbd_update_extended_translation(uint32_t keycode, uint32_t scancode, uint32_t prefix)
417-+{
418-+ int i = 0;
419-+
420-+ do {
421-+ if (extended_translations[i].keysym == keycode)
422-+ break;
423-+ } while(extended_translations[++i].keysym);
424-+
425-+ if (i == (sizeof(extended_translations) / sizeof(struct extended_translation) - 1))
426-+ return;
427-+
428-+ if (!extended_translations[i].keysym) {
429-+ extended_translations[i].keysym = keycode;
430-+
431-+ extended_translations[i+1].keysym = 0;
432-+ extended_translations[i+1].scancode = 0;
433-+ extended_translations[i+1].flags = 0;
434-+ }
435-+
436-+ extended_translations[i].scancode = (uint8_t)(scancode & 0xff);
437-+ extended_translations[i].flags = (prefix ? SCANCODE_E0_PREFIX : 0);
438-+}
439-+
440-+static void
441-+ps2kbd_setkbdlayout(void)
442-+{
443-+ int err;
444-+ int fd;
445-+ char path[256];
446-+ char *buf, *next, *line;
447-+ struct stat sb;
448-+ size_t sz;
449-+ uint8_t ascii;
450-+ uint32_t keycode, scancode, prefix;
451-+
452-+ strcpy(path, PS2KBD_LAYOUT_BASEDIR);
453-+ strncat(path, kbdlayout_name, (sizeof(path) - strlen(PS2KBD_LAYOUT_BASEDIR) - 1));
454-+
455-+ err = stat(path, &sb);
456-+ if (err)
457-+ return;
458-+
459-+ buf = (char *)malloc(sizeof(char) * sb.st_size);
460-+ if (buf == NULL)
461-+ return;
462-+
463-+ fd = open(path, O_RDONLY);
464-+ if (fd == -1)
465-+ goto out;
466-+
467-+ sz = read(fd, buf, sb.st_size );
468-+
469-+ close(fd);
470-+
471-+ if (sz != sb.st_size )
472-+ goto out;
473-+
474-+ next = buf;
475-+ while ((line = strsep(&next, "\n")) != NULL) {
476-+ if (sscanf(line, "'%c',%x;", &ascii, &scancode) == 2) {
477-+ if (ascii < 0x80)
478-+ ascii_translations[ascii] = (uint8_t)(scancode & 0xff);
479-+ } else if (sscanf(line, "%x,%x,%x;", &keycode, &scancode, &prefix) == 3 ) {
480-+ ps2kbd_update_extended_translation(keycode, scancode, prefix);
481-+ } else if (sscanf(line, "%x,%x;", &keycode, &scancode) == 2) {
482-+ if (keycode < 0x80)
483-+ ascii_translations[(uint8_t)(keycode & 0xff)] = (uint8_t)(scancode & 0xff);
484-+ else
485-+ ps2kbd_update_extended_translation(keycode, scancode, 0);
486-+ }
487-+ }
488-+
489-+out:
490-+ free(buf);
491-+}
492-+
493- struct ps2kbd_softc *
494- ps2kbd_init(struct atkbdc_softc *atkbdc_sc)
495- {
496- struct ps2kbd_softc *sc;
497-+
498-+ if (kbdlayout_name != NULL)
499-+ ps2kbd_setkbdlayout();
500-
501- sc = calloc(1, sizeof (struct ps2kbd_softc));
502- pthread_mutex_init(&sc->mtx, NULL);
503271 diff -upN bhyve_orig/ps2kbd.h bhyve/ps2kbd.h
504272 --- bhyve_orig/ps2kbd.h 2020-05-01 11:25:57.441775000 +0900
505-+++ bhyve/ps2kbd.h 2020-05-28 13:42:50.937234000 +0900
273++++ bhyve/ps2kbd.h 2020-06-02 20:27:26.519082000 +0900
506274 @@ -35,7 +35,7 @@ struct atkbdc_softc;
507275
508276 struct ps2kbd_softc *ps2kbd_init(struct atkbdc_softc *sc);
@@ -514,7 +282,7 @@ diff -upN bhyve_orig/ps2kbd.h bhyve/ps2kbd.h
514282 #endif /* _PS2KBD_H_ */
515283 diff -upN bhyve_orig/rfb.c bhyve/rfb.c
516284 --- bhyve_orig/rfb.c 2020-05-01 11:25:57.446856000 +0900
517-+++ bhyve/rfb.c 2020-05-28 13:16:38.135646000 +0900
285++++ bhyve/rfb.c 2020-06-02 20:27:26.520216000 +0900
518286 @@ -97,7 +97,10 @@ struct rfb_softc {
519287 bool enc_raw_ok;
520288 bool enc_zlib_ok;
--- a/kbdlayout_option/bhyve_kbdlayout_fbsd13c.patch
+++ b/qemu_ext_keyevent_msg/bhyve_qemu_ext_key_event_msg_fbsd13c.patch
@@ -1,17 +1,7 @@
1-diff -upN bhyve_orig/Makefile bhyve/Makefile
2---- bhyve_orig/Makefile 2020-04-23 09:06:39.000000000 +0900
3-+++ bhyve/Makefile 2020-05-29 18:03:10.627095000 +0900
4-@@ -99,4 +99,6 @@ CFLAGS+=-DGDB_LOG
5-
6- WARNS?= 2
7-
8-+SUBDIR= kbdlayout
9-+
10- .include <bsd.prog.mk>
111 diff -upN bhyve_orig/atkbdc.c bhyve/atkbdc.c
12---- bhyve_orig/atkbdc.c 2020-04-23 09:06:39.000000000 +0900
13-+++ bhyve/atkbdc.c 2020-05-29 18:03:10.653893000 +0900
14-@@ -211,24 +211,25 @@ atkbdc_kbd_read(struct atkbdc_softc *sc)
2+--- bhyve_orig/atkbdc.c 2020-05-28 09:02:50.000000000 +0900
3++++ bhyve/atkbdc.c 2020-06-03 10:31:37.337347000 +0900
4+@@ -216,24 +216,25 @@ atkbdc_kbd_read(struct atkbdc_softc *sc)
155 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
166 };
177 uint8_t val;
@@ -40,95 +30,9 @@ diff -upN bhyve_orig/atkbdc.c bhyve/atkbdc.c
4030 atkbdc_kbd_queue_data(sc, val);
4131 else
4232 break;
43-diff -upN bhyve_orig/bhyve.8 bhyve/bhyve.8
44---- bhyve_orig/bhyve.8 2020-04-23 09:06:39.000000000 +0900
45-+++ bhyve/bhyve.8 2020-05-29 18:11:54.290185000 +0900
46-@@ -47,6 +47,7 @@
47- .Sm on
48- .Op Fl G Ar port
49- .Op Fl g Ar gdbport
50-+.Op Fl k Ar layout
51- .Oo Fl l
52- .Sm off
53- .Cm help | Ar lpcdev Op Cm \&, Ar conf
54-@@ -161,6 +162,13 @@ Print help message and exit.
55- .It Fl H
56- Yield the virtual CPU thread when a HLT instruction is detected.
57- If this option is not specified, virtual CPUs will use 100% of a host CPU.
58-+.It Fl k Ar layout
59-+Specify the keyboard layout.
60-+The value that can be specified sets the file name in
61-+.Ar /usr/share/bhyve/kbdlayout .
62-+This specification only works when loaded with UEFI mode.(Not working via console or SSH)
63-+If you are using a VNC client that supports QEMU Extended Key Event Message (e.g. TigerVNC), don't need to specify this option.
64-+If you are using a VNC client that doesn't support it(e.g. tightVNC), and you don't specify this option, the US keyboard layout(default) is specified.
65- .It Fl l Op Ar help|lpcdev Ns Op , Ns Ar conf
66- Allow devices behind the LPC PCI-ISA bridge to be configured.
67- The only supported devices are the TTY-class devices
68-diff -upN bhyve_orig/bhyverun.c bhyve/bhyverun.c
69---- bhyve_orig/bhyverun.c 2020-04-23 09:06:39.000000000 +0900
70-+++ bhyve/bhyverun.c 2020-05-29 18:03:10.699642000 +0900
71-@@ -168,6 +168,8 @@ char *vmname;
72- int guest_ncpus;
73- uint16_t cores, maxcpus, sockets, threads;
74-
75-+char *kbdlayout_name;
76-+
77- char *guest_uuid_str;
78-
79- int raw_stdio = 0;
80-@@ -217,7 +219,7 @@ usage(int code)
81- fprintf(stderr,
82- "Usage: %s [-abehuwxACHPSWY]\n"
83- " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n"
84-- " %*s [-g <gdb port>] [-l <lpc>]\n"
85-+ " %*s [-g <gdb port>] [-k layout] [-l <lpc>]\n"
86- " %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
87- " -a: local apic is in xAPIC mode (deprecated)\n"
88- " -A: create ACPI tables\n"
89-@@ -227,6 +229,7 @@ usage(int code)
90- " -g: gdb port\n"
91- " -h: help\n"
92- " -H: vmexit from the guest on hlt\n"
93-+ " -k: PS2 keyboard layout\n"
94- " -l: LPC device configuration\n"
95- " -m: memory size in MB\n"
96- " -p: pin 'vcpu' to 'hostcpu'\n"
97-@@ -1020,8 +1023,9 @@ main(int argc, char *argv[])
98- mptgen = 1;
99- rtc_localtime = 1;
100- memflags = 0;
101-+ kbdlayout_name = NULL;
102-
103-- optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:";
104-+ optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:k:U:";
105- while ((c = getopt(argc, argv, optstr)) != -1) {
106- switch (c) {
107- case 'a':
108-@@ -1057,6 +1061,9 @@ main(int argc, char *argv[])
109- optarg++;
110- }
111- gdb_port = atoi(optarg);
112-+ break;
113-+ case 'k':
114-+ kbdlayout_name = optarg;
115- break;
116- case 'l':
117- if (strncmp(optarg, "help", strlen(optarg)) == 0) {
118-diff -upN bhyve_orig/bhyverun.h bhyve/bhyverun.h
119---- bhyve_orig/bhyverun.h 2020-04-23 09:06:39.000000000 +0900
120-+++ bhyve/bhyverun.h 2020-05-29 18:03:10.703030000 +0900
121-@@ -39,6 +39,7 @@ extern int guest_ncpus;
122- extern uint16_t cores, sockets, threads;
123- extern char *guest_uuid_str;
124- extern char *vmname;
125-+extern char *kbdlayout_name;
126-
127- void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
128-
12933 diff -upN bhyve_orig/console.c bhyve/console.c
130---- bhyve_orig/console.c 2020-04-23 09:06:39.000000000 +0900
131-+++ bhyve/console.c 2020-05-29 18:03:10.705936000 +0900
34+--- bhyve_orig/console.c 2020-05-28 09:02:50.000000000 +0900
35++++ bhyve/console.c 2020-06-03 10:31:37.338047000 +0900
13236 @@ -106,10 +106,10 @@ console_ptr_register(ptr_event_func_t event_cb, void *
13337 }
13438
@@ -143,8 +47,8 @@ diff -upN bhyve_orig/console.c bhyve/console.c
14347
14448 void
14549 diff -upN bhyve_orig/console.h bhyve/console.h
146---- bhyve_orig/console.h 2020-04-23 09:06:39.000000000 +0900
147-+++ bhyve/console.h 2020-05-29 18:03:10.708779000 +0900
50+--- bhyve_orig/console.h 2020-05-28 09:02:50.000000000 +0900
51++++ bhyve/console.h 2020-06-03 10:31:37.338668000 +0900
14852 @@ -34,7 +34,7 @@
14953 struct bhyvegc;
15054
@@ -163,62 +67,18 @@ diff -upN bhyve_orig/console.h bhyve/console.h
16367
16468 void console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri);
16569 void console_ptr_event(uint8_t button, int x, int y);
166-Common subdirectories: bhyve_orig/kbdlayout and bhyve/kbdlayout
16770 diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
168---- bhyve_orig/ps2kbd.c 2020-04-23 09:06:39.000000000 +0900
169-+++ bhyve/ps2kbd.c 2020-05-29 18:03:10.788431000 +0900
170-@@ -31,15 +31,20 @@
171- __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 356523 2020-01-08 22:55:22Z vmaffione $");
172-
173- #include <sys/types.h>
174-+#include <sys/stat.h>
175-
176- #include <assert.h>
177- #include <stdbool.h>
178- #include <stdio.h>
179- #include <stdlib.h>
180-+#include <string.h>
181- #include <strings.h>
182- #include <pthread.h>
183- #include <pthread_np.h>
184-+#include <unistd.h>
185-+#include <fcntl.h>
186-
187-+#include "bhyverun.h"
188- #include "atkbdc.h"
189- #include "debug.h"
190- #include "console.h"
191-@@ -59,8 +64,11 @@ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 35652
192-
193- #define PS2KBD_FIFOSZ 16
194-
195-+#define PS2KBD_LAYOUT_BASEDIR "/usr/share/bhyve/kbdlayout/"
196-+
71+--- bhyve_orig/ps2kbd.c 2020-05-28 09:02:50.000000000 +0900
72++++ bhyve/ps2kbd.c 2020-06-03 10:31:37.339319000 +0900
73+@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/ps2kbd.c 36064
74+
19775 struct fifo {
19876 uint8_t buf[PS2KBD_FIFOSZ];
19977 + uint8_t trans[PS2KBD_FIFOSZ];
20078 int rindex; /* index to read from */
20179 int windex; /* index to write to */
20280 int num; /* number of bytes in the fifo */
203-@@ -87,7 +95,7 @@ struct extended_translation {
204- /*
205- * FIXME: Pause/break and Print Screen/SysRq require special handling.
206- */
207--static const struct extended_translation extended_translations[] = {
208-+static struct extended_translation extended_translations[128] = {
209- {0xff08, 0x66}, /* Back space */
210- {0xff09, 0x0d}, /* Tab */
211- {0xff0d, 0x5a}, /* Return */
212-@@ -159,7 +167,7 @@ static const struct extended_translation extended_tran
213- };
214-
215- /* ASCII to type 2 scancode lookup table */
216--static const uint8_t ascii_translations[128] = {
217-+static uint8_t ascii_translations[128] = {
218- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221-@@ -198,26 +206,28 @@ fifo_reset(struct ps2kbd_softc *sc)
81+@@ -201,26 +202,28 @@ fifo_reset(struct ps2kbd_softc *sc)
22282 }
22383
22484 static void
@@ -249,7 +109,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
249109 fifo->rindex = (fifo->rindex + 1) % fifo->size;
250110 fifo->num--;
251111 return (0);
252-@@ -227,12 +237,12 @@ fifo_get(struct ps2kbd_softc *sc, uint8_t *val)
112+@@ -230,12 +233,12 @@ fifo_get(struct ps2kbd_softc *sc, uint8_t *val)
253113 }
254114
255115 int
@@ -264,7 +124,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
264124 pthread_mutex_unlock(&sc->mtx);
265125
266126 return (retval);
267-@@ -245,13 +255,13 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
127+@@ -248,13 +251,13 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
268128 if (sc->curcmd) {
269129 switch (sc->curcmd) {
270130 case PS2KC_SET_TYPEMATIC:
@@ -281,7 +141,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
281141 break;
282142 default:
283143 EPRINTLN("Unhandled ps2 keyboard current "
284-@@ -262,41 +272,41 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
144+@@ -265,41 +268,41 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
285145 } else {
286146 switch (val) {
287147 case 0x00:
@@ -335,7 +195,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
335195 break;
336196 default:
337197 EPRINTLN("Unhandled ps2 keyboard command "
338-@@ -312,26 +322,32 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
198+@@ -315,26 +318,32 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val)
339199 */
340200 static void
341201 ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
@@ -345,8 +205,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
345205 assert(pthread_mutex_isowned_np(&sc->mtx));
346206 int e0_prefix, found;
347207 uint8_t code;
348-- const struct extended_translation *trans;
349-+ struct extended_translation *trans;
208+ const struct extended_translation *trans;
350209
351210 - found = 0;
352211 - if (keysym < 0x80) {
@@ -381,7 +240,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
381240 }
382241 }
383242 }
384-@@ -342,14 +358,14 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
243+@@ -345,14 +354,14 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
385244 }
386245
387246 if (e0_prefix)
@@ -400,7 +259,7 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
400259 {
401260 struct ps2kbd_softc *sc = arg;
402261 int fifo_full;
403-@@ -360,17 +376,98 @@ ps2kbd_event(int down, uint32_t keysym, void *arg)
262+@@ -363,7 +372,7 @@ ps2kbd_event(int down, uint32_t keysym, void *arg)
404263 return;
405264 }
406265 fifo_full = sc->fifo.num == PS2KBD_FIFOSZ;
@@ -409,101 +268,10 @@ diff -upN bhyve_orig/ps2kbd.c bhyve/ps2kbd.c
409268 pthread_mutex_unlock(&sc->mtx);
410269
411270 if (!fifo_full)
412- atkbdc_event(sc->atkbdc_sc, 1);
413- }
414-
415-+static void
416-+ps2kbd_update_extended_translation(uint32_t keycode, uint32_t scancode, uint32_t prefix)
417-+{
418-+ int i = 0;
419-+
420-+ do {
421-+ if (extended_translations[i].keysym == keycode)
422-+ break;
423-+ } while(extended_translations[++i].keysym);
424-+
425-+ if (i == (sizeof(extended_translations) / sizeof(struct extended_translation) - 1))
426-+ return;
427-+
428-+ if (!extended_translations[i].keysym) {
429-+ extended_translations[i].keysym = keycode;
430-+
431-+ extended_translations[i+1].keysym = 0;
432-+ extended_translations[i+1].scancode = 0;
433-+ extended_translations[i+1].flags = 0;
434-+ }
435-+
436-+ extended_translations[i].scancode = (uint8_t)(scancode & 0xff);
437-+ extended_translations[i].flags = (prefix ? SCANCODE_E0_PREFIX : 0);
438-+}
439-+
440-+static void
441-+ps2kbd_setkbdlayout(void)
442-+{
443-+ int err;
444-+ int fd;
445-+ char path[256];
446-+ char *buf, *next, *line;
447-+ struct stat sb;
448-+ size_t sz;
449-+ uint8_t ascii;
450-+ uint32_t keycode, scancode, prefix;
451-+
452-+ strcpy(path, PS2KBD_LAYOUT_BASEDIR);
453-+ strncat(path, kbdlayout_name, (sizeof(path) - strlen(PS2KBD_LAYOUT_BASEDIR) - 1));
454-+
455-+ err = stat(path, &sb);
456-+ if (err)
457-+ return;
458-+
459-+ buf = (char *)malloc(sizeof(char) * sb.st_size);
460-+ if (buf == NULL)
461-+ return;
462-+
463-+ fd = open(path, O_RDONLY);
464-+ if (fd == -1)
465-+ goto out;
466-+
467-+ sz = read(fd, buf, sb.st_size );
468-+
469-+ close(fd);
470-+
471-+ if (sz != sb.st_size )
472-+ goto out;
473-+
474-+ next = buf;
475-+ while ((line = strsep(&next, "\n")) != NULL) {
476-+ if (sscanf(line, "'%c',%x;", &ascii, &scancode) == 2) {
477-+ if (ascii < 0x80)
478-+ ascii_translations[ascii] = (uint8_t)(scancode & 0xff);
479-+ } else if (sscanf(line, "%x,%x,%x;", &keycode, &scancode, &prefix) == 3 ) {
480-+ ps2kbd_update_extended_translation(keycode, scancode, prefix);
481-+ } else if (sscanf(line, "%x,%x;", &keycode, &scancode) == 2) {
482-+ if (keycode < 0x80)
483-+ ascii_translations[(uint8_t)(keycode & 0xff)] = (uint8_t)(scancode & 0xff);
484-+ else
485-+ ps2kbd_update_extended_translation(keycode, scancode, 0);
486-+ }
487-+ }
488-+
489-+out:
490-+ free(buf);
491-+}
492-+
493- struct ps2kbd_softc *
494- ps2kbd_init(struct atkbdc_softc *atkbdc_sc)
495- {
496- struct ps2kbd_softc *sc;
497-+
498-+ if (kbdlayout_name != NULL)
499-+ ps2kbd_setkbdlayout();
500-
501- sc = calloc(1, sizeof (struct ps2kbd_softc));
502- pthread_mutex_init(&sc->mtx, NULL);
503271 diff -upN bhyve_orig/ps2kbd.h bhyve/ps2kbd.h
504---- bhyve_orig/ps2kbd.h 2020-04-23 09:06:39.000000000 +0900
505-+++ bhyve/ps2kbd.h 2020-05-29 18:03:10.795460000 +0900
506-@@ -35,7 +35,7 @@ struct atkbdc_softc;
272+--- bhyve_orig/ps2kbd.h 2020-05-28 09:02:50.000000000 +0900
273++++ bhyve/ps2kbd.h 2020-06-03 10:31:37.339486000 +0900
274+@@ -36,7 +36,7 @@ struct vm_snapshot_meta;
507275
508276 struct ps2kbd_softc *ps2kbd_init(struct atkbdc_softc *sc);
509277
@@ -511,10 +279,10 @@ diff -upN bhyve_orig/ps2kbd.h bhyve/ps2kbd.h
511279 +int ps2kbd_read(struct ps2kbd_softc *sc, uint8_t *val, uint8_t *trans);
512280 void ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val);
513281
514- #endif /* _PS2KBD_H_ */
282+ #ifdef BHYVE_SNAPSHOT
515283 diff -upN bhyve_orig/rfb.c bhyve/rfb.c
516---- bhyve_orig/rfb.c 2020-04-23 09:06:39.000000000 +0900
517-+++ bhyve/rfb.c 2020-05-29 18:03:10.843000000 +0900
284+--- bhyve_orig/rfb.c 2020-05-28 09:02:50.000000000 +0900
285++++ bhyve/rfb.c 2020-06-03 10:31:37.339898000 +0900
518286 @@ -99,7 +99,10 @@ struct rfb_softc {
519287 bool enc_raw_ok;
520288 bool enc_zlib_ok;