What kind of memory addresses are the ones shown by proc/ioports and proc/iomem?
Solution 1:
which memory addresses are being referred to here. Is it virtual memory?
Part of the design of the first IBM PC was to use some memory addresses for things other than actual memory (of the sort used by programs and data)
In the first IBM PC, you could have up to 640 KB of RAM but the chips could address up to 1024 KB of memory, however writing to memory addresses higher than 640 (and less than 1024) would actually be used to communicate not with RAM but with devices such as plug-in graphics adapters.
This concept is sometimes referred to as memory-mapped IO or memory mapped hardware devices.
IO ports are another type of addressable resource in the IBM PC architecture. In the early days you would physically configure such addresses on plug-in (ISA) cards by using "jumpers" to connect addressing pins on the board. You might also configure software to use matching IO addresses.
The white lettering on the left of the card describes which jumper positions give which IO Port addresses etc.
Nowadays, addressing details are negotiated and assigned dynamically by the cards and the host computer as the system starts up. We no longer have to configure them.
Would it be possible to access these memory addresses from a user program to for example write into the serial port? Maybe using assembler?
I believe so, assuming you are using an operating system that permits it (e.g. PC-DOS, a real-mode OS). In contrast, modern, protected-mode OSs will prevent such operations succeeding from a user program.
Solution 2:
/proc/ioports
lists ranges of I/O port addresses.
/proc/iomem
lists ranges of physical memory addresses.
You can access physical memory addresses directly from a user program by mapping /dev/mem
, but you probably don't want to. You can access I/O ports directly from a user program with ioperm
, but you probably don't want to. Generally, you really want to be in kernel mode to do these kinds of things because you need to do things like disable interrupts.