This is the 9th day of my participation in Gwen Challenge.

Hardwired to von Neumann

Actually the earliest computer is no storage mechanism, through hard wiring to programming, the programming is the wiring, then the computer has the storage mechanism, some instructions and data can be stored, so there will be a able to reuse existing basis, to store binary information by electricity and magnetism, replace the hard wiring.

Computer can store because it is the realization of the Turing machine model, the storage of parts corresponding to the tape of the Turing machine model, von neumann architecture (modern computer architecture) is the realization of the Turing machine, it designs the expressed in binary machine code, storage and computer five components: input, output, control, computation and storage.

Today’s computers have registers in the CPU and L1, L2, L3 caches, as well as memory and hard disk storage. These six levels of storage media are the storage system of the computer. Computer development to the present storage system, storage has been a common sense. Storage is the foundation of program reuse, and you can execute some written code repeatedly. And the emergence and development of compilation, so that we do not have to input machine code, we can use high level language of character programming, and then compiled into binary machine language.

CPU with clock and jump

The program is ultimately executed by THE CPU, and what instructions the CPU executes is controlled by the CS + IP register. The CPU will continuously take the instructions of the memory address represented by these two registers, read into the CPU through the data bus, and then decode with the decoder and execute with different circuits. Take instructions, decode, execute instructions, this is a CPU always cycle, CPU will be infinite cycle this process, the execution frequency of instruction cycle is controlled by the clock, there is a certain frequency, some computers can support a short time of overfrequency, is to improve the frequency of the clock. CPU is cyclic clock cycle ceaselessly, so always should have an initial address, this address is fixed address commonly, put the first instruction that the computer is loaded after electrization, this part of the code is called BIOS (basic input output system), it is the foundation that all subsequent programs execute. The flow of control is supported by instruction support for jumping to another address. As mentioned above, the CPU is constantly cycling the clock cycle, so there is always a way to control its steering, steering control function is through the jump command, so the JUMP command is the STEERING wheel of the CPU. The instructions and data can be placed anywhere in the memory, and the JUMP steering wheel directs the CPU there.

CPU is a car, so the clock is the engine, controlling the frequency of CPU execution instructions, and which instructions are stored in the CS + IP register, it will only drive forward, that is, it will only continue to take the next instruction, and steering (that is, control flow) is controlled by the jump instruction. Run anywhere in memory to fetch instructions to run on the CPU, and the first part of the way is where the BIOS program resides.

BIOS, bare – metal, and operating systems

BIOS program actually won’t write himself generally, unless do embedded, develop directly in bare machine (the computer that does not have operating system) on, that need oneself to do program’s guide, oneself can control instruction existence which, data existence which, take from where. This logic is too general, and there is only one control flow, only one path and scenery, which does not take full advantage of the CPU. To solve this problem, there are operating systems, which can have multiple control flows, that is, the car has multiple paths and can see different scenery.

Operating systems have their own BIOS program, is a way of the CPU at the beginning, to bring the CPU where the operating system, operating system generally provides process mechanism, and the memory management, is no longer optional disorderly use, but need to apply for, as we have to manage things within an enterprise will be asked to do the examination and approval flow, Memory is allocated only after the application is made, and the process’s programs reside on this memory. Logic is one flow of control, and processes can have multiple flows of control. Although a car (a CPU) can only run in one place at a time, it can run for other processes when other code does not need it, like a carpool when it is not used. The CPU is always running, why is there any time when it is not used, because devices such as disks or network cards have their own controllers, called DMA, and when they run to that location, they ask the DMA to carry things, just like ordering a truck but carrying things yourself. As the DMA moves device data to memory, the CPU has to wait and is idle. At this point, it’s better to run somewhere else, or you can just wait and do nothing (blocking). CPU can run other code in IO, run the route is called control flow, control flow also has two types, one is process, one is thread, thread can access the process allocated memory and other resources, and different processes have their own allocated resources, can not access each other, need to use other memory to do transfer.

As we know, when the bare computer program can access and operate all memory, controlled by the program itself, but with the operating system, it is necessary to follow the specifications of the operating system, the operating system has format requirements for executable files, only a certain format can be used as machine code to execute, Windows is exe format, Elf format on Linux and other systems. The ELF format divides the file into code segments (text), data segments (data) and other parts to hold different data, so that the file will be loaded into memory in different places, and then code execution from the text segment, global data from the data segment, and memory occupied by the call stack and heap at runtime. Different processes load their own executables in their own memory, and then form different control flows during execution, placing different data on stacks and heaps. This is operating system limited memory management, determined by the operating system, with less freedom than bare metal (must be executable file format), but more capabilities provided by various operating systems (system calls and standard libraries).

Memory management for the operating system and VM

Operating system to the executable file to run up to the process of the allocated memory, and then the process can be internal division, vm, for example, will do it again on your own memory memory management, various kinds of interpreted languages is run in the memory, because of their management, don’t have different operating systems have different memory format, can be unified into a (cross-platform). For example, the JVM has method areas, static fields, stacks, etc., while the JS VM has global scope (similar to static fields), call stacks (stacks of function contexts), stacks, etc. These VMS do another layer of memory management themselves, so the bytecodes and so on are subject to memory management that is not of the operating system, but of the VM’s own design. However, no matter how to design, always store code, data, dynamic allocation is basically in the heap, global data in the static domain, there is a call stack maintenance context, this is a general design.

Memory management mainly manages the writing and modification of code and data in a certain location of memory. A certain block of memory is referenced by variable. Different variable types refer to different sizes of memory. From arbitrary memory modification on bare metal machines, to process-constrained operating memory on the operating system, to further memory design on the VM. The different layers do their own design, but it’s always up to the CPU to run. When the CPU runs to this area of memory, it uses jump to control the steering, while taking advantage of the threading capabilities provided by the operating system, it can run different routes (control flow).

conclusion

This paper is mainly to sort out the history and principles of some computers, from hardwiring to von Neumann system, to level 6 storage system development process is part of the development history, and CPU instruction cycle and clock frequency is the CPU’s working mode, CPU continuously execute instruction cycle, Jumping to other places (changing the flow of control) is done using the jump instruction, which encapsulates if, else, function calls, and so on.

The computer starts to execute the boot program is BIOS, bare computer and operating system are required, the operating system provides process management capabilities, may have multiple control flows at the same time, but also provides a variety of hardware and software management capabilities, exposed system calls and standard libraries. Operating system can load a certain format of executable files, different systems have their own process memory management, and VM is in the operating system allocated memory to do a layer of memory management, now a lot of cross-platform software is based on this running on the VM language. While memory management designs vary from VM to VM, stack and other designs are universal.