Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 906e5e7

Browse files
committed
Split Uint64 into 2 Uint32s
1 parent 433d9c4 commit 906e5e7

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

js/driver/virtio/blk.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@ const runtime = require('../../core');
1919
const VIRTIO_BLK_T_IN = 0;
2020
const VIRTIO_BLK_T_OUT = 1;
2121

22-
// not sure how to set uint64
23-
function setUint64LE(u8, offset, value) {
24-
u8[offset] = (value >>> 0);
25-
u8[offset + 1] = (value >>> 8);
26-
u8[offset + 2] = (value >>> 16);
27-
u8[offset + 3] = (value >>> 24);
28-
u8[offset + 4] = (value >>> 32);
29-
u8[offset + 5] = (value >>> 40);
30-
u8[offset + 6] = (value >>> 48);
31-
u8[offset + 7] = (value >>> 56);
22+
function split64(num) {
23+
let str = num.toString(2);
24+
for (let i = 0; i < 64 - str.length; i++) str = '0' + str;
25+
return [parseInt(str.substr(0, 32), 2), parseInt(str.substr(32), 2)];
3226
}
3327

3428
function initializeBlockDevice(pciDevice) {
@@ -79,8 +73,9 @@ function initializeBlockDevice(pciDevice) {
7973
const view = new DataView(u8.buffer);
8074
view.setUint32(0, type, true);
8175
view.setUint32(4, 0, true); // priority: low
82-
//setUint64LE(u8, 8, sector); // doesn't work as expected
83-
view.setFloat64(8, sector, true); // DataView doesn't have setUint64!
76+
const split = split64(sector);
77+
view.setUint32(8, split[1], true); // lo
78+
view.setUint32(12, split[0], true); // hi
8479
return u8;
8580
}
8681

0 commit comments

Comments
 (0)