Clean up Multiboot a bit
Thanks to Aimee for helping out with figuring out the iterator.
This commit is contained in:
parent
2b39ac909e
commit
9c5460c1f5
2 changed files with 47 additions and 76 deletions
|
@ -53,26 +53,26 @@ Information::setInformation(Information *info)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Information::MemoryMapIterator::MemoryMapIterator(uint32_t address,
|
Information::MemoryMapIterator::MemoryMapIterator(uint32_t address,
|
||||||
uint32_t count)
|
uint32_t length)
|
||||||
: mCurrent(reinterpret_cast<MemoryChunk *>(address)),
|
: mCurrent(address),
|
||||||
mCount(count)
|
mLength(length)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
Information::MemoryMapIterator::MemoryMapIterator(const MemoryMapIterator& other)
|
Information::MemoryMapIterator::MemoryMapIterator(const MemoryMapIterator& other)
|
||||||
: mCurrent(other.mCurrent),
|
: mCurrent(other.mCurrent),
|
||||||
mCount(other.mCount)
|
mLength(other.mLength)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
Information::MemoryMapIterator&
|
Information::MemoryMapIterator&
|
||||||
Information::MemoryMapIterator::operator++()
|
Information::MemoryMapIterator::operator++()
|
||||||
{
|
{
|
||||||
if (mCount > 0) {
|
if (mLength > 0) {
|
||||||
auto p = reinterpret_cast<uint32_t *>(mCurrent);
|
|
||||||
// The size of the current struct is stored at (mCurrent - 4) bytes.
|
// The size of the current struct is stored at (mCurrent - 4) bytes.
|
||||||
mCurrent = (mCurrent + p[-1]);
|
auto size = *reinterpret_cast<uint32_t*>(mCurrent) + 4;
|
||||||
mCount--;
|
mCurrent = mCurrent + size;
|
||||||
|
mLength = (size > mLength) ? 0 : mLength - size;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ Information::MemoryMapIterator::operator++()
|
||||||
Information::MemoryMapIterator
|
Information::MemoryMapIterator
|
||||||
Information::MemoryMapIterator::operator++(int)
|
Information::MemoryMapIterator::operator++(int)
|
||||||
{
|
{
|
||||||
MemoryMapIterator tmp(reinterpret_cast<uint32_t>(mCurrent), mCount);
|
MemoryMapIterator tmp(mCurrent, mLength);
|
||||||
operator++();
|
operator++();
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -90,10 +90,7 @@ Information::MemoryMapIterator::operator++(int)
|
||||||
MemoryChunk
|
MemoryChunk
|
||||||
Information::MemoryMapIterator::operator*()
|
Information::MemoryMapIterator::operator*()
|
||||||
{
|
{
|
||||||
if (mCount == 0) {
|
return *reinterpret_cast<MemoryChunk*>(mCurrent+4);
|
||||||
return MemoryChunk{0, 0, 0};
|
|
||||||
}
|
|
||||||
return *mCurrent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,11 +98,11 @@ bool
|
||||||
Information::MemoryMapIterator::operator==(const MemoryMapIterator& other)
|
Information::MemoryMapIterator::operator==(const MemoryMapIterator& other)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
if (mCount == 0 && other.mCount == 0) {
|
if (mLength == 0 && other.mLength == 0) {
|
||||||
// If both iterators have 0 counts, it doesn't matter what the mCurrent members point at.
|
// If both iterators have 0 counts, it doesn't matter what the mCurrent members point at.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return mCurrent == other.mCurrent && mCount == other.mCount;
|
return mCurrent == other.mCurrent && mLength == other.mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,17 +147,6 @@ Information::commandLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
Information::memoryMapChunks()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
if ((mFlags & Present::MemoryMap) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return memoryMapCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Information::MemoryMapIterator
|
Information::MemoryMapIterator
|
||||||
Information::memoryMapBegin()
|
Information::memoryMapBegin()
|
||||||
const
|
const
|
||||||
|
@ -168,7 +154,8 @@ Information::memoryMapBegin()
|
||||||
if ((mFlags & Present::MemoryMap) == 0) {
|
if ((mFlags & Present::MemoryMap) == 0) {
|
||||||
return memoryMapEnd();
|
return memoryMapEnd();
|
||||||
}
|
}
|
||||||
return MemoryMapIterator(memoryMapAddress, memoryMapCount);
|
auto& console = kernel::Console::systemConsole();
|
||||||
|
return MemoryMapIterator(mMemoryMapAddress, mMemoryMapLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Multiboot.hh
|
/* Multiboot.hh
|
||||||
* vim: set tw=80:
|
* vim: set tw=120:
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
@ -44,8 +44,8 @@ struct PACKED Information
|
||||||
bool operator!=(const MemoryMapIterator& other) const;
|
bool operator!=(const MemoryMapIterator& other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MemoryChunk *mCurrent;
|
uint32_t mCurrent;
|
||||||
uint32_t mCount;
|
uint32_t mLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const Information *information();
|
static const Information *information();
|
||||||
|
@ -56,7 +56,6 @@ struct PACKED Information
|
||||||
|
|
||||||
const char* commandLine() const;
|
const char* commandLine() const;
|
||||||
|
|
||||||
uint32_t memoryMapChunks() const;
|
|
||||||
MemoryMapIterator memoryMapBegin() const;
|
MemoryMapIterator memoryMapBegin() const;
|
||||||
MemoryMapIterator memoryMapEnd() const;
|
MemoryMapIterator memoryMapEnd() const;
|
||||||
|
|
||||||
|
@ -69,10 +68,7 @@ private:
|
||||||
/** Amount of upper (1 MB to ...) memory, in KB. Maximally, this value is the address of the first upper memory hole, minus 1 MB. */
|
/** Amount of upper (1 MB to ...) memory, in KB. Maximally, this value is the address of the first upper memory hole, minus 1 MB. */
|
||||||
uint32_t mMemUpper;
|
uint32_t mMemUpper;
|
||||||
|
|
||||||
/**
|
/** Indicates which BIOS disk the boot loader loaded the OS image from. */
|
||||||
* Indicates which BIOS disk the boot loader loaded the OS image from.
|
|
||||||
* Defined only if `bootDevice == true`.
|
|
||||||
*/
|
|
||||||
struct PACKED {
|
struct PACKED {
|
||||||
/** Third level partition number. If unused this is set to 0xFF. */
|
/** Third level partition number. If unused this is set to 0xFF. */
|
||||||
uint8_t partitionLevel3;
|
uint8_t partitionLevel3;
|
||||||
|
@ -80,33 +76,27 @@ private:
|
||||||
uint8_t partitionLevel2;
|
uint8_t partitionLevel2;
|
||||||
/** Top-level partition number. */
|
/** Top-level partition number. */
|
||||||
uint8_t partitionLevel1;
|
uint8_t partitionLevel1;
|
||||||
/**
|
/** BIOS drive number, as returned by the `INT 0x13` low-level disk interface. */
|
||||||
* BIOS drive number, as returned by the `INT 0x13` low-level disk
|
|
||||||
* interface.
|
|
||||||
*/
|
|
||||||
uint8_t driveNumber;
|
uint8_t driveNumber;
|
||||||
} bootDevice;
|
} mBootDevice;
|
||||||
|
|
||||||
/**
|
/** Pointer to a C-style string containing the command line arguments. */
|
||||||
* Pointer to a C-style string containing the command line arguments.
|
|
||||||
* Defined only if `commandLinePresent == true`.
|
|
||||||
*/
|
|
||||||
uint32_t mCommandLine;
|
uint32_t mCommandLine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Multiboot Modules
|
||||||
* Indicates what boot modules were loaded along with the kernel image.
|
* Indicates what boot modules were loaded along with the kernel image.
|
||||||
* Defined only if `modulesPresent == true`.
|
* Defined only if `modulesPresent == true`.
|
||||||
|
* @{
|
||||||
*/
|
*/
|
||||||
struct PACKED {
|
/** Number of boot modules present. */
|
||||||
/** Number of boot modules present. */
|
uint32_t mModulesCount;
|
||||||
uint32_t count;
|
/** Pointer to start of boot modules array. */
|
||||||
/** Pointer to start of boot modules array. */
|
uint32_t mModulesAddress;
|
||||||
uint32_t address;
|
/** @} */
|
||||||
} modules;
|
|
||||||
|
|
||||||
// TODO: Document these.
|
// TODO: Document these.
|
||||||
union PACKED
|
union PACKED {
|
||||||
{
|
|
||||||
struct PACKED {
|
struct PACKED {
|
||||||
uint32_t tableSize;
|
uint32_t tableSize;
|
||||||
uint32_t stringSize;
|
uint32_t stringSize;
|
||||||
|
@ -117,42 +107,36 @@ private:
|
||||||
uint32_t number;
|
uint32_t number;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
uint32_t shndx;
|
uint32_t shndx; // TODO: Bad name. What is this?
|
||||||
} elf;
|
} elf;
|
||||||
} symbols;
|
} symbols;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup Memory Map
|
* @defgroup Memory Map
|
||||||
* Points to a buffer containing a memory map of the machine provided by the
|
* Defines a buffer containing a memory map provided by the BIOS.
|
||||||
* BIOS. Defined only if `memoryMapPresent == true`.
|
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/** Number of memory map entries present. */
|
/** Length of the buffer, in bytes. The spec is somewhat unclear on this field. */
|
||||||
uint32_t memoryMapCount;
|
uint32_t mMemoryMapLength;
|
||||||
/** Pointer to start of memory map entry array. */
|
/** Pointer to start of memory map entry array. */
|
||||||
uint32_t memoryMapAddress;
|
uint32_t mMemoryMapAddress;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Points to a buffer containing a list of drive definitions provided by the
|
* @defgroup Drives
|
||||||
* BIOS. Defined only if `drivesPresent == true`.
|
* Defines a buffer containing a list of drive definitions provided by the BIOS.
|
||||||
|
* @{
|
||||||
*/
|
*/
|
||||||
struct PACKED {
|
/** Number of memory map entries present. */
|
||||||
/** Number of memory map entries present. */
|
uint32_t mDrivesLength;
|
||||||
uint32_t count;
|
/** Pointer to start of memory map entry array. */
|
||||||
/** Pointer to start of memory map entry array. */
|
uint32_t mDrivesAddress;
|
||||||
uint32_t address;
|
/** @} */
|
||||||
} drives;
|
|
||||||
|
|
||||||
/**
|
/** Pointer to a table containing APM information. */
|
||||||
* Pointer to the table containing APM information. Defined only if
|
uint32_t mAPMTable;
|
||||||
* `apmTablePresent == true`.
|
|
||||||
*/
|
|
||||||
uint32_t apmTable;
|
|
||||||
|
|
||||||
/**
|
/** I dunno some VBE stuff. TODO. */
|
||||||
* I dunno some VBE stuff. TODO.
|
|
||||||
*/
|
|
||||||
struct PACKED {
|
struct PACKED {
|
||||||
uint32_t controlInformation;
|
uint32_t controlInformation;
|
||||||
uint32_t modeInformation;
|
uint32_t modeInformation;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue