Procházet zdrojové kódy

evx: prepare to support a real getfreepage

rain před 4 roky
rodič
revize
6326ffb538

+ 3 - 0
arch/x86/include/arch/mm.h

@@ -64,6 +64,9 @@ static inline u64 HIGH_AND_LOW(u32 high, u32 low, int bits) {
 #define invalidate() 			__asm__ volatile ("movl %%cr3, %%eax;movl %%eax, %%cr3;" ::: "ax")
 #endif
 
+#define real_addr(a) 			((a) & ~KERNEL_OFFSET)
+#define page_descr(addr) 		(kmem_pages + PAGE_NR(real_addr(addr) & ~PAGE_MASK))
+
 #endif
 #endif
 

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

@@ -40,5 +40,8 @@ typedef __uint32_t __archptr_t;
 #define PTRSHIFT 	2lu
 
 
+#define KERNEL_OFFSET 	0xc0000000lu
+
+
 #endif
 

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

@@ -39,6 +39,8 @@ typedef __uint64_t __archptr_t;
 #define PTRSIZE 	8lu
 #define PTRSHIFT 	3lu
 
+#define KERNEL_OFFSET 	0xffff800000000000lu
+
 
 #endif
 

+ 5 - 1
arch/x86/kernel/Makefile

@@ -4,7 +4,11 @@
 # must be the first, as we call it first. 
 obj-i = arch_mm.c 
 
-target:
+%.S.o: %.S 
+	@$(AS) $*.S -o $*.o -m$(BITS) 
+	@echo "AS               $*.S"
+
+target: $(obj-i)
 
 ifeq ($(D), )
 	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 

+ 14 - 5
arch/x86/kernel/arch_mm.c

@@ -1,4 +1,4 @@
-/* arch/x86/kernel/archx86_mm32.c  
+/* arch/x86/kernel/arch_mm.c  
  * 
  * This file is part of evx. 
  * 
@@ -34,6 +34,8 @@
 static int __init init_mapping_32m(void);
 __archptr_t freeptr;
 
+void *kernel_end;
+
 
 /* the most important work is: get total size of ram, 
  * and initiallize page structures */
@@ -45,13 +47,16 @@ int arch_mm_init(void) {
 
 	int 			i;
 
-	__archptr_t		addr;
+	__archptr_t		addr, total_pages;
+
+	total_pages = 0;
 
 	init_mapping_32m();
+	kernel_end = (void *) (KERNEL_OFFSET | (__archptr_t) &_end);
 
 	/* put them there, after that, are the page structures. */
-	z = (struct zone *) &_end;
-	p = (struct page *) (z + 2);
+	z = kmem_zones;
+	p = kmem_pages;
 
 	memset(z, 0, sizeof(struct zone) * 2);
 
@@ -76,10 +81,12 @@ int arch_mm_init(void) {
 		npages = PAGE_NR(HIGH_AND_LOW(e->lenh, e->lenl, 32));
 		z[e->type].total_pages += npages;
 
+		/* any page */
+		total_pages += npages;
+
 		/* now initiallize page structures */
 
 		for (i = 0; i < npages; i++) {
-			p->pnr = PAGE_NR(addr);
 			p->count = 0;
 			p->next = p + 1;
 
@@ -87,6 +94,8 @@ int arch_mm_init(void) {
 		}
 	}
 
+	first_usable_ram = page_descr(PAGE_ALIGN((__archptr_t) (kmem_pages + total_pages)));
+
 	return 0;
 }
 

+ 1 - 1
arch/x86/vmevx32.lds

@@ -3,7 +3,7 @@ OUTPUT_ARCH(i386)
 ENTRY(_start)
 
 SECTIONS {
-	. = 0xc0000000 + 0x100000;
+	. = 0xc0100000;
 
 	.text : {
 		_text = .;

+ 1 - 1
arch/x86/vmevx64.lds

@@ -3,7 +3,7 @@ OUTPUT_ARCH(i386:x86-64)
 ENTRY(_start)
 
 SECTIONS {
-	. = 0xffff800000000000 + 0x100000;
+	. = 0xffff800000100000;
 
 	.text : {
 		_text = .;

+ 4 - 1
include/kernel/init.h

@@ -39,7 +39,10 @@
 extern void *_init_call_arch, *_init_call_kernel, *_init_call_modules;
 extern void *_einit_call_arch, *_einit_call_kernel, *_einit_call_modules;
 
-extern void *_end;
+
+/* never use this directly. use kernel_end instead of it */
+extern int _end __attribute__ ((__section__(".end")));
+extern void *kernel_end;
 
 
 #define arch_init(fn) 	\

+ 7 - 6
include/kernel/mm.h

@@ -36,14 +36,10 @@
  * can't implement that without this, because we need more memory when 
  * inserting. 
  *
- *
  * we should initiallize this as late as we can, after maps okay. 
  * */
 
 struct page {
-	/* number of this page */
-	__archptr_t 	pnr;
-
 	/* for cow, the reference count. we won't free if count-- */
 	__uint32_t 	count;
 
@@ -66,8 +62,13 @@ struct zone {
 	struct page 	*pages;
 };
 
-#define kmem_zones 	((struct zone *) &_end)
-#define kmem_pages 	((struct page *) (kmem_zones[2]))
+
+/* sets by arch_mm_init */
+
+extern struct page 	*first_usable_ram;
+
+#define kmem_zones 	((struct zone *) kernel_end)
+#define kmem_pages 	((struct page *) (kmem_zones + 2))
 
 
 /* they're really early but fast. actually, most free() did nothing

+ 5 - 1
init/main.c

@@ -33,7 +33,11 @@ static int do_init_calls(void);
 
 
 int __init init(void) {
-	return do_init_calls();
+	do_init_calls();
+
+	printk("%d\n", first_usable_ram - kmem_pages);
+
+	return 0;
 }
 
 

+ 1 - 1
kernel/Makefile

@@ -3,7 +3,7 @@
 
 obj-i = mm.c vsprintf.c tty.c 
 
-target:
+target: $(obj-i)
 
 ifeq ($(D), )
 	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 

+ 3 - 0
kernel/mm.c

@@ -28,6 +28,9 @@
 
 
 
+struct page *first_usable_ram;
+
+
 int mm_init(void) {
 	return 0;
 }

+ 8 - 6
kernel/vsprintf.c

@@ -71,19 +71,21 @@ static const char digits[] = "0123456789abcdef";
 #define UNSIGNED 	2
 
 
-static int number(char *buf, long nr, int base, int flags, int width) {
+static int number(char *buf, long x, int base, int flags, int width) {
 	int neg = 0, i = 0, j;
 	char t[PTRSIZE * 2];
+	unsigned long nr;
 
 	memset(t, 0, PTRSIZE * 2);
 
-	if (nr < 0) {
-		nr = -nr;
-
-		if (!(flags & UNSIGNED)) 
-			neg = 1;
+	if (!(flags & UNSIGNED) && nr < 0) {
+		nr = -x;
+		neg = 1;
 	}
 
+	else 
+		nr = x;
+
 	if (!nr) 
 		t[i++] = '0';
 

+ 1 - 1
modules/Makefile

@@ -3,7 +3,7 @@
 
 obj-i = console.c serial.c 
 
-target:
+target: $(obj-i)
 
 ifeq ($(D), )
 	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 

+ 1 - 0
scripts/do_build.sh

@@ -7,5 +7,6 @@ echo "CC                $1"
 # extended CC flags by arch. 
 
 cd $3
+
 $2 $4 $5 -c $1 -o $1.o