Verify buffer read length and offset

This commit is contained in:
copy 2013-11-28 00:59:36 +01:00
parent f520995582
commit 096001f9c9
4 changed files with 79 additions and 31 deletions

View file

@ -99,13 +99,21 @@ function DMA(dev)
dbg_log("DMA should read more than provided: " + h(len) + " " + h(read_count), LOG_DMA);
}
channels[channel].address += read_count;
buffer.get(start, read_count, function(data)
if(start + read_count > buffer.byteCount)
{
memory.write_blob(data, addr);
fn();
});
dbg_log("DMA read outside of buffer", LOG_DMA);
fn(true);
}
else
{
channels[channel].address += read_count;
buffer.get(start, read_count, function(data)
{
memory.write_blob(data, addr);
fn(false);
});
}
};
// write data, read memory
@ -116,19 +124,30 @@ function DMA(dev)
dbg_log("DMA write channel " + channel, LOG_DMA);
dbg_log("to " + h(addr) + " len " + h(read_count), LOG_DMA);
dbg_log(channels[channel], LOG_DMA);
//dbg_log(channels[channel], LOG_DMA);
if(len < read_count)
{
dbg_log("DMA should read more than provided", LOG_DMA);
}
buffer.set(start,
new Uint8Array(memory.buffer, addr, read_count + 1),
function() {
fn();
}
);
if(start + read_count > buffer.byteCount)
{
dbg_log("DMA write outside of buffer", LOG_DMA);
fn(true);
}
else
{
channels[channel].address += read_count;
buffer.set(start,
new Uint8Array(memory.buffer, addr, read_count + 1),
function() {
fn(false);
}
);
}
}
function flipflop_get(old_dword, new_byte)

View file

@ -287,7 +287,7 @@ function FloppyController(dev, floppy_image)
var head = args[2],
cylinder = args[1],
sector = args[3],
sector_size = 128 * (1 << args[4]),
sector_size = 128 << args[4],
read_count = args[5] - args[3] + 1,
read_offset = ((head + number_of_heads * cylinder) * sectors_per_track + sector - 1) * sector_size;
@ -310,8 +310,14 @@ function FloppyController(dev, floppy_image)
dma.do_read(floppy_image, read_offset, read_count * sector_size, 2, done);
}
function done()
function done(error)
{
if(error)
{
// TODO: Set appropriate bits
return;
}
sector++;
if(sector > sectors_per_track)

View file

@ -145,27 +145,36 @@ function IDEDevice(dev, buffer, is_cd, nr)
count = cmd[7] << 8 | cmd[8],
flags = cmd[1],
bytecount = count * me.sector_size,
transfered_ata_blocks = Math.min(bytecount / 512, cylinder_low << 8 | cylinder_high);
//bytecount = count;
transfered_ata_blocks = Math.min(bytecount / 512, cylinder_low << 8 | cylinder_high),
byte_count = count * me.sector_size,
start = lba * me.sector_size;
dbg_log("CD read lba=" + h(lba) +
" lbacount=" + h(count) +
" bytecount=" + h(count * me.sector_size) +
" bytecount=" + h(byte_count) +
" flags=" + h(flags), LOG_CD);
cylinder_low = transfered_ata_blocks >> 8;
cylinder_high = transfered_ata_blocks;
me.buffer.get(lba * me.sector_size, count * me.sector_size, function(data)
if(start + byte_count > buffer.byteLength)
{
//memory.write_blob(data, dest);
pio_data = data;
status = 0x58;
data_pointer = 0;
dbg_log("CD read: Outside of disk", LOG_DISK);
status = 0xFF;
push_irq();
});
}
else
{
me.buffer.get(start, byte_count, function(data)
{
pio_data = data;
status = 0x58;
data_pointer = 0;
push_irq();
});
}
}
function read_data_port(port_addr)
@ -539,7 +548,8 @@ function IDEDevice(dev, buffer, is_cd, nr)
// 0x24 read sectors ext
var count = bytecount,
lba = (cylinder_high << 16 | cylinder_low) >>> 0,
byte_count = count * me.sector_size;
byte_count = count * me.sector_size,
start = lba * me.sector_size;
dbg_log("ATA read lba=" + h(lba) +
" lbacount=" + h(count) +
@ -547,15 +557,24 @@ function IDEDevice(dev, buffer, is_cd, nr)
cylinder_low += count;
me.buffer.get(lba * me.sector_size, byte_count, function(data)
if(start + byte_count > buffer.byteLength)
{
pio_data = data;
status = 0x58;
data_pointer = 0;
dbg_log("ATA read: Outside of disk", LOG_DISK);
status = 0xFF;
push_irq();
});
}
else
{
me.buffer.get(start, byte_count, function(data)
{
pio_data = data;
status = 0x58;
data_pointer = 0;
push_irq();
});
}
}
else if(cmd === 0xEA)
{

View file

@ -232,11 +232,15 @@ function SyncBuffer(buffer)
// warning: fn may be called synchronously or asynchronously
this.get = function(start, len, fn)
{
dbg_assert(start + len <= buffer.byteLength);
fn(new Uint8Array(buffer, start, len));
};
this.set = function(start, slice, fn)
{
dbg_assert(start + slice.length <= buffer.byteLength);
new Uint8Array(buffer, start, slice.byteLength).set(slice);
fn();
};