[sw] Fix for DV logging

SW logging for DV is broken at TOT. See #2026 for details.

Signed-off-by: Srikrishna Iyer <sriyer@google.com>
diff --git a/sw/device/lib/base/log.c b/sw/device/lib/base/log.c
index 67aac75..8fb68af 100644
--- a/sw/device/lib/base/log.c
+++ b/sw/device/lib/base/log.c
@@ -73,7 +73,7 @@
  * Indicates the fixed location in RAM for SW logging for DV.
  * TODO: Figure aout a better place to put this.
  */
-static const uintptr_t kSwLogDvAddr = 0x1000fffc;
+static const uintptr_t kSwDvLogAddr = 0x1000fffc;
 
 /**
  * Logs `log and the values that follow in an efficient, DV-testbench
@@ -86,7 +86,7 @@
  * @param ... format parameters matching the format string.
  */
 void base_log_internal_dv(const log_fields_t *log, uint32_t nargs, ...) {
-  mmio_region_t log_device = mmio_region_from_addr(kSwLogDvAddr);
+  mmio_region_t log_device = mmio_region_from_addr(kSwDvLogAddr);
   mmio_region_write32(log_device, 0x0, (uintptr_t)log);
 
   va_list args;
diff --git a/sw/device/lib/base/log.h b/sw/device/lib/base/log.h
index 6eae51f..9d7fab4 100644
--- a/sw/device/lib/base/log.h
+++ b/sw/device/lib/base/log.h
@@ -119,7 +119,7 @@
       static const log_fields_t kLogFields =                     \
           LOG_MAKE_FIELDS_(severity, format, ##__VA_ARGS__);     \
       base_log_internal_dv(&kLogFields,                          \
-                           GET_NUM_VARIABLE_ARGS(__VA_ARGS__),   \
+                           GET_NUM_VARIABLE_ARGS(format, ##__VA_ARGS__), \
                            ##__VA_ARGS__); /* clang-format on */ \
     } else {                                                     \
       log_fields_t log_fields =                                  \
@@ -134,7 +134,8 @@
 #define LOG_MAKE_FIELDS_(_severity, _format, ...)                         \
   {                                                                       \
     .severity = _severity, .file_name = "" __FILE__ "", .line = __LINE__, \
-    .nargs = GET_NUM_VARIABLE_ARGS(__VA_ARGS__), .format = "" _format "", \
+    .nargs = GET_NUM_VARIABLE_ARGS(_format, ##__VA_ARGS__),               \
+    .format = "" _format "",                                              \
   }
 
 /**
diff --git a/sw/device/lib/base/macros.h b/sw/device/lib/base/macros.h
index a883914..e0e5424 100644
--- a/sw/device/lib/base/macros.h
+++ b/sw/device/lib/base/macros.h
@@ -16,14 +16,18 @@
  * This macro is based off of a well-known preprocessor trick. This
  * StackOverflow post expains the trick in detail:
  * https://stackoverflow.com/questions/2308243/macro-returning-the-number-of-arguments-it-is-given-in-c
+ * TODO #2026: a dummy token is required for this to work correctly.
+ *
+ * @param dummy a dummy token that is required to be passed for the calculation
+ *              to work correctly.
+ * @param ... the variable args list.
  */
-#define GET_NUM_VARIABLE_ARGS(...) PASS_N_VARIABLE_ARGS_(0, ##__VA_ARGS__)
 
 // Implementation details for `GET_NUM_VARIABLE_ARGS()`.
-#define PASS_N_VARIABLE_ARGS_(...)                                             \
-  SHIFT_N_VARIABLE_ARGS_(__VA_ARGS__, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22,  \
-                         21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, \
-                         7, 6, 5, 4, 3, 2, 1, 0)
+#define GET_NUM_VARIABLE_ARGS(dummy, ...)                                      \
+  SHIFT_N_VARIABLE_ARGS_(dummy, ##__VA_ARGS__, 31, 30, 29, 28, 27, 26, 25, 24, \
+                         23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11,   \
+                         10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
 #define SHIFT_N_VARIABLE_ARGS_(...) GET_NTH_VARIABLE_ARG_(__VA_ARGS__)
 #define GET_NTH_VARIABLE_ARG_(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, \
                               x11, x12, x13, x14, x15, x16, x17, x18, x19, \