flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > easy and fast call mechanism for kernel routines |
Author |
|
revolution 01 Oct 2008, 12:04
You mention minimal overhead but you don't mention how you judge that. Do you mean minimal memory usage? Minimal stack usage? Minimal register usage? Minimal clock tick? Minimal code size? Minimal BTB pollution? Minimal return stack pollution? Minimal cache pollution? You can't get all of those at the same time, many are mutually exclusive of the others.
It is really up to you what you want to do with calling conventions. I doubt there is any "best" or "optimal" convention. They all have their own different strengths and weaknesses. The Windows 64bit OSes uses a variation of the Fastcall convention. Perhaps just for ease of porting code you can consider using that. |
|||
01 Oct 2008, 12:04 |
|
bitRAKE 01 Oct 2008, 15:47
Look at sysenter instruction if going from ring3 to ring0. Otherwise just use call within the same ring. A fast and flexible convention is all parameters in registers - in the rare event more parameters are passed than registers - just pass a structure pointer. Organize register usage to ease management between kernel calls on the application end, and speed usage on the kernel side.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
01 Oct 2008, 15:47 |
|
Mat 01 Oct 2008, 15:51
I'm searching for a method which don't utilisize the stack (because the kernel should build the base for a stack based vm), isn't dependant on register allocations (most of the 16 registers are reserved for other things like vm register caching) and don't consume to much clock ticks per call.
uh, sounds easy ;D |
|||
01 Oct 2008, 15:51 |
|
bitRAKE 01 Oct 2008, 16:18
Code: call [KERNEL_001] dq param0 dq param1 return_here: ... KERNEL_001: mov rax,[rsp] ; access parameters add qword [rsp],16 ... retn _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
01 Oct 2008, 16:18 |
|
revolution 01 Oct 2008, 16:48
Mat: do you have any other requirements like lowest level of CPU used? Because SYSENTER is only available on newer CPUs so if that is a problem you might need to look at other methods also.
|
|||
01 Oct 2008, 16:48 |
|
vid 01 Oct 2008, 18:05
stack is usually fastest-to-access memory, much unlike code area which is usually slowest.
|
|||
01 Oct 2008, 18:05 |
|
Mat 02 Oct 2008, 21:10
bitRAKE wrote:
Sadly, the AMD64 ISA lack support for sysenter and sysexit in both long modes (compatible and native). _________________ make it yourself or you screwed ! |
|||
02 Oct 2008, 21:10 |
|
LocoDelAssembly 02 Oct 2008, 21:32
But it does support SYSCALL
Quote: Long Mode. When long mode is activated, the behavior of the SYSCALL instruction |
|||
02 Oct 2008, 21:32 |
|
Mat 02 Oct 2008, 21:43
revolution: Yes, that's a little problem and after reading this: [link] http://en.wikipedia.org/wiki/X86-64#Differences_between_AMD64_and_Intel_64 [/link] it seems not the only one....
I have choose the following compromise: - Parameters are passed following the call - the r15 register is reserved for return adresses Code:
mov r15,$
jmp KERNEL_HANDLER
dq FUNCTION_ID
dq PARAMETER_A
dq PARAMETER_B
...
Not the fastest but a simple, generic approach and it doesnt change the stack and sacrifies only one register. thanks to all for the answers. _________________ make it yourself or you screwed ! |
|||
02 Oct 2008, 21:43 |
|
Mat 02 Oct 2008, 22:22
LocoDelAssembly wrote: But it does support SYSCALL ok, but what's with Intel EMT64 cpus (using another, system specific register) ? I don't want to handle two SYSCALL behaviors just to implement function calls. _________________ make it yourself or you screwed ! |
|||
02 Oct 2008, 22:22 |
|
LocoDelAssembly 02 Oct 2008, 22:42
Intel Manuals wrote: SYSCALL—Fast System Call However seems that Intel CPUs don't support SYSCALL/SYSRET on legacy mode nor 32-bit long mode, while AMD support it on both modes. On the other hand, AMD supports SYSENTER/SYSEXIT on 32-bit mode only. Anyway, unless I missed something both architectures have the same behavior when them are running in 64-bit long mode. |
|||
02 Oct 2008, 22:42 |
|
Mat 03 Oct 2008, 09:15
after reading both specifications:
the behavior on Intel and AMD architectures is the same Thanks to remind me of this instruction ! I think the dependance on two registers (RCX and R11) is not so crucial (but I use now all registers in one or the other way). |
|||
03 Oct 2008, 09:15 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.