parser_re2c.re 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /*
  2. * XJKJ-STL Deterministic re2c Line Lexer & Coordinate Extractor (v0.8.1.19)
  3. *
  4. * Compiled via: re2c -W --no-generation-date -o parser_re2c.c parser_re2c.re
  5. * Pure C11 / x86-64 SSE2 baseline; zero heap allocations; replaces per-line
  6. * repeated .contains() scans with a deterministic finite automaton (DFA).
  7. *
  8. * Verified 1:1 against both real server firmwares:
  9. * - .166: 107_VD012 / [Hovsee] / [HS_*] / [0][AMT #] GNR-4.3.3 (24 algos)
  10. * - .165: [CxmtDdrTest] / [HD_*] / [0][AMEMDIAG #] GNR-4.3.0 (19 algos)
  11. * - 118.efi / PassMark MemTest86 Site / UEFI Shell / PXE
  12. */
  13. #include "stl_accel.h"
  14. #include <string.h>
  15. static inline uint8_t ascii_lower(uint8_t c) {
  16. return (c >= 'A' && c <= 'Z') ? (uint8_t)(c + 32) : c;
  17. }
  18. static int parse_i32_at(const uint8_t *p, const uint8_t *end, int32_t *out, const uint8_t **after) {
  19. while (p < end && (*p == ' ' || *p == '\t' || *p == ':' || *p == '=' || *p == '#')) {
  20. p++;
  21. }
  22. if (p >= end) return 0;
  23. int neg = 0;
  24. if (*p == '-') { neg = 1; p++; }
  25. else if (*p == '+') { p++; }
  26. if (p >= end || *p < '0' || *p > '9') return 0;
  27. int64_t v = 0;
  28. while (p < end && *p >= '0' && *p <= '9') {
  29. v = v * 10 + (*p - '0');
  30. if (v > 0x7fffffffLL) v = 0x7fffffffLL;
  31. p++;
  32. }
  33. *out = neg ? (int32_t)(-v) : (int32_t)v;
  34. if (after) *after = p;
  35. return 1;
  36. }
  37. static int parse_hex64_at(const uint8_t *p, const uint8_t *end, uint64_t *out) {
  38. while (p < end && (*p == ' ' || *p == '\t' || *p == ':' || *p == '=')) p++;
  39. if (p + 2 <= end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) p += 2;
  40. if (p >= end) return 0;
  41. uint64_t v = 0;
  42. int digits = 0;
  43. while (p < end) {
  44. uint8_t c = *p;
  45. uint8_t d;
  46. if (c >= '0' && c <= '9') d = (uint8_t)(c - '0');
  47. else if (c >= 'a' && c <= 'f') d = (uint8_t)(c - 'a' + 10);
  48. else if (c >= 'A' && c <= 'F') d = (uint8_t)(c - 'A' + 10);
  49. else break;
  50. v = (v << 4) | d;
  51. digits++;
  52. p++;
  53. }
  54. if (digits == 0) return 0;
  55. if (p < end) {
  56. uint8_t nc = *p;
  57. if (nc == '_' ||
  58. (nc >= 'g' && nc <= 'z' && nc != 'h') ||
  59. (nc >= 'G' && nc <= 'Z' && nc != 'H') ||
  60. ((nc == 'h' || nc == 'H') && p + 1 < end &&
  61. ((p[1] >= '0' && p[1] <= '9') || (p[1] >= 'a' && p[1] <= 'z') || (p[1] >= 'A' && p[1] <= 'Z')))) {
  62. return 0;
  63. }
  64. }
  65. *out = v;
  66. return 1;
  67. }
  68. /* Extract leading [<cpu>] prefix common on Hovsee/CxmtDdrTest/AMT lines */
  69. static void extract_leading_bracket_cpu(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
  70. const uint8_t *p = s;
  71. while (p < end && (*p == '.' || *p == ' ' || *p == '\t')) p++;
  72. if (p + 3 <= end && p[0] == '[' && (p[1] == '0' || p[1] == '1') && p[2] == ']') {
  73. ev->cpu = (int8_t)(p[1] - '0');
  74. }
  75. }
  76. /* Extract N<cpu>.C<ch>[.D<dimm>][.SC<sub>][.R<rank>] topology token & RMT margins */
  77. static int extract_ncd_token_cols(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev, int *out_cols) {
  78. if (out_cols) *out_cols = 0;
  79. for (const uint8_t *p = s; p + 5 <= end; p++) {
  80. if ((p[0] == 'N' || p[0] == 'n') &&
  81. (p[1] >= '0' && p[1] <= '3') && p[2] == '.' &&
  82. (p[3] == 'C' || p[3] == 'c') && (p[4] >= '0' && p[4] <= '9')) {
  83. int cpu = p[1] - '0';
  84. const uint8_t *q = p + 4;
  85. int ch = 0;
  86. while (q < end && *q >= '0' && *q <= '9') {
  87. ch = ch * 10 + (*q - '0');
  88. q++;
  89. }
  90. if (cpu >= 0 && cpu <= 1 && ch >= 0 && ch <= 11) {
  91. ev->cpu = (int8_t)cpu;
  92. ev->channel = (int8_t)ch;
  93. while (q + 2 <= end && *q == '.') {
  94. if (q + 3 <= end && (q[1] == 'D' || q[1] == 'd') && q[2] >= '0' && q[2] <= '1') {
  95. ev->dimm = (int8_t)(q[2] - '0');
  96. q += 3;
  97. } else if (q + 4 <= end && (q[1] == 'S' || q[1] == 's') &&
  98. (q[2] == 'C' || q[2] == 'c') && q[3] >= '0' && q[3] <= '1') {
  99. q += 4;
  100. } else if (q + 3 <= end && (q[1] == 'R' || q[1] == 'r') && q[2] >= '0' && q[2] <= '9') {
  101. ev->rank = (int8_t)((q[2] - '0') & 3);
  102. q += 3;
  103. while (q < end && *q >= '0' && *q <= '9') q++;
  104. } else if (q + 3 <= end && (q[1] == 'L' || q[1] == 'l') && q[2] >= '0' && q[2] <= '9') {
  105. q += 3;
  106. while (q < end && *q >= '0' && *q <= '9') q++;
  107. } else if (q + 4 <= end && (q[1] == ' ' || q[1] == '\t') && (q[2] == 'A' || q[2] == 'a') && q[3] >= '0' && q[3] <= '9') {
  108. q += 4;
  109. while (q < end && *q >= '0' && *q <= '9') q++;
  110. } else if (q + 3 <= end && (q[1] == 'B' || q[1] == 'b') && q[2] >= '0' && q[2] <= '9') {
  111. int bk = 0;
  112. const uint8_t *bp = q + 2;
  113. while (bp < end && *bp >= '0' && *bp <= '9') {
  114. bk = bk * 10 + (*bp - '0');
  115. bp++;
  116. }
  117. if (bk >= 0 && bk < 32) {
  118. ev->bank = (int8_t)bk;
  119. }
  120. q = bp;
  121. } else {
  122. break;
  123. }
  124. }
  125. while (q < end && (*q == ' ' || *q == '\t')) q++;
  126. if (q < end && *q == ':') {
  127. q++;
  128. int32_t vals[4] = {0, 0, 0, 0};
  129. int got = 0;
  130. const uint8_t *nx = q;
  131. while (nx < end && got < 4) {
  132. while (nx < end && (*nx == ' ' || *nx == '\t')) nx++;
  133. if (nx < end && *nx == '*') {
  134. vals[got++] = 0;
  135. nx++;
  136. } else {
  137. int32_t mv = 0;
  138. if (parse_i32_at(nx, end, &mv, &nx)) {
  139. vals[got++] = mv;
  140. } else {
  141. break;
  142. }
  143. }
  144. }
  145. if (out_cols) *out_cols = got;
  146. if (got >= 4) {
  147. ev->val0 = vals[0];
  148. ev->val1 = vals[1];
  149. ev->val2 = vals[2];
  150. ev->val3 = vals[3];
  151. }
  152. }
  153. return 1;
  154. }
  155. }
  156. }
  157. return 0;
  158. }
  159. static int extract_ncd_token(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
  160. return extract_ncd_token_cols(s, end, ev, NULL);
  161. }
  162. static int match_ci_kw(const uint8_t *p, const uint8_t *end, const char *kw, const uint8_t **after) {
  163. size_t klen = strlen(kw);
  164. if ((size_t)(end - p) < klen) return 0;
  165. for (size_t i = 0; i < klen; i++) {
  166. if (ascii_lower(p[i]) != (uint8_t)kw[i]) return 0;
  167. }
  168. const uint8_t *q = p + klen;
  169. if (q < end && ((*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || *q == '_')) return 0;
  170. *after = q;
  171. return 1;
  172. }
  173. static int match_ci_word(const uint8_t *buf_start, const uint8_t *p, const uint8_t *end, const char *kw, const uint8_t **after) {
  174. if (p > buf_start) {
  175. uint8_t prev = p[-1];
  176. if ((prev >= 'a' && prev <= 'z') || (prev >= 'A' && prev <= 'Z') || prev == '_') return 0;
  177. }
  178. return match_ci_kw(p, end, kw, after);
  179. }
  180. /*
  181. * Extract physical topology coordinates from BIOS/Training/AMT/MemTest86 lines.
  182. * Strictly enforces 0 <= bank < 32 (never trusts broken historical >= 32 bank analyses).
  183. */
  184. static void extract_coords_and_addr(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
  185. extract_leading_bracket_cpu(s, end, ev);
  186. extract_ncd_token(s, end, ev);
  187. /* Check MemTest86 "CPU<0|1>_DIMM_<A..L>", "(P0,C3,S0,R0)", "Channel/Slot: N0-3-0", or "(Chan,Slot,Rank,Bank,Row,Col): (3,0,0,12,...)" */
  188. for (const uint8_t *p = s; p + 6 <= end; p++) {
  189. if (p + 11 <= end &&
  190. (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
  191. (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_'))) &&
  192. ascii_lower(p[0]) == 'c' && ascii_lower(p[1]) == 'p' && ascii_lower(p[2]) == 'u' &&
  193. (p[3] == '0' || p[3] == '1') && p[4] == '_' &&
  194. ascii_lower(p[5]) == 'd' && ascii_lower(p[6]) == 'i' && ascii_lower(p[7]) == 'm' && ascii_lower(p[8]) == 'm' &&
  195. p[9] == '_') {
  196. uint8_t ltr = p[10];
  197. uint8_t ul = (ltr >= 'a' && ltr <= 'z') ? (uint8_t)(ltr - 32) : ltr;
  198. int ok_after = (p + 11 == end) ||
  199. (!((p[11] >= 'a' && p[11] <= 'z') || (p[11] >= 'A' && p[11] <= 'Z') ||
  200. (p[11] >= '0' && p[11] <= '9') || p[11] == '_'));
  201. if (ok_after && ul >= 'A' && ul <= 'L') {
  202. ev->cpu = (int8_t)(p[3] - '0');
  203. ev->channel = (int8_t)(ul - 'A');
  204. if (ev->dimm < 0) ev->dimm = 0;
  205. }
  206. }
  207. if ((p[0] == 'N' || p[0] == 'n') && (p[1] == '0' || p[1] == '1') &&
  208. p[2] == '-' && p[3] >= '0' && p[3] <= '9') {
  209. int32_t ch = -1, sl = -1;
  210. const uint8_t *nx = p + 3;
  211. if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
  212. ev->cpu = (int8_t)(p[1] - '0');
  213. ev->channel = (int8_t)ch;
  214. if (nx < end && *nx == '-') {
  215. if (parse_i32_at(nx + 1, end, &sl, &nx) && sl >= 0 && sl <= 1) {
  216. ev->dimm = (int8_t)sl;
  217. }
  218. }
  219. }
  220. }
  221. if (p + 8 > end) continue;
  222. if (p[0] == '(' && (p[1] == 'P' || p[1] == 'p') && (p[2] == '0' || p[2] == '1') &&
  223. p[3] == ',' && (p[4] == 'C' || p[4] == 'c')) {
  224. int32_t ch = -1, sl = -1;
  225. const uint8_t *nx = p + 5;
  226. if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
  227. ev->cpu = (int8_t)(p[2] - '0');
  228. ev->channel = (int8_t)ch;
  229. if (nx + 2 < end && nx[0] == ',' && (nx[1] == 'S' || nx[1] == 's')) {
  230. if (parse_i32_at(nx + 2, end, &sl, &nx) && sl >= 0 && sl <= 1) {
  231. ev->dimm = (int8_t)sl;
  232. }
  233. }
  234. }
  235. }
  236. size_t tup_skip = 0;
  237. if (p + 28 <= end && memcmp(p, "(Channel,Slot,Rank,Bank,Row,", 28) == 0) {
  238. tup_skip = 28;
  239. } else if (p + 25 <= end && memcmp(p, "(Chan,Slot,Rank,Bank,Row,", 25) == 0) {
  240. tup_skip = 25;
  241. } else if (p + 16 <= end && memcmp(p, "(Ch,Sl,Rk,Bk,Rw,", 16) == 0) {
  242. tup_skip = 16;
  243. }
  244. if (tup_skip > 0) {
  245. const uint8_t *rp = memchr(p + tup_skip, ')', (size_t)(end - (p + tup_skip)));
  246. const uint8_t *nx = rp ? (rp + 1) : (p + tup_skip);
  247. while (nx < end && (*nx == ':' || *nx == '=' || *nx == ' ' || *nx == '\t' || *nx == '(')) {
  248. nx++;
  249. }
  250. int32_t c_ch = -1, c_sl = -1, c_rk = -1, c_bk = -1;
  251. if (parse_i32_at(nx, end, &c_ch, &nx) && nx < end && *nx == ',' &&
  252. parse_i32_at(nx + 1, end, &c_sl, &nx) && nx < end && *nx == ',' &&
  253. parse_i32_at(nx + 1, end, &c_rk, &nx) && nx < end && *nx == ',' &&
  254. parse_i32_at(nx + 1, end, &c_bk, &nx)) {
  255. if (c_ch >= 12 && c_ch <= 23 && ev->cpu < 0) {
  256. ev->cpu = 1;
  257. ev->channel = (int8_t)(c_ch - 12);
  258. } else if (c_ch >= 0 && c_ch <= 11) {
  259. ev->channel = (int8_t)c_ch;
  260. }
  261. if (c_sl >= 0 && c_sl <= 1) ev->dimm = (int8_t)c_sl;
  262. if (c_rk >= 0 && c_rk <= 3) ev->rank = (int8_t)c_rk;
  263. if (c_bk >= 0 && c_bk < 32) ev->bank = (int8_t)c_bk;
  264. }
  265. }
  266. if ((p + 6 <= end && (p[0] == 'C' || p[0] == 'c') && (p[1] == 'h' || p[1] == 'H') &&
  267. p[2] == '/' && (p[3] == 'S' || p[3] == 's') && (p[4] == 'l' || p[4] == 'L') && p[5] == ':')) {
  268. const uint8_t *nx = p + 6;
  269. while (nx < end && (*nx == ' ' || *nx == '\t')) nx++;
  270. if (nx < end && *nx >= '0' && *nx <= '9') {
  271. int32_t c_ch = -1, c_sl = -1;
  272. if (parse_i32_at(nx, end, &c_ch, &nx) && c_ch >= 0 && c_ch <= 23) {
  273. if (c_ch >= 12 && ev->cpu < 0) {
  274. ev->cpu = 1;
  275. ev->channel = (int8_t)(c_ch - 12);
  276. } else if (c_ch <= 11) {
  277. ev->channel = (int8_t)c_ch;
  278. }
  279. if (nx < end && (*nx == '/' || *nx == '-' || *nx == ',') &&
  280. parse_i32_at(nx + 1, end, &c_sl, &nx) && c_sl >= 0 && c_sl <= 1) {
  281. ev->dimm = (int8_t)c_sl;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. int bg = -1;
  288. int ba = -1;
  289. int direct_bank = -1;
  290. for (const uint8_t *p = s; p < end; p++) {
  291. if (p > s) {
  292. uint8_t prev = p[-1];
  293. if ((prev >= 'a' && prev <= 'z') || (prev >= 'A' && prev <= 'Z') ||
  294. (prev >= '0' && prev <= '9') || prev == '_') {
  295. continue;
  296. }
  297. }
  298. const uint8_t *after = NULL;
  299. int32_t v = 0;
  300. if (match_ci_kw(p, end, "socket", &after) || match_ci_kw(p, end, "scktid", &after) ||
  301. match_ci_kw(p, end, "node", &after) || match_ci_kw(p, end, "cpu", &after)) {
  302. if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 1 && ev->cpu < 0) {
  303. ev->cpu = (int8_t)v;
  304. }
  305. } else if (match_ci_kw(p, end, "channel", &after) || match_ci_kw(p, end, "ch", &after) ||
  306. match_ci_kw(p, end, "chan", &after) ||
  307. (ev->channel < 0 && match_ci_kw(p, end, "chid", &after))) {
  308. if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 23) {
  309. if (v >= 12 && ev->cpu < 0) {
  310. ev->cpu = 1;
  311. ev->channel = (int8_t)(v - 12);
  312. } else if (v <= 11) {
  313. ev->channel = (int8_t)v;
  314. }
  315. }
  316. } else if (match_ci_kw(p, end, "dimm", &after) || match_ci_kw(p, end, "dimmslot", &after) ||
  317. match_ci_kw(p, end, "slot", &after) || match_ci_kw(p, end, "sl", &after)) {
  318. if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 23) {
  319. if (v <= 1) {
  320. ev->dimm = (int8_t)v;
  321. } else if (ev->channel < 0) {
  322. ev->cpu = (int8_t)(v / 12);
  323. ev->channel = (int8_t)(v % 12);
  324. ev->dimm = 0;
  325. }
  326. }
  327. } else if (match_ci_kw(p, end, "rank", &after) || match_ci_kw(p, end, "dimmrank", &after)) {
  328. if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 3) {
  329. ev->rank = (int8_t)v;
  330. }
  331. } else if (match_ci_kw(p, end, "bankgroup", &after) || match_ci_kw(p, end, "bg", &after)) {
  332. if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 7) {
  333. bg = (int)v;
  334. }
  335. } else if (match_ci_kw(p, end, "bank", &after) || match_ci_kw(p, end, "ba", &after)) {
  336. if (parse_i32_at(after, end, &v, NULL)) {
  337. if ((after - p) == 2 && v >= 0 && v <= 3) {
  338. ba = (int)v;
  339. } else if (v >= 0 && v < 32) {
  340. direct_bank = (int)v;
  341. }
  342. }
  343. } else if (match_ci_kw(p, end, "addr", &after) || match_ci_kw(p, end, "address", &after) ||
  344. match_ci_kw(p, end, "checkpoint", &after)) {
  345. uint64_t a = 0;
  346. if (parse_hex64_at(after, end, &a)) {
  347. ev->addr = a;
  348. }
  349. }
  350. }
  351. if (bg >= 0 && ba >= 0) {
  352. int combined = bg * 4 + ba;
  353. if (combined >= 0 && combined < 32) ev->bank = (int8_t)combined;
  354. } else if (direct_bank >= 0 && direct_bank < 32 && ev->bank < 0) {
  355. ev->bank = (int8_t)direct_bank;
  356. }
  357. }
  358. static void trim_ws(const uint8_t **ps, const uint8_t **pe) {
  359. const uint8_t *s = *ps;
  360. const uint8_t *e = *pe;
  361. while (s < e && (*s == ' ' || *s == '\t')) s++;
  362. while (e > s && (e[-1] == ' ' || e[-1] == '\t' || e[-1] == '\r' || e[-1] == '\n')) e--;
  363. *ps = s;
  364. *pe = e;
  365. }
  366. /*!re2c
  367. re2c:define:YYCTYPE = uint8_t;
  368. re2c:yyfill:enable = 0;
  369. re2c:flags:tags = 0;
  370. re2c:flags:case-insensitive = 0;
  371. WS = [ \t]*;
  372. ANY = [\x00-\xff];
  373. DIG = [0-9]+;
  374. */
  375. static uint32_t re2c_scan_token(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
  376. uint8_t buf[1025];
  377. size_t n = (size_t)(end - s);
  378. if (n > 1024) n = 1024;
  379. memcpy(buf, s, n);
  380. buf[n] = 0;
  381. extract_leading_bracket_cpu(buf, buf + n, ev);
  382. const uint8_t *YYCURSOR = buf;
  383. const uint8_t *YYMARKER = buf;
  384. const uint8_t *lim = buf + n;
  385. /* Step 1: Anchored prompt & full-line patterns */
  386. /*!re2c
  387. WS "UIP>" WS "\x00" {
  388. return STL_LK_ICT_PROMPT;
  389. }
  390. WS "[" [01] "][" ("Hovsee" | "CxmtDdrTest") "]Please input your command" ":"? WS "\x00" {
  391. ev->cpu = (int8_t)(buf[1] == '1' ? 1 : 0);
  392. for (size_t i = 0; i + 6 <= n; i++) {
  393. if (memcmp(buf + i, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
  394. if (i + 11 <= n && memcmp(buf + i, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
  395. }
  396. return STL_LK_ICT_PROMPT;
  397. }
  398. WS (("[" [01] "]" WS) | ("CPU" [01] WS ":"? WS))? "[" ("CPU" [01] WS)? ("AMT" | "AMEMDIAG") WS "#" WS "]" WS "\x00" {
  399. for (size_t i = 0; i + 3 <= n; i++) {
  400. if (buf[i] == '[' && (buf[i+1] == '0' || buf[i+1] == '1') && buf[i+2] == ']') {
  401. ev->cpu = (int8_t)(buf[i+1] - '0');
  402. }
  403. if (i + 4 <= n && buf[i] == 'C' && buf[i+1] == 'P' && buf[i+2] == 'U' && (buf[i+3] == '0' || buf[i+3] == '1')) {
  404. ev->cpu = (int8_t)(buf[i+3] - '0');
  405. }
  406. if (i + 8 <= n && memcmp(buf + i, "AMEMDIAG", 8) == 0) ev->fw_family = 2;
  407. else if (memcmp(buf + i, "AMT", 3) == 0 && ev->fw_family == 0) ev->fw_family = 1;
  408. }
  409. return STL_LK_AMT_PROMPT;
  410. }
  411. WS "FS" [0-9] ":\\" ("EFI" | "efi") ("\\" [^\x00\r\n<>]*)? ">" WS "\x00" |
  412. WS "FS" [0-9] ":\\" ("EFI" | "efi") ">" WS "\x00" {
  413. for (size_t i = 0; i + 2 < n; i++) {
  414. if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
  415. ev->fs_index = (uint8_t)(buf[i+2] - '0');
  416. break;
  417. }
  418. }
  419. return STL_LK_UEFI_PROMPT_EFI;
  420. }
  421. WS "FS" [0-9] ":" "\\"? ">" WS "\x00" {
  422. for (size_t i = 0; i + 2 < n; i++) {
  423. if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
  424. ev->fs_index = (uint8_t)(buf[i+2] - '0');
  425. break;
  426. }
  427. }
  428. return STL_LK_UEFI_PROMPT_ROOT;
  429. }
  430. WS "Shell>" WS "\x00" {
  431. ev->fs_index = 255;
  432. return STL_LK_UEFI_PROMPT_ROOT;
  433. }
  434. * { goto scan_anywhere; }
  435. */
  436. scan_anywhere:
  437. YYCURSOR = buf;
  438. while (YYCURSOR < lim) {
  439. const uint8_t *tok = YYCURSOR;
  440. /*!re2c
  441. "[" ("SYS_" | "HS_") "BIOS]Version:" {
  442. if (tok[1] == 'H') ev->fw_family = 1;
  443. return STL_LK_BIOS_BOOT;
  444. }
  445. "[BIOS][Vref]" | "[CHIPID]" | "[SPD_MR]" | "[SPD_CRC]" {
  446. return STL_LK_NONE;
  447. }
  448. "Welcome to Hovsee" | "Hovsee inc. IMC Config Tool" {
  449. ev->fw_family = 1;
  450. return STL_LK_ICT_BANNER_HOVSEE;
  451. }
  452. "Welcome to CxmtDdrTest" | "CxmtDdrTest IMC Config Tool" {
  453. ev->fw_family = 2;
  454. return STL_LK_ICT_BANNER_CXMT;
  455. }
  456. "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "1" {
  457. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  458. return STL_LK_ICT_START_STAGE1;
  459. }
  460. "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "2" {
  461. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  462. return STL_LK_ICT_START_STAGE2;
  463. }
  464. "[Hovsee]Stage2 UIP" {
  465. ev->fw_family = 1;
  466. return STL_LK_ICT_START_STAGE2;
  467. }
  468. "[CxmtDdrTest]Stage2 UIP" {
  469. ev->fw_family = 2;
  470. return STL_LK_ICT_START_STAGE2;
  471. }
  472. "[Hovsee]Start UIP" {
  473. ev->fw_family = 1;
  474. return STL_LK_ICT_START_STAGE1;
  475. }
  476. "[CxmtDdrTest]Start UIP" {
  477. ev->fw_family = 2;
  478. return STL_LK_ICT_START_STAGE1;
  479. }
  480. "Please press ENTER to start UIP" {
  481. return STL_LK_ICT_ENTER_HINT;
  482. }
  483. "[" ("Hovsee" | "CxmtDdrTest") "]Please input your command" {
  484. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  485. /* Only prompt if no trailing user command echo on same line */
  486. const uint8_t *colon = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
  487. if (!colon || colon + 1 >= lim) return STL_LK_ICT_PROMPT;
  488. continue;
  489. }
  490. "[Hovsee]Exit UIP" | "[CxmtDdrTest]Exit UIP" |
  491. "[Hovsee]Exit Uip ddr test" | "[CxmtDdrTest]Exit Uip ddr test" |
  492. "[Hovsee]Exit Hovsee UIP" | "[CxmtDdrTest]Exit CxmtDdrTest UIP" |
  493. "[Hovsee]Exit ICT ddr test" | "[CxmtDdrTest]Exit ICT ddr test" |
  494. "No command input or timeout, so go on training" |
  495. "User input command is exit" {
  496. if (tok[0] == '[' && tok[1] == 'H') ev->fw_family = 1;
  497. if (tok[0] == '[' && tok[1] == 'C') ev->fw_family = 2;
  498. return STL_LK_ICT_EXIT;
  499. }
  500. "is not recognized as an internal or external command" {
  501. ev->subkind = 3; /* UEFI shell missing binary error */
  502. return STL_LK_MT_FAIL_COMPLETE;
  503. }
  504. "AdvancedMemTestWorker" | "GNR AP Gpio" | "SetVMGpioMemTest" | "DdrMemTest()" {
  505. for (const uint8_t *p = buf; p + 6 <= lim; p++) {
  506. if (memcmp(p, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
  507. if (p + 11 <= lim && memcmp(p, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
  508. }
  509. return STL_LK_NONE;
  510. }
  511. "[HS_MRC]" | "[HD_MRC]" |
  512. "[HS_StartMemTrain]" | "[HD_StartMemTrain]" |
  513. "[Hovsee]Socket " [01] " RcdQcaTraining" {
  514. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  515. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'o') ev->fw_family = 1;
  516. return STL_LK_MRC_START;
  517. }
  518. "STOP_MRC_RUN" | "MRC Done" | "Memory Training Complete" |
  519. "[HS_EndMemTrain]" | "[HD_EndMemTrain]" {
  520. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  521. return STL_LK_MRC_DONE;
  522. }
  523. "0x4F : DXE IPL Start" | "0x60 : DXE Core Started" |
  524. "0x90 : BDS Started" | "0x91 : Connecting Drivers" {
  525. ev->subkind = 4; /* POST / DXE milestone */
  526. return STL_LK_MRC_DONE;
  527. }
  528. ("AMT" | "AMEMDIAG") WS "Test Start" {
  529. ev->fw_family = (tok[0] == 'A' && tok[1] == 'M' && tok[2] == 'E') ? 2 : 1;
  530. ev->subkind = 3; /* AMT start */
  531. return STL_LK_AMT_PROGRESS;
  532. }
  533. "[" ("HS_" | "") "BIOS][Training][ScktId:" WS [01] "]" {
  534. if (tok[1] == 'H') ev->fw_family = 1;
  535. extract_coords_and_addr(s, end, ev);
  536. int is_pipe_sync_sbsp = 0;
  537. for (const uint8_t *p = YYCURSOR; p + 20 <= lim; p++) {
  538. if (memcmp(p, "Pipe Sync SBSP Status", 21) == 0) {
  539. is_pipe_sync_sbsp = 1;
  540. break;
  541. }
  542. }
  543. /* Check if Rank Margin Tool or MemTest or FAILED (excluding benign SNC/Pipe Sync SBSP Status reset notice) */
  544. for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
  545. if (p + 16 <= lim && memcmp(p, "Rank Margin Tool", 16) == 0) {
  546. return STL_LK_RMT_STOP;
  547. }
  548. if (!is_pipe_sync_sbsp && memcmp(p, "FAILED", 6) == 0) {
  549. ev->subkind = 2;
  550. return STL_LK_TRAINING_ERROR;
  551. }
  552. }
  553. return STL_LK_MRC_START;
  554. }
  555. "START_RMT_N" [01] {
  556. ev->cpu = (int8_t)(tok[11] - '0');
  557. return STL_LK_RMT_START;
  558. }
  559. "START_RMT" | "Starting RMT test v" | "Rank Margin Tool -- Started" |
  560. "[HS_StartRmt]" | "[HD_StartRmt]" {
  561. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  562. extract_coords_and_addr(s, end, ev);
  563. return STL_LK_RMT_START;
  564. }
  565. "STOP_RMT_N" [01] {
  566. ev->cpu = (int8_t)(tok[10] - '0');
  567. return STL_LK_RMT_STOP;
  568. }
  569. "STOP_RMT" | "[HS_StopRmt]" | "[HD_StopRmt]" | "RMT test v" {
  570. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') {
  571. ev->fw_family = 1;
  572. return STL_LK_RMT_STOP;
  573. }
  574. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'D') {
  575. return STL_LK_RMT_STOP;
  576. }
  577. for (const uint8_t *p = tok; p + 8 <= lim; p++) {
  578. if (memcmp(p, "complete", 8) == 0) {
  579. return STL_LK_RMT_STOP;
  580. }
  581. }
  582. if (tok[0] == 'S') return STL_LK_RMT_STOP;
  583. continue;
  584. }
  585. "[" ("HS" | "HD") "_" ("RMTSensor" | "Sensor") "]" {
  586. if (tok[2] == 'S') ev->fw_family = 1;
  587. extract_ncd_token(s, end, ev);
  588. const uint8_t *cl = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
  589. if (cl) {
  590. int32_t deg = 0;
  591. const uint8_t *nx = NULL;
  592. if (parse_i32_at(cl + 1, lim, &deg, &nx)) {
  593. int32_t tenths = 0;
  594. if (nx && nx + 1 < lim && *nx == '.' && nx[1] >= '0' && nx[1] <= '9') {
  595. tenths = nx[1] - '0';
  596. }
  597. ev->val3 = deg * 10 + (deg >= 0 ? tenths : -tenths);
  598. }
  599. }
  600. return STL_LK_INLINE_TEMP;
  601. }
  602. "[" ("HS" | "HD") "_DRAM]" {
  603. if (tok[2] == 'S') ev->fw_family = 1;
  604. extract_coords_and_addr(s, end, ev);
  605. /* Check Size:0 -> absent, else present */
  606. ev->subkind = 4;
  607. for (const uint8_t *p = YYCURSOR; p + 5 <= lim; p++) {
  608. if (memcmp(p, "Size:", 5) == 0) {
  609. int32_t sz = 0;
  610. if (parse_i32_at(p + 5, lim, &sz, NULL)) {
  611. ev->subkind = (sz > 0) ? 4 : 0;
  612. ev->val0 = sz;
  613. }
  614. break;
  615. }
  616. }
  617. return STL_LK_DIMM_INVENTORY;
  618. }
  619. "[" ("HS" | "HD") "_Disable" ("Dimm" | "DIMM") "]" | "DisableDIMM()" | "MapOutDimm()" | "Mapping out DDR" {
  620. extract_coords_and_addr(s, end, ev);
  621. ev->subkind = 3; /* disabled */
  622. return STL_LK_DIMM_INVENTORY;
  623. }
  624. "AMT Version " | "Welcome to Advanced Memory Test" | "GNR-4.3.3" {
  625. ev->fw_family = 1;
  626. return STL_LK_AMT_BANNER;
  627. }
  628. "AMEMDIAG Version " | "Welcome to Advanced Memory Diagnostic" | "GNR-4.3.0" {
  629. ev->fw_family = 2;
  630. return STL_LK_AMT_BANNER;
  631. }
  632. ("AMT" | "AMEMDIAG") WS "Test Algo Count:" {
  633. int32_t cnt = 0;
  634. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  635. ev->val1 = cnt; /* algorithm count */
  636. }
  637. ev->subkind = 0;
  638. return STL_LK_AMT_SUMMARY;
  639. }
  640. ("AMT" | "AMEMDIAG") WS "Test Result Summary:" |
  641. ("AMT" | "AMEMDIAG") WS "Test Result:" |
  642. "AMT Test PASS" | "AMEMDIAG Test PASS" | "All Test PASS" |
  643. "AMT Test FAIL" | "AMEMDIAG Test FAIL" | "All Test FAIL" {
  644. extract_coords_and_addr(s, end, ev);
  645. /* Determine scope: summary vs per-socket */
  646. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  647. const uint8_t *af = NULL;
  648. if (match_ci_kw(p, lim, "summary", &af)) {
  649. ev->val2 = 1; /* scope = summary */
  650. }
  651. if (match_ci_kw(p, lim, "fail", &af) || match_ci_kw(p, lim, "block", &af)) {
  652. ev->subkind = 2;
  653. } else if (match_ci_kw(p, lim, "pass", &af) && ev->subkind != 2) {
  654. ev->subkind = 1;
  655. }
  656. }
  657. return STL_LK_AMT_SUMMARY;
  658. }
  659. "Total Error Count" {
  660. int32_t cnt = 0;
  661. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  662. ev->val0 = cnt;
  663. ev->subkind = (cnt > 0) ? 2 : 1;
  664. }
  665. extract_coords_and_addr(s, end, ev);
  666. return STL_LK_AMT_SUMMARY;
  667. }
  668. "[" ("AMT" | "AMEMDIAG") WS DIG "/" DIG WS DIG "/" DIG WS DIG "/" DIG "]" {
  669. /* e.g. [0][AMT 1/1 1/1 3/24] Algo ... */
  670. ev->fw_family = (tok[1] == 'A' && tok[2] == 'M' && tok[3] == 'E') ? 2 : 1;
  671. const uint8_t *p = tok + 4;
  672. while (p < YYCURSOR && (*p < '0' || *p > '9')) p++;
  673. int32_t r1=0, r2=0, p1=0, p2=0, a1=0, a2=0;
  674. if (parse_i32_at(p, YYCURSOR, &r1, &p) && p < YYCURSOR && *p == '/' &&
  675. parse_i32_at(p+1, YYCURSOR, &r2, &p) &&
  676. parse_i32_at(p, YYCURSOR, &p1, &p) && p < YYCURSOR && *p == '/' &&
  677. parse_i32_at(p+1, YYCURSOR, &p2, &p) &&
  678. parse_i32_at(p, YYCURSOR, &a1, &p) && p < YYCURSOR && *p == '/' &&
  679. parse_i32_at(p+1, YYCURSOR, &a2, &p)) {
  680. ev->val0 = a1; /* algorithm_index */
  681. ev->val1 = a2; /* algorithm_count */
  682. if (a2 > 0) ev->val2 = (a1 * 100) / a2;
  683. }
  684. return STL_LK_AMT_PROGRESS;
  685. }
  686. "Failure detected - Advanced Memtest" | "Failure detected - PPR Memtest" |
  687. "Data Compare Error" | "[AMT_ERR]" | "[AMEMDIAG_ERR]" |
  688. "AMT-Correctable error found" |
  689. "[" ("HS" | "HD") "_MemoryError]" {
  690. ev->subkind = 2;
  691. extract_coords_and_addr(s, end, ev);
  692. return STL_LK_AMT_ERROR;
  693. }
  694. "Error Address" | "Fail Address" {
  695. uint64_t ea = 0;
  696. if (!parse_hex64_at(YYCURSOR, lim, &ea) || ea == 0) {
  697. continue;
  698. }
  699. ev->subkind = 2;
  700. ev->addr = ea;
  701. extract_coords_and_addr(s, end, ev);
  702. return STL_LK_AMT_ERROR;
  703. }
  704. "Logical Rank" WS "=" | "Error on rising strobe:" | "Error on falling strobe:" {
  705. ev->subkind = 5; /* 3-line AMT diagnostic continuation */
  706. extract_coords_and_addr(s, end, ev);
  707. return STL_LK_AMT_ERROR;
  708. }
  709. ("[Parity Error]" | "[Parity]") WS "Test:" {
  710. ev->subkind = 2;
  711. extract_coords_and_addr(s, end, ev);
  712. return STL_LK_MT_ERROR;
  713. }
  714. "Failing DIMM" | "[BIOS][FailMode]" |
  715. "Training Fail" | "BIST Error" | "BIST FAIL" | "Uncorrectable" |
  716. "Correctable error threshold exceeded" | "Critical Margin Error" |
  717. "FatalError:" | "No Eye width" |
  718. "No eye found" | "smaller than minimum critical margin" | "RxPerBitDeskew Failure" |
  719. "Parity Error" | "Parity error" | "[Parity]" | "[Parity Error]" | "PEC Error" | "PEC error" {
  720. ev->subkind = 2;
  721. extract_coords_and_addr(s, end, ev);
  722. return STL_LK_TRAINING_ERROR;
  723. }
  724. "UEFI Interactive Shell" {
  725. return STL_LK_UEFI_BANNER;
  726. }
  727. "Start PXE over IPv4" | "Downloading NBP file" | "NBP filename is" {
  728. ev->subkind = 0;
  729. return STL_LK_PXE_BOOT;
  730. }
  731. "NBP file downloaded successfully" | "LoadImage Status = Success" | "StartImage Status = Success" {
  732. ev->subkind = 1;
  733. return STL_LK_PXE_BOOT;
  734. }
  735. "PassMark MemTest86" | "MemTest86 V" | "MemTest86 v" |
  736. "Hovsee V" | "Hovsee v" |
  737. "Found configuration file:" | "*** TEST SESSION -" | "Launching 118.efi" |
  738. "STL_SIM TEST_START MT" {
  739. return STL_LK_MT_BANNER;
  740. }
  741. "STL_SIM TEST_RESULT " ("PASS" | "FAIL") {
  742. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  743. const uint8_t *af = NULL;
  744. if (match_ci_kw(p, lim, "fail", &af)) {
  745. ev->subkind = 2;
  746. return STL_LK_MT_FAIL_COMPLETE;
  747. }
  748. }
  749. ev->subkind = 1;
  750. return STL_LK_MT_PASS_COMPLETE;
  751. }
  752. "[MEM ERROR" | "[Mem Error]" | "[ECC Errors]" | "[ECC Error]" |
  753. "[IBECC Errors]" | "[Scrub ECC Errors]" | "[Data Error]" | "ECC Error:" {
  754. ev->subkind = 2;
  755. extract_coords_and_addr(s, end, ev);
  756. return STL_LK_MT_ERROR;
  757. }
  758. "DIMM err count=" {
  759. int32_t cnt = 0;
  760. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL) && cnt > 0) {
  761. ev->subkind = 2;
  762. extract_coords_and_addr(s, end, ev);
  763. return STL_LK_MT_ERROR;
  764. }
  765. continue;
  766. }
  767. "Channel/Slot:" | "Channel-Slot:" |
  768. "(Chan,Slot,Rank,Bank,Row," | "(Channel,Slot,Rank,Bank,Row," | "(Ch,Sl,Rk,Bk,Rw," {
  769. ev->subkind = 5; /* 2nd-line MT ECC/Data Error coordinate continuation */
  770. extract_coords_and_addr(s, end, ev);
  771. return STL_LK_MT_ERROR;
  772. }
  773. "(" WS "Test" WS DIG WS "cumulative error count:" WS DIG {
  774. int32_t tid = 0, cnt = 0;
  775. const uint8_t *nx = NULL;
  776. const uint8_t *tpos = memchr(tok, 'T', (size_t)(YYCURSOR - tok));
  777. if (tpos && parse_i32_at(tpos + 4, YYCURSOR, &tid, &nx)) {
  778. const uint8_t *cl = memchr(nx ? nx : tok, ':', (size_t)(YYCURSOR - (nx ? nx : tok)));
  779. if (cl && parse_i32_at(cl + 1, lim, &cnt, NULL) && cnt > 0) {
  780. ev->subkind = 6; /* MemTest86 per-test cumulative error count */
  781. ev->val1 = tid;
  782. ev->val0 = cnt;
  783. return STL_LK_MT_ERROR;
  784. }
  785. }
  786. continue;
  787. }
  788. "Finished pass #" DIG WS "(of" WS DIG ")" {
  789. int32_t pno = 0, ptot = 0;
  790. const uint8_t *nx = NULL;
  791. if (parse_i32_at(tok + 15, lim, &pno, &nx)) {
  792. const uint8_t *ofp = memchr(tok + 15, 'f', (size_t)(lim - (tok + 15)));
  793. if (ofp) parse_i32_at(ofp + 1, lim, &ptot, NULL);
  794. }
  795. int32_t errs = 0;
  796. for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
  797. const uint8_t *af = NULL;
  798. if (match_ci_kw(p, lim, "count", &af) || match_ci_kw(p, lim, "errors", &af)) {
  799. int32_t v = 0;
  800. if (parse_i32_at(af, lim, &v, NULL)) errs += v;
  801. }
  802. }
  803. ev->val0 = errs;
  804. if (ptot > 0 && pno >= ptot) {
  805. ev->subkind = (errs > 0) ? 2 : 1;
  806. return (errs > 0) ? STL_LK_MT_FAIL_COMPLETE : STL_LK_MT_PASS_COMPLETE;
  807. }
  808. ev->val2 = (ptot > 0) ? ((pno * 100) / ptot) : 50;
  809. return STL_LK_MT_PROGRESS;
  810. }
  811. ("#" WS)? "Tests Passed" WS ":" WS DIG "/" DIG {
  812. int32_t passed = 0, total = 0;
  813. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  814. const uint8_t *nx = NULL;
  815. if (cl && parse_i32_at(cl + 1, YYCURSOR, &passed, &nx)
  816. && nx && nx < YYCURSOR && *nx == '/'
  817. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  818. if (passed == total) {
  819. ev->subkind = 1;
  820. ev->val0 = 0;
  821. return STL_LK_MT_PASS_COMPLETE;
  822. }
  823. ev->val0 = passed;
  824. ev->val1 = total;
  825. ev->val2 = (passed * 100) / total;
  826. return STL_LK_MT_PROGRESS;
  827. }
  828. continue;
  829. }
  830. ("#" WS)? "Tests Completed" WS ":" WS DIG "/" DIG {
  831. int32_t done = 0, total = 0;
  832. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  833. const uint8_t *nx = NULL;
  834. if (cl && parse_i32_at(cl + 1, YYCURSOR, &done, &nx)
  835. && nx && nx < YYCURSOR && *nx == '/'
  836. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  837. ev->val0 = done;
  838. ev->val1 = total;
  839. ev->val2 = (done * 100) / total;
  840. return STL_LK_MT_PROGRESS;
  841. }
  842. continue;
  843. }
  844. ("#" WS)? "Bits in Error" WS ":" WS "Total" WS ":" WS DIG {
  845. int32_t cnt = 0;
  846. const uint8_t *tpos = NULL;
  847. for (const uint8_t *p = tok; p + 5 <= YYCURSOR; p++) {
  848. const uint8_t *af = NULL;
  849. if (match_ci_kw(p, YYCURSOR, "total", &af)) {
  850. tpos = af;
  851. break;
  852. }
  853. }
  854. if (tpos) {
  855. const uint8_t *cl = memchr(tpos, ':', (size_t)(YYCURSOR - tpos));
  856. if (cl && parse_i32_at(cl + 1, YYCURSOR, &cnt, NULL) && cnt > 0) {
  857. ev->subkind = 6;
  858. ev->val0 = cnt;
  859. ev->val1 = 99;
  860. return STL_LK_MT_ERROR;
  861. }
  862. }
  863. continue;
  864. }
  865. ("Test Result" | "Test result" | "Result") WS ":" WS (("INCOMPLETE" | "Incomplete" | "incomplete") WS)? ("PASS" | "Pass" | "pass" | "FAIL" | "Fail" | "fail" | "FAILED" | "Failed" | "failed") {
  866. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  867. const uint8_t *af = NULL;
  868. if (match_ci_kw(p, lim, "fail", &af) ||
  869. match_ci_kw(p, lim, "failed", &af)) {
  870. ev->subkind = 2;
  871. return STL_LK_MT_FAIL_COMPLETE;
  872. }
  873. if (match_ci_kw(p, lim, "pass", &af)) {
  874. ev->subkind = 1;
  875. return STL_LK_MT_PASS_COMPLETE;
  876. }
  877. }
  878. continue;
  879. }
  880. "Pass complete, no errors" {
  881. ev->subkind = 1;
  882. ev->val0 = 0;
  883. return STL_LK_MT_PASS_COMPLETE;
  884. }
  885. "Test Complete" {
  886. extract_coords_and_addr(s, end, ev);
  887. if (ev->val0 > 0) {
  888. ev->subkind = 2;
  889. return STL_LK_MT_FAIL_COMPLETE;
  890. }
  891. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  892. const uint8_t *af = NULL;
  893. if (match_ci_kw(p, lim, "fail", &af)) {
  894. ev->subkind = 2;
  895. return STL_LK_MT_FAIL_COMPLETE;
  896. }
  897. }
  898. ev->subkind = 1;
  899. return STL_LK_MT_PASS_COMPLETE;
  900. }
  901. "Running test #" DIG {
  902. int32_t tid = 0;
  903. if (parse_i32_at(tok + 14, lim, &tid, NULL)) {
  904. ev->val0 = tid;
  905. ev->val1 = 25;
  906. ev->val2 = (tid >= 0 && tid <= 25) ? ((tid * 100) / 26) : 50;
  907. }
  908. return STL_LK_MT_PROGRESS;
  909. }
  910. "N" [01] ".C" DIG (".D" [01])? (".SC" [01])? ".R" DIG (".L" DIG | "." WS "A" DIG)? (".B" DIG)? WS ":" {
  911. int mcols = 0;
  912. extract_ncd_token_cols(s, end, ev, &mcols);
  913. for (const uint8_t *q = YYCURSOR; q + 4 <= lim; q++) {
  914. const uint8_t *af = NULL;
  915. if (match_ci_word(YYCURSOR, q, lim, "advanced memtest", &af) ||
  916. match_ci_word(YYCURSOR, q, lim, "failure detected", &af) ||
  917. match_ci_word(YYCURSOR, q, lim, "ppr memtest", &af)) {
  918. ev->subkind = 2;
  919. extract_coords_and_addr(s, end, ev);
  920. return STL_LK_AMT_ERROR;
  921. }
  922. if (match_ci_word(YYCURSOR, q, lim, "error", &af) ||
  923. match_ci_word(YYCURSOR, q, lim, "failed", &af) ||
  924. match_ci_word(YYCURSOR, q, lim, "fail", &af)) {
  925. ev->subkind = 2;
  926. extract_coords_and_addr(s, end, ev);
  927. return STL_LK_TRAINING_ERROR;
  928. }
  929. }
  930. if (mcols >= 4) {
  931. return STL_LK_RMT_ROW;
  932. }
  933. continue;
  934. }
  935. "N" [01] ".C" DIG ".D" [01] {
  936. extract_ncd_token(s, end, ev);
  937. for (const uint8_t *q = tok; q + 11 <= lim; q++) {
  938. const uint8_t *af_por = NULL;
  939. if (match_ci_word(tok, q, lim, "minimum por", &af_por)) {
  940. ev->subkind = 4;
  941. return STL_LK_DIMM_INVENTORY;
  942. }
  943. }
  944. for (const uint8_t *p = tok; p + 11 <= lim; p++) {
  945. const uint8_t *af = NULL;
  946. if (match_ci_word(tok, p, lim, "failure detected", &af) ||
  947. match_ci_word(tok, p, lim, "advanced memtest", &af) ||
  948. match_ci_word(tok, p, lim, "ppr memtest", &af)) {
  949. ev->subkind = 2;
  950. extract_coords_and_addr(s, end, ev);
  951. return STL_LK_AMT_ERROR;
  952. }
  953. }
  954. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  955. const uint8_t *af = NULL;
  956. if (match_ci_word(tok, p, lim, "disabled", &af)) {
  957. ev->subkind = 3;
  958. return STL_LK_DIMM_INVENTORY;
  959. }
  960. if (match_ci_word(tok, p, lim, "fail", &af) ||
  961. match_ci_word(tok, p, lim, "failed", &af) ||
  962. match_ci_word(tok, p, lim, "failure", &af) ||
  963. match_ci_word(tok, p, lim, "error", &af)) {
  964. ev->subkind = 2;
  965. extract_coords_and_addr(s, end, ev);
  966. return STL_LK_TRAINING_ERROR;
  967. }
  968. }
  969. for (const uint8_t *p = tok; p + 3 <= lim; p++) {
  970. const uint8_t *af = NULL;
  971. if (match_ci_word(tok, p, lim, "not", &af) ||
  972. match_ci_word(tok, p, lim, "empty", &af) ||
  973. match_ci_word(tok, p, lim, "absent", &af)) {
  974. ev->subkind = 0;
  975. return STL_LK_DIMM_INVENTORY;
  976. }
  977. if (match_ci_word(tok, p, lim, "present", &af) ||
  978. match_ci_word(tok, p, lim, "ddr5", &af) ||
  979. match_ci_word(tok, p, lim, "enabled", &af) ||
  980. match_ci_word(tok, p, lim, "test", &af)) {
  981. ev->subkind = 4;
  982. return STL_LK_DIMM_INVENTORY;
  983. }
  984. }
  985. continue;
  986. }
  987. ("Test" DIG | "Test:" WS DIG) WS "Addr:" WS {
  988. ev->subkind = 2;
  989. extract_coords_and_addr(s, end, ev);
  990. return STL_LK_MT_ERROR;
  991. }
  992. "Test:" WS DIG {
  993. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  994. const uint8_t *af = NULL;
  995. if (match_ci_kw(p, lim, "expected", &af) ||
  996. match_ci_kw(p, lim, "actual", &af) ||
  997. match_ci_kw(p, lim, "addr", &af)) {
  998. ev->subkind = 2;
  999. extract_coords_and_addr(s, end, ev);
  1000. return STL_LK_MT_ERROR;
  1001. }
  1002. }
  1003. int32_t tnum = 0;
  1004. const uint8_t *nx = NULL;
  1005. if (parse_i32_at(tok + 5, lim, &tnum, &nx)) {
  1006. ev->val0 = tnum;
  1007. if (nx && nx < lim && *nx == '/') {
  1008. int32_t ttot = 0;
  1009. if (parse_i32_at(nx + 1, lim, &ttot, &nx)) ev->val1 = ttot;
  1010. }
  1011. }
  1012. for (const uint8_t *p = YYCURSOR; p < lim; p++) {
  1013. if (*p == '%' && p > buf && p[-1] >= '0' && p[-1] <= '9') {
  1014. const uint8_t *dg = p - 1;
  1015. while (dg > buf && dg[-1] >= '0' && dg[-1] <= '9') dg--;
  1016. int32_t pct = 0;
  1017. if (parse_i32_at(dg, p, &pct, NULL)) ev->val2 = pct;
  1018. break;
  1019. }
  1020. }
  1021. return STL_LK_MT_PROGRESS;
  1022. }
  1023. ("Test Pattern" | "Algo" WS "#" | "AlgoId") {
  1024. extract_coords_and_addr(s, end, ev);
  1025. int32_t aid = -1;
  1026. if (parse_i32_at(YYCURSOR, lim, &aid, NULL) && aid >= 0) ev->val0 = aid;
  1027. for (const uint8_t *p = buf; p + 4 <= lim; p++) {
  1028. const uint8_t *af = NULL;
  1029. if (match_ci_kw(p, lim, "fail", &af)) { ev->subkind = 2; break; }
  1030. if (match_ci_kw(p, lim, "pass", &af)) { ev->subkind = 1; }
  1031. }
  1032. return STL_LK_AMT_PROGRESS;
  1033. }
  1034. ("BankGroup" | "SubRank") {
  1035. ev->subkind = 5;
  1036. extract_coords_and_addr(s, end, ev);
  1037. if (ev->cpu >= 0 || ev->channel >= 0 || ev->bank >= 0) {
  1038. return STL_LK_AMT_ERROR;
  1039. }
  1040. continue;
  1041. }
  1042. "\x00" { break; }
  1043. ANY { continue; }
  1044. */
  1045. }
  1046. return STL_LK_NONE;
  1047. }
  1048. void stl_re2c_parse_line(const uint8_t *line, size_t len, uint32_t tag_mask, StlRe2cEvent *ev) {
  1049. memset(ev, 0, sizeof(*ev));
  1050. ev->cpu = -1;
  1051. ev->channel = -1;
  1052. ev->dimm = -1;
  1053. ev->rank = -1;
  1054. ev->bank = -1;
  1055. if (!line || len == 0) return;
  1056. const uint8_t *s = line;
  1057. const uint8_t *e = line + len;
  1058. trim_ws(&s, &e);
  1059. if (s >= e) return;
  1060. if (tag_mask == 0 && s[0] == '.') {
  1061. int only_dots = 1;
  1062. for (const uint8_t *p = s; p < e; p++) {
  1063. if (*p != '.' && *p != ' ' && *p != '\t') {
  1064. only_dots = 0;
  1065. break;
  1066. }
  1067. }
  1068. if (only_dots) return;
  1069. }
  1070. ev->kind = re2c_scan_token(s, e, ev);
  1071. }
  1072. int stl_re2c_detect_halfline_prompt(const uint8_t *buf, size_t len, StlRe2cEvent *ev) {
  1073. memset(ev, 0, sizeof(*ev));
  1074. ev->cpu = -1;
  1075. ev->channel = -1;
  1076. ev->dimm = -1;
  1077. ev->rank = -1;
  1078. ev->bank = -1;
  1079. if (!buf || len == 0) return 0;
  1080. const uint8_t *s = buf;
  1081. const uint8_t *e = buf + len;
  1082. trim_ws(&s, &e);
  1083. if (s >= e) return 0;
  1084. uint32_t k = re2c_scan_token(s, e, ev);
  1085. if (k == STL_LK_ICT_PROMPT || k == STL_LK_ICT_ENTER_HINT ||
  1086. k == STL_LK_AMT_PROMPT || k == STL_LK_UEFI_PROMPT_EFI ||
  1087. k == STL_LK_UEFI_PROMPT_ROOT) {
  1088. ev->kind = k;
  1089. return 1;
  1090. }
  1091. size_t tlen = (size_t)(e - s);
  1092. if (tlen >= 4 && memcmp(e - 4, "UIP>", 4) == 0) {
  1093. ev->kind = STL_LK_ICT_PROMPT;
  1094. return 1;
  1095. }
  1096. if (tlen >= 26 && memcmp(e - 26, "Please input your command:", 26) == 0) {
  1097. ev->kind = STL_LK_ICT_PROMPT;
  1098. extract_leading_bracket_cpu(s, e, ev);
  1099. return 1;
  1100. }
  1101. if (tlen >= 25 && memcmp(e - 25, "Please input your command", 25) == 0) {
  1102. ev->kind = STL_LK_ICT_PROMPT;
  1103. extract_leading_bracket_cpu(s, e, ev);
  1104. return 1;
  1105. }
  1106. if (tlen >= 7 && memcmp(e - 7, "[AMT #]", 7) == 0) {
  1107. ev->kind = STL_LK_AMT_PROMPT;
  1108. ev->fw_family = 1;
  1109. if (tlen >= 10 && e[-10] == '[' && (e[-9] == '0' || e[-9] == '1') && e[-8] == ']') {
  1110. ev->cpu = (int8_t)(e[-9] - '0');
  1111. }
  1112. return 1;
  1113. }
  1114. if (tlen >= 12 && memcmp(e - 12, "[AMEMDIAG #]", 12) == 0) {
  1115. ev->kind = STL_LK_AMT_PROMPT;
  1116. ev->fw_family = 2;
  1117. if (tlen >= 15 && e[-15] == '[' && (e[-14] == '0' || e[-14] == '1') && e[-13] == ']') {
  1118. ev->cpu = (int8_t)(e[-14] - '0');
  1119. }
  1120. return 1;
  1121. }
  1122. if (tlen >= 6 && memcmp(e - 6, "Shell>", 6) == 0) {
  1123. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1124. ev->fs_index = 255;
  1125. return 1;
  1126. }
  1127. /* Check trailing FSx:\EFI\> or FSx:\> */
  1128. if (tlen >= 6 && e[-1] == '>') {
  1129. for (size_t i = (tlen > 24 ? tlen - 24 : 0); i + 4 < tlen; i++) {
  1130. if (s[i] == 'F' && s[i+1] == 'S' && s[i+2] >= '0' && s[i+2] <= '9' && s[i+3] == ':') {
  1131. ev->fs_index = (uint8_t)(s[i+2] - '0');
  1132. for (size_t j = i + 4; j + 3 <= tlen; j++) {
  1133. if ((s[j] == 'E' || s[j] == 'e') && (s[j+1] == 'F' || s[j+1] == 'f') &&
  1134. (s[j+2] == 'I' || s[j+2] == 'i')) {
  1135. ev->kind = STL_LK_UEFI_PROMPT_EFI;
  1136. return 1;
  1137. }
  1138. }
  1139. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1140. return 1;
  1141. }
  1142. }
  1143. }
  1144. return 0;
  1145. }