commit 7420c9b7648a69ed3727b069608e6abcba721621 parent 85743cc3e3d80b3e2a255986f154ad8b290b11a1 Author: Roberto Vargas <roberto.vargas@arm.com> Date: Thu, 22 Nov 2018 14:50:51 +0000 [arch/sys] Create sys directories Change-Id: Ic6b3bb120c4fd0947b31af43790289f4b93d192b Diffstat:
51 files changed, 393 insertions(+), 51 deletions(-)
diff --git a/arch/amd64/Makefile b/arch/amd64/Makefile @@ -2,24 +2,33 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk -ROMOBJS = crt.o \ - arch.o \ +ROMOBJS = arch.o \ rom.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/romfw/builtin.o \ -RAMOBJS = crt.o \ - arch.o \ +RAMOBJS = arch.o \ ram.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/ramfw/builtin.o \ TARGET = $(BINDIR)/romfw.elf $(BINDIR)/ramfw.elf +DIRS = sys all: $(TARGET) +sys/$(SYS)/builtin.o: sys/$(SYS) + +sys/$(SYS): FORCE + cd $@ && $(MAKE) + $(BINDIR)/romfw.elf: $(ROMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(ROMOBJS) $(RCODE_LDLIBS) -o $@ $(BINDIR)/ramfw.elf: $(RAMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(RAMOBJS) $(RCODE_LDLIBS) -o $@ + +clean: + $(FORALL) diff --git a/arch/amd64/bss.c b/arch/amd64/bss.c @@ -1 +1 @@ -#include "../posix/bss.c" +#include "../sys/bss.c" diff --git a/arch/amd64/crt.s b/arch/amd64/crt.s @@ -1,37 +0,0 @@ - .section ".note.openbsd.ident", "a" - .p2align 2 - .long 8 - .long 4 - .long 1 - .ascii "OpenBSD\0" - .long 0 - .p2align 2 - - .section ".note.netbsd.ident", "a" - .p2align 2 - - .long 7 - .long 4 - .long 1 - .ascii "NetBSD\0\0" - .long 800000000 - - .bss - .globl _environ -_environ: - .quad 0 - - .text - .global _start -_start: - movq %rsp,%rbp - - /* load argc, argv, envp from stack */ - movq (%rbp),%rdi /* argc */ - leaq 8(%rbp),%rsi /* argv */ - leaq 16(%rbp,%rdi,8),%rdx /* envp = argv + 8*argc + 8 */ - movq %rdx,_environ - - call main - movl %eax,%edi - jmp exit diff --git a/arch/amd64/sys/Makefile b/arch/amd64/sys/Makefile @@ -0,0 +1,8 @@ +.POSIX: +PROJECTDIR=../../.. +include $(PROJECTDIR)/scripts/rules.mk + +DIRS = dragonfly linux netbsd openbsd + +clean: + $(FORALL) diff --git a/arch/amd64/sys/crt-posix.s b/arch/amd64/sys/crt-posix.s @@ -0,0 +1,19 @@ + .bss + .globl _environ +_environ: + .quad 0 + + .text + .global _start +_start: + movq %rsp,%rbp + + /* load argc, argv, envp from stack */ + movq (%rbp),%rdi /* argc */ + leaq 8(%rbp),%rsi /* argv */ + leaq 16(%rbp,%rdi,8),%rdx /* envp = argv + 8*argc + 8 */ + movq %rdx,_environ + + call main + movl %eax,%edi + jmp exit diff --git a/arch/amd64/sys/dragonfly/Makefile b/arch/amd64/sys/dragonfly/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/amd64/sys/dragonfly/crt.s b/arch/amd64/sys/dragonfly/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/amd64/sys/dragonfly/putenv.c b/arch/amd64/sys/dragonfly/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/amd64/sys/linux/Makefile b/arch/amd64/sys/linux/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/amd64/sys/linux/crt.s b/arch/amd64/sys/linux/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/amd64/sys/linux/putenv.c b/arch/amd64/sys/linux/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/amd64/sys/netbsd/Makefile b/arch/amd64/sys/netbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/amd64/sys/netbsd/crt.s b/arch/amd64/sys/netbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.netbsd.ident", "a" + .p2align 2 + + .long 7 + .long 4 + .long 1 + .ascii "NetBSD\0\0" + .long 800000000 + .include "../crt-posix.s" diff --git a/arch/amd64/sys/netbsd/putenv.c b/arch/amd64/sys/netbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/amd64/sys/openbsd/Makefile b/arch/amd64/sys/openbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/amd64/sys/openbsd/crt.s b/arch/amd64/sys/openbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.openbsd.ident", "a" + .p2align 2 + .long 8 + .long 4 + .long 1 + .ascii "OpenBSD\0" + .long 0 + .p2align 2 + .include "../crt-posix.s" diff --git a/arch/amd64/sys/openbsd/putenv.c b/arch/amd64/sys/openbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm32/Makefile b/arch/arm32/Makefile @@ -2,24 +2,33 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk -ROMOBJS = crt.o \ - arch.o \ +ROMOBJS = arch.o \ rom.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/romfw/builtin.o \ -RAMOBJS = crt.o \ - arch.o \ +RAMOBJS = arch.o \ ram.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/ramfw/builtin.o \ TARGET = $(BINDIR)/romfw.elf $(BINDIR)/ramfw.elf +DIRS = sys all: $(TARGET) +sys/$(SYS)/builtin.o: sys/$(SYS) + +sys/$(SYS): FORCE + cd $@ && $(MAKE) + $(BINDIR)/romfw.elf: $(ROMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(ROMOBJS) $(RCODE_LDLIBS) -o $@ $(BINDIR)/ramfw.elf: $(RAMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(RAMOBJS) $(RCODE_LDLIBS) -o $@ + +clean: + $(FORALL) diff --git a/arch/arm32/sys/Makefile b/arch/arm32/sys/Makefile @@ -0,0 +1,8 @@ +.POSIX: +PROJECTDIR=../../.. +include $(PROJECTDIR)/scripts/rules.mk + +DIRS = dragonfly linux netbsd openbsd + +clean: + $(FORALL) diff --git a/arch/arm32/crt.s b/arch/arm32/sys/crt-posix.s diff --git a/arch/arm32/sys/dragonfly/Makefile b/arch/arm32/sys/dragonfly/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm32/sys/dragonfly/crt.s b/arch/arm32/sys/dragonfly/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/arm32/sys/dragonfly/putenv.c b/arch/arm32/sys/dragonfly/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm32/sys/linux/Makefile b/arch/arm32/sys/linux/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm32/sys/linux/crt.s b/arch/arm32/sys/linux/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/arm32/sys/linux/putenv.c b/arch/arm32/sys/linux/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm32/sys/netbsd/Makefile b/arch/arm32/sys/netbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm32/sys/netbsd/crt.s b/arch/arm32/sys/netbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.netbsd.ident", "a" + .p2align 2 + + .long 7 + .long 4 + .long 1 + .ascii "NetBSD\0\0" + .long 800000000 + .include "../crt-posix.s" diff --git a/arch/arm32/sys/netbsd/putenv.c b/arch/arm32/sys/netbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm32/sys/openbsd/Makefile b/arch/arm32/sys/openbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm32/sys/openbsd/crt.s b/arch/arm32/sys/openbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.openbsd.ident", "a" + .p2align 2 + .long 8 + .long 4 + .long 1 + .ascii "OpenBSD\0" + .long 0 + .p2align 2 + .include "../crt-posix.s" diff --git a/arch/arm32/sys/openbsd/putenv.c b/arch/arm32/sys/openbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile @@ -2,24 +2,33 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk -ROMOBJS = crt.o \ - arch.o \ +ROMOBJS = arch.o \ rom.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/romfw/builtin.o \ -RAMOBJS = crt.o \ - arch.o \ +RAMOBJS = arch.o \ ram.o \ bss.o \ + sys/$(SYS)/builtin.o \ $(SRCDIR)/ramfw/builtin.o \ TARGET = $(BINDIR)/romfw.elf $(BINDIR)/ramfw.elf +DIRS = sys all: $(TARGET) +sys/$(SYS)/builtin.o: sys/$(SYS) + +sys/$(SYS): FORCE + cd $@ && $(MAKE) + $(BINDIR)/romfw.elf: $(ROMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(ROMOBJS) $(RCODE_LDLIBS) -o $@ $(BINDIR)/ramfw.elf: $(RAMOBJS) $(LIBDEP) $(LD) $(RCODE_LDFLAGS) $(RAMOBJS) $(RCODE_LDLIBS) -o $@ + +clean: + $(FORALL) diff --git a/arch/arm64/sys/Makefile b/arch/arm64/sys/Makefile @@ -0,0 +1,8 @@ +.POSIX: +PROJECTDIR=../../.. +include $(PROJECTDIR)/scripts/rules.mk + +DIRS = dragonfly linux netbsd openbsd + +clean: + $(FORALL) diff --git a/arch/arm64/crt.s b/arch/arm64/sys/crt-posix.s diff --git a/arch/arm64/sys/dragonfly/Makefile b/arch/arm64/sys/dragonfly/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm64/sys/dragonfly/crt.s b/arch/arm64/sys/dragonfly/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/arm64/sys/dragonfly/putenv.c b/arch/arm64/sys/dragonfly/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm64/sys/linux/Makefile b/arch/arm64/sys/linux/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm64/sys/linux/crt.s b/arch/arm64/sys/linux/crt.s @@ -0,0 +1 @@ + .include "../crt-posix.s" diff --git a/arch/arm64/sys/linux/putenv.c b/arch/arm64/sys/linux/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm64/sys/netbsd/Makefile b/arch/arm64/sys/netbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm64/sys/netbsd/crt.s b/arch/arm64/sys/netbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.netbsd.ident", "a" + .p2align 2 + + .long 7 + .long 4 + .long 1 + .ascii "NetBSD\0\0" + .long 800000000 + .include "../crt-posix.s" diff --git a/arch/arm64/sys/netbsd/putenv.c b/arch/arm64/sys/netbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/arm64/sys/openbsd/Makefile b/arch/arm64/sys/openbsd/Makefile @@ -0,0 +1,13 @@ +.POSIX: +PROJECTDIR=../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = crt.o \ + putenv.o \ + +all: builtin.o + +builtin.o: $(OBJS) + $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) + +crt.o: ../crt-posix.s diff --git a/arch/arm64/sys/openbsd/crt.s b/arch/arm64/sys/openbsd/crt.s @@ -0,0 +1,9 @@ + .section ".note.openbsd.ident", "a" + .p2align 2 + .long 8 + .long 4 + .long 1 + .ascii "OpenBSD\0" + .long 0 + .p2align 2 + .include "../crt-posix.s" diff --git a/arch/arm64/sys/openbsd/putenv.c b/arch/arm64/sys/openbsd/putenv.c @@ -0,0 +1 @@ +#include "../../../sys/putenv-posix.c" diff --git a/arch/rmode/crt.s b/arch/rmode/crt.s @@ -3,7 +3,7 @@ SRAMADDR = 0x2E00F000 SRAMSIZE = 4096 .text - .globl _start + .globl _start,_environ _start: bl getpc getpc: @@ -43,6 +43,12 @@ initmem: b.ne initmem ret +_environ: + mov x0,sp + mov x1,#(~4095) + and x0,x0,x1 + ret + .section .rodata outsync: .asciz "out of sync" diff --git a/arch/rmode/putenv.c b/arch/rmode/putenv.c @@ -0,0 +1,40 @@ +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +extern char **_environ(); + +int +putenv(char *name) +{ + char **p, **env, *s; + size_t len; + int *nump; + + if ((s = strchr(name, '=')) == NULL) { + errno = EINVAL; + return -1; + } + len = s - name; + + env = _environ(); + for (p = env + 1; *p; ++p) { + if (!strncmp(name, *p, len) && (*p)[len] == '=') + break; + } + + if (*p) { + *p = name; + } else { + nump = (int *) env; + if (*nump == 0) { + errno = ENOMEM; + return -1; + } + --*nump; + *p++ = name; + *p = NULL; + } + + return 0; +} diff --git a/arch/posix/bss.c b/arch/sys/bss.c diff --git a/arch/sys/putenv-posix.c b/arch/sys/putenv-posix.c @@ -0,0 +1,35 @@ +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +extern char **_environ; + +int +putenv(char *name) +{ + char **p, *s; + size_t len, cnt; + + if ((s = strchr(name, '=')) == NULL) { + errno = EINVAL; + return -1; + } + len = s - name; + + for (p = _environ; *p; ++p) { + if (!strncmp(name, *p, len) && (*p)[len] == '=') { + *p = name; + return 0; + } + } + + cnt = (_environ) ? p - _environ : 0; + p = realloc(_environ, (cnt + 2) * sizeof(char **)); + if (!p) + return -1; + _environ = p; + p[cnt] = name; + p[cnt+1] = NULL; + + return 0; +}