调整user下libs的libc目录结构 (#103)

* 调整user下libs的libc目录结构

* 修正.gitignore文件的问题

* 修复无法编译的问题

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
wwc-15172310230
2022-12-11 22:22:10 +08:00
committed by GitHub
parent 2291ffdece
commit 237e95c6dd
57 changed files with 229 additions and 124 deletions

View File

@ -0,0 +1,11 @@
[build]
target = "src/arch/x86_64/x86_64-unknown-none.json"
[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]
[target.'cfg(target_os = "none")']
runner = "bootimage runner"
[env]

2
user/libs/libc/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
Cargo.lock

18
user/libs/libc/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "libc"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["staticlib"]
# 运行时依赖项
[dependencies]
x86_64 = "0.14.10"
# 构建时依赖项
[build-dependencies]
bindgen = "0.61.0"

View File

@ -1,48 +1,7 @@
all: libc
CFLAGS += -I .
all:
$(MAKE) -C src all
libc_sub_dirs=math sys
ifeq ($(ARCH), __x86_64__)
libc_sub_dirs += sysdeps/x86_64
endif
libc: unistd.o fcntl.o malloc.o errno.o printf.o stdlib.o ctype.o string.o dirent.o time.o
@list='$(libc_sub_dirs)'; for subdir in $$list; do \
echo "make all in $$subdir";\
cd $$subdir;\
$(MAKE) all CFLAGS="$(CFLAGS) -I $(shell pwd)";\
cd ..;\
done
unistd.o: unistd.c
$(CC) $(CFLAGS) -c unistd.c -o unistd.o
fcntl.o: fcntl.c
$(CC) $(CFLAGS) -c fcntl.c -o fcntl.o
malloc.o: malloc.c
$(CC) $(CFLAGS) -c malloc.c -o malloc.o
errno.o: errno.c
$(CC) $(CFLAGS) -c errno.c -o errno.o
printf.o: printf.c
$(CC) $(CFLAGS) -c printf.c -o printf.o
stdlib.o: stdlib.c
$(CC) $(CFLAGS) -c stdlib.c -o stdlib.o
ctype.o: ctype.c
$(CC) $(CFLAGS) -c ctype.c -o ctype.o
string.o: string.c
$(CC) $(CFLAGS) -c string.c -o string.o
dirent.o: dirent.c
$(CC) $(CFLAGS) -c dirent.c -o dirent.o
time.o: time.c
$(CC) $(CFLAGS) -c time.c -o time.o
clean:
rm -f Cargo.lock
$(MAKE) -C src clean

View File

@ -0,0 +1,63 @@
GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel
GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
all: libc
CFLAGS += -I .
libc_sub_dirs=math sys
ifeq ($(ARCH), __x86_64__)
libc_sub_dirs += sysdeps/x86_64
endif
clean:
cargo clean
rm -rf $(GARBAGE)
@list='$(libc_sub_dirs)'; for subdir in $$list; do \
echo "Clean in dir: $$subdir";\
cd $$subdir && $(MAKE) clean;\
cd .. ;\
done
libc: unistd.o fcntl.o malloc.o errno.o printf.o stdlib.o ctype.o string.o dirent.o time.o libc_rust
@list='$(libc_sub_dirs)'; for subdir in $$list; do \
echo "make all in $$subdir";\
cd $$subdir;\
$(MAKE) all CFLAGS="$(CFLAGS) -I $(shell pwd)";\
cd ..;\
done
unistd.o: unistd.c
$(CC) $(CFLAGS) -c unistd.c -o unistd.o
fcntl.o: fcntl.c
$(CC) $(CFLAGS) -c fcntl.c -o fcntl.o
malloc.o: malloc.c
$(CC) $(CFLAGS) -c malloc.c -o malloc.o
errno.o: errno.c
$(CC) $(CFLAGS) -c errno.c -o errno.o
printf.o: printf.c
$(CC) $(CFLAGS) -c printf.c -o printf.o
stdlib.o: stdlib.c
$(CC) $(CFLAGS) -c stdlib.c -o stdlib.o
ctype.o: ctype.c
$(CC) $(CFLAGS) -c ctype.c -o ctype.o
string.o: string.c
$(CC) $(CFLAGS) -c string.c -o string.o
dirent.o: dirent.c
$(CC) $(CFLAGS) -c dirent.c -o dirent.o
time.o: time.c
$(CC) $(CFLAGS) -c time.c -o time.o
libc_rust:
rustup default nightly
cargo +nightly build --release --target ./x86_64-unknown-none.json

View File

@ -1,4 +1,4 @@
#include <libc/ctype.h>
#include <libc/src/ctype.h>
int isprint(int c)

View File

@ -1,10 +1,10 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
#pragma once
#include <libc/__libc__.h>
#include <libc/src/__libc__.h>
int isalnum(int c);

View File

@ -1,5 +1,5 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
/**

View File

@ -1,4 +1,4 @@
#include <libc/fcntl.h>
#include <libc/src/fcntl.h>
#include <libsystem/syscall.h>
/**

21
user/libs/libc/src/lib.rs Normal file
View File

@ -0,0 +1,21 @@
#![no_std] // <1>
#![no_main] // <1>
#![feature(core_intrinsics)] // <2>
#![feature(alloc_error_handler)]
#![feature(panic_info_message)]
#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn scanf() {
}

View File

@ -1,9 +1,9 @@
#include <libc/stdlib.h>
#include <libc/src/stdlib.h>
#include <libsystem/syscall.h>
#include <libc/stddef.h>
#include <libc/unistd.h>
#include <libc/errno.h>
#include <libc/stdio.h>
#include <libc/src/stddef.h>
#include <libc/src/unistd.h>
#include <libc/src/errno.h>
#include <libc/src/stdio.h>
#define PAGE_4K_SHIFT 12
#define PAGE_2M_SHIFT 21

View File

@ -1,7 +1,6 @@
#include <libc/math.h>
#include <libc/sys/types.h>
#include <libc/src/math.h>
#include <libc/src/sys/types.h>
#include "libm.h"
double fabs(double x)
{
union

View File

@ -1,5 +1,5 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
// ===== 描述long double 的数据比特结构
#if __LDBL_MANT_DIG__ == 53 && __LDBL_MAX_EXP__ == 1024

View File

@ -1,5 +1,5 @@
#include <libc/math.h>
#include <libc/stddef.h>
#include <libc/src/math.h>
#include <libc/src/stddef.h>
int64_t pow(int64_t x, int y)
{

View File

@ -1,9 +1,9 @@
#include "printf.h"
#include <libc/math.h>
#include <libc/stdio.h>
#include <libc/stdlib.h>
#include <libc/string.h>
#include <libc/src/math.h>
#include <libc/src/stdio.h>
#include <libc/src/stdlib.h>
#include <libc/src/string.h>
#include <libsystem/syscall.h>
static char *write_num(char *str, uint64_t num, int base, int field_width, int precision, int flags);

View File

@ -1,6 +1,6 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
#ifdef __cplusplus
#define NULL 0

View File

@ -1,6 +1,6 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
#include <stdarg.h>
// 字体颜色的宏定义

View File

@ -1,6 +1,6 @@
#include <libc/unistd.h>
#include <libc/stdlib.h>
#include <libc/ctype.h>
#include <libc/src/unistd.h>
#include <libc/src/stdlib.h>
#include <libc/src/ctype.h>
#include <libsystem/syscall.h>
int abs(int i)

View File

@ -1,5 +1,5 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
/**
* @brief

View File

@ -1,6 +1,6 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
void *memset(void *dst, unsigned char C, uint64_t size);
/**

View File

@ -1,5 +1,5 @@
#pragma once
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
/**
* @brief

View File

@ -1,6 +1,6 @@
#include <libc/stdio.h>
#include <libc/stdlib.h>
#include <libc/src/stdio.h>
#include <libc/src/stdlib.h>
extern int main(int, char **);

View File

@ -1,10 +1,10 @@
#include <libc/unistd.h>
#include <libc/src/unistd.h>
#include <libsystem/syscall.h>
#include <libc/errno.h>
#include <libc/stdio.h>
#include <libc/stddef.h>
#include <libc/string.h>
#include <libc/fcntl.h>
#include <libc/src/errno.h>
#include <libc/src/stdio.h>
#include <libc/src/stddef.h>
#include <libc/src/string.h>
#include <libc/src/fcntl.h>
/**
* @brief

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <libc/sys/types.h>
#include <libc/src/sys/types.h>
/**
* @brief

View File

@ -0,0 +1,15 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"executables": true,
"features": "-mmx,-sse,+soft-float",
"disable-redzone": true,
"panic-strategy": "abort"
}