parser_re2c.re 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  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. int has_ncd = extract_ncd_token(s, end, ev);
  187. int has_explicit_dimm_coord = has_ncd;
  188. /* Check MemTest86 "CPU<0|1>_DIMM_<A..L>", "P<0|1>_DIMM_<A..L>[0|1]", "(P0,C3,S0,R0)", "Channel/Slot: N0-3-0", or "(Chan,Slot,Rank,Bank,Row,Col): (3,0,0,12,...)" */
  189. for (const uint8_t *p = s; p + 6 <= end; p++) {
  190. if (!has_ncd && p + 11 <= end &&
  191. (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
  192. (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_'))) &&
  193. ascii_lower(p[0]) == 'c' && ascii_lower(p[1]) == 'p' && ascii_lower(p[2]) == 'u' &&
  194. (p[3] == '0' || p[3] == '1') && p[4] == '_' &&
  195. ascii_lower(p[5]) == 'd' && ascii_lower(p[6]) == 'i' && ascii_lower(p[7]) == 'm' && ascii_lower(p[8]) == 'm' &&
  196. p[9] == '_') {
  197. uint8_t ltr = p[10];
  198. uint8_t ul = (ltr >= 'a' && ltr <= 'z') ? (uint8_t)(ltr - 32) : ltr;
  199. int ok_after = (p + 11 == end) ||
  200. (!((p[11] >= 'a' && p[11] <= 'z') || (p[11] >= 'A' && p[11] <= 'Z') ||
  201. (p[11] >= '0' && p[11] <= '9') || p[11] == '_'));
  202. if (ok_after && ul >= 'A' && ul <= 'L') {
  203. ev->cpu = (int8_t)(p[3] - '0');
  204. ev->channel = (int8_t)(ul - 'A');
  205. if (ev->dimm < 0) ev->dimm = 0;
  206. has_explicit_dimm_coord = 1;
  207. }
  208. }
  209. if (!has_ncd && p + 9 <= end &&
  210. (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
  211. (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_'))) &&
  212. (p[0] == 'P' || p[0] == 'p') && (p[1] == '0' || p[1] == '1') && p[2] == '_' &&
  213. ascii_lower(p[3]) == 'd' && ascii_lower(p[4]) == 'i' && ascii_lower(p[5]) == 'm' && ascii_lower(p[6]) == 'm' &&
  214. p[7] == '_') {
  215. uint8_t ltr = p[8];
  216. uint8_t ul = (ltr >= 'a' && ltr <= 'z') ? (uint8_t)(ltr - 32) : ltr;
  217. if (ul >= 'A' && ul <= 'L') {
  218. int ok_after = (p + 9 == end) ||
  219. (p[9] == '0' || p[9] == '1') ||
  220. (!((p[9] >= 'a' && p[9] <= 'z') || (p[9] >= 'A' && p[9] <= 'Z') ||
  221. (p[9] >= '0' && p[9] <= '9') || p[9] == '_'));
  222. if (ok_after) {
  223. ev->cpu = (int8_t)(p[1] - '0');
  224. ev->channel = (int8_t)(ul - 'A');
  225. if (p + 9 < end && (p[9] == '0' || p[9] == '1')) {
  226. ev->dimm = (int8_t)(p[9] - '0');
  227. } else if (ev->dimm < 0) {
  228. ev->dimm = 0;
  229. }
  230. has_explicit_dimm_coord = 1;
  231. }
  232. }
  233. }
  234. if (!has_ncd && (p[0] == 'N' || p[0] == 'n') && (p[1] == '0' || p[1] == '1') &&
  235. p[2] == '-' && p[3] >= '0' && p[3] <= '9') {
  236. int32_t ch = -1, sl = -1;
  237. const uint8_t *nx = p + 3;
  238. if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
  239. ev->cpu = (int8_t)(p[1] - '0');
  240. ev->channel = (int8_t)ch;
  241. if (nx < end && *nx == '-') {
  242. if (parse_i32_at(nx + 1, end, &sl, &nx) && sl >= 0 && sl <= 1) {
  243. ev->dimm = (int8_t)sl;
  244. }
  245. }
  246. has_explicit_dimm_coord = 1;
  247. }
  248. }
  249. if (p + 8 > end) continue;
  250. if (!has_ncd && p[0] == '(' && (p[1] == 'P' || p[1] == 'p') && (p[2] == '0' || p[2] == '1') &&
  251. p[3] == ',' && (p[4] == 'C' || p[4] == 'c')) {
  252. int32_t ch = -1, sl = -1;
  253. const uint8_t *nx = p + 5;
  254. if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
  255. ev->cpu = (int8_t)(p[2] - '0');
  256. ev->channel = (int8_t)ch;
  257. if (nx + 2 < end && nx[0] == ',' && (nx[1] == 'S' || nx[1] == 's')) {
  258. if (parse_i32_at(nx + 2, end, &sl, &nx) && sl >= 0 && sl <= 1) {
  259. ev->dimm = (int8_t)sl;
  260. }
  261. }
  262. has_explicit_dimm_coord = 1;
  263. }
  264. }
  265. size_t tup_skip = 0;
  266. if (p + 28 <= end && memcmp(p, "(Channel,Slot,Rank,Bank,Row,", 28) == 0) {
  267. tup_skip = 28;
  268. } else if (p + 25 <= end && memcmp(p, "(Chan,Slot,Rank,Bank,Row,", 25) == 0) {
  269. tup_skip = 25;
  270. } else if (p + 16 <= end && memcmp(p, "(Ch,Sl,Rk,Bk,Rw,", 16) == 0) {
  271. tup_skip = 16;
  272. }
  273. if (tup_skip > 0) {
  274. const uint8_t *rp = memchr(p + tup_skip, ')', (size_t)(end - (p + tup_skip)));
  275. const uint8_t *nx = rp ? (rp + 1) : (p + tup_skip);
  276. while (nx < end && (*nx == ':' || *nx == '=' || *nx == ' ' || *nx == '\t' || *nx == '(')) {
  277. nx++;
  278. }
  279. int32_t c_ch = -1, c_sl = -1, c_rk = -1, c_bk = -1;
  280. if (parse_i32_at(nx, end, &c_ch, &nx) && nx < end && *nx == ',' &&
  281. parse_i32_at(nx + 1, end, &c_sl, &nx) && nx < end && *nx == ',' &&
  282. parse_i32_at(nx + 1, end, &c_rk, &nx) && nx < end && *nx == ',' &&
  283. parse_i32_at(nx + 1, end, &c_bk, &nx)) {
  284. if (!has_explicit_dimm_coord) {
  285. if (c_ch >= 12 && c_ch <= 23 && ev->cpu < 0) {
  286. ev->cpu = 1;
  287. ev->channel = (int8_t)(c_ch - 12);
  288. } else if (c_ch >= 0 && c_ch <= 11) {
  289. ev->channel = (int8_t)c_ch;
  290. }
  291. if (c_sl >= 0 && c_sl <= 1) ev->dimm = (int8_t)c_sl;
  292. }
  293. if (c_rk >= 0 && c_rk <= 3 && ev->rank < 0) ev->rank = (int8_t)c_rk;
  294. if (c_bk >= 0 && c_bk < 32 && ev->bank < 0) ev->bank = (int8_t)c_bk;
  295. }
  296. }
  297. if (!has_explicit_dimm_coord &&
  298. (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
  299. (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_')))) {
  300. static const char *const cs_prefixes[] = {
  301. "channel/slot:",
  302. "channel-slot:",
  303. "chan/slot:",
  304. "chan-slot:",
  305. "ch/sl:",
  306. "ch-sl:"
  307. };
  308. const uint8_t *cs_nx = NULL;
  309. for (size_t k = 0; k < sizeof(cs_prefixes) / sizeof(cs_prefixes[0]); k++) {
  310. size_t plen = strlen(cs_prefixes[k]);
  311. if (p + plen <= end) {
  312. int eq = 1;
  313. for (size_t j = 0; j < plen; j++) {
  314. if (ascii_lower(p[j]) != (uint8_t)cs_prefixes[k][j]) {
  315. eq = 0;
  316. break;
  317. }
  318. }
  319. if (eq) {
  320. cs_nx = p + plen;
  321. break;
  322. }
  323. }
  324. }
  325. if (cs_nx) {
  326. while (cs_nx < end && (*cs_nx == ' ' || *cs_nx == '\t')) cs_nx++;
  327. if (cs_nx < end && *cs_nx >= '0' && *cs_nx <= '9') {
  328. int32_t c_ch = -1, c_sl = -1;
  329. if (parse_i32_at(cs_nx, end, &c_ch, &cs_nx) && c_ch >= 0 && c_ch <= 23) {
  330. if (c_ch >= 12 && ev->cpu < 0) {
  331. ev->cpu = 1;
  332. ev->channel = (int8_t)(c_ch - 12);
  333. } else if (c_ch <= 11) {
  334. ev->channel = (int8_t)c_ch;
  335. }
  336. if (cs_nx < end && (*cs_nx == '/' || *cs_nx == '-' || *cs_nx == ',') &&
  337. parse_i32_at(cs_nx + 1, end, &c_sl, &cs_nx) && c_sl >= 0 && c_sl <= 1) {
  338. ev->dimm = (int8_t)c_sl;
  339. }
  340. has_explicit_dimm_coord = 1;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. int bg = -1;
  347. int ba = -1;
  348. int direct_bank = -1;
  349. int explicit_socket = -1;
  350. int fallback_cpu = -1;
  351. int ctrl_mc = -1;
  352. int raw_chid = -1;
  353. /* Check for 120.efi "/GNR ... Flag=<hex> ... Socket=<hex> ... MC=<hex> Channel=<hex> ..." (hex fields) */
  354. const uint8_t *gnr_pos = NULL;
  355. for (const uint8_t *p = s; p + 5 <= end; p++) {
  356. if (p[0] == '/' && p[1] == 'G' && p[2] == 'N' && p[3] == 'R' && (p[4] == ' ' || p[4] == '\t')) {
  357. gnr_pos = p;
  358. break;
  359. }
  360. }
  361. if (gnr_pos) {
  362. int gnr_mc = -1, gnr_nmmc = -1, gnr_ch = -1, gnr_nmch = -1;
  363. for (const uint8_t *p = gnr_pos + 5; p < end; p++) {
  364. if (p > gnr_pos && ((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
  365. (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_')) {
  366. continue;
  367. }
  368. const uint8_t *after = NULL;
  369. uint64_t hv = 0;
  370. if (!has_explicit_dimm_coord && match_ci_kw(p, end, "socket", &after)) {
  371. if (parse_hex64_at(after, end, &hv) && hv <= 1) explicit_socket = (int)hv;
  372. } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "mc", &after)) {
  373. if (parse_hex64_at(after, end, &hv) && hv <= 11) gnr_mc = (int)hv;
  374. } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "nmmc", &after)) {
  375. if (parse_hex64_at(after, end, &hv) && hv <= 11) gnr_nmmc = (int)hv;
  376. } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "channel", &after)) {
  377. if (parse_hex64_at(after, end, &hv) && hv <= 23) gnr_ch = (int)hv;
  378. } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "nmchannel", &after)) {
  379. if (parse_hex64_at(after, end, &hv) && hv <= 23) gnr_nmch = (int)hv;
  380. } else if (match_ci_kw(p, end, "dimm", &after) || match_ci_kw(p, end, "nmdimm", &after)) {
  381. if (ev->dimm < 0 && parse_hex64_at(after, end, &hv) && hv <= 1) ev->dimm = (int8_t)hv;
  382. } else if (match_ci_kw(p, end, "rank", &after) || match_ci_kw(p, end, "cs", &after)) {
  383. if (ev->rank < 0 && parse_hex64_at(after, end, &hv) && hv <= 3) ev->rank = (int8_t)hv;
  384. } else if (match_ci_kw(p, end, "bg", &after)) {
  385. if (parse_hex64_at(after, end, &hv) && hv <= 7) bg = (int)hv;
  386. } else if (match_ci_kw(p, end, "bank", &after)) {
  387. if (parse_hex64_at(after, end, &hv)) {
  388. if (hv <= 3) ba = (int)hv;
  389. else if (hv < 32) direct_bank = (int)hv;
  390. }
  391. }
  392. }
  393. if (!has_explicit_dimm_coord) {
  394. int eff_mc = (gnr_mc >= 0) ? gnr_mc : gnr_nmmc;
  395. int eff_ch = (gnr_ch >= 0) ? gnr_ch : gnr_nmch;
  396. /* Granite Rapids-AP has 12 M2M/MCs (MC 0..11) x 1 sub-MC channel (Channel 0) */
  397. if (eff_mc >= 0 && eff_mc <= 11 && eff_ch <= 0) {
  398. ev->channel = (int8_t)eff_mc;
  399. } else if (eff_mc == 0 && eff_ch >= 0 && eff_ch <= 11) {
  400. ev->channel = (int8_t)eff_ch;
  401. } else if (eff_mc > 0 && eff_ch > 0 && (eff_mc * 2 + eff_ch) <= 11) {
  402. ev->channel = (int8_t)(eff_mc * 2 + eff_ch);
  403. } else if (eff_ch >= 0 && eff_ch <= 11) {
  404. ev->channel = (int8_t)eff_ch;
  405. }
  406. }
  407. }
  408. const uint8_t *kw_scan_end = gnr_pos ? gnr_pos : end;
  409. for (const uint8_t *p = s; p < kw_scan_end; p++) {
  410. if (p > s) {
  411. uint8_t prev = p[-1];
  412. if ((prev >= 'a' && prev <= 'z') || (prev >= 'A' && prev <= 'Z') ||
  413. (prev >= '0' && prev <= '9') || prev == '_') {
  414. continue;
  415. }
  416. }
  417. const uint8_t *after = NULL;
  418. int32_t v = 0;
  419. if (!has_explicit_dimm_coord &&
  420. (match_ci_kw(p, kw_scan_end, "socket", &after) || match_ci_kw(p, kw_scan_end, "sock", &after) ||
  421. match_ci_kw(p, kw_scan_end, "scktid", &after) || match_ci_kw(p, kw_scan_end, "node", &after))) {
  422. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 1) {
  423. explicit_socket = (int)v;
  424. }
  425. } else if (!has_explicit_dimm_coord && match_ci_kw(p, kw_scan_end, "cpu", &after)) {
  426. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 1 && fallback_cpu < 0) {
  427. fallback_cpu = (int)v;
  428. }
  429. } else if (!has_explicit_dimm_coord &&
  430. (match_ci_kw(p, kw_scan_end, "ctrl", &after) || match_ci_kw(p, kw_scan_end, "mc", &after))) {
  431. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 11) {
  432. ctrl_mc = (int)v;
  433. }
  434. } else if (!has_explicit_dimm_coord &&
  435. (match_ci_kw(p, kw_scan_end, "channel", &after) || match_ci_kw(p, kw_scan_end, "ch", &after) ||
  436. match_ci_kw(p, kw_scan_end, "chan", &after) ||
  437. (ev->channel < 0 && match_ci_kw(p, kw_scan_end, "chid", &after)))) {
  438. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 23) {
  439. raw_chid = (int)v;
  440. if (v >= 12 && explicit_socket < 0) {
  441. explicit_socket = 1;
  442. ev->channel = (int8_t)(v - 12);
  443. } else if (v <= 11) {
  444. ev->channel = (int8_t)v;
  445. }
  446. }
  447. } else if (match_ci_kw(p, kw_scan_end, "dimm", &after) || match_ci_kw(p, kw_scan_end, "dimmslot", &after) ||
  448. match_ci_kw(p, kw_scan_end, "dimmsl", &after) ||
  449. match_ci_kw(p, kw_scan_end, "slot", &after) || match_ci_kw(p, kw_scan_end, "sl", &after)) {
  450. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 23) {
  451. if (v <= 1) {
  452. if (ev->dimm < 0) ev->dimm = (int8_t)v;
  453. } else if (!has_explicit_dimm_coord && ev->channel < 0) {
  454. explicit_socket = (int)(v / 12);
  455. ev->channel = (int8_t)(v % 12);
  456. ev->dimm = 0;
  457. }
  458. }
  459. } else if (match_ci_kw(p, kw_scan_end, "rank", &after) || match_ci_kw(p, kw_scan_end, "dimmrank", &after) ||
  460. match_ci_kw(p, kw_scan_end, "dimmrk", &after)) {
  461. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 3) {
  462. ev->rank = (int8_t)v;
  463. }
  464. } else if (match_ci_kw(p, kw_scan_end, "bankgroup", &after) || match_ci_kw(p, kw_scan_end, "bg", &after)) {
  465. if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 7) {
  466. bg = (int)v;
  467. }
  468. } else if (match_ci_kw(p, kw_scan_end, "bank", &after) || match_ci_kw(p, kw_scan_end, "ba", &after)) {
  469. if (parse_i32_at(after, kw_scan_end, &v, NULL)) {
  470. if ((after - p) == 2 && v >= 0 && v <= 3) {
  471. ba = (int)v;
  472. } else if (v >= 0 && v < 32) {
  473. direct_bank = (int)v;
  474. }
  475. }
  476. } else if (match_ci_kw(p, kw_scan_end, "addr", &after) || match_ci_kw(p, kw_scan_end, "address", &after) ||
  477. match_ci_kw(p, kw_scan_end, "checkpoint", &after)) {
  478. uint64_t a = 0;
  479. if (parse_hex64_at(after, kw_scan_end, &a)) {
  480. ev->addr = a;
  481. }
  482. }
  483. }
  484. if (!has_explicit_dimm_coord) {
  485. if (!gnr_pos && ctrl_mc > 0 && ctrl_mc <= 11 && raw_chid == 0) {
  486. ev->channel = (int8_t)ctrl_mc;
  487. }
  488. if (explicit_socket >= 0 && explicit_socket <= 1) {
  489. ev->cpu = (int8_t)explicit_socket;
  490. } else if (!gnr_pos && fallback_cpu >= 0 && fallback_cpu <= 1 && ev->cpu < 0) {
  491. ev->cpu = (int8_t)fallback_cpu;
  492. }
  493. }
  494. if (bg >= 0 && ba >= 0) {
  495. int combined = bg * 4 + ba;
  496. if (combined >= 0 && combined < 32) ev->bank = (int8_t)combined;
  497. } else if (direct_bank >= 0 && direct_bank < 32 && ev->bank < 0) {
  498. ev->bank = (int8_t)direct_bank;
  499. }
  500. }
  501. static void trim_ws(const uint8_t **ps, const uint8_t **pe) {
  502. const uint8_t *s = *ps;
  503. const uint8_t *e = *pe;
  504. while (s < e && (*s == ' ' || *s == '\t')) s++;
  505. while (e > s && (e[-1] == ' ' || e[-1] == '\t' || e[-1] == '\r' || e[-1] == '\n')) e--;
  506. *ps = s;
  507. *pe = e;
  508. }
  509. /*!re2c
  510. re2c:define:YYCTYPE = uint8_t;
  511. re2c:yyfill:enable = 0;
  512. re2c:flags:tags = 0;
  513. re2c:flags:case-insensitive = 0;
  514. WS = [ \t]*;
  515. ANY = [\x00-\xff];
  516. DIG = [0-9]+;
  517. */
  518. static uint32_t re2c_scan_token(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
  519. uint8_t buf[1025];
  520. size_t n = (size_t)(end - s);
  521. if (n > 1024) n = 1024;
  522. memcpy(buf, s, n);
  523. buf[n] = 0;
  524. extract_leading_bracket_cpu(buf, buf + n, ev);
  525. const uint8_t *YYCURSOR = buf;
  526. const uint8_t *YYMARKER = buf;
  527. const uint8_t *lim = buf + n;
  528. /* Step 1: Anchored prompt & full-line patterns */
  529. /*!re2c
  530. WS "UIP>" WS "\x00" {
  531. return STL_LK_ICT_PROMPT;
  532. }
  533. WS "[" [01] "][" ("Hovsee" | "CxmtDdrTest") "]Please input your command" ":"? WS "\x00" {
  534. ev->cpu = (int8_t)(buf[1] == '1' ? 1 : 0);
  535. for (size_t i = 0; i + 6 <= n; i++) {
  536. if (memcmp(buf + i, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
  537. if (i + 11 <= n && memcmp(buf + i, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
  538. }
  539. return STL_LK_ICT_PROMPT;
  540. }
  541. WS (("[" [01] "]" WS) | ("CPU" [01] WS ":"? WS))? "[" ("CPU" [01] WS)? ("AMT" | "AMEMDIAG") WS "#" WS "]" WS "\x00" {
  542. for (size_t i = 0; i + 3 <= n; i++) {
  543. if (buf[i] == '[' && (buf[i+1] == '0' || buf[i+1] == '1') && buf[i+2] == ']') {
  544. ev->cpu = (int8_t)(buf[i+1] - '0');
  545. }
  546. if (i + 4 <= n && buf[i] == 'C' && buf[i+1] == 'P' && buf[i+2] == 'U' && (buf[i+3] == '0' || buf[i+3] == '1')) {
  547. ev->cpu = (int8_t)(buf[i+3] - '0');
  548. }
  549. if (i + 8 <= n && memcmp(buf + i, "AMEMDIAG", 8) == 0) ev->fw_family = 2;
  550. else if (memcmp(buf + i, "AMT", 3) == 0 && ev->fw_family == 0) ev->fw_family = 1;
  551. }
  552. return STL_LK_AMT_PROMPT;
  553. }
  554. WS "FS" [0-9] ":\\" ("EFI" | "efi") ("\\" [^\x00\r\n<>]*)? ">" WS "\x00" |
  555. WS "FS" [0-9] ":\\" ("EFI" | "efi") ">" WS "\x00" {
  556. for (size_t i = 0; i + 2 < n; i++) {
  557. if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
  558. ev->fs_index = (uint8_t)(buf[i+2] - '0');
  559. break;
  560. }
  561. }
  562. return STL_LK_UEFI_PROMPT_EFI;
  563. }
  564. WS "FS" [0-9] ":" "\\"? ">" WS "\x00" {
  565. for (size_t i = 0; i + 2 < n; i++) {
  566. if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
  567. ev->fs_index = (uint8_t)(buf[i+2] - '0');
  568. break;
  569. }
  570. }
  571. return STL_LK_UEFI_PROMPT_ROOT;
  572. }
  573. WS "Shell>" WS "\x00" {
  574. ev->fs_index = 255;
  575. return STL_LK_UEFI_PROMPT_ROOT;
  576. }
  577. * { goto scan_anywhere; }
  578. */
  579. scan_anywhere:
  580. YYCURSOR = buf;
  581. while (YYCURSOR < lim) {
  582. const uint8_t *tok = YYCURSOR;
  583. /*!re2c
  584. "[" ("SYS_" | "HS_") "BIOS]Version:" {
  585. if (tok[1] == 'H') ev->fw_family = 1;
  586. return STL_LK_BIOS_BOOT;
  587. }
  588. "[BIOS][Vref]" | "[CHIPID]" | "[SPD_MR]" | "[SPD_CRC]" {
  589. return STL_LK_NONE;
  590. }
  591. "Welcome to Hovsee" | "Hovsee inc. IMC Config Tool" {
  592. ev->fw_family = 1;
  593. return STL_LK_ICT_BANNER_HOVSEE;
  594. }
  595. "Welcome to CxmtDdrTest" | "CxmtDdrTest IMC Config Tool" {
  596. ev->fw_family = 2;
  597. return STL_LK_ICT_BANNER_CXMT;
  598. }
  599. "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "1" {
  600. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  601. return STL_LK_ICT_START_STAGE1;
  602. }
  603. "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "2" {
  604. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  605. return STL_LK_ICT_START_STAGE2;
  606. }
  607. "[Hovsee]Stage2 UIP" {
  608. ev->fw_family = 1;
  609. return STL_LK_ICT_START_STAGE2;
  610. }
  611. "[CxmtDdrTest]Stage2 UIP" {
  612. ev->fw_family = 2;
  613. return STL_LK_ICT_START_STAGE2;
  614. }
  615. "[Hovsee]Start UIP" {
  616. ev->fw_family = 1;
  617. return STL_LK_ICT_START_STAGE1;
  618. }
  619. "[CxmtDdrTest]Start UIP" {
  620. ev->fw_family = 2;
  621. return STL_LK_ICT_START_STAGE1;
  622. }
  623. "Please press ENTER to start UIP" {
  624. return STL_LK_ICT_ENTER_HINT;
  625. }
  626. "[" ("Hovsee" | "CxmtDdrTest") "]Please input your command" {
  627. ev->fw_family = (tok[1] == 'H') ? 1 : 2;
  628. /* Only prompt if no trailing user command echo on same line */
  629. const uint8_t *colon = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
  630. if (!colon || colon + 1 >= lim) return STL_LK_ICT_PROMPT;
  631. continue;
  632. }
  633. "[Hovsee]Exit UIP" | "[CxmtDdrTest]Exit UIP" |
  634. "[Hovsee]Exit Uip ddr test" | "[CxmtDdrTest]Exit Uip ddr test" |
  635. "[Hovsee]Exit Hovsee UIP" | "[CxmtDdrTest]Exit CxmtDdrTest UIP" |
  636. "[Hovsee]Exit ICT ddr test" | "[CxmtDdrTest]Exit ICT ddr test" |
  637. "No command input or timeout, so go on training" |
  638. "User input command is exit" {
  639. if (tok[0] == '[' && tok[1] == 'H') ev->fw_family = 1;
  640. if (tok[0] == '[' && tok[1] == 'C') ev->fw_family = 2;
  641. return STL_LK_ICT_EXIT;
  642. }
  643. "is not recognized as an internal or external command" {
  644. ev->subkind = 3; /* UEFI shell missing binary error */
  645. return STL_LK_MT_FAIL_COMPLETE;
  646. }
  647. "AdvancedMemTestWorker" | "GNR AP Gpio" | "SetVMGpioMemTest" | "DdrMemTest()" {
  648. for (const uint8_t *p = buf; p + 6 <= lim; p++) {
  649. if (memcmp(p, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
  650. if (p + 11 <= lim && memcmp(p, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
  651. }
  652. return STL_LK_NONE;
  653. }
  654. "[HS_MRC]" | "[HD_MRC]" |
  655. "[HS_StartMemTrain]" | "[HD_StartMemTrain]" |
  656. "[Hovsee]Socket " [01] " RcdQcaTraining" {
  657. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  658. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'o') ev->fw_family = 1;
  659. return STL_LK_MRC_START;
  660. }
  661. "STOP_MRC_RUN" | "MRC Done" | "Memory Training Complete" |
  662. "[HS_EndMemTrain]" | "[HD_EndMemTrain]" {
  663. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  664. return STL_LK_MRC_DONE;
  665. }
  666. "0x4F : DXE IPL Start" | "0x60 : DXE Core Started" |
  667. "0x90 : BDS Started" | "0x91 : Connecting Drivers" {
  668. ev->subkind = 4; /* POST / DXE milestone */
  669. return STL_LK_MRC_DONE;
  670. }
  671. ("AMT" | "AMEMDIAG") WS "Test Start" {
  672. ev->fw_family = (tok[0] == 'A' && tok[1] == 'M' && tok[2] == 'E') ? 2 : 1;
  673. ev->subkind = 3; /* AMT start */
  674. return STL_LK_AMT_PROGRESS;
  675. }
  676. "[" ("HS_" | "") "BIOS][Training][ScktId:" WS [01] "]" {
  677. if (tok[1] == 'H') ev->fw_family = 1;
  678. extract_coords_and_addr(s, end, ev);
  679. int is_pipe_sync_sbsp = 0;
  680. for (const uint8_t *p = YYCURSOR; p + 20 <= lim; p++) {
  681. if (memcmp(p, "Pipe Sync SBSP Status", 21) == 0) {
  682. is_pipe_sync_sbsp = 1;
  683. break;
  684. }
  685. }
  686. /* Check if Rank Margin Tool or MemTest or FAILED (excluding benign SNC/Pipe Sync SBSP Status reset notice) */
  687. for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
  688. if (p + 16 <= lim && memcmp(p, "Rank Margin Tool", 16) == 0) {
  689. return STL_LK_RMT_STOP;
  690. }
  691. if (!is_pipe_sync_sbsp && memcmp(p, "FAILED", 6) == 0) {
  692. ev->subkind = 2;
  693. return STL_LK_TRAINING_ERROR;
  694. }
  695. }
  696. return STL_LK_MRC_START;
  697. }
  698. "START_RMT_N" [01] {
  699. ev->cpu = (int8_t)(tok[11] - '0');
  700. return STL_LK_RMT_START;
  701. }
  702. "START_RMT" | "Starting RMT test v" | "Rank Margin Tool -- Started" |
  703. "[HS_StartRmt]" | "[HD_StartRmt]" {
  704. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  705. extract_coords_and_addr(s, end, ev);
  706. return STL_LK_RMT_START;
  707. }
  708. "STOP_RMT_N" [01] {
  709. ev->cpu = (int8_t)(tok[10] - '0');
  710. return STL_LK_RMT_STOP;
  711. }
  712. "STOP_RMT" | "[HS_StopRmt]" | "[HD_StopRmt]" | "RMT test v" {
  713. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') {
  714. ev->fw_family = 1;
  715. return STL_LK_RMT_STOP;
  716. }
  717. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'D') {
  718. return STL_LK_RMT_STOP;
  719. }
  720. for (const uint8_t *p = tok; p + 8 <= lim; p++) {
  721. if (memcmp(p, "complete", 8) == 0) {
  722. return STL_LK_RMT_STOP;
  723. }
  724. }
  725. if (tok[0] == 'S') return STL_LK_RMT_STOP;
  726. continue;
  727. }
  728. "[" ("HS" | "HD") "_" ("RMTSensor" | "Sensor") "]" {
  729. if (tok[2] == 'S') ev->fw_family = 1;
  730. extract_ncd_token(s, end, ev);
  731. const uint8_t *cl = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
  732. if (cl) {
  733. int32_t deg = 0;
  734. const uint8_t *nx = NULL;
  735. if (parse_i32_at(cl + 1, lim, &deg, &nx)) {
  736. int32_t tenths = 0;
  737. if (nx && nx + 1 < lim && *nx == '.' && nx[1] >= '0' && nx[1] <= '9') {
  738. tenths = nx[1] - '0';
  739. }
  740. ev->val3 = deg * 10 + (deg >= 0 ? tenths : -tenths);
  741. }
  742. }
  743. return STL_LK_INLINE_TEMP;
  744. }
  745. "[" ("HS" | "HD") "_NODIMM]" {
  746. if (tok[2] == 'S') ev->fw_family = 1;
  747. extract_coords_and_addr(s, end, ev);
  748. ev->subkind = 0; /* explicitly absent */
  749. ev->val1 = 1; /* PEI DRAM inventory marker */
  750. return STL_LK_DIMM_INVENTORY;
  751. }
  752. "[" ("HS" | "HD") "_DRAM]" {
  753. if (tok[2] == 'S') ev->fw_family = 1;
  754. extract_coords_and_addr(s, end, ev);
  755. /* Check Size:0 or absent/empty/not-installed -> absent, else present */
  756. ev->subkind = 4;
  757. ev->val1 = 1; /* PEI DRAM inventory marker */
  758. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  759. const uint8_t *af = NULL;
  760. if (match_ci_word(YYCURSOR, p, lim, "size", &af)) {
  761. int32_t sz = 0;
  762. if (parse_i32_at(af, lim, &sz, NULL)) {
  763. ev->subkind = (sz > 0) ? 4 : 0;
  764. ev->val0 = sz;
  765. break;
  766. }
  767. }
  768. if (match_ci_word(YYCURSOR, p, lim, "not installed", &af) ||
  769. match_ci_word(YYCURSOR, p, lim, "not present", &af) ||
  770. match_ci_word(YYCURSOR, p, lim, "no dimm", &af) ||
  771. match_ci_word(YYCURSOR, p, lim, "absent", &af) ||
  772. match_ci_word(YYCURSOR, p, lim, "empty", &af) ||
  773. match_ci_word(YYCURSOR, p, lim, "unpopulated", &af)) {
  774. ev->subkind = 0;
  775. break;
  776. }
  777. }
  778. return STL_LK_DIMM_INVENTORY;
  779. }
  780. "[" ("HS" | "HD") "_Disable" ("Dimm" | "DIMM") "]" | "DisableDIMM()" | "MapOutDimm()" | "Mapping out DDR" {
  781. extract_coords_and_addr(s, end, ev);
  782. ev->subkind = 3; /* disabled */
  783. return STL_LK_DIMM_INVENTORY;
  784. }
  785. "AMT Version " | "Welcome to Advanced Memory Test" | "GNR-4.3.3" {
  786. ev->fw_family = 1;
  787. return STL_LK_AMT_BANNER;
  788. }
  789. "AMEMDIAG Version " | "Welcome to Advanced Memory Diagnostic" | "GNR-4.3.0" {
  790. ev->fw_family = 2;
  791. return STL_LK_AMT_BANNER;
  792. }
  793. ("AMT" | "AMEMDIAG") WS "Test Algo Count:" {
  794. int32_t cnt = 0;
  795. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  796. ev->val1 = cnt; /* algorithm count */
  797. }
  798. ev->subkind = 0;
  799. return STL_LK_AMT_SUMMARY;
  800. }
  801. ("AMT" | "AMEMDIAG") WS "Test Result Summary:" |
  802. ("AMT" | "AMEMDIAG") WS "Test Result:" |
  803. "AMT Test PASS" | "AMEMDIAG Test PASS" | "All Test PASS" |
  804. "AMT Test FAIL" | "AMEMDIAG Test FAIL" | "All Test FAIL" {
  805. extract_coords_and_addr(s, end, ev);
  806. /* Determine scope: summary vs per-socket */
  807. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  808. const uint8_t *af = NULL;
  809. if (match_ci_kw(p, lim, "summary", &af)) {
  810. ev->val2 = 1; /* scope = summary */
  811. }
  812. if (match_ci_kw(p, lim, "fail", &af) || match_ci_kw(p, lim, "block", &af)) {
  813. ev->subkind = 2;
  814. } else if (match_ci_kw(p, lim, "pass", &af) && ev->subkind != 2) {
  815. ev->subkind = 1;
  816. }
  817. }
  818. return STL_LK_AMT_SUMMARY;
  819. }
  820. "Total Error Count" {
  821. int32_t cnt = 0;
  822. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  823. ev->val0 = cnt;
  824. ev->subkind = (cnt > 0) ? 2 : 1;
  825. }
  826. extract_coords_and_addr(s, end, ev);
  827. return STL_LK_AMT_SUMMARY;
  828. }
  829. "[" ("AMT" | "AMEMDIAG") WS DIG "/" DIG WS DIG "/" DIG WS DIG "/" DIG "]" {
  830. /* e.g. [0][AMT 1/1 1/1 3/24] Algo ... */
  831. ev->fw_family = (tok[1] == 'A' && tok[2] == 'M' && tok[3] == 'E') ? 2 : 1;
  832. const uint8_t *p = tok + 4;
  833. while (p < YYCURSOR && (*p < '0' || *p > '9')) p++;
  834. int32_t r1=0, r2=0, p1=0, p2=0, a1=0, a2=0;
  835. if (parse_i32_at(p, YYCURSOR, &r1, &p) && p < YYCURSOR && *p == '/' &&
  836. parse_i32_at(p+1, YYCURSOR, &r2, &p) &&
  837. parse_i32_at(p, YYCURSOR, &p1, &p) && p < YYCURSOR && *p == '/' &&
  838. parse_i32_at(p+1, YYCURSOR, &p2, &p) &&
  839. parse_i32_at(p, YYCURSOR, &a1, &p) && p < YYCURSOR && *p == '/' &&
  840. parse_i32_at(p+1, YYCURSOR, &a2, &p)) {
  841. ev->val0 = a1; /* algorithm_index */
  842. ev->val1 = a2; /* algorithm_count */
  843. if (a2 > 0) ev->val2 = (a1 * 100) / a2;
  844. }
  845. return STL_LK_AMT_PROGRESS;
  846. }
  847. "Failure detected - Advanced Memtest" | "Failure detected - PPR Memtest" |
  848. "Data Compare Error" | "[AMT_ERR]" | "[AMEMDIAG_ERR]" |
  849. "AMT-Correctable error found" |
  850. "[" ("HS" | "HD") "_MemoryError]" {
  851. ev->subkind = 2;
  852. extract_coords_and_addr(s, end, ev);
  853. return STL_LK_AMT_ERROR;
  854. }
  855. "Error Address" | "Fail Address" {
  856. uint64_t ea = 0;
  857. if (!parse_hex64_at(YYCURSOR, lim, &ea) || ea == 0) {
  858. continue;
  859. }
  860. ev->subkind = 2;
  861. ev->addr = ea;
  862. extract_coords_and_addr(s, end, ev);
  863. return STL_LK_AMT_ERROR;
  864. }
  865. "Logical Rank" WS "=" | "Error on rising strobe:" | "Error on falling strobe:" {
  866. ev->subkind = 5; /* 3-line AMT diagnostic continuation */
  867. extract_coords_and_addr(s, end, ev);
  868. return STL_LK_AMT_ERROR;
  869. }
  870. ("[Parity Error]" | "[Parity]") WS "Test:" {
  871. ev->subkind = 2;
  872. extract_coords_and_addr(s, end, ev);
  873. return STL_LK_MT_ERROR;
  874. }
  875. "Failing DIMM" | "[BIOS][FailMode]" |
  876. "Training Fail" | "BIST Error" | "BIST FAIL" | "Uncorrectable" |
  877. "Correctable error threshold exceeded" | "Critical Margin Error" |
  878. "FatalError:" | "No Eye width" |
  879. "No eye found" | "smaller than minimum critical margin" | "RxPerBitDeskew Failure" |
  880. "Parity Error" | "Parity error" | "[Parity]" | "[Parity Error]" | "PEC Error" | "PEC error" {
  881. ev->subkind = 2;
  882. extract_coords_and_addr(s, end, ev);
  883. return STL_LK_TRAINING_ERROR;
  884. }
  885. "UEFI Interactive Shell" {
  886. return STL_LK_UEFI_BANNER;
  887. }
  888. "Start PXE over IPv4" | "Downloading NBP file" | "NBP filename is" {
  889. ev->subkind = 0;
  890. return STL_LK_PXE_BOOT;
  891. }
  892. "NBP file downloaded successfully" | "LoadImage Status = Success" | "StartImage Status = Success" {
  893. ev->subkind = 1;
  894. return STL_LK_PXE_BOOT;
  895. }
  896. "PassMark MemTest86" | "MemTest86 V" | "MemTest86 v" |
  897. "Hovsee V" | "Hovsee v" |
  898. "Found configuration file:" | "*** TEST SESSION -" | "Launching 118.efi" |
  899. "STL_SIM TEST_START MT" {
  900. return STL_LK_MT_BANNER;
  901. }
  902. "STL_SIM TEST_RESULT " ("PASS" | "FAIL") {
  903. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  904. const uint8_t *af = NULL;
  905. if (match_ci_kw(p, lim, "fail", &af)) {
  906. ev->subkind = 2;
  907. return STL_LK_MT_FAIL_COMPLETE;
  908. }
  909. }
  910. ev->subkind = 1;
  911. return STL_LK_MT_PASS_COMPLETE;
  912. }
  913. "[MEM ERROR" | "[Mem Error]" | "[ECC Errors]" | "[ECC Error]" |
  914. "[IBECC Errors]" | "[Scrub ECC Errors]" | "[Data Error]" | "ECC Error:" {
  915. ev->subkind = 2;
  916. extract_coords_and_addr(s, end, ev);
  917. return STL_LK_MT_ERROR;
  918. }
  919. "DIMM err count=" {
  920. int32_t cnt = 0;
  921. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL) && cnt > 0) {
  922. ev->subkind = 2;
  923. extract_coords_and_addr(s, end, ev);
  924. return STL_LK_MT_ERROR;
  925. }
  926. continue;
  927. }
  928. "Channel/Slot:" | "Channel-Slot:" |
  929. "/GNR " ("DDR(hex)" | "raw(hex)" | "Decode=") |
  930. "(Chan,Slot,Rank,Bank,Row," | "(Channel,Slot,Rank,Bank,Row," | "(Ch,Sl,Rk,Bk,Rw," {
  931. ev->subkind = 5; /* 2nd-line MT ECC/Data Error coordinate continuation */
  932. extract_coords_and_addr(s, end, ev);
  933. return STL_LK_MT_ERROR;
  934. }
  935. "(" WS "Test" WS DIG WS "cumulative error count:" WS DIG {
  936. int32_t tid = 0, cnt = 0;
  937. const uint8_t *nx = NULL;
  938. const uint8_t *tpos = memchr(tok, 'T', (size_t)(YYCURSOR - tok));
  939. if (tpos && parse_i32_at(tpos + 4, YYCURSOR, &tid, &nx)) {
  940. const uint8_t *cl = memchr(nx ? nx : tok, ':', (size_t)(YYCURSOR - (nx ? nx : tok)));
  941. if (cl && parse_i32_at(cl + 1, lim, &cnt, NULL) && cnt > 0) {
  942. ev->subkind = 6; /* MemTest86 per-test cumulative error count */
  943. ev->val1 = tid;
  944. ev->val0 = cnt;
  945. return STL_LK_MT_ERROR;
  946. }
  947. }
  948. continue;
  949. }
  950. "Finished pass #" DIG WS "(of" WS DIG ")" {
  951. int32_t pno = 0, ptot = 0;
  952. const uint8_t *nx = NULL;
  953. if (parse_i32_at(tok + 15, lim, &pno, &nx)) {
  954. const uint8_t *ofp = memchr(tok + 15, 'f', (size_t)(lim - (tok + 15)));
  955. if (ofp) parse_i32_at(ofp + 1, lim, &ptot, NULL);
  956. }
  957. int32_t errs = 0;
  958. for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
  959. const uint8_t *af = NULL;
  960. if (match_ci_kw(p, lim, "count", &af) || match_ci_kw(p, lim, "errors", &af)) {
  961. int32_t v = 0;
  962. if (parse_i32_at(af, lim, &v, NULL)) errs += v;
  963. }
  964. }
  965. ev->val0 = errs;
  966. if (ptot > 0 && pno >= ptot) {
  967. ev->subkind = (errs > 0) ? 2 : 1;
  968. return (errs > 0) ? STL_LK_MT_FAIL_COMPLETE : STL_LK_MT_PASS_COMPLETE;
  969. }
  970. ev->val2 = (ptot > 0) ? ((pno * 100) / ptot) : 50;
  971. return STL_LK_MT_PROGRESS;
  972. }
  973. ("#" WS)? "Tests Passed" WS ":" WS DIG "/" DIG {
  974. int32_t passed = 0, total = 0;
  975. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  976. const uint8_t *nx = NULL;
  977. if (cl && parse_i32_at(cl + 1, YYCURSOR, &passed, &nx)
  978. && nx && nx < YYCURSOR && *nx == '/'
  979. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  980. if (passed == total) {
  981. ev->subkind = 1;
  982. ev->val0 = 0;
  983. return STL_LK_MT_PASS_COMPLETE;
  984. }
  985. ev->val0 = passed;
  986. ev->val1 = total;
  987. ev->val2 = (passed * 100) / total;
  988. return STL_LK_MT_PROGRESS;
  989. }
  990. continue;
  991. }
  992. ("#" WS)? "Tests Completed" WS ":" WS DIG "/" DIG {
  993. int32_t done = 0, total = 0;
  994. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  995. const uint8_t *nx = NULL;
  996. if (cl && parse_i32_at(cl + 1, YYCURSOR, &done, &nx)
  997. && nx && nx < YYCURSOR && *nx == '/'
  998. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  999. ev->val0 = done;
  1000. ev->val1 = total;
  1001. ev->val2 = (done * 100) / total;
  1002. return STL_LK_MT_PROGRESS;
  1003. }
  1004. continue;
  1005. }
  1006. ("#" WS)? "Bits in Error" WS ":" WS "Total" WS ":" WS DIG {
  1007. int32_t cnt = 0;
  1008. const uint8_t *tpos = NULL;
  1009. for (const uint8_t *p = tok; p + 5 <= YYCURSOR; p++) {
  1010. const uint8_t *af = NULL;
  1011. if (match_ci_kw(p, YYCURSOR, "total", &af)) {
  1012. tpos = af;
  1013. break;
  1014. }
  1015. }
  1016. if (tpos) {
  1017. const uint8_t *cl = memchr(tpos, ':', (size_t)(YYCURSOR - tpos));
  1018. if (cl && parse_i32_at(cl + 1, YYCURSOR, &cnt, NULL) && cnt > 0) {
  1019. ev->subkind = 6;
  1020. ev->val0 = cnt;
  1021. ev->val1 = 99;
  1022. return STL_LK_MT_ERROR;
  1023. }
  1024. }
  1025. continue;
  1026. }
  1027. ("Test Result" | "Test result" | "Result") WS ":" WS (("INCOMPLETE" | "Incomplete" | "incomplete") WS)? ("PASS" | "Pass" | "pass" | "FAIL" | "Fail" | "fail" | "FAILED" | "Failed" | "failed") {
  1028. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  1029. const uint8_t *af = NULL;
  1030. if (match_ci_kw(p, lim, "fail", &af) ||
  1031. match_ci_kw(p, lim, "failed", &af)) {
  1032. ev->subkind = 2;
  1033. return STL_LK_MT_FAIL_COMPLETE;
  1034. }
  1035. if (match_ci_kw(p, lim, "pass", &af)) {
  1036. ev->subkind = 1;
  1037. return STL_LK_MT_PASS_COMPLETE;
  1038. }
  1039. }
  1040. continue;
  1041. }
  1042. "Pass complete, no errors" {
  1043. ev->subkind = 1;
  1044. ev->val0 = 0;
  1045. return STL_LK_MT_PASS_COMPLETE;
  1046. }
  1047. "Test Complete" {
  1048. extract_coords_and_addr(s, end, ev);
  1049. if (ev->val0 > 0) {
  1050. ev->subkind = 2;
  1051. return STL_LK_MT_FAIL_COMPLETE;
  1052. }
  1053. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  1054. const uint8_t *af = NULL;
  1055. if (match_ci_kw(p, lim, "fail", &af)) {
  1056. ev->subkind = 2;
  1057. return STL_LK_MT_FAIL_COMPLETE;
  1058. }
  1059. }
  1060. ev->subkind = 1;
  1061. return STL_LK_MT_PASS_COMPLETE;
  1062. }
  1063. "Running test #" DIG {
  1064. int32_t tid = 0;
  1065. if (parse_i32_at(tok + 14, lim, &tid, NULL)) {
  1066. ev->val0 = tid;
  1067. ev->val1 = 25;
  1068. ev->val2 = (tid >= 0 && tid <= 25) ? ((tid * 100) / 26) : 50;
  1069. }
  1070. return STL_LK_MT_PROGRESS;
  1071. }
  1072. "N" [01] ".C" DIG (".D" [01])? (".SC" [01])? ".R" DIG (".L" DIG | "." WS "A" DIG)? (".B" DIG)? WS ":" {
  1073. int mcols = 0;
  1074. extract_ncd_token_cols(s, end, ev, &mcols);
  1075. for (const uint8_t *q = YYCURSOR; q + 4 <= lim; q++) {
  1076. const uint8_t *af = NULL;
  1077. if (match_ci_word(YYCURSOR, q, lim, "advanced memtest", &af) ||
  1078. match_ci_word(YYCURSOR, q, lim, "failure detected", &af) ||
  1079. match_ci_word(YYCURSOR, q, lim, "ppr memtest", &af)) {
  1080. ev->subkind = 2;
  1081. extract_coords_and_addr(s, end, ev);
  1082. return STL_LK_AMT_ERROR;
  1083. }
  1084. if (match_ci_word(YYCURSOR, q, lim, "error", &af) ||
  1085. match_ci_word(YYCURSOR, q, lim, "failed", &af) ||
  1086. match_ci_word(YYCURSOR, q, lim, "fail", &af)) {
  1087. ev->subkind = 2;
  1088. extract_coords_and_addr(s, end, ev);
  1089. return STL_LK_TRAINING_ERROR;
  1090. }
  1091. }
  1092. if (mcols >= 4) {
  1093. return STL_LK_RMT_ROW;
  1094. }
  1095. continue;
  1096. }
  1097. "N" [01] ".C" DIG ".D" [01] {
  1098. extract_ncd_token(s, end, ev);
  1099. for (const uint8_t *q = tok; q + 11 <= lim; q++) {
  1100. const uint8_t *af_por = NULL;
  1101. if (match_ci_word(tok, q, lim, "minimum por", &af_por)) {
  1102. ev->subkind = 4;
  1103. return STL_LK_DIMM_INVENTORY;
  1104. }
  1105. }
  1106. for (const uint8_t *p = tok; p + 11 <= lim; p++) {
  1107. const uint8_t *af = NULL;
  1108. if (match_ci_word(tok, p, lim, "failure detected", &af) ||
  1109. match_ci_word(tok, p, lim, "advanced memtest", &af) ||
  1110. match_ci_word(tok, p, lim, "ppr memtest", &af)) {
  1111. ev->subkind = 2;
  1112. extract_coords_and_addr(s, end, ev);
  1113. return STL_LK_AMT_ERROR;
  1114. }
  1115. }
  1116. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  1117. const uint8_t *af = NULL;
  1118. if (match_ci_word(tok, p, lim, "disabled", &af)) {
  1119. ev->subkind = 3;
  1120. return STL_LK_DIMM_INVENTORY;
  1121. }
  1122. if (match_ci_word(tok, p, lim, "fail", &af) ||
  1123. match_ci_word(tok, p, lim, "failed", &af) ||
  1124. match_ci_word(tok, p, lim, "failure", &af) ||
  1125. match_ci_word(tok, p, lim, "error", &af)) {
  1126. ev->subkind = 2;
  1127. extract_coords_and_addr(s, end, ev);
  1128. return STL_LK_TRAINING_ERROR;
  1129. }
  1130. }
  1131. for (const uint8_t *p = tok; p + 3 <= lim; p++) {
  1132. const uint8_t *af = NULL;
  1133. if (match_ci_word(tok, p, lim, "not", &af) ||
  1134. match_ci_word(tok, p, lim, "empty", &af) ||
  1135. match_ci_word(tok, p, lim, "absent", &af) ||
  1136. match_ci_word(tok, p, lim, "unpopulated", &af) ||
  1137. match_ci_word(tok, p, lim, "nodimm", &af)) {
  1138. ev->subkind = 0;
  1139. return STL_LK_DIMM_INVENTORY;
  1140. }
  1141. if (match_ci_word(tok, p, lim, "present", &af) ||
  1142. match_ci_word(tok, p, lim, "ddr5", &af) ||
  1143. match_ci_word(tok, p, lim, "enabled", &af) ||
  1144. match_ci_word(tok, p, lim, "test", &af)) {
  1145. ev->subkind = 4;
  1146. return STL_LK_DIMM_INVENTORY;
  1147. }
  1148. }
  1149. continue;
  1150. }
  1151. ("Test" DIG | "Test:" WS DIG) WS "Addr:" WS {
  1152. ev->subkind = 2;
  1153. extract_coords_and_addr(s, end, ev);
  1154. return STL_LK_MT_ERROR;
  1155. }
  1156. "Test:" WS DIG {
  1157. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  1158. const uint8_t *af = NULL;
  1159. if (match_ci_kw(p, lim, "expected", &af) ||
  1160. match_ci_kw(p, lim, "actual", &af) ||
  1161. match_ci_kw(p, lim, "addr", &af)) {
  1162. ev->subkind = 2;
  1163. extract_coords_and_addr(s, end, ev);
  1164. return STL_LK_MT_ERROR;
  1165. }
  1166. }
  1167. int32_t tnum = 0;
  1168. const uint8_t *nx = NULL;
  1169. if (parse_i32_at(tok + 5, lim, &tnum, &nx)) {
  1170. ev->val0 = tnum;
  1171. if (nx && nx < lim && *nx == '/') {
  1172. int32_t ttot = 0;
  1173. if (parse_i32_at(nx + 1, lim, &ttot, &nx)) ev->val1 = ttot;
  1174. }
  1175. }
  1176. for (const uint8_t *p = YYCURSOR; p < lim; p++) {
  1177. if (*p == '%' && p > buf && p[-1] >= '0' && p[-1] <= '9') {
  1178. const uint8_t *dg = p - 1;
  1179. while (dg > buf && dg[-1] >= '0' && dg[-1] <= '9') dg--;
  1180. int32_t pct = 0;
  1181. if (parse_i32_at(dg, p, &pct, NULL)) ev->val2 = pct;
  1182. break;
  1183. }
  1184. }
  1185. return STL_LK_MT_PROGRESS;
  1186. }
  1187. ("Test Pattern" | "Algo" WS "#" | "AlgoId") {
  1188. extract_coords_and_addr(s, end, ev);
  1189. int32_t aid = -1;
  1190. if (parse_i32_at(YYCURSOR, lim, &aid, NULL) && aid >= 0) ev->val0 = aid;
  1191. for (const uint8_t *p = buf; p + 4 <= lim; p++) {
  1192. const uint8_t *af = NULL;
  1193. if (match_ci_kw(p, lim, "fail", &af)) { ev->subkind = 2; break; }
  1194. if (match_ci_kw(p, lim, "pass", &af)) { ev->subkind = 1; }
  1195. }
  1196. return STL_LK_AMT_PROGRESS;
  1197. }
  1198. ("BankGroup" | "SubRank") {
  1199. ev->subkind = 5;
  1200. extract_coords_and_addr(s, end, ev);
  1201. if (ev->cpu >= 0 || ev->channel >= 0 || ev->bank >= 0) {
  1202. return STL_LK_AMT_ERROR;
  1203. }
  1204. continue;
  1205. }
  1206. "\x00" { break; }
  1207. ANY { continue; }
  1208. */
  1209. }
  1210. return STL_LK_NONE;
  1211. }
  1212. void stl_re2c_parse_line(const uint8_t *line, size_t len, uint32_t tag_mask, StlRe2cEvent *ev) {
  1213. memset(ev, 0, sizeof(*ev));
  1214. ev->cpu = -1;
  1215. ev->channel = -1;
  1216. ev->dimm = -1;
  1217. ev->rank = -1;
  1218. ev->bank = -1;
  1219. if (!line || len == 0) return;
  1220. const uint8_t *s = line;
  1221. const uint8_t *e = line + len;
  1222. trim_ws(&s, &e);
  1223. if (s >= e) return;
  1224. if (tag_mask == 0 && s[0] == '.') {
  1225. int only_dots = 1;
  1226. for (const uint8_t *p = s; p < e; p++) {
  1227. if (*p != '.' && *p != ' ' && *p != '\t') {
  1228. only_dots = 0;
  1229. break;
  1230. }
  1231. }
  1232. if (only_dots) return;
  1233. }
  1234. ev->kind = re2c_scan_token(s, e, ev);
  1235. }
  1236. int stl_re2c_detect_halfline_prompt(const uint8_t *buf, size_t len, StlRe2cEvent *ev) {
  1237. memset(ev, 0, sizeof(*ev));
  1238. ev->cpu = -1;
  1239. ev->channel = -1;
  1240. ev->dimm = -1;
  1241. ev->rank = -1;
  1242. ev->bank = -1;
  1243. if (!buf || len == 0) return 0;
  1244. const uint8_t *s = buf;
  1245. const uint8_t *e = buf + len;
  1246. trim_ws(&s, &e);
  1247. if (s >= e) return 0;
  1248. uint32_t k = re2c_scan_token(s, e, ev);
  1249. if (k == STL_LK_ICT_PROMPT || k == STL_LK_ICT_ENTER_HINT ||
  1250. k == STL_LK_AMT_PROMPT || k == STL_LK_UEFI_PROMPT_EFI ||
  1251. k == STL_LK_UEFI_PROMPT_ROOT) {
  1252. ev->kind = k;
  1253. return 1;
  1254. }
  1255. size_t tlen = (size_t)(e - s);
  1256. if (tlen >= 4 && memcmp(e - 4, "UIP>", 4) == 0) {
  1257. ev->kind = STL_LK_ICT_PROMPT;
  1258. return 1;
  1259. }
  1260. if (tlen >= 26 && memcmp(e - 26, "Please input your command:", 26) == 0) {
  1261. ev->kind = STL_LK_ICT_PROMPT;
  1262. extract_leading_bracket_cpu(s, e, ev);
  1263. return 1;
  1264. }
  1265. if (tlen >= 25 && memcmp(e - 25, "Please input your command", 25) == 0) {
  1266. ev->kind = STL_LK_ICT_PROMPT;
  1267. extract_leading_bracket_cpu(s, e, ev);
  1268. return 1;
  1269. }
  1270. if (tlen >= 7 && memcmp(e - 7, "[AMT #]", 7) == 0) {
  1271. ev->kind = STL_LK_AMT_PROMPT;
  1272. ev->fw_family = 1;
  1273. if (tlen >= 10 && e[-10] == '[' && (e[-9] == '0' || e[-9] == '1') && e[-8] == ']') {
  1274. ev->cpu = (int8_t)(e[-9] - '0');
  1275. }
  1276. return 1;
  1277. }
  1278. if (tlen >= 12 && memcmp(e - 12, "[AMEMDIAG #]", 12) == 0) {
  1279. ev->kind = STL_LK_AMT_PROMPT;
  1280. ev->fw_family = 2;
  1281. if (tlen >= 15 && e[-15] == '[' && (e[-14] == '0' || e[-14] == '1') && e[-13] == ']') {
  1282. ev->cpu = (int8_t)(e[-14] - '0');
  1283. }
  1284. return 1;
  1285. }
  1286. if (tlen >= 6 && memcmp(e - 6, "Shell>", 6) == 0) {
  1287. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1288. ev->fs_index = 255;
  1289. return 1;
  1290. }
  1291. /* Check trailing FSx:\EFI\> or FSx:\> */
  1292. if (tlen >= 6 && e[-1] == '>') {
  1293. for (size_t i = (tlen > 24 ? tlen - 24 : 0); i + 4 < tlen; i++) {
  1294. if (s[i] == 'F' && s[i+1] == 'S' && s[i+2] >= '0' && s[i+2] <= '9' && s[i+3] == ':') {
  1295. ev->fs_index = (uint8_t)(s[i+2] - '0');
  1296. for (size_t j = i + 4; j + 3 <= tlen; j++) {
  1297. if ((s[j] == 'E' || s[j] == 'e') && (s[j+1] == 'F' || s[j+1] == 'f') &&
  1298. (s[j+2] == 'I' || s[j+2] == 'i')) {
  1299. ev->kind = STL_LK_UEFI_PROMPT_EFI;
  1300. return 1;
  1301. }
  1302. }
  1303. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1304. return 1;
  1305. }
  1306. }
  1307. }
  1308. return 0;
  1309. }