user571138
user571138

Reputation:

What memory addresses are available for use?

How do i find out what memory addresses are suitable for use ?

More specifically, the example of How to use a specific address is here: Pointer to a specific fixed address, but not information on Why this is a valid address for reading/writing.

I would like a way of finding out that addresses x to y are useable.

This is so i can do something similar to memory mapped IO without a specific simulator. (My linked Question relevant so i can use one set of addresses for testing on Ubuntu, and another for the actual software-on-chip)

Ubuntu specific answers please.

Upvotes: 0

Views: 148

Answers (3)

Mike
Mike

Reputation: 49523

You're mixing two independent topics here. The Question that you're linking to, is regarding a micro controller's memory mapped IO. It's referring to the ATM128, a Microcontroller from the Atmel. The OP of that question is trying to write to one of the registers of it, these registers are given specific addresses.

If you're trying to write to the address of a register, you need to understand how memory mapped IO works, you need to read the spec for the chipset/IC your working on. Asking this talking about "Ubuntu specific answers" is meaningless.

Your program running on the Ubuntu OS is running it it's own virtual address space. So asking if addresses x to y are available for use is pretty pointless... unless you're accessing hardware, there's no point in looking for a specific address, just use what the OS gives you and you'll know you're good.


Based on your edit, the fact that you're trying to do a simulation of memory mapped IO, you could do something like:

#ifdef SIMULATION
    unsigned int TX_BUF_REG;  // The "simulated" 32-bit register
#else
#define TX_BUF_REG 0x123456   // The actual address of the reg you're simulating
#endif

Then use accessor macro's to read or write specific bits via a mask (as is typically done):

#define WRITE_REG_BITS(reg, bits) {reg |= bits;}
...
WRITE_REG_BITS(TX_BUF_REG, SOME_MASK);

Static variables can be used in simulations this way so you don't have to worry about what addresses are "safe" to write to.

Upvotes: 2

bidifx
bidifx

Reputation: 1650

For the referenced ATMega128 microcontroller you look in the Datasheet to see which addresses are mapped to registers. On a PC with OS installed you won't have a chance to access hardware registers directly this way. At least not from userspace. Normally only device drivers (ring 0) are allowed to access hardware.

As already mentioned by others you have to use e.g. malloc() to tell the OS that you need a pointer to memory chuck that you are allowed to write to. This is because the OS manages the memory for the whole system.

Upvotes: 0

mouviciel
mouviciel

Reputation: 67899

You can use whatever memory address malloc() returns. Moreover, you can specify how much memory you need. And with realloc() you even can change your mind afterwards.

Upvotes: 3

Related Questions