fslongjin 2 years ago
parent
commit
edb21695ae

+ 1 - 1
.vscode/c_cpp_properties.json

@@ -6,7 +6,7 @@
                 "${workspaceFolder}/**"
             ],
             "defines": [
-                "x86_64",
+                "__x86_64__",
                 "DEBUG"
             ],
             "compilerPath": "/usr/bin/gcc",

+ 2 - 1
.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": ""

+ 1 - 1
Makefile

@@ -3,7 +3,7 @@ SUBDIRS = kernel user
 
 
 
-export ARCH=x86_64
+export ARCH=__x86_64__
 export ROOT_PATH=$(shell pwd)
 
 export DEBUG=DEBUG

+ 1 - 1
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

+ 12 - 0
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

+ 3 - 1
kernel/common/glib.h

@@ -8,8 +8,10 @@
 //引入对bool类型的支持
 #include <stdbool.h>
 #include <stdint.h>
+#include <common/miniLibc/stddef.h>
+#include <arch/arch.h>
+
 
-#define NULL 0
 
 #define sti() __asm__ __volatile__("sti\n\t" :: \
                                        : "memory") //开启外部中断

+ 7 - 0
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.

+ 84 - 0
kernel/common/miniLibc/sys/types.h

@@ -0,0 +1,84 @@
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+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;

+ 6 - 5
kernel/smp/ipi.h

@@ -1,6 +1,7 @@
 #pragma once
 
-#ifdef x86_64
+#include <arch/arch.h>
+#if ARCH(I386) || ARCH(X86_64)
 #include <arch/x86_64/x86_64_ipi.h>
 #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);
+                          void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs),
+                          uint64_t param, hardware_intr_controller *controller, char *irq_name);