All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Wu, Michael Y [US] (MS)" <Michael.Wu@ngc.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] EXT :Re:  Emulating external registers
Date: Thu, 6 Apr 2017 17:23:32 +0000	[thread overview]
Message-ID: <a710ff5405c04e8b97f5d4ed6739fb7b@XCGC3021.northgrum.com> (raw)
In-Reply-To: <CAFEAcA8C17TnnBKim9T9k32Re9C-pWUokF-UeVAd=itcpROvRg@mail.gmail.com>

Thank you Peter!

I changed my code to the following and added the appropriate read,write functions and a MemoryRegionOps.
    memory_region_init_io(reg_memory, NULL, &reg_ops, reg,
                          "reg_mem", 0x00000040); //set to 64 bytes
    memory_region_add_subregion(sysmem, 0xFC000000, reg_memory);

For the read function I just returned a zero. So if I were to read from the address 0xFC000000 it should return a value of 0? The current issue I am having is that gdb hangs when the pointer is accessed. I am starting to think my bare-metal program is incorrect. I also added log messages in my read and write functions. The read function was not accessed.

//Some code in my bare metal program
volatile unsigned int  * const test = (unsigned int *) 0xFC000000;
if (0x0 == *test)  //gdb hangs on this line, cannot step further
  {
    read_hit();
  }

The file 'unimp.c' you mentioned looks great! I will be using that as inspiration for creating my own device model.

-----Original Message-----
From: Peter Maydell [mailto:peter.maydell@linaro.org] 
Sent: Thursday, April 06, 2017 1:33 AM
To: Wu, Michael Y [US] (MS)
Cc: qemu-devel@nongnu.org
Subject: EXT :Re: [Qemu-devel] Emulating external registers

On 5 April 2017 at 22:03, Wu, Michael Y [US] (MS) <Michael.Wu@ngc.com> wrote:
> My current approach is to create a new MemoryRegion in the init function of the g3beige source code (mac_oldworld.c). My idea is to set up some mmio to certain address to represent those registers. For now I only care about reading and writing, but in the future I hope to add additional logic when the registers are written.
> I added the following lines:
> MemoryRegion *reg = g_new(MemoryRegion, 1); 
> memory_region_init_alias(reg, NULL, "reg_mmio",
>                             get_system_io(), 0, 0x00200000);

This is defining your region to be an alias into the system IO region, so reading/writing your region will act like reads and writes into those IO ports. This doesn't sound like what you were trying to do.
Usually memory regions for registers are defined using memory_region_init_io(), where you pass in a structure that includes pointers to functions which are called for reads and writes.

> memory_region_add_subregion(sysmem, 0xfc000000, reg);

Typically you would create a device model for whatever this device is, and then map it in the board code, not directly create a memory region in the board code.

You might find it useful to look at hw/misc/unimp.c, which is a device which simply prints log messages when it is read or written. Or try a simple device that your board already has.

thanks
-- PMM


  reply	other threads:[~2017-04-06 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05 21:03 [Qemu-devel] Emulating external registers Wu, Michael Y [US] (MS)
2017-04-06  8:32 ` Peter Maydell
2017-04-06 17:23   ` Wu, Michael Y [US] (MS) [this message]
2017-04-06 17:37     ` [Qemu-devel] EXT :Re: " Peter Maydell
2017-04-12 18:44       ` Wu, Michael Y [US] (MS)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a710ff5405c04e8b97f5d4ed6739fb7b@XCGC3021.northgrum.com \
    --to=michael.wu@ngc.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.