Page 1 of 1

Setting up IVT from C address

Posted: Thu Sep 26, 2013 10:52 am
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");

Re: Setting up IVT from C address

Posted: Thu Sep 26, 2013 11:16 am
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.