Home | History | Annotate | Download | only in hw
      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 
     24 static uint32_t memlog_read(void *opaque, target_phys_addr_t offset)
     25 {
     26     (void)opaque;
     27     (void)offset;
     28     return 0;
     29 }
     30 
     31 unsigned info[8];
     32 
     33 static void memlog_write(void *opaque, target_phys_addr_t offset, uint32_t val)
     34 {
     35     char buf[128];
     36     struct goldfish_device *dev = opaque;
     37     int ret;
     38 
     39     (void)dev;
     40 
     41     if (offset < 8*4)
     42         info[offset / 4] = val;
     43 
     44     if (offset == 0) {
     45             /* write PID and VADDR to logfile */
     46         snprintf(buf, sizeof buf, "%08x %08x\n", info[0], info[1]);
     47         do {
     48             ret = write(fd, buf, strlen(buf));
     49         } while (ret < 0 && errno == EINTR);
     50     }
     51 }
     52 
     53 
     54 static CPUReadMemoryFunc *memlog_readfn[] = {
     55    memlog_read,
     56    memlog_read,
     57    memlog_read
     58 };
     59 
     60 static CPUWriteMemoryFunc *memlog_writefn[] = {
     61    memlog_write,
     62    memlog_write,
     63    memlog_write
     64 };
     65 
     66 struct goldfish_device memlog_dev;
     67 
     68 void goldfish_memlog_init(uint32_t base)
     69 {
     70     struct goldfish_device *dev = &memlog_dev;
     71 
     72     dev->name = "goldfish_memlog";
     73     dev->id = 0;
     74     dev->base = base;
     75     dev->size = 0x1000;
     76     dev->irq_count = 0;
     77 
     78     do {
     79         fd = open("mem.log", /* O_CREAT | */ O_TRUNC | O_WRONLY, 0644);
     80     } while (fd < 0 && errno == EINTR);
     81 
     82     goldfish_device_add(dev, memlog_readfn, memlog_writefn, dev);
     83 }
     84 
     85