Subversion Repositories Kolibri OS

Rev

Rev 5271 | Rev 6321 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5271 Rev 6104
Line 224... Line 224...
224
 *          linebuf, sizeof(linebuf), true);
224
 *          linebuf, sizeof(linebuf), true);
225
 *
225
 *
226
 * example output buffer:
226
 * example output buffer:
227
 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
227
 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
228
 */
228
 */
229
void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
229
int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
230
            int groupsize, char *linebuf, size_t linebuflen,
230
               char *linebuf, size_t linebuflen, bool ascii)
231
            bool ascii)
-
 
232
{
231
{
233
    const u8 *ptr = buf;
232
    const u8 *ptr = buf;
-
 
233
    int ngroups;
234
    u8 ch;
234
    u8 ch;
235
    int j, lx = 0;
235
    int j, lx = 0;
236
    int ascii_column;
236
    int ascii_column;
-
 
237
    int ret;
Line 237... Line 238...
237
 
238
 
238
    if (rowsize != 16 && rowsize != 32)
239
    if (rowsize != 16 && rowsize != 32)
Line 239... Line -...
239
        rowsize = 16;
-
 
240
 
-
 
241
    if (!len)
240
        rowsize = 16;
242
        goto nil;
241
 
-
 
242
    if (len > rowsize)      /* limit to one line at a time */
-
 
243
        len = rowsize;
243
    if (len > rowsize)      /* limit to one line at a time */
244
    if (!is_power_of_2(groupsize) || groupsize > 8)
244
        len = rowsize;
245
        groupsize = 1;
Line 245... Line 246...
245
    if ((len % groupsize) != 0) /* no mixed size output */
246
    if ((len % groupsize) != 0) /* no mixed size output */
-
 
247
        groupsize = 1;
-
 
248
 
-
 
249
    ngroups = len / groupsize;
-
 
250
    ascii_column = rowsize * 2 + rowsize / groupsize + 1;
-
 
251
 
246
        groupsize = 1;
252
    if (!linebuflen)
-
 
253
        goto overflow1;
-
 
254
 
-
 
255
    if (!len)
247
 
256
        goto nil;
248
    switch (groupsize) {
-
 
Line 249... Line 257...
249
    case 8: {
257
 
250
        const u64 *ptr8 = buf;
258
    if (groupsize == 8) {
251
        int ngroups = len / groupsize;
259
        const u64 *ptr8 = buf;
252
 
260
 
253
        for (j = 0; j < ngroups; j++)
261
        for (j = 0; j < ngroups; j++) {
-
 
262
            ret = snprintf(linebuf + lx, linebuflen - lx,
254
            lx += scnprintf(linebuf + lx, linebuflen - lx,
263
                       "%s%16.16llx", j ? " " : "",
255
                    "%s%16.16llx", j ? " " : "",
264
                       (unsigned long long)*(ptr8 + j));
256
                    (unsigned long long)*(ptr8 + j));
-
 
257
        ascii_column = 17 * ngroups + 2;
265
            if (ret >= linebuflen - lx)
258
        break;
266
                goto overflow1;
259
    }
-
 
Line 260... Line 267...
260
 
267
            lx += ret;
261
    case 4: {
268
        }
262
        const u32 *ptr4 = buf;
269
    } else if (groupsize == 4) {
263
        int ngroups = len / groupsize;
270
        const u32 *ptr4 = buf;
-
 
271
 
-
 
272
        for (j = 0; j < ngroups; j++) {
264
 
273
            ret = snprintf(linebuf + lx, linebuflen - lx,
265
        for (j = 0; j < ngroups; j++)
274
                       "%s%8.8x", j ? " " : "",
266
            lx += scnprintf(linebuf + lx, linebuflen - lx,
-
 
267
                    "%s%8.8x", j ? " " : "", *(ptr4 + j));
275
                       *(ptr4 + j));
268
        ascii_column = 9 * ngroups + 2;
276
            if (ret >= linebuflen - lx)
269
        break;
-
 
Line 270... Line 277...
270
    }
277
                goto overflow1;
271
 
278
            lx += ret;
272
    case 2: {
279
        }
273
        const u16 *ptr2 = buf;
280
    } else if (groupsize == 2) {
-
 
281
        const u16 *ptr2 = buf;
-
 
282
 
274
        int ngroups = len / groupsize;
283
        for (j = 0; j < ngroups; j++) {
275
 
284
            ret = snprintf(linebuf + lx, linebuflen - lx,
276
        for (j = 0; j < ngroups; j++)
-
 
277
            lx += scnprintf(linebuf + lx, linebuflen - lx,
285
                       "%s%4.4x", j ? " " : "",
278
                    "%s%4.4x", j ? " " : "", *(ptr2 + j));
286
                       *(ptr2 + j));
-
 
287
            if (ret >= linebuflen - lx)
-
 
288
                goto overflow1;
279
        ascii_column = 5 * ngroups + 2;
289
            lx += ret;
280
        break;
290
        }
281
    }
291
    } else {
282
 
292
        for (j = 0; j < len; j++) {
283
    default:
293
            if (linebuflen < lx + 3)
284
        for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) {
294
                goto overflow2;
285
            ch = ptr[j];
295
            ch = ptr[j];
286
            linebuf[lx++] = hex_asc_hi(ch);
-
 
287
            linebuf[lx++] = hex_asc_lo(ch);
-
 
288
            linebuf[lx++] = ' ';
-
 
289
        }
296
            linebuf[lx++] = hex_asc_hi(ch);
290
        if (j)
297
            linebuf[lx++] = hex_asc_lo(ch);
291
            lx--;
298
            linebuf[lx++] = ' ';
Line 292... Line 299...
292
 
299
        }
-
 
300
        if (j)
-
 
301
            lx--;
293
        ascii_column = 3 * rowsize + 2;
302
    }
-
 
303
    if (!ascii)
294
        break;
304
        goto nil;
-
 
305
 
-
 
306
    while (lx < ascii_column) {
295
    }
307
        if (linebuflen < lx + 2)
296
    if (!ascii)
308
            goto overflow2;
297
        goto nil;
309
        linebuf[lx++] = ' ';
298
 
310
    }
-
 
311
    for (j = 0; j < len; j++) {
-
 
312
        if (linebuflen < lx + 2)
-
 
313
            goto overflow2;
299
    while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
314
        ch = ptr[j];
-
 
315
        linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
-
 
316
    }
300
        linebuf[lx++] = ' ';
317
nil:
301
    for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
-
 
302
        ch = ptr[j];
318
    linebuf[lx] = '\0';
303
        linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
319
    return lx;
304
    }
