Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/vmt Removed little endian dependencies.



details:   https://anonhg.NetBSD.org/src/rev/e9833150bb49
branches:  trunk
changeset: 954017:e9833150bb49
user:      ryo <ryo%NetBSD.org@localhost>
date:      Sat Mar 27 21:23:14 2021 +0000

description:
Removed little endian dependencies.
Now vmt(4) works on aarch64eb on vmware ESXIonARM.

diffstat:

 sys/dev/vmt/vmt_subr.c |  254 ++++++++++++++++++++++--------------------------
 sys/dev/vmt/vmtvar.h   |   64 +++++------
 2 files changed, 147 insertions(+), 171 deletions(-)

diffs (truncated from 498 to 300 lines):

diff -r 52899e5c9158 -r e9833150bb49 sys/dev/vmt/vmt_subr.c
--- a/sys/dev/vmt/vmt_subr.c    Sat Mar 27 19:59:22 2021 +0000
+++ b/sys/dev/vmt/vmt_subr.c    Sat Mar 27 21:23:14 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmt_subr.c,v 1.2 2020/11/17 17:59:31 ryo Exp $ */
+/* $NetBSD: vmt_subr.c,v 1.3 2021/03/27 21:23:14 ryo Exp $ */
 /* $OpenBSD: vmt.c,v 1.11 2011/01/27 21:29:25 dtucker Exp $ */
 
 /*
@@ -90,12 +90,10 @@
 {
        memset(frame, 0, sizeof(*frame));
 
-       (frame->eax).word = VM_MAGIC;
-       (frame->ebx).word = ~VM_MAGIC;
-       (frame->ecx).part.low = cmd;
-       (frame->ecx).part.high = 0xffff;
-       (frame->edx).part.low  = VM_PORT_CMD;
-       (frame->edx).part.high = 0;
+       frame->eax = VM_MAGIC;
+       frame->ebx = ~VM_MAGIC & VM_REG_WORD_MASK;
+       frame->ecx = VM_REG_CMD(0xffff, cmd);
+       frame->edx = VM_REG_CMD(0, VM_PORT_CMD);
 
        vm_cmd(frame);
 }
@@ -103,26 +101,18 @@
 bool
 vmt_probe(void)
 {
-#if BYTE_ORDER == BIG_ENDIAN
-       /*
-        * XXX: doesn't support in big-endian.
-        * vmt has some code depends on little-endian.
-        */
-       return false;
-#else
        struct vm_backdoor frame;
 
        vmt_probe_cmd(&frame, VM_CMD_GET_VERSION);
-       if (frame.eax.word == 0xffffffff ||
-           frame.ebx.word != VM_MAGIC)
+       if (__SHIFTOUT(frame.eax, VM_REG_WORD_MASK) == 0xffffffff ||
+           __SHIFTOUT(frame.ebx, VM_REG_WORD_MASK) != VM_MAGIC)
                return false;
 
        vmt_probe_cmd(&frame, VM_CMD_GET_SPEED);
-       if (frame.eax.word == VM_MAGIC)
+       if (__SHIFTOUT(frame.eax, VM_REG_WORD_MASK) == VM_MAGIC)
                return false;
 
        return true;
-#endif
 }
 
 void
@@ -137,8 +127,8 @@
 
        /* check again */
        vmt_probe_cmd(&frame, VM_CMD_GET_VERSION);
