blob: b621ba93ee5e452e89bd8ab32a49e11118e0c496 [file] [log] [blame]
Jon Medhurstaaf37a32013-06-11 12:10:56 +01001/**
Jon Medhurst15ce78d2014-04-10 09:02:02 +01002 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
Jon Medhurstaaf37a32013-06-11 12:10:56 +01003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 */
9
10static void gator_buffer_write_packed_int(int cpu, int buftype, int x)
11{
12 uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
13 uint32_t mask = gator_buffer_mask[buftype];
14 char *buffer = per_cpu(gator_buffer, cpu)[buftype];
15 int packedBytes = 0;
16 int more = true;
17 while (more) {
18 // low order 7 bits of x
19 char b = x & 0x7f;
20 x >>= 7;
21
22 if ((x == 0 && (b & 0x40) == 0) || (x == -1 && (b & 0x40) != 0)) {
23 more = false;
24 } else {
25 b |= 0x80;
26 }
27
28 buffer[(write + packedBytes) & mask] = b;
29 packedBytes++;
30 }
31
32 per_cpu(gator_buffer_write, cpu)[buftype] = (write + packedBytes) & mask;
33}
34
35static void gator_buffer_write_packed_int64(int cpu, int buftype, long long x)
36{
37 uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
38 uint32_t mask = gator_buffer_mask[buftype];
39 char *buffer = per_cpu(gator_buffer, cpu)[buftype];
40 int packedBytes = 0;
41 int more = true;
42 while (more) {
43 // low order 7 bits of x
44 char b = x & 0x7f;
45 x >>= 7;
46
47 if ((x == 0 && (b & 0x40) == 0) || (x == -1 && (b & 0x40) != 0)) {
48 more = false;
49 } else {
50 b |= 0x80;
51 }
52
53 buffer[(write + packedBytes) & mask] = b;
54 packedBytes++;
55 }
56
57 per_cpu(gator_buffer_write, cpu)[buftype] = (write + packedBytes) & mask;
58}
Jon Medhurst15ce78d2014-04-10 09:02:02 +010059
60static void gator_buffer_write_bytes(int cpu, int buftype, const char *x, int len)
61{
62 int i;
63 u32 write = per_cpu(gator_buffer_write, cpu)[buftype];
64 u32 mask = gator_buffer_mask[buftype];
65 char *buffer = per_cpu(gator_buffer, cpu)[buftype];
66
67 for (i = 0; i < len; i++) {
68 buffer[write] = x[i];
69 write = (write + 1) & mask;
70 }
71
72 per_cpu(gator_buffer_write, cpu)[buftype] = write;
73}
74
75static void gator_buffer_write_string(int cpu, int buftype, const char *x)
76{
77 int len = strlen(x);
78 gator_buffer_write_packed_int(cpu, buftype, len);
79 gator_buffer_write_bytes(cpu, buftype, x, len);
80}