320
overflow2:
305
nil:
321
    linebuf[lx++] = '\0';
306
    linebuf[lx++] = '\0';
322
overflow1:
Line 375... Line 391...
375
{
391
{
376
    print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
392
    print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
377
                       buf, len, true);
393
                       buf, len, true);
378
}
394
}
Line -... Line 395...
-
 
395
 
-
 
396
#define KMAP_MAX    256
-
 
397
 
-
 
398
static struct mutex kmap_mutex;
-
 
399
static struct page* kmap_table[KMAP_MAX];
-
 
400
static int kmap_av;
-
 
401
static int kmap_first;
-
 
402
static void* kmap_base;
-
 
403
 
-
 
404
 
-
 
405
int kmap_init()
-
 
406
{
-
 
407
    kmap_base = AllocKernelSpace(KMAP_MAX*4096);
-
 
408
    if(kmap_base == NULL)
-
 
409
        return -1;
-
 
410
 
-
 
411
    kmap_av = KMAP_MAX;
-
 
412
    MutexInit(&kmap_mutex);
-
 
413
    return 0;
-
 
414
};
-
 
415
 
-
 
416
void *kmap(struct page *page)
-
 
417
{
-
 
418
    void *vaddr = NULL;
-
 
419
    int i;
-
 
420
 
-
 
421
    do
-
 
422
    {
-
 
423
        MutexLock(&kmap_mutex);
-
 
424
        if(kmap_av != 0)
-
 
425
        {
-
 
426
            for(i = kmap_first; i < KMAP_MAX; i++)
-
 
427
            {
-
 
428
                if(kmap_table[i] == NULL)
-
 
429
                {
-
 
430
                    kmap_av--;
-
 
431
                    kmap_first = i;
-
 
432
                    kmap_table[i] = page;
-
 
433
                    vaddr = kmap_base + (i<<12);
-
 
434
                    MapPage(vaddr,(addr_t)page,3);
-
 
435
                    break;
-
 
436
                };
-
 
437
            };
-
 
438
        };
-
 
439
        MutexUnlock(&kmap_mutex);
-
 
440
    }while(vaddr == NULL);
-
 
441
 
-
 
442
    return vaddr;
-
 
443
};
-
 
