diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/util.c b/src/hlib/flatBuffers/util.c index d96f281..e0b014f 100644 --- a/src/hlib/flatBuffers/util.c +++ b/src/hlib/flatBuffers/util.c @@ -67,9 +67,7 @@ printf("%s%s: %s(%s)\n", indentData, hexData, info->name, length ? "true" : "false"); break; // can't even print a float yet... case TYPE_STRING: - buffer = malloc(length + 1); - memcpy(data + dataOffset, buffer, length); - buffer[length] = 0; + buffer = (void *)msgPackReadStr(allocationData, data); printf("%s%s: %s(\"%s\")\n", indentData, hexData, info->name, buffer); free(buffer); break; @@ -102,7 +100,7 @@ FormatInfo *info = &formatInfo[format]; uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); if (info->dataType == TYPE_MAP) { - length <<= 1; + length *= 2; } switch (info->readType) { case Inline: diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/util.c b/src/hlib/flatBuffers/util.c index d96f281..e0b014f 100644 --- a/src/hlib/flatBuffers/util.c +++ b/src/hlib/flatBuffers/util.c @@ -67,9 +67,7 @@ printf("%s%s: %s(%s)\n", indentData, hexData, info->name, length ? "true" : "false"); break; // can't even print a float yet... case TYPE_STRING: - buffer = malloc(length + 1); - memcpy(data + dataOffset, buffer, length); - buffer[length] = 0; + buffer = (void *)msgPackReadStr(allocationData, data); printf("%s%s: %s(\"%s\")\n", indentData, hexData, info->name, buffer); free(buffer); break; @@ -102,7 +100,7 @@ FormatInfo *info = &formatInfo[format]; uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); if (info->dataType == TYPE_MAP) { - length <<= 1; + length *= 2; } switch (info->readType) { case Inline: diff --git a/src/include/buffers.h b/src/include/buffers.h index 34a0242..ade7b8a 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -68,7 +68,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_INTEGER) catchError \ - msgPackReadInt(allocationData, data); \ + msgPackReadInt(allocationData, buffer); \ }) #define _AS_UINT(data, catchError, catchNegative) \ @@ -86,7 +86,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_STRING) catchError \ - msgPackReadStr(allocationData, data); \ + msgPackReadStr(allocationData, buffer); \ }) #define AS_INT(data, retval, ...) \ @@ -107,10 +107,11 @@ return retval; \ } \ void *elementName; \ - uint32_t maxElement = msgPackReadArraySize(data, &elementName); \ + uint32_t maxElement = msgPackReadArraySize(allocationData, data, &elementName); \ + elementName = data + 1; \ for (uint32_t i = 0; i < maxElement; i++) { \ (action); \ - elementName = msgPackSeek(elementName); \ + elementName = msgPackSeek(allocationData, elementName); \ } \ } @@ -224,7 +225,7 @@ extern FormatInfo formatInfo[]; typedef char * STRING; -typedef intmax_t INT; +typedef uint32_t INT; extern Formats FirstByteToFormat[256]; extern FormatInfo formatInfo[]; @@ -260,5 +261,6 @@ #define msgPackDump(data) _msgPackDump(allocationData, data, 0) extern void initializeFlatBuffers(); +extern void *msgPackSeek(AllocationData allocationData, void *data); #endif \ No newline at end of file diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/util.c b/src/hlib/flatBuffers/util.c index d96f281..e0b014f 100644 --- a/src/hlib/flatBuffers/util.c +++ b/src/hlib/flatBuffers/util.c @@ -67,9 +67,7 @@ printf("%s%s: %s(%s)\n", indentData, hexData, info->name, length ? "true" : "false"); break; // can't even print a float yet... case TYPE_STRING: - buffer = malloc(length + 1); - memcpy(data + dataOffset, buffer, length); - buffer[length] = 0; + buffer = (void *)msgPackReadStr(allocationData, data); printf("%s%s: %s(\"%s\")\n", indentData, hexData, info->name, buffer); free(buffer); break; @@ -102,7 +100,7 @@ FormatInfo *info = &formatInfo[format]; uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); if (info->dataType == TYPE_MAP) { - length <<= 1; + length *= 2; } switch (info->readType) { case Inline: diff --git a/src/include/buffers.h b/src/include/buffers.h index 34a0242..ade7b8a 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -68,7 +68,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_INTEGER) catchError \ - msgPackReadInt(allocationData, data); \ + msgPackReadInt(allocationData, buffer); \ }) #define _AS_UINT(data, catchError, catchNegative) \ @@ -86,7 +86,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_STRING) catchError \ - msgPackReadStr(allocationData, data); \ + msgPackReadStr(allocationData, buffer); \ }) #define AS_INT(data, retval, ...) \ @@ -107,10 +107,11 @@ return retval; \ } \ void *elementName; \ - uint32_t maxElement = msgPackReadArraySize(data, &elementName); \ + uint32_t maxElement = msgPackReadArraySize(allocationData, data, &elementName); \ + elementName = data + 1; \ for (uint32_t i = 0; i < maxElement; i++) { \ (action); \ - elementName = msgPackSeek(elementName); \ + elementName = msgPackSeek(allocationData, elementName); \ } \ } @@ -224,7 +225,7 @@ extern FormatInfo formatInfo[]; typedef char * STRING; -typedef intmax_t INT; +typedef uint32_t INT; extern Formats FirstByteToFormat[256]; extern FormatInfo formatInfo[]; @@ -260,5 +261,6 @@ #define msgPackDump(data) _msgPackDump(allocationData, data, 0) extern void initializeFlatBuffers(); +extern void *msgPackSeek(AllocationData allocationData, void *data); #endif \ No newline at end of file diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index 9f4b184..7d5a322 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -3,9 +3,22 @@ REQUEST(pciDump, "lspci", "dumpAll"); +uint32_t showDevice(void *data) { + GET(STRING, className); + GET(INT, class); + GET(INT, id); + GET(INT, subclass); + GET(INT, programmingInterface); + + printf("id: %i, class: \"%s\" (%i) / %i / %i\n", id, className, class, subclass, programmingInterface); + + free(className); + return 0; +} + int32_t main() { uintptr_t dataPhysical = pciDump(1, 0); void *data = requestMemory(1, NULL, PTR(dataPhysical)); printf("pci data:\n"); - msgPackDump(data); + ARRAY_LOOP(data, 0, device, showDevice(device)); } \ No newline at end of file diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/util.c b/src/hlib/flatBuffers/util.c index d96f281..e0b014f 100644 --- a/src/hlib/flatBuffers/util.c +++ b/src/hlib/flatBuffers/util.c @@ -67,9 +67,7 @@ printf("%s%s: %s(%s)\n", indentData, hexData, info->name, length ? "true" : "false"); break; // can't even print a float yet... case TYPE_STRING: - buffer = malloc(length + 1); - memcpy(data + dataOffset, buffer, length); - buffer[length] = 0; + buffer = (void *)msgPackReadStr(allocationData, data); printf("%s%s: %s(\"%s\")\n", indentData, hexData, info->name, buffer); free(buffer); break; @@ -102,7 +100,7 @@ FormatInfo *info = &formatInfo[format]; uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); if (info->dataType == TYPE_MAP) { - length <<= 1; + length *= 2; } switch (info->readType) { case Inline: diff --git a/src/include/buffers.h b/src/include/buffers.h index 34a0242..ade7b8a 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -68,7 +68,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_INTEGER) catchError \ - msgPackReadInt(allocationData, data); \ + msgPackReadInt(allocationData, buffer); \ }) #define _AS_UINT(data, catchError, catchNegative) \ @@ -86,7 +86,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_STRING) catchError \ - msgPackReadStr(allocationData, data); \ + msgPackReadStr(allocationData, buffer); \ }) #define AS_INT(data, retval, ...) \ @@ -107,10 +107,11 @@ return retval; \ } \ void *elementName; \ - uint32_t maxElement = msgPackReadArraySize(data, &elementName); \ + uint32_t maxElement = msgPackReadArraySize(allocationData, data, &elementName); \ + elementName = data + 1; \ for (uint32_t i = 0; i < maxElement; i++) { \ (action); \ - elementName = msgPackSeek(elementName); \ + elementName = msgPackSeek(allocationData, elementName); \ } \ } @@ -224,7 +225,7 @@ extern FormatInfo formatInfo[]; typedef char * STRING; -typedef intmax_t INT; +typedef uint32_t INT; extern Formats FirstByteToFormat[256]; extern FormatInfo formatInfo[]; @@ -260,5 +261,6 @@ #define msgPackDump(data) _msgPackDump(allocationData, data, 0) extern void initializeFlatBuffers(); +extern void *msgPackSeek(AllocationData allocationData, void *data); #endif \ No newline at end of file diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index 9f4b184..7d5a322 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -3,9 +3,22 @@ REQUEST(pciDump, "lspci", "dumpAll"); +uint32_t showDevice(void *data) { + GET(STRING, className); + GET(INT, class); + GET(INT, id); + GET(INT, subclass); + GET(INT, programmingInterface); + + printf("id: %i, class: \"%s\" (%i) / %i / %i\n", id, className, class, subclass, programmingInterface); + + free(className); + return 0; +} + int32_t main() { uintptr_t dataPhysical = pciDump(1, 0); void *data = requestMemory(1, NULL, PTR(dataPhysical)); printf("pci data:\n"); - msgPackDump(data); + ARRAY_LOOP(data, 0, device, showDevice(device)); } \ No newline at end of file diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 4bc642d..c79e4c2 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -94,6 +94,7 @@ for (uint8_t i = 0; i < 6; i++) { pciDevice->bar[i] = (temp = READ(0x10 + 4 * i)); } + pciDevice->id = listCount(pciDevices); listAdd(&pciDevices, pciDevice); if (class == 6 && pciDevice->subclass == 4) { checkBus(READ8(0x19)); @@ -195,10 +196,12 @@ X(INTEGER, device->bar[4]) #define DEVICE_DUMP_MAP_DATA(X, S) \ - X(STRING, "bars") S \ - X(ARRAY, DEVICE_DUMP_BARS) S \ - X(STRING, "class") S \ - X(INTEGER, device->class << 16 | device->subclass << 8 | device->programmingInterface) + X(STRING, "bars") S X(ARRAY, DEVICE_DUMP_BARS) S \ + X(STRING, "id") S X(INTEGER, device->id) S \ + X(STRING, "class") S X(INTEGER, device->class) S \ + X(STRING, "className") S X(STRING, classNames[device->class]) S \ + X(STRING, "subclass") S X(INTEGER, device->subclass) S \ + X(STRING, "programmingInterface") S X(INTEGER, device->programmingInterface) #define DEVICE_DUMP(X, ...) X(MAP, DEVICE_DUMP_MAP_DATA) @@ -236,5 +239,4 @@ printf("[%i:%i:%i]: %s\n", device->bus, device->device, device->function, classNames[device->class]); }) - ; } diff --git a/src/hlib/flatBuffers/array.c b/src/hlib/flatBuffers/array.c index c085b9a..50da2ba 100644 --- a/src/hlib/flatBuffers/array.c +++ b/src/hlib/flatBuffers/array.c @@ -76,10 +76,13 @@ switch (format) { case FORMAT_FIXARRAY: *firstElement = data + 1; + break; case FORMAT_ARRAY16: *firstElement = data + 3; + break; case FORMAT_ARRAY32: *firstElement = data + 5; + break; } return msgPackReadLength(allocationData, data, info->readTypeParameter); } diff --git a/src/hlib/flatBuffers/flatBuffers.h b/src/hlib/flatBuffers/flatBuffers.h index 0e68bd3..9bc9084 100644 --- a/src/hlib/flatBuffers/flatBuffers.h +++ b/src/hlib/flatBuffers/flatBuffers.h @@ -3,7 +3,6 @@ #include -extern void *msgPackSeek(AllocationData allocationData, void *data); extern uintmax_t msgPackReadLength(AllocationData allocationData, void *data, int8_t size); #endif // FLAT_BUFFERS_H \ No newline at end of file diff --git a/src/hlib/flatBuffers/string.c b/src/hlib/flatBuffers/string.c index 9670d10..9246826 100644 --- a/src/hlib/flatBuffers/string.c +++ b/src/hlib/flatBuffers/string.c @@ -59,10 +59,10 @@ } else if (format == FORMAT_STR32) { offset = 5; } - uint32_t size = msgPackReadLength(allocationData, data, info->readTypeParameter); - char *str = malloc(size + 1); - memcpy(data + offset, str, size); - str[size] = 0; + uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); + char *str = malloc(length + 1); + memcpy(data + offset, str, length); + str[length] = 0; return str; } diff --git a/src/hlib/flatBuffers/util.c b/src/hlib/flatBuffers/util.c index d96f281..e0b014f 100644 --- a/src/hlib/flatBuffers/util.c +++ b/src/hlib/flatBuffers/util.c @@ -67,9 +67,7 @@ printf("%s%s: %s(%s)\n", indentData, hexData, info->name, length ? "true" : "false"); break; // can't even print a float yet... case TYPE_STRING: - buffer = malloc(length + 1); - memcpy(data + dataOffset, buffer, length); - buffer[length] = 0; + buffer = (void *)msgPackReadStr(allocationData, data); printf("%s%s: %s(\"%s\")\n", indentData, hexData, info->name, buffer); free(buffer); break; @@ -102,7 +100,7 @@ FormatInfo *info = &formatInfo[format]; uint32_t length = msgPackReadLength(allocationData, data, info->readTypeParameter); if (info->dataType == TYPE_MAP) { - length <<= 1; + length *= 2; } switch (info->readType) { case Inline: diff --git a/src/include/buffers.h b/src/include/buffers.h index 34a0242..ade7b8a 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -68,7 +68,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_INTEGER) catchError \ - msgPackReadInt(allocationData, data); \ + msgPackReadInt(allocationData, buffer); \ }) #define _AS_UINT(data, catchError, catchNegative) \ @@ -86,7 +86,7 @@ uint8_t *buffer = (uint8_t *) data; \ uint8_t type = FirstByteToFormat[*buffer]; \ if (formatInfo[type].dataType != TYPE_STRING) catchError \ - msgPackReadStr(allocationData, data); \ + msgPackReadStr(allocationData, buffer); \ }) #define AS_INT(data, retval, ...) \ @@ -107,10 +107,11 @@ return retval; \ } \ void *elementName; \ - uint32_t maxElement = msgPackReadArraySize(data, &elementName); \ + uint32_t maxElement = msgPackReadArraySize(allocationData, data, &elementName); \ + elementName = data + 1; \ for (uint32_t i = 0; i < maxElement; i++) { \ (action); \ - elementName = msgPackSeek(elementName); \ + elementName = msgPackSeek(allocationData, elementName); \ } \ } @@ -224,7 +225,7 @@ extern FormatInfo formatInfo[]; typedef char * STRING; -typedef intmax_t INT; +typedef uint32_t INT; extern Formats FirstByteToFormat[256]; extern FormatInfo formatInfo[]; @@ -260,5 +261,6 @@ #define msgPackDump(data) _msgPackDump(allocationData, data, 0) extern void initializeFlatBuffers(); +extern void *msgPackSeek(AllocationData allocationData, void *data); #endif \ No newline at end of file diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index 9f4b184..7d5a322 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -3,9 +3,22 @@ REQUEST(pciDump, "lspci", "dumpAll"); +uint32_t showDevice(void *data) { + GET(STRING, className); + GET(INT, class); + GET(INT, id); + GET(INT, subclass); + GET(INT, programmingInterface); + + printf("id: %i, class: \"%s\" (%i) / %i / %i\n", id, className, class, subclass, programmingInterface); + + free(className); + return 0; +} + int32_t main() { uintptr_t dataPhysical = pciDump(1, 0); void *data = requestMemory(1, NULL, PTR(dataPhysical)); printf("pci data:\n"); - msgPackDump(data); + ARRAY_LOOP(data, 0, device, showDevice(device)); } \ No newline at end of file diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 4bc642d..c79e4c2 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -94,6 +94,7 @@ for (uint8_t i = 0; i < 6; i++) { pciDevice->bar[i] = (temp = READ(0x10 + 4 * i)); } + pciDevice->id = listCount(pciDevices); listAdd(&pciDevices, pciDevice); if (class == 6 && pciDevice->subclass == 4) { checkBus(READ8(0x19)); @@ -195,10 +196,12 @@ X(INTEGER, device->bar[4]) #define DEVICE_DUMP_MAP_DATA(X, S) \ - X(STRING, "bars") S \ - X(ARRAY, DEVICE_DUMP_BARS) S \ - X(STRING, "class") S \ - X(INTEGER, device->class << 16 | device->subclass << 8 | device->programmingInterface) + X(STRING, "bars") S X(ARRAY, DEVICE_DUMP_BARS) S \ + X(STRING, "id") S X(INTEGER, device->id) S \ + X(STRING, "class") S X(INTEGER, device->class) S \ + X(STRING, "className") S X(STRING, classNames[device->class]) S \ + X(STRING, "subclass") S X(INTEGER, device->subclass) S \ + X(STRING, "programmingInterface") S X(INTEGER, device->programmingInterface) #define DEVICE_DUMP(X, ...) X(MAP, DEVICE_DUMP_MAP_DATA) @@ -236,5 +239,4 @@ printf("[%i:%i:%i]: %s\n", device->bus, device->device, device->function, classNames[device->class]); }) - ; } diff --git a/src/userland/lspci/pci.h b/src/userland/lspci/pci.h index d32f502..23be43b 100644 --- a/src/userland/lspci/pci.h +++ b/src/userland/lspci/pci.h @@ -4,6 +4,7 @@ #include typedef struct { + uint32_t id; uint8_t bus, device, function; uint8_t class, subclass; uint16_t configuration;