|
@@ -1,8 +1,6 @@
|
1
|
|
-#include "limits.h"
|
2
|
1
|
#include "io.h"
|
3
|
|
-#include "memsizes.h"
|
4
|
|
-#include "init.h"
|
5
|
|
-#include "buffer.h"
|
|
2
|
+#include "heap.h"
|
|
3
|
+#include "load_buffer.h"
|
6
|
4
|
|
7
|
5
|
/*
|
8
|
6
|
* Initialise a buffer in an unused portion of memory, to be used for
|
|
@@ -10,55 +8,58 @@
|
10
|
8
|
*
|
11
|
9
|
*/
|
12
|
10
|
|
13
|
|
-/* Under KEEP_IT_REAL, always use 07c0:0000 as the buffer. Otherwise,
|
14
|
|
- * use a reset_fn that finds the largest available block of RAM.
|
15
|
|
- */
|
16
|
|
-struct buffer load_buffer = {
|
17
|
|
- .start = 0x7c00,
|
18
|
|
- .end = 0xa0000,
|
19
|
|
-};
|
|
11
|
+#ifdef KEEP_IT_REAL
|
20
|
12
|
|
21
|
|
-#ifndef KEEP_IT_REAL
|
|
13
|
+/*
|
|
14
|
+ * Under KEEP_IT_REAL, always use 07c0:0000 as the load buffer.
|
|
15
|
+ *
|
|
16
|
+ */
|
22
|
17
|
|
23
|
|
-extern char _text[];
|
|
18
|
+int init_load_buffer ( struct buffer *buffer ) {
|
|
19
|
+ buffer->start = 0x7c00;
|
|
20
|
+ buffer->end = 0xa0000;
|
|
21
|
+ init_buffer ( buffer );
|
|
22
|
+ return 1;
|
|
23
|
+}
|
24
|
24
|
|
25
|
|
-static void init_load_buffer ( void ) {
|
26
|
|
- unsigned int i;
|
27
|
|
- unsigned long size = 0;
|
|
25
|
+void trim_load_buffer ( struct buffer *buffer ) {
|
|
26
|
+ /* Nothing to do */
|
|
27
|
+}
|
28
|
28
|
|
29
|
|
- load_buffer.start = 0;
|
30
|
|
- load_buffer.end = 0;
|
|
29
|
+void done_load_buffer ( struct buffer *buffer ) {
|
|
30
|
+ /* Nothing to do */
|
|
31
|
+}
|
31
|
32
|
|
32
|
|
- /* Find the largest usable segment in memory */
|
33
|
|
- for ( i = 0 ; i < meminfo.map_count ; i++ ) {
|
34
|
|
- unsigned long r_start, r_end;
|
|
33
|
+#else /* KEEP_IT_REAL */
|
35
|
34
|
|
36
|
|
- if ( meminfo.map[i].type != E820_RAM )
|
37
|
|
- continue;
|
|
35
|
+/*
|
|
36
|
+ * Without KEEP_IT_REAL, use all remaining heap space as the load buffer.
|
|
37
|
+ *
|
|
38
|
+ */
|
|
39
|
+int init_load_buffer ( struct buffer *buffer ) {
|
|
40
|
+ void *data;
|
|
41
|
+ size_t size;
|
|
42
|
+
|
|
43
|
+ data = emalloc_all ( &size );
|
|
44
|
+ if ( ! data )
|
|
45
|
+ return 0;
|
38
|
46
|
|
39
|
|
- if ( meminfo.map[i].addr + meminfo.map[i].size > ULONG_MAX )
|
40
|
|
- continue;
|
|
47
|
+ buffer->start = virt_to_phys ( data );
|
|
48
|
+ buffer->end = buffer->start + size;
|
|
49
|
+ init_buffer ( buffer );
|
|
50
|
+ return 1;
|
|
51
|
+}
|
41
|
52
|
|
42
|
|
- r_start = meminfo.map[i].addr;
|
43
|
|
- r_end = meminfo.map[i].size;
|
|
53
|
+void trim_load_buffer ( struct buffer *buffer ) {
|
|
54
|
+ void *new_start;
|
44
|
55
|
|
45
|
|
- /* Avoid overlap with Etherboot. Etherboot will be
|
46
|
|
- * located towards the top of a segment, so we need
|
47
|
|
- * only consider one-sided truncation.
|
48
|
|
- */
|
49
|
|
- if ( ( r_start <= virt_to_phys ( _text ) ) &&
|
50
|
|
- ( virt_to_phys ( _text ) < r_end ) ) {
|
51
|
|
- r_end = virt_to_phys ( _text );
|
52
|
|
- }
|
|
56
|
+ /* Shrink buffer */
|
|
57
|
+ new_start = erealloc ( phys_to_virt ( buffer->start ), buffer->fill );
|
|
58
|
+ buffer->start = virt_to_phys ( new_start );
|
|
59
|
+}
|
53
|
60
|
|
54
|
|
- if ( r_end - r_start > size ) {
|
55
|
|
- size = r_end - r_start;
|
56
|
|
- load_buffer.start = r_start;
|
57
|
|
- load_buffer.end = r_end;
|
58
|
|
- }
|
59
|
|
- }
|
|
61
|
+void done_load_buffer ( struct buffer *buffer ) {
|
|
62
|
+ efree ( phys_to_virt ( buffer->start ) );
|
60
|
63
|
}
|
61
|
64
|
|
62
|
|
-INIT_FN ( INIT_HEAP, init_load_buffer, init_load_buffer, NULL );
|
63
|
|
-
|
64
|
65
|
#endif
|