Application commands

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.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Application commands

Post by ComputerPsi »

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..
stafe
Posts: 22
Joined: Fri Oct 29, 2004 11:00 pm

Re: Application commands

Post by stafe »

I think the best way is to use interrupts ...

In my OS i use interrupts for applications and it works fine ...
User avatar
intel_breaker
Member
Member
Posts: 46
Joined: Tue Jan 04, 2005 12:00 am
Location: Poland
Contact:

Re: Application commands

Post by intel_breaker »

Also I always pushing every argument on the stack. It works well in my O.S
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Application commands

Post by Legend »

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*
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Application commands

Post by ComputerPsi »

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.
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Application commands

Post by Legend »

Well, you can probably pass a pointer to the string.
Just check it before using it.
*post*
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Re: Application commands

Post by Osbios »

I use Ints. with Regs..
For more parameters I hand over a pointer.
dw 0xAA55
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Re: Application commands

Post by bontanu »

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.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Application commands

Post by carbonBased »

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
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Re: Application commands

Post by bontanu »

I have just lost a very long and detailed answer to this ;)
Nice forum timeout :P

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
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:

Code: Select all

Call API_Window_Create, STDCALL [window_x],[window_y],[window_dx],[window_dy],FLAG_WND_APLHA
I rest my case ;)
Last edited by bontanu on Sat Aug 20, 2005 11:00 pm, edited 3 times in total.
eosp
Posts: 4
Joined: Wed Dec 08, 2004 12:00 am
Location: Sitting at my Desk
Contact:

Re: Application commands

Post by eosp »

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.
The following statement is false.
The previous statement is true.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Application commands

Post by bubach »

Hmm, if you ever get into a situtaion where you need more registers you can do:

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
I speak in favor of INT's and regs becasue that's what I use.. ;)
Last edited by bubach on Sun Aug 21, 2005 11:00 pm, edited 1 time in total.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Re: Application commands

Post by bontanu »

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 :D

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.
Phibred
Member
Member
Posts: 31
Joined: Sun Jun 26, 2005 11:00 pm
Location: Toronto, Ontario, Canada
Contact:

Re: Application commands

Post by Phibred »

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
AltCtrlDel
Member
Member
Posts: 25
Joined: Sat Jun 25, 2005 11:00 pm

Re: Application commands

Post by AltCtrlDel »

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 :)
Post Reply