OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Add an INT with C...
PostPosted: Thu Feb 20, 2003 12:00 am 
Hello:

I am trying to add the INT 20H to the Interrupt Table for an real mode OS, I did it with ASM yet, but now I like do it with C:

extern void putch(char);
ISR20H(void);

main() {

putch('M');
putch('I');
putch('S');
putch('I');
putch('S');
putch(' ');
putch('1');
putch('.');
putch('0');
putch('.');
putch(13);
putch(10);

asm xor ax, ax;
asm mov ss, ax;
asm mov ax, cs;

asm cli;
asm mov bx, offset ISR20H;
asm mov word [ss:80h], bx;
asm mov word [ss:82h], ax;
asm sti;

asm int 20h;

while(1) {}}

ISR20H(void) {

putch('I');
putch('N');
putch('T');
putch(' ');
putch('2');
putch('0');
putch('H');
putch(13);
putch(10); }

I compile the file that have the putch() rutine with:
tasm -mx k_lib.asm

And then I compile the kernel with:
tcc -mt -B kernel.c k_lib.obj

Finally, I use exe2bin to create a .COM file that I load with my boot program (I've tasted it with other files and it is working nice).

I can't display the text "INT 20H".

Some one know where my error is?

Thank you


Top
  
 
 Post subject: RE:Add an INT with C...
PostPosted: Thu Feb 20, 2003 12:00 am 
I'm suprised that you're not asking us to explain why that code causes the computer to reboot.

First off, you're smashing up the SS register while interrupts are enabled, and you aren't restoring it afterwards.

Secondly, your ISR20h() function doesn't appear to be defined as an interrupt handler.

Third, if your compiler supports FAR pointers, you shouldn't need to use inline ASM to set the interrupt vector.

These three points aside, however, the only things I can come up with is that the linker or exe2bin is messing up the offset relocation for the interrupt handler or that the boot loader is starting the program with a denormalized entry point (if memory serves, the .COM file format needs to start executing at the start of the file with a PC value of 0x100, if that gets messed up CS-relative offset fixups aren't going to work, but PC-relative calls and branches will still work).

Hope this helps.


Top
  
 
 Post subject: RE:Add an INT with C...
PostPosted: Thu Feb 20, 2003 12:00 am 
Thank you very much your soon response...


Top
  
 
 Post subject: RE:Add an INT with C...
PostPosted: Fri Feb 21, 2003 12:00 am 
hello:

I corrected the second point defining an interrupt handler function using the interrupt keyword.

void interrupt INT20H(...);

Now I like to use FAR pointers as you say, but I canĀ“t do it work.
(Sorry, I am new with OS, ASM and C. But I program very well with high level languages).

Look my code:

void ChangeINT20H() {

/* The struct vector is to hold segment and offset of the interrupt vector */
struct vector { unsigned int seg;
unsigned int off; };

/* I defined a pointer to update the interupt vector table at 0000:0080 */

vector far * pTVI;

/* I assign that pointer the address of INT 20H (0000:0080) using the macro MK_FP, exist other way to create a far pointer? */

pTVI = MK_FP(0, 4*(0x20));

/* I write at this address (0000:0080) the address of the interrupt handler function */

*pTVI = Int20H;

/* That's all */

}

What's wrong?

Thank you...


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Garnek0, Google [Bot], Yahoo [Bot] and 54 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group