444
 
-
 
445
void *kmap_atomic(struct page *page) __attribute__ ((alias ("kmap")));
-
 
446
 
-
 
447
void kunmap(struct page *page)
-
 
448
{
-
 
449
    void *vaddr;
-
 
450
    int   i;
-
 
451
 
-
 
452
    MutexLock(&kmap_mutex);
-
 
453
 
-
 
454
    for(i = 0; i < KMAP_MAX; i++)
-
 
455
    {
-
 
456
        if(kmap_table[i] == page)
-
 
457
        {
-
 
458
            kmap_av++;
-
 
459
            if(i < kmap_first)
-
 
460
                kmap_first = i;
-
 
461
            kmap_table[i] = NULL;
-
 
462
            vaddr = kmap_base + (i<<12);
-
 
463
            MapPage(vaddr,0,0);
-
 
464
            break;
-
 
465
        };
-
 
466
    };
-
 
467
 
-
 
468
    MutexUnlock(&kmap_mutex);
-
 
469
};
-
 
470
 
-
 
471
void kunmap_atomic(void *vaddr)
-
 
472
{
-
 
473
    int i;
-
 
474
 
-
 
475
    MapPage(vaddr,0,0);
-
 
476
 
-
 
477
    i = (vaddr - kmap_base) >> 12;
-
 
478
 
-
 
479
    MutexLock(&kmap_mutex);
-
 
480
 
-
 
481
    kmap_av++;
-
 
482
    if(i < kmap_first)
-
 
483
        kmap_first = i;
-
 
484
    kmap_table[i] = NULL;
-
 
485
 
-
 
486
    MutexUnlock(&kmap_mutex);
379
 
487
}
380
void msleep(unsigned int msecs)
488
void msleep(unsigned int msecs)
381
{
489
{
382
    msecs /= 10;
490
    msecs /= 10;
Line 972... Line 1080...
972
void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
1080
void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
973
{
1081
{
974
        __call_rcu(head, func, &rcu_sched_ctrlblk);
1082
        __call_rcu(head, func, &rcu_sched_ctrlblk);
975
}
1083
}
Line -... Line 1084...
-
 
1084
 
-
 
1085
fb_get_options(const char *name, char **option)
-
 
1086
{
-
 
1087
    return 1;
-
 
1088
 
-
 
1089
}
-
 
1090
 
-
 
1091
ktime_t ktime_get(void)
-
 
1092
{
-
 
1093
    ktime_t t;
-
 
1094
 
-
 
1095
    t.tv64 = GetClockNs();
-
 
1096
 
-
 
1097
    return t;
-
 
1098
}
-
 
1099
 
-
 
1100
void radeon_cursor_reset(struct drm_crtc *crtc)
-
 
1101
{
-
 
1102
 
-
 
1103
}
-
 
1104
 
-
 
1105
/* Greatest common divisor */
-
 
1106
unsigned long gcd(unsigned long a, unsigned long b)
-
 
1107
{
-
 
1108
        unsigned long r;
-
 
1109
 
-
 
1110
        if (a < b)
-
 
1111
                swap(a, b);
-
 
1112
 
-
 
1113
        if (!b)
-
 
1114
                return a;
-
 
1115
        while ((r = a % b) != 0) {
-
 
1116
                a = b;
-
 
1117
                b = r;
-
 
1118
        }
-
 
1119
        return b;