Skip to content

Commit

Permalink
Merge pull request #6 from wenxuanjun/main
Browse files Browse the repository at this point in the history
使用xmake构建libc和shell
  • Loading branch information
xiaoyi1212 authored Nov 12, 2024
2 parents 7e2d151 + 264cbab commit 87b020b
Show file tree
Hide file tree
Showing 96 changed files with 1,332 additions and 1,404 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project struct document [Project docs](docs/README.md)
## Build

* Install `xmake` and `nasm`
* Type `xmake build qemu`
* Type `xmake run`

## Contributing

Expand Down
51 changes: 24 additions & 27 deletions apps/include/ctype.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#pragma once

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>

typedef int ssize_t;
typedef size_t usize;
typedef ssize_t isize;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -13,54 +21,47 @@ static inline int isalpha(int c) {
}

static inline int isalnum(int c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) return 8;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9')) return 8;
return 0;
}

static inline int islower(int c) {
if (c >= 'a' && c <= 'z') return 512;

return 0;
}

static inline int ispunct(char ch) {
return ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
ch == '(' || ch == ')' || ch == '+' || ch == '-' || ch == '/' || ch == '?' || ch == '"' || ch == '\'' ||
ch == ':' || ch == ';' || ch == '{' || ch == '[' || ch == ']' || ch == '}' || ch == '|' || ch == '\\' ||
ch == '~' || ch == '`' || ch == '<' || ch == '>' || ch == ',' || ch == '.';
return ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%' ||
ch == '^' || ch == '&' || ch == '*' || ch == '(' || ch == ')' ||
ch == '+' || ch == '-' || ch == '/' || ch == '?' || ch == '"' ||
ch == '\'' || ch == ':' || ch == ';' || ch == '{' || ch == '[' ||
ch == ']' || ch == '}' || ch == '|' || ch == '\\' || ch == '~' ||
ch == '`' || ch == '<' || ch == '>' || ch == ',' || ch == '.';
}

static inline char toupper(char ch) {
return (ch & 0xDF);
}
static inline char toupper(char ch) { return (ch & 0xDF); }

static inline char tolower(char ch) {
return (ch | 0x20);
}
static inline char tolower(char ch) { return (ch | 0x20); }

static inline int iscsymf(int ch) {
return ch == '_' || isdigit(ch) || isalpha(ch);
}

static inline int isascll(char ch) {
return ((ch & 0x80) == 0);
}
static inline int isascll(char ch) { return ((ch & 0x80) == 0); }

static inline int iscntrl(char ch) {
return ((ch == 0x7F) || (ch >= 0x00 && ch <= 0x1F));
}

static inline int isprint(int c) {
return (c > 0x1F && c < 0x7F);
}
static inline int isprint(int c) { return (c > 0x1F && c < 0x7F); }

static inline int isgraph(int c) {
return (c > 0x20 && c < 0x7F);
}
static inline int isgraph(int c) { return (c > 0x20 && c < 0x7F); }

static inline int isxdigit(int c) {
if (!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
if (!isdigit(c)) return 0;
if (!isdigit(c))
return 0;
}
return 1;
}
Expand All @@ -70,12 +71,8 @@ static inline int isspace(int c) {
c == '\v');
}

static inline int isupper(int c) {
return (c >= 'A' && c <= 'Z');
}
static inline int isupper(int c) { return (c >= 'A' && c <= 'Z'); }

#ifdef __cplusplus
}
#endif


