php hit counter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS401 Interrupt chaining Assignment 4 June 2010
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
A. What are Interrupts? (in real mode)

Interrupts are signals generated by the computer, by either software or hardware, every time a certain event occurs. For example, anytime a key is pressed at any point during program execution, the 0x09 interrupt is generated, causing the 0x09 interrupt handler to be called, which does its job then returns control back to the program were it left off. The interrupts are numbered from 0x00 to 0xFF and each have a special function (most are unused). In real mode, the first 1,024 bytes of memory of the computer are used as the interrupt handler table. This table has a 4 byte far address to the interrupt handler (Interrupt Service Routine - ISR) for each of the 256 interrupts. Interrupts may also be simulated by calling them with the INT command in real mode, or the __dpmi_int command in protected mode

B. Protected Mode

C. Adding your own ISRs

Many times it is useful to have your own functions be automatically called every time a specific event occurs, without having to continuously check for it. This can be done by changing the proper entry in the interrupt handler table to point to your new ISR. But many times you must have your ISR first call the original ISR to make sure the event is handled properly. To do this the address of the original ISR must be taken, and the old ISR must be called from within the new ISR. This is called chaining. The whole process is implemented in the next section

II. Implementation in DJGPP (protected mode)

A. Using _go32_dpmi functions

There are three steps to using custom interrupt handler functions

Get the address the current ISR and save it
Chain your new ISR onto the old on
Replace the old ISR once the program is done
the whole process is shown in the example code below.
//Simple Example of chaining interrupt handlers
//Adopted from Matthew Mastracci's code

#include <stdio.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>

//macros by Shawn Hargreaves from the Allegro library for locking
//functions and variables.
#define LOCK_VARIABLE(x) _go32_dpmi_lock_data((void *)&x,
(long)sizeof(x));
#define LOCK_FUNCTION(x) _go32_dpmi_lock_code(x,(long)sizeof(x));

//timer interrupt 8 is generated every 18.2 ms
#define TIMER 8

//global counter
int counter = 0;

//the new ISR, will be called automatically every 18.2 ms once
installed

void TickHandler(void)
{
counter++;
}


int main(void)
{
//structures to hold selector: offset info for the ISRs
_go32_dpmi_seginfo OldISR, NewISR;

printf("About to chain the new ISR onto the old timer ISR..\n");
getkey();

//lock the functions and variables
LOCK_FUNCTION(TickHandler);
LOCK_VARIABLE(counter);

//load the address of the old timer ISR into the OldISR structure
_go32_dpmi_get_protected_mode_interrupt_vector(TIMER, &OldISR);

//point NewISR to the proper selector: offset for handler function
NewISR.pm_offset = (int)TickHandler;
NewISR.pm_selector = _go32_my_cs();

//chain the new ISR onto the old one so that first the old timer ISR
//will be called, then the new timer ISR
_go32_dpmi_chain_protected_mode_interrupt_vector(TIMER,&NewISR);

//notice no changes to counter in this loop- the interrupt
//changes it
while (!kbhit())
printf("%d\n",counter);

printf("Removing new ISR from the timer ISR chain\n");

//load the old timer ISR back without the new ISR chained on
_go32_dpmi_set_protected_mode_interrupt_vector(TIMER, &OldISR);

return 0;
}
B. Using other DPMI functions

there's a bunch of them that are for doing stuff with interrupts

C. Calling (simulating) Interrupts

The __dpmi_regs structure holds the register values __dpmi_int calls the interrupt. This example sets to video mode 0x13 by calling the video I/O interrupt 0x10.


__dpmi_regs r;
r.x.ax = 0x13;
__dpmi_int(0x10,&r);
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SEO in Simple Words: How a VU Student Can Write a Clearer Assignment or Blog Post admin 0 42 11-01-2026, 05:11 AM
Last Post: admin
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,284 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,138 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,660 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,336 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,923 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,153 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,960 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,588 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,611 05-15-2015, 03:52 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support