wok view linld/stuff/src/HIMEM.CPP @ rev 21621

linld: more ram for zImage (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 25 13:23:29 2019 +0200 (2019-05-25)
parents 094f58ac8183
children 6460d542c35a
line source
1 // This file is distributed under GPL
2 //
3 // High mem handling routines
4 // C++ part of VCPI madness is here
6 #include "crtl.h"
7 #include "common.h"
9 int skip_alloc;
11 void load_image(struct image_himem *m) {
12 no_exit++; // die() won't return to DOS
13 m->remaining = m->size;
14 m->buf = m->fallback;
15 u32 buf;
16 u32* bufv= &buf;
17 if(((u16 *)&m->fallback)[1] >= 0x10 && !skip_alloc) { // >= _1m ?
18 if(vcpi) {
19 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv
20 }
21 else {
22 xmm_alloc(m); // update m->buf
23 }
24 }
25 buf = m->buf;
26 do {
27 u16 size;
28 if(s16(size = read_image(m)) <= 0) break;
29 storepage(bufv);
30 if (bufv != &buf) next(bufv);
31 buf += size;
32 } while (*bufv);
33 if(m->remaining) die("Read error");
34 close(m->fd2close);
35 }
37 // Called just before rm->pm
38 void far last_ditch() {
39 asm {
40 cli
41 push ds
42 push cs
43 pop ds
44 # ifdef NO386
45 push ax
46 push bx
47 push cx
48 push dx
49 # else
50 pusha
51 # endif
52 }
53 struct image_himem *m = &pm;
54 u32 *q;
55 vm2rm();
56 if(((u16 *)&m->fallback)[1] >= 0x10) // >= _1m ?
57 ((u16 *)&m->fallback)[1] = 0x10;
58 q = m->bufv;
59 if(q==0) {
60 // Move kernel
61 memcpy_image(m);
62 // Move initrd
63 memcpy_image(pm2initrd(m));
64 } else { //vcpi
65 #if defined(__BORLANDC__) && defined(NO386)
66 #pragma option -3
67 asm{
68 .386p
69 }
70 #endif
71 // Move kernel
72 // 'Gathering' copy in chunks of PAGE_SIZE
73 // No risk of overlapping: kernel is copied from above to 1m mark
74 m->size = pm2initrd(m)->size = PAGE_SIZE;
75 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
76 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
77 reset_bufv(q);
78 do {
79 m->buf = *q;
80 memcpy_image(m);
81 next(q); ADD_PAGE(m->fallback);
82 } while(*q);
83 // Move initrd
84 m = pm2initrd(m);
85 if(((u16 *)&m->fallback)[1]) {
86 // This is tricky: copy initrd backwards to reduce
87 // risk of overlapping: use the fact that initrd is copied
88 // to the very top of ram
89 // (overlapping still can happen with more than 256mb ram)
90 // (generic solution for this overwrite problem, anyone?)
91 q=m->bufv;
92 reset_bufv(q);
93 do {
94 next(q); ADD_PAGE(m->fallback);
95 } while(*q);
96 do {
97 prev(q); SUB_PAGE(m->fallback);
98 m->buf = *q;
99 memcpy_image(m);
100 } while(q != m->bufv);
101 }
102 }
103 asm {
104 # ifdef NO386
105 pop dx
106 pop cx
107 pop bx
108 pop ax
109 # else
110 popa
111 # endif
112 pop ds
113 }
114 }