Sign in to follow this  

software and hardware interaction

Recommended Posts

I would like to gain a some knowledge on the control of hardware, say a monitor interacting from an operating system,  What is the lowest level like and how does the software do this?

 

 

Thank you,

Joshua

 

Share this post


Link to post
Share on other sites

Do you have a particular piece of hardware you'd like to interact with?

Are you trying to make an OS?

Depending on what you want to do a good place to begin might be the Windows DDK (driver development kit).

Alongside the DDK data sheets and programming guides for certain chips that are in certain products would be a good read.

Another good place to start might be OS programming websites, or old DOS based programming books/sites since the OS didn't protect hardware access.

Become familiar with terms like interupts, DMA, MMIO, and I./O address space.

 

But basically reading and writing to special registers and memory areas which are mapped to the CPU address space is how its done.  But each piece of hardware is different in how its controlled.  For example AMD video cards are controlled differently than nvidia video cards and USB ports are still different to both those (and different brands of USB are different.

Share this post


Link to post
Share on other sites
Try taking a look at some sites like osdev.org, which will provide you with a wealth of information and even source code as low level as it's possible to go without creating your own hardware or flashing the bios with your own code (neither really recommended these days).

Let me know if this helps!

Share this post


Link to post
Share on other sites

Anything your high-level program does is never interpreted directly by hardware in a modern system.

Even what you visualise as machine code opcodes are just handled by microcode, interpreted at some level within the cpu to a more pure form...

A modern pc is like a huge game of "Chinese whispers", where each layer whispers a command to the next which is reinterpreted into a more suitable form.

Assuming you're running a c++ program on Windows 10, there are probably about 15 layers between you and the hardware. If you're executing .NET CIL code, many more layers exist on top of that.

It's important to only concern yourself with the layers that immediately concern what you want to achieve as there's many man-centuries of code and computer science between you and that discrete electronic signal bouncing around transistors.

Hope this helps!

Edited by Brain

Share this post


Link to post
Share on other sites

what I mean is the signal from the programming command to the actual computer.  Maybe this is a different answer.  I am at the level of how does a command turn into any sort of electronic signal.

 

Thank you,

JoshuaE

Share this post


Link to post
Share on other sites

That sounds right, I'll stop at the library and look at a visual dictionary for hard drive.  I think I may be forgetting that the software is digital being that its stored digitally.

 

Thanks to everyone,

Joshuae 

 

Of, course we were talking about OS too.

Edited by Josheir

Share this post


Link to post
Share on other sites

You mean secondary storage devices like hard drives, SSD's, USB sticks...   Again what do you want to know?  The basic jist of it is that the real world is analog and computers are digital so at some point you need to convert between the two.

Share this post


Link to post
Share on other sites

Digital as in "1s and 0s" doesn't exist at the lowest level in the entire computer. It's an electric system, 1s and 0s get stored and transported as different voltages. Transistors are used to switch on or off based on existence of a voltage. There are ways to "store" voltages (or lack thereof) over time.

With incredible amounts of wires and transistors, and smart usage of these you get what we know as computer :)

 

"Structured computer organization" by Tanenbaum will give you all the details you want:

https://www.amazon.com/Structured-Computer-Organization-Andrew-Tanenbaum/dp/0273769243/ref=dp_ob_title_bk

Share this post


Link to post
Share on other sites

That's very interesting Alberth, thank you!  I thought of a keyboard and thought maybe it was different milliamperes for the keys now I'm thinking it's the voltage.  Does a keyboard use prime numbered voltages?

 

Thank you,

Joshuae

Share this post


Link to post
Share on other sites

That's very interesting Alberth, thank you!  I thought of a keyboard and thought maybe it was different milliamperes for the keys now I'm thinking it's the voltage.  Does a keyboard use prime numbered voltages?

 

Thank you,

Joshuae

Generally it's a kind of button matrix, where a microcontroller can test for the 0-equivalent and 1-equivalent voltage across every button.

http://pcbheaven.com/wikipages/How_Key_Matrices_Works/

Share this post


Link to post
Share on other sites

That's very interesting Alberth, thank you! I thought of a keyboard and thought maybe it was different milliamperes for the keys now I'm thinking it's the voltage. Does a keyboard use prime numbered voltages?
It started with analog computers see https://en.wikipedia.org/wiki/Analog_computer

where variable values were electronic voltages, and a program was an electric circuit. Infinite precision for free, but not very accurate due to inaccuracies in the electronic components (due to aging and varying temperatures).

 

Digital computers are completely digital, ie 2 voltages everywhere. For a keyboard, the keys are detected with a wire matrix, as Hodgman linked to, transfer to the computer is serial, ie 1s and 0s over time, through a single wire (and a second ground wire, as the common reference point). To get an idea of how that works, an ancient serial RS-232 connection is probably one of the simplest protocols, see https://en.wikipedia.org/wiki/Asynchronous_serial . Usual there are more wires, eg for control flow.

Serial connections work very well, eg USB and SATA (to/from disks) are serial connections too.

 

Everything is voltage based in computers, as that gives much better switching times, but there exist current based protocols too, eg RS-422, an industrial serial protocol like RS-232, but it uses currents to represent 1s and 0s. Big electric motors switching on and off gives huge voltage spikes in nearby wires due to induction, so running a RS-232 at a factory floor doesn't quite work, the voltage spikes mess up the 1s and 0s voltages. Current is much more stable in such an environment.

