Rev 1618 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | /* This file contains the DOS memory allocator */ |
||
23 | |||
24 | #include <ll/i386/mem.h> |
||
25 | #include <ll/i386/x-bios.h> |
||
26 | #include <ll/i386/x-dosmem.h> |
||
27 | #include <ll/i386/error.h> |
||
28 | |||
40 | pj | 29 | FILE(X-Dos-Memory); |
2 | pj | 30 | |
31 | /* |
||
32 | We do not use the standard K&R pointer based memory allocator! |
||
33 | This is because we cannot do pointer tricks easily with the GCC |
||
34 | which only handles explicitely 32 bit non segmented address space. |
||
35 | So we cannot use far pointers, and we cannot chain buckets of memory |
||
36 | which are located in low memory area, beyond the accessibility |
||
37 | of the ELF address space. |
||
38 | A static allocation is so preferred; this should not give trouble |
||
39 | since DOS memory is only used for reflection related purposes |
||
40 | */ |
||
41 | |||
40 | pj | 42 | #define MAX_PARTITION 50 /* Max available partition */ |
2 | pj | 43 | |
44 | static struct { |
||
40 | pj | 45 | BYTE used; |
46 | LIN_ADDR addr; |
||
47 | DWORD size; |
||
2 | pj | 48 | } mem_table[MAX_PARTITION]; |
49 | |||
50 | static int inited = 0; |
||
51 | |||
52 | void DOS_dump_mem(void) |
||
53 | { |
||
54 | register int i; |
||
55 | for (i = 0; i < MAX_PARTITION; i++) { |
||
40 | pj | 56 | if (mem_table[i].used) message("(%d) Addr : %p Size : %lu/%lx\n", |
57 | i, mem_table[i].addr, |
||
58 | mem_table[i].size, mem_table[i].size); |
||
2 | pj | 59 | } |
60 | } |
||
61 | |||
40 | pj | 62 | __attribute__ ((weak)) void DOS_mem_init(void) |
2 | pj | 63 | { |
64 | register int i; |
||
65 | |||
66 | if (inited == 0) { |
||
40 | pj | 67 | mem_table[0].used = TRUE; |
68 | X_meminfo(NULL,NULL,&(mem_table[0].addr),&(mem_table[0].size)); |
||
69 | for (i = 1; i < MAX_PARTITION; i++) mem_table[i].used = FALSE; |
||
2 | pj | 70 | } else { |
40 | pj | 71 | inited = 1; |
2 | pj | 72 | } |
73 | } |
||
74 | |||
113 | giacomo | 75 | /*__attribute__ ((weak)) LIN_ADDR DOS_alloc(DWORD s) |
2 | pj | 76 | { |
77 | LIN_ADDR p = 0; |
||
78 | int i = 0; |
||
79 | |||
80 | while (i < MAX_PARTITION && p == NULL) { |
||
81 | if (mem_table[i].used && (mem_table[i].size >= s)) |
||
40 | pj | 82 | p = mem_table[i].addr; |
83 | else i++; |
||
2 | pj | 84 | } |
85 | if (p != 0) { |
||
86 | if (mem_table[i].size > s) { |
||
87 | mem_table[i].size -= s; |
||
88 | mem_table[i].addr += s; |
||
40 | pj | 89 | } |
90 | else mem_table[i].used = FALSE; |
||
2 | pj | 91 | } |
40 | pj | 92 | return(p); |
2 | pj | 93 | } |
94 | |||
40 | pj | 95 | __attribute__ ((weak)) int DOS_free(LIN_ADDR p,DWORD s) |
2 | pj | 96 | { |
97 | register int i = 1; |
||
98 | unsigned i1 = 0, i2 = 0; |
||
99 | |||
40 | pj | 100 | while (i < MAX_PARTITION && ((i1 == 0) || (i2 == 0)) ) { |
2 | pj | 101 | if (mem_table[i].used) { |
40 | pj | 102 | if (mem_table[i].addr + mem_table[i].size == p) i1 = i; |
103 | if (mem_table[i].addr == p + s) i2 = i; |
||
2 | pj | 104 | } |
105 | i++; |
||
106 | } |
||
107 | if (i1 != 0 && i2 != 0) { |
||
108 | mem_table[i1].size += mem_table[i2].size + s; |
||
109 | mem_table[i2].used = FALSE; |
||
40 | pj | 110 | } |
111 | else if (i1 == 0 && i2 != 0) { |
||
2 | pj | 112 | mem_table[i2].addr = p; |
113 | mem_table[i2].size += s; |
||
40 | pj | 114 | } |
115 | else if (i1 != 0 && i2 == 0) mem_table[i1].size += s; |
||
2 | pj | 116 | else { |
117 | i = 0; |
||
40 | pj | 118 | while (i < MAX_PARTITION && (mem_table[i].used == TRUE)) i++; |
119 | if (i == MAX_PARTITION) return(FALSE); |
||
2 | pj | 120 | mem_table[i].addr = p; |
121 | mem_table[i].size = s; |
||
122 | mem_table[i].used = TRUE; |
||
123 | } |
||
40 | pj | 124 | return(TRUE); |
113 | giacomo | 125 | }*/ |