Welcome, To Be Efficient


Saturday, June 27, 2009

BIOS Programming with MS-DOS 16 bit

  • Lowest 640k bytes: used by OS and applications
  1. Interrupt Vector Table(1k bytes, 00000-003FF)
  2. BIOS and DOS data
  3. Software BIOS
  4. MS-DOS Kernel
  5. Resident Command processor
  6. Transient programs
  • Video graphics and text
  • Reserved( Device Controllers)
  • ROM BIOS(F0000 to FFFFF)

Interrupt
>If you call your friend and his/her mom says he/she is not home, what do you do?
>Do something else, and get interrupted when he/she is back and returns your call.
>When you are interrupted by a phone ring, you must somehow know who is interrupting you and what he/she wants.
>Based on the type of interrupts, you then do the required operations.
>After serving the interrupt, you return to the operations before interrupt.



>You may be interrupted by external events, e.g. phone ring, or internal events, e.g. fetch a soda while studying.
>Analog in processor:
>>Interrupts may be triggered by hardware, e.g. I/O devices, which is outside of your program.
>>Interrupts may also be trigger by software, e.g. program faults or system service calls, which is generated by your program itself.
>Software interrupt:
>>A call to an OS procedure (interrupt handler), mainly for I/O



Hardware Device Initialization
>At startup, a hardware device is assigned:
>>An IRQ by which it can signal the CPU that it needs attention
>>Some I/O addresses by which the CPU and the device can communicate
>>Some memory addresses that indicate where the program to manage the device can be stored



>>Perhaps a DMA channel to speed up sending its data to memory

INT Instruction
>Executes a software interrupt to request MS-DOS services
>>The code that handles the interrupt is called an interrupt handler (or interrupt service routine (ISR))
>Syntax: INT number (number =0..FFh)
>>The Interrupt Vector Table (IVT) maps an interrupt number to a 32-bit segment-offset address for each interrupt handler.



INT Vectors



>In Interrupt Vector Table in 00000h-003FFh (1KB)
>For the execution of INT 00-FF
>Each INT uses a 4-byte vector (CS:IP):
>>2 bytes for IP
>>2 bytes for CS
>Actual code (Service Routine) is in CS:IP
>IRET at the end of INT Service Routine

Interrupt Vectoring Process

Step 1:
>The operand of INT is multiplied by 4 to locate the matching interrupt vector table entry
Step 2:
>CPU pushes flags and a 32-bit return address on stack, disables hardware interrupts, and calls using the address stored at location (10h * 4) in the interrupt vector table (F000:F065)
Step 3:
>Interrupt handler executes until IRET is reached
Step 4:
>Pop the stack and return to application program



Common Interrupts



Software interrupts will call interrupt service routines (ISRs) either in BIOS or DOS
>INT 10h Video Services
>INT 16h Keyboard Services
>INT 17h Printer Services
>INT 1Ah Time of Day
>INT 1Ch User Timer Interrupt
>INT 21h MS-DOS Services



Example: Hello World
.model small
.stack 100h
.386
.data
message BYTE "Hello, world!",0dh,0ah
.code
main PROC
mov ax,@data ; initialize DS
mov ds,ax
mov ah,40h ; write to file/device
mov bx,1 ; output handle
mov cx,SIZEOF message ; number of bytes
mov dx,OFFSET message ; addr of buffer
int 21h
.exit
main ENDP
END main












No comments:

Post a Comment

Disclaimer

.........................................................................................................................................................
The all content are through my experiences, that i have learn in going through Studies and in building projects, some of were taken from some web sites, books and other sources, where i have visited and learn the concepts, I am very thankful to them for having those valuable things, which make me more efficient, and i have added those all in my experience. If any of these content violets copyrights, please contact me i will try to resolve and will do the needful assistance. Thank you all very much.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................