History

more minor fixes

* tccgen: re-allow long double constants for x87 cross sizeof (long double) may be 12 or 16 depending on host platform (i386/x86_64 on unix/windows). Except that it's 8 if the host is on windows and not gcc was used to compile tcc. * win64: fix builtin_va_start after VT_REF removal See also a8b83ce43a95fa519dacfe7690a3a0098af7909c * tcctest.c: remove outdated limitation for ll-bitfield test It always worked, there is no reason why it should not work in future. * libtcc1.c: exclude long double conversion on ARM * Makefile: remove CFLAGS from link recipes * lib/Makefile: use target DEFINES as passed from main Makefile * lib/armflush.c lib/va_list.c: factor out from libtcc1.c * arm-gen.c: disable "depreciated" warnings for now

grischka committed 9 years ago

Commit 44abffe1 parent 94ac9f29 files · +194 −166Browse files

Showing the changes to lib (4 of 9 files). Show all

Unified · Split

4 files
  1. lib/Makefile +25 −32
  2. lib/armflush.c +58 −0
  3. lib/libtcc1.c +16 −112
  4. lib/va_list.c +65 −0
lib/Makefile+25−32
@@ -17,61 +17,54 @@ XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include · 16 unmodified lines
17XFLAGS = $(XFLAGS$(XCFG))17XFLAGS = $(XFLAGS$(XCFG))
18XCFG = $(or $(findstring -win,$T),-unx)18XCFG = $(or $(findstring -win,$T),-unx)
19 19
20ifeq ($(X),)20# using gcc ("make armlib-usegcc=no" to use tcc)
21 BCHECK_O = bcheck.o21armlib-usegcc ?= no
22 ifeq "$T" "arm"
23 XCC = $(CC)
24 XAR = $(AR)
25 XFLAGS = $(CFLAGS) -fPIC
26 endif
27endif
28 22
29ifdef CONFIG_OSX23ifeq "$($(X)$(T)lib-usegcc)" "yes"
30 XFLAGS += -D_ANSI_SOURCE24 XCC = $(CC)
25 XAR = $(AR)
26 XFLAGS = $(CFLAGS) -fPIC
31endif27endif
32 28
29# only for native compiler
30$(X)BCHECK_O = bcheck.o
31
33ifeq ($(CONFIG_musl),yes)32ifeq ($(CONFIG_musl),yes)
34 BCHECK_O =33 BCHECK_O =
35endif34endif
36 35
36ifdef CONFIG_OSX
37 XFLAGS += -D_ANSI_SOURCE
38endif
39
37I386_O = libtcc1.o alloca86.o alloca86-bt.o40I386_O = libtcc1.o alloca86.o alloca86-bt.o
38X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o41X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o
39ARM_O = libtcc1.o armeabi.o alloca-arm.o42ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o
40ARM64_O = lib-arm64.o43ARM64_O = lib-arm64.o
41WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o44WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
42 45
43OBJ-i386 = $(I386_O) $(BCHECK_O)46OBJ-i386 = $(I386_O) $(BCHECK_O)
44TGT-i386 = -DTCC_TARGET_I38647OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O)
45 48OBJ-x86_64-osx = $(X86_64_O) va_list.o
46OBJ-x86_64 = $(X86_64_O) $(BCHECK_O)
47TGT-x86_64 = -DTCC_TARGET_X86_64
48
49OBJ-x86_64-osx = $(X86_64_O)
50TGT-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
51
52OBJ-arm = $(ARM_O)
53TGT-arm = -DTCC_TARGET_ARM
54
55OBJ-arm64 = $(ARM64_O)
56TGT-arm64 = -DTCC_TARGET_ARM64
57
58OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O)49OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O)
59TGT-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE
60
61OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O)50OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O)
62TGT-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE51OBJ-arm64 = $(ARM64_O)
63 52OBJ-arm = $(ARM_O)
53OBJ-arm-fpa = $(ARM_O)
54OBJ-arm-fpa-ld = $(ARM_O)
55OBJ-arm-vfp = $(ARM_O)
56OBJ-arm-eabi = $(ARM_O)
57OBJ-arm-eabihf = $(ARM_O)
64OBJ-arm-wince = $(ARM_O) $(WIN_O)58OBJ-arm-wince = $(ARM_O) $(WIN_O)
65TGT-arm-wince = -DTCC_TARGET_ARM -DTCC_TARGET_PE
66 59
67$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))60$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))
68 $(XAR) rcs $@ $^61 $(XAR) rcs $@ $^
69 62
70$(X)%.o : %.c63$(X)%.o : %.c
71 $(XCC) -c $< -o $@ $(TGT-$T) $(XFLAGS)64 $(XCC) -c $< -o $@ $(DEFINES) $(XFLAGS)
72 65
73$(X)%.o : %.S66$(X)%.o : %.S
74 $(XCC) -c $< -o $@ $(TGT-$T) $(XFLAGS)67 $(XCC) -c $< -o $@ $(DEFINES) $(XFLAGS)
75 68
76$(X)crt1w.o : crt1.c69$(X)crt1w.o : crt1.c
77$(X)wincrt1w.o : wincrt1.c70$(X)wincrt1w.o : wincrt1.c
lib/armflush.c+58−0
@@ -0,0 +1,58 @@
1/* armflush.c - flush the instruction cache
2
3 __clear_cache is used in tccrun.c, It is a built-in
4 intrinsic with gcc. However tcc in order to compile
5 itself needs this function */
6
7#ifdef __TINYC__
8
9/* syscall wrapper */
10unsigned syscall(unsigned syscall_nr, ...);
11
12/* arm-tcc supports only fake asm currently */
13__asm__(
14 ".global syscall\n"
15 "syscall:\n"
16 ".int 0xe92d4080\n" // push {r7, lr}
17 ".int 0xe1a07000\n" // mov r7, r0
18 ".int 0xe1a00001\n" // mov r0, r1
19 ".int 0xe1a01002\n" // mov r1, r2
20 ".int 0xe1a02003\n" // mov r2, r3
21 ".int 0xef000000\n" // svc 0x00000000
22 ".int 0xe8bd8080\n" // pop {r7, pc}
23 );
24
25/* from unistd.h: */
26#if defined(__thumb__) || defined(__ARM_EABI__)
27# define __NR_SYSCALL_BASE 0x0
28#else
29# define __NR_SYSCALL_BASE 0x900000
30#endif
31#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000)
32#define __ARM_NR_cacheflush (__ARM_NR_BASE+2)
33
34#else
35
36#define _GNU_SOURCE
37#include <unistd.h>
38#include <sys/syscall.h>
39#include <stdio.h>
40
41#endif
42
43/* Flushing for tccrun */
44void __clear_cache(void *beginning, void *end)
45{
46/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
47 * However, there is no ARM asm parser in tcc so we use it for now */
48#if 1
49 syscall(__ARM_NR_cacheflush, beginning, end, 0);
50#else
51 __asm__ ("push {r7}\n\t"
52 "mov r7, #0xf0002\n\t"
53 "mov r2, #0\n\t"
54 "swi 0\n\t"
55 "pop {r7}\n\t"
56 "ret");
57#endif
58}
lib/libtcc1.c+16−112
@@ -550,6 +550,13 @@ unsigned long long __fixunssfdi (float a1) · 549 unmodified lines
550 return 0;550 return 0;
551}551}
552 552
553long long __fixsfdi (float a1)
554{
555 long long ret; int s;
556 ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
557 return s ? ret : -ret;
558}
559
553unsigned long long __fixunsdfdi (double a1)560unsigned long long __fixunsdfdi (double a1)
554{561{
555 register union double_long dl1;562 register union double_long dl1;
@@ -575,6 +582,14 @@ unsigned long long __fixunsdfdi (double a1) · 19 unmodified lines
575 return 0;582 return 0;
576}583}
577 584
585long long __fixdfdi (double a1)
586{
587 long long ret; int s;
588 ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
589 return s ? ret : -ret;
590}
591
592#ifndef TCC_TARGET_ARM
578unsigned long long __fixunsxfdi (long double a1)593unsigned long long __fixunsxfdi (long double a1)
579{594{
580 register union ldouble_long dl1;595 register union ldouble_long dl1;
@@ -598,121 +613,10 @@ unsigned long long __fixunsxfdi (long double a1) · 17 unmodified lines
598 return 0;613 return 0;
599}614}
600 615
601long long __fixsfdi (float a1)
602{
603 long long ret; int s;
604 ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
605 return s ? ret : -ret;
606}
607
608long long __fixdfdi (double a1)
609{
610 long long ret; int s;
611 ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
612 return s ? ret : -ret;
613}
614
615long long __fixxfdi (long double a1)616long long __fixxfdi (long double a1)
616{617{
617 long long ret; int s;618 long long ret; int s;
618 ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);619 ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
619 return s ? ret : -ret;620 return s ? ret : -ret;
620}621}
621 622#endif /* !ARM */
622#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
623
624#ifndef __TINYC__
625# include <stdlib.h>
626# include <stdio.h>
627# include <string.h>
628# undef __va_start
629# undef __va_arg
630# undef __va_copy
631# undef __va_end
632#else
633/* Avoid include files, they may not be available when cross compiling */
634extern void *memset(void *s, int c, __SIZE_TYPE__ n);
635extern void abort(void);
636#endif
637
638/* This should be in sync with our include/stdarg.h */
639enum __va_arg_type {
640 __va_gen_reg, __va_float_reg, __va_stack
641};
642
643/* GCC compatible definition of va_list. */
644typedef struct {
645 unsigned int gp_offset;
646 unsigned int fp_offset;
647 union {
648 unsigned int overflow_offset;
649 char *overflow_arg_area;
650 };
651 char *reg_save_area;
652} __va_list_struct;
653
654void __va_start(__va_list_struct *ap, void *fp)
655{
656 memset(ap, 0, sizeof(__va_list_struct));
657 *ap = *(__va_list_struct *)((char *)fp - 16);
658 ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
659 ap->reg_save_area = (char *)fp - 176 - 16;
660}
661
662void *__va_arg(__va_list_struct *ap,
663 enum __va_arg_type arg_type,
664 int size, int align)
665{
666 size = (size + 7) & ~7;
667 align = (align + 7) & ~7;
668 switch (arg_type) {
669 case __va_gen_reg:
670 if (ap->gp_offset + size <= 48) {
671 ap->gp_offset += size;
672 return ap->reg_save_area + ap->gp_offset - size;
673 }
674 goto use_overflow_area;
675
676 case __va_float_reg:
677 if (ap->fp_offset < 128 + 48) {
678 ap->fp_offset += 16;
679 return ap->reg_save_area + ap->fp_offset - 16;
680 }
681 size = 8;
682 goto use_overflow_area;
683
684 case __va_stack:
685 use_overflow_area:
686 ap->overflow_arg_area += size;
687 ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
688 return ap->overflow_arg_area - size;
689
690 default: /* should never happen */
691 abort();
692 }
693}
694#endif /* __x86_64__ */
695
696#if defined TCC_TARGET_ARM && !defined __TINYC__
697#define _GNU_SOURCE
698#include <unistd.h>
699#include <sys/syscall.h>
700#include <stdio.h>
701
702/* Flushing for tccrun */
703void __clear_cache(void *beginning, void *end)
704{
705/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
706 * However, there is no ARM asm parser in tcc so we use it for now */
707#if 1
708 syscall(__ARM_NR_cacheflush, beginning, end, 0);
709#else
710 __asm__ ("push {r7}\n\t"
711 "mov r7, #0xf0002\n\t"
712 "mov r2, #0\n\t"
713 "swi 0\n\t"
714 "pop {r7}\n\t"
715 "ret");
716#endif
717}
718#endif /* arm */
lib/va_list.c+65−0
@@ -0,0 +1,65 @@
1/* va_list.c - tinycc support for va_list on X86_64 */
2
3#if defined TCC_TARGET_X86_64
4
5/* Avoid include files, they may not be available when cross compiling */
6extern void *memset(void *s, int c, __SIZE_TYPE__ n);
7extern void abort(void);
8
9/* This should be in sync with our include/stdarg.h */
10enum __va_arg_type {
11 __va_gen_reg, __va_float_reg, __va_stack
12};
13
14/* GCC compatible definition of va_list. */
15typedef struct {
16 unsigned int gp_offset;
17 unsigned int fp_offset;
18 union {
19 unsigned int overflow_offset;
20 char *overflow_arg_area;
21 };
22 char *reg_save_area;
23} __va_list_struct;
24
25void __va_start(__va_list_struct *ap, void *fp)
26{
27 memset(ap, 0, sizeof(__va_list_struct));
28 *ap = *(__va_list_struct *)((char *)fp - 16);
29 ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
30 ap->reg_save_area = (char *)fp - 176 - 16;
31}
32
33void *__va_arg(__va_list_struct *ap,
34 enum __va_arg_type arg_type,
35 int size, int align)
36{
37 size = (size + 7) & ~7;
38 align = (align + 7) & ~7;
39 switch (arg_type) {
40 case __va_gen_reg:
41 if (ap->gp_offset + size <= 48) {
42 ap->gp_offset += size;
43 return ap->reg_save_area + ap->gp_offset - size;
44 }
45 goto use_overflow_area;
46
47 case __va_float_reg:
48 if (ap->fp_offset < 128 + 48) {
49 ap->fp_offset += 16;
50 return ap->reg_save_area + ap->fp_offset - 16;
51 }
52 size = 8;
53 goto use_overflow_area;
54
55 case __va_stack:
56 use_overflow_area:
57 ap->overflow_arg_area += size;
58 ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
59 return ap->overflow_arg_area - size;
60
61 default: /* should never happen */
62 abort();
63 }
64}
65#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t