#define RNGEND(rng) ((struct memrange __far*)((char __far*)(rng) + (rng)->len))
static struct memrange __far *pool;
-static unsigned int freemem, num_alloc;
+static unsigned long freemem;
+static unsigned int num_alloc;
int kmalloc_init(int numblk)
}
}
}
+
+void dbg_print_kmalloc_pool(void)
+{
+ struct memrange __far *m;
+
+ m = pool;
+ while(m) {
+ printf("[%x:%x/%x] ", FP_SEG(m), FP_OFFS(m), m->len);
+ m = m->next;
+ }
+ putchar('\n');
+}
+
+void dbg_print_kmalloc_stats(void)
+{
+ printf("free memory: %lx, num alloc: %x\n", freemem, num_alloc);
+}
void __far *kmalloc(unsigned long sz);
void kfree(void __far *ptr);
+void dbg_print_kmalloc_pool(void);
+void dbg_print_kmalloc_stats(void);
+
#endif /* MALLOC_H_ */
--- /dev/null
+#include <stdlib.h>
+#include <inttypes.h>
+
+unsigned long st = 1;
+
+int rand(void)
+{
+ st = st * 1103515245 + 12345;
+ return (unsigned int)(st >> 16) & 0xffff;
+}
+
+void srand(unsigned int seed)
+{
+ st = seed;
+}
+
#ifndef STDLIB_H_
#define STDLIB_H_
+#define RAND_MAX 32767
+
#define abs(x) __builtin_abs(x)
int atoi(const char *str);
long atol(const char *str);
long strtol(const char *str, char **endp, int base);
+int rand(void);
+void srand(unsigned int seed);
+
#endif /* STDLIB_H_ */
#include "config.h"
#include <stdio.h>
+#include <stdlib.h>
#include <malloc.h>
#include "intr.h"
#include "vid.h"
void kmain(void)
{
+ int i;
+
vid_init();
ser_init();
con_init();
printf("eightysix kernel %s\n", VERSTR);
- void __far *ptr = kmalloc(2000);
- printf("allocated 2k at: %x:%x\n", FP_SEG(ptr), FP_OFFS(ptr));
- kfree(ptr);
- printf("freed\n");
- ptr = kmalloc(256);
- printf("allocated 256b, got: %x:%x\n", FP_SEG(ptr), FP_OFFS(ptr));
- ptr = kmalloc(512);
- printf("allocated 512 more at: %x:%x\n", FP_SEG(ptr), FP_OFFS(ptr));
+ printf("kmalloc free pool\n");
+ dbg_print_kmalloc_pool();
+ printf("kmalloc stats\n");
+ dbg_print_kmalloc_stats();
+
+ void __far *ptr[32];
+
+ for(i=0; i<32; i++) {
+ ptr[i] = kmalloc(256);
+ }
+
+ for(i=0; i<20; i++) {
+ int idx = rand() & 0x1f;
+ if(ptr[idx]) {
+ kfree(ptr[idx]);
+ ptr[idx] = 0;
+ }
+ }
+
+ printf("kmalloc free pool\n");
+ dbg_print_kmalloc_pool();
+ printf("kmalloc stats\n");
+ dbg_print_kmalloc_stats();
init_intr();
}