-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
383 lines (333 loc) · 9.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include <stdint.h>
#include <pip/fpinfo.h>
#include <pip/paging.h>
#include <pip/vidt.h>
#include <pip/api.h>
#include <pip/compat.h>
#include <pip/debug.h>
#include "test.h"
#define BUFFSIZE 30
extern void* _fpart, *_efpart;
extern void* _disptpart, *_edisptpart;
int atests=0;/* number of achieved tests */
int tests=0; /*number of tests */
uint32_t *tpage, *atpage;
int used;
int length,lengthd,offset;
uint32_t BTVS[BUFFSIZE]; /* Buffer the vampire slayer : here to allocate memmory*/
volatile int currchild; /*tells if there is a child alive */
static const struct {uint32_t start, end;} fpart = {
(uint32_t)&_fpart, (uint32_t)&_efpart,
};
static const struct {uint32_t start, end;} disptpart = {
(uint32_t)&_disptpart, (uint32_t)&_edisptpart,
};
void AllocAll(){
used=0;
for(;used<BUFFSIZE;used++){
BTVS[used]=(uint32_t)Pip_AllocPage();
}
used=0;
}
INTERRUPT_HANDLER(timerAsm,timerHandler)
log1("DEBUG TOKEN",-1);
if(currchild!=0){
log1("entry resume timer\n",-1);
Pip_Resume(BTVS[0],1);
}
resume(0xFFFFFFFF,1);
}
/*
*
*
*
*/
INTERRUPT_HANDLER(PfaultAsm,PfaultHandler)
puts("Got page fault from ");
puthex(caller);
putc('\n');
puts("data1 ");
puthex(data1);
putc('\n');
puts("data 2 ");
puthex(data2);
putc('\n');
END_OF_INTERRUPT
/*
* The interruption triggering the Handler have to come from the child
* this interrupt allow me to test the deleting of Partitions
* atm i'm testing to delete one existing part, the same part but already deleted
* and a last part which never existed
*/
INTERRUPT_HANDLER(takebackAsm,takebackHandler)
/* getting back pages with tests info */
log1("Recovering page with testsinfo from Child ",-1);
if(!Pip_RemoveVAddr(BTVS[0],0x73C000)){
log1("Couldn't recover test counter memory from Child",-1);
//PANIC();
}
tests++;
if(deletePartition(BTVS[0])){
log1("Deleting Part : 0",1);
currchild--;
atests++;
}
else{
log1("Couldn't delete part",0);
}
tests++;
if(deletePartition(BTVS[0])){
log1("Was abble to deleted again the child 0",0);
}
else{
log1("Couldn't delete once again the child",1);
atests++;
}
tests++;
if(deletePartition(BTVS[5])){
log1("Succeded to delete inexisting partition ",0);
}
else{
log1("Infructuous attenpt to delete inexisting partition ",1);
atests++;
}
resume(0xFFFFFFFF,1);
}
/*
* @define wrap multiple pages from an array
* @param tab the uint32_t array of allocated pages
* @type uint32_t array
* @param number the number of page to map from the array
* @type uint32_t (might change can't use 3Blions pages)
* @param name child the child partition to map on
* @type uint32_t
* @param place the place in the child memory to map on
* @type uint32_t
*/
int multiWrapp(uint32_t tab[],uint32_t number,uint32_t child,uint32_t place){
int mwi,mwh;
mwh=0;/* here if place is already used */
for(mwi=0;mwi<number;mwi++){
if(Pip_MapPageWrapper(tab[mwi],child,place+(mwh*0x1000))){
puts("Failed to map on : ");
puthex(place+(mwh*0X1000));
putc('\n');
mwi--;
}
else{
puts("|Test| Mapping on : ");
puthex(place+(mwh*0X1000));
putc('\n');
}
mwh++;
}
return 0;
}
/* return the number of unsuccessful tests */
int main(pip_fpinfo* bootinfo){
atests=0;
tests= 0;
log1("Test loading :\n",-1);
log1("Pip BootInfo: \n",-1);
parse_bootinfo(bootinfo);
log1("Initializing paging.\n",-1);
if(bootinfo->magic==FPINFO_MAGIC){
initPaging((void*)(bootinfo->memend-0x200000), (void*)bootinfo->memend);
puts("Paging start at : ");
puthex(bootinfo->memend-0x200000);
puts(" - ends at : ");
puthex(bootinfo->memend);
putc('\n');
}
else{
puts("Boot init Error ");
//PANIC();
}
AllocAll();
log1("PART0",-1);
tests++;
if(createPartition(BTVS[0],BTVS[1],BTVS[2],BTVS[3],BTVS[4])){
log1("Partition created :",1);
currchild=1;
atests++;
}
else
log1("Partition created :",0);
puthex(BTVS[0]);puts("\n");
puthex(BTVS[1]);puts("\n");
puthex(BTVS[2]);puts("\n");
puthex(BTVS[3]);puts("\n");
puthex(BTVS[4]);puts("\n");
log1("Creating Test Partitions : ",-1);
log1("PART 1",-1);
tests++;
if (!createPartition(BTVS[0],BTVS[5],BTVS[6],BTVS[7],BTVS[8])){
log1("Malfunctionous Partition couldn't be created (Recall of a previous used address without freeing memmory) :",1);
atests++;
}
else
log1("Malfunctionous Partition could be created (Recall of a previous used address without freeing memmory) :",0);
log1("PART 2",-1);
tests++;
if(!createPartition(0x20000,BTVS[9],BTVS[10],BTVS[11],BTVS[12])){
log1("Malfunctionous Partition coulnd't be created (Call of a non-allocated address in a non-paged area) :",1);
atests++;
}
else
log1("Malfunctionous Partition could be created (Call of a non-allocated address in a non-paged area) :",0);
log1("Initializing interrupts... ",-1);
Pip_RegisterInterrupt(33, &timerAsm,(uint32_t *) 0x2000000);
Pip_RegisterInterrupt(88, &takebackAsm,(uint32_t *) 0x2001000);
Pip_RegisterInterrupt(15, &PfaultAsm,(uint32_t *) 0x2002000);
puts("Mapping partition ");
length= fpart.end-fpart.start;
puthex(length);
puts("\n");
for(offset = 0; offset < length; offset+=0x1000){
if (mapPageWrapper((uint32_t)(fpart.start+ offset), BTVS[0],(uint32_t)(0x700000 +offset))){
log1("Failed to map fpart ",-1);
puthex(fpart.start + offset);
puts(" to destination ");
puthex(0x700000 + offset);
puts("\n");
}
else{
log1("mapped",-2);
puthex((uint32_t)(fpart.start+ offset));
putc('\n');
}
}
puts("Mapping interrupt stack... ");
uint32_t istack_addr = (uint32_t)allocPage();
if(mapPageWrapper((uint32_t)istack_addr, (uint32_t)BTVS[0], (uint32_t)0xC00000))
{
puts("Couldn't map stack.\n");
} else {
puts("done.\n");
}
puts("Mapping stack... \n");
uint32_t stack_addr = (uint32_t)allocPage();
puts("No alloc problems \n");
if(mapPageWrapper((uint32_t)stack_addr,BTVS[0], (uint32_t)0xC0000000))
{
log1("Couldn't map stack.\n",-1);
} else {
puts("stack done.\n");
}
vidt_t * vidt = (vidt_t*) allocPage();
puts("vidt at ");
puthex((uint32_t)vidt);
puts("\n");
vidt->vint[0].eip = 0x700000 ;
vidt->vint[0].esp = 0xC0000000 + 0x1000 - sizeof(uint32_t);
vidt->flags = 0x1;
if(mapPageWrapper((uint32_t)vidt,BTVS[0], (uint32_t)0xFFFFF000))
{
log1("Couldn't map VIDT.\n",-1);
} else {
puts("vidt done.\n");
}
log1("addVAddr Test Start",-1);
MultAddrTest(BTVS[0]);
log1("Next tests are on the writing rigths of a Vaddr addresses are send Now but will be tested later",-1);
log1("\t -Send an address to the child with the writing rigths",-1);
if(Pip_AddVAddr((uint32_t) allocPage(),BTVS[0],0x73A000,1,1,1)){
log1("Succeded to send address",-1);
}
else {
log1("FAILED TO SEND ADDRESS TO CHILD AT :",-1);puthex(0x730000);
}
log1("\t -Send an address to the child without writing rigths",-1);
if(Pip_AddVAddr((uint32_t)allocPage(),BTVS[0],0x73B000,1,0,1)){
log1("Succeded to send address",-1);
}
else {
log1("FAILED TO SEND ADDRESS TO CHILD AT :",-1);puthex(0x73B000);
}
tests++;
/* Test on wrong child */
puts("Next test could be improuved by Searching all kernel/binary addresses with the multAddrTest \n");
if(!Pip_AddVAddr((uint32_t)allocPage(),BTVS[1],0xA00000,1,1,1)){
log1("Couldn't give an address to a false child ",1);
atests++;
}
else{
log1("Malfunctionous address achived to be transmited to son ",0);
}
/*
tests++;
already tried to give memory from kernel to child in multaddrTest
if(!Pip_AddVAddr(0x0,BTVS[0],0xA00000,1,1,1)){
log1("Couldn't transmit Kernel address to child partition ",0);
atests++;
}
else{
log1("Was abble to transmit address to child partition ",1);
}*/
//if(!Pip_AddVAddr())
/*Pip_VCLI();*/
/* Test on addVAddr */
testOnPages(BTVS[0],0x10000000);
/* Page to transfer to parts to increment Test and Atest outside rootpart */
tpage = Pip_AllocPage();
atpage = tpage+1;
*tpage=0x0;
*atpage=0x0;
if(!Pip_AddVAddr((unsigned long)tpage,BTVS[0],0x73C000,1,1,1)){
log1("No deadbeef tonigth ",1);
PANIC();
}
/* Test on notify resume on an already deleted part */
Pip_Notify((uint32_t)BTVS[0],0,0,0);
log1("tests #0",-1);
log1("trying to resume deleted child (Expected to WARNING_IAL in the next line)",-1);
Pip_Resume(BTVS[0],1);
/*Test on Dispatch */
log1("Dispatch/Resume Test partition.",-1);
if (createPartition(BTVS[20],BTVS[21],BTVS[22],BTVS[23],BTVS[24])){
log1("Created part on Dispatch",-1);
}
else{
log1("Couldn't create the dispatch testPart",-1);
}
lengthd= disptpart.end-disptpart.start;
log1("Size of Disptpart : ",-2);
puthex(lengthd);
puts("\n");
for(offset = 0; offset < lengthd; offset+=0x1000){
if (mapPageWrapper((uint32_t)(disptpart.start+ offset), BTVS[20],(uint32_t)(0x700000+offset))){
log1("Failed to map disptpart ",-1);
puthex(disptpart.start + offset);
puts(" to destination ");
puthex(0x700000+ offset);
puts("\n");
}
else{
log1("mapped",-2);
puthex((uint32_t)(disptpart.start+ offset));
putc('\n');
}
}
if(mapPageWrapper((uint32_t)vidt,BTVS[20],(uint32_t)0xFFFFF000))
{
log1("Couldn't map VIDT.\n",-1);
} else {
puts("vidt done.\n");
}
dispatch(BTVS[13],0,0,0);
log1("end of tests on dispatch",-1);
//puthex(*tpage);putc('\n');
//puthex(*atpage);putc('\n');
tests+= *tpage;
atests+= *atpage;
puts(" v0.02\n");
log1("Achevied ",-2);
putdec(atests);
puts(" of ");
putdec(tests);
puts(" tests\n");
puts("#AT#TOKEN");
putdec(tests-atests);
putc('\n');
return (tests-atests);
}