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

linld: add iso support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 08 20:15:35 2021 +0000 (2021-01-08)
parents 3d19917d3a03
children bc4b94310a29
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 extern u32 himem_buf;
11 void load_image(struct image_himem *m) {
12 m->remaining = m->size;
13 m->buf = m->fallback; // set no_exit btw: die() won't return to DOS
14 u32* bufv= &himem_buf;
15 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ?
16 if(vcpi) {
17 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv
18 }
19 #ifdef WITH_XMM_ALLOC
20 else {
21 xmm_alloc(m); // update m->buf
22 }
23 #endif
24 }
25 himem_buf = m->buf;
26 do {
27 u16 size;
28 if(s16(size = read_image(m)) -1 < 0) break;
29 storepage(bufv);
30 if (bufv != &himem_buf) next(bufv);
31 himem_buf += size;
32 } while (*bufv);
33 if(m->remaining) loadfailure();
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 vm2rm();
54 struct image_himem *m = &pm;
55 u32 *q;
56 if(((u16 *)&m->fallback)[1] >= 0x10) // >= _1m ?
57 ((u16 *)&m->fallback)[1] = 0x10;
58 q = m->bufv;
59 if(q==0) {
60 // Move kernel
61 memcpy_image(m);
62 // Move initrd
63 memcpy_image(pm2initrd(m));
64 } else { //vcpi
65 #if defined(__BORLANDC__) && defined(NO386)
66 #pragma option -3
67 asm{
68 .386p
69 }
70 #endif
71 // Move kernel
72 // 'Gathering' copy in chunks of PAGE_SIZE
73 // No risk of overlapping: kernel is copied from above to 1m mark
74 m->size = pm2initrd(m)->size = PAGE_SIZE;
75 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
76 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
77 reset_bufv(q);
78 do {
79 m->buf = *q;
80 memcpy_image(m);
81 next(q); ADD_PAGE(m->fallback);
82 } while(*q);
83 // Move initrd
84 m = pm2initrd(m);
85 if(((u16 *)&m->fallback)[1]) {
86 // This is tricky: copy initrd backwards to reduce
87 // risk of overlapping: use the fact that initrd is copied
88 // to the very top of ram
89 // (overlapping still can happen with more than 256mb ram)
90 // (generic solution for this overwrite problem, anyone?)
91 q=m->bufv;
92 reset_bufv(q);
93 do {
94 next(q); ADD_PAGE(m->fallback);
95 } while(*q);
96 do {
97 prev(q); SUB_PAGE(m->fallback);
98 m->buf = *q;
99 memcpy_image(m);
100 } while(q != m->bufv);
101 }
102 }
103 asm {
104 # ifdef NO386
105 pop dx
106 pop cx
107 pop bx
108 pop ax
109 # else
110 popa
111 # endif
112 pop ds
113 }
114 }