Quellcode durchsuchen

evx: fix bug of head.S and main.c: head.S always executes first

rain vor 5 Jahren
Ursprung
Commit
19066743e2

+ 4 - 2
Makefile

@@ -23,7 +23,7 @@ KERNEL_VERSION 		= $(KERNEL_MAJOR).$(KERNEL_PATCH_LEVEL).$(KERNEL_SUBVER)\
 			$(KERNEL_COMPILE_TIME) $(KERNEL_COMPILE_BY) on $(ARCH)
 
 MAKEFLAGS		+= --no-print-directory 
-CFLAGS 			+= -I$(PWD)/include/ -g -nostdinc -nostdlib 
+CFLAGS 			+= -I$(PWD)/include/ -g -nostdinc -nostdlib -Wall -Werror 
 ARCHCFLAGS 		+= $(shell cat $(ARCHDIR)/.archcflags)
 
 SHELl 			= $(shell echo $$SHELL)
@@ -49,10 +49,11 @@ ifeq 	($D,)
 
 
 # that inside object, and we don't support other objects at this time :-)
+
+obj-i 			+= $(ARCHDIR)/ 
 obj-i 			+= $(PWD)/kernel/ 
 obj-i 			+= $(PWD)/init/ 
 
-obj-i 			+= $(ARCHDIR)/ 
 
 
 _all:
@@ -60,6 +61,7 @@ _all:
 	@for d in $(obj-i); do 				\
 		$(MAKE) $(MAKEFLAGS) -C $$d D=$$d;	\
 	done
+
 	@$(MAKE) -C $(ARCHDIR)/ vmevx.o
 	@$(MAKE) -C $(ARCHDIR)/ boot 
 

+ 1 - 1
arch/x86/.archcflags

@@ -1 +1 @@
--m64
+-m64 -I/root/evx/arch/x86/include -I/root/evx/arch/x86/include64 

+ 7 - 1
arch/x86/Makefile

@@ -13,7 +13,12 @@ ifeq ($(D), )
 	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 
 	@exit 1
 endif
-	@echo "-m$(BITS)" > .archcflags
+	@echo -n "-m$(BITS) " > .archcflags
+	@echo -n "-I`pwd`/include " >> .archcflags
+	@echo -n "-I`pwd`/include$(BITS) " >> .archcflags
+
+# must be the first 
+	@echo "`pwd`/init/head$(BITS).S.o" > $(PWD)/.objlist 
 
 # $(PWD) is the / directory of kernel, e.g. /root/evx/
 	@$(MAKE) -C $(PWD) D=$(shell pwd) obj-i="$(obj-i)"
@@ -35,3 +40,4 @@ boot: 	vmevx.bin
 	@$(MAKE) -C boot/ clean
 	@$(MAKE) -C init/ clean
 
+

+ 41 - 0
arch/x86/include32/arch/archinfo.h

@@ -0,0 +1,41 @@
+/* arch/x86/include32/arch/archinfo.h 
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __ARCH_ARCHINFO_H
+#define __ARCH_ARCHINFO_H
+
+
+#define ARCH_NAME 	"i386"
+#define ARCH_BITS 	32lu
+
+
+typedef __uint32_t __archptr_t;
+
+#define PAGE_SIZE 	4096lu
+#define PAGE_MASK 	4095lu
+#define PAGE_ALIGN(a) 	(((a) + PAGE_MASK) & (~PAGE_MASK))
+
+#define PTRSIZE 	4lu
+#define PTRSHIFT 	2lu
+
+
+#endif
+

+ 41 - 0
arch/x86/include64/arch/archinfo.h

@@ -0,0 +1,41 @@
+/* arch/x86/include64/arch/archinfo.h 
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __ARCH_ARCHINFO_H
+#define __ARCH_ARCHINFO_H
+
+
+#define ARCH_NAME 	"x86_64"
+#define ARCH_BITS 	64lu
+
+
+typedef __uint64_t __archptr_t;
+
+#define PAGE_SIZE 	4096lu
+#define PAGE_MASK 	4095lu
+#define PAGE_ALIGN(a) 	(((a) + PAGE_MASK) & ~(PAGE_MASK))
+
+#define PTRSIZE 	8lu
+#define PTRSHIFT 	3lu
+
+
+#endif
+

+ 0 - 1
arch/x86/init/Makefile

@@ -1,7 +1,6 @@
 obj-s = head$(BITS).S.o 
 
 target: $(obj-s)
-	@echo `pwd`/$(obj-s) >> $(PWD)/.objlist 
 
 %.S.o: %.S
 	@$(CPP) $*.S | $(AS) --$(BITS) -o $*.S.o 

+ 55 - 0
init/main.c

@@ -22,12 +22,67 @@
 #include <kernel/init.h>
 #include <kernel/module.h>
 
+#include <arch/archinfo.h>
+
 #include <sys/types.h>
 
 
+int do_init_calls(void);
+
 
 
 int __init init(void) {
+	return do_init_calls();
+}
+
+
+static void *init_call_levels[] = {
+	&_init_call_arch, &_einit_call_arch, 
+	&_init_call_kernel, &_einit_call_kernel, 
+	&_init_call_modules, &_einit_call_modules
+};
+
+
+
+
+/*
+ * call hooks in those sections those defined with init_call_levels. 
+ *
+ * that when you use a module_init() macro, you add a new entry into 
+ * that section. when bootstrap, we call them with no argument. if one 
+ * of them returns a non-zero, kernel will halt and do nothing. 
+ * */
+
+typedef int (* __initcall_t) (void);
+
+
+int do_init_calls(void) {
+	int error;
+	int i;
+
+	__archptr_t *start, *end;
+	__archptr_t fn, *initcalls;
+
+	
+	for (i = 0; i < ARRAYSIZE(init_call_levels); i++) {
+		start = init_call_levels[++i];
+		end = init_call_levels[++i];
+
+		int ncalls = (end - start) >> PTRSHIFT;
+
+
+		for (initcalls = start; ncalls; initcalls++, ncalls--) {
+			fn = *initcalls;
+
+			if (!fn) 
+				break;
+
+			if ((error = ((__initcall_t) fn)())) 
+				return error;
+		}
+	}
+
 	return 0;
 }
 
+