parser_re2c.re 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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 already parsed accurately with leading whitespace by extract_leading_bracket_cpu */
  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. for (const uint8_t *q = p + 16; q + 6 <= lim; q++) {
  690. if (memcmp(q, "FAILED", 6) == 0) {
  691. ev->subkind = 2;
  692. return STL_LK_TRAINING_ERROR;
  693. }
  694. if (q + 7 <= lim && memcmp(q, "Started", 7) == 0) {
  695. return STL_LK_RMT_START;
  696. }
  697. if (q + 7 <= lim && (memcmp(q, "Skipped", 7) == 0 || memcmp(q, "SKIPPED", 7) == 0)) {
  698. ev->subkind = 3;
  699. return STL_LK_RMT_STOP;
  700. }
  701. if (q + 8 <= lim && (memcmp(q, "Disabled", 8) == 0 || memcmp(q, "DISABLED", 8) == 0)) {
  702. ev->subkind = 3;
  703. return STL_LK_RMT_STOP;
  704. }
  705. if (q + 9 <= lim && memcmp(q, "SUCCEEDED", 9) == 0) {
  706. ev->subkind = 1;
  707. return STL_LK_RMT_STOP;
  708. }
  709. }
  710. return STL_LK_RMT_STOP;
  711. }
  712. if (!is_pipe_sync_sbsp && memcmp(p, "FAILED", 6) == 0) {
  713. ev->subkind = 2;
  714. return STL_LK_TRAINING_ERROR;
  715. }
  716. }
  717. return STL_LK_MRC_START;
  718. }
  719. "START_RMT_N" [01] {
  720. ev->cpu = (int8_t)(tok[11] - '0');
  721. return STL_LK_RMT_START;
  722. }
  723. "START_RMT" | "Starting RMT test v" | "Rank Margin Tool -- Started" |
  724. "[HS_StartRmt]" | "[HD_StartRmt]" {
  725. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
  726. extract_coords_and_addr(s, end, ev);
  727. return STL_LK_RMT_START;
  728. }
  729. "STOP_RMT_N" [01] {
  730. ev->cpu = (int8_t)(tok[10] - '0');
  731. return STL_LK_RMT_STOP;
  732. }
  733. "STOP_RMT" | "[HS_StopRmt]" | "[HD_StopRmt]" | "RMT test v" {
  734. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') {
  735. ev->fw_family = 1;
  736. return STL_LK_RMT_STOP;
  737. }
  738. if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'D') {
  739. return STL_LK_RMT_STOP;
  740. }
  741. for (const uint8_t *p = tok; p + 8 <= lim; p++) {
  742. if (memcmp(p, "complete", 8) == 0) {
  743. return STL_LK_RMT_STOP;
  744. }
  745. }
  746. if (tok[0] == 'S') return STL_LK_RMT_STOP;
  747. continue;
  748. }
  749. "[" ("HS" | "HD") "_" ("RMTSensor" | "Sensor") "]" {
  750. if (tok[2] == 'S') ev->fw_family = 1;
  751. extract_ncd_token(s, end, ev);
  752. const uint8_t *cl = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
  753. if (cl) {
  754. int32_t deg = 0;
  755. const uint8_t *nx = NULL;
  756. if (parse_i32_at(cl + 1, lim, &deg, &nx)) {
  757. int32_t tenths = 0;
  758. if (nx && nx + 1 < lim && *nx == '.' && nx[1] >= '0' && nx[1] <= '9') {
  759. tenths = nx[1] - '0';
  760. }
  761. ev->val3 = deg * 10 + (deg >= 0 ? tenths : -tenths);
  762. }
  763. }
  764. return STL_LK_INLINE_TEMP;
  765. }
  766. "[" ("HS" | "HD") "_NODIMM]" {
  767. if (tok[2] == 'S') ev->fw_family = 1;
  768. extract_coords_and_addr(s, end, ev);
  769. ev->subkind = 0; /* explicitly absent */
  770. ev->val1 = 1; /* PEI DRAM inventory marker */
  771. return STL_LK_DIMM_INVENTORY;
  772. }
  773. "[" ("HS" | "HD") "_DRAM]" {
  774. if (tok[2] == 'S') ev->fw_family = 1;
  775. extract_coords_and_addr(s, end, ev);
  776. /* Check Size:0 or absent/empty/not-installed -> absent, else present */
  777. ev->subkind = 4;
  778. ev->val1 = 1; /* PEI DRAM inventory marker */
  779. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  780. const uint8_t *af = NULL;
  781. if (match_ci_word(YYCURSOR, p, lim, "size", &af)) {
  782. int32_t sz = 0;
  783. if (parse_i32_at(af, lim, &sz, NULL)) {
  784. ev->subkind = (sz > 0) ? 4 : 0;
  785. ev->val0 = sz;
  786. break;
  787. }
  788. }
  789. if (match_ci_word(YYCURSOR, p, lim, "not installed", &af) ||
  790. match_ci_word(YYCURSOR, p, lim, "not present", &af) ||
  791. match_ci_word(YYCURSOR, p, lim, "no dimm", &af) ||
  792. match_ci_word(YYCURSOR, p, lim, "absent", &af) ||
  793. match_ci_word(YYCURSOR, p, lim, "empty", &af) ||
  794. match_ci_word(YYCURSOR, p, lim, "unpopulated", &af)) {
  795. ev->subkind = 0;
  796. break;
  797. }
  798. }
  799. return STL_LK_DIMM_INVENTORY;
  800. }
  801. "[" ("HS" | "HD") "_Disable" ("Dimm" | "DIMM") "]" | "DisableDIMM()" | "MapOutDimm()" | "Mapping out DDR" {
  802. extract_coords_and_addr(s, end, ev);
  803. ev->subkind = 3; /* disabled */
  804. return STL_LK_DIMM_INVENTORY;
  805. }
  806. "AMT Version " | "Welcome to Advanced Memory Test" | "GNR-4.3.3" {
  807. ev->fw_family = 1;
  808. return STL_LK_AMT_BANNER;
  809. }
  810. "AMEMDIAG Version " | "Welcome to Advanced Memory Diagnostic" | "GNR-4.3.0" {
  811. ev->fw_family = 2;
  812. return STL_LK_AMT_BANNER;
  813. }
  814. ("AMT" | "AMEMDIAG") WS "Test Algo Count:" {
  815. int32_t cnt = 0;
  816. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  817. ev->val1 = cnt; /* algorithm count */
  818. }
  819. ev->subkind = 0;
  820. return STL_LK_AMT_SUMMARY;
  821. }
  822. ("AMT" | "AMEMDIAG") WS "Test Result Summary:" |
  823. ("AMT" | "AMEMDIAG") WS "Test Result:" |
  824. "AMT Test PASS" | "AMEMDIAG Test PASS" | "All Test PASS" |
  825. "AMT Test FAIL" | "AMEMDIAG Test FAIL" | "All Test FAIL" {
  826. extract_coords_and_addr(s, end, ev);
  827. /* Determine scope: summary vs per-socket */
  828. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  829. const uint8_t *af = NULL;
  830. if (match_ci_kw(p, lim, "summary", &af)) {
  831. ev->val2 = 1; /* scope = summary */
  832. }
  833. if (match_ci_kw(p, lim, "fail", &af) || match_ci_kw(p, lim, "block", &af)) {
  834. ev->subkind = 2;
  835. } else if (match_ci_kw(p, lim, "pass", &af) && ev->subkind != 2) {
  836. ev->subkind = 1;
  837. }
  838. }
  839. return STL_LK_AMT_SUMMARY;
  840. }
  841. "Total Error Count" {
  842. int32_t cnt = 0;
  843. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
  844. ev->val0 = cnt;
  845. ev->subkind = (cnt > 0) ? 2 : 1;
  846. }
  847. extract_coords_and_addr(s, end, ev);
  848. return STL_LK_AMT_SUMMARY;
  849. }
  850. "[" ("AMT" | "AMEMDIAG") WS DIG "/" DIG WS DIG "/" DIG WS DIG "/" DIG "]" {
  851. /* e.g. [0][AMT 1/1 1/1 3/24] Algo ... */
  852. ev->fw_family = (tok[1] == 'A' && tok[2] == 'M' && tok[3] == 'E') ? 2 : 1;
  853. const uint8_t *p = tok + 4;
  854. while (p < YYCURSOR && (*p < '0' || *p > '9')) p++;
  855. int32_t r1=0, r2=0, p1=0, p2=0, a1=0, a2=0;
  856. if (parse_i32_at(p, YYCURSOR, &r1, &p) && p < YYCURSOR && *p == '/' &&
  857. parse_i32_at(p+1, YYCURSOR, &r2, &p) &&
  858. parse_i32_at(p, YYCURSOR, &p1, &p) && p < YYCURSOR && *p == '/' &&
  859. parse_i32_at(p+1, YYCURSOR, &p2, &p) &&
  860. parse_i32_at(p, YYCURSOR, &a1, &p) && p < YYCURSOR && *p == '/' &&
  861. parse_i32_at(p+1, YYCURSOR, &a2, &p)) {
  862. ev->val0 = a1; /* algorithm_index */
  863. ev->val1 = a2; /* algorithm_count */
  864. if (a2 > 0) ev->val2 = (a1 * 100) / a2;
  865. }
  866. return STL_LK_AMT_PROGRESS;
  867. }
  868. "Failure detected - Advanced Memtest" | "Failure detected - PPR Memtest" |
  869. "Data Compare Error" | "[AMT_ERR]" | "[AMEMDIAG_ERR]" |
  870. "AMT-Correctable error found" |
  871. "[" ("HS" | "HD") "_MemoryError]" {
  872. ev->subkind = 2;
  873. extract_coords_and_addr(s, end, ev);
  874. return STL_LK_AMT_ERROR;
  875. }
  876. "Error Address" | "Fail Address" {
  877. uint64_t ea = 0;
  878. if (!parse_hex64_at(YYCURSOR, lim, &ea) || ea == 0) {
  879. continue;
  880. }
  881. ev->subkind = 2;
  882. ev->addr = ea;
  883. extract_coords_and_addr(s, end, ev);
  884. return STL_LK_AMT_ERROR;
  885. }
  886. "Logical Rank" WS "=" | "Error on rising strobe:" | "Error on falling strobe:" {
  887. ev->subkind = 5; /* 3-line AMT diagnostic continuation */
  888. extract_coords_and_addr(s, end, ev);
  889. return STL_LK_AMT_ERROR;
  890. }
  891. ("[Parity Error]" | "[Parity]") WS "Test:" {
  892. ev->subkind = 2;
  893. extract_coords_and_addr(s, end, ev);
  894. return STL_LK_MT_ERROR;
  895. }
  896. "Failing DIMM" | "[BIOS][FailMode]" |
  897. "Training Fail" | "BIST Error" | "BIST FAIL" | "Uncorrectable" |
  898. "Correctable error threshold exceeded" | "Critical Margin Error" |
  899. "FatalError:" | "No Eye width" |
  900. "No eye found" | "smaller than minimum critical margin" | "RxPerBitDeskew Failure" |
  901. "Parity Error" | "Parity error" | "[Parity]" | "[Parity Error]" | "PEC Error" | "PEC error" {
  902. ev->subkind = 2;
  903. extract_coords_and_addr(s, end, ev);
  904. return STL_LK_TRAINING_ERROR;
  905. }
  906. "UEFI Interactive Shell" {
  907. return STL_LK_UEFI_BANNER;
  908. }
  909. "Start PXE over IPv4" | "Downloading NBP file" | "NBP filename is" {
  910. ev->subkind = 0;
  911. return STL_LK_PXE_BOOT;
  912. }
  913. "NBP file downloaded successfully" | "LoadImage Status = Success" | "StartImage Status = Success" {
  914. ev->subkind = 1;
  915. return STL_LK_PXE_BOOT;
  916. }
  917. "PassMark MemTest86" | "MemTest86 V" | "MemTest86 v" |
  918. "Hovsee V" | "Hovsee v" |
  919. "Found configuration file:" | "*** TEST SESSION -" | "Launching 118.efi" |
  920. "STL_SIM TEST_START MT" {
  921. return STL_LK_MT_BANNER;
  922. }
  923. "STL_SIM TEST_RESULT " ("PASS" | "FAIL") {
  924. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  925. const uint8_t *af = NULL;
  926. if (match_ci_kw(p, lim, "fail", &af)) {
  927. ev->subkind = 2;
  928. return STL_LK_MT_FAIL_COMPLETE;
  929. }
  930. }
  931. ev->subkind = 1;
  932. return STL_LK_MT_PASS_COMPLETE;
  933. }
  934. "[MEM ERROR" | "[Mem Error]" | "[ECC Errors]" | "[ECC Error]" |
  935. "[IBECC Errors]" | "[Scrub ECC Errors]" | "[Data Error]" | "ECC Error:" {
  936. ev->subkind = 2;
  937. extract_coords_and_addr(s, end, ev);
  938. return STL_LK_MT_ERROR;
  939. }
  940. "DIMM err count=" {
  941. int32_t cnt = 0;
  942. if (parse_i32_at(YYCURSOR, lim, &cnt, NULL) && cnt > 0) {
  943. ev->subkind = 2;
  944. extract_coords_and_addr(s, end, ev);
  945. return STL_LK_MT_ERROR;
  946. }
  947. continue;
  948. }
  949. "Channel/Slot:" | "Channel-Slot:" |
  950. "/GNR " ("DDR(hex)" | "raw(hex)" | "Decode=") |
  951. "(Chan,Slot,Rank,Bank,Row," | "(Channel,Slot,Rank,Bank,Row," | "(Ch,Sl,Rk,Bk,Rw," {
  952. ev->subkind = 5; /* 2nd-line MT ECC/Data Error coordinate continuation */
  953. extract_coords_and_addr(s, end, ev);
  954. return STL_LK_MT_ERROR;
  955. }
  956. "(" WS "Test" WS DIG WS "cumulative error count:" WS DIG {
  957. int32_t tid = 0, cnt = 0;
  958. const uint8_t *nx = NULL;
  959. const uint8_t *tpos = memchr(tok, 'T', (size_t)(YYCURSOR - tok));
  960. if (tpos && parse_i32_at(tpos + 4, YYCURSOR, &tid, &nx)) {
  961. const uint8_t *cl = memchr(nx ? nx : tok, ':', (size_t)(YYCURSOR - (nx ? nx : tok)));
  962. if (cl && parse_i32_at(cl + 1, lim, &cnt, NULL) && cnt > 0) {
  963. ev->subkind = 6; /* MemTest86 per-test cumulative error count */
  964. ev->val1 = tid;
  965. ev->val0 = cnt;
  966. return STL_LK_MT_ERROR;
  967. }
  968. }
  969. continue;
  970. }
  971. "Finished pass #" DIG WS "(of" WS DIG ")" {
  972. int32_t pno = 0, ptot = 0;
  973. const uint8_t *nx = NULL;
  974. if (parse_i32_at(tok + 15, lim, &pno, &nx)) {
  975. const uint8_t *ofp = memchr(tok + 15, 'f', (size_t)(lim - (tok + 15)));
  976. if (ofp) parse_i32_at(ofp + 1, lim, &ptot, NULL);
  977. }
  978. int32_t errs = 0;
  979. for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
  980. const uint8_t *af = NULL;
  981. if (match_ci_kw(p, lim, "count", &af) || match_ci_kw(p, lim, "errors", &af)) {
  982. int32_t v = 0;
  983. if (parse_i32_at(af, lim, &v, NULL)) errs += v;
  984. }
  985. }
  986. ev->val0 = errs;
  987. if (ptot > 0 && pno >= ptot) {
  988. ev->subkind = (errs > 0) ? 2 : 1;
  989. return (errs > 0) ? STL_LK_MT_FAIL_COMPLETE : STL_LK_MT_PASS_COMPLETE;
  990. }
  991. ev->val2 = (ptot > 0) ? ((pno * 100) / ptot) : 50;
  992. return STL_LK_MT_PROGRESS;
  993. }
  994. ("#" WS)? "Tests Passed" WS ":" WS DIG "/" DIG {
  995. int32_t passed = 0, total = 0;
  996. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  997. const uint8_t *nx = NULL;
  998. if (cl && parse_i32_at(cl + 1, YYCURSOR, &passed, &nx)
  999. && nx && nx < YYCURSOR && *nx == '/'
  1000. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  1001. if (passed == total) {
  1002. ev->subkind = 1;
  1003. ev->val0 = 0;
  1004. return STL_LK_MT_PASS_COMPLETE;
  1005. }
  1006. ev->val0 = passed;
  1007. ev->val1 = total;
  1008. ev->val2 = (passed * 100) / total;
  1009. return STL_LK_MT_PROGRESS;
  1010. }
  1011. continue;
  1012. }
  1013. ("#" WS)? "Tests Completed" WS ":" WS DIG "/" DIG {
  1014. int32_t done = 0, total = 0;
  1015. const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
  1016. const uint8_t *nx = NULL;
  1017. if (cl && parse_i32_at(cl + 1, YYCURSOR, &done, &nx)
  1018. && nx && nx < YYCURSOR && *nx == '/'
  1019. && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
  1020. ev->val0 = done;
  1021. ev->val1 = total;
  1022. ev->val2 = (done * 100) / total;
  1023. return STL_LK_MT_PROGRESS;
  1024. }
  1025. continue;
  1026. }
  1027. ("#" WS)? "Bits in Error" WS ":" WS "Total" WS ":" WS DIG {
  1028. int32_t cnt = 0;
  1029. const uint8_t *tpos = NULL;
  1030. for (const uint8_t *p = tok; p + 5 <= YYCURSOR; p++) {
  1031. const uint8_t *af = NULL;
  1032. if (match_ci_kw(p, YYCURSOR, "total", &af)) {
  1033. tpos = af;
  1034. break;
  1035. }
  1036. }
  1037. if (tpos) {
  1038. const uint8_t *cl = memchr(tpos, ':', (size_t)(YYCURSOR - tpos));
  1039. if (cl && parse_i32_at(cl + 1, YYCURSOR, &cnt, NULL) && cnt > 0) {
  1040. ev->subkind = 6;
  1041. ev->val0 = cnt;
  1042. ev->val1 = 99;
  1043. return STL_LK_MT_ERROR;
  1044. }
  1045. }
  1046. continue;
  1047. }
  1048. ("Test Result" | "Test result" | "Result") WS ":" WS (("INCOMPLETE" | "Incomplete" | "incomplete") WS)? ("PASS" | "Pass" | "pass" | "FAIL" | "Fail" | "fail" | "FAILED" | "Failed" | "failed") {
  1049. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  1050. const uint8_t *af = NULL;
  1051. if (match_ci_kw(p, lim, "fail", &af) ||
  1052. match_ci_kw(p, lim, "failed", &af)) {
  1053. ev->subkind = 2;
  1054. return STL_LK_MT_FAIL_COMPLETE;
  1055. }
  1056. if (match_ci_kw(p, lim, "pass", &af)) {
  1057. ev->subkind = 1;
  1058. return STL_LK_MT_PASS_COMPLETE;
  1059. }
  1060. }
  1061. continue;
  1062. }
  1063. "Pass complete, no errors" {
  1064. ev->subkind = 1;
  1065. ev->val0 = 0;
  1066. return STL_LK_MT_PASS_COMPLETE;
  1067. }
  1068. "Test Complete" {
  1069. extract_coords_and_addr(s, end, ev);
  1070. for (const uint8_t *p = YYCURSOR; p + 5 <= lim; p++) {
  1071. const uint8_t *af = NULL;
  1072. if (match_ci_kw(p, lim, "errors", &af) || match_ci_kw(p, lim, "error", &af)) {
  1073. int32_t ec = 0;
  1074. if (parse_i32_at(af, lim, &ec, NULL) && ec >= 0) {
  1075. ev->val0 = ec;
  1076. break;
  1077. }
  1078. }
  1079. }
  1080. if (ev->val0 > 0) {
  1081. ev->subkind = 2;
  1082. return STL_LK_MT_FAIL_COMPLETE;
  1083. }
  1084. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  1085. const uint8_t *af = NULL;
  1086. if (match_ci_kw(p, lim, "fail", &af)) {
  1087. ev->subkind = 2;
  1088. return STL_LK_MT_FAIL_COMPLETE;
  1089. }
  1090. }
  1091. ev->subkind = 1;
  1092. return STL_LK_MT_PASS_COMPLETE;
  1093. }
  1094. "Running test #" DIG {
  1095. int32_t tid = 0;
  1096. if (parse_i32_at(tok + 14, lim, &tid, NULL)) {
  1097. ev->val0 = tid;
  1098. ev->val1 = 25;
  1099. ev->val2 = (tid >= 0 && tid <= 25) ? ((tid * 100) / 26) : 50;
  1100. }
  1101. return STL_LK_MT_PROGRESS;
  1102. }
  1103. "N" [01] ".C" DIG (".D" [01])? (".SC" [01])? ".R" DIG (".L" DIG | "." WS "A" DIG)? (".B" DIG)? WS ":" {
  1104. int mcols = 0;
  1105. extract_ncd_token_cols(s, end, ev, &mcols);
  1106. for (const uint8_t *q = YYCURSOR; q + 4 <= lim; q++) {
  1107. const uint8_t *af = NULL;
  1108. if (match_ci_word(YYCURSOR, q, lim, "advanced memtest", &af) ||
  1109. match_ci_word(YYCURSOR, q, lim, "failure detected", &af) ||
  1110. match_ci_word(YYCURSOR, q, lim, "ppr memtest", &af)) {
  1111. ev->subkind = 2;
  1112. extract_coords_and_addr(s, end, ev);
  1113. return STL_LK_AMT_ERROR;
  1114. }
  1115. if (match_ci_word(YYCURSOR, q, lim, "error", &af) ||
  1116. match_ci_word(YYCURSOR, q, lim, "failed", &af) ||
  1117. match_ci_word(YYCURSOR, q, lim, "fail", &af)) {
  1118. ev->subkind = 2;
  1119. extract_coords_and_addr(s, end, ev);
  1120. return STL_LK_TRAINING_ERROR;
  1121. }
  1122. }
  1123. if (mcols >= 4) {
  1124. return STL_LK_RMT_ROW;
  1125. }
  1126. continue;
  1127. }
  1128. "N" [01] ".C" DIG ".D" [01] {
  1129. extract_ncd_token(s, end, ev);
  1130. for (const uint8_t *q = tok; q + 11 <= lim; q++) {
  1131. const uint8_t *af_por = NULL;
  1132. if (match_ci_word(tok, q, lim, "minimum por", &af_por)) {
  1133. ev->subkind = 4;
  1134. return STL_LK_DIMM_INVENTORY;
  1135. }
  1136. }
  1137. for (const uint8_t *p = tok; p + 11 <= lim; p++) {
  1138. const uint8_t *af = NULL;
  1139. if (match_ci_word(tok, p, lim, "failure detected", &af) ||
  1140. match_ci_word(tok, p, lim, "advanced memtest", &af) ||
  1141. match_ci_word(tok, p, lim, "ppr memtest", &af)) {
  1142. ev->subkind = 2;
  1143. extract_coords_and_addr(s, end, ev);
  1144. return STL_LK_AMT_ERROR;
  1145. }
  1146. }
  1147. for (const uint8_t *p = tok; p + 4 <= lim; p++) {
  1148. const uint8_t *af = NULL;
  1149. if (match_ci_word(tok, p, lim, "disabled", &af)) {
  1150. ev->subkind = 3;
  1151. return STL_LK_DIMM_INVENTORY;
  1152. }
  1153. if (match_ci_word(tok, p, lim, "fail", &af) ||
  1154. match_ci_word(tok, p, lim, "failed", &af) ||
  1155. match_ci_word(tok, p, lim, "failure", &af) ||
  1156. match_ci_word(tok, p, lim, "error", &af)) {
  1157. ev->subkind = 2;
  1158. extract_coords_and_addr(s, end, ev);
  1159. return STL_LK_TRAINING_ERROR;
  1160. }
  1161. }
  1162. for (const uint8_t *p = tok; p + 3 <= lim; p++) {
  1163. const uint8_t *af = NULL;
  1164. if (match_ci_word(tok, p, lim, "not", &af) ||
  1165. match_ci_word(tok, p, lim, "empty", &af) ||
  1166. match_ci_word(tok, p, lim, "absent", &af) ||
  1167. match_ci_word(tok, p, lim, "unpopulated", &af) ||
  1168. match_ci_word(tok, p, lim, "nodimm", &af)) {
  1169. ev->subkind = 0;
  1170. return STL_LK_DIMM_INVENTORY;
  1171. }
  1172. if (match_ci_word(tok, p, lim, "present", &af) ||
  1173. match_ci_word(tok, p, lim, "ddr5", &af) ||
  1174. match_ci_word(tok, p, lim, "enabled", &af) ||
  1175. match_ci_word(tok, p, lim, "test", &af)) {
  1176. ev->subkind = 4;
  1177. return STL_LK_DIMM_INVENTORY;
  1178. }
  1179. }
  1180. continue;
  1181. }
  1182. ("Test" DIG | "Test:" WS DIG) WS "Addr:" WS {
  1183. ev->subkind = 2;
  1184. extract_coords_and_addr(s, end, ev);
  1185. return STL_LK_MT_ERROR;
  1186. }
  1187. "Test:" WS DIG {
  1188. for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
  1189. const uint8_t *af = NULL;
  1190. if (match_ci_kw(p, lim, "expected", &af) ||
  1191. match_ci_kw(p, lim, "actual", &af) ||
  1192. match_ci_kw(p, lim, "addr", &af)) {
  1193. ev->subkind = 2;
  1194. extract_coords_and_addr(s, end, ev);
  1195. return STL_LK_MT_ERROR;
  1196. }
  1197. }
  1198. int32_t tnum = 0;
  1199. const uint8_t *nx = NULL;
  1200. if (parse_i32_at(tok + 5, lim, &tnum, &nx)) {
  1201. ev->val0 = tnum;
  1202. if (nx && nx < lim && *nx == '/') {
  1203. int32_t ttot = 0;
  1204. if (parse_i32_at(nx + 1, lim, &ttot, &nx)) ev->val1 = ttot;
  1205. }
  1206. }
  1207. for (const uint8_t *p = YYCURSOR; p < lim; p++) {
  1208. if (*p == '%' && p > buf && p[-1] >= '0' && p[-1] <= '9') {
  1209. const uint8_t *dg = p - 1;
  1210. while (dg > buf && dg[-1] >= '0' && dg[-1] <= '9') dg--;
  1211. int32_t pct = 0;
  1212. if (parse_i32_at(dg, p, &pct, NULL)) ev->val2 = pct;
  1213. break;
  1214. }
  1215. }
  1216. return STL_LK_MT_PROGRESS;
  1217. }
  1218. ("Test Pattern" | "Algo" WS "#" | "AlgoId") {
  1219. extract_coords_and_addr(s, end, ev);
  1220. int32_t aid = -1;
  1221. if (parse_i32_at(YYCURSOR, lim, &aid, NULL) && aid >= 0) ev->val0 = aid;
  1222. for (const uint8_t *p = buf; p + 4 <= lim; p++) {
  1223. const uint8_t *af = NULL;
  1224. if (match_ci_kw(p, lim, "fail", &af)) { ev->subkind = 2; break; }
  1225. if (match_ci_kw(p, lim, "pass", &af)) { ev->subkind = 1; }
  1226. }
  1227. return STL_LK_AMT_PROGRESS;
  1228. }
  1229. ("BankGroup" | "SubRank") {
  1230. ev->subkind = 5;
  1231. extract_coords_and_addr(s, end, ev);
  1232. if (ev->cpu >= 0 || ev->channel >= 0 || ev->bank >= 0) {
  1233. return STL_LK_AMT_ERROR;
  1234. }
  1235. continue;
  1236. }
  1237. "\x00" { break; }
  1238. ANY { continue; }
  1239. */
  1240. }
  1241. return STL_LK_NONE;
  1242. }
  1243. void stl_re2c_parse_line(const uint8_t *line, size_t len, uint32_t tag_mask, StlRe2cEvent *ev) {
  1244. memset(ev, 0, sizeof(*ev));
  1245. ev->cpu = -1;
  1246. ev->channel = -1;
  1247. ev->dimm = -1;
  1248. ev->rank = -1;
  1249. ev->bank = -1;
  1250. if (!line || len == 0) return;
  1251. const uint8_t *s = line;
  1252. const uint8_t *e = line + len;
  1253. trim_ws(&s, &e);
  1254. if (s >= e) return;
  1255. if (tag_mask == 0 && s[0] == '.') {
  1256. int only_dots = 1;
  1257. for (const uint8_t *p = s; p < e; p++) {
  1258. if (*p != '.' && *p != ' ' && *p != '\t') {
  1259. only_dots = 0;
  1260. break;
  1261. }
  1262. }
  1263. if (only_dots) return;
  1264. }
  1265. ev->kind = re2c_scan_token(s, e, ev);
  1266. }
  1267. int stl_re2c_detect_halfline_prompt(const uint8_t *buf, size_t len, StlRe2cEvent *ev) {
  1268. memset(ev, 0, sizeof(*ev));
  1269. ev->cpu = -1;
  1270. ev->channel = -1;
  1271. ev->dimm = -1;
  1272. ev->rank = -1;
  1273. ev->bank = -1;
  1274. if (!buf || len == 0) return 0;
  1275. const uint8_t *s = buf;
  1276. const uint8_t *e = buf + len;
  1277. trim_ws(&s, &e);
  1278. if (s >= e) return 0;
  1279. uint32_t k = re2c_scan_token(s, e, ev);
  1280. if (k == STL_LK_ICT_PROMPT || k == STL_LK_ICT_ENTER_HINT ||
  1281. k == STL_LK_AMT_PROMPT || k == STL_LK_UEFI_PROMPT_EFI ||
  1282. k == STL_LK_UEFI_PROMPT_ROOT) {
  1283. ev->kind = k;
  1284. return 1;
  1285. }
  1286. size_t tlen = (size_t)(e - s);
  1287. if (tlen >= 4 && memcmp(e - 4, "UIP>", 4) == 0) {
  1288. ev->kind = STL_LK_ICT_PROMPT;
  1289. return 1;
  1290. }
  1291. if (tlen >= 26 && memcmp(e - 26, "Please input your command:", 26) == 0) {
  1292. ev->kind = STL_LK_ICT_PROMPT;
  1293. extract_leading_bracket_cpu(s, e, ev);
  1294. return 1;
  1295. }
  1296. if (tlen >= 25 && memcmp(e - 25, "Please input your command", 25) == 0) {
  1297. ev->kind = STL_LK_ICT_PROMPT;
  1298. extract_leading_bracket_cpu(s, e, ev);
  1299. return 1;
  1300. }
  1301. if (tlen >= 7 && memcmp(e - 7, "[AMT #]", 7) == 0) {
  1302. ev->kind = STL_LK_AMT_PROMPT;
  1303. ev->fw_family = 1;
  1304. if (tlen >= 10 && e[-10] == '[' && (e[-9] == '0' || e[-9] == '1') && e[-8] == ']') {
  1305. ev->cpu = (int8_t)(e[-9] - '0');
  1306. }
  1307. return 1;
  1308. }
  1309. if (tlen >= 12 && memcmp(e - 12, "[AMEMDIAG #]", 12) == 0) {
  1310. ev->kind = STL_LK_AMT_PROMPT;
  1311. ev->fw_family = 2;
  1312. if (tlen >= 15 && e[-15] == '[' && (e[-14] == '0' || e[-14] == '1') && e[-13] == ']') {
  1313. ev->cpu = (int8_t)(e[-14] - '0');
  1314. }
  1315. return 1;
  1316. }
  1317. if (tlen >= 6 && memcmp(e - 6, "Shell>", 6) == 0) {
  1318. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1319. ev->fs_index = 255;
  1320. return 1;
  1321. }
  1322. /* Check trailing FSx:\EFI\> or FSx:\> */
  1323. if (tlen >= 6 && e[-1] == '>') {
  1324. for (size_t i = (tlen > 24 ? tlen - 24 : 0); i + 4 < tlen; i++) {
  1325. if (s[i] == 'F' && s[i+1] == 'S' && s[i+2] >= '0' && s[i+2] <= '9' && s[i+3] == ':') {
  1326. ev->fs_index = (uint8_t)(s[i+2] - '0');
  1327. for (size_t j = i + 4; j + 3 <= tlen; j++) {
  1328. if ((s[j] == 'E' || s[j] == 'e') && (s[j+1] == 'F' || s[j+1] == 'f') &&
  1329. (s[j+2] == 'I' || s[j+2] == 'i')) {
  1330. ev->kind = STL_LK_UEFI_PROMPT_EFI;
  1331. return 1;
  1332. }
  1333. }
  1334. ev->kind = STL_LK_UEFI_PROMPT_ROOT;
  1335. return 1;
  1336. }
  1337. }
  1338. }
  1339. return 0;
  1340. }