| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176 |
- /*
- * 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);
- extract_ncd_token(s, end, ev);
- /* Check MemTest86 "CPU<0|1>_DIMM_<A..L>", "(P0,C3,S0,R0)", "Channel/Slot: N0-3-0", or "(Chan,Slot,Rank,Bank,Row,Col): (3,0,0,12,...)" */
- for (const uint8_t *p = s; p + 6 <= end; p++) {
- if (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;
- }
- }
- if ((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;
- }
- }
- }
- }
- if (p + 8 > end) continue;
- if (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;
- }
- }
- }
- }
- 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 (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 = (int8_t)c_rk;
- if (c_bk >= 0 && c_bk < 32) ev->bank = (int8_t)c_bk;
- }
- }
- if ((p + 6 <= end && (p[0] == 'C' || p[0] == 'c') && (p[1] == 'h' || p[1] == 'H') &&
- p[2] == '/' && (p[3] == 'S' || p[3] == 's') && (p[4] == 'l' || p[4] == 'L') && p[5] == ':')) {
- const uint8_t *nx = p + 6;
- while (nx < end && (*nx == ' ' || *nx == '\t')) nx++;
- if (nx < end && *nx >= '0' && *nx <= '9') {
- int32_t c_ch = -1, c_sl = -1;
- if (parse_i32_at(nx, end, &c_ch, &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 (nx < end && (*nx == '/' || *nx == '-' || *nx == ',') &&
- parse_i32_at(nx + 1, end, &c_sl, &nx) && c_sl >= 0 && c_sl <= 1) {
- ev->dimm = (int8_t)c_sl;
- }
- }
- }
- }
- }
- int bg = -1;
- int ba = -1;
- int direct_bank = -1;
- for (const uint8_t *p = s; p < 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 (match_ci_kw(p, end, "socket", &after) || match_ci_kw(p, end, "scktid", &after) ||
- match_ci_kw(p, end, "node", &after) || match_ci_kw(p, end, "cpu", &after)) {
- if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 1 && ev->cpu < 0) {
- ev->cpu = (int8_t)v;
- }
- } else if (match_ci_kw(p, end, "channel", &after) || match_ci_kw(p, end, "ch", &after) ||
- match_ci_kw(p, end, "chan", &after) ||
- (ev->channel < 0 && match_ci_kw(p, end, "chid", &after))) {
- if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 23) {
- if (v >= 12 && ev->cpu < 0) {
- ev->cpu = 1;
- ev->channel = (int8_t)(v - 12);
- } else if (v <= 11) {
- ev->channel = (int8_t)v;
- }
- }
- } else if (match_ci_kw(p, end, "dimm", &after) || match_ci_kw(p, end, "dimmslot", &after) ||
- match_ci_kw(p, end, "slot", &after) || match_ci_kw(p, end, "sl", &after)) {
- if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 23) {
- if (v <= 1) {
- ev->dimm = (int8_t)v;
- } else if (ev->channel < 0) {
- ev->cpu = (int8_t)(v / 12);
- ev->channel = (int8_t)(v % 12);
- ev->dimm = 0;
- }
- }
- } else if (match_ci_kw(p, end, "rank", &after) || match_ci_kw(p, end, "dimmrank", &after)) {
- if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 3) {
- ev->rank = (int8_t)v;
- }
- } else if (match_ci_kw(p, end, "bankgroup", &after) || match_ci_kw(p, end, "bg", &after)) {
- if (parse_i32_at(after, end, &v, NULL) && v >= 0 && v <= 7) {
- bg = (int)v;
- }
- } else if (match_ci_kw(p, end, "bank", &after) || match_ci_kw(p, end, "ba", &after)) {
- if (parse_i32_at(after, 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, end, "addr", &after) || match_ci_kw(p, end, "address", &after) ||
- match_ci_kw(p, end, "checkpoint", &after)) {
- uint64_t a = 0;
- if (parse_hex64_at(after, end, &a)) {
- ev->addr = a;
- }
- }
- }
- 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 = (int8_t)(buf[1] == '1' ? 1 : 0);
- 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) {
- 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") "_DRAM]" {
- if (tok[2] == 'S') ev->fw_family = 1;
- extract_coords_and_addr(s, end, ev);
- /* Check Size:0 -> absent, else present */
- ev->subkind = 4;
- for (const uint8_t *p = YYCURSOR; p + 5 <= lim; p++) {
- if (memcmp(p, "Size:", 5) == 0) {
- int32_t sz = 0;
- if (parse_i32_at(p + 5, lim, &sz, NULL)) {
- ev->subkind = (sz > 0) ? 4 : 0;
- ev->val0 = sz;
- }
- 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:" |
- "(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);
- 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)) {
- 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;
- }
|