diff --git a/src/hlib/flatBuffers/integer.c b/src/hlib/flatBuffers/integer.c index 19d34d1..e2713a1 100644 --- a/src/hlib/flatBuffers/integer.c +++ b/src/hlib/flatBuffers/integer.c @@ -23,12 +23,15 @@ } void *msgPackIntegerWrite(void *buffer, int32_t x, IntegerType type) { + uint8_t *bufferByte = buffer; if (x < 0 && type != Signed) { // printf("integerWrite: %i is negative but type is Unsigned!\n", x); // should never occur when using the correct macros - return buffer; + // as a failsave, treat it as a uint32_t + *bufferByte = formatInfo[FORMAT_UINT32].min; + *(uint32_t *)(buffer + 1) = (uint32_t) x; + return buffer + 5; } - uint8_t *bufferByte = buffer; if ((x & 0x7F) == x) { *bufferByte = (uint8_t)x; // fixint diff --git a/src/hlib/flatBuffers/integer.c b/src/hlib/flatBuffers/integer.c index 19d34d1..e2713a1 100644 --- a/src/hlib/flatBuffers/integer.c +++ b/src/hlib/flatBuffers/integer.c @@ -23,12 +23,15 @@ } void *msgPackIntegerWrite(void *buffer, int32_t x, IntegerType type) { + uint8_t *bufferByte = buffer; if (x < 0 && type != Signed) { // printf("integerWrite: %i is negative but type is Unsigned!\n", x); // should never occur when using the correct macros - return buffer; + // as a failsave, treat it as a uint32_t + *bufferByte = formatInfo[FORMAT_UINT32].min; + *(uint32_t *)(buffer + 1) = (uint32_t) x; + return buffer + 5; } - uint8_t *bufferByte = buffer; if ((x & 0x7F) == x) { *bufferByte = (uint8_t)x; // fixint diff --git a/src/include/buffers.h b/src/include/buffers.h index b286d20..34a0242 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -26,6 +26,9 @@ #define STRING_Length_id() STRING_Length #define MAP_Length_id() MAP_Length +#define LIST_Length(list, type, name, contents) msgPackArrayLength(listCount(list)) + ({ uint32_t len = 0; foreach (list, type, name, { len += contents(LENGTH, +); }) len; }) +#define LIST_Length_id() LIST_Length + #define ARRAY_Length(contents) msgPackArrayLength(contents(ONE, +)) + contents(LENGTH, +) #define MAP_Length(contents) msgPackMapLength(allocationData, contents(ONE, +)) + contents(LENGTH, +) @@ -40,6 +43,9 @@ #define STRING_Write_id() STRING_Write #define MAP_Write_id() MAP_Write +#define LIST_Write_id() LIST_Write +#define LIST_Write(list, type, name, contents) buffer = msgPackArrayWrite(buffer, listCount(list)); foreach (list, type, name, { contents(WRITE, NOTHING); }) + #define ARRAY_Write(contents) buffer = msgPackArrayWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) #define MAP_Write(contents) buffer = msgPackMapWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) diff --git a/src/hlib/flatBuffers/integer.c b/src/hlib/flatBuffers/integer.c index 19d34d1..e2713a1 100644 --- a/src/hlib/flatBuffers/integer.c +++ b/src/hlib/flatBuffers/integer.c @@ -23,12 +23,15 @@ } void *msgPackIntegerWrite(void *buffer, int32_t x, IntegerType type) { + uint8_t *bufferByte = buffer; if (x < 0 && type != Signed) { // printf("integerWrite: %i is negative but type is Unsigned!\n", x); // should never occur when using the correct macros - return buffer; + // as a failsave, treat it as a uint32_t + *bufferByte = formatInfo[FORMAT_UINT32].min; + *(uint32_t *)(buffer + 1) = (uint32_t) x; + return buffer + 5; } - uint8_t *bufferByte = buffer; if ((x & 0x7F) == x) { *bufferByte = (uint8_t)x; // fixint diff --git a/src/include/buffers.h b/src/include/buffers.h index b286d20..34a0242 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -26,6 +26,9 @@ #define STRING_Length_id() STRING_Length #define MAP_Length_id() MAP_Length +#define LIST_Length(list, type, name, contents) msgPackArrayLength(listCount(list)) + ({ uint32_t len = 0; foreach (list, type, name, { len += contents(LENGTH, +); }) len; }) +#define LIST_Length_id() LIST_Length + #define ARRAY_Length(contents) msgPackArrayLength(contents(ONE, +)) + contents(LENGTH, +) #define MAP_Length(contents) msgPackMapLength(allocationData, contents(ONE, +)) + contents(LENGTH, +) @@ -40,6 +43,9 @@ #define STRING_Write_id() STRING_Write #define MAP_Write_id() MAP_Write +#define LIST_Write_id() LIST_Write +#define LIST_Write(list, type, name, contents) buffer = msgPackArrayWrite(buffer, listCount(list)); foreach (list, type, name, { contents(WRITE, NOTHING); }) + #define ARRAY_Write(contents) buffer = msgPackArrayWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) #define MAP_Write(contents) buffer = msgPackMapWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index eff6473..9f4b184 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -1,11 +1,11 @@ #include #include -REQUEST(pciDump, "lspci", "dump"); +REQUEST(pciDump, "lspci", "dumpAll"); int32_t main() { uintptr_t dataPhysical = pciDump(1, 0); void *data = requestMemory(1, NULL, PTR(dataPhysical)); - printf("pci data for device 1:\n"); + printf("pci data:\n"); msgPackDump(data); } \ No newline at end of file diff --git a/src/hlib/flatBuffers/integer.c b/src/hlib/flatBuffers/integer.c index 19d34d1..e2713a1 100644 --- a/src/hlib/flatBuffers/integer.c +++ b/src/hlib/flatBuffers/integer.c @@ -23,12 +23,15 @@ } void *msgPackIntegerWrite(void *buffer, int32_t x, IntegerType type) { + uint8_t *bufferByte = buffer; if (x < 0 && type != Signed) { // printf("integerWrite: %i is negative but type is Unsigned!\n", x); // should never occur when using the correct macros - return buffer; + // as a failsave, treat it as a uint32_t + *bufferByte = formatInfo[FORMAT_UINT32].min; + *(uint32_t *)(buffer + 1) = (uint32_t) x; + return buffer + 5; } - uint8_t *bufferByte = buffer; if ((x & 0x7F) == x) { *bufferByte = (uint8_t)x; // fixint diff --git a/src/include/buffers.h b/src/include/buffers.h index b286d20..34a0242 100644 --- a/src/include/buffers.h +++ b/src/include/buffers.h @@ -26,6 +26,9 @@ #define STRING_Length_id() STRING_Length #define MAP_Length_id() MAP_Length +#define LIST_Length(list, type, name, contents) msgPackArrayLength(listCount(list)) + ({ uint32_t len = 0; foreach (list, type, name, { len += contents(LENGTH, +); }) len; }) +#define LIST_Length_id() LIST_Length + #define ARRAY_Length(contents) msgPackArrayLength(contents(ONE, +)) + contents(LENGTH, +) #define MAP_Length(contents) msgPackMapLength(allocationData, contents(ONE, +)) + contents(LENGTH, +) @@ -40,6 +43,9 @@ #define STRING_Write_id() STRING_Write #define MAP_Write_id() MAP_Write +#define LIST_Write_id() LIST_Write +#define LIST_Write(list, type, name, contents) buffer = msgPackArrayWrite(buffer, listCount(list)); foreach (list, type, name, { contents(WRITE, NOTHING); }) + #define ARRAY_Write(contents) buffer = msgPackArrayWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) #define MAP_Write(contents) buffer = msgPackMapWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index eff6473..9f4b184 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -1,11 +1,11 @@ #include #include -REQUEST(pciDump, "lspci", "dump"); +REQUEST(pciDump, "lspci", "dumpAll"); int32_t main() { uintptr_t dataPhysical = pciDump(1, 0); void *data = requestMemory(1, NULL, PTR(dataPhysical)); - printf("pci data for device 1:\n"); + printf("pci data:\n"); msgPackDump(data); } \ No newline at end of file diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 7934528..4bc642d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -133,6 +133,7 @@ int32_t enableBusMaster(uint32_t deviceId); int32_t getPCIInterrupt(uint32_t deviceId); uintptr_t dump(uint32_t device); +uintptr_t dumpAll(); void initializePci() { createFunction("getDeviceClass", (void *)getDeviceClass); @@ -140,6 +141,7 @@ createFunction("enableBusMaster", (void *)enableBusMaster); createFunction("getInterrupt", (void *)getPCIInterrupt); createFunction("dump", (void *)dump); + createFunction("dumpAll", (void *)dumpAll); if (!(pciConfigRead(0, 0, 0, 0x0E) & 0x80)) { checkBus(0); } else { @@ -198,7 +200,7 @@ X(STRING, "class") S \ X(INTEGER, device->class << 16 | device->subclass << 8 | device->programmingInterface) -#define DEVICE_DUMP(X) X(MAP, DEVICE_DUMP_MAP_DATA) +#define DEVICE_DUMP(X, ...) X(MAP, DEVICE_DUMP_MAP_DATA) uintptr_t dump(uint32_t deviceId) { GET_HEADER @@ -210,6 +212,19 @@ return result; } +#define DEVICES_DUMP(X) X(LIST, pciDevices, PciDevice *, device, DEVICE_DUMP) + +uintptr_t dumpAll() { + uint32_t deviceId = 0; + GET_HEADER + CREATE(data, DEVICES_DUMP); + void *resultBuffer = requestMemory(1, NULL, NULL); + memcpy(data, resultBuffer, dataLength); + uint32_t result = U32(getPhysicalAddress(resultBuffer)); + free(resultBuffer); + return result; +} + int32_t main() { if (!initialized) { initializePci();