mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
调整user下libs的libc目录结构 (#103)
* 调整user下libs的libc目录结构 * 修正.gitignore文件的问题 * 修复无法编译的问题 Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -10,3 +10,10 @@ $(user_libs_sub_dirs): ECHO
|
||||
$(MAKE) -C $@ all CFLAGS="$(CFLAGS) -I $(shell pwd)"
|
||||
|
||||
all: $(user_libs_sub_dirs)
|
||||
|
||||
clean:
|
||||
@list='$(user_libs_sub_dirs)'; for subdir in $$list; do \
|
||||
echo "Clean in dir: $$subdir";\
|
||||
cd $$subdir && $(MAKE) clean;\
|
||||
cd .. ;\
|
||||
done
|
@ -1,5 +1,5 @@
|
||||
#include "keyboard.h"
|
||||
#include <libc/unistd.h>
|
||||
#include <libc/src/unistd.h>
|
||||
// 功能键标志变量
|
||||
static bool shift_l = 0, shift_r = 0, ctrl_l = 0, ctrl_r = 0, alt_l = 0, alt_r = 0;
|
||||
static bool gui_l = 0, gui_r = 0, apps = 0, insert = 0, home = 0, pgup = 0, del = 0, end = 0, pgdn = 0, arrow_u = 0, arrow_l = 0, arrow_d = 0, arrow_r = 0;
|
||||
|
11
user/libs/libc/.cargo/config.toml
Normal file
11
user/libs/libc/.cargo/config.toml
Normal 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
2
user/libs/libc/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target/
|
||||
Cargo.lock
|
18
user/libs/libc/Cargo.toml
Normal file
18
user/libs/libc/Cargo.toml
Normal 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"
|
||||
|
||||
|
@ -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
|
63
user/libs/libc/src/Makefile
Normal file
63
user/libs/libc/src/Makefile
Normal 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
|
@ -1,4 +1,4 @@
|
||||
#include <libc/ctype.h>
|
||||
#include <libc/src/ctype.h>
|
||||
|
||||
|
||||
int isprint(int c)
|
@ -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);
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
|
||||
|
||||
/**
|
@ -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
21
user/libs/libc/src/lib.rs
Normal 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() {
|
||||
|
||||
}
|
@ -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
|
@ -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
|
@ -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
|
@ -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)
|
||||
{
|
@ -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);
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// 字体颜色的宏定义
|
@ -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)
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
|
||||
/**
|
||||
* @brief 获取一块堆内存
|
@ -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);
|
||||
/**
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
|
||||
/**
|
||||
* @brief 系统内存信息结构体(单位:字节)
|
@ -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 **);
|
||||
|
@ -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 关闭文件接口
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <libc/sys/types.h>
|
||||
#include <libc/src/sys/types.h>
|
||||
|
||||
/**
|
||||
* @brief 关闭文件接口
|
15
user/libs/libc/src/x86_64-unknown-none.json
Normal file
15
user/libs/libc/src/x86_64-unknown-none.json
Normal 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"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "syscall.h"
|
||||
#include <libc/stdio.h>
|
||||
#include <libc/errno.h>
|
||||
#include <libc/src/stdio.h>
|
||||
#include <libc/src/errno.h>
|
||||
long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7)
|
||||
{
|
||||
uint64_t __err_code;
|
||||
|
Reference in New Issue
Block a user