64-bit calls

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.
Post Reply
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

64-bit calls

Post 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
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
WeirdCat
Posts: 11
Joined: Thu Feb 05, 2009 5:13 am
Location: Berlin, Germany

Re: 64-bit calls

Post 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
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: 64-bit calls

Post 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
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
WeirdCat
Posts: 11
Joined: Thu Feb 05, 2009 5:13 am
Location: Berlin, Germany

Re: 64-bit calls

Post 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.
Post Reply