Live data from Hacker News

What happens when a CPU starts

lateblt.tripod.com

61–70 of 133 posts

Re: What happens when a CPU starts

#62
post #9

"It starts at 0 and executes instructions" is a funny, but mostly true way to express this. Some people are shocked that no magic happens before the instructions start.

This is pretty old. There's quite a lot that happens before instructions start on modern CPUs. Just one small example: CPUs have many small SRAM arrays for micro-architecture features like branch predictors. Some of these need to be initialized after reset by a state machine that takes many cycles. I have even heard of a large chip that pushes initialization vectors through the scan chains so that all flops begin in…

sidebar, have a question about an older comment of yours that can't be replied to. would you reach out via email (in profile)?

Re: What happens when a CPU starts

#63
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,…

This seems wildly inefficient. Can’t we have multiple sets of registers? Not millions, but… Are registers expensive in hardware? Why not have loads of them?

Registers are expensive, yeah, but pushing them onto the stack isn't the most expensive part of a context switch on a modern cpu anyway. Switching the page table, and blowing away the TLB is. Pushing all the registers is some nice sequential memory activity and the stack area is frequently accessed and unlikely to have contention, so it's easy to cache (other than one or the other of push or pop has to go backwards, so you better have predictive access in both directions)

Re: What happens when a CPU starts

#64
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…

True. It's like what's happened with electronics, radio, video in that way. A solid grasp of the (always-present) basic components, and basic tech and design philosophy, goes a long way. It's like learning a language. So easily-understandable articles like this are essential for beginners, along with a short list of masterful books ( e.g. those by Forrest Mims, for electronics) and playing with physical components! T…

[deleted]

Re: What happens when a CPU starts

#65
post #49

"It starts at 0 and executes instructions" is a funny, but mostly true way to express this. Some people are shocked that no magic happens before the instructions start.

If older CPUs have no magic, what is the 6502 doing here ( https://youtu.be/yl8vPW5hydQ?t=706 ) that causes it to put eb60 → ffff → eb60 → 01f7 → 01f6 → 01f5 on the address bus, before it actually reads from memory?

https://www.pagetable.com/?p=410 may go some way toward explaining this. The behavior is slightly different than in the video. I believe this is because the video is using a 65C02 instead of the original NMOS 6502 and the implementation is slightly different.

Re: What happens when a CPU starts

#66
post #37

Earlier quoted context omitted.

writing programs for old game consoles, Oh yeah, like the Intellivision. particularly the Nintendo DS. Oh come on, the DS ain't that old.

Never done anything but I think the gameboy family is a good choice. Unlike NES or SNES which use assembly heavily, we can use C for the GBA. There are also great communities devoted for them.

You can, but it’s pretty lacking in registers.

Re: What happens when a CPU starts

#67
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,…

This seems wildly inefficient. Can’t we have multiple sets of registers? Not millions, but… Are registers expensive in hardware? Why not have loads of them?

Many processors do have this and expose it to programmers, it’s called “register windows” (though usually used for procedure calls). Or you can have banked registers, which often serve different privilege levels. Once you start looking at the microarchitectural level, you’ll find that modern processors have large register files and rename them into the architecturally visible ones.

Re: What happens when a CPU starts

#68
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…

Macs with a T2 chip first start execution there before pulling the Intel CPU out of reset.

Re: What happens when a CPU starts

#70
> The Z80's system, although simpler, creates a "hole" in the memory, because the bottom of the memory space is used by ROM and therefore you cannot use the beginning of the memory space for normal RAM work.

Gameboy actually does a funny thing where the boot ROM gets mapped at the bottom of the address space, and then it writes to a MMIO address to unmap the ROM overlay and restore the first 256 bytes of the cartridge there instead. It’s quite amusing!

> On some computer platforms, the instruction pointer is called the "program counter", inexplicably abbreviated "PG"

Typo, maybe? Typically it’s called “pc”.

Post reply on HN