Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ LIB_TARGETS := $(PREFIX_A)libphoenix.a $(PREFIX_A)crt0.o

all: $(LIB_TARGETS)

ifeq ($(TARGET_SUBFAMILY),multilib)
LIBPHOENIX_MULTILIB := y
CPPFLAGS += -DLIBPHOENIX_MULTILIB
else
LIBPHOENIX_MULTILIB := n
endif

ifneq (,$(findstring arm,$(TARGET_SUFF)))
include arch/arm/Makefile
else ifneq (,$(findstring aarch64,$(TARGET_SUFF)))
Expand Down
25 changes: 21 additions & 4 deletions arch/arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@
# %LICENSE%
#

ifneq (,$(findstring v7a,$(TARGET_SUFF)))
# Obtain architecture based on ARM ACLE 2.0
# https://developer.arm.com/documentation/dui0774/l/Other-Compiler-specific-Features/Predefined-macros
arm_version := $(word 3, $(shell echo | arm-phoenix-gcc $(CFLAGS) -E -dM - | grep -E "[[:space:]]__ARM_ARCH[[:space:]]"))
arm_profile_num := $(word 3, $(shell echo | arm-phoenix-gcc $(CFLAGS) -E -dM - | grep -E "[[:space:]]__ARM_ARCH_PROFILE[[:space:]]"))
# ASCII conversion
arm_profile := $(subst 65,A,$(subst 77,M,$(subst 82,R,$(arm_profile_num))))
arm_arch := $(arm_version)$(arm_profile)

arm_use_common := y
ifneq (,$(findstring 7A,$(arm_arch)))
include arch/arm/v7a/Makefile
else ifneq (,$(findstring v7m,$(TARGET_SUFF)))
else ifneq (,$(findstring 7M,$(arm_arch)))
include arch/arm/v7m/Makefile
else ifneq (,$(findstring v8m,$(TARGET_SUFF)))
else ifneq (,$(findstring 8M,$(arm_arch)))
include arch/arm/v8m/Makefile
else ifneq (,$(findstring v8r,$(TARGET_SUFF)))
else ifneq (,$(findstring 8R,$(arm_arch)))
include arch/arm/v8r/Makefile
else ifeq ($(LIBPHOENIX_MULTILIB),y)
include arch/arm/multilib/Makefile
arm_use_common := n
else
$(error Unsupported TARGET)
endif

# FIXME: multilib supports more targets that functions in those files do,
# eg. arm/arch=armv5te or Thumb-1 targets (v6s-m and v8-m.base).
ifeq ($(arm_use_common),y)
OBJS += $(addprefix $(PREFIX_O)arch/arm/, jmp.o memcpy.o memset.o signal.o string.o)
endif

CRT0_OBJS += $(addprefix $(PREFIX_O)arch/arm/, crt0.o)
11 changes: 11 additions & 0 deletions arch/arm/multilib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Makefile for libphoenix/arch/arm/multilib
#
# Copyright 2025 Phoenix Systems
#
# %LICENSE%
#

OBJS += $(addprefix $(PREFIX_O)arch/arm/multilib/, syscalls.o reboot.o)

OBJS += $(addprefix $(PREFIX_O)arch/arm/multilib/, jmp.o signal.o string.o)
42 changes: 42 additions & 0 deletions arch/arm/multilib/jmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
*
* _setjmp, _longjmp, setjmp, sigsetjmp
*
* Copyright 2025 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include <setjmp.h>
#include <stdlib.h>


int _setjmp(jmp_buf var)
{
abort();
}


__attribute__((__noreturn__)) void _longjmp(jmp_buf var, int m)
{
abort();
}


int setjmp(jmp_buf var)
{
abort();
}


int sigsetjmp(sigjmp_buf env, int savesigs)
{
abort();
}
31 changes: 31 additions & 0 deletions arch/arm/multilib/reboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* reboot.c
*
* Copyright 2025 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include <sys/reboot.h>
#include <sys/platform.h>


int reboot(int magic)
{
return -1;
}


int reboot_reason(uint32_t *val)
{
*val = 0u;

return 0;
}
24 changes: 24 additions & 0 deletions arch/arm/multilib/signal.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* Signal trampoline (arm)
*
* Copyright 2025 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#define __ASSEMBLY__

.text

.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
bl abort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bl as b may have to short range

