Skip to content

Commit 74d6cff

Browse files
committed
feat port: added generic platform support
Signed-off-by: John Sanpe <sanpeqf@gmail.com>
1 parent 3010520 commit 74d6cff

7 files changed

Lines changed: 310 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: build generic on ubuntu gcc
2+
3+
on:
4+
repository_dispatch:
5+
workflow_dispatch:
6+
push:
7+
pull_request:
8+
schedule:
9+
- cron: '0 */2 * * *'
10+
11+
env:
12+
BUILD_TYPE: Release
13+
14+
jobs:
15+
build:
16+
name: Test on ${{matrix.os}}
17+
runs-on: ${{matrix.os}}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-22.04]
21+
22+
steps:
23+
- name: checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: install dependencies
29+
run: |
30+
sudo apt update
31+
sudo apt install cmake make gcc ccache
32+
33+
- name: configure cmake
34+
run: |
35+
cmake -B ${{github.workspace}}/build \
36+
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install \
37+
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
38+
-D CMAKE_C_COMPILER=/usr/lib/ccache/gcc \
39+
-D CMAKE_SYSTEM_NAME=Generic -Wno-dev \
40+
-D BFDEV_DEVEL=ON
41+
42+
- name: make
43+
run: |
44+
cmake --build ${{github.workspace}}/build \
45+
--config ${{env.BUILD_TYPE}}
46+
47+
- name: install
48+
run: |
49+
cmake --build ${{github.workspace}}/build \
50+
--config ${{env.BUILD_TYPE}} -- install
51+
52+
- name: ctest
53+
working-directory: ${{github.workspace}}/build
54+
run: ctest -C ${{env.BUILD_TYPE}} -V

port/build.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD|FreeBSD|NetBSD|OpenBSD|DragonFly")
1515
set(BFDEV_PORT_TYPE "posix")
1616
endif()
1717

18+
if(CMAKE_SYSTEM_NAME MATCHES "Generic")
19+
set(BFDEV_PORT_TYPE "generic")
20+
endif()
21+
1822
if(BFDEV_PORT_TYPE)
1923
include(${BFDEV_PORT_PATH}/${BFDEV_PORT_TYPE}/build.cmake)
2024
else()

port/generic/build.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: LGPL-3.0-or-later
2+
#
3+
# Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
#
5+
6+
set(BFDEV_SOURCE
7+
${BFDEV_SOURCE}
8+
${CMAKE_CURRENT_LIST_DIR}/log.c
9+
${CMAKE_CURRENT_LIST_DIR}/stdio.c
10+
${CMAKE_CURRENT_LIST_DIR}/stdlib.c
11+
${CMAKE_CURRENT_LIST_DIR}/string.c
12+
)

port/generic/log.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: LGPL-3.0-or-later */
2+
/*
3+
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#include <port/stdio.h>
7+
#include <port/log.h>
8+
#include <export.h>
9+
10+
/* TODO: PORTME */
11+
12+
export int
13+
bfport_log_write(bfdev_log_message_t *msg)
14+
{
15+
return 0;
16+
}

port/generic/stdio.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: LGPL-3.0-or-later */
2+
/*
3+
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#include <port/stdio.h>
7+
#include <port/stdio.h>
8+
#include <export.h>
9+
10+
/* TODO: PORTME */
11+
12+
export int
13+
bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt,
14+
bfdev_va_list arg)
15+
{
16+
return 0;
17+
}

port/generic/stdlib.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* SPDX-License-Identifier: LGPL-3.0-or-later */
2+
/*
3+
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#include <port/stdlib.h>
7+
#include <export.h>
8+
9+
/* TODO: PORTME */
10+
11+
export __bfdev_malloc void *
12+
bfport_malloc(bfdev_size_t size)
13+
{
14+
return BFDEV_NULL;
15+
}
16+
17+
export __bfdev_malloc void *
18+
bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size)
19+
{
20+
return BFDEV_NULL;
21+
}
22+
23+
export __bfdev_malloc void *
24+
bfport_realloc(void *ptr, bfdev_size_t size)
25+
{
26+
return BFDEV_NULL;
27+
}
28+
29+
export void
30+
bfport_free(void *ptr)
31+
{
32+
return;
33+
}
34+
35+
export int
36+
bfport_rand(void)
37+
{
38+
return 0;
39+
}
40+
41+
export __bfdev_noreturn void
42+
bfport_abort(void)
43+
{
44+
for (;;);
45+
}

