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

Remove linux-mmc
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 01 11:07:58 2018 +0100 (2018-12-01)
parents 65366955881f
children ab907169f156
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 = &pm;
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 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
62 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
63 reset_bufv(q);
64 do {
65 m->buf = *q;
66 memcpy_image(m);
67 next(q); ADD_PAGE(m->fallback);
68 } while(*q);
69 // Move initrd
70 m = pm2initrd(m);
71 if(((u16 *)&m->fallback)[1]) {
72 // This is tricky: copy initrd backwards to reduce
73 // risk of overlapping: use the fact that initrd is copied
74 // to the very top of ram
75 // (overlapping still can happen with more than 256mb ram)
76 // (generic solution for this overwrite problem, anyone?)
77 q=m->bufv;
78 reset_bufv(q);
79 do {
80 next(q); ADD_PAGE(m->fallback);
81 } while(*q);
82 do {
83 prev(q); SUB_PAGE(m->fallback);
84 m->buf = *q;
85 memcpy_image(m);
86 } while(q != m->bufv);
87 }
88 }
89 }