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

Up libltdl (2.4.6), mtp-tools (1.1.16)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 19 15:52:41 2019 +0200 (2019-04-19)
parents ab907169f156
children 87b6697bb350
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) m->fallback = _1m; // >= _1m ?
57 q = m->bufv;
58 if(q==0) {
59 // Move kernel
60 memcpy_image(m);
61 // Move initrd
62 memcpy_image(pm2initrd(m));
63 } else { //vcpi
64 #if defined(__BORLANDC__) && defined(NO386)
65 #pragma option -3
66 asm{
67 .386p
68 }
69 #endif
70 // Move kernel
71 // 'Gathering' copy in chunks of PAGE_SIZE
72 // No risk of overlapping: kernel is copied from above to 1m mark
73 m->size = pm2initrd(m)->size = PAGE_SIZE;
74 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
75 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
76 reset_bufv(q);
77 do {
78 m->buf = *q;
79 memcpy_image(m);
80 next(q); ADD_PAGE(m->fallback);
81 } while(*q);
82 // Move initrd
83 m = pm2initrd(m);
84 if(((u16 *)&m->fallback)[1]) {
85 // This is tricky: copy initrd backwards to reduce
86 // risk of overlapping: use the fact that initrd is copied
87 // to the very top of ram
88 // (overlapping still can happen with more than 256mb ram)
89 // (generic solution for this overwrite problem, anyone?)
90 q=m->bufv;
91 reset_bufv(q);
92 do {
93 next(q); ADD_PAGE(m->fallback);
94 } while(*q);
95 do {
96 prev(q); SUB_PAGE(m->fallback);
97 m->buf = *q;
98 memcpy_image(m);
99 } while(q != m->bufv);
100 }
101 }
102 asm {
103 # ifdef NO386
104 pop dx
105 pop cx
106 pop bx
107 pop ax
108 # else
109 popa
110 # endif
111 pop ds
112 }
113 }