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,35 +53,35 @@ Information::setInformation(Information *info)
|
|||
*/
|
||||
|
||||
Information::MemoryMapIterator::MemoryMapIterator(uint32_t address,
|
||||
uint32_t count)
|
||||
: mCurrent(reinterpret_cast<MemoryChunk *>(address)),
|
||||
mCount(count)
|
||||
uint32_t length)
|
||||
: mCurrent(address),
|
||||
mLength(length)
|
||||
{ }
|
||||
|
||||
|
||||
Information::MemoryMapIterator::MemoryMapIterator(const MemoryMapIterator& other)
|
||||
: mCurrent(other.mCurrent),
|
||||
mCount(other.mCount)
|
||||
mLength(other.mLength)
|
||||
{ }
|
||||
|
||||
|
||||
Information::MemoryMapIterator&
|
||||
Information::MemoryMapIterator::operator++()
|
||||
{
|
||||
if (mCount > 0) {
|
||||
auto p = reinterpret_cast<uint32_t *>(mCurrent);
|
||||
if (mLength > 0) {
|
||||
// The size of the current struct is stored at (mCurrent - 4) bytes.
|
||||
mCurrent = (mCurrent + p[-1]);
|
||||
mCount--;
|
||||
auto size = *reinterpret_cast<uint32_t*>(mCurrent) + 4;
|
||||
mCurrent = mCurrent + size;
|
||||
mLength = (size > mLength) ? 0 : mLength - size;
|
||||
}
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Information::MemoryMapIterator
|
||||
Information::MemoryMapIterator::operator++(int)
|
||||
{
|
||||
MemoryMapIterator tmp(reinterpret_cast<uint32_t>(mCurrent), mCount);
|
||||
MemoryMapIterator tmp(mCurrent, mLength);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
|
@ -90,10 +90,7 @@ Information::MemoryMapIterator::operator++(int)
|
|||
MemoryChunk
|
||||
Information::MemoryMapIterator::operator*()
|
||||
{
|
||||
if (mCount == 0) {
|
||||
return MemoryChunk{0, 0, 0};
|
||||
}
|
||||
return *mCurrent;
|
||||
return *reinterpret_cast<MemoryChunk*>(mCurrent+4);
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,11 +98,11 @@ bool
|
|||
Information::MemoryMapIterator::operator==(const MemoryMapIterator& other)
|
||||
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.
|
||||
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::memoryMapBegin()
|
||||
const
|
||||
|
@ -168,7 +154,8 @@ Information::memoryMapBegin()
|
|||
if ((mFlags & Present::MemoryMap) == 0) {
|
||||
return memoryMapEnd();
|
||||
}
|
||||
return MemoryMapIterator(memoryMapAddress, memoryMapCount);
|
||||
auto& console = kernel::Console::systemConsole();
|
||||
return MemoryMapIterator(mMemoryMapAddress, mMemoryMapLength);
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,5 +165,5 @@ Information::memoryMapEnd()
|
|||
{
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
|
||||
} /* namespace multiboot */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Multiboot.hh
|
||||
* vim: set tw=80:
|
||||
* vim: set tw=120:
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
/**
|
||||
|
@ -44,8 +44,8 @@ struct PACKED Information
|
|||
bool operator!=(const MemoryMapIterator& other) const;
|
||||
|
||||
private:
|
||||
MemoryChunk *mCurrent;
|
||||
uint32_t mCount;
|
||||
uint32_t mCurrent;
|
||||
uint32_t mLength;
|
||||
};
|
||||
|
||||
static const Information *information();
|
||||
|
@ -56,7 +56,6 @@ struct PACKED Information
|
|||
|
||||
const char* commandLine() const;
|
||||
|
||||
uint32_t memoryMapChunks() const;
|
||||
MemoryMapIterator memoryMapBegin() 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. */
|
||||
uint32_t mMemUpper;
|
||||
|
||||
/**
|
||||
* Indicates which BIOS disk the boot loader loaded the OS image from.
|
||||
* Defined only if `bootDevice == true`.
|
||||
*/
|
||||
/** Indicates which BIOS disk the boot loader loaded the OS image from. */
|
||||
struct PACKED {
|
||||
/** Third level partition number. If unused this is set to 0xFF. */
|
||||
uint8_t partitionLevel3;
|
||||
|
@ -80,33 +76,27 @@ private:
|
|||
uint8_t partitionLevel2;
|
||||
/** Top-level partition number. */
|
||||
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;
|
||||
} bootDevice;
|
||||
} mBootDevice;
|
||||
|
||||
/**
|
||||
* Pointer to a C-style string containing the command line arguments.
|
||||
* Defined only if `commandLinePresent == true`.
|
||||
*/
|
||||
/** Pointer to a C-style string containing the command line arguments. */
|
||||
uint32_t mCommandLine;
|
||||
|
||||
/**
|
||||
* Multiboot Modules
|
||||
* Indicates what boot modules were loaded along with the kernel image.
|
||||
* Defined only if `modulesPresent == true`.
|
||||
* @{
|
||||
*/
|
||||
struct PACKED {
|
||||
/** Number of boot modules present. */
|
||||
uint32_t count;
|
||||
/** Pointer to start of boot modules array. */
|
||||
uint32_t address;
|
||||
} modules;
|
||||
/** Number of boot modules present. */
|
||||
uint32_t mModulesCount;
|
||||
/** Pointer to start of boot modules array. */
|
||||
uint32_t mModulesAddress;
|
||||
/** @} */
|
||||
|
||||
// TODO: Document these.
|
||||
union PACKED
|
||||
{
|
||||
union PACKED {
|
||||
struct PACKED {
|
||||
uint32_t tableSize;
|
||||
uint32_t stringSize;
|
||||
|
@ -117,42 +107,36 @@ private:
|
|||
uint32_t number;
|
||||
uint32_t size;
|
||||
uint32_t address;
|
||||
uint32_t shndx;
|
||||
uint32_t shndx; // TODO: Bad name. What is this?
|
||||
} elf;
|
||||
} symbols;
|
||||
|
||||
/**
|
||||
* @defgroup Memory Map
|
||||
* Points to a buffer containing a memory map of the machine provided by the
|
||||
* BIOS. Defined only if `memoryMapPresent == true`.
|
||||
* Defines a buffer containing a memory map provided by the BIOS.
|
||||
* @{
|
||||
*/
|
||||
/** Number of memory map entries present. */
|
||||
uint32_t memoryMapCount;
|
||||
/** Length of the buffer, in bytes. The spec is somewhat unclear on this field. */
|
||||
uint32_t mMemoryMapLength;
|
||||
/** 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
|
||||
* BIOS. Defined only if `drivesPresent == true`.
|
||||
* @defgroup Drives
|
||||
* Defines a buffer containing a list of drive definitions provided by the BIOS.
|
||||
* @{
|
||||
*/
|
||||
struct PACKED {
|
||||
/** Number of memory map entries present. */
|
||||
uint32_t count;
|
||||
/** Pointer to start of memory map entry array. */
|
||||
uint32_t address;
|
||||
} drives;
|
||||
/** Number of memory map entries present. */
|
||||
uint32_t mDrivesLength;
|
||||
/** Pointer to start of memory map entry array. */
|
||||
uint32_t mDrivesAddress;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Pointer to the table containing APM information. Defined only if
|
||||
* `apmTablePresent == true`.
|
||||
*/
|
||||
uint32_t apmTable;
|
||||
/** Pointer to a table containing APM information. */
|
||||
uint32_t mAPMTable;
|
||||
|
||||
/**
|
||||
* I dunno some VBE stuff. TODO.
|
||||
*/
|
||||
/** I dunno some VBE stuff. TODO. */
|
||||
struct PACKED {
|
||||
uint32_t controlInformation;
|
||||
uint32_t modeInformation;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue