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
+4
View File
@@ -8,3 +8,7 @@ static inline UInt32 BytesSwap32(UInt32 value) {
static inline UInt64 BytesSwap64(UInt64 value) {
return __builtin_bswap64(value);
}
static inline UInt64 Merge32To64(UInt32 low, UInt32 high) {
return ((UInt64)high << 32) | low;
}
+3 -1
View File
@@ -15,4 +15,6 @@ Size StringGetLength(const ASCII* string);
const ASCII* StringFindLastOccurrenceOfCharacter(const ASCII* string, ASCII separator);
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
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);
}
+4
View File
@@ -176,4 +176,8 @@ Int32 StringFormat(ASCII* destination, UInt64 size, const ASCII* format, ...) {
Int32 returnValue = StringFormatVariadic(destination, size, format, args);
va_end(args);
return returnValue;
}
Boolean StringStartsWith(const ASCII* string, const ASCII* prefix) {
return StringCompareWithLimit(string, prefix, StringGetLength(prefix)) == 0;
}