Subversion Repositories shark

Rev

Rev 563 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
498 giacomo 1
#include <FTrace_chunk.h>
2
#include <FTrace_OSD.h>
3
#include <FTrace_types.h>
4
 
550 giacomo 5
#include <FTrace_udp.h>
6
 
498 giacomo 7
#include <kernel/kern.h>
8
#include <stdlib.h>
9
 
10
SYS_FLAGS FTracef;
11
 
12
extern FTrace_Chunk_Ptr ActualChunk;
532 giacomo 13
extern void *OSD_current_pointer;
498 giacomo 14
 
1027 tullio 15
/**
16
 * This flag keeps track of the current chunk sending action.
17
 * It is 1 if the output is still ongoing.
18
 * It is reset to 0 if the output is finished.
19
 */
20
int chunk_sending = 0;
21
 
22
/**
23
 * Pointer to the function that actually perform the chunk send.
24
 */
25
void (*FTrace_internal_send_chunk)(FTrace_Chunk_Ptr) = NULL;
26
 
27
/**
28
 * Initializes the poiter to the function for actually sending the chunk.
29
 */
30
void FTrace_set_internal_chunk_sender(void (*ptr)(FTrace_Chunk_Ptr)) {
31
        FTrace_internal_send_chunk = ptr;
32
}
33
 
34
/**
35
 * This function is called before starting the chunck sending.
36
 */
37
void FTrace_chunck_output_start() {
38
        chunk_sending = 1;
39
}
40
 
41
/**
42
 * This function is called after the chunck has been entirely sent.
43
 */
44
void FTrace_chunck_output_end() {
45
        chunk_sending = 0;
46
}
47
 
48
 
498 giacomo 49
void FTrace_fsave()
50
{
51
 
563 giacomo 52
  __asm__("cpuid\n\t":::"eax","ebx","ecx","edx");
498 giacomo 53
  FTracef = kern_fsave();
54
 
55
}
56
 
57
void FTrace_frestore()
58
{
563 giacomo 59
  __asm__("cpuid\n\t":::"eax","ebx","ecx","edx");                                                                            
498 giacomo 60
  kern_frestore(FTracef);
61
 
62
}
63
 
64
void FTrace_lock()
65
{
66
 
67
}
68
 
69
void FTrace_unlock()
70
{
71
 
72
}
73
 
74
void *FTrace_malloc(int size)
75
{
76
 
77
  return malloc(size);
78
 
79
}
80
 
81
void FTrace_free(void *ptr)
82
{
83
 
84
  free(ptr);
85
 
86
}
87
 
88
int FTrace_OSD_init()
89
{
90
 
91
  return 0;
92
 
93
}
94
 
501 giacomo 95
/* OSD_pointers
532 giacomo 96
 
534 giacomo 97
   00 - Actual Chunk Position
98
   04 - Actual Chunk Start
99
   08 - Actual Chunk Size
100
   12 - Actual Chunk Emergency Size
101
   16 - Actual Chunk Flags
501 giacomo 102
 
534 giacomo 103
   20 - Next Chunk OSD Pointer
501 giacomo 104
 
105
*/
106
 
107
int FTrace_OSD_chunk_init(FTrace_Chunk_Ptr c, int size, int emergency_size, FTrace_flags flags)
498 giacomo 108
{
109
 
532 giacomo 110
  *(DWORD *)(c->osd) = (DWORD)(c->osd + FTRACE_OSD_CHUNK_HEAD);
501 giacomo 111
  *(DWORD *)(c->osd + 4) = (DWORD)(c->osd + FTRACE_OSD_CHUNK_HEAD);
534 giacomo 112
  *(DWORD *)(c->osd + 8) = (DWORD)(c->size);
113
  *(DWORD *)(c->osd + 12) = (DWORD)(c->emergency_size);
114
  *(DWORD *)(c->osd + 16) = (DWORD)(c->flags);
115
  *(DWORD *)(c->osd + 20) = 0;
501 giacomo 116
 
498 giacomo 117
  return 0;
118
 
119
}
120
 
121
/* OSD Chunk Link */
532 giacomo 122
int FTrace_OSD_chunk_link(FTrace_Chunk_Ptr a, FTrace_Chunk_Ptr b)
498 giacomo 123
{
124
 
534 giacomo 125
  *(DWORD *)(a->osd + 20) = (DWORD)(b->osd);
498 giacomo 126
 
127
  return 0;
128
 
129
}
130
 
503 giacomo 131
int FTrace_OSD_update_chunk_flags(FTrace_Chunk_Ptr c)
132
{
133
 
534 giacomo 134
  *(DWORD *)(c->osd + 16) = (DWORD)(c->flags);
503 giacomo 135
 
136
  return 0;
137
 
138
}
139
 
498 giacomo 140
int FTrace_OSD_compress_chunk(int number, void *temp_data, int *data_size)
141
{
142
 
143
  return 0;
144
 
145
}
146
 
1027 tullio 147
int FTrace_OSD_send_chunk(FTrace_Chunk_Ptr c, int osd_flag) {
498 giacomo 148
 
1027 tullio 149
  // Tool: send the chunk using the selected method
150
  if (FTrace_internal_send_chunk != NULL)
151
        FTrace_internal_send_chunk(c);
552 giacomo 152
 
1027 tullio 153
 
154
  struct timespec t;
155
  t.tv_sec = 2;
156
  t.tv_nsec = 0;
157
  //cprintf("Chunk sending");   // Tool: DEBUG
158
  while(chunk_sending) {
159
        //cprintf(".");   // Tool: DEBUG
160
        nanosleep(&t,NULL);
161
  }
162
  //cprintf("\n");   // Tool: DEBUG
550 giacomo 163
 
498 giacomo 164
  return 0;
165
}
166
 
534 giacomo 167
int FTrace_OSD_chunk_dump(FTrace_Chunk_Ptr c)
168
{
498 giacomo 169
 
534 giacomo 170
  FTrace_printf("Position : %x\n",*(int *)(c->osd));
171
  FTrace_printf("Start    : %x\n",*(int *)(c->osd+4));
172
  FTrace_printf("Size     : %d\n",*(int *)(c->osd+8));
173
  FTrace_printf("Em-Size  : %d\n",*(int *)(c->osd+12));
174
  FTrace_printf("Flags    : %x\n",*(int *)(c->osd+16));
175
  FTrace_printf("Next     : %x\n\n",*(int *)(c->osd+20));
176
 
177
  return 0;
178
 
179
}
180
 
181