Browse Source

[librm] Provide an abstraction wrapper for prot_call

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
31b5c2e753

+ 1
- 1
src/arch/i386/include/bits/compiler.h View File

9
 #ifndef ASSEMBLY
9
 #ifndef ASSEMBLY
10
 
10
 
11
 /** Declare a function with standard calling conventions */
11
 /** Declare a function with standard calling conventions */
12
-#define __asmcall __attribute__ (( cdecl, regparm(0) ))
12
+#define __asmcall __attribute__ (( used, cdecl, regparm(0) ))
13
 
13
 
14
 /**
14
 /**
15
  * Declare a function with libgcc implicit linkage
15
  * Declare a function with libgcc implicit linkage

+ 6
- 12
src/arch/i386/interface/syslinux/comboot_call.c View File

660
 
660
 
661
 	__asm__ __volatile__ (
661
 	__asm__ __volatile__ (
662
 		TEXT16_CODE ( "\nint20_wrapper:\n\t"
662
 		TEXT16_CODE ( "\nint20_wrapper:\n\t"
663
-		              "pushl %0\n\t"
664
-		              "call prot_call\n\t"
663
+			      VIRT_CALL ( int20 )
665
 			      "clc\n\t"
664
 			      "clc\n\t"
666
 			      "call patch_cf\n\t"
665
 			      "call patch_cf\n\t"
667
-		              "iret\n\t" )
668
-		          : : "i" ( int20 ) );
666
+		              "iret\n\t" ) );
669
 
667
 
670
 	hook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, &int20_vector );
668
 	hook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, &int20_vector );
671
 
669
 
672
 	__asm__ __volatile__ (
670
 	__asm__ __volatile__ (
673
 		TEXT16_CODE ( "\nint21_wrapper:\n\t"
671
 		TEXT16_CODE ( "\nint21_wrapper:\n\t"
674
-		              "pushl %0\n\t"
675
-		              "call prot_call\n\t"
672
+			      VIRT_CALL ( int21 )
676
 			      "clc\n\t"
673
 			      "clc\n\t"
677
 			      "call patch_cf\n\t"
674
 			      "call patch_cf\n\t"
678
-		              "iret\n\t" )
679
-		          : : "i" ( int21 ) );
675
+		              "iret\n\t" ) );
680
 
676
 
681
 	hook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, &int21_vector );
677
 	hook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, &int21_vector );
682
 
678
 
683
 	__asm__  __volatile__ (
679
 	__asm__  __volatile__ (
684
 		TEXT16_CODE ( "\nint22_wrapper:\n\t"
680
 		TEXT16_CODE ( "\nint22_wrapper:\n\t"
685
-		              "pushl %0\n\t"
686
-		              "call prot_call\n\t"
681
+			      VIRT_CALL ( int22 )
687
 			      "clc\n\t"
682
 			      "clc\n\t"
688
 			      "call patch_cf\n\t"
683
 			      "call patch_cf\n\t"
689
-		              "iret\n\t" )
690
-		          : : "i" ( int22) );
684
+		              "iret\n\t" ) );
691
 
685
 
692
 	hook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, &int22_vector );
686
 	hook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, &int22_vector );
693
 }
687
 }

+ 2
- 3
src/arch/x86/core/dumpregs.c View File

6
 	__asm__ __volatile__ (
6
 	__asm__ __volatile__ (
7
 		TEXT16_CODE ( ".globl dump_regs\n\t"
7
 		TEXT16_CODE ( ".globl dump_regs\n\t"
8
 			      "\ndump_regs:\n\t"
8
 			      "\ndump_regs:\n\t"
9
-			      "pushl $_dump_regs\n\t"
10
-			      "call prot_call\n\t"
11
-			      "ret\n\t" ) : : );
9
+			      VIRT_CALL ( _dump_regs )
10
+			      "ret\n\t" ) );
12
 
11
 
13
 	printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
12
 	printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
14
 		 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
13
 		 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"

+ 22
- 1
src/arch/x86/include/librm.h View File

19
 #define LONG_DS 0x40
19
 #define LONG_DS 0x40
20
 #endif
20
 #endif
21
 
21
 
22
-#ifndef ASSEMBLY
22
+#ifdef ASSEMBLY
23
+
24
+/**
25
+ * Call C function from real-mode code
26
+ *
27
+ * @v function		C function
28
+ */
29
+.macro virtcall function
30
+	pushl	$\function
31
+	call	prot_call
32
+.endm
33
+
34
+#else /* ASSEMBLY */
23
 
