MS DOS was designed for 8086 processor. 8086 has 16bit data bus and 20bit address bus. It can have physical memory range from zero to 1MB(0x0 -0xFFFFF). It has general purpose CPU registers like AX, BX, CX, DX, SI, DI, SP, BP, IP, and segment registers CS,DS,ES,SS,GS,FS. All registers are 16 bit wide. CPU has 16bit data lines and 20bit address lines. It also has control lines like clock, MEMRead, MemWrite, I/O read/write and interrupt and DMA control lines. A preriferal like PS/2 keyboard controller, or mouse controller, VGA card etc can be connected to these bus lines via a bridge. This bridge steps down CPU clock to lower clock speed to match peripheral clock speed. CPU can access peripheral memory mapped registers via MOV instructions. CPU also can access I/O registers via IN/OUT instructions. Again peripheral can inform CPU about some events via interrupt lines.
PC architecture has 640 Kb of conventional memory. This range is from 0x0-0x9FFFF) . Above this there is a memory hole till 0xE0000. Peripherals like VGA display card maps its internal video memory(VRAM) to the address fromm 0xA0000 to 0xBFFFF). Above this address there is a hole for BIOS ROM and ROM for addon card. BIOS takes address 0xE0000-0xFFFFF) Below this 0xC0000-DFFFF is for BIOS rom for add-on cards. CPU can also access peripheral registers like it access system memory.CPU has MOV instruction. MEMRD/MEMWR control line get activated depending on the direction of the data flow. This mechanism is simple and this can be done with simple pointers in C. Thus C runtime does not have any functions. We will access video memory of VGA card when it is in text mode. VGA card takes character array from location 0xB8000 and creates a 80x25 text console. Each character takes two bytes. First byte is the ASCII value of the. Second byte contains foreground and background color attribute. Here we will access starting of VRAM and copy ACSII character and color attribute one by one via memory pointer. We will see the output at the VGA monitor. This is the basic principle of giving output to VGA text screen which is used in printf.
MMIO is used when a large range of memory like VRAM is needed to be accessed. Peripherals often implement small range I/O control and status registers. These registers works in I/O address space. CPU can access I/O range via 16bit I/O address space. I/O read and write are control lines and 16bit lower bits of the same memory address lines are used for I/O access. CPU controls I/O trans via IN and OUT instruction. It generally puts 16bit I/O address in DX register and accumularor AX is used for data transfer. If instruction is IN then data flow would be from peripheral to AX. If instruction is OUT then value of AX would transfer to pheriferal. C library has a series of wrapper function like inport inb, inportb, inw, inl for reading I/O register and outport, outb, outportb outw, outl etc for writing to I/o re
We discussed till now is either reading or writing pheferal registers. Now there are situations when peripheral wants to inform CPU about some events like read completion, write completion or errors. These are asynchronous events. Each hardware has a interrupt line connected to interrupt controller. Finally there is INTR line from interrult controller is attached to CPU. Another line Inta is backfeed to interrupt controller which acts as a acknowledge line from CPU. Peripheral generates interrupts and interrupt controller feeds this signal to CPU. CPU changes context to interrupt and interrupt controller gives vector number to CPU and CPU jumps to the code for this vector. OS default Interrupt handler saves current user context to the stack and switches to kernel stack. Then it executes code inside interrupt vector. C library provides getvect and setvect routines. to get vector address of a interrupt number ansystem provides Getvect
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average