How does language speak with equipment?

Ok, so I'm very confused about how the piece of hardware can understand the code. I read somewhere that it relates to voltages, but how exactly does the hardware know what the instruction in software means? I know that drivers are the bridge between software and hardware, but the driver is still software: S.

For example, in C ++ we have pointers, and they can point to some address in memory. Can we have a pointer pointing to some kind of hardware address, and then write to that address, and this will affect the hardware? Or does the hardware have no addresses?

I guess I'm really asking how the OS or BIOS knows where the hardware is and how to talk to it?

+7
c ++ assembly hardware
source share
4 answers

For example, in C ++, we have pointers, and they can point to some address in memory. Can we have a pointer pointing to some equipment address, and then write to this address, and this will affect the hardware? Or does the hardware have no addresses?

Some hardware has addresses such as pointers, some do not (in this case, it most likely uses something called an I / O port, which requires special IN and OUT instructions instead of normal memory operations). But most modern hardware has a memory address somewhere, and if you write the correct value to the correct address, the hardware will do what you ask for it. It depends on a really simple approach - say, the serial port where you write the byte to the "output register", and the byte is sent on the serial line, and the other address contains the input received on the serial port, for graphics that have their own machine language and can run hundreds or thousands of threads.

And, as a rule, it is the OS’s responsibility, through drivers, to gain access to the equipment.

This is very simplified, and the whole subject of programming, OS and equipment is enough to write a rather thick book (and that only in general terms, if you really want to know about specific hardware, it is easy to dozens of pages for a serial port and hundreds or thousands of pages for a graphics chip).

+6
source share

There are whole books on this subject. But briefly:

  • SW speaks differently with equipment. This hardware can respond to values ​​written to very specific addresses ("memory mapped") or through I / O ports and instructions supported by the CPU (for example, x86 in and out instructions). When accessing the port (address) mapped by memory, HW is designed to recognize a specific address or a small range of addresses and route signals to peripheral equipment, and not to memory in this case. Or in the case of I / O instructions, the CPU has a separate set of signals used specifically for this purpose.
  • The OS (at the lowest level - the board support board) and the BIOS have “knowledge” built into them about the hardware address and / or I / O ports needed to perform various available hardware functions. That is, at some level they are encoded exactly what addresses are needed for different functions.
+2
source share

You must read the Soul of the new car , Tracy Kidder. This is the 1981 Pullitzer price, and is very suitable for explaining in non-specialized terms how a computer works and how people should think in order to create one. It is also a true story and one of the few to convey the thrill of hardware and software. All in all, a good introduction to the topic.

+2
source share

Design engineers know where memory and peripherals live in the address space of processors. So this is what is known because these addresses were chosen by someone and documented so that others could write drivers.

The processor does not know peripheral devices from RAM. The instructions simply use addresses that are ultimately determined by the programmers who wrote the software on which the processor runs. Thus, it is correct that peripherals and ram (and rom) are just addresses. If you were writing a video driver and changing the screen resolution, there would be several addresses that you would need to write. At some point, there will be hardware between the processor core and the peripheral device (video card) that checks the address and basically directs it to the right place. This is how the hardware was designed, it analyzes the addresses, some ranges of addresses are marked and sent to the memory that needs to be processed, and some peripheral devices are sent there for processing. Sometimes memory ranges are programmed on their own, so you can organize your memory space for any reason. Just as you move from the place where you live now, somewhere else, you are still in your house, but it has a different address, and the postal people who deliver the mail know how to find your new address. And then there are MMUs that add a layer of protection and other features. MMU (memory management unit) can also virtualize the address, so the processor can be programmed to write to the address 0x100000, but mmu transfers it to 0x2300000 before it goes off on a regular bus, which will be sorted as a memory or peripheral device, Why do you need to do this , and even two main reasons. One of them is that, for example, when you compile an application to work on your operating system, all programs for this OS can be compiled to work at the same address, for example, address 0x8000. But there is only one physical address 0x8000 (suggesting) what happens when the operating system configured mmu for your program, so that your program things work at that address, also the operating system can, if it chooses, and mmu has this function to add protection, so if your program tries to access something outside the allocated memory space, then an error occurs and your program fails to do this. Prevention of hacking or memory failure of other programs. Similarly, if the operating system supports this, it can also use this error to swap some data from ram to disk, and then provide you with more virtual memory, allowing programs to think that they have more memory than they actually are. MMM is not the only way to do all this, but it is a popular way. Therefore, when you have a pointer to C ++ running on some operating system, most likely it is a virtual address, not a physical address, mmu converts this address that was transferred to your program into a real memory address. When os decides to disable your program for another, it is relatively easy to tell mmu so that the other task thinks this is a small numbered address space of 0x8000, for example, now belongs to another program. And your program falls asleep (not executed) for a while.

+1
source share

All Articles