diff options
Diffstat (limited to 'firmware/test/memory/test.y')
-rw-r--r-- | firmware/test/memory/test.y | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/firmware/test/memory/test.y b/firmware/test/memory/test.y deleted file mode 100644 index b3b39acc26..0000000000 --- a/firmware/test/memory/test.y +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | %{ | ||
2 | #include "memory.h" | ||
3 | #include "memory-page.h" | ||
4 | #include <stdlib.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | void allocate (int); | ||
8 | void release (int); | ||
9 | void spy (int); | ||
10 | void dump (void); | ||
11 | void prompt (void); | ||
12 | %} | ||
13 | |||
14 | %token NUMBER | ||
15 | %token ALLOCATE | ||
16 | %token RELEASE | ||
17 | %token DUMP | ||
18 | %token SPY | ||
19 | %token CHECK | ||
20 | %token INIT | ||
21 | %token QUIT | ||
22 | |||
23 | %left '+' '-' | ||
24 | %left '*' '/' | ||
25 | %nonassoc UMINUS | ||
26 | |||
27 | %% | ||
28 | commands | ||
29 | : command ';' | ||
30 | { } | ||
31 | | commands command ';' | ||
32 | { } | ||
33 | | error ';' | ||
34 | { yyerrok; } | ||
35 | ; | ||
36 | |||
37 | command | ||
38 | : allocate | ||
39 | | release | ||
40 | | spy | ||
41 | | check | ||
42 | | INIT | ||
43 | { memory_setup (); } | ||
44 | | DUMP | ||
45 | { dump (); } | ||
46 | | QUIT | ||
47 | { return 0; } | ||
48 | ; | ||
49 | |||
50 | allocate | ||
51 | : ALLOCATE expression | ||
52 | { allocate (yylval); } | ||
53 | ; | ||
54 | |||
55 | release | ||
56 | : RELEASE expression | ||
57 | { release (yylval); } | ||
58 | ; | ||
59 | |||
60 | spy | ||
61 | : SPY expression | ||
62 | { spy (yylval); } | ||
63 | ; | ||
64 | |||
65 | check | ||
66 | : CHECK expression | ||
67 | { __memory_check (yylval); } | ||
68 | ; | ||
69 | |||
70 | expression | ||
71 | : expression '+' expression | ||
72 | { $$ = $1 + $3; } | ||
73 | | expression '-' expression | ||
74 | { $$ = $1 - $3; } | ||
75 | | expression '*' expression | ||
76 | { $$ = $1 * $3; } | ||
77 | | expression '/' expression | ||
78 | { | ||
79 | if($3 == 0) | ||
80 | yyerror("divide by zero"); | ||
81 | else | ||
82 | $$ = $1 / $3; | ||
83 | } | ||
84 | | '-' expression %prec UMINUS | ||
85 | { | ||
86 | $$ = -$2; | ||
87 | } | ||
88 | | '(' expression ')' | ||
89 | { | ||
90 | $$ = $2; | ||
91 | } | ||
92 | | NUMBER | ||
93 | { | ||
94 | $$ = $1; | ||
95 | } | ||
96 | ; | ||
97 | |||
98 | %% | ||
99 | |||
100 | #include <readline/readline.h> | ||
101 | #include <readline/history.h> | ||
102 | |||
103 | int yyerror(char *s) | ||
104 | { | ||
105 | fprintf(stderr,"\nBad command"); | ||
106 | return 1; | ||
107 | } | ||
108 | |||
109 | void prompt (void) | ||
110 | { | ||
111 | printf("\n>"); fflush (stdout); | ||
112 | } | ||
113 | |||
114 | void allocate (int order) | ||
115 | { | ||
116 | void *address; | ||
117 | printf("\nallocating a page of %d bytes...",512<<order); | ||
118 | if ((unsigned)order > 21) | ||
119 | printf (" bad order !"); | ||
120 | else if ((address = memory_allocate_page (order))) | ||
121 | printf (" page #%d allocated !",((char *)address - (char *)__memory_free_page) >> 9); | ||
122 | else | ||
123 | printf (" cannot allocate a page !"); | ||
124 | } | ||
125 | |||
126 | void release (int page) | ||
127 | { | ||
128 | void *address = (void *)((char *)__memory_free_page + (page << 9)); | ||
129 | printf("\nreleasing page #%d...",page); | ||
130 | if ((unsigned)page >= (2*1024*1024/512)) | ||
131 | printf (" bad page number !"); | ||
132 | else if (memory_release_page (address)) | ||
133 | printf (" page #%d released !",page); | ||
134 | else | ||
135 | printf (" cannot release this page !"); | ||
136 | } | ||
137 | |||
138 | void spy (int page) | ||
139 | { | ||
140 | void *address = (void *)((char *)__memory_free_page + (page << 9)); | ||
141 | printf("\nspying page #%d...",page); | ||
142 | if ((unsigned)page >= (2*1024*1024/512)) | ||
143 | printf (" bad page number !"); | ||
144 | else | ||
145 | __memory_spy_page (address); | ||
146 | } | ||
147 | |||
148 | void dump (void) | ||
149 | { | ||
150 | int order; | ||
151 | printf("\ndumping free pages list..."); | ||
152 | for (order = 0; order < 13; ++order) | ||
153 | __memory_dump (order); | ||
154 | } | ||
155 | |||
156 | int main () | ||
157 | { | ||
158 | yyparse(); | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | int read_input (char *buffer,int max) | ||
163 | { | ||
164 | char *line = 0; | ||
165 | while (1) | ||
166 | { | ||
167 | line = readline ("\n>"); | ||
168 | if (!line) | ||
169 | break; | ||
170 | if (*line) | ||
171 | add_history(line); | ||
172 | strncpy (buffer,line,max); | ||
173 | strcat (buffer,";"); | ||
174 | free (line); | ||
175 | return strlen (buffer); | ||
176 | } | ||
177 | buffer[0] = ';'; | ||
178 | return 1; | ||
179 | } | ||
180 | |||