• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #include <unistd.h>
13 #include <fcntl.h>
14 #include <string.h>
15 
16 #include "qemu_file.h"
17 #include "goldfish_device.h"
18 #include "audio/audio.h"
19 
20 extern void  dprint(const char*  fmt, ...);
21 
22 int fd = -1;
23 
memlog_read(void * opaque,target_phys_addr_t offset)24 static uint32_t memlog_read(void *opaque, target_phys_addr_t offset)
25 {
26     struct goldfish_device *dev = opaque;
27     offset -= dev->base;
28 
29     return 0;
30 }
31 
32 unsigned info[8];
33 
memlog_write(void * opaque,target_phys_addr_t offset,uint32_t val)34 static void memlog_write(void *opaque, target_phys_addr_t offset, uint32_t val)
35 {
36     char buf[128];
37     struct goldfish_device *dev = opaque;
38     offset -= dev->base;
39 
40     info[offset / 4] = val;
41 
42     if (offset == 0) {
43             /* write PID and VADDR to logfile */
44         sprintf(buf,"%08x %08x\n", info[0], info[1]);
45         write(fd, buf, strlen(buf));
46     }
47 }
48 
49 
50 static CPUReadMemoryFunc *memlog_readfn[] = {
51    memlog_read,
52    memlog_read,
53    memlog_read
54 };
55 
56 static CPUWriteMemoryFunc *memlog_writefn[] = {
57    memlog_write,
58    memlog_write,
59    memlog_write
60 };
61 
62 struct goldfish_device memlog_dev;
63 
goldfish_memlog_init(uint32_t base)64 void goldfish_memlog_init(uint32_t base)
65 {
66     struct goldfish_device *dev = &memlog_dev;
67 
68     dev->name = "goldfish_memlog";
69     dev->id = 0;
70     dev->base = base;
71     dev->size = 0x1000;
72     dev->irq_count = 0;
73 
74     fd = open("mem.log", /* O_CREAT | */ O_TRUNC | O_WRONLY, 0644);
75 
76     goldfish_device_add(dev, memlog_readfn, memlog_writefn, dev);
77 }
78 
79