diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 146479bf..2de76a96 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,7 @@ "${workspaceFolder}/**" ], "defines": [ - "x86_64", + "__x86_64__", "DEBUG" ], "compilerPath": "/usr/bin/gcc", diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ff226d2..8ccf25d5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -94,7 +94,8 @@ "fcntl.h": "c", "types.h": "c", "string.h": "c", - "math.h": "c" + "math.h": "c", + "ipi.h": "c" }, "C_Cpp.errorSquiggles": "Enabled", "esbonio.sphinx.confDir": "" diff --git a/Makefile b/Makefile index c56da388..8e0085de 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SUBDIRS = kernel user -export ARCH=x86_64 +export ARCH=__x86_64__ export ROOT_PATH=$(shell pwd) export DEBUG=DEBUG diff --git a/kernel/Makefile b/kernel/Makefile index d6b80e2c..dbeb34c9 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -89,7 +89,7 @@ VFS.o: filesystem/VFS/VFS.c gcc $(CFLAGS) -c filesystem/VFS/VFS.c -o filesystem/VFS/VFS.o # IPI的代码 -ifeq ($(ARCH), x86_64) +ifeq ($(ARCH), __x86_64__) OBJ_LIST += ipi.o LD_LIST += arch/x86_64/x86_64_ipi.o ipi.o: arch/x86_64/x86_64_ipi.c diff --git a/kernel/arch/arch.h b/kernel/arch/arch.h new file mode 100644 index 00000000..320ef366 --- /dev/null +++ b/kernel/arch/arch.h @@ -0,0 +1,12 @@ +#pragma once + +#define ARCH(arch) (defined(AK_ARCH_##arch) && AK_ARCH_##arch) + + +#ifdef __i386__ +# define AK_ARCH_I386 1 +#endif + +#ifdef __x86_64__ +# define AK_ARCH_X86_64 1 +#endif \ No newline at end of file diff --git a/kernel/common/glib.h b/kernel/common/glib.h index 53e8522e..4334a527 100644 --- a/kernel/common/glib.h +++ b/kernel/common/glib.h @@ -8,8 +8,10 @@ //引入对bool类型的支持 #include #include +#include +#include + -#define NULL 0 #define sti() __asm__ __volatile__("sti\n\t" :: \ : "memory") //开启外部中断 diff --git a/kernel/common/miniLibc/stddef.h b/kernel/common/miniLibc/stddef.h new file mode 100644 index 00000000..247c592a --- /dev/null +++ b/kernel/common/miniLibc/stddef.h @@ -0,0 +1,7 @@ +#pragma once + +#include "./sys/types.h" + +#define NULL 0 + +typedef __PTRDIFF_TYPE__ ptrdiff_t; // Signed integer type of the result of subtracting two pointers. diff --git a/kernel/common/miniLibc/sys/types.h b/kernel/common/miniLibc/sys/types.h new file mode 100644 index 00000000..5efae368 --- /dev/null +++ b/kernel/common/miniLibc/sys/types.h @@ -0,0 +1,84 @@ +#pragma once + +#include +#include + +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef uint32_t uid_t; +typedef uint32_t gid_t; +typedef long long ssize_t; + +typedef int __pid_t; +#define pid_t __pid_t +typedef __SIZE_TYPE__ size_t; + +typedef char *caddr_t; + +typedef int id_t; + +typedef uint64_t ino_t; +typedef int64_t off_t; + +typedef uint32_t blkcnt_t; +typedef uint32_t blksize_t; +typedef uint32_t dev_t; +typedef uint16_t mode_t; +typedef uint32_t nlink_t; + +typedef int64_t time_t; +typedef uint32_t useconds_t; +typedef int32_t suseconds_t; +typedef uint32_t clock_t; + +typedef uint64_t fsblkcnt_t; +typedef uint64_t fsfilcnt_t; + +#define __socklen_t_defined +#define __socklen_t uint32_t +typedef __socklen_t socklen_t; + +struct utimbuf +{ + time_t actime; + time_t modtime; +}; + +typedef int pthread_t; +typedef int pthread_key_t; +typedef uint32_t pthread_once_t; + +typedef struct __pthread_mutex_t +{ + uint32_t lock; + pthread_t owner; + int level; + int type; +} pthread_mutex_t; + +typedef void *pthread_attr_t; +typedef struct __pthread_mutexattr_t +{ + int type; +} pthread_mutexattr_t; + +typedef struct __pthread_cond_t +{ + pthread_mutex_t *mutex; + uint32_t value; + int clockid; // clockid_t +} pthread_cond_t; + +typedef uint64_t pthread_rwlock_t; +typedef void *pthread_rwlockattr_t; +typedef struct __pthread_spinlock_t +{ + int m_lock; +} pthread_spinlock_t; +typedef struct __pthread_condattr_t +{ + int clockid; // clockid_t +} pthread_condattr_t; \ No newline at end of file diff --git a/kernel/smp/ipi.h b/kernel/smp/ipi.h index 5c3b2eb1..df2e4ac1 100644 --- a/kernel/smp/ipi.h +++ b/kernel/smp/ipi.h @@ -1,6 +1,7 @@ #pragma once -#ifdef x86_64 +#include +#if ARCH(I386) || ARCH(X86_64) #include #else #error "error type of arch!" @@ -24,15 +25,15 @@ extern void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t l /** * @brief ipi中断处理注册函数 - * + * * @param irq_num 中断向量号 * @param arg 参数 * @param handler 处理函数 * @param param 参数 - * @param controller 当前为NULL + * @param controller 当前为NULL * @param irq_name ipi中断名 * @return int 成功:0 */ extern int ipi_regiserIPI(uint64_t irq_num, void *arg, - void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs), - uint64_t param, hardware_intr_controller *controller, char *irq_name); \ No newline at end of file + void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs), + uint64_t param, hardware_intr_controller *controller, char *irq_name); \ No newline at end of file