35
 
24
 #ifdef UACCESS_LIBRM
36
 #ifdef UACCESS_LIBRM
25
 #define UACCESS_PREFIX_librm
37
 #define UACCESS_PREFIX_librm
27
 #define UACCESS_PREFIX_librm __librm_
39
 #define UACCESS_PREFIX_librm __librm_
28
 #endif
40
 #endif
29
 
41
 
42
+/**
43
+ * Call C function from real-mode code
44
+ *
45
+ * @v function		C function
46
+ */
47
+#define VIRT_CALL( function )						\
48
+	"pushl $( " #function " )\n\t"					\
49
+	"call prot_call\n\t"
50
+
30
 /* Variables in librm.S */
51
 /* Variables in librm.S */
31
 extern unsigned long virt_offset;
52
 extern unsigned long virt_offset;
32
 
53
 

+ 3
- 5
src/arch/x86/interface/pcbios/bios_console.c View File

531
 	__asm__ __volatile__ (
531
 	__asm__ __volatile__ (
532
 		TEXT16_CODE ( "\nint16_wrapper:\n\t"
532
 		TEXT16_CODE ( "\nint16_wrapper:\n\t"
533
 			      "pushfw\n\t"
533
 			      "pushfw\n\t"
534
-			      "cmpb $0, %%cs:bios_inject_lock\n\t"
534
+			      "cmpb $0, %cs:bios_inject_lock\n\t"
535
 			      "jnz 1f\n\t"
535
 			      "jnz 1f\n\t"
536
-			      "pushl %0\n\t"
537
-			      "call prot_call\n\t"
536
+			      VIRT_CALL ( bios_inject )
538
 			      "\n1:\n\t"
537
 			      "\n1:\n\t"
539
 			      "popfw\n\t"
538
 			      "popfw\n\t"
540
-			      "ljmp *%%cs:int16_vector\n\t" )
541
-		: : "i" ( bios_inject ) );
539
+			      "ljmp *%cs:int16_vector\n\t" ) );
542
 
540
 
543
 	/* Hook INT 16 */
541
 	/* Hook INT 16 */
544
 	hook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ),
542
 	hook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ),

+ 1
- 1
src/arch/x86/interface/pcbios/bios_reboot.c View File

46
 	put_real ( flag, BDA_SEG, BDA_REBOOT );
46
 	put_real ( flag, BDA_SEG, BDA_REBOOT );
47
 
47
 
48
 	/* Jump to system reset vector */
48
 	/* Jump to system reset vector */
49
-	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : );
49
+	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) );
50
 }
50
 }
51
 
51
 
52
 PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );
52
 PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );

+ 2
- 4
src/arch/x86/interface/pcbios/int13.c View File

1480
 			     /* Clear OF, set CF, call int13() */
1480
 			     /* Clear OF, set CF, call int13() */
1481
 			     "orb $0, %%al\n\t" 
1481
 			     "orb $0, %%al\n\t" 
1482
 			     "stc\n\t"
1482
 			     "stc\n\t"
1483
-			     "pushl %0\n\t"
1484
-			     "call prot_call\n\t"
1483
+			     VIRT_CALL ( int13 )
1485
 			     /* Chain if OF not set */
1484
 			     /* Chain if OF not set */
1486
 			     "jo 1f\n\t"
1485
 			     "jo 1f\n\t"
1487
 			     "pushfw\n\t"
1486
 			     "pushfw\n\t"
1512
 			     "\n3:\n\t"
1511
 			     "\n3:\n\t"
1513
 			     "movw %%bp, %%sp\n\t"
1512
 			     "movw %%bp, %%sp\n\t"
1514
 			     "popw %%bp\n\t"
1513
 			     "popw %%bp\n\t"
1515
-			     "iret\n\t" )
1516
-	       : : "i" ( int13 ) );
1514
+			     "iret\n\t" ) : : );
1517
 
