Well I have started to try to implement a few interrupt things for kernel interfacing but well have run into a design block
what exactly is the best way to pass parameters to an int
the things I can think of are-
1. use registers
2. use the stack(c calling convention)
3. use a messaging system to send parameters before the interrupt
4. use a register that just contains a block of memory for parameters
5. use a fixed virtual address for parameters and jsut put data in it
the most useful way I can see is using #5 because it would be easy to use because no pusha'ing; not all too bad at speed; easy to implement at both interrupt and libc point of views, just using structs
but does anyone have anything that would be better, or see a flaw with my idea?
Is this the best way for interrupt parameters
Re:Is this the best way for interrupt parameters
I'd also strive for approach number 5, but maybe combining it with number 4. Thus, in a register you have the address where the struct with the parameters is located. Everything's more dynamic then, both on kernel and on user level and it cost's you nothing (very few lines of additional code).
Another aspect of your problem is the return values. How are you going to handle return values?
Candamir
Another aspect of your problem is the return values. How are you going to handle return values?
Candamir
Re:Is this the best way for interrupt parameters
that'd be simple just set block of memory
I think I'm gonna use #5 purely because no registers are required, and it would be like 0x2000 and then maybe use paging to remap it or even just have the whole bottom virtual meg switched out for each thread for multi threaded apps to avoid pesky race conditions
just using no registers seams super good to me as in things like C you never know which registers are safe to use all the time
meh don't even know why I made this thread my mind was pretty well decided when I posted
I think I'm gonna use #5 purely because no registers are required, and it would be like 0x2000 and then maybe use paging to remap it or even just have the whole bottom virtual meg switched out for each thread for multi threaded apps to avoid pesky race conditions
just using no registers seams super good to me as in things like C you never know which registers are safe to use all the time
meh don't even know why I made this thread my mind was pretty well decided when I posted
Re:Is this the best way for interrupt parameters
The problem would be threads colliding to use the same virtual address, which to implement this in a multi-threaded enviroment you probably need to spinlock for access. Generally this isn't very practical to do in my opinion, unless each thread has its own address space (which is acting more or less a process then a thread) you could map a different page in that specific address. But #1, #2 and #4 (if you mean passing a pointer through a register, more or less like a __fastcall) would be my choices. I still like my stacks and is generally overruled to any methods mentioned here, because push/pop are only byte long instructions, also UV pairable, for my kernel it must fit in a 64KB ROM so its a factor on my end.Jordan3 wrote:the most useful way I can see is using #5 because it would be easy to use because no pusha'ing; not all too bad at speed; easy to implement at both interrupt and libc point of views, just using structs
Re:Is this the best way for interrupt parameters
hmmm well every thread kindof does have its address space its kindof like it overlaps, every thread has its own little lower part of memory for use in interrupts well take this code...
yea I know their could be problems if they use that area of memory for something besides interrupts but hey every OS has those special areas of memory your not suppose to touch
Code: Select all
void thread1(){
unsigned int *ptr=0x2000;
//this thread is runnign
*ptr=5;
/*oh no a task switch happens right before the call interrupt
but in a threadswitch what I will do is swap 0x2000-0x3000 to its own little memory in the thread struct, and then thread2's area of memory is swapped into memory...*/
CallInterrupt(0x51);
}
void thread2(){
unsigned int *ptr=0x2000;
}
Re:Is this the best way for interrupt parameters
You could also push magical values before and after your parameters on the stack:
Candamir
Code: Select all
push 0xDEADBEEF
push 0xCAFEBABE
push all your arguments, doesn't matter how many
push 0xCAFEBABE
push 0xDEADBEEF
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re:Is this the best way for interrupt parameters
My personal preference is #1, resorting to #4 when running out of registers.
as said, The biggest problem for #5 is that once you run multiple threads in the same address space you'll get issues with conflicting writes to kernel communication space, which are probably more annoying than for instance saying that e.g. ESI contains the parameters, and the results are to be written to a block pointed to by EDI.
And since you probably have to ASM the callinterrupt() function anyway you can push those in as well
the magic push implementation looks fundamentally flawed btw
as said, The biggest problem for #5 is that once you run multiple threads in the same address space you'll get issues with conflicting writes to kernel communication space, which are probably more annoying than for instance saying that e.g. ESI contains the parameters, and the results are to be written to a block pointed to by EDI.
And since you probably have to ASM the callinterrupt() function anyway you can push those in as well
Code: Select all
push ESI
push EDI
mov ESI, ...
mov EDI, ...
int 0x51
pop EDI
pop ESI
what if you e.g. want to write the same combination to the disk driver (writing an executable for instance).....You could also push magical values before and after your parameters on the stack: