ref: 52a3502927870a330f02a9b71cf9710f65f1a58a
parent: 2bb65c40ab0713b011ff758cc2d8bc20e885fe85
author: aiju <devnull@localhost>
date: Sat Jun 17 18:50:03 EDT 2017
vmx(1): support debug instructions
--- a/sys/src/cmd/vmx/dat.h
+++ b/sys/src/cmd/vmx/dat.h
@@ -15,6 +15,17 @@
#define RBX "bx"
#define RCX "cx"
#define RDX "dx"
+#define RBP "bp"
+#define RSI "si"
+#define RDI "di"
+#define R8 "r8"
+#define R9 "r9"
+#define R10 "r10"
+#define R11 "r11"
+#define R12 "r12"
+#define R13 "r13"
+#define R14 "r14"
+#define R15 "r15"
enum {
MMIORD = 0,
@@ -72,8 +83,12 @@
};
enum {
+ /* irqline argument */
IRQLTOGGLE = -1,
IRQLLOHI = -2,
+
+ /* postexc */
+ NOERRC = -1,
};
typedef struct VgaMode VgaMode;
--- a/sys/src/cmd/vmx/exith.c
+++ b/sys/src/cmd/vmx/exith.c
@@ -75,7 +75,7 @@
isin = (ei->qual & 8) != 0;
if((ei->qual & 1<<4) != 0){
vmerror("i/o string instruction not implemented");
- postexc("#ud", 0);
+ postexc("#ud", NOERRC);
return;
}
if(isin){
@@ -321,6 +321,37 @@
}
static void
+movdr(ExitInfo *ei)
+{
+ static char *reg[16] = {
+ RAX, RCX, RDX, RBX,
+ RSP, RBP, RSI, RDI,
+ R8, R9, R10, R11,
+ R12, R13, R14, R15
+ };
+ static char *dr[8] = { "dr0", "dr1", "dr2", "dr3", nil, nil, "dr6", "dr7" };
+ int q;
+
+ q = ei->qual;
+ if((q & 6) == 4){
+ postexc("#gp", 0);
+ return;
+ }
+ if((q & 16) != 0)
+ rset(reg[q >> 8 & 15], rget(dr[q & 7]));
+ else
+ rset(dr[q & 7], rget(reg[q >> 8 & 15]));
+ skipinstr(ei);
+}
+
+static void
+dbgexc(ExitInfo *ei)
+{
+ rset("dr6", rget("dr6") | ei->qual);
+ postexc("#db", NOERRC);
+}
+
+static void
hlt(ExitInfo *ei)
{
if(irqactive == 0)
@@ -347,6 +378,8 @@
{"*ack", irqackhand},
{".rdmsr", rdwrmsr},
{".wrmsr", rdwrmsr},
+ {".movdr", movdr},
+ {"#db", dbgexc},
};
void
@@ -391,7 +424,7 @@
}
if(*f[0] == '.'){
vmerror("vmx: unknown instruction %s", f[0]+1);
- postexc("#ud", 0);
+ postexc("#ud", NOERRC);
return;
}
if(*f[0] == '*'){
--- a/sys/src/cmd/vmx/fns.h
+++ b/sys/src/cmd/vmx/fns.h
@@ -13,7 +13,7 @@
void registermmio(uvlong, uvlong, uvlong (*)(int, uvlong, uvlong));
void irqline(int, int);
void irqack(int);
-void postexc(char *, u32int);
+void postexc(char *, vlong);
void vgaresize(void);
void uartinit(int, char *);
void sendnotif(void (*)(void *), void *);
--- a/sys/src/cmd/vmx/vmx.c
+++ b/sys/src/cmd/vmx/vmx.c
@@ -318,10 +318,14 @@
}
void
-postexc(char *name, u32int)
+postexc(char *name, vlong code)
{
- if(ctl("exc %s", name) < 0)
- sysfatal("ctl(postexc): %r");
+ if(code >= 0){
+ if(ctl("exc %s,%#ux", name, (u32int)code) < 0)
+ sysfatal("ctl(postexc): %r");
+ }else
+ if(ctl("exc %s", name) < 0)
+ sysfatal("ctl(postexc): %r");
}
void