feat: parsing dtb
This commit is contained in:
@@ -8,3 +8,7 @@ static inline UInt32 BytesSwap32(UInt32 value) {
|
|||||||
static inline UInt64 BytesSwap64(UInt64 value) {
|
static inline UInt64 BytesSwap64(UInt64 value) {
|
||||||
return __builtin_bswap64(value);
|
return __builtin_bswap64(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline UInt64 Merge32To64(UInt32 low, UInt32 high) {
|
||||||
|
return ((UInt64)high << 32) | low;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,3 +16,5 @@ const ASCII* StringFindLastOccurrenceOfCharacter(const ASCII* string, ASCII sepa
|
|||||||
|
|
||||||
Int32 StringFormatVariadic(ASCII* string, Size size, const ASCII* format, va_list args);
|
Int32 StringFormatVariadic(ASCII* string, Size size, const ASCII* format, va_list args);
|
||||||
Int32 StringFormat(ASCII* destination, UInt64 size, const ASCII* format, ...);
|
Int32 StringFormat(ASCII* destination, UInt64 size, const ASCII* format, ...);
|
||||||
|
|
||||||
|
Boolean StringStartsWith(const ASCII* string, const ASCII* prefix);
|
||||||
+13
-12
@@ -16,8 +16,7 @@ void DTBParse(Pointer dtb) {
|
|||||||
|
|
||||||
BytePointer structs = (BytePointer)dtb + offStruct;
|
BytePointer structs = (BytePointer)dtb + offStruct;
|
||||||
ASCII* strings = (ASCII*)dtb + offStrings;
|
ASCII* strings = (ASCII*)dtb + offStrings;
|
||||||
|
ASCII* currentNode = "";
|
||||||
Int depth = 0;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
UInt32 token = BytesSwap32(*(UInt32*)structs);
|
UInt32 token = BytesSwap32(*(UInt32*)structs);
|
||||||
@@ -25,15 +24,12 @@ void DTBParse(Pointer dtb) {
|
|||||||
|
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case FDTTokenBeginNode: {
|
case FDTTokenBeginNode: {
|
||||||
ASCII* name = (ASCII*)structs;
|
currentNode = (ASCII*)structs;
|
||||||
|
|
||||||
OSLog("Node [%d]: %s\n", depth, name[0] ? name : "ROOT");
|
UInt32 nameLength = StringGetLength(currentNode);
|
||||||
|
|
||||||
UInt32 nameLength = StringGetLength(name);
|
|
||||||
structs += (nameLength + 1);
|
structs += (nameLength + 1);
|
||||||
structs = (BytePointer)AlignUp32((Address)structs, 4);
|
structs = (BytePointer)AlignUp64((Address)structs, 4);
|
||||||
|
|
||||||
depth++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FDTTokenProperty: {
|
case FDTTokenProperty: {
|
||||||
@@ -42,16 +38,21 @@ void DTBParse(Pointer dtb) {
|
|||||||
structs += 8;
|
structs += 8;
|
||||||
|
|
||||||
ASCII* propertyName = strings + nameOffset;
|
ASCII* propertyName = strings + nameOffset;
|
||||||
BytePointer propertyData = structs;
|
if (StringCompare(propertyName, "reg") == 0 && StringStartsWith(currentNode, "memory")) {
|
||||||
OSLog("Property %s (len %d)\n", propertyName, propertyLength);
|
UInt32* cells = (UInt32*)structs;
|
||||||
|
|
||||||
|
UInt64 base = Merge32To64(BytesSwap32(cells[0]), BytesSwap32(cells[1]));
|
||||||
|
UInt64 size = Merge32To64(BytesSwap32(cells[2]), BytesSwap32(cells[3]));
|
||||||
|
|
||||||
|
OSLog("Memory: base=0x%x, size=0x%x\n", base, size);
|
||||||
|
}
|
||||||
structs += propertyLength;
|
structs += propertyLength;
|
||||||
structs = (BytePointer)AlignUp32((Address)structs, 4);
|
structs = (BytePointer)AlignUp64((Address)structs, 4);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case FDTTokenEndNode: depth--; break;
|
case FDTTokenEndNode: break;
|
||||||
case FDTTokenNOP: continue;
|
case FDTTokenNOP: continue;
|
||||||
case FDTTokenEnd: return;
|
case FDTTokenEnd: return;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
#include <IO/Serial.h>
|
#include <IO/Serial.h>
|
||||||
#include <OS/Panic.h>
|
#include <OS/Panic.h>
|
||||||
|
|
||||||
void ExceptionsHandler(ExceptionsContext* frame, ExceptionsType type) {
|
void ExceptionsHandler(ExceptionsContext* frame, [[maybe_unused]]ExceptionsType type) {
|
||||||
OSPanicException(frame);
|
OSPanicException(frame);
|
||||||
}
|
}
|
||||||
@@ -177,3 +177,7 @@ Int32 StringFormat(ASCII* destination, UInt64 size, const ASCII* format, ...) {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boolean StringStartsWith(const ASCII* string, const ASCII* prefix) {
|
||||||
|
return StringCompareWithLimit(string, prefix, StringGetLength(prefix)) == 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user