Setting up IVT from C address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Setting up IVT from C address

Post by lopidas »

I am trying to create function from this tutorial http://wiki.osdev.org/Real_mode_assembly_IV

Code: Select all

void set_interrupt(char c,void* a){
asm("push %es ;save es");
asm("xor %es,%es ;null out es");

asm("mov %al,%0 ;set al to int number"::"g"(c):);
asm("mov %bl,0x4 ;prepare mul by 0x4");
asm("mul %bl ;multiply al by 0x4");
asm("mov %bx,%ax ;mov result to bx");
asm("mov es:(bx),%0"::"m"(a):); 
asm("add %bx,$2");
asm("mov es:(bx), segment");

asm("pop %es ;restore es ");
}
How should I get segment from a to pass it on this line

Code: Select all

asm("mov es:(bx), segment");
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Setting up IVT from C address

Post by bluemoon »

1. learn function pointer (instead of passing void* a)
2. interrupt vector should have range 0<= vector < 256, which requires at least unsigned char to hold full range
3. C function may use ABI that trash some registers, and not suitable for direct interrupt handler (unless special compiler specific attributes).

For C programming with real mode x86, how to retrieve the segment of a pointer depends on the memory model,
for example with far pointer, the segment is the first two bytes of the pointer.
Post Reply