feat: parsing dtb

This commit is contained in:
karina
2026-04-26 10:48:54 +04:00
parent f15a146608
commit 32931021d2
5 changed files with 25 additions and 14 deletions
+13 -12
View File
@@ -16,8 +16,7 @@ void DTBParse(Pointer dtb) {
BytePointer structs = (BytePointer)dtb + offStruct;
ASCII* strings = (ASCII*)dtb + offStrings;
Int depth = 0;
ASCII* currentNode = "";
while (true) {
UInt32 token = BytesSwap32(*(UInt32*)structs);
@@ -25,15 +24,12 @@ void DTBParse(Pointer dtb) {
switch (token) {
case FDTTokenBeginNode: {
ASCII* name = (ASCII*)structs;
currentNode = (ASCII*)structs;
OSLog("Node [%d]: %s\n", depth, name[0] ? name : "ROOT");
UInt32 nameLength = StringGetLength(name);
UInt32 nameLength = StringGetLength(currentNode);
structs += (nameLength + 1);
structs = (BytePointer)AlignUp32((Address)structs, 4);
structs = (BytePointer)AlignUp64((Address)structs, 4);
depth++;
break;
}
case FDTTokenProperty: {
@@ -42,16 +38,21 @@ void DTBParse(Pointer dtb) {
structs += 8;
ASCII* propertyName = strings + nameOffset;
BytePointer propertyData = structs;
OSLog("Property %s (len %d)\n", propertyName, propertyLength);
if (StringCompare(propertyName, "reg") == 0 && StringStartsWith(currentNode, "memory")) {
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 = (BytePointer)AlignUp32((Address)structs, 4);
structs = (BytePointer)AlignUp64((Address)structs, 4);
break;
}
case FDTTokenEndNode: depth--; break;
case FDTTokenEndNode: break;
case FDTTokenNOP: continue;
case FDTTokenEnd: return;
default:
+1 -1
View File
@@ -3,6 +3,6 @@
#include <IO/Serial.h>
#include <OS/Panic.h>
void ExceptionsHandler(ExceptionsContext* frame, ExceptionsType type) {
void ExceptionsHandler(ExceptionsContext* frame, [[maybe_unused]]ExceptionsType type) {
OSPanicException(frame);
}