Skip to content

Commit e0061e4

Browse files
authored
Update
0 parents  commit e0061e4

17 files changed

+2882
-0
lines changed

Diff for: README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# MdrOS 应用程序开发环境
2+
3+
该环境编译出的应用程序仅适用于`CP_Kernel`内核系列的操作系统.
4+
5+
<hr>
6+
7+
* 注意! 该环境只能在Linux系统下使用, 并要求您具备zig cc编译器(或者clang)和nasm汇编器
8+
9+
* `src` - 源码文件夹
10+
* `lib` - 适用于MdrOS的标准库实现, 尽量不要更改该文件夹内的代码
11+
* `xmake.lua` - 构建脚本
12+
13+
> `xmake build` 一键构建命令 \
14+
> 根目录会生成 `app.elf` 该文件即应用程序实体, 将其移动至mdros光盘映像内即可 \
15+
> 然后启动MdrOS, 在终端中输入 `/app.elf` 即可查看运行结果

Diff for: app.elf

24.7 KB
Binary file not shown.

Diff for: lib/include/ctype.h

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
3+
#include <stdarg.h>
4+
#include <stddef.h>
5+
#include <stdint.h>
6+
7+
typedef int ssize_t;
8+
typedef size_t usize;
9+
typedef ssize_t isize;
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
static inline int isdigit(int c) {
16+
return (c >= '0' && c <= '9');
17+
}
18+
19+
static inline int isalpha(int c) {
20+
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
21+
}
22+
23+
static inline int isalnum(int c) {
24+
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
25+
(c >= '0' && c <= '9')) return 8;
26+
return 0;
27+
}
28+
29+
static inline int islower(int c) {
30+
if (c >= 'a' && c <= 'z') return 512;
31+
return 0;
32+
}
33+
34+
static inline int ispunct(char ch) {
35+
return ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%' ||
36+
ch == '^' || ch == '&' || ch == '*' || ch == '(' || ch == ')' ||
37+
ch == '+' || ch == '-' || ch == '/' || ch == '?' || ch == '"' ||
38+
ch == '\'' || ch == ':' || ch == ';' || ch == '{' || ch == '[' ||
39+
ch == ']' || ch == '}' || ch == '|' || ch == '\\' || ch == '~' ||
40+
ch == '`' || ch == '<' || ch == '>' || ch == ',' || ch == '.';
41+
}
42+
43+
static inline char toupper(char ch) { return (ch & 0xDF); }
44+
45+
static inline char tolower(char ch) { return (ch | 0x20); }
46+
47+
static inline int iscsymf(int ch) {
48+
return ch == '_' || isdigit(ch) || isalpha(ch);
49+
}
50+
51+
static inline int isascll(char ch) { return ((ch & 0x80) == 0); }
52+
53+
static inline int iscntrl(char ch) {
54+
return ((ch == 0x7F) || (ch >= 0x00 && ch <= 0x1F));
55+
}
56+
57+
static inline int isprint(int c) { return (c > 0x1F && c < 0x7F); }
58+
59+
static inline int isgraph(int c) { return (c > 0x20 && c < 0x7F); }
60+
61+
static inline int isxdigit(int c) {
62+
if (!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
63+
if (!isdigit(c))
64+
return 0;
65+
}
66+
return 1;
67+
}
68+
69+
static inline int isspace(int c) {
70+
return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' ||
71+
c == '\v');
72+
}
73+
74+
static inline int isupper(int c) { return (c >= 'A' && c <= 'Z'); }
75+
76+
#ifdef __cplusplus
77+
}
78+
#endif

