Live data from Hacker News

What happens when a CPU starts

lateblt.tripod.com

101–110 of 133 posts

Re: What happens when a CPU starts

#101
One route to understanding how CPUs work is to explore the computers that have been made in cellular automata. Golly (https://golly.sourceforge.net/) has several, including one by John von Neumann, one by Edgar Codd and another by John Devore. The advantage of course is that the physics is trivial and you can see everything that happens and step backwards and forwards.

Example:

https://timhutton.github.io/2010/03/10/30984.html

https://github.com/GollyGang/ruletablerepository/wiki/CoddsD...

Re: What happens when a CPU starts

#102
post #13
post #3

Amongst the first sentences... > It may be thought of as what happens when a whole computer starts, since the CPU is the center of the computer and the place where the action begins. I thought that too. Last year I spent a while getting as low-level as I could and trying to understand how to write a boot loader, a kernel, learn about clocks and pins and interrupts, etc. I thought, "I know, I'll get a Raspberry Pi! Th…

As early as the mid-70s, minicomputers started including microcontrollers to manage the boot environment. I had a Sun machine once that included what they called Lights Out Management. A little microcontroller that had control over the system power and etc. Always available via its dedicated serial port, even when the machine was shut off. Everything is like that now. A smartphone will have multiple processors. Some…

A recurring question I have is: how many microcontrollers/CPUs are in a modern personal computer? There are clearly a lot, but just how many?

Re: What happens when a CPU starts

#103
post #97
post #48

Earlier quoted context omitted.

Yeah, more or less; mostly more. pusha/pushad is one of those instructions that sounded good, but isn't used much (it became invalid in amd64), windows will push the registers one at a time, and maybe FPU, MMX, SSE, etc registers; of course, that's a lot of extra pushing, so there's strategies to avoid it if the thread doesn't use them. If you switch to a different task, you're going to need to load its page tables,…

> windows will push the registers one at a time Wouldn't Windows (and Linux) use the FXSAVE instruction instead?

Probably FXSAVE or XSAVE for the mathy registers, yes. But that doesn't cover the general purpose registers, and (F)XSAVE can be skipped if the process in question doesn't use fancy math (easy to detect, disable it, when the process uses it, the kernel will catch the fault, then enable it and set a flag on the process so it saves and restores that state as well)

Re: What happens when a CPU starts

#104
post #3

Amongst the first sentences... > It may be thought of as what happens when a whole computer starts, since the CPU is the center of the computer and the place where the action begins. I thought that too. Last year I spent a while getting as low-level as I could and trying to understand how to write a boot loader, a kernel, learn about clocks and pins and interrupts, etc. I thought, "I know, I'll get a Raspberry Pi! Th…

> Turns out the Raspberry Pi (and I'm guessing many other systems) are pretty confusing to understand at boot time.

That is because how ARM ecosystem functions. There is no standard way of integrating ARM CPU into a product as Arm, the company, just sells base IP and not the complete CPU. Every ARM licensee, from Qualcomm to Apple to Nvidia are free to design their own extensions and integrations into their SoC. There is no standard for this. This creates a lot of problems for writing a generic tutorial that you see in the x86 world.

Re: What happens when a CPU starts

#105
Could anybody clarify for me the purpose of the NOP opcode that the article refers to? I would think that something like a "do nothing" instruction would want to be optimized away as much as possible, but maybe there's some hidden facet of the instruction protocol I'm not familiar with that necessitates it?

Re: What happens when a CPU starts

#106
post #13

Earlier quoted context omitted.

As early as the mid-70s, minicomputers started including microcontrollers to manage the boot environment. I had a Sun machine once that included what they called Lights Out Management. A little microcontroller that had control over the system power and etc. Always available via its dedicated serial port, even when the machine was shut off. Everything is like that now. A smartphone will have multiple processors. Some…

A recurring question I have is: how many microcontrollers/CPUs are in a modern personal computer? There are clearly a lot, but just how many?

- the embedded controller (EC)

- the CPU core in the chipset that runs the ME/PSP

- if the TPM is not an fTPM, it has a CPU I'm sure.

- if your NIC has offload engines, it has a CPU or two.

- each storage device has a CPU.

- each Wi-Fi device has a CPU.

- thunderbolt controller takes firmware, it has a CPU. I'd bet USB3 and 4 do too.

- any USB device has a CPU on the other end accepting and interpreting commands.

- same with any SCSI device.

- monitors have a CPU or two, one for the OSD settings and another to drive the display I'm sure.

- I think any nVidia or AMD graphics card has a CPU in there (in addition to the GPU).

- The following portable media has microcontroller firmware: SD cards, Memory Stick. (The now defunct SmartMedia and Olympus XD were raw NAND).

- your optical mouse has a CPU as well to process optical data.

- obviously printers have CPUs and firmware, probably separate ones for the web UI and the part that drives the actual print mechanism, and I'd bet a separate one for scanning and image processing.

- any keyboard has a microcontroller and firmware (there are open source keyboard firmwares)

- SIM cards for cellular connections have their own CPU and firmware.

Re: What happens when a CPU starts

#107
post #89

Ben Eater's fantastic video series on building a breadboard 6502 based computer and an 8-bit breadboard computer from scratch might be appreciated in this thread. 6502 playlist: https://www.youtube.com/watch?v=LnzuMJLZRdU&list=PLowKtXNTBy... 8-bit build playlist: https://www.youtube.com/watch?v=HyznrdDSSGM&list=PLowKtXNTBy... He also sells kits if one is interested in playing along.

Similarly, I have come to appreciate rehsd's[0] efforts in building a 80286 computer. 0. https://www.youtube.com/@rehsd/videos

Wow, that series looks fascinating!

Only watched the first video yet, after initializing itself the CPU actually runs this code (because D8-D15 is wired to zero):

  addr    opcode
  FFFFF0  90           NOP
  FFFFF1  00 90 00 90  ADD [BX+SI+9000],DL
  FFFFF5  00 90 00 90  ADD [BX+SI+9000],DL
  FFFFF9  00 90 00 90  ADD [BX+SI+9000],DL
  FFFFFD  00 90 00 --  !! general protection fault
You can see it read and write the same address three times, then fetch the interrupt 0Dh vector and push flags+CS+IP to the stack :)

Re: What happens when a CPU starts

#108

Could anybody clarify for me the purpose of the NOP opcode that the article refers to? I would think that something like a "do nothing" instruction would want to be optimized away as much as possible, but maybe there's some hidden facet of the instruction protocol I'm not familiar with that necessitates it?

I don't know how much it's really used these days, but when I've done asm stuff before if you have tight timing requirements in assembly, say you're bit banging an IO for some arcane serial protocol a la WS281X LED series, where it doesn't use a hardware supported serial protocol like SPI (where you can just DMA what you want to send to the controller) you then have to implement this protocol manually, in code, switching the IO pin on & off according to the timing requirements of said serial protocol/what data you want to send.

For the purposes of this, the nop instruction is useful as it's a great way to delay the processor for 1 instruction at a time and given you know the clock speed and therefore instructions per second you can: * Set the IO high * Use nops (or other instructions) to waste time * Set the IO low

This is very useful in situations where the timing needs to be too precise to use interrupts, which are somewhat unpredictable. Obviously this means an entire CPU is held up running this code.

Another timing usage is for generating a signal to display a picture on a CRT using a microcontroller. Plenty of others as well.

Personally, though, I would never bother. It's always better to get a dedicated chip/controller for something like driving those stupid LEDs (or just get an SPI LED) or to generate a TV signal.

Reading up on it further, apparently it is also used as a way to reserve space in code memory, I imagine for self-modifying code (ie fill with nops which can be replaced with actual instructions by your code, depending on code execution). But I've never actually done this myself.

Re: What happens when a CPU starts

#110

Earlier quoted context omitted.

A recurring question I have is: how many microcontrollers/CPUs are in a modern personal computer? There are clearly a lot, but just how many?

- the embedded controller (EC) - the CPU core in the chipset that runs the ME/PSP - if the TPM is not an fTPM, it has a CPU I'm sure. - if your NIC has offload engines, it has a CPU or two. - each storage device has a CPU. - each Wi-Fi device has a CPU. - thunderbolt controller takes firmware, it has a CPU. I'd bet USB3 and 4 do too. - any USB device has a CPU on the other end accepting and interpreting commands. - s…

forgot memory controller

https://en.wikipedia.org/wiki/Memory_controller

Post reply on HN