blob: f7b9ec0b61763ed2a1cea60082b521341c099c5f [file] [log] [blame]
Martin Roth9b1b3352016-02-24 12:27:06 -08001/* test.h - MemTest-86 Version 3.4
2 *
3 * Released under version 2 of the Gnu Public License.
4 * By Chris Brady
5 */
6
7#ifndef _TEST_H_
8#define _TEST_H_
9#define E88 0x00
10#define E801 0x04
11#define E820NR 0x08 /* # entries in E820MAP */
12#define E820MAP 0x0c /* our map */
13#define E820MAX 127 /* number of entries in E820MAP */
14#define E820ENTRY_SIZE 20
15#define MEMINFO_SIZE (E820MAP + E820MAX * E820ENTRY_SIZE)
16
17#ifndef __ASSEMBLY__
18
19#define E820_RAM 1
20#define E820_RESERVED 2
21#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
22#define E820_NVS 4
23
24struct e820entry {
25 unsigned long long addr; /* start of memory segment */
26 unsigned long long size; /* size of memory segment */
27 unsigned long type; /* type of memory segment */
28};
29
30struct mem_info_t {
31 unsigned long e88_mem_k; /* 0x00 */
32 unsigned long e801_mem_k; /* 0x04 */
33 unsigned long e820_nr; /* 0x08 */
34 struct e820entry e820[E820MAX]; /* 0x0c */
35 /* 0x28c */
36};
37
38typedef unsigned long ulong;
39#define STACKSIZE (8*1024)
40#define MAX_MEM 0x7FF00000 /* 8 TB */
41#define WIN_SZ 0x80000 /* 2 GB */
42#define UNMAP_SZ (0x100000-WIN_SZ) /* Size of umappped first segment */
43
44#define SPINSZ 0x4000000 /* 256 MB */
45#define MOD_SZ 20
Ben Gardnerb6621c32016-03-08 08:47:58 -060046#define BAILOUT do { if (bail) return(1); } while (0)
47#define BAILR do { if (bail) return; } while (0)
Martin Roth9b1b3352016-02-24 12:27:06 -080048
49#define RES_START 0xa0000
50#define RES_END 0x100000
51#define SCREEN_ADR 0xb8000
52#define SCREEN_END_ADR (SCREEN_ADR + 80*25*2)
53
54#define DMI_SEARCH_START 0x0000F000
55#define DMI_SEARCH_LENGTH 0x000F0FFF
56#define MAX_DMI_MEMDEVS 16
57
58#define TITLE_WIDTH 28
59#define LINE_TITLE 0
60#define LINE_TST 3
61#define LINE_RANGE 4
62#define LINE_PAT 5
63#define LINE_TIME 5
64#define LINE_STATUS 8
65#define LINE_INFO 9
66#define LINE_HEADER 12
67#define LINE_SCROLL 14
68#define LINE_SPD 14
69#define LINE_MSG 22
70#define LINE_CPU 7
71#define LINE_RAM 8
72#define LINE_DMI 23
73#define COL_INF1 15
74#define COL_INF2 32
75#define COL_INF3 51
76#define COL_INF4 70
77#define COL_MODE 15
78#define COL_MID 30
79#define COL_PAT 41
80#define BAR_SIZE (78-COL_MID-9)
81#define COL_MSG 23
82#define COL_TIME 67
83#define COL_SPEC 41
84
85#define POP_W 34
86#define POP_H 15
87#define POP_X 11
88#define POP_Y 8
89#define POP2_W 74
90#define POP2_H 21
91#define POP2_X 3
92#define POP2_Y 2
93
94/* CPU mode types */
95#define CPM_ALL 1
96#define CPM_RROBIN 2
97#define CPM_SEQ 3
98
99/* memspeed operations */
100#define MS_COPY 1
101#define MS_WRITE 2
102#define MS_READ 3
103
104#define SZ_MODE_BIOS 1
105#define SZ_MODE_PROBE 2
106
107#define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
108
109int memcmp(const void *s1, const void *s2, ulong count);
110void *memmove(void *dest, const void *src, ulong n);
111int strncmp(const char *s1, const char *s2, ulong n);
Ben Gardner3754fd42016-04-29 09:21:36 -0500112int strstr(const char *str1, const char *str2);
113int strlen(const char *string);
Martin Roth61ea5412016-03-07 20:58:18 -0700114int query_coreboot(void);
Martin Roth9b1b3352016-02-24 12:27:06 -0800115int query_pcbios(void);
Martin Roth8cc1aeb2016-02-24 13:03:52 -0800116int query_multiboot(void);
Martin Roth9b1b3352016-02-24 12:27:06 -0800117int insertaddress(ulong);
118void printpatn(void);
119void printpatn(void);
Martin Roth4dcd13d2016-02-24 13:53:07 -0800120void itoa(char s[], int n);
Martin Roth9b1b3352016-02-24 12:27:06 -0800121void reverse(char *p);
122void serial_console_setup(char *param);
123void serial_echo_init(void);
124void serial_echo_print(const char *s);
125void ttyprint(int y, int x, const char *s);
126void ttyprintc(int y, int x, char c);
127void cprint(int y,int x, const char *s);
128void cplace(int y,int x, const char s);
129void hprint(int y,int x, ulong val);
130void hprint2(int y,int x, ulong val, int len);
131void hprint3(int y,int x, ulong val, int len);
132void xprint(int y,int x,ulong val);
133void aprint(int y,int x,ulong page);
134void dprint(int y,int x,ulong val,int len, int right);
135void movinv1(int iter, ulong p1, ulong p2, int cpu);
136void movinvr(int cpu);
137void movinv32(int iter, ulong p1, ulong lb, ulong mb, int sval, int off,
138 int cpu);
139void modtst(int off, int iter, ulong p1, ulong p2, int cpu);
140void error(ulong* adr, ulong good, ulong bad);
141void ad_err1(ulong *adr1, ulong *adr2, ulong good, ulong bad);
142void ad_err2(ulong *adr, ulong bad);
143void do_tick();
144void init(void);
145struct eregs;
146void inter(struct eregs *trap_regs);
147void set_cache(int val);
148void check_input(void);
149void footer(void);
150void scroll(void);
151void clear_scroll(void);
Martin Roth5bb29b22016-03-27 20:51:17 -0600152extern char pop_save_buffer_1[2][POP_H][POP_W];
153extern char pop_save_buffer_2[2][POP2_H][POP2_W];
154#define POP_SAVE_BUFFER_1 POP_X, POP_Y, POP_H, POP_W, pop_save_buffer_1
155#define POP_SAVE_BUFFER_2 POP2_X, POP2_Y, POP2_H, POP2_W, pop_save_buffer_2
156void popup(int pop_x, int pop_y, int pop_h, int pop_w, char pop_save_buffer[2][pop_h][pop_w]);
157void popdown(int pop_x, int pop_y, int pop_h, int pop_w, char pop_save_buffer[2][pop_h][pop_w]);
158void popclear(int pop_x, int pop_y, int pop_h, int pop_w, char pop_save_buffer[2][pop_h][pop_w]);
Martin Roth9b1b3352016-02-24 12:27:06 -0800159void get_config(void);
160void get_menu(void);
161void get_printmode(void);
162void addr_tst1(int cpu);
163void addr_tst2(int cpu);
164int getnum(ulong val);
165void sleep(long sec, int flag, int cpu, int sms);
166void block_move(int iter, int cpu);
167void find_ticks(void);
168void print_err(ulong *adr, ulong good, ulong bad, ulong xor);
Martin Roth4dcd13d2016-02-24 13:53:07 -0800169void print_ecc_err(ulong page, ulong offset, int corrected,
Martin Roth9b1b3352016-02-24 12:27:06 -0800170 unsigned short syndrome, int channel);
171void mem_size(void);
172void adj_mem(void);
173ulong getval(int x, int y, int result_shift);
174int get_key(void);
175int ascii_to_keycode(int in);
176void wait_keyup(void);
177void print_hdr(void);
178void restart(void);
179void parity_err(ulong edi, ulong esi);
180void start_config(void);
181void clear_screen(void);
182void paging_off(void);
183void show_spd(void);
184int map_page(unsigned long page);
185void *mapping(unsigned long page_address);
186void *emapping(unsigned long page_address);
187int isdigit(char c);
188ulong memspeed(ulong src, ulong len, int iter);
189unsigned long page_of(void *ptr);
190ulong correct_tsc(ulong el_org);
191void bit_fade_fill(unsigned long n, int cpu);
192void bit_fade_chk(unsigned long n, int cpu);
193void find_ticks_for_pass(void);
194void beep(unsigned int frequency);
195
196#define PRINTMODE_SUMMARY 0
197#define PRINTMODE_ADDRESSES 1
198#define PRINTMODE_PATTERNS 2
199#define PRINTMODE_NONE 3
200
201#define BADRAM_MAXPATNS 10
202
203struct pair {
204 ulong adr;
205 ulong mask;
206};
207
208static inline void cache_off(void)
209{
210 asm(
211 "push %eax\n\t"
212 "movl %cr0,%eax\n\t"
213 "orl $0x40000000,%eax\n\t" /* Set CD */
214 "movl %eax,%cr0\n\t"
215 "wbinvd\n\t"
216 "pop %eax\n\t");
217}
218
219static inline void cache_on(void)
220{
221 asm(
222 "push %eax\n\t"
223 "movl %cr0,%eax\n\t"
Martin Roth4dcd13d2016-02-24 13:53:07 -0800224 "andl $0x9fffffff,%eax\n\t" /* Clear CD and NW */
Martin Roth9b1b3352016-02-24 12:27:06 -0800225 "movl %eax,%cr0\n\t"
226 "pop %eax\n\t");
227}
228
229struct mmap {
230 ulong pbase_addr;
231 ulong *start;
232 ulong *end;
233};
234
235struct pmap {
236 ulong start;
237 ulong end;
238};
239
240struct tseq {
241 short sel;
242 short cpu_sel;
243 short pat;
244 short iter;
245 short errors;
246 char *msg;
247};
248
249struct xadr {
250 ulong page;
251 ulong offset;
252};
253
254struct err_info {
255 struct xadr low_addr;
256 struct xadr high_addr;
257 unsigned long ebits;
258 long tbits;
259 short min_bits;
260 short max_bits;
261 unsigned long maxl;
262 unsigned long eadr;
263 unsigned long exor;
264 unsigned long cor_err;
265 short hdr_flag;
266};
267
268
269
270#define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */
271
272#define MAX_MEM_SEGMENTS E820MAX
273
Elyes HAOUAS54506bf2018-08-24 09:17:59 +0200274/* Define common variables across relocations of memtest86 */
Martin Roth9b1b3352016-02-24 12:27:06 -0800275struct vars {
276 int pass;
277 int msg_line;
278 int ecount;
279 int ecc_ecount;
280 int msegs;
281 int testsel;
282 int scroll_start;
283 int pass_ticks;
284 int total_ticks;
285 int pptr;
286 int tptr;
287 struct err_info erri;
288 struct pmap pmap[MAX_MEM_SEGMENTS];
289 volatile struct mmap map[MAX_MEM_SEGMENTS];
290 ulong plim_lower;
291 ulong plim_upper;
292 ulong clks_msec;
293 ulong starth;
294 ulong startl;
295 ulong snaph;
296 ulong snapl;
297 int printmode;
298 int numpatn;
299 struct pair patn [BADRAM_MAXPATNS];
300 ulong test_pages;
301 ulong selected_pages;
302 ulong reserved_pages;
303 int check_temp;
304 int fail_safe;
305 int each_sec;
306 int beepmode;
307};
308
309#define FIRMWARE_UNKNOWN 0
310#define FIRMWARE_PCBIOS 1
Martin Roth61ea5412016-03-07 20:58:18 -0700311#define FIRMWARE_COREBOOT 2
Martin Roth8cc1aeb2016-02-24 13:03:52 -0800312#define FIRMWARE_MULTIBOOT 3
Martin Roth9b1b3352016-02-24 12:27:06 -0800313
314extern struct vars * const v;
315extern unsigned char _start[], _end[], startup_32[];
316extern unsigned char _size, _pages;
317
318extern struct mem_info_t mem_info;
319
320#endif /* __ASSEMBLY__ */
321#endif /* _TEST_H_ */