CPU

CPU

July 29, 2023 | permanent

tags
Electronics, Computers

How OS, CPU communicate? #

  • CPU calls OS for specific tasks using interrupts, and
  • OS uses special privileged CPU registers to program CPU
  • For example, when you press key on keyboard, interrupt is generated by hardware.
  • CPU calls interrupt handler function (it is part of OS), which will handle keypress and, for example, pass it into user program.
  • Other example of frequent OS-CPU interaction is task switching. Most OS uses hardware timer to generate around 100 timer interrupts every second. On this interrupt OS scheduler is called, and sometimes it can switch tasks by changing some CPU registers. In simplest OS & CPUs, scheduler will change SP (stack pointer) and PC (program counter) register. With more complex CPUs it will also reprogram MMU hardware unit of CPU and change many internal control registers. stackoverflow

External hardware usually programmed by drivers by doing PIO writes or writes to mapped PCI space (writes to special addresses of hardware memory).

How OS and CPU executes a Program? #

Quora The OS:

  1. creates an entry in the process table
  2. creates a virtual memory space for the process
  3. loads the program code, Binary code, in the process memory
  4. points the process instruction pointer to the process entry point
  5. creates an entry in the scheduler and sets the process thread ready for execution.
  6. The application is loaded into memory by the Operating System
  7. CPU executes the instructions stackoverflow

How Program or Binary code runs on different Machines? #

  1. If it’s build for portability and the platforms are compatible, then yes (e.g. 64 bit editions of Windows are able to execute 32 bit and 64 bit Windows executables, but not 16 bit ones anymore), Binary file can be moved.
  2. They’re made for a specific instruction set. Since those are typically extensions and there’s Backward compatibility in x64, you might run older files on newer processors, but not necessarily the other way around. For example, a program compiled for Windows 95 will probably still run on today’s hardware, but you can’t run a program compiled for today’s hardware on an old Windows 95 machine. However, if two machines run completely different instructions, the executables won’t be compatible (e.g. Intel vs. ARM).
  3. Binary code is platform dependent, there are multiple formats with different headers and stuff, but basically there’s always some kind of header working as an index, telling the operating system where to find specific things (such as the main entry point). stackexchange


Go to random page

Previous Next