Application commands
-
- Member
- Posts: 83
- Joined: Fri Oct 22, 2004 11:00 pm
Application commands
From experience what do you think is the best way for a application to run commands from the operating system? Interrupts or calls? Push parameters into stack, or just use registers? etc..
Re: Application commands
I think the best way is to use interrupts ...
In my OS i use interrupts for applications and it works fine ...
In my OS i use interrupts for applications and it works fine ...
- intel_breaker
- Member
- Posts: 46
- Joined: Tue Jan 04, 2005 12:00 am
- Location: Poland
- Contact:
Re: Application commands
Also I always pushing every argument on the stack. It works well in my O.S
Re: Application commands
I got a syscall interrupt and pass parameters using registers. Well, that means of course that I don't have too many parameters per function.
*post*
-
- Member
- Posts: 83
- Joined: Fri Oct 22, 2004 11:00 pm
Re: Application commands
The problems having to do with registers are:
1. You are limited on the registers to use.
2. You are limited on the size of the information, if it is a number.
You can of course send the information through the registers as a string, but that would mean you need the OS to find parts of your application. This seems to be more work, especially in protected mode.
The problems having to do with pushing parameters into stack:
1. You are faced with a problem to come up with an algorithem, or something that enables you to read the information from the stack, even though the stack already contains the placement of the code before the command was called. I don't know about C, but in ASM, this seems to require quite some thinking..
As for INTs and Calls, well, there doesn't seem much of a difference. You -would- be saving a bit more memory space by just calling something like "Int 25" then "Call 234h:3214h" though.
1. You are limited on the registers to use.
2. You are limited on the size of the information, if it is a number.
You can of course send the information through the registers as a string, but that would mean you need the OS to find parts of your application. This seems to be more work, especially in protected mode.
The problems having to do with pushing parameters into stack:
1. You are faced with a problem to come up with an algorithem, or something that enables you to read the information from the stack, even though the stack already contains the placement of the code before the command was called. I don't know about C, but in ASM, this seems to require quite some thinking..
As for INTs and Calls, well, there doesn't seem much of a difference. You -would- be saving a bit more memory space by just calling something like "Int 25" then "Call 234h:3214h" though.
Re: Application commands
Well, you can probably pass a pointer to the string.
Just check it before using it.
Just check it before using it.
*post*
Re: Application commands
I use Ints. with Regs..
For more parameters I hand over a pointer.
For more parameters I hand over a pointer.
dw 0xAA55
-
- Member
- Posts: 134
- Joined: Thu Aug 18, 2005 11:00 pm
- Location: Sol. Earth. Europe. Romania. Bucuresti
- Contact:
Re: Application commands
I would only use "parameters on the stack" ...
IMHO it is faster an better (versatile).
The "INT's with Registers" is the more easy way to do it and can be helpfull at start.
IMHO it is faster an better (versatile).
The "INT's with Registers" is the more easy way to do it and can be helpfull at start.
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: Application commands
registers (ie, on-chip cache) are actually faster then the stack (standard memory).
But yes, the stack affords some ammount of versitility in that you can push as much as you want on it... you aren't limited by the number of registers.
Not to mention, each platform will have different number of general purpose registers, but every platform will have a stack. If you plan on porting to another OS, the stack might be easier.
--Jeff
But yes, the stack affords some ammount of versitility in that you can push as much as you want on it... you aren't limited by the number of registers.
Not to mention, each platform will have different number of general purpose registers, but every platform will have a stack. If you plan on porting to another OS, the stack might be easier.
--Jeff
-
- Member
- Posts: 134
- Joined: Thu Aug 18, 2005 11:00 pm
- Location: Sol. Earth. Europe. Romania. Bucuresti
- Contact:
Re: Application commands
I have just lost a very long and detailed answer to this
Nice forum timeout
Ok, now let me rewrite all -- this time with less information:
Yes, registers are faster only for inner loops and inside funtions but in this case: "API call parameters transfer" the stack is the best performer.
The stack is always in cache and besides any decent API will need registers to perform its work.
This will require that you save the registers --ironically-- on the stack and restore them later on...
It is not uncommon for an API to need it argument multiple times during code and some at startup and other at the end of code... this generatea a nightmare of save/restores inside API and ugly code at least.
The overal better speed of FreeBSD is also because it uses stack based parameter passing for its API.
The Only real advantage of the INT xx is that you do not need callgates and you can get by with a single API INT gate that is easyer to setup and test at the start of OS development...
The sad fact that DOS and Linux and Menuet use it is... well just sad
Consider those 2 examples:
I would never consider using it because:
-it is non-professional, non-elegant and ugly
-it is overall slower
-it is limited to the ammount of registers, one extra parmeter and you are out of luck
-it hinders code folding and code completion in IDE
-it hinders type checking by the assembler
compared with:
I rest my case
Nice forum timeout
Ok, now let me rewrite all -- this time with less information:
Yes, registers are faster only for inner loops and inside funtions but in this case: "API call parameters transfer" the stack is the best performer.
The stack is always in cache and besides any decent API will need registers to perform its work.
This will require that you save the registers --ironically-- on the stack and restore them later on...
It is not uncommon for an API to need it argument multiple times during code and some at startup and other at the end of code... this generatea a nightmare of save/restores inside API and ugly code at least.
The overal better speed of FreeBSD is also because it uses stack based parameter passing for its API.
The Only real advantage of the INT xx is that you do not need callgates and you can get by with a single API INT gate that is easyer to setup and test at the start of OS development...
The sad fact that DOS and Linux and Menuet use it is... well just sad
Consider those 2 examples:
Code: Select all
mov eax,[window_parent]
mov ebx,[window_x]
mov ecx,[window_y]
mov edx,[window_dx]
mov esi,[window_dy]
mov edi,WND_FLAG_ALPHA
mov ebp API_WIndow_Create
int 0x80
-it is non-professional, non-elegant and ugly
-it is overall slower
-it is limited to the ammount of registers, one extra parmeter and you are out of luck
-it hinders code folding and code completion in IDE
-it hinders type checking by the assembler
compared with:
Code: Select all
Call API_Window_Create, STDCALL [window_x],[window_y],[window_dx],[window_dy],FLAG_WND_APLHA
Last edited by bontanu on Sat Aug 20, 2005 11:00 pm, edited 3 times in total.
Re: Application commands
First: Ctrl-A, Ctrl-V before that happens again
Second, on topic. My OS is completely based on message ppassing, so it's very simple. Just send a message to the kernel with what you want to do, and it will put you into the scheduler.
Second, on topic. My OS is completely based on message ppassing, so it's very simple. Just send a message to the kernel with what you want to do, and it will put you into the scheduler.
The following statement is false.
The previous statement is true.
The previous statement is true.
Re: Application commands
Hmm, if you ever get into a situtaion where you need more registers you can do:
I speak in favor of INT's and regs becasue that's what I use..
Code: Select all
; data area
window_data:
window_parent dd 0
window_x dd 0
window_y dd 0
window_dx dd 0
window_dy dd 0
;... some stuff
mov esi, window_data
mov edi, WND_FLAG_ALPHA
mov ebp, API_WIndow_Create
int 0x80
Last edited by bubach on Sun Aug 21, 2005 11:00 pm, edited 1 time in total.
-
- Member
- Posts: 134
- Joined: Thu Aug 18, 2005 11:00 pm
- Location: Sol. Earth. Europe. Romania. Bucuresti
- Contact:
Re: Application commands
Of course we do know that one can send a pointer to a structure... but in that case you are sending a pointer towards a global variable(s) area
The very same thing that is done by the stack but with a little help form the CPU and non-global.
-and it will get you into additional trouble with recursive functions or re-entrant API
Sending parameters by registers does have it's well established place in speed optimizations but is not a very good scheme for a general API parameter passing hence the "confusion"
The very same thing that is done by the stack but with a little help form the CPU and non-global.
-and it will get you into additional trouble with recursive functions or re-entrant API
Sending parameters by registers does have it's well established place in speed optimizations but is not a very good scheme for a general API parameter passing hence the "confusion"
Last edited by bontanu on Sun Aug 21, 2005 11:00 pm, edited 2 times in total.
-
- Member
- Posts: 31
- Joined: Sun Jun 26, 2005 11:00 pm
- Location: Toronto, Ontario, Canada
- Contact:
Re: Application commands
Ya, I am just about to start writing some of my OS's API, and I seam to be finding that interrupts are the way to go with registers, kind of like how the rest of my OS works. But ya, I would never consider EVER having people do interrupt calls in their code, I think a C wrapper is so much nicer for that sort of thing so you don't double hit your stack with your native assembler call and the C wrapper.
It will come from the ashes of the old era.
-- James Vaughan
-- James Vaughan
-
- Member
- Posts: 25
- Joined: Sat Jun 25, 2005 11:00 pm
Re: Application commands
have anybody tried to use call gates? I think it is the best way to invoke OS services ..
although I don't use it, but I will do some day, when I have nothing else to do
although I don't use it, but I will do some day, when I have nothing else to do