80 changes: 40 additions & 40 deletions apps/include/limits.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
/*
* limits.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Functions for manipulating paths and directories (included from io.h)
* plus functions for setting the current drive.
*
* Defines constants for the sizes of integral types.
*
* NOTE: GCC should supply a version of this header and it should be safe to
* use that version instead of this one (maybe safer).
*
*/
* limits.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Functions for manipulating paths and directories (included from io.h)
* plus functions for setting the current drive.
*
* Defines constants for the sizes of integral types.
*
* NOTE: GCC should supply a version of this header and it should be safe to
* use that version instead of this one (maybe safer).
*
*/
#ifndef _LIMITS_H_
#define _LIMITS_H_
/* All the headers include this file. */
/*
* File system limits
*
* TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the
* same as FILENAME_MAX and FOPEN_MAX from stdio.h?
* NOTE: Apparently the actual size of PATH_MAX is 260, but a space is
* required for the NUL. TODO: Test?
*/
* File system limits
*
* TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the
* same as FILENAME_MAX and FOPEN_MAX from stdio.h?
* NOTE: Apparently the actual size of PATH_MAX is 260, but a space is
* required for the NUL. TODO: Test?
*/
#define PATH_MAX (259)
/*
* Characteristics of the char data type.
*
* TODO: Is MB_LEN_MAX correct?
*/
* Characteristics of the char data type.
*
* TODO: Is MB_LEN_MAX correct?
*/
#define CHAR_BIT 8
#define MB_LEN_MAX 2
#define SCHAR_MIN (-128)
#define SCHAR_MAX 127
#define UCHAR_MAX 255
/* TODO: Is this safe? I think it might just be testing the preprocessor,
* not the compiler itself... */
* not the compiler itself... */
#if ('\x80' < 0)
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
Expand All @@ -45,30 +45,30 @@
#define CHAR_MAX UCHAR_MAX
#endif
/*
* Maximum and minimum values for ints.
*/
* Maximum and minimum values for ints.
*/
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX-1)
#define INT_MIN (-INT_MAX - 1)
#define UINT_MAX 0xffffffff
/*
* Maximum and minimum values for shorts.
*/
* Maximum and minimum values for shorts.
*/
#define SHRT_MAX 32767
#define SHRT_MIN (-SHRT_MAX-1)
#define SHRT_MIN (-SHRT_MAX - 1)
#define USHRT_MAX 0xffff
/*
* Maximum and minimum values for longs and unsigned longs.
*
* TODO: This is not correct for Alphas, which have 64 bit longs.
*/
* Maximum and minimum values for longs and unsigned longs.
*
* TODO: This is not correct for Alphas, which have 64 bit longs.
*/
#define LONG_MAX 2147483647L
#define LONG_MIN (-LONG_MAX-1)
#define LONG_MIN (-LONG_MAX - 1)
#define ULONG_MAX 0xffffffffUL
/*
* The GNU C compiler also allows 'long long int'
*/
* The GNU C compiler also allows 'long long int'
*/
#define LONG_LONG_MAX 9223370L
#define LONG_LONG_MIN (-LONG_LONG_MAX-1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define ULONG_LONG_MAX (2ULL * LONG_LONG_MAX + 1)
/* ISO C9x macro names */
#define LLONG_MAX LONG_LONG_MAX
Expand Down
11 changes: 5 additions & 6 deletions apps/include/math.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once


#define MIN(i, j) (((i) < (j)) ? (i) : (j))
#define MAX(i, j) (((i) > (j)) ? (i) : (j))

Expand All @@ -14,11 +13,11 @@

#define PHI 1.61803398874989484820458683436563811772030917980576

#define NAN __builtin_nan("")
#define NAN __builtin_nan("")
#define INFINITY __builtin_inf()
#define HUGE_VALF __builtin_huge_valf()
#define HUGE_VAL __builtin_huge_val()
#define HUGE_VALL __builtin_huge_vall()
#define HUGE_VALF __builtin_huge_valf()
#define HUGE_VAL __builtin_huge_val()
#define HUGE_VALL __builtin_huge_vall()

#define INT_MAX 2147483647
#define INT_MIN -2147483648
Expand Down Expand Up @@ -148,4 +147,4 @@ double log(double a);

double exp(double x);

float roundf(float x);
float roundf(float x);
6 changes: 2 additions & 4 deletions apps/include/stdio.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include "ctype.h"

int printf(char *format,...);
int printf(const char *format,...);
int putchar(char c);
int puts(char *string);
int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap);
Expand Down
5 changes: 1 addition & 4 deletions apps/include/stdlib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <stddef.h>
#include "ctype.h"

void exit(int retval);
Expand All @@ -18,6 +17,4 @@ static inline int atoi(const char **s) {
return i;
}

static inline void abort(void){
exit(-1);
}
static inline void abort(void) { exit(-1); }
Loading

0 comments on commit 87b020b

Please sign in to comment.