peripheral addresses

jj1984

Member
I'm aware that as a part of the startup / booting process the firmware initializes the peripheral devices' BARs to assign them address ranges in the CPU's memory space. The CPU then sends those addresses to the memory controller to "talk" to those devices just like the CPU would send an address to the memory controller to grab data from RAM.

So, for example, if you write a program that tells the CPU to grab some data from a peripheral and put that data into a register the source code for that instruction would compile into a simple 'mov' instruction in machine code.

But, how can you run the same program over and over after rebooting the system when the firmware might not assign the same address for the pertinent peripheral?

What I mean is, if you want to grab the data from a register on peripheral device A and this time the register has been assigned address a12f, but after the next boot it has been assigned the address c03b, how can the same precompiled code run successfully?
 
Last edited:
Pointers are fun. ;)

You don't write your code to look at a static address. You keep a variable that points to the location you need to access. You're always looking at 0x1a23 (or whatever) for the address contained and then read from there.
 
Pointers are fun. ;)

You don't write your code to look at a static address. You keep a variable that points to the location you need to access. You're always looking at 0x1a23 (or whatever) for the address contained and then read from there.

So, then am I to assume that at some point in the startup process the firmware writes the addresses it has just initialized for peripherals into some kernel space data structure that is always found at the same address?
 
Back
Top