.size _signal_trampoline, .-_signal_trampoline
127 changes: 127 additions & 0 deletions arch/arm/multilib/string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* arch/arm/multilib/string
*
* Copyright 2025 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#include <stddef.h>


void *memmove(void *dest, const void *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
((char *)dest)[i] = ((const char *)src)[i];
}
return dest;
}


int memcmp(const void *ptr1, const void *ptr2, size_t n)
{
for (size_t i = 0; i < n; i++) {
int diff = ((int)(((const unsigned char *)ptr1)[i])) - ((int)(((const unsigned char *)ptr2)[i]));
if (diff != 0) {
return diff;
}
}
return 0;
}


size_t strlen(const char *s)
{
size_t len = 0;
while (s[len] != '\0') {
len++;
}
return len;
}


size_t strnlen(const char *s, size_t maxlen)
{
size_t len = 0;
while ((s[len] != '\0') && (len < maxlen)) {
len++;
}
return len;
}


int strcmp(const char *s1, const char *s2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid - strcmp("a", "ab") returns 0 (should return negative value)

{
for (size_t i = 0; (s1[i] != '\0') || (s2[i] != '\0'); i++) {
int diff = ((int)(((const unsigned char *)s1)[i])) - ((int)(((const unsigned char *)s2)[i]));
if (diff != 0) {
return diff;
}
}
return 0;
}


int strncmp(const char *s1, const char *s2, size_t count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid - strncmp("a", "ab", 2) returns 0 (should return negative value)

{
for (size_t i = 0; ((i < count) && ((s1[i] != '\0') || (s2[i] != '\0'))); i++) {
int diff = ((int)(((const unsigned char *)s1)[i])) - ((int)(((const unsigned char *)s2)[i]));
if (diff != 0) {
return diff;
}
}
return 0;
}


char *strcpy(char *dest, const char *src)
{
size_t i = 0;
while ((src[i] != '\0')) {
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return dest;
}


char *strncpy(char *dest, const char *src, size_t n)
{
size_t i = 0;
while (((i < n) && (src[i] != '\0'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a valid implementation of strncpy (zero-fill all of the remaining place, don't add `'\0' if it doesn't fit)

dest[i] = src[i];
i++;
}
while (i < n) {
dest[i] = '\0';
i++;
}
return dest;
}


void *memcpy(void *dest, const void *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
((char *)dest)[i] = ((const char *)src)[i];
}
return dest;
}


void *memset(void *dest, int value, size_t n)
{
for (size_t i = 0; i < n; i++) {
((unsigned char *)dest)[i] = (unsigned char)value;
}
return dest;
}
41 changes: 41 additions & 0 deletions arch/arm/multilib/syscalls.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* syscalls (arm-multilib)
*
* Copyright 2025 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#define __ASSEMBLY__
#include <phoenix/syscalls.h>

.text


#define SYSCALLDEF(sym, sn) \
.globl sym; \
.type sym, %function; \
sym: \
bl abort; \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bl as b may have to short range

.size sym, .-sym


.globl vfork;
.type vfork, %function;
vfork:
b vforksvc
.size vfork, .-vfork


#define SYSCALLS_LIBC(name) \
SYSCALLDEF(name, __COUNTER__);


SYSCALLS(SYSCALLS_LIBC)
21 changes: 21 additions & 0 deletions arch/arm/v7a/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
*/

#include <sys/reboot.h>

#if defined(LIBPHOENIX_MULTILIB)


int reboot(int magic)
{
return -1;
}


int reboot_reason(uint32_t *val)
{
return -1;
}


#else


#include <sys/platform.h>
#if defined(__CPU_ZYNQ7000)
#include <phoenix/arch/armv7a/zynq7000/zynq7000.h>
Expand Down Expand Up @@ -52,3 +71,5 @@ int reboot_reason(uint32_t *val)
*val = pctl.reboot.reason;
return 0;
}

#endif
21 changes: 21 additions & 0 deletions arch/arm/v7m/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
*/

#include <sys/reboot.h>

#if defined(LIBPHOENIX_MULTILIB)


int reboot(int magic)
{
return -1;
}


int reboot_reason(uint32_t *val)
{
return -1;
}


#else


#include <sys/platform.h>

#if defined(__CPU_STM32L4X6)
Expand Down Expand Up @@ -55,3 +74,5 @@ int reboot_reason(uint32_t *val)
*val = pctl.reboot.reason;
return 0;
}

#endif
Loading
Loading