wok-6.x view linld/stuff/src/HIMEM.CPP @ rev 20634
linld: fix open()
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jan 08 17:51:51 2019 +0100 (2019-01-08) |
parents | 16d1d23aefee |
children | 094f58ac8183 |
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 last_ditch() {
39 struct image_himem *m = ±
40 u32 *q;
41 vm2rm();
42 if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ?
43 q = m->bufv;
44 if(q==0) {
45 // Move kernel
46 memcpy_image(m);
47 // Move initrd
48 memcpy_image(pm2initrd(m));
49 } else { //vcpi
50 #if defined(__BORLANDC__) && defined(NO386)
51 #pragma option -3
52 asm{
53 .386p
54 }
55 #endif
56 // Move kernel
57 // 'Gathering' copy in chunks of PAGE_SIZE
58 // No risk of overlapping: kernel is copied from above to 1m mark
59 m->size = pm2initrd(m)->size = PAGE_SIZE;
60 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
61 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
62 reset_bufv(q);
63 do {
64 m->buf = *q;
65 memcpy_image(m);
66 next(q); ADD_PAGE(m->fallback);
67 } while(*q);
68 // Move initrd
69 m = pm2initrd(m);
70 if(((u16 *)&m->fallback)[1]) {
71 // This is tricky: copy initrd backwards to reduce
72 // risk of overlapping: use the fact that initrd is copied
73 // to the very top of ram
74 // (overlapping still can happen with more than 256mb ram)
75 // (generic solution for this overwrite problem, anyone?)
76 q=m->bufv;
77 reset_bufv(q);
78 do {
79 next(q); ADD_PAGE(m->fallback);
80 } while(*q);
81 do {
82 prev(q); SUB_PAGE(m->fallback);
83 m->buf = *q;
84 memcpy_image(m);
85 } while(q != m->bufv);
86 }
87 }
88 }