Linux System Programming Basics (i) a little basic knowledge of computer architecture

Source: Internet
Author: User
Tags range requires

Whether the device that is connected to the bus on the CPU or inside the CPU has its own address range, can access the same as access to memory, many architectures (such as ARM) operate the device in this way, called memory mapped I/O (memory-mappedi/o). But x86 is more special, x86 for the device to have a separate port address space, the CPU core needs to elicit additional address lines to connect the device (and access to the memory of the address line is different), access to device registers with a special in/out instruction (assembly), rather than and access to memory with the same instructions, This approach is called Port I/O (porti/o).

On the x86 platform, the hard disk is a device that hangs on the IDE, SATA, or SCSI bus, and the program stored on the hard disk cannot be executed directly by the CPU, and the operating system copies it from the hard disk to the memory when it executes the program, which is called loading (load). After the program is loaded into memory, it becomes a task that the operating system dispatches to perform, called a process. The process and program are not one by one corresponding. A program can be loaded into memory multiple times, becoming multiple simultaneous processes, such as opening multiple terminal windows at the same time, each running a shell process, and their corresponding programs are/bin/bash files on disk.

The operating system (OperatingSystem) itself is also a piece of program that is saved on disk, and the computer executes a fixed boot code (called bootloader) at startup to first load the operating system from disk into memory, Then execute the code in the operating system to load the other programs that the user needs into memory. Operating system and other user programs are different: The operating system is resident memory, and other user programs are not necessarily, the user needs to run which program, the operating system to load it into memory, the user does not need which program, the operating system to terminate it, the release of its memory. The most core function of the operating system is to manage the process scheduling, manage the allocation of memory, use and manage various devices, the program that does these work is called the Kernel (Kernel), on a system the kernel program is/boot/vmlinuz-2.6.28-13-generic file, It loads into memory and resides in memory when the computer starts. The concept of operating system in a broad sense also includes some essential user programs, such as the shell is necessary for each Linux system, and Office Office suite is dispensable, so the former is also a broad range of operating systems, and the latter belongs to the application software.

Access to the device is also a bit different from accessing memory. Memory simply saves data without generating new data, and if the CPU does not read it, it does not need to actively provide data to the CPU, so the memory is always passively waiting to be read or written. And the device will often generate their own data, and need to actively notify the CPU to read the data, such as knocking on the keyboard to produce an input character, the user wants the computer immediately respond to their input, which requires the keyboard device to actively notify the CPU to read this character and do the corresponding processing (hard interrupt), to This is implemented by the interrupt (Interrupt) mechanism, each device has a broken line, connected to the CPU through the interrupt controller, when the device needs to actively notify the CPU to raise an interrupt signal, the CPU is executing the instructions will be interrupted, the program counter will point to a fixed address ( This address is defined by the architecture, so the CPU takes the instruction (or jumps to the address) from this address, executes the interrupt service (Isr,interruptservice routine), completes the interrupt processing, and returns to the place where it was interrupted before executing the subsequent instructions. For example, when an architecture rule breaks to the address 0x00000010 execution, it is necessary to load an ISR program into this address beforehand, and the ISR program is part of the kernel code that first determines which device caused the interrupt, Then call the device's interrupt handler function for further processing. Because each device operates differently, each device requires a specialized device driver (Devicedriver), and an operating system requires a large number of device drivers to support a wide range of devices, and in fact the majority of the Linux kernel source code is a device driver. Device drivers are usually a set of functions in the kernel, which can be used to initialize, read and write devices by reading and writing device registers, and some devices also provide an interrupt processing function for ISR calls.

MMU (memorymanagement unit) maps VA to the PA is in page (page), the 32-bit processor's page size is usually 4KB. For example, MMU can map a page of VA 0xb7001000~0xb7001fff to a page of PA 0x2000~0x2fff through a mapping item, and if the CPU execution unit accesses the virtual address 0xb7001008, the physical address that is actually accessed is 0x2008. A page in physical memory is called a physical page or a page frame (pageframe). Which page of virtual memory is mapped to physical memory which page frame is described by the page table (pagetable), the page table is in physical memory, and MMU finds the page table to determine what PA the VA should map to.

The operating system and the MMU are compatible with this:

1. The operating system performs some instruction in initializing or allocating, releasing memory, filling out the page table in physical memory, and then using the instruction

Set MMU to tell MMU where the page table is in physical memory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.