Browse Source

[librm] Provide an abstraction wrapper for prot_call

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

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

@@ -9,7 +9,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
9 9
 #ifndef ASSEMBLY
10 10
 
11 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 15
  * Declare a function with libgcc implicit linkage

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

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

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

@@ -6,9 +6,8 @@ void __asmcall _dump_regs ( struct i386_all_regs *ix86 ) {
6 6
 	__asm__ __volatile__ (
7 7
 		TEXT16_CODE ( ".globl dump_regs\n\t"
8 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 12
 	printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
14 13
 		 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"

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

@@ -19,7 +19,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
19 19
 #define LONG_DS 0x40
20 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 36
 #ifdef UACCESS_LIBRM
25 37
 #define UACCESS_PREFIX_librm
@@ -27,6 +39,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
27 39
 #define UACCESS_PREFIX_librm __librm_
28 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 51
 /* Variables in librm.S */
31 52
 extern unsigned long virt_offset;
32 53
 

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

@@ -531,14 +531,12 @@ static void bios_inject_startup ( void ) {
531 531
 	__asm__ __volatile__ (
532 532
 		TEXT16_CODE ( "\nint16_wrapper:\n\t"
533 533
 			      "pushfw\n\t"
534
-			      "cmpb $0, %%cs:bios_inject_lock\n\t"
534
+			      "cmpb $0, %cs:bios_inject_lock\n\t"
535 535
 			      "jnz 1f\n\t"
536
-			      "pushl %0\n\t"
537
-			      "call prot_call\n\t"
536
+			      VIRT_CALL ( bios_inject )
538 537
 			      "\n1:\n\t"
539 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 541
 	/* Hook INT 16 */
544 542
 	hook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ),

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

@@ -46,7 +46,7 @@ static void bios_reboot ( int warm ) {
46 46
 	put_real ( flag, BDA_SEG, BDA_REBOOT );
47 47
 
48 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 52
 PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );

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

@@ -1480,8 +1480,7 @@ static void int13_hook_vector ( void ) {
1480 1480
 			     /* Clear OF, set CF, call int13() */
1481 1481
 			     "orb $0, %%al\n\t" 
1482 1482
 			     "stc\n\t"
1483
-			     "pushl %0\n\t"
1484
-			     "call prot_call\n\t"
1483
+			     VIRT_CALL ( int13 )
1485 1484
 			     /* Chain if OF not set */
1486 1485
 			     "jo 1f\n\t"
1487 1486
 			     "pushfw\n\t"
@@ -1512,8 +1511,7 @@ static void int13_hook_vector ( void ) {
1512 1511
 			     "\n3:\n\t"
1513 1512
 			     "movw %%bp, %%sp\n\t"
1514 1513
 			     "popw %%bp\n\t"
1515
-			     "iret\n\t" )
1516
-	       : : "i" ( int13 ) );
1514
+			     "iret\n\t" ) : : );
1517 1515
 
1518 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,6 +24,8 @@
24 24
 
25 25
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
26 26
 
27
+#include <librm.h>
28
+
27 29
 	.arch i386
28 30
 
29 31
 /****************************************************************************
@@ -120,8 +122,7 @@ pxenv_null_entry:
120 122
 	.section ".text16", "ax", @progbits
121 123
 	.code16
122 124
 pxenv_entry:
123
-	pushl	$pxe_api_call
124
-	call	prot_call
125
+	virtcall pxe_api_call
125 126
 	lret
126 127
 	.size	pxenv_entry, . - pxenv_entry
127 128
 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -56,9 +56,9 @@ static struct profiler real_call_profiler __profiler = { .name = "real_call" };
56 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 62
 	/* Do nothing */
63 63
 }
64 64
 
@@ -97,7 +97,7 @@ static void librm_test_exec ( void ) {
97 97
 	/* Profile complete real-mode call cycle */
98 98
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
99 99
 		profile_start ( &real_call_profiler );
100
-		__asm__ __volatile__ ( REAL_CODE ( "" ) : : );
100
+		__asm__ __volatile__ ( REAL_CODE ( "" ) );
101 101
 		profile_stop ( &real_call_profiler );
102 102
 	}
103 103
 
@@ -105,12 +105,10 @@ static void librm_test_exec ( void ) {
105 105
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
106 106
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
107 107
 						   "movl %k0, %k2\n\t"
108
-						   "pushl %k3\n\t"
109
-						   "call prot_call\n\t"
108
+						   VIRT_CALL ( librm_test_call )
110 109
 						   "rdtsc\n\t" )
111 110
 				       : "=a" ( stopped ), "=d" ( discard_d ),
112
-					 "=R" ( started )
113
-				       : "i" ( librm_test_prot_call ) );
111
+					 "=R" ( started ) : );
114 112
 		profile_start_at ( &prot_call_profiler, started );
115 113
 		profile_stop_at ( &prot_call_profiler, stopped );
116 114
 	}

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

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

Loading…
Cancel
Save