Diff for: lib/include/math.h

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#pragma once
2+
3+
#define MIN(i, j) (((i) < (j)) ? (i) : (j))
4+
#define MAX(i, j) (((i) > (j)) ? (i) : (j))
5+
6+
#define F32_EPSILON 1e-5f
7+
#define F64_EPSILON 1e-10
8+
9+
#define PI 3.14159265358979323846264338327950288
10+
#define E 2.718281828459045235360287
11+
12+
#define SQRT2 1.41421356237309504880168872420969807
13+
14+
#define PHI 1.61803398874989484820458683436563811772030917980576
15+
16+
#define NAN __builtin_nan("")
17+
#define INFINITY __builtin_inf()
18+
#define HUGE_VALF __builtin_huge_valf()
19+
#define HUGE_VAL __builtin_huge_val()
20+
#define HUGE_VALL __builtin_huge_vall()
21+
22+
#define INT_MAX 2147483647
23+
#define INT_MIN -2147483648
24+
25+
#define W_TYPE_SIZE 32
26+
#define BITS_PER_UNIT 8
27+
28+
#define POW223 8388608.0
29+
30+
#include <stddef.h>
31+
#include <stdbool.h>
32+
33+
static inline unsigned __FLOAT_BITS(float __f) {
34+
union {
35+
float __f;
36+
unsigned __i;
37+
} __u;
38+
__u.__f = __f;
39+
return __u.__i;
40+
}
41+
42+
static inline unsigned long long __DOUBLE_BITS(double __f) {
43+
union {
44+
double __f;
45+
unsigned long long __i;
46+
} __u;
47+
__u.__f = __f;
48+
return __u.__i;
49+
}
50+
51+
#define fpclassify(x) ( \
52+
sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
53+
sizeof(x) == sizeof(double) ? __fpclassify(x) : \
54+
__fpclassify(x) )
55+
56+
#define isinf(x) ( \
57+
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
58+
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \
59+
__fpclassify(x) == FP_INFINITE)
60+
61+
#define isnan(x) ( \
62+
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
63+
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
64+
__fpclassify(x) == FP_NAN)
65+
66+
#define isnormal(x) ( \
67+
sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \
68+
sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \
69+
__fpclassify(x) == FP_NORMAL)
70+
71+
#define isfinite(x) ( \
72+
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \
73+
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \
74+
__fpclassify(x) > FP_INFINITE)
75+
76+
typedef int Wtype;
77+
typedef unsigned int UWtype;
78+
typedef unsigned int USItype;
79+
typedef long long DWtype;
80+
typedef unsigned long long UDWtype;
81+
82+
struct DWstruct {
83+
Wtype low, high;
84+
};
85+
86+
typedef union {
87+
struct DWstruct s;
88+
DWtype ll;
89+
} DWunion;
90+
91+
typedef long double XFtype;
92+
93+
#include <stdint.h>
94+
95+
void srandlevel(unsigned short randlevel_);
96+
97+
void smax(unsigned short max_b);
98+
99+
int32_t abs(int32_t x);
100+
101+
double pow(double a, long long b);
102+
103+
unsigned long long ull_pow(unsigned long long a, unsigned long long b);
104+
105+
double sqrt(double x);
106+
107+
float q_sqrt(float number);
108+
109+
double mod(double x, double y);
110+
111+
double sin(double x);
112+
113+
double cos(double x);
114+
115+
double tan(double x);
116+
117+
double asin(double x);
118+
119+
double acos(double x);
120+
121+
double atan(double x);
122+
123+
double atan2(double y, double x);
124+
125+
double floor(double x);
126+
127+
double modf(double x, double *iptr);
128+
129+
double fabs(double x);
130+
131+
double ceil(double x);
132+
133+
double frexp(double x, int *e);
134+
135+
double scalbln(double x, long n);
136+
137+
double ldexp(double x, int n);
138+
139+
float scalbnf(float x, int n);
140+
141+
double scalbn(double x, int n);
142+
143+
double fmod(double x, double y);
144+
145+
double log10(double x);
146+
147+
double log2(float x);
148+
149+
double log(double a);
150+
151+
double exp(double x);
152+
153+
float roundf(float x);

Diff for: lib/include/stdio.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "ctype.h"
4+
5+
int printf(const char *format,...);
6+
int putchar(char c);
7+
int puts(char *string);
8+
int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap);
9+
int vsprintf(char *buf, const char *fmt, va_list args);
10+
int sprintf(char *buf, const char *fmt, ...);

Diff for: lib/include/stdlib.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "ctype.h"
4+
5+
void exit(int retval);
6+
void *calloc(size_t nelem, size_t elsize);
7+
void *malloc(unsigned size);
8+
void *realloc(void *ptr, unsigned newsize);
9+
void free(void *ptr);
10+
void *xmalloc(size_t size);
11+
int atoi(const char **s);
12+
static inline void abort(void) { exit(-1); }

Diff for: lib/include/string.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include "ctype.h"
4+
5+
#define MAX_PRECISION (10)
6+
7+
// String length functions
8+
size_t strlen(const char *str);
9+
size_t strnlen(const char *s, size_t maxlen);
10+
11+
// String comparison functions
12+
int strcmp(const char *s1, const char *s2);
13+
int strncmp(const char *s1, const char *s2, size_t n);
14+
int strcoll(const char *str1, const char *str2);
15+
16+
// String copy functions
17+
char *strcpy(char *dest, const char *src);
18+
char *strncpy(char *dest, const char *src, unsigned long long count);
19+
20+
// String concatenation functions
21+
char *strcat(char *dest, const char *src);
22+
char *strncat(char *dest, const char *src, unsigned long long count);
23+
24+
// Memory functions
25+
void *memcpy(void *s, const void *ct, size_t n);
26+
int memcmp(const void *a_, const void *b_, uint32_t size);
27+
void *memset(void *s, int c, size_t n);
28+
void *memmove(void *dest, const void *src, size_t num);
29+
30+
// String search functions
31+
const char *strstr(const char *str1, const char *str2);
32+
char *strchr(const char *s, const char ch);
33+
char *strpbrk(const char *str, const char *strCharSet);
34+
size_t strspn(const char *string, const char *control);
35+
36+
// String utility functions
37+
char *strdup(const char *str);
38+
double strtod(const char *nptr, char **endptr);
39+
char *ftoa(double f, char *buf, int precision);

0 commit comments

Comments
 (0)