scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit c6c3d1d60e49d18e9cd530c776df7778ec71d83b
parent 0b353ff11d5bff34a621e2775fc146ccce335a26
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  3 Dec 2018 09:38:52 +0000

[lib/c] Add support for arm32

Diffstat:
Alib/c/arch/arm32/Makefile | 14++++++++++++++
Alib/c/arch/arm32/linux/.gitignore | 10++++++++++
Alib/c/arch/arm32/linux/Makefile | 37+++++++++++++++++++++++++++++++++++++
Alib/c/arch/arm32/linux/_cerrno.s | 14++++++++++++++
Alib/c/arch/arm32/linux/_getheap.s | 6++++++
Alib/c/arch/arm32/linux/_open.c | 13+++++++++++++
Alib/c/arch/arm32/linux/_tzone.c | 1+
Alib/c/arch/arm32/linux/gensys.sh | 19+++++++++++++++++++
Alib/c/arch/arm32/linux/getenv.c | 1+
Alib/c/arch/arm32/linux/raise.c | 1+
Alib/c/arch/arm32/linux/signal.c | 1+
Alib/c/arch/arm32/linux/syscall.lst | 11+++++++++++
Alib/c/arch/arm32/linux/time.c | 1+
Alib/c/arch/arm32/longjmp.s | 11+++++++++++
Alib/c/arch/arm32/setjmp.s | 9+++++++++
Aroot/include/scc/bits/arm32/arch/limits.h | 18++++++++++++++++++
Aroot/include/scc/bits/arm32/arch/setjmp.h | 1+
Aroot/include/scc/bits/arm32/arch/stddef.h | 9+++++++++
Aroot/include/scc/bits/arm32/arch/stdint.h | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aroot/include/scc/bits/arm32/arch/stdio.h | 15+++++++++++++++
Aroot/include/scc/bits/arm32/arch/stdlib.h | 14++++++++++++++
Aroot/include/scc/bits/arm32/arch/string.h | 6++++++
Aroot/include/scc/bits/arm32/arch/time.h | 8++++++++
23 files changed, 316 insertions(+), 0 deletions(-)

