OSDev.org
https://forum.osdev.org/

Add an INT with C...
https://forum.osdev.org/viewtopic.php?f=1&t=1592
Page 1 of 1

Author:  Pepito [ Thu Feb 20, 2003 12:00 am ]
Post subject:  Add an INT with C...

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

Author:  jamethiel [ Thu Feb 20, 2003 12:00 am ]
Post subject:  RE:Add an INT with C...

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.

Author:  Pepito [ Thu Feb 20, 2003 12:00 am ]
Post subject:  RE:Add an INT with C...

Thank you very much your soon response...

Author:  Pepito [ Fri Feb 21, 2003 12:00 am ]
Post subject:  RE:Add an INT with C...

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...

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/