Page 1 of 1

64-bit calls

Posted: Sat Nov 27, 2010 9:51 am
by IanSeyler
We are experimenting with running an application in the higher half while running the kernel in the lower half.

The begining of the kernel looks like this:

Code: Select all

USE64
ORG 0x0000000000100000

%DEFINE BAREMETALOS_VER 'v0.5.0-dev (September 17, 2010)', 13, 'Copyright (C) 2010, Return Infinity', 13, 0
%DEFINE BAREMETALOS_API_VER 1

kernel_start:
	jmp start		; Skip over the function call index

	align 16		; 0x0010
	jmp os_print_string
	align 8			; 0x0018
	jmp os_print_char
	align 8			; 0x0020
	jmp os_print_char_hex
An application just needs to do a 'call 0x00100010' in order to do a print string. This works fine if you are in the first 4GiB of memory. The issue is that the call is relative so calling from the higher half this happens: 'call 0xFFFF800000100010' which doesn't work.

Why isn't there a 'call rel64' function?

Any ideas on how to call kernel functions from the higher half? 'syscall' or 'sysenter'? Everything runs in ring zero.

Thanks,
-Ian

Re: 64-bit calls

Posted: Sat Nov 27, 2010 1:25 pm
by WeirdCat
ReturnInfinity wrote:Any ideas on how to call kernel functions from the higher half? 'syscall' or 'sysenter'? Everything runs in ring zero.
If you don't need to change privilege level just load the address of the function into a 64 bit register and call it:

Code: Select all

mov  rax, printString
call  rax

Re: 64-bit calls

Posted: Sat Nov 27, 2010 1:50 pm
by IanSeyler
Seems like this is the best bet. I wanted to avoid using a register since I use the registers to pass data to the functions. For example os_print_char prints the character in AL.

I guess I can use a different register for the call though. Perhaps R15 or RBP? Is RBP used in a C binary?

Thanks,
-Ian

Re: 64-bit calls

Posted: Sat Nov 27, 2010 2:03 pm
by WeirdCat
ReturnInfinity wrote:Is RBP used in a C binary?
I think this depends on the compiler. To be specific, this depends on the application binary interface (ABI) (http://en.wikipedia.org/wiki/Applicatio ... _interface) used by the compiler.