Share this post


Link to post
Share on other sites

The CPU is a logic controller that reads assembly instructions from a loaded program in RAM which dictates how program memory is manipulated in RAM, and also how input signals are interpreted and output signals are generated. In the case of modern OS's, the output signals are typically generated over a USB connection, which requires that the program explains to the CPU how to interact and accept the USB device, along with device drivers that basically handle the actual interpretation of hardware signals over USB and generalize them (and responding to them) via an abstraction called an API, or 'Application Programming Interface', which is just a collection of functions that generalize everything that could happen with whatever hardware is communicating via USB.

 

However, it's been the same since the original serial and parallel ports that proceeded the 'universal serial bus' of modern times.

 

For graphics, and audio, you *could* control such things over USB, serial, parallel, but they have become their own core parts of the computer because they've been essential since the dawn of the personal computer. So they have their own means of communication. But you could just as well develop your own protocol for communicating with a robotic body via audio output or video output: it's all about the output signals generated and what they are intended to do on the recipient hardware.

 

It's actually not that complicated once you understand how a CPU itself works.

Share this post


Link to post
Share on other sites
Posted (edited)

I am at the level of how does a command turn into any sort of electronic signal.


 
It's not easy to answer this question because a "command" is an abstract concept. There's no such thing as a "command" at the hardware level. Nor is there any "stack" or "memory" etc. The deeper down you go the more concrete everything gets. Concepts created through abstractions no longer bear any meaning.
 
It may be worth looking into automata theory. Computers in their "lowest software form" consist of combinational logic, which is stateless and time independent (it's just boolean functions). In the earlier days, combinational logic was organised together directly in hardware to create an abstract turing machine capable of "executing instructions". In modern CPUs, this became less feasible due to it being inflexible, so a method for dynamically being able to organise boolean circuits using a hardware description language (such as  verilog, VHDL, SpinalHDL or whatever) was devised, making it possible to describe things such as finite state machines or turing machines in software. These descriptions are synthesized and programmed into a hardware device, thus creating something that behaves like a modern CPU. This is what we know as "micro code", which is a stupid name in my opinion, because it creates this false idea that the CPU is "running a program", when in fact the micro code is conceptually operating 3 classes below a turing machine.
 
If you go deeper, you will see that combinational logic can be implemented in many different ways in hardware. It is not restricted to just "2 voltages" nor is it restricted to being a voltage (as previously mentioned). One could for example choose to build an electrical circuit that computes boolean functions using analog current levels. You would then quantize these levels to form the concept of a "digital value". The number of quantization levels can be arbitrary. One might even go further and implement an optical or mechanical solution to computing boolean expressions.
 
But sticking to electrical circuits: These days, combinational logic is largely implemented using CMOS technology; Transistors that turn "on" and "off" (this is an over-simplified way of thinking about it).
 
So to answer your question to some degree: A specific CPU "command" or "instruction" is encoded in memory by a series of transistors that are either turned on or off and are most likely located in one of the chips on one of your RAM sticks. The fetch of these "bits" into the CPU's instruction cache is achieved over a bus (a parallel routing of copper wires) using some standard protocol. The bits are stored inside the CPU in an abstract piece of memory, which doesn't physically exist, but was instantiated via a hardware description language which describes the behaviour of a collection of lookup tables inside the CPU, which in turn were implemented using CMOS technology, thus organising a number of transistors in such a way as to create something that behaves like memory. Depending on what the instruction is, it will cause a series of state transitions to happen on the CPU (the transition functions being described in a hardware description language and also programmed into hardware lookup tables) which will eventually lead to some result data being computed and transferred to some other place in your computer.
 
Going deeper, it is important to realise that an analog circuit is a superset of everything digital, meaning that any digital circuit is by definition analog. A circuit that implements the evaluation of a boolean expression exhibits some complicated analog phenomenon (which can be ignored if you aren't directly involved with the fabrication of the circuit). For example, look at this picture (blue line) to see what the voltage and current does when a complementary MOSFET transistor pair switches from "off" to "on". While the circuit will perform as expected most of the time, random events can occasionally happen, causing a bit to be flipped every now and again. This is why almost every transport of data goes through some form of error check (ranging from a simple parity check to CRC, depending on how important the data is). 
 
You can go even deeper and start looking at how the lattice of silicon atoms transport electrons, and how impurities ("doping") of the lattice cause electrons to be under- or oversaturated, and how electrical fields influence how electrons are transported across silicon lattices with different dopings to eventually construct a physical chunk of atoms that behave like a transistor.
 
Indeed, you can go even deeper and touch on quantum mechanics, as has also been previously mentioned in this thread, which introduces even more weird stuff that can interfere with the normal digital operation of the circuit. This is especially relevant when dealing with very tiny transistors. But we've reached a level where going deeper just gets less and less relevant.

Edited by TheComet

Share this post


Link to post
Share on other sites

@TheComet, that was an awesome description of electronics, computing and even electrical engineering that I wish I could +1 multiple times :)

It's almost like the "in the beginning, the engineer said" let there be electrons"..." of descriptions :)

 

There is no spoon.

 

Actually, if you want to pursue this to the extreme, what might have more value knowledge-wise is find a handy youtube video on building analog computers out of tinker toys, Lincoln logs, there's probably videos on how to create simple logic gates using light bulbs and switches, which I played with as a kid. Google Babbage's engine. Quantum computing is getting into reality, there's a cool topic.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this