1 | /* $Id: VSCSIInline.h 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Virtual SCSI driver: Inline helpers
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef ___VSCSIInline_h
|
---|
18 | #define ___VSCSIInline_h
|
---|
19 |
|
---|
20 | #include <iprt/stdint.h>
|
---|
21 |
|
---|
22 | DECLINLINE(void) vscsiH2BEU16(uint8_t *pbBuf, uint16_t val)
|
---|
23 | {
|
---|
24 | pbBuf[0] = val >> 8;
|
---|
25 | pbBuf[1] = val;
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | DECLINLINE(void) vscsiH2BEU24(uint8_t *pbBuf, uint32_t val)
|
---|
30 | {
|
---|
31 | pbBuf[0] = val >> 16;
|
---|
32 | pbBuf[1] = val >> 8;
|
---|
33 | pbBuf[2] = val;
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | DECLINLINE(void) vscsiH2BEU32(uint8_t *pbBuf, uint32_t val)
|
---|
38 | {
|
---|
39 | pbBuf[0] = val >> 24;
|
---|
40 | pbBuf[1] = val >> 16;
|
---|
41 | pbBuf[2] = val >> 8;
|
---|
42 | pbBuf[3] = val;
|
---|
43 | }
|
---|
44 |
|
---|
45 | DECLINLINE(void) vscsiH2BEU64(uint8_t *pbBuf, uint64_t val)
|
---|
46 | {
|
---|
47 | pbBuf[0] = val >> 56;
|
---|
48 | pbBuf[1] = val >> 48;
|
---|
49 | pbBuf[2] = val >> 40;
|
---|
50 | pbBuf[3] = val >> 32;
|
---|
51 | pbBuf[4] = val >> 24;
|
---|
52 | pbBuf[5] = val >> 16;
|
---|
53 | pbBuf[6] = val >> 8;
|
---|
54 | pbBuf[7] = val;
|
---|
55 | }
|
---|
56 |
|
---|
57 | DECLINLINE(uint16_t) vscsiBE2HU16(const uint8_t *pbBuf)
|
---|
58 | {
|
---|
59 | return (pbBuf[0] << 8) | pbBuf[1];
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | DECLINLINE(uint32_t) vscsiBE2HU24(const uint8_t *pbBuf)
|
---|
64 | {
|
---|
65 | return (pbBuf[0] << 16) | (pbBuf[1] << 8) | pbBuf[2];
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | DECLINLINE(uint32_t) vscsiBE2HU32(const uint8_t *pbBuf)
|
---|
70 | {
|
---|
71 | return (pbBuf[0] << 24) | (pbBuf[1] << 16) | (pbBuf[2] << 8) | pbBuf[3];
|
---|
72 | }
|
---|
73 |
|
---|
74 | DECLINLINE(uint64_t) vscsiBE2HU64(const uint8_t *pbBuf)
|
---|
75 | {
|
---|
76 | return ((uint64_t)pbBuf[0] << 56)
|
---|
77 | | ((uint64_t)pbBuf[1] << 48)
|
---|
78 | | ((uint64_t)pbBuf[2] << 40)
|
---|
79 | | ((uint64_t)pbBuf[3] << 32)
|
---|
80 | | ((uint64_t)pbBuf[4] << 24)
|
---|
81 | | ((uint64_t)pbBuf[5] << 16)
|
---|
82 | | ((uint64_t)pbBuf[6] << 8)
|
---|
83 | | (uint64_t)pbBuf[7];
|
---|
84 | }
|
---|
85 |
|
---|
86 | DECLINLINE(void) vscsiPadStr(int8_t *pbDst, const char *pbSrc, uint32_t cbSize)
|
---|
87 | {
|
---|
88 | for (uint32_t i = 0; i < cbSize; i++)
|
---|
89 | {
|
---|
90 | if (*pbSrc)
|
---|
91 | pbDst[i] = *pbSrc++;
|
---|
92 | else
|
---|
93 | pbDst[i] = ' ';
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | #endif /* ___VSCSIInline_h */
|
---|
98 |
|
---|