1
/* Callout/callback interface for Etherboot
3
* This file provides the mechanisms for making calls from Etherboot
4
* to external programs and vice-versa.
6
* Initial version by Michael Brown <mbrown@fensystems.co.uk>, January 2004.
10
#include "callbacks.h"
15
/* Maximum amount of stack data that prefix may request to be passed
18
#define MAX_PREFIX_STACK_DATA 16
20
/* Prefix exit routine is defined in prefix object */
21
extern void prefix_exit ( void );
22
extern void prefix_exit_end ( void );
24
/*****************************************************************************
28
*****************************************************************************
31
/* in_call(): entry point for calls in to Etherboot from external code.
33
* Parameters: some set up by assembly code _in_call(), others as
34
* passed from external code.
36
uint32_t i386_in_call ( va_list ap, i386_pm_in_call_data_t pm_data,
39
i386_rm_in_call_data_t rm_data;
40
in_call_data_t in_call_data = { &pm_data, NULL };
42
int data[MAX_PREFIX_STACK_DATA/4];
45
/* Fill out rm_data if we were called from real mode */
46
if ( opcode & EB_CALL_FROM_REAL_MODE ) {
47
in_call_data.rm = &rm_data;
48
rm_data = va_arg ( ap, typeof(rm_data) );
49
/* Null return address indicates to use the special
50
* prefix exit mechanism, and that there are
51
* parameters on the stack that the prefix wants
52
* handed to its exit routine.
54
if ( rm_data.ret_addr.offset == 0 ) {
55
int n = va_arg ( ap, int ) / 4;
57
for ( i = 0; i < n; i++ ) {
58
in_stack.data[i] = va_arg ( ap, int );
63
/* Hand off to main in_call() routine */
64
ret = in_call ( &in_call_data, opcode, ap );
66
/* If real-mode return address is null, it means that we
67
* should exit via the prefix's exit path, which is part of
68
* our image. (This arrangement is necessary since the prefix
69
* code itself may have been vapourised by the time we want to
72
if ( ( opcode & EB_CALL_FROM_REAL_MODE ) &&
73
( rm_data.ret_addr.offset == 0 ) ) {
74
real_call ( prefix_exit, &in_stack, NULL );
75
/* Should never return */
83
/* install_rm_callback_interface(): install real-mode callback
84
* interface at specified address.
86
* Real-mode code may then call to this address (or lcall to this
87
* address plus RM_IN_CALL_FAR) in order to make an in_call() to
90
* Returns the size of the installed code, or 0 if the code could not
93
int install_rm_callback_interface ( void *address, size_t available ) {
95
( available < rm_callback_interface_size ) ) return 0;
97
/* Inform RM code where to find Etherboot */
98
rm_etherboot_location = virt_to_phys(_text);
100
/* Install callback interface */
101
memcpy ( address, &rm_callback_interface,
102
rm_callback_interface_size );
104
return rm_callback_interface_size;