diff --git a/lib/c/arch/arm32/Makefile b/lib/c/arch/arm32/Makefile @@ -0,0 +1,14 @@ +.POSIX: +PROJECTDIR =../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = longjmp.o setjmp.o +DIRS = linux + +all: $(OBJS) $(SYS) + +$(SYS): FORCE + +@cd $@ && $(MAKE) + +clean: + $(FORALL) diff --git a/lib/c/arch/arm32/linux/.gitignore b/lib/c/arch/arm32/linux/.gitignore @@ -0,0 +1,10 @@ +_Exit.s +_brk.s +_close.s +_getpid.s +_kill.s +_lseek.s +_openat.s +_read.s +_sys_errlist.c +_write.s diff --git a/lib/c/arch/arm32/linux/Makefile b/lib/c/arch/arm32/linux/Makefile @@ -0,0 +1,37 @@ +.POSIX: +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk +include ../../rules.mk + +OBJS = _Exit.o \ + _close.o \ + _brk.o \ + _getpid.o \ + _kill.o \ + _lseek.o \ + _openat.o \ + _read.o \ + _write.o \ + _getheap.o \ + _cerrno.o \ + _open.o \ + _sigaction.o \ + _tzone.o \ + getenv.o \ + raise.o \ + signal.o \ + time.o \ + _sys_errlist.o \ + +all: syscall + $(MAKE) objs + +objs: $(OBJS) + +syscall: syscall.lst + ./gensys.sh syscall.lst + touch syscall + +clean: + rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` + rm -f syscall _sys_errlist.c diff --git a/lib/c/arch/arm32/linux/_cerrno.s b/lib/c/arch/arm32/linux/_cerrno.s @@ -0,0 +1,14 @@ + .file "_cerrno.s" + .globl _cerrno + +_cerrno: + cmp r0,#0 + blt 1f + bx lr + +1: + neg r0,r0 + ldr r1,=errno + str r0,[r1] + mov r0,#-1 + bx lr diff --git a/lib/c/arch/arm32/linux/_getheap.s b/lib/c/arch/arm32/linux/_getheap.s @@ -0,0 +1,6 @@ + .file "_getheap.s" + + .globl _getheap +_getheap: + mov r0,#0 + b _brk diff --git a/lib/c/arch/arm32/linux/_open.c b/lib/c/arch/arm32/linux/_open.c @@ -0,0 +1,13 @@ +#include <stddef.h> + +#include "../../../syscall.h" + +#define AT_FDCWD -100 + +extern int _openat(int fd, const char *fname, int flags); + +int +_open(const char *fname, int flags) +{ + return _openat(AT_FDCWD, fname, flags); +} diff --git a/lib/c/arch/arm32/linux/_tzone.c b/lib/c/arch/arm32/linux/_tzone.c @@ -0,0 +1 @@ +#include "../../posix/_tzone.c" diff --git a/lib/c/arch/arm32/linux/gensys.sh b/lib/c/arch/arm32/linux/gensys.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +sed 's/[ ]*#.*// + /^$/d' syscall.lst | +while read num name +do +cat <<EOF > $name.s + .file "$name.s" + + .globl $name + .arm +$name: + push {r7,lr} + ldr r7,=$num + swi 0 + pop {r7,lr} + b _cerrno +EOF +done diff --git a/lib/c/arch/arm32/linux/getenv.c b/lib/c/arch/arm32/linux/getenv.c @@ -0,0 +1 @@ +#include "../../posix/getenv.c" diff --git a/lib/c/arch/arm32/linux/raise.c b/lib/c/arch/arm32/linux/raise.c @@ -0,0 +1 @@ +#include "../../posix/raise.c" diff --git a/lib/c/arch/arm32/linux/signal.c b/lib/c/arch/arm32/linux/signal.c @@ -0,0 +1 @@ +#include "../../posix/signal.c" diff --git a/lib/c/arch/arm32/linux/syscall.lst b/lib/c/arch/arm32/linux/syscall.lst @@ -0,0 +1,11 @@ +#number name +322 _openat +6 _close +3 _read +4 _write +1 _Exit +20 _getpid +37 _kill +19 _lseek +45 _brk +134 _sigaction diff --git a/lib/c/arch/arm32/linux/time.c b/lib/c/arch/arm32/linux/time.c @@ -0,0 +1 @@ +#include "../../posix/time.c" diff --git a/lib/c/arch/arm32/longjmp.s b/lib/c/arch/arm32/longjmp.s @@ -0,0 +1,11 @@ + .file "longjmp.s" + + .text + .globl longjmp +longjmp: + ldmia r0, {r4-r11, sp, lr} + + // If r1 is 0 return 1 instead + movs r0, r1 + moveq r0, #1 + bx lr diff --git a/lib/c/arch/arm32/setjmp.s b/lib/c/arch/arm32/setjmp.s @@ -0,0 +1,9 @@ + .file "setjmp.s" + + .text + .globl setjmp +setjmp: + // IHI0042F_aapcs.pdf 5.1.1 callee saved registers + stmia r0, {r4-r11, sp, lr} + mov r0, #0 + bx lr diff --git a/root/include/scc/bits/arm32/arch/limits.h b/root/include/scc/bits/arm32/arch/limits.h @@ -0,0 +1,18 @@ +#define CHAR_BIT 8 +#define SCHAR_MAX 0x7F +#define SCHAR_MIN (-SCHAR_MIN - 1) +#define CHAR_MAX 0x7F +#define CHAR_MIN (-CHAR_MAX - 1) +#define UCHAR_MAX 0xFF +#define SHRT_MAX 0x7FFF +#define SHRT_MIN (-SHRT_MAX - 1) +#define USHRT_MAX 0xFFFF +#define INT_MAX 0x7FFFFFFF +#define INT_MIN (-INT_MAX - 1) +#define UINT_MAX 0xFFFFFFFF +#define LONG_MAX 0x7FFFFFFF +#define LONG_MIN (-LONG_MAX - 1) +#define ULONG_MAX 0xFFFFFFFF +#define LLONG_MAX 0x7FFFFFFFFFFFFFFF +#define LLONG_MIN (-LLONG_MAX - 1) +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF diff --git a/root/include/scc/bits/arm32/arch/setjmp.h b/root/include/scc/bits/arm32/arch/setjmp.h @@ -0,0 +1 @@ +typedef unsigned long jmp_buf[10]; diff --git a/root/include/scc/bits/arm32/arch/stddef.h b/root/include/scc/bits/arm32/arch/stddef.h @@ -0,0 +1,9 @@ +#ifndef SIZET_ +typedef unsigned int size_t; +#define SIZET_ +#endif + +#ifndef _PTRDIFF_T +typedef long ptrdiff_t; +#define _PTRDIFF_T +#endif diff --git a/root/include/scc/bits/arm32/arch/stdint.h b/root/include/scc/bits/arm32/arch/stdint.h @@ -0,0 +1,96 @@ +#define INT8_MAX 0x7F +#define INT8_MIN (-INT8_MAX - 1) +#define UINT8_MAX 0xFF + +#define INT16_MAX 0x7FFF +#define INT16_MIN (-INT16_MAX - 1) +#define UINT16_MAX 0xFFFF + +#define INT32_MAX 0x7FFFFFFF +#define INT32_MIN (-INT32_MAX - 1) +#define UINT32_MAX 0xFFFFFFFF + +#define INT64_MAX 0x7FFFFFFFFFFFFFFF +#define INT64_MIN (-INT64_MAX - 1) +#define UINT64_MAX 0xFFFFFFFFFFFFFFFF + +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +#define INT_FAST8_MIN INT32_MIN +#define INT_FAST8_MAX INT32_MAX +#define UINT_FAST8_MAX UINT32_MAX + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST16_MAX INT32_MAX +#define UINT_FAST16_MAX UINT32_MAX + +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST64_MAX UINT64_MAX + +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +#define SIZE_MAX UINT32_MAX + +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef signed char int8_least_t; +typedef short int16_least_t; +typedef int int32_least_t; +typedef long long int64_least_t; + +typedef unsigned char uint8_least_t; +typedef unsigned short uint16_least_t; +typedef unsigned int uint32_least_t; +typedef unsigned long long uint64_least_t; + +typedef int int8_fast_t; +typedef int int16_fast_t; +typedef int int32_fast_t; +typedef long long int64_fast_t; + +typedef unsigned int uint8_fast_t; +typedef unsigned int uint16_fast_t; +typedef unsigned int uint32_fast_t; +typedef unsigned long long uint64_fast_t; + +typedef long intptr_t; +typedef unsigned long uintptr_t; + +typedef long long intmax_t; +typedef unsigned long long uintmax_t; diff --git a/root/include/scc/bits/arm32/arch/stdio.h b/root/include/scc/bits/arm32/arch/stdio.h @@ -0,0 +1,15 @@ +#ifndef _SIZET +typedef unsigned int size_t; +#define _SIZET +#endif + +#define BUFSIZ 512 +#define FILENAME_MAX 256 +#define FOPEN_MAX 16 + +#define TMP_MAX 25 +#define L_tmpnam 256 + +#define _TMPNAME "/tmp/tmp.0000000" + +typedef int fpos_t; diff --git a/root/include/scc/bits/arm32/arch/stdlib.h b/root/include/scc/bits/arm32/arch/stdlib.h @@ -0,0 +1,14 @@ +#ifndef SIZET_ +typedef unsigned int size_t; +#define SIZET_ +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#ifndef _WCHAR_T +typedef int wchar_t; // TODO +#define _WCHAR_T +#endif + +#define _ALIGNTYPE long double diff --git a/root/include/scc/bits/arm32/arch/string.h b/root/include/scc/bits/arm32/arch/string.h @@ -0,0 +1,6 @@ +#ifndef SIZET_ +typedef unsigned int size_t; +#define SIZET_ +#endif + +#define __NUMCHARS 128 diff --git a/root/include/scc/bits/arm32/arch/time.h b/root/include/scc/bits/arm32/arch/time.h @@ -0,0 +1,8 @@ +#ifndef _SIZET +typedef unsigned int size_t; +#define _SIZET +#endif + +#define _MAXYEAR 9999 + +typedef long int time_t;