wip: dtb:
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include "Types.h"
|
||||
#include <Arch/DTB.h>
|
||||
#include <OS/Panic.h>
|
||||
#include <OS/Log.h>
|
||||
#include <Lib/Bytes.h>
|
||||
#include <Lib/Align.h>
|
||||
#include <Lib/String.h>
|
||||
|
||||
void DTBParse(Pointer dtb) {
|
||||
FDTHeader* header = (FDTHeader*)dtb;
|
||||
if (BytesSwap32(header->magic) != kFDTHeaderMagic) {
|
||||
OSPanic("Invalid DTB magic");
|
||||
}
|
||||
|
||||
UInt32 offStruct = BytesSwap32(header->offDtStruct);
|
||||
UInt32 offStrings = BytesSwap32(header->offDtStrings);
|
||||
|
||||
BytePointer structs = (BytePointer)dtb + offStruct;
|
||||
ASCII* strings = (ASCII*)dtb + offStrings;
|
||||
|
||||
Int depth = 0;
|
||||
|
||||
while (true) {
|
||||
UInt32 token = BytesSwap32(*(UInt32*)structs);
|
||||
structs += 4;
|
||||
|
||||
switch (token) {
|
||||
case FDTTokenBeginNode: {
|
||||
ASCII* name = (ASCII*)structs;
|
||||
|
||||
OSLog("Node [%d]: %s\n", depth, name[0] ? name : "ROOT");
|
||||
|
||||
UInt32 nameLength = StringGetLength(name);
|
||||
structs += (nameLength + 1);
|
||||
structs = (BytePointer)AlignUp32((Address)structs, 4);
|
||||
|
||||
depth++;
|
||||
break;
|
||||
}
|
||||
case FDTTokenProperty: {
|
||||
UInt32 propertyLength = BytesSwap32(*(UInt32*)structs);
|
||||
UInt32 nameOffset = BytesSwap32(*(UInt32*)(structs + 4));
|
||||
structs += 8;
|
||||
|
||||
ASCII* propertyName = strings + nameOffset;
|
||||
BytePointer propertyData = structs;
|
||||
OSLog("Property %s (len %d)\n", propertyName, propertyLength);
|
||||
|
||||
structs += propertyLength;
|
||||
structs = (BytePointer)AlignUp32((Address)structs, 4);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case FDTTokenEndNode: depth--; break;
|
||||
case FDTTokenNOP: continue;
|
||||
case FDTTokenEnd: return;
|
||||
default:
|
||||
OSPanic("Invalid DTB token");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user