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

syslinux: fix build
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 28 16:32:57 2021 +0000 (2021-02-28)
parents bc4b94310a29
children 6b6d14c9f7e9
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 u32* bufv= &himem_buf;
14 #ifdef VCPI
15 #ifdef WITH_XMM_ALLOC
16 m->buf = m->fallback; // set no_exit btw: die() won't return to DOS
17 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _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 himem_buf = m->buf;
26 #else
27 *bufv = m->buf = m->fallback; // set no_exit btw: die() won't return to DOS
28 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ?
29 if(vcpi) {
30 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv
31 }
32 }
33 #endif
34 #else
35 m->buf = m->fallback; // set no_exit btw: die() won't return to DOS
36 #ifdef WITH_XMM_ALLOC
37 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ?
38 xmm_alloc(m); // update m->buf
39 }
40 himem_buf = m->buf;
41 #endif
42 #endif
43 do {
44 u16 size;
45 if(s16(size = read_image(m)) -1 < 0) break;
46 storepage(bufv);
47 #ifdef VCPI
48 if (bufv != &himem_buf) next(bufv);
49 #endif
50 himem_buf += size;
51 } while (*bufv);
52 if(m->remaining) loadfailure();
53 close(m->fd2close);
54 }
56 // Called just before rm->pm
57 void far last_ditch() {
58 asm {
59 pushf
60 ;cli
61 push ds
62 push cs
63 pop ds
64 # ifdef NO386
65 push ax
66 push bx
67 push cx
68 push dx
69 # else
70 pusha
71 # endif
72 }
73 #ifdef VCPI
74 vm2rm();
75 #endif
76 struct image_himem *m = &pm;
77 #define KERNEL 0
78 #define INITRD 1
79 if(((u16 *)&m[KERNEL].fallback)[1] >= 0x10) // >= _1m ?
80 ((u16 *)&m[KERNEL].fallback)[1] = 0x10;
81 #ifdef VCPI
82 u32 *q;
83 q = m[KERNEL].bufv;
84 if(q==0) {
85 #endif
86 // Move kernel
87 memcpy_image_kernel();
88 // Move initrd
89 memcpy_image_initrd();
90 #ifdef VCPI
91 } else { //vcpi
92 #if defined(__BORLANDC__) && defined(NO386)
93 #pragma option -3
94 asm{
95 .386p
96 }
97 #endif
98 // Move kernel
99 // 'Gathering' copy in chunks of PAGE_SIZE
100 // No risk of overlapping: kernel is copied from above to 1m mark
101 m[KERNEL].size = m[INITRD].size = PAGE_SIZE;
102 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
103 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
104 reset_bufv(q);
105 do {
106 m[KERNEL].buf = *q;
107 memcpy_image_kernel();
108 next(q); ADD_PAGE(m[KERNEL].fallback);
109 } while(*q);
110 // Move initrd
111 if(((u16 *)&m[INITRD].fallback)[1]) {
112 // This is tricky: copy initrd backwards to reduce
113 // risk of overlapping: use the fact that initrd is copied
114 // to the very top of ram
115 // (overlapping still can happen with more than 256mb ram)
116 // (generic solution for this overwrite problem, anyone?)
117 q=m[INITRD].bufv;
118 reset_bufv(q);
119 do {
120 next(q); ADD_PAGE(m[INITRD].fallback);
121 } while(*q);
122 do {
123 prev(q); SUB_PAGE(m[INITRD].fallback);
124 m[INITRD].buf = *q;
125 memcpy_image_initrd();
126 } while(q != m[INITRD].bufv);
127 }
128 }
129 #endif
130 asm {
131 # ifdef NO386
132 pop dx
133 pop cx
134 pop bx
135 pop ax
136 # else
137 popa
138 # endif
139 pop ds
140 popf
141 }
142 }