[klibc] [PATCH/RFC] Add initial avr32 port
maximilian attems
max at stro.at
Mon Aug 8 10:17:11 PDT 2011
From: Bradley Smith <brad at brad-smith.co.uk>
This patch is from
http://git.brad-smith.co.uk/?p=avr32/klibc.git;a=summary
It squashes together and includes those commits:
* Fix ld flags such that shared builds actually run.
* Fix setjmp.
* Fix sigaction/sigrestorer.
* Tidy everything up.
* Fix lseek mess.
Cc: Håvard_Skinnemoen <hskinnemoen at gmail.com>
Cc: Hans-Christian Egtvedt <hans-christian.egtvedt at atmel.com>
Signed-off-by: Bradley Smith <brad at brad-smith.co.uk>
[ minor whitespace adjusting ]
Signed-off-by: maximilian attems <max at stro.at>
---
I am unsure of the state of testing of that branch:
1) Do the klibc tests compile and run?
2) Does initramfs-tools boot in Debian avr32 port with
that klibc patch (that is a strong hint that klibc works
on said port)?
As I don't have such testboards around maybe arch
Maintainers could give that patch a go.
Also I saw that the signal handling gets an axe,
so maybe less is needed against latest linux git?
latest klibc git can be found here:
http://git.kernel.org/?p=libs/klibc/klibc.git;a=summary
At the current state of not ported, I thought belows
might be a first step.
thank you for any information.
maks
usr/include/arch/avr32/klibc/archconfig.h | 14 ++++
usr/include/arch/avr32/klibc/archsetjmp.h | 14 ++++
usr/include/arch/avr32/klibc/archsignal.h | 110 +++++++++++++++++++++++++++++
usr/include/arch/avr32/klibc/archstat.h | 40 +++++++++++
usr/include/arch/avr32/klibc/asmmacros.h | 10 +++
usr/klibc/README.klibc | 2 +-
usr/klibc/arch/avr32/Kbuild | 8 ++
usr/klibc/arch/avr32/MCONFIG | 16 ++++
usr/klibc/arch/avr32/crt0.S | 20 +++++
usr/klibc/arch/avr32/setjmp.S | 30 ++++++++
usr/klibc/arch/avr32/sigreturn.S | 15 ++++
usr/klibc/arch/avr32/syscall.S | 24 ++++++
usr/klibc/arch/avr32/sysstub.ph | 31 ++++++++
usr/klibc/arch/avr32/vfork.S | 26 +++++++
14 files changed, 359 insertions(+), 1 deletions(-)
create mode 100644 usr/include/arch/avr32/klibc/archconfig.h
create mode 100644 usr/include/arch/avr32/klibc/archsetjmp.h
create mode 100644 usr/include/arch/avr32/klibc/archsignal.h
create mode 100644 usr/include/arch/avr32/klibc/archstat.h
create mode 100644 usr/include/arch/avr32/klibc/asmmacros.h
create mode 100644 usr/klibc/arch/avr32/Kbuild
create mode 100644 usr/klibc/arch/avr32/MCONFIG
create mode 100644 usr/klibc/arch/avr32/crt0.S
create mode 100644 usr/klibc/arch/avr32/setjmp.S
create mode 100644 usr/klibc/arch/avr32/sigreturn.S
create mode 100644 usr/klibc/arch/avr32/syscall.S
create mode 100644 usr/klibc/arch/avr32/sysstub.ph
create mode 100644 usr/klibc/arch/avr32/vfork.S
diff --git a/usr/include/arch/avr32/klibc/archconfig.h b/usr/include/arch/avr32/klibc/archconfig.h
new file mode 100644
index 0000000..6876922
--- /dev/null
+++ b/usr/include/arch/avr32/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/avr32/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+#define _KLIBC_NEEDS_SA_RESTORER 1
+
+#endif /* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/avr32/klibc/archsetjmp.h b/usr/include/arch/avr32/klibc/archsetjmp.h
new file mode 100644
index 0000000..da59124
--- /dev/null
+++ b/usr/include/arch/avr32/klibc/archsetjmp.h
@@ -0,0 +1,14 @@
+/*
+ * arch/avr32/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned int regs[11];
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/usr/include/arch/avr32/klibc/archsignal.h b/usr/include/arch/avr32/klibc/archsignal.h
new file mode 100644
index 0000000..a3fafff
--- /dev/null
+++ b/usr/include/arch/avr32/klibc/archsignal.h
@@ -0,0 +1,110 @@
+/*
+ * arch/avr32/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#define _NSIG 64
+#define _NSIG_BPW 32
+#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+
+typedef struct {
+ unsigned long sig[_NSIG_WORDS];
+} sigset_t;
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGIOT 6
+#define SIGBUS 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGSTKFLT 16
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGTSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGURG 23
+#define SIGXCPU 24
+#define SIGXFSZ 25
+#define SIGVTALRM 26
+#define SIGPROF 27
+#define SIGWINCH 28
+#define SIGIO 29
+#define SIGPOLL SIGIO
+/*
+#define SIGLOST 29
+*/
+#define SIGPWR 30
+#define SIGSYS 31
+#define SIGUNUSED 31
+
+/* These should not be considered constants from userland. */
+#define SIGRTMIN 32
+#define SIGRTMAX (_NSIG-1)
+
+/*
+ * SA_FLAGS values:
+ *
+ * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
+ * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
+ * SA_SIGINFO deliver the signal with SIGINFO structs
+ * SA_ONSTACK indicates that a registered stack_t will be used.
+ * SA_RESTART flag to get restarting signals (which were the default long ago)
+ * SA_NODEFER prevents the current signal from being masked in the handler.
+ * SA_RESETHAND clears the handler when the signal is delivered.
+ *
+ * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
+ * Unix names RESETHAND and NODEFER respectively.
+ */
+#define SA_NOCLDSTOP 0x00000001
+#define SA_NOCLDWAIT 0x00000002
+#define SA_SIGINFO 0x00000004
+#define SA_RESTORER 0x04000000
+#define SA_ONSTACK 0x08000000
+#define SA_RESTART 0x10000000
+#define SA_NODEFER 0x40000000
+#define SA_RESETHAND 0x80000000
+
+#define SA_NOMASK SA_NODEFER
+#define SA_ONESHOT SA_RESETHAND
+
+/*
+ * sigaltstack controls
+ */
+#define SS_ONSTACK 1
+#define SS_DISABLE 2
+
+#define MINSIGSTKSZ 2048
+#define SIGSTKSZ 8192
+
+#include <asm-generic/signal.h>
+
+struct siginfo;
+
+struct sigaction {
+ union {
+ __sighandler_t sa_handler;
+ void (*sa_sigaction)(int, struct siginfo *, void *);
+ };
+ unsigned long sa_flags;
+ __sigrestore_t sa_restorer;
+ sigset_t sa_mask;
+};
+
+#endif
diff --git a/usr/include/arch/avr32/klibc/archstat.h b/usr/include/arch/avr32/klibc/archstat.h
new file mode 100644
index 0000000..347c4a0
--- /dev/null
+++ b/usr/include/arch/avr32/klibc/archstat.h
@@ -0,0 +1,40 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+
+struct stat {
+ __stdev64 (st_dev);
+ unsigned char __pad0[4];
+
+ unsigned long __st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ __stdev64(st_rdev);
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+ unsigned long long st_blocks; /* Number 512-byte blocks allocated. */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/usr/include/arch/avr32/klibc/asmmacros.h b/usr/include/arch/avr32/klibc/asmmacros.h
new file mode 100644
index 0000000..32bc2d3
--- /dev/null
+++ b/usr/include/arch/avr32/klibc/asmmacros.h
@@ -0,0 +1,10 @@
+/*
+ * usr/include/arch/avr32/klibc/asmmacros.h
+ *
+ * Assembly macros used by AVR32 system call stubs
+ */
+
+#ifndef _KLIBC_ASMMACROS_H
+#define _KLIBC_ASMMACROS_H
+
+#endif /* _KLIBC_ASMMACROS_H */
diff --git a/usr/klibc/README.klibc b/usr/klibc/README.klibc
index b4135cb..81b28ba 100644
--- a/usr/klibc/README.klibc
+++ b/usr/klibc/README.klibc
@@ -38,7 +38,7 @@ b) If you're cross-compiling, you need to set KLIBCARCH to the
arm-thumb: Untested
arm: Working
arm26: Not yet ported
- avr32: Not yet ported
+ avr32: Untested
cris: Working
h8300: Not yet ported
i386: Working
diff --git a/usr/klibc/arch/avr32/Kbuild b/usr/klibc/arch/avr32/Kbuild
new file mode 100644
index 0000000..e631e32
--- /dev/null
+++ b/usr/klibc/arch/avr32/Kbuild
@@ -0,0 +1,8 @@
+#
+# klibc files for avr32
+#
+
+klib-y := setjmp.o syscall.o vfork.o sigreturn.o
+
+always := crt0.o
+targets := crt0.o
diff --git a/usr/klibc/arch/avr32/MCONFIG b/usr/klibc/arch/avr32/MCONFIG
new file mode 100644
index 0000000..5f2570c
--- /dev/null
+++ b/usr/klibc/arch/avr32/MCONFIG
@@ -0,0 +1,16 @@
+# -*- makefile -*-
+#
+# arch/avr32/MCONFIG
+#
+# Special rules for this architecture. Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS += -Os -fomit-frame-pointer
+KLIBCBITSIZE = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+KLIBCSHAREDFLAGS = -Ttext 0x2aaab600 --section-start .rela.dyn=0x2aaa0000
diff --git a/usr/klibc/arch/avr32/crt0.S b/usr/klibc/arch/avr32/crt0.S
new file mode 100644
index 0000000..d3527c0
--- /dev/null
+++ b/usr/klibc/arch/avr32/crt0.S
@@ -0,0 +1,20 @@
+#
+# arch/avr32/crt0.S
+#
+# void _start(void)
+# {
+# __libc_init(elf_structure, atexit_ptr);
+# }
+#
+
+ .text
+ .align 4
+ .type _start, at function
+ .globl _start
+
+_start:
+ mov r12, sp
+ mov r11, 0
+ bral __libc_init
+
+ .size _start, . - _start
diff --git a/usr/klibc/arch/avr32/setjmp.S b/usr/klibc/arch/avr32/setjmp.S
new file mode 100644
index 0000000..2115ea1
--- /dev/null
+++ b/usr/klibc/arch/avr32/setjmp.S
@@ -0,0 +1,30 @@
+#
+# arch/avr32/setjmp.S
+#
+# setjmp/longjmp for the AVR32 architecture
+#
+
+ .text
+ .align 4
+ .globl setjmp
+ .type setjmp, @function
+setjmp:
+ mustr r8
+ stm r12, r0-r8,sp,lr
+ mov r12, 0
+ retal r12
+ .size setjmp, . - setjmp
+
+ .text
+ .align 4
+ .globl longjmp
+ .type longjmp, @function
+longjmp:
+ ldm r12++, r0-r8,sp,lr
+ mustr r8
+ mov r12, r11
+ cp r12, 0
+ frs
+ moveq r12, 1
+ retal r12
+ .size longjmp, . - longjmp
diff --git a/usr/klibc/arch/avr32/sigreturn.S b/usr/klibc/arch/avr32/sigreturn.S
new file mode 100644
index 0000000..6627694
--- /dev/null
+++ b/usr/klibc/arch/avr32/sigreturn.S
@@ -0,0 +1,15 @@
+/*
+ * arch/avr32/sigreturn.S
+ */
+
+#include <asm/unistd.h>
+
+ .text
+ .align 4
+ .globl __sigreturn
+ .type __sigreturn, @function
+__sigreturn:
+ mov r8, __NR_rt_sigreturn
+ scall
+
+ .size __sigreturn, . - __sigreturn
diff --git a/usr/klibc/arch/avr32/syscall.S b/usr/klibc/arch/avr32/syscall.S
new file mode 100644
index 0000000..230542f
--- /dev/null
+++ b/usr/klibc/arch/avr32/syscall.S
@@ -0,0 +1,24 @@
+/*
+ * arch/avr32/syscall.S
+ *
+ * System call common handling
+ */
+
+ .type __syscall_common, at function
+ .globl __syscall_common
+
+ .align 4
+__syscall_common:
+ ld.w r3, sp[16]
+ scall
+ cp.w r12, -4095
+ brlo .Ldone
+ neg r12
+ lddpc r3, .Lerrno
+ st.w r3[0], r12
+.Ldone:
+ ldm sp++, r3,r5,r6,pc
+
+ .align 4
+.Lerrno:
+ .long errno
diff --git a/usr/klibc/arch/avr32/sysstub.ph b/usr/klibc/arch/avr32/sysstub.ph
new file mode 100644
index 0000000..912cc7b
--- /dev/null
+++ b/usr/klibc/arch/avr32/sysstub.ph
@@ -0,0 +1,31 @@
+# -*- perl -*-
+#
+# arch/avr32/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+
+sub make_sysstub($$$$$@) {
+ my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "${outputdir}/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "#include <klibc/asmmacros.h>\n";
+
+ print OUT " .text\n";
+ print OUT " .type ${fname}, \@function\n";
+ print OUT " .globl ${fname}\n";
+
+
+ print OUT " .align 4\n";
+ print OUT "${fname}:\n";
+ print OUT " stm --sp, r3,r5,r6,lr\n";
+ print OUT " mov r5, r8\n";
+ print OUT " mov r8, __NR_${sname}\n";
+ print OUT " bral __syscall_common\n";
+
+ print OUT " .size __syscall${i}, . - __syscall${i}\n";
+}
+
+1;
diff --git a/usr/klibc/arch/avr32/vfork.S b/usr/klibc/arch/avr32/vfork.S
new file mode 100644
index 0000000..5397582
--- /dev/null
+++ b/usr/klibc/arch/avr32/vfork.S
@@ -0,0 +1,26 @@
+/*
+ * arch/avr32/vfork.S
+ *
+ * vfork - nasty system call which must not use the stack.
+ */
+
+#include <asm/unistd.h>
+
+ .type vfork, at function
+ .globl vfork
+
+ .align 4
+vfork:
+ mov r8, __NR_vfork
+ scall
+ cp.w r12, -4095
+ brlo .Ldone
+ neg r12
+ lddpc r8, .Lerrno
+ st.w r8, r12
+.Ldone:
+ retal r12
+
+ .align 4
+.Lerrno:
+ .word errno
--
1.7.5.4
More information about the klibc
mailing list