@@ -306,32 +306,52 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
306306 });
307307
308308 for (obj .object .get ("items" ).? .array .items ) | item | {
309+ var register_ids : std .ArrayList (Database .RegisterID ) = .empty ;
310+ defer register_ids .deinit (allocator );
309311 const register_name = item .object .get ("name" ).? .string ;
310312 const description : ? []const u8 = if (item .object .get ("description" )) | desc | desc .string else null ;
311313 const byte_offset = item .object .get ("byte_offset" ).? .integer ;
312314 const item_bit_size = if (item .object .get ("bit_size" )) | v | v .integer else 32 ;
313-
314- const register_id = try db .create_register (group_id , .{
315- .name = register_name ,
316- .description = description ,
317- .offset_bytes = @intCast (byte_offset ),
318- .size_bits = @intCast (item_bit_size ),
319- .count = if (item .object .get ("array" )) | array | blk : {
320- if (array .object .get ("len" )) | count | {
321- // ensure stride is always 4 for now, assuming that
322- // it's in bytes
323- const stride = array .object .get ("stride" ).? .integer ;
324- if (stride != 4 ) {
325- std .log .warn ("ignoring register array with unsupported stride: {} != 4 for register {s} in {s} in {s}" , .{ stride , register_name , key ["block/" .len .. ], name });
326- break :blk null ;
315+ const maybe_count : ? u64 , const maybe_stride : ? u64 = if (item .object .get ("array" )) | array | blk : {
316+ if (array .object .get ("len" )) | count | {
317+ if (array .object .get ("stride" )) | stride | {
318+ if (stride .integer > 4 ) {
319+ break :blk .{ @intCast (count .integer ), @intCast (stride .integer ) };
327320 }
328-
329- break :blk @intCast (count .integer );
330321 }
322+ break :blk .{ @intCast (count .integer ), null };
323+ }
331324
332- break :blk null ;
333- } else null ,
334- });
325+ break :blk .{ null , null };
326+ } else .{ null , null };
327+
328+ if (maybe_stride ) | stride | {
329+ if (maybe_count ) | count | {
330+ for (0.. count ) | id | {
331+ const register_part_name = try std .fmt .allocPrint (allocator , "{s}[{d}]" , .{
332+ register_name ,
333+ id ,
334+ });
335+ const register_id = try db .create_register (group_id , .{
336+ .name = register_part_name ,
337+ .description = description ,
338+ .offset_bytes = @intCast (byte_offset + (id * stride )),
339+ .size_bits = @intCast (item_bit_size ),
340+ .count = null ,
341+ });
342+ try register_ids .append (allocator , register_id );
343+ }
344+ }
345+ } else {
346+ const register_id = try db .create_register (group_id , .{
347+ .name = register_name ,
348+ .description = description ,
349+ .offset_bytes = @intCast (byte_offset ),
350+ .size_bits = @intCast (item_bit_size ),
351+ .count = maybe_count ,
352+ });
353+ try register_ids .append (allocator , register_id );
354+ }
335355
336356 if (item .object .get ("fieldset" )) | fieldset | blk : {
337357 const fieldset_key = try std .fmt .allocPrint (allocator , "fieldset/{s}" , .{fieldset .string });
@@ -356,7 +376,7 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
356376 // these are evenly spaced and much nicer to work with.
357377
358378 array_count = if (object_map .get ("len" )) | len | @intCast (len .integer ) else null ;
359- array_stride = if (object_map .get ("stride" )) | stride | @intCast (stride .integer ) else null ;
379+ array_stride = if (object_map .get ("stride" )) | field_stride | @intCast (field_stride .integer ) else null ;
360380
361381 // This category where there is an array of items, but it is given by
362382 // individual offsets as opposed to a count + stride. This is used when strides are
@@ -365,30 +385,32 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
365385 if (object_map .get ("offsets" )) | positions | {
366386 for (positions .array .items , 0.. ) | position , idx | {
367387 const field_name_irregular_stride = try std .fmt .allocPrint (allocator , "{s}[{}]" , .{ field_name , idx });
368-
369- try db .add_register_field (register_id , .{
370- .name = field_name_irregular_stride ,
371- .description = field_description ,
372- .offset_bits = @intCast (position .integer + bit_offset ),
373- .size_bits = @intCast (bit_size ),
374- .enum_id = enum_id ,
375- .count = null ,
376- .stride = null ,
377- });
388+ for (register_ids .items ) | register_id | {
389+ try db .add_register_field (register_id , .{
390+ .name = field_name_irregular_stride ,
391+ .description = field_description ,
392+ .offset_bits = @intCast (position .integer + bit_offset ),
393+ .size_bits = @intCast (bit_size ),
394+ .enum_id = enum_id ,
395+ .count = null ,
396+ .stride = null ,
397+ });
398+ }
378399 }
379400 continue :next_field ;
380401 }
381402 }
382-
383- try db .add_register_field (register_id , .{
384- .name = field_name ,
385- .description = field_description ,
386- .offset_bits = @intCast (bit_offset ),
387- .size_bits = @intCast (bit_size ),
388- .enum_id = enum_id ,
389- .count = array_count ,
390- .stride = array_stride ,
391- });
403+ for (register_ids .items ) | register_id | {
404+ try db .add_register_field (register_id , .{
405+ .name = field_name ,
406+ .description = field_description ,
407+ .offset_bits = @intCast (bit_offset ),
408+ .size_bits = @intCast (bit_size ),
409+ .enum_id = enum_id ,
410+ .count = array_count ,
411+ .stride = array_stride ,
412+ });
413+ }
392414 },
393415 .array = > | arr | {
394416 // This case is for discontinuous fields where the first few bits are
@@ -411,18 +433,19 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
411433 var array_stride : ? u8 = null ;
412434 if (field .object .get ("array" )) | array | {
413435 array_count = if (array .object .get ("len" )) | len | @intCast (len .integer ) else null ;
414- array_stride = if (array .object .get ("stride" )) | stride | @intCast (stride .integer ) else null ;
436+ array_stride = if (array .object .get ("stride" )) | field_stride | @intCast (field_stride .integer ) else null ;
437+ }
438+ for (register_ids .items ) | register_id | {
439+ try db .add_register_field (register_id , .{
440+ .name = non_contiguous_field_name ,
441+ .description = field_description ,
442+ .offset_bits = @intCast (bit_offset ),
443+ .size_bits = @intCast (bit_size ),
444+ .enum_id = enum_id ,
445+ .count = array_count ,
446+ .stride = array_stride ,
447+ });
415448 }
416-
417- try db .add_register_field (register_id , .{
418- .name = non_contiguous_field_name ,
419- .description = field_description ,
420- .offset_bits = @intCast (bit_offset ),
421- .size_bits = @intCast (bit_size ),
422- .enum_id = enum_id ,
423- .count = array_count ,
424- .stride = array_stride ,
425- });
426449 }
427450 },
428451 else = > | val | {
@@ -603,4 +626,3 @@ const std = @import("std");
603626const Database = @import ("Database.zig" );
604627const Arch = @import ("arch.zig" ).Arch ;
605628const arm = @import ("arch/arm.zig" );
606- const FS_Directory = @import ("FS_Directory.zig" );
0 commit comments