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

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