1515
 
1518
 	hook_bios_interrupt ( 0x13, ( intptr_t ) int13_wrapper, &int13_vector );
1516
 	hook_bios_interrupt ( 0x13, ( intptr_t ) int13_wrapper, &int13_vector );
1519
 }
1517
 }

+ 3
- 2
src/arch/x86/interface/pxe/pxe_entry.S View File

24
 
24
 
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
26
 
26
 
27
+#include <librm.h>
28
+
27
 	.arch i386
29
 	.arch i386
28
 
30
 
29
 /****************************************************************************
31
 /****************************************************************************
120
 	.section ".text16", "ax", @progbits
122
 	.section ".text16", "ax", @progbits
121
 	.code16
123
 	.code16
122
 pxenv_entry:
124
 pxenv_entry:
123
-	pushl	$pxe_api_call
124
-	call	prot_call
125
+	virtcall pxe_api_call
125
 	lret
126
 	lret
126
 	.size	pxenv_entry, . - pxenv_entry
127
 	.size	pxenv_entry, . - pxenv_entry
127
 
128
 

+ 4
- 2
src/arch/x86/prefix/dskprefix.S View File

18
 
18
 
19
 FILE_LICENCE ( GPL2_ONLY )
19
 FILE_LICENCE ( GPL2_ONLY )
20
 
20
 
21
+#include <librm.h>
22
+
21
 .equ	BOOTSEG, 0x07C0			/* original address of boot-sector */
23
 .equ	BOOTSEG, 0x07C0			/* original address of boot-sector */
22
 
24
 
23
 .equ	SYSSEG, 0x1000			/* system loaded at SYSSEG<<4 */
25
 .equ	SYSSEG, 0x1000			/* system loaded at SYSSEG<<4 */
370
 	lret
372
 	lret
371
 	.section ".text16", "awx", @progbits
373
 	.section ".text16", "awx", @progbits
372
 1:
374
 1:
373
-	pushl	$main
374
-	call	prot_call
375
+	/* Run iPXE */
376
+	virtcall main
375
 
377
 
376
 	/* Uninstall iPXE */
378
 	/* Uninstall iPXE */
377
 	call	uninstall
379
 	call	uninstall

+ 3
- 2
src/arch/x86/prefix/exeprefix.S View File

24
 
24
 
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
26
 
26
 
27
+#include <librm.h>
28
+
27
 /* Initial temporary stack size */
29
 /* Initial temporary stack size */
28
 #define EXE_STACK_SIZE 0x400
30
 #define EXE_STACK_SIZE 0x400
29
 
31
 
148
 	movl	%esi, cmdline_phys
150
 	movl	%esi, cmdline_phys
149
 
151
 
150
 	/* Run iPXE */
152
 	/* Run iPXE */
151
-	pushl	$main
152
-	call	prot_call
153
+	virtcall main
153
 
154
 
154
 	/* Uninstall iPXE */
155
 	/* Uninstall iPXE */
155
 	call	uninstall
156
 	call	uninstall

+ 4
- 2
src/arch/x86/prefix/hdprefix.S View File

1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
 
2
 
3
+#include <librm.h>
4
+
3
 	.text
5
 	.text
4
 	.arch i386
6
 	.arch i386
5
 	.section ".prefix", "awx", @progbits
7
 	.section ".prefix", "awx", @progbits
99
 	lret
101
 	lret
100
 	.section ".text16", "awx", @progbits
102
 	.section ".text16", "awx", @progbits
101
 1:
103
 1:
102
-	pushl	$main
103
-	call	prot_call
104
+	/* Run iPXE */
105
+	virtcall main
104
 
106
 
105
 	/* Uninstall iPXE */
107
 	/* Uninstall iPXE */
106
 	call	uninstall
108
 	call	uninstall

+ 3
- 2
src/arch/x86/prefix/libprefix.S View File

24
 
24
 
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
26
 
26
 
27
+#include <librm.h>
28
+
27
 	.arch i386
29
 	.arch i386
28
 
30
 
29
 /* Image compression enabled */
31
 /* Image compression enabled */
887
 	 * ready for the copy to the new location.
