Code: Select all
char isr_wrapper[] = {
/* pusha, push gs, fs, es, ds */
0x60, 0x0F, 0xA8, 0x0F, 0xA0, 0x06, 0x1E,
/* push parameter 2 onto stack [8]-[11] */
0x68, 0x00, 0x00, 0x00, 0x00,
/* push parameter 1 onto stack [13]-[16] */
0x68, 0x00, 0x00, 0x00, 0x00,
/* call function [18]-[21] */
0x9A, 0x00, 0x00, 0x00, 0x00,
/* pop ds, es, fs, gs, popa, iret */
0x1F, 0x07, 0x0F, 0xA1, 0x0F, 0x09, 0x61, 0xCF
};
char *test_isr = NULL;
typedef void (*isr_caller)();
isr_caller my_isr;
Code: Select all
char *str = "%s\n";
char *str_param = "An interrupt from dynamically generated code";
void init_isr() {
test_isr = (char *)malloc(30);
memcpy(test_isr, isr_wrapper, 30);
unsigned long param2 = (unsigned long)str_param;
unsigned long param1 = (unsigned long)str;
unsigned long address = (unsigned long)&printf;
test_isr[ 8] = (param2 >> 0) & 0xFF;
test_isr[ 9] = (param2 >> 8) & 0xFF;
test_isr[10] = (param2 >> 16) & 0xFF;
test_isr[11] = (param2 >> 24) & 0xFF;
test_isr[13] = (param1 >> 0) & 0xFF;
test_isr[14] = (param1 >> 8) & 0xFF;
test_isr[15] = (param1 >> 16) & 0xFF;
test_isr[16] = (param1 >> 24) & 0xFF;
test_isr[18] = (address >> 0) & 0xFF;
test_isr[19] = (address >> 8) & 0xFF;
test_isr[20] = (address >> 16) & 0xFF;
test_isr[21] = (address >> 24) & 0xFF;
my_isr = (isr_caller)test_isr;
}
Code: Select all
void test_isr() {
my_isr();
}