-       if (frame.eax.word == 0xffffffff ||
-           frame.ebx.word != VM_MAGIC) {
+       if (__SHIFTOUT(frame.eax, VM_REG_WORD_MASK) == 0xffffffff ||
+           __SHIFTOUT(frame.ebx, VM_REG_WORD_MASK) != VM_MAGIC) {
                aprint_error_dev(self, "failed to get VMware version\n");
                return;
        }
@@ -149,16 +139,17 @@
                uint32_t u;
 
                vmt_probe_cmd(&frame, VM_CMD_GET_BIOS_UUID);
-               uuid.time_low = htobe32(frame.eax.word);
-               u = htobe32(frame.ebx.word);
+               uuid.time_low =
+                   bswap32(__SHIFTOUT(frame.eax, VM_REG_WORD_MASK));
+               u = bswap32(__SHIFTOUT(frame.ebx, VM_REG_WORD_MASK));
                uuid.time_mid = u >> 16;
                uuid.time_hi_and_version = u;
-               u = htobe32(frame.ecx.word);
+               u = bswap32(__SHIFTOUT(frame.ecx, VM_REG_WORD_MASK));
                uuid.clock_seq_hi_and_reserved = u >> 24;
                uuid.clock_seq_low = u >> 16;
                uuid.node[0] = u >> 8;
                uuid.node[1] = u;
-               u = htobe32(frame.edx.word);
+               u = bswap32(__SHIFTOUT(frame.edx, VM_REG_WORD_MASK));
                uuid.node[2] = u >> 24;
                uuid.node[3] = u >> 16;
                uuid.node[4] = u >> 8;
@@ -421,14 +412,16 @@
        struct timespec ts;
 
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word = VM_MAGIC;
-       frame.ecx.part.low = VM_CMD_GET_TIME_FULL;
-       frame.edx.part.low  = VM_PORT_CMD;
+       frame.eax = VM_MAGIC;
+       frame.ecx = VM_CMD_GET_TIME_FULL;
+       frame.edx = VM_REG_CMD(0, VM_PORT_CMD);
        vm_cmd(&frame);
 
-       if (frame.eax.word != 0xffffffff) {
-               ts.tv_sec = ((uint64_t)frame.esi.word << 32) | frame.edx.word;
-               ts.tv_nsec = frame.ebx.word * 1000;
+       if (__SHIFTOUT(frame.eax, VM_REG_WORD_MASK) != 0xffffffff) {
+               ts.tv_sec = ((uint64_t)(
+                   __SHIFTOUT(frame.esi, VM_REG_WORD_MASK) << 32)) |
+                   __SHIFTOUT(frame.edx, VM_REG_WORD_MASK);
+               ts.tv_nsec = __SHIFTOUT(frame.ebx, VM_REG_WORD_MASK) * 1000;
                tc_setclock(&ts);
        }
 }
@@ -738,25 +731,25 @@
        struct vm_backdoor frame;
 
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word      = VM_MAGIC;
-       frame.ebx.word      = proto | VM_RPC_FLAG_COOKIE;
-       frame.ecx.part.low  = VM_CMD_RPC;
-       frame.ecx.part.high = VM_RPC_OPEN;
-       frame.edx.part.low  = VM_PORT_CMD;
-       frame.edx.part.high = 0;
+       frame.eax = VM_MAGIC;
+       frame.ebx = proto | VM_RPC_FLAG_COOKIE;
+       frame.ecx = VM_REG_CMD_RPC(VM_RPC_OPEN);
+       frame.edx = VM_REG_PORT_CMD(0);
 
        vm_cmd(&frame);
 
-       if (frame.ecx.part.high != 1 || frame.edx.part.low != 0) {
+       if (__SHIFTOUT(frame.ecx, VM_REG_HIGH_MASK) != 1 ||
+           __SHIFTOUT(frame.edx, VM_REG_LOW_MASK) != 0) {
                /* open-vm-tools retries without VM_RPC_FLAG_COOKIE here.. */
-               printf("vmware: open failed, eax=%08x, ecx=%08x, edx=%08x\n",
-                       frame.eax.word, frame.ecx.word, frame.edx.word);
+               printf("vmware: open failed, eax=%#"PRIxREGISTER
+                   ", ecx=%#"PRIxREGISTER", edx=%#"PRIxREGISTER"\n",
+                   frame.eax, frame.ecx, frame.edx);
                return EIO;
        }
 
-       rpc->channel = frame.edx.part.high;
-       rpc->cookie1 = frame.esi.word;
-       rpc->cookie2 = frame.edi.word;
+       rpc->channel = __SHIFTOUT(frame.edx, VM_REG_HIGH_MASK);
+       rpc->cookie1 = __SHIFTOUT(frame.esi, VM_REG_WORD_MASK);
+       rpc->cookie2 = __SHIFTOUT(frame.edi, VM_REG_WORD_MASK);
 
        return 0;
 }
@@ -767,20 +760,20 @@
        struct vm_backdoor frame;
 
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word      = VM_MAGIC;
-       frame.ebx.word      = 0;
-       frame.ecx.part.low  = VM_CMD_RPC;
-       frame.ecx.part.high = VM_RPC_CLOSE;
-       frame.edx.part.low  = VM_PORT_CMD;
-       frame.edx.part.high = rpc->channel;
-       frame.edi.word      = rpc->cookie2;
-       frame.esi.word      = rpc->cookie1;
+       frame.eax = VM_MAGIC;
+       frame.ebx = 0;
+       frame.ecx = VM_REG_CMD_RPC(VM_RPC_CLOSE);
+       frame.edx = VM_REG_PORT_CMD(rpc->channel);
+       frame.edi = rpc->cookie2;
+       frame.esi = rpc->cookie1;
 
        vm_cmd(&frame);
 
-       if (frame.ecx.part.high == 0 || frame.ecx.part.low != 0) {
-               printf("vmware: close failed, eax=%08x, ecx=%08x\n",
-                               frame.eax.word, frame.ecx.word);
+       if (__SHIFTOUT(frame.ecx, VM_REG_HIGH_MASK) == 0 ||
+           __SHIFTOUT(frame.ecx, VM_REG_LOW_MASK) != 0) {
+               printf("vmware: close failed, "
+                   "eax=%#"PRIxREGISTER", ecx=%#"PRIxREGISTER"\n",
+                   frame.eax, frame.ecx);
                return EIO;
        }
 
@@ -798,20 +791,20 @@
 
        /* Send the length of the command. */
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word = VM_MAGIC;
-       frame.ebx.word = length;
-       frame.ecx.part.low  = VM_CMD_RPC;
-       frame.ecx.part.high = VM_RPC_SET_LENGTH;
-       frame.edx.part.low  = VM_PORT_CMD;
-       frame.edx.part.high = rpc->channel;
-       frame.esi.word = rpc->cookie1;
-       frame.edi.word = rpc->cookie2;
+       frame.eax = VM_MAGIC;
+       frame.ebx = length;
+       frame.ecx = VM_REG_CMD_RPC(VM_RPC_SET_LENGTH);
+       frame.edx = VM_REG_PORT_CMD(rpc->channel);
+       frame.esi = rpc->cookie1;
+       frame.edi = rpc->cookie2;
 
        vm_cmd(&frame);
 
-       if ((frame.ecx.part.high & VM_RPC_REPLY_SUCCESS) == 0) {
-               printf("vmware: sending length failed, eax=%08x, ecx=%08x\n",
-                               frame.eax.word, frame.ecx.word);
+       if ((__SHIFTOUT(frame.ecx, VM_REG_HIGH_MASK) & VM_RPC_REPLY_SUCCESS) ==
+           0) {
+               printf("vmware: sending length failed, "
+                   "eax=%#"PRIxREGISTER", ecx=%#"PRIxREGISTER"\n",
+                   frame.eax, frame.ecx);
                return EIO;
        }
 
@@ -820,24 +813,20 @@
 
        /* Send the command using enhanced RPC. */
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word = VM_MAGIC;
-       frame.ebx.word = VM_RPC_ENH_DATA;
-       frame.ecx.word = length;
-       frame.edx.part.low  = VM_PORT_RPC;
-       frame.edx.part.high = rpc->channel;
-       frame.ebp.word = rpc->cookie1;
-       frame.edi.word = rpc->cookie2;
-#if defined(__amd64__) || defined(__aarch64__)
-       frame.esi.quad = (uint64_t)buf;
-#else
-       frame.esi.word = (uint32_t)buf;
-#endif
+       frame.eax = VM_MAGIC;
+       frame.ebx = VM_RPC_ENH_DATA;
+       frame.ecx = length;
+       frame.edx = VM_REG_PORT_RPC(rpc->channel);
+       frame.ebp = rpc->cookie1;
+       frame.edi = rpc->cookie2;
+       frame.esi = (register_t)buf;
 
        vm_outs(&frame);
 
-       if (frame.ebx.word != VM_RPC_ENH_DATA) {
+       if (__SHIFTOUT(frame.ebx, VM_REG_WORD_MASK) != VM_RPC_ENH_DATA) {
                /* open-vm-tools retries on VM_RPC_REPLY_CHECKPOINT */
-               printf("vmware: send failed, ebx=%08x\n", frame.ebx.word);
+               printf("vmware: send failed, ebx=%#"PRIxREGISTER"\n",
+                   frame.ebx);
                return EIO;
        }
 
@@ -858,46 +847,40 @@
 
        /* Get data using enhanced RPC. */
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word      = VM_MAGIC;
-       frame.ebx.word      = VM_RPC_ENH_DATA;
-       frame.ecx.word      = length;
-       frame.edx.part.low  = VM_PORT_RPC;
-       frame.edx.part.high = rpc->channel;
-       frame.esi.word      = rpc->cookie1;
-#if defined(__amd64__) || defined(__aarch64__)
-       frame.edi.quad      = (uint64_t)data;
-#else
-       frame.edi.word      = (uint32_t)data;
-#endif
-       frame.ebp.word      = rpc->cookie2;
+       frame.eax = VM_MAGIC;
+       frame.ebx = VM_RPC_ENH_DATA;
+       frame.ecx = length;
+       frame.edx = VM_REG_PORT_RPC(rpc->channel);
+       frame.esi = rpc->cookie1;
+       frame.edi = (register_t)data;
+       frame.ebp = rpc->cookie2;
 
        vm_ins(&frame);
 
        /* NUL-terminate the data */
        data[length] = '\0';
 
-       if (frame.ebx.word != VM_RPC_ENH_DATA) {
-               printf("vmware: get data failed, ebx=%08x\n",
-                               frame.ebx.word);
+       if (__SHIFTOUT(frame.ebx, VM_REG_WORD_MASK) != VM_RPC_ENH_DATA) {
+               printf("vmware: get data failed, ebx=%#"PRIxREGISTER"\n",
+                   frame.ebx);
                return EIO;
        }
 
        /* Acknowledge data received. */
        memset(&frame, 0, sizeof(frame));
-       frame.eax.word      = VM_MAGIC;
-       frame.ebx.word      = dataid;
-       frame.ecx.part.low  = VM_CMD_RPC;
-       frame.ecx.part.high = VM_RPC_GET_END;
-       frame.edx.part.low  = VM_PORT_CMD;
-       frame.edx.part.high = rpc->channel;
-       frame.esi.word      = rpc->cookie1;
-       frame.edi.word      = rpc->cookie2;
+       frame.eax = VM_MAGIC;
+       frame.ebx = dataid;
+       frame.ecx = VM_REG_CMD_RPC(VM_RPC_GET_END);



Home | Main Index | Thread Index | Old Index