Subversion Repositories shark

Rev

Rev 1206 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1200 giacomo 1
#include <kernel/kern.h>
2
#include <stdlib.h>
3
#include "parser.h"
4
 
1208 giacomo 5
int dos_preload(char *file_name, long max_size, void **start_file, void **end_file)
1200 giacomo 6
{
7
  DOS_FILE* file;
8
  void      *buf;
9
  long      rd;
10
 
11
 
12
  file = DOS_fopen(file_name,"r");
13
  if (file == NULL) return -1;
14
 
15
  buf = malloc(max_size);
1208 giacomo 16
  *start_file = buf;
1200 giacomo 17
 
18
  while(((rd = DOS_fread(buf, sizeof(BYTE), 2048, file)) == 2048) &&
1208 giacomo 19
        ((buf - *start_file + rd) < (max_size-2048))) {
1200 giacomo 20
        buf += rd;
21
  }
22
 
1208 giacomo 23
  *end_file = buf + rd;
1200 giacomo 24
 
25
  DOS_fclose(file);
26
  return(0);
27
 
28
}
29
 
1208 giacomo 30
int line_reader(void *start_file, void *end_file, struct timespec *total, struct loader_task **start_loader_task)
1200 giacomo 31
{
32
 
1208 giacomo 33
  char *pbuf = start_file;
1206 giacomo 34
  int res,line_num,total_loader_task;
1201 giacomo 35
  struct loader_task *current = NULL;
1200 giacomo 36
 
37
  NULL_TIMESPEC(total);
38
 
39
  line_num = 0;
40
  total_loader_task = 0;
1208 giacomo 41
  while ((void *)(pbuf) < end_file) {
1206 giacomo 42
 
1200 giacomo 43
    line_num++;
1203 giacomo 44
 
45
    if (*start_loader_task == NULL)
1206 giacomo 46
      res = line_parser(&pbuf, line_num, total, &current);
1203 giacomo 47
    else
1206 giacomo 48
      res = line_parser(&pbuf, line_num, total, &current->next);
1203 giacomo 49
 
1200 giacomo 50
    if (res == 2) {
51
      total_loader_task++;
1203 giacomo 52
      if (*start_loader_task == NULL)
53
        *start_loader_task = current;
54
      else
55
        current = current->next;
1200 giacomo 56
    }
1206 giacomo 57
 
58
    if (res == 3) break;
59
 
1200 giacomo 60
  }
61
 
62
  cprintf("Total decoded lines %d\n",line_num);
63
  cprintf("Total loader task %d\n",total_loader_task);
64
  cprintf("Simulation time sec = %ld usec = %ld\n",total->tv_sec,total->tv_nsec/1000);
65
 
66
  return 0;
67
 
68
}