LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2007, 11:13 AM   #1
john_crichton
LQ Newbie
 
Registered: Mar 2007
Distribution: slackware
Posts: 9

Rep: Reputation: 0
How to patch 0x1c interrupt handler in protected mode


As a part of a larger project I need to patch the timer interrupt so it switches to my handler. The main language is c but some parts are done in assembly. The architecture is x86 32-bit. The solution should be as portable between opereating systems as possible. I am trying to do it in assembly (nasm).
I tried to do it with _sidt_ and then trying to point the 0x1c vector to my routine but it doesn't work. Here is the code:
Code:
CPU 386

segment .bss
idt:		resb 6

segment .text
; variables
extern		idtp, idtl, old_segment, old_offset
; functions
extern		setIVT, checkIDT, intRoutine
global		setIVTasm
setIVTasm:
			cli	
			push eax
	
			;call setIVT
			
			xor eax, eax 
			sidt [idt]
			
			;store IDTP to idtp
			mov eax, [idt + 2]
			mov [idtp], eax
			;store IDT Limit to idtl
			mov eax, [idt]
			mov [idtl], eax			
			
			; save old int handler
			xor eax, eax
			; save old segment
			mov ax, [idtp + 2]
			mov [old_segment], ax
			; save old offset low word
			mov ax, [idtp]
			mov [old_offset], ax
			; save old offset high word
			mov ax, [idtp + 6]
			mov [old_offset + 2], ax
			

			call checkIDT
			
			; set new int handler
			xor eax, eax
			; set new segment
			mov ax, cs
			mov [idtp + 2], ax
			; set new offset low word
			mov ax, [intRoutineAsm]
			mov [idtp], ax
			; set new offset high word
			mov ax, [intRoutineAsm + 2]
			mov [idtp + 6], ax 
			
			pop eax
			sti
			ret
Does anyone have an idea how this might work?
 
Old 04-04-2007, 07:53 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
In any modern operating-system .. Linux, Windows, OS/X, whatever .. you don't have direct access to interrupts, vectors and so-forth.

You do have various kinds of asynchronous notifications, timers, and so-forth. In the Unix-variant systems, these are called signals, and the specific signal you're interested in here is named SIGALARM.

(By the way, this is the same mechanism Unix/Linux uses to handle other things, like program errors or your decision to kill a program. All of these result in a signal being issued.)

Forget about the hardware: you can't control it; can't touch it. You're not allowed, and with very good reason! But you can ask the operating-system to send a signal to your process, say, approximately so-many times a second. Then you define a handler routine to service the signal. When the signal arrives, your program will be diverted to the handler routine, asynchronously.

All of this signal-handling occurs comfortably within the context of your own process.

You do not get "precision intervals." You do not get guaranteed latency.

Standard libraries in various languages all provide for some analog of this facility and it can be expected to be portable across any operating-system without source-code changes.

Last edited by sundialsvcs; 04-04-2007 at 07:54 PM.
 
Old 04-05-2007, 04:59 AM   #3
john_crichton
LQ Newbie
 
Registered: Mar 2007
Distribution: slackware
Posts: 9

Original Poster
Rep: Reputation: 0
Thank you. This answers a lot of my questions. Thank you again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
control is not going to interrupt handler when interrupt comes in serial driver sateeshalla Linux - Kernel 1 05-04-2006 09:43 AM
Linux Interrupt Handler lucky6969b Linux - Software 1 12-01-2005 11:55 AM
printk in the interrupt handler lordofring Programming 3 08-23-2005 08:00 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
Why this interrupt handler does not work? opereira Programming 1 03-04-2004 01:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration