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

Openssh (8.5p1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 08 09:21:26 2021 +0000 (2021-04-08)
parents 61df94a0fa43
children
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 es
63 push cs
64 pop ds
65 # ifdef NO386
66 push ax
67 push bx
68 push cx
69 push dx
70 # else
71 pusha
72 # endif
73 }
74 #ifdef VCPI
75 vm2rm();
76 #endif
77 struct image_himem *m = &pm;
78 #define KERNEL 0
79 #define INITRD 1
80 if(((u16 *)&m[KERNEL].fallback)[1] >= 0x10) // >= _1m ?
81 ((u16 *)&m[KERNEL].fallback)[1] = 0x10;
82 #ifdef VCPI
83 u32 *q;
84 q = m[KERNEL].bufv;
85 if(q==0) {
86 #endif
87 // Move kernel
88 memcpy_image_kernel();
89 // Move initrd
90 memcpy_image_initrd();
91 #ifdef VCPI
92 } else { //vcpi FIXME: LARGE_ZIMAGE case
93 #if defined(__BORLANDC__) && defined(NO386)
94 #pragma option -3
95 asm{
96 .386p
97 pushad
98 }
99 #endif
100 // Move kernel
101 // 'Gathering' copy in chunks of PAGE_SIZE
102 // No risk of overlapping: kernel is copied from above to 1m mark
103 m[KERNEL].size = m[INITRD].size = PAGE_SIZE;
104 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
105 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
106 reset_bufv(q);
107 do {
108 m[KERNEL].buf = *q;
109 memcpy_image_kernel();
110 next(q); ADD_PAGE(m[KERNEL].fallback);
111 } while(*q);
112 // Move initrd
113 if(((u16 *)&m[INITRD].fallback)[1]) {
114 // This is tricky: copy initrd backwards to reduce
115 // risk of overlapping: use the fact that initrd is copied
116 // to the very top of ram
117 // (overlapping still can happen with more than 256mb ram)
118 // (generic solution for this overwrite problem, anyone?)
119 q=m[INITRD].bufv;
120 reset_bufv(q);
121 do {
122 next(q); ADD_PAGE(m[INITRD].fallback);
123 } while(*q);
124 do {
125 prev(q); SUB_PAGE(m[INITRD].fallback);
126 m[INITRD].buf = *q;
127 memcpy_image_initrd();
128 } while(q != m[INITRD].bufv);
129 }
130 asm{
131 popad
132 }
133 }
134 #endif
135 asm {
136 # ifdef NO386
137 pop dx
138 pop cx
139 pop bx
140 pop ax
141 # else
142 popa
143 # endif
144 pop es
145 pop ds
146 popf
147 }
148 }