Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | pmbaty | 1 | #include "scratch.h" |
2 | #include "diag.h" |
||
3 | #include "fwsetup.h" |
||
4 | #include "harness/trace.h" |
||
5 | #include "resource.h" |
||
6 | |||
7 | char scratchString[512] = "SCRATCH"; |
||
8 | |||
9 | // IDA: void* __cdecl BrScratchAllocate(br_size_t size) |
||
10 | void* BrScratchAllocate(br_size_t size) { |
||
11 | LOG_TRACE("(%d)", size); |
||
12 | |||
13 | if (fw.scratch_inuse != 0) { |
||
14 | BrFailure("Scratchpad not available"); |
||
15 | } |
||
16 | |||
17 | fw.scratch_last = size; |
||
18 | |||
19 | if (size > fw.scratch_size) { |
||
20 | if (fw.scratch_ptr != NULL) { |
||
21 | BrResFree(fw.scratch_ptr); |
||
22 | } |
||
23 | fw.scratch_ptr = BrResAllocate(fw.res, size, BR_MEMORY_SCRATCH); |
||
24 | fw.scratch_size = size; |
||
25 | } |
||
26 | fw.scratch_inuse = 1; |
||
27 | return fw.scratch_ptr; |
||
28 | } |
||
29 | |||
30 | // IDA: void __cdecl BrScratchFree(void *scratch) |
||
31 | void BrScratchFree(void* scratch) { |
||
32 | LOG_TRACE("(%p)", scratch); |
||
33 | |||
34 | fw.scratch_inuse = 0; |
||
35 | } |
||
36 | |||
37 | // IDA: void __cdecl BrScratchFlush() |
||
38 | void BrScratchFlush(void) { |
||
39 | LOG_TRACE("()"); |
||
40 | |||
41 | if (fw.scratch_inuse != 0) { |
||
42 | BrFailure("Scratchpad cannot be flushed while in use"); |
||
43 | } |
||
44 | if (fw.scratch_ptr != NULL) { |
||
45 | BrResFree(fw.scratch_ptr); |
||
46 | } |
||
47 | fw.scratch_ptr = NULL; |
||
48 | fw.scratch_size = 0; |
||
49 | } |
||
50 | |||
51 | // IDA: br_size_t __cdecl BrScratchInquire() |
||
52 | br_size_t BrScratchInquire(void) { |
||
53 | LOG_TRACE("()"); |
||
54 | |||
55 | return fw.scratch_size; |
||
56 | } |
||
57 | |||
58 | // IDA: char* __cdecl BrScratchString() |
||
59 | char* BrScratchString(void) { |
||
60 | LOG_TRACE9("()"); |
||
61 | |||
62 | return scratchString; |
||
63 | } |
||
64 | |||
65 | // IDA: br_size_t __cdecl BrScratchStringSize() |
||
66 | br_size_t BrScratchStringSize(void) { |
||
67 | LOG_TRACE9("()"); |
||
68 | |||
69 | return sizeof(scratchString); |
||
70 | } |