Remove old DatBuffer class.

(also increase the number of sectors loaded by the bootloader in the
since I just noticed we were at the limit. This is not the ideal way
of doing this.)
This commit is contained in:
Andreas Kling 2018-10-25 10:49:43 +02:00
parent de7c54545a
commit 4bd69d4352
Notes: sideshowbarker 2024-07-19 18:39:07 +09:00
6 changed files with 9 additions and 128 deletions

View file

@ -42,7 +42,7 @@ boot:
inc word [cur_lba]
mov cx, word [cur_lba]
cmp cx, 400
cmp cx, 600
jz .sector_loop_end
mov bx, es

View file

@ -1,75 +0,0 @@
#include "DataBuffer.h"
#include "StdLib.h"
#define SANITIZE_DATABUFFER
DataBuffer::DataBuffer(size_t length)
: m_length(length)
, m_owned(true)
{
m_data = new BYTE[m_length];
#ifdef SANITIZE_DATABUFFER
memset(m_data, 0x1a, length);
#endif
}
DataBuffer::DataBuffer(BYTE* data, size_t length, ConstructionMode mode)
: m_length(length)
{
switch (mode) {
case Copy:
m_data = new BYTE[m_length];
memcpy(m_data, data, m_length);
m_owned = true;
break;
case Adopt:
m_data = data;
m_owned = true;
break;
case Wrap:
m_data = data;
m_owned = false;
break;
}
}
DataBuffer::~DataBuffer()
{
clear();
#ifdef SANITIZE_DATABUFFER
m_data = (BYTE*)0x88888888;
#endif
}
void DataBuffer::clear()
{
if (m_owned) {
#ifdef SANITIZE_DATABUFFER
memset(m_data, 0x99, m_length);
#endif
delete [] m_data;
}
m_owned = false;
m_data = nullptr;
m_length = 0;
}
RefPtr<DataBuffer> DataBuffer::createUninitialized(size_t length)
{
return adoptRef(new DataBuffer(length));
}
RefPtr<DataBuffer> DataBuffer::copy(const BYTE* data, size_t length)
{
return adoptRef(new DataBuffer(const_cast<BYTE*>(data), length, Copy));
}
RefPtr<DataBuffer> DataBuffer::wrap(BYTE* data, size_t length)
{
return adoptRef(new DataBuffer(data, length, Wrap));
}
RefPtr<DataBuffer> DataBuffer::adopt(BYTE* data, size_t length)
{
return adoptRef(new DataBuffer(data, length, Adopt));
}

View file

@ -1,39 +0,0 @@
#pragma once
#include "types.h"
#include "RefCounted.h"
#include "RefPtr.h"
class DataBuffer : public RefCounted<DataBuffer> {
public:
~DataBuffer();
BYTE operator[](size_t i) const { return m_data[i]; }
bool isEmpty() const { return !m_length; }
size_t length() const { return m_length; }
BYTE* data() { return m_data; }
const BYTE* data() const { return m_data; }
static RefPtr<DataBuffer> copy(const BYTE*, size_t length);
static RefPtr<DataBuffer> wrap(BYTE*, size_t length);
static RefPtr<DataBuffer> adopt(BYTE*, size_t length);
static RefPtr<DataBuffer> createUninitialized(size_t length);
void clear();
void leak() { m_data = nullptr; m_length = 0; m_owned = false; }
private:
DataBuffer() { }
DataBuffer(DataBuffer&&) = delete;
DataBuffer& operator=(DataBuffer&&) = delete;
enum ConstructionMode { Copy, Wrap, Adopt };
explicit DataBuffer(size_t length);
DataBuffer(BYTE*, size_t length, ConstructionMode);
DataBuffer(const DataBuffer&) = delete;
DataBuffer& operator=(const DataBuffer&) = delete;
BYTE* m_data { nullptr };
size_t m_length { 0 };
bool m_owned { false };
};

View file

@ -6,7 +6,6 @@
#include "StdLib.h"
#include "IO.h"
#include "i386.h"
#include "DataBuffer.h"
#include "PIC.h"
//#define DISK_DEBUG
@ -88,11 +87,11 @@ void initialize()
enableIRQ();
waitForInterrupt();
RefPtr<DataBuffer> wbuf = DataBuffer::createUninitialized(512);
BYTE* byteBuffer = new BYTE[512];
BYTE* b = byteBuffer;
WORD* wbufbase = (WORD*)wbuf->data();
WORD* w = (WORD*)wbuf->data();
ByteBuffer wbuf = ByteBuffer::createUninitialized(512);
ByteBuffer bbuf = ByteBuffer::createUninitialized(512);
BYTE* b = bbuf.pointer();
WORD* w = (WORD*)wbuf.pointer();
const WORD* wbufbase = (WORD*)wbuf.pointer();
for (DWORD i = 0; i < 256; ++i) {
WORD data = IO::in16(IDE0_DATA);
@ -102,8 +101,8 @@ void initialize()
}
// "Unpad" the device name string.
for (DWORD i = 93; i > 54 && byteBuffer[i] == ' '; --i)
byteBuffer[i] = 0;
for (DWORD i = 93; i > 54 && bbuf[i] == ' '; --i)
bbuf[i] = 0;
drive[0].cylinders = wbufbase[1];
drive[0].heads = wbufbase[3];
@ -111,13 +110,11 @@ void initialize()
kprintf(
"ide0: Master=\"%s\", C/H/Spt=%u/%u/%u\n",
byteBuffer + 54,
bbuf.pointer() + 54,
drive[0].cylinders,
drive[0].heads,
drive[0].sectors_per_track
);
delete byteBuffer;
}
struct CHS {

View file

@ -1,7 +1,6 @@
#pragma once
#include "types.h"
#include "DataBuffer.h"
#define IDE0_DATA 0x1F0
#define IDE0_STATUS 0x1F7

View file

@ -12,7 +12,6 @@ KERNEL_OBJS = \
IO.o \
PIC.o \
Syscall.o \
DataBuffer.o \
Disk.o \
Userspace.o \
IDEDiskDevice.o \