[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] EXT :Re: Emulating external registers

From: Wu, Michael Y [US] (MS)
Subject: Re: [Qemu-devel] EXT :Re: Emulating external registers
Date: Thu, 6 Apr 2017 17:23:32 +0000

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

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:address@hidden 
Sent: Thursday, April 06, 2017 1:33 AM
To: Wu, Michael Y [US] (MS)
Cc: address@hidden
Subject: EXT :Re: [Qemu-devel] Emulating external registers

On 5 April 2017 at 22:03, Wu, Michael Y [US] (MS) <address@hidden> 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.

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]