port/generic/string.c

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* SPDX-License-Identifier: LGPL-3.0-or-later */
2+
/*
3+
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#include <port/string.h>
7+
#include <export.h>
8+
9+
export void *
10+
bfport_memcpy(void *dest, const void *src, bfdev_size_t n)
11+
{
12+
const unsigned char *nsrc;
13+
unsigned char *ndest;
14+
15+
ndest = dest;
16+
nsrc = src;
17+
18+
while (n--)
19+
*ndest++ = *nsrc++;
20+
21+
return dest;
22+
}
23+
24+
export void *
25+
bfport_memset(void *s, int c, bfdev_size_t n)
26+
{
27+
unsigned char *xs;
28+
29+
xs = s;
30+
while (n--)
31+
*xs++ = c;
32+
33+
return s;
34+
}
35+
36+
export int
37+
bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n)
38+
{
39+
const unsigned char *su1, *su2;
40+
int res;
41+
42+
res = 0;
43+
for (su1 = s1, su2 = s2; 0 < n; ++su1, ++su2, n--) {
44+
if ((res = *su1 - *su2) != 0)
45+
break;
46+
}
47+
48+
return res;
49+
}
50+
51+
export int
52+
bfport_strcmp(const char *s1, const char *s2)
53+
{
54+
int cp;
55+
56+
cp = 0;
57+
while (!(cp = *s1++ - *s2++)) {
58+
if (*s1 == '\0')
59+
break;
60+
}
61+
62+
return cp;
63+
}
64+
65+
export char *
66+
bfport_strchr(const char *s, int c)
67+
{
68+
for (; *s != (char)c; ++s) {
69+
if (*s == '\0')
70+
return BFDEV_NULL;
71+
}
72+
73+
return (char *)s;
74+
}
75+
76+
export bfdev_size_t
77+
bfport_strspn(const char *s, const char *accept)
78+
{
79+
const unsigned char *p, *a;
80+
bfdev_size_t count;
81+
82+
count = 0;
83+
for (p = s; *p != '\0'; ++p) {
84+
for (a = accept; *a != '\0'; ++a) {
85+
if (*p == *a)
86+
break;
87+
}
88+
if (*a == '\0')
89+
return count;
90+
++count;
91+
}
92+
93+
return count;
94+
}
95+
96+
export bfdev_size_t
97+
bfport_strcspn(const char *s, const char *reject)
98+
{
99+
const unsigned char *p, *r;
100+
bfdev_size_t count;
101+
102+
count = 0;
103+
for (p = s; *p != '\0'; ++p) {
104+
for (r = reject; *r != '\0'; ++r) {
105+
if (*p == *r)
106+
return count;
107+
}
108+
++count;
109+
}
110+
111+
return count;
112+
}
113+
114+
export char *
115+
bfport_strcpy(char *dest, const char *src)
116+
{
117+
unsigned char *tmp;
118+
119+
tmp = dest;
120+
while ((*tmp++ = *src++) != '\0')
121+
;
122+
123+
return dest;
124+
}
125+
126+
export char *
127+
bfport_strncpy(char *dest, const char *src, bfdev_size_t n)
128+
{
129+
unsigned char *tmp;
130+
131+
for (tmp = dest; n--; ++tmp) {
132+
if ((*tmp = *src) != 0)
133+
src++;
134+
}
135+
136+
return dest;
137+
}
138+
139+
export bfdev_size_t
140+
bfport_strlen(const char *s)
141+
{
142+
const unsigned char *len;
143+
144+
len = s;
145+
while (*len != '\0')
146+
len++;
147+
148+
return (char *)len - s;
149+
}
150+
151+
export bfdev_size_t
152+
bfport_strnlen(const char *s, bfdev_size_t len)
153+
{
154+
const unsigned char *sc;
155+
156+
for (sc = s; len--; ++sc) {
157+
if (*sc == '\0')
158+
break;
159+
}
160+
161+
return (char *)sc - s;
162+
}

0 commit comments

Comments
 (0)