889
 	 * ready for the copy to the new location.
888
 	 */
890
 	 */
889
 	progress "  relocate\n"
891
 	progress "  relocate\n"
890
-	pushl	$relocate
891
-	call	prot_call
892
+	virtcall relocate
892
 
893
 
893
 	/* Jump back to .prefix segment */
894
 	/* Jump back to .prefix segment */
894
 	pushw	$1f
895
 	pushw	$1f

+ 3
- 2
src/arch/x86/prefix/lkrnprefix.S View File

1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
 
2
 
3
+#include <librm.h>
4
+
3
 #define BZI_LOAD_HIGH_ADDR 0x100000
5
 #define BZI_LOAD_HIGH_ADDR 0x100000
4
 
6
 
5
 	.text
7
 	.text
197
 	movl	%ecx, initrd_len
199
 	movl	%ecx, initrd_len
198
 
200
 
199
 	/* Run iPXE */
201
 	/* Run iPXE */
200
-	pushl	$main
201
-	call	prot_call
202
+	virtcall main
202
 
203
 
203
 	/* Uninstall iPXE */
204
 	/* Uninstall iPXE */
204
 	call	uninstall
205
 	call	uninstall

+ 4
- 2
src/arch/x86/prefix/nbiprefix.S View File

1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
 
2
 
3
+#include <librm.h>
4
+
3
 	.text
5
 	.text
4
 	.arch i386
6
 	.arch i386
5
 	.code16
7
 	.code16
66
 	lret
68
 	lret
67
 	.section ".text16", "awx", @progbits
69
 	.section ".text16", "awx", @progbits
68
 1:
70
 1:
69
-	pushl	$main
70
-	call	prot_call
71
+	/* Run iPXE */
72
+	virtcall main
71
 
73
 
72
 	/* Uninstall iPXE */
74
 	/* Uninstall iPXE */
73
 	call	uninstall
75
 	call	uninstall

+ 2
- 2
src/arch/x86/prefix/pxeprefix.S View File

16
 	.org 0
16
 	.org 0
17
 	.code16
17
 	.code16
18
 
18
 
19
+#include <librm.h>
19
 #include <undi.h>
20
 #include <undi.h>
20
 
21
 
21
 #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
22
 #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
820
 	movl	%ecx, cached_dhcpack_phys
821
 	movl	%ecx, cached_dhcpack_phys
821
 
822
 
822
 	/* Run main program */
823
 	/* Run main program */
823
-	pushl	$main
824
-	call	prot_call
824
+	virtcall main
825
 
825
 
826
 	/* Uninstall iPXE */
826
 	/* Uninstall iPXE */
827
 	call	uninstall
827
 	call	uninstall

+ 3
- 3
src/arch/x86/prefix/romprefix.S View File

8
 
8
 
9
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
9
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
10
 
10
 
11
+#include <librm.h>
11
 #include <config/general.h>
12
 #include <config/general.h>
12
 #include <config/branding.h>
13
 #include <config/branding.h>
13
 
14
 
806
 #endif /* AUTOBOOT_ROM_FILTER */
807
 #endif /* AUTOBOOT_ROM_FILTER */
807
 .endif
808
 .endif
808
 
809
 
809
-	/* Call main() */
810
-	pushl	$main
811
-	call	prot_call
810
+	/* Run iPXE */
811
+	virtcall main
812
 
812
 
813
 	/* Set up flat real mode for return to BIOS */
813
 	/* Set up flat real mode for return to BIOS */
814
 	call	flatten_real_mode
814
 	call	flatten_real_mode

+ 3
- 2
src/arch/x86/prefix/undiloader.S View File

1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
1
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
 
2
 
3
+#include <librm.h>
4
+
3
 	.text
5
 	.text
4
 	.code16
6
 	.code16
5
 	.arch i386
7
 	.arch i386
45
 	.section ".text16", "ax", @progbits
47
 	.section ".text16", "ax", @progbits
46
 1:
48
 1:
47
 	/* Call UNDI loader C code */
49
 	/* Call UNDI loader C code */
48
-	pushl	$pxe_loader_call
49
-	call	prot_call
50
+	virtcall pxe_loader_call
50
 
