Use my own int types for Multiboot

This commit is contained in:
Eryn Wells 2016-04-09 13:33:20 -04:00
parent 95b524a94d
commit 31cba1bdc8
2 changed files with 60 additions and 46 deletions

View file

@ -33,8 +33,8 @@ namespace multiboot {
* Public * Public
*/ */
Information::MemoryMapIterator::MemoryMapIterator(uint32_t address, Information::MemoryMapIterator::MemoryMapIterator(u32 address,
uint32_t length) u32 length)
: mCurrent(address), : mCurrent(address),
mLength(length) mLength(length)
{ } { }
@ -51,7 +51,7 @@ Information::MemoryMapIterator::operator++()
{ {
if (mLength > 0) { if (mLength > 0) {
// The size of the current struct is stored at (mCurrent - 4) bytes. // The size of the current struct is stored at (mCurrent - 4) bytes.
auto size = *reinterpret_cast<uint32_t*>(mCurrent) + 4; auto size = *reinterpret_cast<u32*>(mCurrent) + 4;
mCurrent = mCurrent + size; mCurrent = mCurrent + size;
mLength = (size > mLength) ? 0 : mLength - size; mLength = (size > mLength) ? 0 : mLength - size;
} }
@ -95,7 +95,7 @@ Information::MemoryMapIterator::operator!=(const MemoryMapIterator& other)
} }
uint32_t u32
Information::lowerMemoryKB() Information::lowerMemoryKB()
const const
{ {
@ -106,7 +106,7 @@ Information::lowerMemoryKB()
} }
uint32_t u32
Information::upperMemoryKB() Information::upperMemoryKB()
const const
{ {
@ -117,6 +117,14 @@ Information::upperMemoryKB()
} }
u32
Information::memoryKB()
const
{
return lowerMemoryKB() + upperMemoryKB();
}
const char * const char *
Information::commandLine() Information::commandLine()
const const

View file

@ -12,17 +12,19 @@
#include "stdint.h" #include "stdint.h"
#include "Attributes.hh" #include "Attributes.hh"
#include "kstd/Types.hh"
namespace multiboot { namespace multiboot {
struct PACKED MemoryChunk struct PACKED MemoryChunk
{ {
/** Base address of the chunk of memory. */ /** Base address of the chunk of memory. */
uint64_t base; u64 base;
/** Length of the chunk of memory, in bytes. */ /** Length of the chunk of memory, in bytes. */
uint64_t length; u64 length;
/** Type of address range. 1 indicates available; all other values indicate reserved memory. */ /** Type of address range. 1 indicates available; all other values indicate reserved memory. */
uint32_t type; u32 type;
}; };
/** /**
@ -33,7 +35,7 @@ struct PACKED Information
{ {
struct MemoryMapIterator struct MemoryMapIterator
{ {
MemoryMapIterator(uint32_t address, uint32_t count); MemoryMapIterator(u32 address, u32 count);
MemoryMapIterator(const MemoryMapIterator& other); MemoryMapIterator(const MemoryMapIterator& other);
MemoryMapIterator& operator++(); MemoryMapIterator& operator++();
@ -44,12 +46,16 @@ struct PACKED Information
bool operator!=(const MemoryMapIterator& other) const; bool operator!=(const MemoryMapIterator& other) const;
private: private:
uint32_t mCurrent; u32 mCurrent;
uint32_t mLength; u32 mLength;
}; };
uint32_t lowerMemoryKB() const; /** Size of lower memory in KB. */
uint32_t upperMemoryKB() const; u32 lowerMemoryKB() const;
/** Size of upper memory in KB. */
u32 upperMemoryKB() const;
/** Total size of memory in KB. */
u32 memoryKB() const;
const char* commandLine() const; const char* commandLine() const;
@ -58,27 +64,27 @@ struct PACKED Information
private: private:
/** Bit field of flags. Fields below are only defined if the appropriate flag is set. */ /** Bit field of flags. Fields below are only defined if the appropriate flag is set. */
uint32_t mFlags; u32 mFlags;
/** Amount of lower (0 to 1 MB) memory, in KB. */ /** Amount of lower (0 to 1 MB) memory, in KB. */
uint32_t mMemLower; u32 mMemLower;
/** 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; u32 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. */
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; u8 partitionLevel3;
/** Sub-partition number. If unused this is set to 0xFF. */ /** Sub-partition number. If unused this is set to 0xFF. */
uint8_t partitionLevel2; u8 partitionLevel2;
/** Top-level partition number. */ /** Top-level partition number. */
uint8_t partitionLevel1; u8 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; u8 driveNumber;
} mBootDevice; } mBootDevice;
/** Pointer to a C-style string containing the command line arguments. */ /** Pointer to a C-style string containing the command line arguments. */
uint32_t mCommandLine; u32 mCommandLine;
/** /**
* Multiboot Modules * Multiboot Modules
@ -87,24 +93,24 @@ private:
* @{ * @{
*/ */
/** Number of boot modules present. */ /** Number of boot modules present. */
uint32_t mModulesCount; u32 mModulesCount;
/** Pointer to start of boot modules array. */ /** Pointer to start of boot modules array. */
uint32_t mModulesAddress; u32 mModulesAddress;
/** @} */ /** @} */
// TODO: Document these. // TODO: Document these.
union PACKED { union PACKED {
struct PACKED { struct PACKED {
uint32_t tableSize; u32 tableSize;
uint32_t stringSize; u32 stringSize;
uint32_t address; u32 address;
uint32_t reserved; u32 reserved;
} aout; } aout;
struct PACKED { struct PACKED {
uint32_t number; u32 number;
uint32_t size; u32 size;
uint32_t address; u32 address;
uint32_t shndx; // TODO: Bad name. What is this? u32 shndx; // TODO: Bad name. What is this?
} elf; } elf;
} symbols; } symbols;
@ -114,9 +120,9 @@ private:
* @{ * @{
*/ */
/** Length of the buffer, in bytes. The spec is somewhat unclear on this field. */ /** Length of the buffer, in bytes. The spec is somewhat unclear on this field. */
uint32_t mMemoryMapLength; u32 mMemoryMapLength;
/** Pointer to start of memory map entry array. */ /** Pointer to start of memory map entry array. */
uint32_t mMemoryMapAddress; u32 mMemoryMapAddress;
/** @} */ /** @} */
/** /**
@ -125,35 +131,35 @@ private:
* @{ * @{
*/ */
/** Number of memory map entries present. */ /** Number of memory map entries present. */
uint32_t mDrivesLength; u32 mDrivesLength;
/** Pointer to start of memory map entry array. */ /** Pointer to start of memory map entry array. */
uint32_t mDrivesAddress; u32 mDrivesAddress;
/** @} */ /** @} */
/** Pointer to a table containing APM information. */ /** Pointer to a table containing APM information. */
uint32_t mAPMTable; u32 mAPMTable;
/** I dunno some VBE stuff. TODO. */ /** I dunno some VBE stuff. TODO. */
struct PACKED { struct PACKED {
uint32_t controlInformation; u32 controlInformation;
uint32_t modeInformation; u32 modeInformation;
uint32_t mode; u32 mode;
uint32_t interfaceSegment; u32 interfaceSegment;
uint32_t interfaceOff; u32 interfaceOff;
uint32_t interfaceLength; u32 interfaceLength;
} vbe; } vbe;
}; };
struct PACKED Module struct PACKED Module
{ {
/** Start address of boot module. */ /** Start address of boot module. */
uint32_t start; u32 start;
/** End address of boot module. */ /** End address of boot module. */
uint32_t end; u32 end;
/** Pointer to a C-style boot module string. */ /** Pointer to a C-style boot module string. */
uint32_t string; u32 string;
/** Reserved and ignored. */ /** Reserved and ignored. */
uint32_t reserved; u32 reserved;
}; };
// TODO: Define the Drive struct // TODO: Define the Drive struct