<>11.1 Application and hardware
The hardware is controlled by Windows Full responsibility , actually Windows A method of indirectly controlling hardware by application is provided , Using the system call provided by the operating system
Function can achieve the control of hardware , stay Windows in , System calls are called API, various API Is the function that the application calls , The entities of these functions are stored in the DLL In the file
If you want to display the string in the window , You can use it Windows API In Text Out function
‘ Handle to the device description ’ Parameters in hdc, Is used to specify the string and graphics drawing object recognition value , It is not a direct hardware device
Windows In fact, to CPU Some instructions were passed , So the hardware is controlled by software
<>11.2 Support hardware input and output IN Instructions and OUT instructions
Windows I / O instructions are used to control the hardware , The two representative input and output instructions are IN and OUT, These instructions are also mnemonics of assembly language
IN Instruction inputs data through a port with a specified port number , And store it in the CPU In the internal register ,OUT The instruction is to CPU Data stored in registers , Output to the port with the specified port number
In the host computer , The connector is used to connect the monitor, keyboard and other peripheral devices , And inside each connector , All are connected with a circuit for exchanging the current characteristics between the computer host and the peripheral equipment IC. these ones here IC, Collectively referred to as
I/O controller . Due to different voltages , The computer host and peripheral devices cannot be connected directly ,I/O The controller is used to solve this problem
monitor , Keyboard and other peripherals have their own dedicated I/O controller ,I/O There is memory in the controller for temporarily saving input and output data , This memory is the port
, It gets its name from the port, which is like the port for loading and unloading goods between the computer host and peripherals
I/O Memory inside the controller , Also called registers , But it's not the same CPU The internal registers are different ,CPU Internal registers are used for data operations , and I/O Registers are mainly used to store data temporarily
One I/O The controller can control a peripheral , You can also control multiple peripherals , Each port is distinguished by port number , The port number is also known as I/O address
,IN Instructions and OUT The instruction is executed on the specified port and CPU Data input and output between , This is the same as reading and writing main memory through memory address
<>11.3 Input and output program for testing
stay AT In compatible computers , The default port number of the buzzer is 61H, use IN Instructions input data through this port , And lower the data 2 Bit set to ON, Then output the data in the same way , Then the buzzer will ring . In the same way , Lower the value of the data 2 Bit set to OFF And output , The buzzer stops
current Windows The way that the application program directly controls the hardware is prohibited
<>11.4 Interrupt request of peripheral device
IRQ Interrupt request , Used to pause a currently running program , And jump to the necessary mechanism of other programs , This mechanism is called interrupt handling
Interrupt processing plays an important role in hardware control , Because there is no interrupt processing , It is possible that the processing cannot be carried out smoothly
From interrupt processing to request interrupt ( Interrupt handler ) Before the end of operation , Interrupted program ( main program ) The processing is suspended . After the interrupt handler runs , Processing also returns to the main program to continue
Interrupt request is implemented by connecting peripheral devices I/O controller , Responsible for implementing the interrupt handler is CPU, Interrupt requests for peripherals use different I/O Other port numbers , This number is called the interrupt number
, Operating system and BIOS Provides an interrupt handler that responds to the interrupt number
If there are multiple peripheral devices making interrupt requests at the same time ,CPU It's hard to do . At this time, we need to I/O Controller and CPU Add an interrupt controller in the middle
Of IC To buffer , The interrupt controller will send the interrupt requests from multiple peripheral devices to each device in order CPU
CPU After receiving an interrupt request from the interrupt controller , Will interrupt the main program currently running , And switch to interrupt handler . The first step of interrupt handler , That's to say CPU The values of all the registers in are stored in the memory stack . After processing the interrupt request , Will restore the value stored in the stack to CPU In register , Then continue to process the main program
After the interrupt request is completed , The value of each register must be restored to the state before interrupt , As long as the value of the register remains unchanged , The main program can continue to process as if nothing happened
<>11.5 Real time processing with interrupt
Most of the peripherals , Will make frequent requests , The reason is to process the data input from peripheral devices in real time
<>11.6 DMA It can transfer a large amount of data in a short time
DMA
: It means not to pass CPU In this case , Peripherals transfer data directly to main memory , Disk and so on DMA mechanism , By using DMA, A large amount of data can be transferred to main memory in a short time , Why so fast , Because CPU Time as an intermediary is saved
The resource tag contains DMA set up , If a floppy disk DMA Set to 02, that 02 This number is called DMA passageway ,CPU With the help of DMA passageway , To identify which peripherals are used DMA
I/O Port number ,IRQ,DMA Channels can be said to identify peripherals 3 Point combination , however IRQ and DMA Channels are not required for all peripherals . Suppose multiple peripherals have the same port number ,IRQ,DMA The passage , The computer will not work properly , appear ‘ device conflict ’
<>11.7 Display mechanism of text and picture
The information displayed in the display is always stored in a memory , This memory is called VRAM
, In the program , Just go VRAM Write data in , The data will be displayed on the display , The program to realize this function , Is it by the operating system or BIOS provide , And with the help of interrupt to deal with
In today's computers , Graphics card and other special hardware are generally equipped with independent memory VRAM and GPU ( Graphics processor )
, For those who often need to draw graphics Windows For , Larger VRAM It is necessary , And in order to improve the drawing speed of graphics , Sometimes special graphics processing is needed . But anyway , Memory VRAM The data stored in is the information displayed on the display , This mechanism remains unchanged
Using software to control hardware , In fact, it's just using input and output instructions to process input and output with peripheral devices . Interrupt handling is an optional function that is used on demand ,DMA Then it is directly handed over to the corresponding peripheral equipment
Technology