51
 
51
 1:	/* Restore registers and return */
52
 1:	/* Restore registers and return */
52
 	popw	%bx
53
 	popw	%bx

+ 2
- 4
src/arch/x86/transitions/librm.S View File

131
 	addl	$gdt, gdt_base
131
 	addl	$gdt, gdt_base
132
 
132
 
133
 	/* Initialise IDT */
133
 	/* Initialise IDT */
134
-	pushl	$init_idt
135
-	call	prot_call
134
+	virtcall init_idt
136
 
135
 
137
 	/* Restore registers */
136
 	/* Restore registers */
138
 	negl	%edi
137
 	negl	%edi
554
 	movb	$0x8f, real_cs + 6
553
 	movb	$0x8f, real_cs + 6
555
 	movb	$0x8f, real_ds + 6
554
 	movb	$0x8f, real_ds + 6
556
 	/* Call dummy protected-mode function */
555
 	/* Call dummy protected-mode function */
557
-	pushl	$flatten_dummy
558
-	call	prot_call
556
+	virtcall flatten_dummy
559
 	/* Restore GDT */
557
 	/* Restore GDT */
560
 	movb	$0x00, real_cs + 6
558
 	movb	$0x00, real_cs + 6
561
 	movb	$0x00, real_ds + 6
559
 	movb	$0x00, real_ds + 6

+ 5
- 7
src/arch/x86/transitions/librm_test.c View File

56
 static struct profiler prot_call_profiler __profiler = { .name = "prot_call" };
56
 static struct profiler prot_call_profiler __profiler = { .name = "prot_call" };
57
 
57
 
58
 /**
58
 /**
59
- * Dummy protected-mode function
59
+ * Dummy function for profiling tests
60
  */
60
  */
61
-static void librm_test_prot_call ( void ) {
61
+static __asmcall void librm_test_call ( struct i386_all_regs *ix86 __unused ) {
62
 	/* Do nothing */
62
 	/* Do nothing */
63
 }
63
 }
64
 
64
 
97
 	/* Profile complete real-mode call cycle */
97
 	/* Profile complete real-mode call cycle */
98
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
98
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
99
 		profile_start ( &real_call_profiler );
99
 		profile_start ( &real_call_profiler );
100
-		__asm__ __volatile__ ( REAL_CODE ( "" ) : : );
100
+		__asm__ __volatile__ ( REAL_CODE ( "" ) );
101
 		profile_stop ( &real_call_profiler );
101
 		profile_stop ( &real_call_profiler );
102
 	}
102
 	}
103
 
103
 
105
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
105
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
106
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
106
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
107
 						   "movl %k0, %k2\n\t"
107
 						   "movl %k0, %k2\n\t"
108
-						   "pushl %k3\n\t"
109
-						   "call prot_call\n\t"
108
+						   VIRT_CALL ( librm_test_call )
110
 						   "rdtsc\n\t" )
109
 						   "rdtsc\n\t" )
111
 				       : "=a" ( stopped ), "=d" ( discard_d ),
110
 				       : "=a" ( stopped ), "=d" ( discard_d ),
112
-					 "=R" ( started )
113
-				       : "i" ( librm_test_prot_call ) );
111
+					 "=R" ( started ) : );
114
 		profile_start_at ( &prot_call_profiler, started );
112
 		profile_start_at ( &prot_call_profiler, started );
115
 		profile_stop_at ( &prot_call_profiler, stopped );
113
 		profile_stop_at ( &prot_call_profiler, stopped );
116
 	}
114
 	}

+ 1
- 1
src/arch/x86_64/include/bits/compiler.h View File

7
 #ifndef ASSEMBLY
7
 #ifndef ASSEMBLY
8
 
8
 
9
 /** Declare a function with standard calling conventions */
9
 /** Declare a function with standard calling conventions */
10
-#define __asmcall __attribute__ (( regparm(0) ))
10
+#define __asmcall __attribute__ (( used, regparm(0) ))
11
 
11
 
12
 /** Declare a function with libgcc implicit linkage */
12
 /** Declare a function with libgcc implicit linkage */
13
 #define __libgcc
13
 #define __libgcc

Loading…
Cancel
Save