PulkoMandy | 17fc759 | 2022-07-28 18:27:54 +0200 | [diff] [blame^] | 1 | This chapter documents the Backend for the Intel i386 processor family. |
| 2 | |
| 3 | @section Additional options for this version |
| 4 | |
| 5 | This backend provides the following additional options: |
| 6 | |
| 7 | @table @option |
| 8 | |
| 9 | @item -longalign |
| 10 | Align multibyte-values on 4-byte-boundaries. Needed by some |
| 11 | operating systems. |
| 12 | |
| 13 | @item -elf |
| 14 | Do not use a '_'-prefix in front of external identifiers. |
| 15 | Use a '.'-prefix for label names. |
| 16 | |
| 17 | @item -merge-constants |
| 18 | Place identical floating point constants at the same |
| 19 | memory location. This can reduce program size and increase |
| 20 | compilation time. |
| 21 | |
| 22 | @item -const-in-data |
| 23 | By default constant data will be placed in a read-only |
| 24 | section. Using this option it will be placed in the data section |
| 25 | Note that on operating systems with memory protection this |
| 26 | option will disable write-protection of constant data. |
| 27 | |
| 28 | @item -no-delayed-popping |
| 29 | By default arguments of function calls are not always popped |
| 30 | from the stack immediately after the call, so that the |
| 31 | arguments of several calls may be popped at once. |
| 32 | With this option vbcc can be forced to pop them after every |
| 33 | function call. |
| 34 | This may simplify debugging and very slightly reduce the |
| 35 | stack size needed by the compiled program. |
| 36 | |
| 37 | @item -safe-fp |
| 38 | Do not use the floating-point-stack for register variables. |
| 39 | At the moment this is necessary as vbcci386 still has problems |
| 40 | in some cases otherwise. |
| 41 | @end table |
| 42 | |
| 43 | |
| 44 | @section ABI |
| 45 | |
| 46 | This backend supports the following registers: |
| 47 | |
| 48 | @itemize @minus |
| 49 | @item @code{%eax, %ebx, %ecx, %edx} |
| 50 | @item @code{%esi, %edi, %ebp, %esp} |
| 51 | @end itemize |
| 52 | |
| 53 | (And @code{%st(0)-%st(7)} for the floating point stack but these must not |
| 54 | bes used for register variables because they cannot be handled like |
| 55 | normal registers.) |
| 56 | |
| 57 | The current version generates assembly output for use with the GNU |
| 58 | assembler. The generated code should work on systems with Intel 80386 |
| 59 | or higher CPUs with FPU and compatible chips. |
| 60 | |
| 61 | The registers @code{%eax, %ecx} and @code{%edx} (as well as the floating point stack) |
| 62 | are used as scratch registers (i.e. they can be destroyed in function |
| 63 | calls), all other registers are preserved. |
| 64 | |
| 65 | All elementary types up to 4 bytes are returned in register @code{%eax} |
| 66 | Floating point values are returned in %st(0). |
| 67 | All other types are returned by passing the function the address |
| 68 | of the result as a hidden argument - so when you call such a function |
| 69 | without a proper declaration in scope you can expect a crash. |
| 70 | |
| 71 | @code{vbcc} uses @code{%eax, %ebx, %ecx, %edx, %esi, %edi, %ebp} and the floating point |
| 72 | stack for temporary results and register variables. Local variables |
| 73 | are created on the stack and addressed via @code{%esp}. |
| 74 | |
| 75 | The elementary data types are represented like: |
| 76 | |
| 77 | @example |
| 78 | type size in bits alignment in bytes (-longalign) |
| 79 | |
| 80 | char 8 1 (1) |
| 81 | short 16 2 (4) |
| 82 | int 32 2 (4) |
| 83 | long 32 2 (4) |
| 84 | long long n/a n/a |
| 85 | all pointers 32 2 (4) |
| 86 | float 32 2 (4) |
| 87 | double 64 2 (4) |
| 88 | @end example |
| 89 | |
| 90 | @section Predefined Macros |
| 91 | |
| 92 | This backend defines the following macros: |
| 93 | |
| 94 | @table @code |
| 95 | @item __I386__ |
| 96 | @item __X86__ |
| 97 | |
| 98 | @end table |
| 99 | |
| 100 | |
| 101 | @section Stdarg |
| 102 | |
| 103 | A possible <stdarg.h> could look like this: |
| 104 | |
| 105 | @example |
| 106 | typedef unsigned char *va_list; |
| 107 | |
| 108 | #define va_start(ap, lastarg) ((ap) = (va_list)(&lastarg + 1)) |
| 109 | #define va_arg(ap, type) ((ap) += \ |
| 110 | (sizeof(type)<sizeof(int)?sizeof(int):sizeof(type)), ((type *)(ap))[-1]) |
| 111 | #define va_end(ap) ((ap) = 0L) |
| 112 | @end example |
| 113 | |
| 114 | |
| 115 | @section Known Problems |
| 116 | |
| 117 | @itemize @minus |
| 118 | @item generated code is rather poor |
| 119 | @item functions which return floating-point values sometimes are broken(?) |
| 120 | @item in some cases (scare registers) non-reentrant code is generated |
| 121 | @end itemize |
| 122 | |
| 123 | |