| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373 |
- /*
- * XJKJ-STL Deterministic re2c Line Lexer & Coordinate Extractor (v0.8.1.19)
- *
- * Compiled via: re2c -W --no-generation-date -o parser_re2c.c parser_re2c.re
- * Pure C11 / x86-64 SSE2 baseline; zero heap allocations; replaces per-line
- * repeated .contains() scans with a deterministic finite automaton (DFA).
- *
- * Verified 1:1 against both real server firmwares:
- * - .166: 107_VD012 / [Hovsee] / [HS_*] / [0][AMT #] GNR-4.3.3 (24 algos)
- * - .165: [CxmtDdrTest] / [HD_*] / [0][AMEMDIAG #] GNR-4.3.0 (19 algos)
- * - 118.efi / PassMark MemTest86 Site / UEFI Shell / PXE
- */
- #include "stl_accel.h"
- #include <string.h>
- static inline uint8_t ascii_lower(uint8_t c) {
- return (c >= 'A' && c <= 'Z') ? (uint8_t)(c + 32) : c;
- }
- static int parse_i32_at(const uint8_t *p, const uint8_t *end, int32_t *out, const uint8_t **after) {
- while (p < end && (*p == ' ' || *p == '\t' || *p == ':' || *p == '=' || *p == '#')) {
- p++;
- }
- if (p >= end) return 0;
- int neg = 0;
- if (*p == '-') { neg = 1; p++; }
- else if (*p == '+') { p++; }
- if (p >= end || *p < '0' || *p > '9') return 0;
- int64_t v = 0;
- while (p < end && *p >= '0' && *p <= '9') {
- v = v * 10 + (*p - '0');
- if (v > 0x7fffffffLL) v = 0x7fffffffLL;
- p++;
- }
- *out = neg ? (int32_t)(-v) : (int32_t)v;
- if (after) *after = p;
- return 1;
- }
- static int parse_hex64_at(const uint8_t *p, const uint8_t *end, uint64_t *out) {
- while (p < end && (*p == ' ' || *p == '\t' || *p == ':' || *p == '=')) p++;
- if (p + 2 <= end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) p += 2;
- if (p >= end) return 0;
- uint64_t v = 0;
- int digits = 0;
- while (p < end) {
- uint8_t c = *p;
- uint8_t d;
- if (c >= '0' && c <= '9') d = (uint8_t)(c - '0');
- else if (c >= 'a' && c <= 'f') d = (uint8_t)(c - 'a' + 10);
- else if (c >= 'A' && c <= 'F') d = (uint8_t)(c - 'A' + 10);
- else break;
- v = (v << 4) | d;
- digits++;
- p++;
- }
- if (digits == 0) return 0;
- if (p < end) {
- uint8_t nc = *p;
- if (nc == '_' ||
- (nc >= 'g' && nc <= 'z' && nc != 'h') ||
- (nc >= 'G' && nc <= 'Z' && nc != 'H') ||
- ((nc == 'h' || nc == 'H') && p + 1 < end &&
- ((p[1] >= '0' && p[1] <= '9') || (p[1] >= 'a' && p[1] <= 'z') || (p[1] >= 'A' && p[1] <= 'Z')))) {
- return 0;
- }
- }
- *out = v;
- return 1;
- }
- /* Extract leading [<cpu>] prefix common on Hovsee/CxmtDdrTest/AMT lines */
- static void extract_leading_bracket_cpu(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
- const uint8_t *p = s;
- while (p < end && (*p == '.' || *p == ' ' || *p == '\t')) p++;
- if (p + 3 <= end && p[0] == '[' && (p[1] == '0' || p[1] == '1') && p[2] == ']') {
- ev->cpu = (int8_t)(p[1] - '0');
- }
- }
- /* Extract N<cpu>.C<ch>[.D<dimm>][.SC<sub>][.R<rank>] topology token & RMT margins */
- static int extract_ncd_token_cols(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev, int *out_cols) {
- if (out_cols) *out_cols = 0;
- for (const uint8_t *p = s; p + 5 <= end; p++) {
- if ((p[0] == 'N' || p[0] == 'n') &&
- (p[1] >= '0' && p[1] <= '3') && p[2] == '.' &&
- (p[3] == 'C' || p[3] == 'c') && (p[4] >= '0' && p[4] <= '9')) {
- int cpu = p[1] - '0';
- const uint8_t *q = p + 4;
- int ch = 0;
- while (q < end && *q >= '0' && *q <= '9') {
- ch = ch * 10 + (*q - '0');
- q++;
- }
- if (cpu >= 0 && cpu <= 1 && ch >= 0 && ch <= 11) {
- ev->cpu = (int8_t)cpu;
- ev->channel = (int8_t)ch;
- while (q + 2 <= end && *q == '.') {
- if (q + 3 <= end && (q[1] == 'D' || q[1] == 'd') && q[2] >= '0' && q[2] <= '1') {
- ev->dimm = (int8_t)(q[2] - '0');
- q += 3;
- } else if (q + 4 <= end && (q[1] == 'S' || q[1] == 's') &&
- (q[2] == 'C' || q[2] == 'c') && q[3] >= '0' && q[3] <= '1') {
- q += 4;
- } else if (q + 3 <= end && (q[1] == 'R' || q[1] == 'r') && q[2] >= '0' && q[2] <= '9') {
- ev->rank = (int8_t)((q[2] - '0') & 3);
- q += 3;
- while (q < end && *q >= '0' && *q <= '9') q++;
- } else if (q + 3 <= end && (q[1] == 'L' || q[1] == 'l') && q[2] >= '0' && q[2] <= '9') {
- q += 3;
- while (q < end && *q >= '0' && *q <= '9') q++;
- } else if (q + 4 <= end && (q[1] == ' ' || q[1] == '\t') && (q[2] == 'A' || q[2] == 'a') && q[3] >= '0' && q[3] <= '9') {
- q += 4;
- while (q < end && *q >= '0' && *q <= '9') q++;
- } else if (q + 3 <= end && (q[1] == 'B' || q[1] == 'b') && q[2] >= '0' && q[2] <= '9') {
- int bk = 0;
- const uint8_t *bp = q + 2;
- while (bp < end && *bp >= '0' && *bp <= '9') {
- bk = bk * 10 + (*bp - '0');
- bp++;
- }
- if (bk >= 0 && bk < 32) {
- ev->bank = (int8_t)bk;
- }
- q = bp;
- } else {
- break;
- }
- }
- while (q < end && (*q == ' ' || *q == '\t')) q++;
- if (q < end && *q == ':') {
- q++;
- int32_t vals[4] = {0, 0, 0, 0};
- int got = 0;
- const uint8_t *nx = q;
- while (nx < end && got < 4) {
- while (nx < end && (*nx == ' ' || *nx == '\t')) nx++;
- if (nx < end && *nx == '*') {
- vals[got++] = 0;
- nx++;
- } else {
- int32_t mv = 0;
- if (parse_i32_at(nx, end, &mv, &nx)) {
- vals[got++] = mv;
- } else {
- break;
- }
- }
- }
- if (out_cols) *out_cols = got;
- if (got >= 4) {
- ev->val0 = vals[0];
- ev->val1 = vals[1];
- ev->val2 = vals[2];
- ev->val3 = vals[3];
- }
- }
- return 1;
- }
- }
- }
- return 0;
- }
- static int extract_ncd_token(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
- return extract_ncd_token_cols(s, end, ev, NULL);
- }
- static int match_ci_kw(const uint8_t *p, const uint8_t *end, const char *kw, const uint8_t **after) {
- size_t klen = strlen(kw);
- if ((size_t)(end - p) < klen) return 0;
- for (size_t i = 0; i < klen; i++) {
- if (ascii_lower(p[i]) != (uint8_t)kw[i]) return 0;
- }
- const uint8_t *q = p + klen;
- if (q < end && ((*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || *q == '_')) return 0;
- *after = q;
- return 1;
- }
- 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) {
- if (p > buf_start) {
- uint8_t prev = p[-1];
- if ((prev >= 'a' && prev <= 'z') || (prev >= 'A' && prev <= 'Z') || prev == '_') return 0;
- }
- return match_ci_kw(p, end, kw, after);
- }
- /*
- * Extract physical topology coordinates from BIOS/Training/AMT/MemTest86 lines.
- * Strictly enforces 0 <= bank < 32 (never trusts broken historical >= 32 bank analyses).
- */
- static void extract_coords_and_addr(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
- extract_leading_bracket_cpu(s, end, ev);
- int has_ncd = extract_ncd_token(s, end, ev);
- int has_explicit_dimm_coord = has_ncd;
- /* 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,...)" */
- for (const uint8_t *p = s; p + 6 <= end; p++) {
- if (!has_ncd && p + 11 <= end &&
- (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
- (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_'))) &&
- ascii_lower(p[0]) == 'c' && ascii_lower(p[1]) == 'p' && ascii_lower(p[2]) == 'u' &&
- (p[3] == '0' || p[3] == '1') && p[4] == '_' &&
- ascii_lower(p[5]) == 'd' && ascii_lower(p[6]) == 'i' && ascii_lower(p[7]) == 'm' && ascii_lower(p[8]) == 'm' &&
- p[9] == '_') {
- uint8_t ltr = p[10];
- uint8_t ul = (ltr >= 'a' && ltr <= 'z') ? (uint8_t)(ltr - 32) : ltr;
- int ok_after = (p + 11 == end) ||
- (!((p[11] >= 'a' && p[11] <= 'z') || (p[11] >= 'A' && p[11] <= 'Z') ||
- (p[11] >= '0' && p[11] <= '9') || p[11] == '_'));
- if (ok_after && ul >= 'A' && ul <= 'L') {
- ev->cpu = (int8_t)(p[3] - '0');
- ev->channel = (int8_t)(ul - 'A');
- if (ev->dimm < 0) ev->dimm = 0;
- has_explicit_dimm_coord = 1;
- }
- }
- if (!has_ncd && p + 9 <= end &&
- (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
- (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_'))) &&
- (p[0] == 'P' || p[0] == 'p') && (p[1] == '0' || p[1] == '1') && p[2] == '_' &&
- ascii_lower(p[3]) == 'd' && ascii_lower(p[4]) == 'i' && ascii_lower(p[5]) == 'm' && ascii_lower(p[6]) == 'm' &&
- p[7] == '_') {
- uint8_t ltr = p[8];
- uint8_t ul = (ltr >= 'a' && ltr <= 'z') ? (uint8_t)(ltr - 32) : ltr;
- if (ul >= 'A' && ul <= 'L') {
- int ok_after = (p + 9 == end) ||
- (p[9] == '0' || p[9] == '1') ||
- (!((p[9] >= 'a' && p[9] <= 'z') || (p[9] >= 'A' && p[9] <= 'Z') ||
- (p[9] >= '0' && p[9] <= '9') || p[9] == '_'));
- if (ok_after) {
- ev->cpu = (int8_t)(p[1] - '0');
- ev->channel = (int8_t)(ul - 'A');
- if (p + 9 < end && (p[9] == '0' || p[9] == '1')) {
- ev->dimm = (int8_t)(p[9] - '0');
- } else if (ev->dimm < 0) {
- ev->dimm = 0;
- }
- has_explicit_dimm_coord = 1;
- }
- }
- }
- if (!has_ncd && (p[0] == 'N' || p[0] == 'n') && (p[1] == '0' || p[1] == '1') &&
- p[2] == '-' && p[3] >= '0' && p[3] <= '9') {
- int32_t ch = -1, sl = -1;
- const uint8_t *nx = p + 3;
- if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
- ev->cpu = (int8_t)(p[1] - '0');
- ev->channel = (int8_t)ch;
- if (nx < end && *nx == '-') {
- if (parse_i32_at(nx + 1, end, &sl, &nx) && sl >= 0 && sl <= 1) {
- ev->dimm = (int8_t)sl;
- }
- }
- has_explicit_dimm_coord = 1;
- }
- }
- if (p + 8 > end) continue;
- if (!has_ncd && p[0] == '(' && (p[1] == 'P' || p[1] == 'p') && (p[2] == '0' || p[2] == '1') &&
- p[3] == ',' && (p[4] == 'C' || p[4] == 'c')) {
- int32_t ch = -1, sl = -1;
- const uint8_t *nx = p + 5;
- if (parse_i32_at(nx, end, &ch, &nx) && ch >= 0 && ch <= 11) {
- ev->cpu = (int8_t)(p[2] - '0');
- ev->channel = (int8_t)ch;
- if (nx + 2 < end && nx[0] == ',' && (nx[1] == 'S' || nx[1] == 's')) {
- if (parse_i32_at(nx + 2, end, &sl, &nx) && sl >= 0 && sl <= 1) {
- ev->dimm = (int8_t)sl;
- }
- }
- has_explicit_dimm_coord = 1;
- }
- }
- size_t tup_skip = 0;
- if (p + 28 <= end && memcmp(p, "(Channel,Slot,Rank,Bank,Row,", 28) == 0) {
- tup_skip = 28;
- } else if (p + 25 <= end && memcmp(p, "(Chan,Slot,Rank,Bank,Row,", 25) == 0) {
- tup_skip = 25;
- } else if (p + 16 <= end && memcmp(p, "(Ch,Sl,Rk,Bk,Rw,", 16) == 0) {
- tup_skip = 16;
- }
- if (tup_skip > 0) {
- const uint8_t *rp = memchr(p + tup_skip, ')', (size_t)(end - (p + tup_skip)));
- const uint8_t *nx = rp ? (rp + 1) : (p + tup_skip);
- while (nx < end && (*nx == ':' || *nx == '=' || *nx == ' ' || *nx == '\t' || *nx == '(')) {
- nx++;
- }
- int32_t c_ch = -1, c_sl = -1, c_rk = -1, c_bk = -1;
- if (parse_i32_at(nx, end, &c_ch, &nx) && nx < end && *nx == ',' &&
- parse_i32_at(nx + 1, end, &c_sl, &nx) && nx < end && *nx == ',' &&
- parse_i32_at(nx + 1, end, &c_rk, &nx) && nx < end && *nx == ',' &&
- parse_i32_at(nx + 1, end, &c_bk, &nx)) {
- if (!has_explicit_dimm_coord) {
- if (c_ch >= 12 && c_ch <= 23 && ev->cpu < 0) {
- ev->cpu = 1;
- ev->channel = (int8_t)(c_ch - 12);
- } else if (c_ch >= 0 && c_ch <= 11) {
- ev->channel = (int8_t)c_ch;
- }
- if (c_sl >= 0 && c_sl <= 1) ev->dimm = (int8_t)c_sl;
- }
- if (c_rk >= 0 && c_rk <= 3 && ev->rank < 0) ev->rank = (int8_t)c_rk;
- if (c_bk >= 0 && c_bk < 32 && ev->bank < 0) ev->bank = (int8_t)c_bk;
- }
- }
- if (!has_explicit_dimm_coord &&
- (p == s || (!((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
- (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_')))) {
- static const char *const cs_prefixes[] = {
- "channel/slot:",
- "channel-slot:",
- "chan/slot:",
- "chan-slot:",
- "ch/sl:",
- "ch-sl:"
- };
- const uint8_t *cs_nx = NULL;
- for (size_t k = 0; k < sizeof(cs_prefixes) / sizeof(cs_prefixes[0]); k++) {
- size_t plen = strlen(cs_prefixes[k]);
- if (p + plen <= end) {
- int eq = 1;
- for (size_t j = 0; j < plen; j++) {
- if (ascii_lower(p[j]) != (uint8_t)cs_prefixes[k][j]) {
- eq = 0;
- break;
- }
- }
- if (eq) {
- cs_nx = p + plen;
- break;
- }
- }
- }
- if (cs_nx) {
- while (cs_nx < end && (*cs_nx == ' ' || *cs_nx == '\t')) cs_nx++;
- if (cs_nx < end && *cs_nx >= '0' && *cs_nx <= '9') {
- int32_t c_ch = -1, c_sl = -1;
- if (parse_i32_at(cs_nx, end, &c_ch, &cs_nx) && c_ch >= 0 && c_ch <= 23) {
- if (c_ch >= 12 && ev->cpu < 0) {
- ev->cpu = 1;
- ev->channel = (int8_t)(c_ch - 12);
- } else if (c_ch <= 11) {
- ev->channel = (int8_t)c_ch;
- }
- if (cs_nx < end && (*cs_nx == '/' || *cs_nx == '-' || *cs_nx == ',') &&
- parse_i32_at(cs_nx + 1, end, &c_sl, &cs_nx) && c_sl >= 0 && c_sl <= 1) {
- ev->dimm = (int8_t)c_sl;
- }
- has_explicit_dimm_coord = 1;
- }
- }
- }
- }
- }
- int bg = -1;
- int ba = -1;
- int direct_bank = -1;
- int explicit_socket = -1;
- int fallback_cpu = -1;
- int ctrl_mc = -1;
- int raw_chid = -1;
- /* Check for 120.efi "/GNR ... Flag=<hex> ... Socket=<hex> ... MC=<hex> Channel=<hex> ..." (hex fields) */
- const uint8_t *gnr_pos = NULL;
- for (const uint8_t *p = s; p + 5 <= end; p++) {
- if (p[0] == '/' && p[1] == 'G' && p[2] == 'N' && p[3] == 'R' && (p[4] == ' ' || p[4] == '\t')) {
- gnr_pos = p;
- break;
- }
- }
- if (gnr_pos) {
- int gnr_mc = -1, gnr_nmmc = -1, gnr_ch = -1, gnr_nmch = -1;
- for (const uint8_t *p = gnr_pos + 5; p < end; p++) {
- if (p > gnr_pos && ((p[-1] >= 'a' && p[-1] <= 'z') || (p[-1] >= 'A' && p[-1] <= 'Z') ||
- (p[-1] >= '0' && p[-1] <= '9') || p[-1] == '_')) {
- continue;
- }
- const uint8_t *after = NULL;
- uint64_t hv = 0;
- if (!has_explicit_dimm_coord && match_ci_kw(p, end, "socket", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 1) explicit_socket = (int)hv;
- } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "mc", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 11) gnr_mc = (int)hv;
- } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "nmmc", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 11) gnr_nmmc = (int)hv;
- } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "channel", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 23) gnr_ch = (int)hv;
- } else if (!has_explicit_dimm_coord && match_ci_kw(p, end, "nmchannel", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 23) gnr_nmch = (int)hv;
- } else if (match_ci_kw(p, end, "dimm", &after) || match_ci_kw(p, end, "nmdimm", &after)) {
- if (ev->dimm < 0 && parse_hex64_at(after, end, &hv) && hv <= 1) ev->dimm = (int8_t)hv;
- } else if (match_ci_kw(p, end, "rank", &after) || match_ci_kw(p, end, "cs", &after)) {
- if (ev->rank < 0 && parse_hex64_at(after, end, &hv) && hv <= 3) ev->rank = (int8_t)hv;
- } else if (match_ci_kw(p, end, "bg", &after)) {
- if (parse_hex64_at(after, end, &hv) && hv <= 7) bg = (int)hv;
- } else if (match_ci_kw(p, end, "bank", &after)) {
- if (parse_hex64_at(after, end, &hv)) {
- if (hv <= 3) ba = (int)hv;
- else if (hv < 32) direct_bank = (int)hv;
- }
- }
- }
- if (!has_explicit_dimm_coord) {
- int eff_mc = (gnr_mc >= 0) ? gnr_mc : gnr_nmmc;
- int eff_ch = (gnr_ch >= 0) ? gnr_ch : gnr_nmch;
- /* Granite Rapids-AP has 12 M2M/MCs (MC 0..11) x 1 sub-MC channel (Channel 0) */
- if (eff_mc >= 0 && eff_mc <= 11 && eff_ch <= 0) {
- ev->channel = (int8_t)eff_mc;
- } else if (eff_mc == 0 && eff_ch >= 0 && eff_ch <= 11) {
- ev->channel = (int8_t)eff_ch;
- } else if (eff_mc > 0 && eff_ch > 0 && (eff_mc * 2 + eff_ch) <= 11) {
- ev->channel = (int8_t)(eff_mc * 2 + eff_ch);
- } else if (eff_ch >= 0 && eff_ch <= 11) {
- ev->channel = (int8_t)eff_ch;
- }
- }
- }
- const uint8_t *kw_scan_end = gnr_pos ? gnr_pos : end;
- for (const uint8_t *p = s; p < kw_scan_end; p++) {
- if (p > s) {
- uint8_t prev = p[-1];
- if ((prev >= 'a' && prev <= 'z') || (prev >= 'A' && prev <= 'Z') ||
- (prev >= '0' && prev <= '9') || prev == '_') {
- continue;
- }
- }
- const uint8_t *after = NULL;
- int32_t v = 0;
- if (!has_explicit_dimm_coord &&
- (match_ci_kw(p, kw_scan_end, "socket", &after) || match_ci_kw(p, kw_scan_end, "sock", &after) ||
- match_ci_kw(p, kw_scan_end, "scktid", &after) || match_ci_kw(p, kw_scan_end, "node", &after))) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 1) {
- explicit_socket = (int)v;
- }
- } else if (!has_explicit_dimm_coord && match_ci_kw(p, kw_scan_end, "cpu", &after)) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 1 && fallback_cpu < 0) {
- fallback_cpu = (int)v;
- }
- } else if (!has_explicit_dimm_coord &&
- (match_ci_kw(p, kw_scan_end, "ctrl", &after) || match_ci_kw(p, kw_scan_end, "mc", &after))) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 11) {
- ctrl_mc = (int)v;
- }
- } else if (!has_explicit_dimm_coord &&
- (match_ci_kw(p, kw_scan_end, "channel", &after) || match_ci_kw(p, kw_scan_end, "ch", &after) ||
- match_ci_kw(p, kw_scan_end, "chan", &after) ||
- (ev->channel < 0 && match_ci_kw(p, kw_scan_end, "chid", &after)))) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 23) {
- raw_chid = (int)v;
- if (v >= 12 && explicit_socket < 0) {
- explicit_socket = 1;
- ev->channel = (int8_t)(v - 12);
- } else if (v <= 11) {
- ev->channel = (int8_t)v;
- }
- }
- } else if (match_ci_kw(p, kw_scan_end, "dimm", &after) || match_ci_kw(p, kw_scan_end, "dimmslot", &after) ||
- match_ci_kw(p, kw_scan_end, "dimmsl", &after) ||
- match_ci_kw(p, kw_scan_end, "slot", &after) || match_ci_kw(p, kw_scan_end, "sl", &after)) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 23) {
- if (v <= 1) {
- if (ev->dimm < 0) ev->dimm = (int8_t)v;
- } else if (!has_explicit_dimm_coord && ev->channel < 0) {
- explicit_socket = (int)(v / 12);
- ev->channel = (int8_t)(v % 12);
- ev->dimm = 0;
- }
- }
- } else if (match_ci_kw(p, kw_scan_end, "rank", &after) || match_ci_kw(p, kw_scan_end, "dimmrank", &after) ||
- match_ci_kw(p, kw_scan_end, "dimmrk", &after)) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 3) {
- ev->rank = (int8_t)v;
- }
- } else if (match_ci_kw(p, kw_scan_end, "bankgroup", &after) || match_ci_kw(p, kw_scan_end, "bg", &after)) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL) && v >= 0 && v <= 7) {
- bg = (int)v;
- }
- } else if (match_ci_kw(p, kw_scan_end, "bank", &after) || match_ci_kw(p, kw_scan_end, "ba", &after)) {
- if (parse_i32_at(after, kw_scan_end, &v, NULL)) {
- if ((after - p) == 2 && v >= 0 && v <= 3) {
- ba = (int)v;
- } else if (v >= 0 && v < 32) {
- direct_bank = (int)v;
- }
- }
- } else if (match_ci_kw(p, kw_scan_end, "addr", &after) || match_ci_kw(p, kw_scan_end, "address", &after) ||
- match_ci_kw(p, kw_scan_end, "checkpoint", &after)) {
- uint64_t a = 0;
- if (parse_hex64_at(after, kw_scan_end, &a)) {
- ev->addr = a;
- }
- }
- }
- if (!has_explicit_dimm_coord) {
- if (!gnr_pos && ctrl_mc > 0 && ctrl_mc <= 11 && raw_chid == 0) {
- ev->channel = (int8_t)ctrl_mc;
- }
- if (explicit_socket >= 0 && explicit_socket <= 1) {
- ev->cpu = (int8_t)explicit_socket;
- } else if (!gnr_pos && fallback_cpu >= 0 && fallback_cpu <= 1 && ev->cpu < 0) {
- ev->cpu = (int8_t)fallback_cpu;
- }
- }
- if (bg >= 0 && ba >= 0) {
- int combined = bg * 4 + ba;
- if (combined >= 0 && combined < 32) ev->bank = (int8_t)combined;
- } else if (direct_bank >= 0 && direct_bank < 32 && ev->bank < 0) {
- ev->bank = (int8_t)direct_bank;
- }
- }
- static void trim_ws(const uint8_t **ps, const uint8_t **pe) {
- const uint8_t *s = *ps;
- const uint8_t *e = *pe;
- while (s < e && (*s == ' ' || *s == '\t')) s++;
- while (e > s && (e[-1] == ' ' || e[-1] == '\t' || e[-1] == '\r' || e[-1] == '\n')) e--;
- *ps = s;
- *pe = e;
- }
- /*!re2c
- re2c:define:YYCTYPE = uint8_t;
- re2c:yyfill:enable = 0;
- re2c:flags:tags = 0;
- re2c:flags:case-insensitive = 0;
- WS = [ \t]*;
- ANY = [\x00-\xff];
- DIG = [0-9]+;
- */
- static uint32_t re2c_scan_token(const uint8_t *s, const uint8_t *end, StlRe2cEvent *ev) {
- uint8_t buf[1025];
- size_t n = (size_t)(end - s);
- if (n > 1024) n = 1024;
- memcpy(buf, s, n);
- buf[n] = 0;
- extract_leading_bracket_cpu(buf, buf + n, ev);
- const uint8_t *YYCURSOR = buf;
- const uint8_t *YYMARKER = buf;
- const uint8_t *lim = buf + n;
- /* Step 1: Anchored prompt & full-line patterns */
- /*!re2c
- WS "UIP>" WS "\x00" {
- return STL_LK_ICT_PROMPT;
- }
- WS "[" [01] "][" ("Hovsee" | "CxmtDdrTest") "]Please input your command" ":"? WS "\x00" {
- /* ev->cpu already parsed accurately with leading whitespace by extract_leading_bracket_cpu */
- for (size_t i = 0; i + 6 <= n; i++) {
- if (memcmp(buf + i, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
- if (i + 11 <= n && memcmp(buf + i, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
- }
- return STL_LK_ICT_PROMPT;
- }
- WS (("[" [01] "]" WS) | ("CPU" [01] WS ":"? WS))? "[" ("CPU" [01] WS)? ("AMT" | "AMEMDIAG") WS "#" WS "]" WS "\x00" {
- for (size_t i = 0; i + 3 <= n; i++) {
- if (buf[i] == '[' && (buf[i+1] == '0' || buf[i+1] == '1') && buf[i+2] == ']') {
- ev->cpu = (int8_t)(buf[i+1] - '0');
- }
- if (i + 4 <= n && buf[i] == 'C' && buf[i+1] == 'P' && buf[i+2] == 'U' && (buf[i+3] == '0' || buf[i+3] == '1')) {
- ev->cpu = (int8_t)(buf[i+3] - '0');
- }
- if (i + 8 <= n && memcmp(buf + i, "AMEMDIAG", 8) == 0) ev->fw_family = 2;
- else if (memcmp(buf + i, "AMT", 3) == 0 && ev->fw_family == 0) ev->fw_family = 1;
- }
- return STL_LK_AMT_PROMPT;
- }
- WS "FS" [0-9] ":\\" ("EFI" | "efi") ("\\" [^\x00\r\n<>]*)? ">" WS "\x00" |
- WS "FS" [0-9] ":\\" ("EFI" | "efi") ">" WS "\x00" {
- for (size_t i = 0; i + 2 < n; i++) {
- if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
- ev->fs_index = (uint8_t)(buf[i+2] - '0');
- break;
- }
- }
- return STL_LK_UEFI_PROMPT_EFI;
- }
- WS "FS" [0-9] ":" "\\"? ">" WS "\x00" {
- for (size_t i = 0; i + 2 < n; i++) {
- if (buf[i] == 'F' && buf[i+1] == 'S' && buf[i+2] >= '0' && buf[i+2] <= '9') {
- ev->fs_index = (uint8_t)(buf[i+2] - '0');
- break;
- }
- }
- return STL_LK_UEFI_PROMPT_ROOT;
- }
- WS "Shell>" WS "\x00" {
- ev->fs_index = 255;
- return STL_LK_UEFI_PROMPT_ROOT;
- }
- * { goto scan_anywhere; }
- */
- scan_anywhere:
- YYCURSOR = buf;
- while (YYCURSOR < lim) {
- const uint8_t *tok = YYCURSOR;
- /*!re2c
- "[" ("SYS_" | "HS_") "BIOS]Version:" {
- if (tok[1] == 'H') ev->fw_family = 1;
- return STL_LK_BIOS_BOOT;
- }
- "[BIOS][Vref]" | "[CHIPID]" | "[SPD_MR]" | "[SPD_CRC]" {
- return STL_LK_NONE;
- }
- "Welcome to Hovsee" | "Hovsee inc. IMC Config Tool" {
- ev->fw_family = 1;
- return STL_LK_ICT_BANNER_HOVSEE;
- }
- "Welcome to CxmtDdrTest" | "CxmtDdrTest IMC Config Tool" {
- ev->fw_family = 2;
- return STL_LK_ICT_BANNER_CXMT;
- }
- "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "1" {
- ev->fw_family = (tok[1] == 'H') ? 1 : 2;
- return STL_LK_ICT_START_STAGE1;
- }
- "[" ("Hovsee" | "CxmtDdrTest") "]Current stage is" WS "2" {
- ev->fw_family = (tok[1] == 'H') ? 1 : 2;
- return STL_LK_ICT_START_STAGE2;
- }
- "[Hovsee]Stage2 UIP" {
- ev->fw_family = 1;
- return STL_LK_ICT_START_STAGE2;
- }
- "[CxmtDdrTest]Stage2 UIP" {
- ev->fw_family = 2;
- return STL_LK_ICT_START_STAGE2;
- }
- "[Hovsee]Start UIP" {
- ev->fw_family = 1;
- return STL_LK_ICT_START_STAGE1;
- }
- "[CxmtDdrTest]Start UIP" {
- ev->fw_family = 2;
- return STL_LK_ICT_START_STAGE1;
- }
- "Please press ENTER to start UIP" {
- return STL_LK_ICT_ENTER_HINT;
- }
- "[" ("Hovsee" | "CxmtDdrTest") "]Please input your command" {
- ev->fw_family = (tok[1] == 'H') ? 1 : 2;
- /* Only prompt if no trailing user command echo on same line */
- const uint8_t *colon = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
- if (!colon || colon + 1 >= lim) return STL_LK_ICT_PROMPT;
- continue;
- }
- "[Hovsee]Exit UIP" | "[CxmtDdrTest]Exit UIP" |
- "[Hovsee]Exit Uip ddr test" | "[CxmtDdrTest]Exit Uip ddr test" |
- "[Hovsee]Exit Hovsee UIP" | "[CxmtDdrTest]Exit CxmtDdrTest UIP" |
- "[Hovsee]Exit ICT ddr test" | "[CxmtDdrTest]Exit ICT ddr test" |
- "No command input or timeout, so go on training" |
- "User input command is exit" {
- if (tok[0] == '[' && tok[1] == 'H') ev->fw_family = 1;
- if (tok[0] == '[' && tok[1] == 'C') ev->fw_family = 2;
- return STL_LK_ICT_EXIT;
- }
- "is not recognized as an internal or external command" {
- ev->subkind = 3; /* UEFI shell missing binary error */
- return STL_LK_MT_FAIL_COMPLETE;
- }
- "AdvancedMemTestWorker" | "GNR AP Gpio" | "SetVMGpioMemTest" | "DdrMemTest()" {
- for (const uint8_t *p = buf; p + 6 <= lim; p++) {
- if (memcmp(p, "Hovsee", 6) == 0) { ev->fw_family = 1; break; }
- if (p + 11 <= lim && memcmp(p, "CxmtDdrTest", 11) == 0) { ev->fw_family = 2; break; }
- }
- return STL_LK_NONE;
- }
- "[HS_MRC]" | "[HD_MRC]" |
- "[HS_StartMemTrain]" | "[HD_StartMemTrain]" |
- "[Hovsee]Socket " [01] " RcdQcaTraining" {
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'o') ev->fw_family = 1;
- return STL_LK_MRC_START;
- }
- "STOP_MRC_RUN" | "MRC Done" | "Memory Training Complete" |
- "[HS_EndMemTrain]" | "[HD_EndMemTrain]" {
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
- return STL_LK_MRC_DONE;
- }
- "0x4F : DXE IPL Start" | "0x60 : DXE Core Started" |
- "0x90 : BDS Started" | "0x91 : Connecting Drivers" {
- ev->subkind = 4; /* POST / DXE milestone */
- return STL_LK_MRC_DONE;
- }
- ("AMT" | "AMEMDIAG") WS "Test Start" {
- ev->fw_family = (tok[0] == 'A' && tok[1] == 'M' && tok[2] == 'E') ? 2 : 1;
- ev->subkind = 3; /* AMT start */
- return STL_LK_AMT_PROGRESS;
- }
- "[" ("HS_" | "") "BIOS][Training][ScktId:" WS [01] "]" {
- if (tok[1] == 'H') ev->fw_family = 1;
- extract_coords_and_addr(s, end, ev);
- int is_pipe_sync_sbsp = 0;
- for (const uint8_t *p = YYCURSOR; p + 20 <= lim; p++) {
- if (memcmp(p, "Pipe Sync SBSP Status", 21) == 0) {
- is_pipe_sync_sbsp = 1;
- break;
- }
- }
- /* Check if Rank Margin Tool or MemTest or FAILED (excluding benign SNC/Pipe Sync SBSP Status reset notice) */
- for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
- if (p + 16 <= lim && memcmp(p, "Rank Margin Tool", 16) == 0) {
- for (const uint8_t *q = p + 16; q + 6 <= lim; q++) {
- if (memcmp(q, "FAILED", 6) == 0) {
- ev->subkind = 2;
- return STL_LK_TRAINING_ERROR;
- }
- if (q + 7 <= lim && memcmp(q, "Started", 7) == 0) {
- return STL_LK_RMT_START;
- }
- if (q + 7 <= lim && (memcmp(q, "Skipped", 7) == 0 || memcmp(q, "SKIPPED", 7) == 0)) {
- ev->subkind = 3;
- return STL_LK_RMT_STOP;
- }
- if (q + 8 <= lim && (memcmp(q, "Disabled", 8) == 0 || memcmp(q, "DISABLED", 8) == 0)) {
- ev->subkind = 3;
- return STL_LK_RMT_STOP;
- }
- if (q + 9 <= lim && memcmp(q, "SUCCEEDED", 9) == 0) {
- ev->subkind = 1;
- return STL_LK_RMT_STOP;
- }
- }
- return STL_LK_RMT_STOP;
- }
- if (!is_pipe_sync_sbsp && memcmp(p, "FAILED", 6) == 0) {
- ev->subkind = 2;
- return STL_LK_TRAINING_ERROR;
- }
- }
- return STL_LK_MRC_START;
- }
- "START_RMT_N" [01] {
- ev->cpu = (int8_t)(tok[11] - '0');
- return STL_LK_RMT_START;
- }
- "START_RMT" | "Starting RMT test v" | "Rank Margin Tool -- Started" |
- "[HS_StartRmt]" | "[HD_StartRmt]" {
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') ev->fw_family = 1;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_RMT_START;
- }
- "STOP_RMT_N" [01] {
- ev->cpu = (int8_t)(tok[10] - '0');
- return STL_LK_RMT_STOP;
- }
- "STOP_RMT" | "[HS_StopRmt]" | "[HD_StopRmt]" | "RMT test v" {
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'S') {
- ev->fw_family = 1;
- return STL_LK_RMT_STOP;
- }
- if (tok[0] == '[' && tok[1] == 'H' && tok[2] == 'D') {
- return STL_LK_RMT_STOP;
- }
- for (const uint8_t *p = tok; p + 8 <= lim; p++) {
- if (memcmp(p, "complete", 8) == 0) {
- return STL_LK_RMT_STOP;
- }
- }
- if (tok[0] == 'S') return STL_LK_RMT_STOP;
- continue;
- }
- "[" ("HS" | "HD") "_" ("RMTSensor" | "Sensor") "]" {
- if (tok[2] == 'S') ev->fw_family = 1;
- extract_ncd_token(s, end, ev);
- const uint8_t *cl = memchr(YYCURSOR, ':', (size_t)(lim - YYCURSOR));
- if (cl) {
- int32_t deg = 0;
- const uint8_t *nx = NULL;
- if (parse_i32_at(cl + 1, lim, °, &nx)) {
- int32_t tenths = 0;
- if (nx && nx + 1 < lim && *nx == '.' && nx[1] >= '0' && nx[1] <= '9') {
- tenths = nx[1] - '0';
- }
- ev->val3 = deg * 10 + (deg >= 0 ? tenths : -tenths);
- }
- }
- return STL_LK_INLINE_TEMP;
- }
- "[" ("HS" | "HD") "_NODIMM]" {
- if (tok[2] == 'S') ev->fw_family = 1;
- extract_coords_and_addr(s, end, ev);
- ev->subkind = 0; /* explicitly absent */
- ev->val1 = 1; /* PEI DRAM inventory marker */
- return STL_LK_DIMM_INVENTORY;
- }
- "[" ("HS" | "HD") "_DRAM]" {
- if (tok[2] == 'S') ev->fw_family = 1;
- extract_coords_and_addr(s, end, ev);
- /* Check Size:0 or absent/empty/not-installed -> absent, else present */
- ev->subkind = 4;
- ev->val1 = 1; /* PEI DRAM inventory marker */
- for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_word(YYCURSOR, p, lim, "size", &af)) {
- int32_t sz = 0;
- if (parse_i32_at(af, lim, &sz, NULL)) {
- ev->subkind = (sz > 0) ? 4 : 0;
- ev->val0 = sz;
- break;
- }
- }
- if (match_ci_word(YYCURSOR, p, lim, "not installed", &af) ||
- match_ci_word(YYCURSOR, p, lim, "not present", &af) ||
- match_ci_word(YYCURSOR, p, lim, "no dimm", &af) ||
- match_ci_word(YYCURSOR, p, lim, "absent", &af) ||
- match_ci_word(YYCURSOR, p, lim, "empty", &af) ||
- match_ci_word(YYCURSOR, p, lim, "unpopulated", &af)) {
- ev->subkind = 0;
- break;
- }
- }
- return STL_LK_DIMM_INVENTORY;
- }
- "[" ("HS" | "HD") "_Disable" ("Dimm" | "DIMM") "]" | "DisableDIMM()" | "MapOutDimm()" | "Mapping out DDR" {
- extract_coords_and_addr(s, end, ev);
- ev->subkind = 3; /* disabled */
- return STL_LK_DIMM_INVENTORY;
- }
- "AMT Version " | "Welcome to Advanced Memory Test" | "GNR-4.3.3" {
- ev->fw_family = 1;
- return STL_LK_AMT_BANNER;
- }
- "AMEMDIAG Version " | "Welcome to Advanced Memory Diagnostic" | "GNR-4.3.0" {
- ev->fw_family = 2;
- return STL_LK_AMT_BANNER;
- }
- ("AMT" | "AMEMDIAG") WS "Test Algo Count:" {
- int32_t cnt = 0;
- if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
- ev->val1 = cnt; /* algorithm count */
- }
- ev->subkind = 0;
- return STL_LK_AMT_SUMMARY;
- }
- ("AMT" | "AMEMDIAG") WS "Test Result Summary:" |
- ("AMT" | "AMEMDIAG") WS "Test Result:" |
- "AMT Test PASS" | "AMEMDIAG Test PASS" | "All Test PASS" |
- "AMT Test FAIL" | "AMEMDIAG Test FAIL" | "All Test FAIL" {
- extract_coords_and_addr(s, end, ev);
- /* Determine scope: summary vs per-socket */
- for (const uint8_t *p = tok; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "summary", &af)) {
- ev->val2 = 1; /* scope = summary */
- }
- if (match_ci_kw(p, lim, "fail", &af) || match_ci_kw(p, lim, "block", &af)) {
- ev->subkind = 2;
- } else if (match_ci_kw(p, lim, "pass", &af) && ev->subkind != 2) {
- ev->subkind = 1;
- }
- }
- return STL_LK_AMT_SUMMARY;
- }
- "Total Error Count" {
- int32_t cnt = 0;
- if (parse_i32_at(YYCURSOR, lim, &cnt, NULL)) {
- ev->val0 = cnt;
- ev->subkind = (cnt > 0) ? 2 : 1;
- }
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_SUMMARY;
- }
- "[" ("AMT" | "AMEMDIAG") WS DIG "/" DIG WS DIG "/" DIG WS DIG "/" DIG "]" {
- /* e.g. [0][AMT 1/1 1/1 3/24] Algo ... */
- ev->fw_family = (tok[1] == 'A' && tok[2] == 'M' && tok[3] == 'E') ? 2 : 1;
- const uint8_t *p = tok + 4;
- while (p < YYCURSOR && (*p < '0' || *p > '9')) p++;
- int32_t r1=0, r2=0, p1=0, p2=0, a1=0, a2=0;
- if (parse_i32_at(p, YYCURSOR, &r1, &p) && p < YYCURSOR && *p == '/' &&
- parse_i32_at(p+1, YYCURSOR, &r2, &p) &&
- parse_i32_at(p, YYCURSOR, &p1, &p) && p < YYCURSOR && *p == '/' &&
- parse_i32_at(p+1, YYCURSOR, &p2, &p) &&
- parse_i32_at(p, YYCURSOR, &a1, &p) && p < YYCURSOR && *p == '/' &&
- parse_i32_at(p+1, YYCURSOR, &a2, &p)) {
- ev->val0 = a1; /* algorithm_index */
- ev->val1 = a2; /* algorithm_count */
- if (a2 > 0) ev->val2 = (a1 * 100) / a2;
- }
- return STL_LK_AMT_PROGRESS;
- }
- "Failure detected - Advanced Memtest" | "Failure detected - PPR Memtest" |
- "Data Compare Error" | "[AMT_ERR]" | "[AMEMDIAG_ERR]" |
- "AMT-Correctable error found" |
- "[" ("HS" | "HD") "_MemoryError]" {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_ERROR;
- }
- "Error Address" | "Fail Address" {
- uint64_t ea = 0;
- if (!parse_hex64_at(YYCURSOR, lim, &ea) || ea == 0) {
- continue;
- }
- ev->subkind = 2;
- ev->addr = ea;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_ERROR;
- }
- "Logical Rank" WS "=" | "Error on rising strobe:" | "Error on falling strobe:" {
- ev->subkind = 5; /* 3-line AMT diagnostic continuation */
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_ERROR;
- }
- ("[Parity Error]" | "[Parity]") WS "Test:" {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- "Failing DIMM" | "[BIOS][FailMode]" |
- "Training Fail" | "BIST Error" | "BIST FAIL" | "Uncorrectable" |
- "Correctable error threshold exceeded" | "Critical Margin Error" |
- "FatalError:" | "No Eye width" |
- "No eye found" | "smaller than minimum critical margin" | "RxPerBitDeskew Failure" |
- "Parity Error" | "Parity error" | "[Parity]" | "[Parity Error]" | "PEC Error" | "PEC error" {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_TRAINING_ERROR;
- }
- "UEFI Interactive Shell" {
- return STL_LK_UEFI_BANNER;
- }
- "Start PXE over IPv4" | "Downloading NBP file" | "NBP filename is" {
- ev->subkind = 0;
- return STL_LK_PXE_BOOT;
- }
- "NBP file downloaded successfully" | "LoadImage Status = Success" | "StartImage Status = Success" {
- ev->subkind = 1;
- return STL_LK_PXE_BOOT;
- }
- "PassMark MemTest86" | "MemTest86 V" | "MemTest86 v" |
- "Hovsee V" | "Hovsee v" |
- "Found configuration file:" | "*** TEST SESSION -" | "Launching 118.efi" |
- "STL_SIM TEST_START MT" {
- return STL_LK_MT_BANNER;
- }
- "STL_SIM TEST_RESULT " ("PASS" | "FAIL") {
- for (const uint8_t *p = tok; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "fail", &af)) {
- ev->subkind = 2;
- return STL_LK_MT_FAIL_COMPLETE;
- }
- }
- ev->subkind = 1;
- return STL_LK_MT_PASS_COMPLETE;
- }
- "[MEM ERROR" | "[Mem Error]" | "[ECC Errors]" | "[ECC Error]" |
- "[IBECC Errors]" | "[Scrub ECC Errors]" | "[Data Error]" | "ECC Error:" {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- "DIMM err count=" {
- int32_t cnt = 0;
- if (parse_i32_at(YYCURSOR, lim, &cnt, NULL) && cnt > 0) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- continue;
- }
- "Channel/Slot:" | "Channel-Slot:" |
- "/GNR " ("DDR(hex)" | "raw(hex)" | "Decode=") |
- "(Chan,Slot,Rank,Bank,Row," | "(Channel,Slot,Rank,Bank,Row," | "(Ch,Sl,Rk,Bk,Rw," {
- ev->subkind = 5; /* 2nd-line MT ECC/Data Error coordinate continuation */
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- "(" WS "Test" WS DIG WS "cumulative error count:" WS DIG {
- int32_t tid = 0, cnt = 0;
- const uint8_t *nx = NULL;
- const uint8_t *tpos = memchr(tok, 'T', (size_t)(YYCURSOR - tok));
- if (tpos && parse_i32_at(tpos + 4, YYCURSOR, &tid, &nx)) {
- const uint8_t *cl = memchr(nx ? nx : tok, ':', (size_t)(YYCURSOR - (nx ? nx : tok)));
- if (cl && parse_i32_at(cl + 1, lim, &cnt, NULL) && cnt > 0) {
- ev->subkind = 6; /* MemTest86 per-test cumulative error count */
- ev->val1 = tid;
- ev->val0 = cnt;
- return STL_LK_MT_ERROR;
- }
- }
- continue;
- }
- "Finished pass #" DIG WS "(of" WS DIG ")" {
- int32_t pno = 0, ptot = 0;
- const uint8_t *nx = NULL;
- if (parse_i32_at(tok + 15, lim, &pno, &nx)) {
- const uint8_t *ofp = memchr(tok + 15, 'f', (size_t)(lim - (tok + 15)));
- if (ofp) parse_i32_at(ofp + 1, lim, &ptot, NULL);
- }
- int32_t errs = 0;
- for (const uint8_t *p = YYCURSOR; p + 6 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "count", &af) || match_ci_kw(p, lim, "errors", &af)) {
- int32_t v = 0;
- if (parse_i32_at(af, lim, &v, NULL)) errs += v;
- }
- }
- ev->val0 = errs;
- if (ptot > 0 && pno >= ptot) {
- ev->subkind = (errs > 0) ? 2 : 1;
- return (errs > 0) ? STL_LK_MT_FAIL_COMPLETE : STL_LK_MT_PASS_COMPLETE;
- }
- ev->val2 = (ptot > 0) ? ((pno * 100) / ptot) : 50;
- return STL_LK_MT_PROGRESS;
- }
- ("#" WS)? "Tests Passed" WS ":" WS DIG "/" DIG {
- int32_t passed = 0, total = 0;
- const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
- const uint8_t *nx = NULL;
- if (cl && parse_i32_at(cl + 1, YYCURSOR, &passed, &nx)
- && nx && nx < YYCURSOR && *nx == '/'
- && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
- if (passed == total) {
- ev->subkind = 1;
- ev->val0 = 0;
- return STL_LK_MT_PASS_COMPLETE;
- }
- ev->val0 = passed;
- ev->val1 = total;
- ev->val2 = (passed * 100) / total;
- return STL_LK_MT_PROGRESS;
- }
- continue;
- }
- ("#" WS)? "Tests Completed" WS ":" WS DIG "/" DIG {
- int32_t done = 0, total = 0;
- const uint8_t *cl = memchr(tok, ':', (size_t)(YYCURSOR - tok));
- const uint8_t *nx = NULL;
- if (cl && parse_i32_at(cl + 1, YYCURSOR, &done, &nx)
- && nx && nx < YYCURSOR && *nx == '/'
- && parse_i32_at(nx + 1, YYCURSOR, &total, NULL) && total > 0) {
- ev->val0 = done;
- ev->val1 = total;
- ev->val2 = (done * 100) / total;
- return STL_LK_MT_PROGRESS;
- }
- continue;
- }
- ("#" WS)? "Bits in Error" WS ":" WS "Total" WS ":" WS DIG {
- int32_t cnt = 0;
- const uint8_t *tpos = NULL;
- for (const uint8_t *p = tok; p + 5 <= YYCURSOR; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, YYCURSOR, "total", &af)) {
- tpos = af;
- break;
- }
- }
- if (tpos) {
- const uint8_t *cl = memchr(tpos, ':', (size_t)(YYCURSOR - tpos));
- if (cl && parse_i32_at(cl + 1, YYCURSOR, &cnt, NULL) && cnt > 0) {
- ev->subkind = 6;
- ev->val0 = cnt;
- ev->val1 = 99;
- return STL_LK_MT_ERROR;
- }
- }
- continue;
- }
- ("Test Result" | "Test result" | "Result") WS ":" WS (("INCOMPLETE" | "Incomplete" | "incomplete") WS)? ("PASS" | "Pass" | "pass" | "FAIL" | "Fail" | "fail" | "FAILED" | "Failed" | "failed") {
- for (const uint8_t *p = tok; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "fail", &af) ||
- match_ci_kw(p, lim, "failed", &af)) {
- ev->subkind = 2;
- return STL_LK_MT_FAIL_COMPLETE;
- }
- if (match_ci_kw(p, lim, "pass", &af)) {
- ev->subkind = 1;
- return STL_LK_MT_PASS_COMPLETE;
- }
- }
- continue;
- }
- "Pass complete, no errors" {
- ev->subkind = 1;
- ev->val0 = 0;
- return STL_LK_MT_PASS_COMPLETE;
- }
- "Test Complete" {
- extract_coords_and_addr(s, end, ev);
- for (const uint8_t *p = YYCURSOR; p + 5 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "errors", &af) || match_ci_kw(p, lim, "error", &af)) {
- int32_t ec = 0;
- if (parse_i32_at(af, lim, &ec, NULL) && ec >= 0) {
- ev->val0 = ec;
- break;
- }
- }
- }
- if (ev->val0 > 0) {
- ev->subkind = 2;
- return STL_LK_MT_FAIL_COMPLETE;
- }
- for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "fail", &af)) {
- ev->subkind = 2;
- return STL_LK_MT_FAIL_COMPLETE;
- }
- }
- ev->subkind = 1;
- return STL_LK_MT_PASS_COMPLETE;
- }
- "Running test #" DIG {
- int32_t tid = 0;
- if (parse_i32_at(tok + 14, lim, &tid, NULL)) {
- ev->val0 = tid;
- ev->val1 = 25;
- ev->val2 = (tid >= 0 && tid <= 25) ? ((tid * 100) / 26) : 50;
- }
- return STL_LK_MT_PROGRESS;
- }
- "N" [01] ".C" DIG (".D" [01])? (".SC" [01])? ".R" DIG (".L" DIG | "." WS "A" DIG)? (".B" DIG)? WS ":" {
- int mcols = 0;
- extract_ncd_token_cols(s, end, ev, &mcols);
- for (const uint8_t *q = YYCURSOR; q + 4 <= lim; q++) {
- const uint8_t *af = NULL;
- if (match_ci_word(YYCURSOR, q, lim, "advanced memtest", &af) ||
- match_ci_word(YYCURSOR, q, lim, "failure detected", &af) ||
- match_ci_word(YYCURSOR, q, lim, "ppr memtest", &af)) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_ERROR;
- }
- if (match_ci_word(YYCURSOR, q, lim, "error", &af) ||
- match_ci_word(YYCURSOR, q, lim, "failed", &af) ||
- match_ci_word(YYCURSOR, q, lim, "fail", &af)) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_TRAINING_ERROR;
- }
- }
- if (mcols >= 4) {
- return STL_LK_RMT_ROW;
- }
- continue;
- }
- "N" [01] ".C" DIG ".D" [01] {
- extract_ncd_token(s, end, ev);
- for (const uint8_t *q = tok; q + 11 <= lim; q++) {
- const uint8_t *af_por = NULL;
- if (match_ci_word(tok, q, lim, "minimum por", &af_por)) {
- ev->subkind = 4;
- return STL_LK_DIMM_INVENTORY;
- }
- }
- for (const uint8_t *p = tok; p + 11 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_word(tok, p, lim, "failure detected", &af) ||
- match_ci_word(tok, p, lim, "advanced memtest", &af) ||
- match_ci_word(tok, p, lim, "ppr memtest", &af)) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_AMT_ERROR;
- }
- }
- for (const uint8_t *p = tok; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_word(tok, p, lim, "disabled", &af)) {
- ev->subkind = 3;
- return STL_LK_DIMM_INVENTORY;
- }
- if (match_ci_word(tok, p, lim, "fail", &af) ||
- match_ci_word(tok, p, lim, "failed", &af) ||
- match_ci_word(tok, p, lim, "failure", &af) ||
- match_ci_word(tok, p, lim, "error", &af)) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_TRAINING_ERROR;
- }
- }
- for (const uint8_t *p = tok; p + 3 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_word(tok, p, lim, "not", &af) ||
- match_ci_word(tok, p, lim, "empty", &af) ||
- match_ci_word(tok, p, lim, "absent", &af) ||
- match_ci_word(tok, p, lim, "unpopulated", &af) ||
- match_ci_word(tok, p, lim, "nodimm", &af)) {
- ev->subkind = 0;
- return STL_LK_DIMM_INVENTORY;
- }
- if (match_ci_word(tok, p, lim, "present", &af) ||
- match_ci_word(tok, p, lim, "ddr5", &af) ||
- match_ci_word(tok, p, lim, "enabled", &af) ||
- match_ci_word(tok, p, lim, "test", &af)) {
- ev->subkind = 4;
- return STL_LK_DIMM_INVENTORY;
- }
- }
- continue;
- }
- ("Test" DIG | "Test:" WS DIG) WS "Addr:" WS {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- "Test:" WS DIG {
- for (const uint8_t *p = YYCURSOR; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "expected", &af) ||
- match_ci_kw(p, lim, "actual", &af) ||
- match_ci_kw(p, lim, "addr", &af)) {
- ev->subkind = 2;
- extract_coords_and_addr(s, end, ev);
- return STL_LK_MT_ERROR;
- }
- }
- int32_t tnum = 0;
- const uint8_t *nx = NULL;
- if (parse_i32_at(tok + 5, lim, &tnum, &nx)) {
- ev->val0 = tnum;
- if (nx && nx < lim && *nx == '/') {
- int32_t ttot = 0;
- if (parse_i32_at(nx + 1, lim, &ttot, &nx)) ev->val1 = ttot;
- }
- }
- for (const uint8_t *p = YYCURSOR; p < lim; p++) {
- if (*p == '%' && p > buf && p[-1] >= '0' && p[-1] <= '9') {
- const uint8_t *dg = p - 1;
- while (dg > buf && dg[-1] >= '0' && dg[-1] <= '9') dg--;
- int32_t pct = 0;
- if (parse_i32_at(dg, p, &pct, NULL)) ev->val2 = pct;
- break;
- }
- }
- return STL_LK_MT_PROGRESS;
- }
- ("Test Pattern" | "Algo" WS "#" | "AlgoId") {
- extract_coords_and_addr(s, end, ev);
- int32_t aid = -1;
- if (parse_i32_at(YYCURSOR, lim, &aid, NULL) && aid >= 0) ev->val0 = aid;
- for (const uint8_t *p = buf; p + 4 <= lim; p++) {
- const uint8_t *af = NULL;
- if (match_ci_kw(p, lim, "fail", &af)) { ev->subkind = 2; break; }
- if (match_ci_kw(p, lim, "pass", &af)) { ev->subkind = 1; }
- }
- return STL_LK_AMT_PROGRESS;
- }
- ("BankGroup" | "SubRank") {
- ev->subkind = 5;
- extract_coords_and_addr(s, end, ev);
- if (ev->cpu >= 0 || ev->channel >= 0 || ev->bank >= 0) {
- return STL_LK_AMT_ERROR;
- }
- continue;
- }
- "\x00" { break; }
- ANY { continue; }
- */
- }
- return STL_LK_NONE;
- }
- void stl_re2c_parse_line(const uint8_t *line, size_t len, uint32_t tag_mask, StlRe2cEvent *ev) {
- memset(ev, 0, sizeof(*ev));
- ev->cpu = -1;
- ev->channel = -1;
- ev->dimm = -1;
- ev->rank = -1;
- ev->bank = -1;
- if (!line || len == 0) return;
- const uint8_t *s = line;
- const uint8_t *e = line + len;
- trim_ws(&s, &e);
- if (s >= e) return;
- if (tag_mask == 0 && s[0] == '.') {
- int only_dots = 1;
- for (const uint8_t *p = s; p < e; p++) {
- if (*p != '.' && *p != ' ' && *p != '\t') {
- only_dots = 0;
- break;
- }
- }
- if (only_dots) return;
- }
- ev->kind = re2c_scan_token(s, e, ev);
- }
- int stl_re2c_detect_halfline_prompt(const uint8_t *buf, size_t len, StlRe2cEvent *ev) {
- memset(ev, 0, sizeof(*ev));
- ev->cpu = -1;
- ev->channel = -1;
- ev->dimm = -1;
- ev->rank = -1;
- ev->bank = -1;
- if (!buf || len == 0) return 0;
- const uint8_t *s = buf;
- const uint8_t *e = buf + len;
- trim_ws(&s, &e);
- if (s >= e) return 0;
- uint32_t k = re2c_scan_token(s, e, ev);
- if (k == STL_LK_ICT_PROMPT || k == STL_LK_ICT_ENTER_HINT ||
- k == STL_LK_AMT_PROMPT || k == STL_LK_UEFI_PROMPT_EFI ||
- k == STL_LK_UEFI_PROMPT_ROOT) {
- ev->kind = k;
- return 1;
- }
- size_t tlen = (size_t)(e - s);
- if (tlen >= 4 && memcmp(e - 4, "UIP>", 4) == 0) {
- ev->kind = STL_LK_ICT_PROMPT;
- return 1;
- }
- if (tlen >= 26 && memcmp(e - 26, "Please input your command:", 26) == 0) {
- ev->kind = STL_LK_ICT_PROMPT;
- extract_leading_bracket_cpu(s, e, ev);
- return 1;
- }
- if (tlen >= 25 && memcmp(e - 25, "Please input your command", 25) == 0) {
- ev->kind = STL_LK_ICT_PROMPT;
- extract_leading_bracket_cpu(s, e, ev);
- return 1;
- }
- if (tlen >= 7 && memcmp(e - 7, "[AMT #]", 7) == 0) {
- ev->kind = STL_LK_AMT_PROMPT;
- ev->fw_family = 1;
- if (tlen >= 10 && e[-10] == '[' && (e[-9] == '0' || e[-9] == '1') && e[-8] == ']') {
- ev->cpu = (int8_t)(e[-9] - '0');
- }
- return 1;
- }
- if (tlen >= 12 && memcmp(e - 12, "[AMEMDIAG #]", 12) == 0) {
- ev->kind = STL_LK_AMT_PROMPT;
- ev->fw_family = 2;
- if (tlen >= 15 && e[-15] == '[' && (e[-14] == '0' || e[-14] == '1') && e[-13] == ']') {
- ev->cpu = (int8_t)(e[-14] - '0');
- }
- return 1;
- }
- if (tlen >= 6 && memcmp(e - 6, "Shell>", 6) == 0) {
- ev->kind = STL_LK_UEFI_PROMPT_ROOT;
- ev->fs_index = 255;
- return 1;
- }
- /* Check trailing FSx:\EFI\> or FSx:\> */
- if (tlen >= 6 && e[-1] == '>') {
- for (size_t i = (tlen > 24 ? tlen - 24 : 0); i + 4 < tlen; i++) {
- if (s[i] == 'F' && s[i+1] == 'S' && s[i+2] >= '0' && s[i+2] <= '9' && s[i+3] == ':') {
- ev->fs_index = (uint8_t)(s[i+2] - '0');
- for (size_t j = i + 4; j + 3 <= tlen; j++) {
- if ((s[j] == 'E' || s[j] == 'e') && (s[j+1] == 'F' || s[j+1] == 'f') &&
- (s[j+2] == 'I' || s[j+2] == 'i')) {
- ev->kind = STL_LK_UEFI_PROMPT_EFI;
- return 1;
- }
- }
- ev->kind = STL_LK_UEFI_PROMPT_ROOT;
- return 1;
- }
- }
- }
- return 0;
- }
|