aboutsummaryrefslogtreecommitdiffstats
path: root/android/hw-kmsg.c
blob: 987943bdaa2bc7e13b8dae6c57a70dbf5a1eae23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (C) 2007-2008 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/
#include "android/hw-kmsg.h"
#include "qemu-char.h"
#include "charpipe.h"
#include "android/utils/debug.h"

static CharDriverState*  android_kmsg_cs;

typedef struct {
    CharDriverState*  cs;
    AndroidKmsgFlags  flags;
} KernelLog;

static int
kernel_log_can_read( void*  opaque )
{
    return 1024;
}

static void
kernel_log_read( void*  opaque, const uint8_t*  from, int  len )
{
    KernelLog*  k = opaque;

    if (k->flags & ANDROID_KMSG_PRINT_MESSAGES)
        printf( "%.*s", len, (const char*)from );

    /* XXXX: TODO: save messages into in-memory buffer for later retrieval */
}

static void
kernel_log_init( KernelLog*  k, AndroidKmsgFlags  flags )
{
    if ( qemu_chr_open_charpipe( &k->cs, &android_kmsg_cs ) < 0 ) {
        derror( "could not create kernel log charpipe" );
        exit(1);
    }

    qemu_chr_add_handlers( k->cs, kernel_log_can_read, kernel_log_read, NULL, k );

    k->flags = flags;
}

static KernelLog  _kernel_log[1];

void
android_kmsg_init( AndroidKmsgFlags  flags )
{
    if (_kernel_log->cs == NULL)
        kernel_log_init( _kernel_log, flags );
}


CharDriverState*  android_kmsg_get_cs( void )
{
    if (android_kmsg_cs == NULL) {
        android_kmsg_init(0);
    }
    return android_kmsg_cs;
}