wok view linld/stuff/src/HIMEM.CPP @ rev 20538
linld: _fastcall calls
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Nov 28 19:46:10 2018 +0100 (2018-11-28) |
parents | f0d71e920c5a |
children | 16d1d23aefee |
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 struct image_himem imgs[2];
10 int skip_alloc;
12 void load_image(struct image_himem *m) {
13 no_exit++; // die() won't return to DOS
14 m->remaining = m->size;
15 m->buf = m->fallback;
16 u32 buf;
17 u32* bufv= &buf;
18 if(((u16 *)&m->fallback)[1] >= 0x10 && !skip_alloc) { // >= _1m ?
19 if(vcpi) {
20 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv
21 }
22 else {
23 xmm_alloc(m); // update m->buf
24 }
25 }
26 buf = m->buf;
27 do {
28 u16 size;
29 if(s16(size = read_image(m)) <= 0) break;
30 storepage(bufv);
31 if (bufv != &buf) next(bufv);
32 buf += size;
33 } while (*bufv);
34 if(m->remaining) die("Read error");
35 close(m->fd2close);
36 }
38 // Called just before rm->pm
39 void last_ditch() {
40 struct image_himem *m = ±
41 u32 *q;
42 vm2rm();
43 if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ?
44 q = m->bufv;
45 if(q==0) {
46 // Move kernel
47 memcpy_image(m);
48 // Move initrd
49 memcpy_image(pm2initrd(m));
50 } else { //vcpi
51 #if defined(__BORLANDC__) && defined(NO386)
52 #pragma option -3
53 asm{
54 .386p
55 }
56 #endif
57 // Move kernel
58 // 'Gathering' copy in chunks of PAGE_SIZE
59 // No risk of overlapping: kernel is copied from above to 1m mark
60 m->size = pm2initrd(m)->size = PAGE_SIZE;
61 reset_bufv(q);
62 do {
63 m->buf = *q;
64 memcpy_image(m);
65 next(q); m->fallback+=PAGE_SIZE;
66 } while(*q);
67 // Move initrd
68 m = pm2initrd(m);
69 if(((u16 *)&m->fallback)[1]) {
70 // This is tricky: copy initrd backwards to reduce
71 // risk of overlapping: use the fact that initrd is copied
72 // to the very top of ram
73 // (overlapping still can happen with more than 256mb ram)
74 // (generic solution for this overwrite problem, anyone?)
75 q=m->bufv;
76 reset_bufv(q);
77 do {
78 next(q); m->fallback+=PAGE_SIZE;
79 } while(*q);
80 do {
81 prev(q); m->fallback-=PAGE_SIZE;
82 m->buf = *q;
83 memcpy_image(m);
84 } while(q != m->bufv);
85 }
86 }
87 }