wok view linld/stuff/src/HIMEM.CPP @ rev 23471
updated python-cheetah (2.4.3 -> 2.4.4)
author | Hans-G?nter Theisgen |
---|---|
date | Sun Apr 05 14:34:55 2020 +0100 (2020-04-05) |
parents | 306a4bbdee7d |
children | afa00d471293 |
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 u16 skip_alloc;
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 buf;
15 u32* bufv= &buf;
16 if(((u16 *)&m->fallback)[1] >= (skip_alloc|0x10)) { // >= _1m ?
17 if(vcpi) {
18 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv
19 }
20 else {
21 xmm_alloc(m); // update m->buf
22 }
23 }
24 buf = m->buf;
25 do {
26 u16 size;
27 if(s16(size = read_image(m)) -1 < 0) break;
28 storepage(bufv);
29 if (bufv != &buf) next(bufv);
30 buf += size;
31 } while (*bufv);
32 if(m->remaining) die("Read error");
33 close(m->fd2close);
34 }
36 // Called just before rm->pm
37 void far last_ditch() {
38 asm {
39 cli
40 push ds
41 push cs
42 pop ds
43 # ifdef NO386
44 push ax
45 push bx
46 push cx
47 push dx
48 # else
49 pusha
50 # endif
51 }
52 struct image_himem *m = ±
53 u32 *q;
54 vm2rm();
55 if(((u16 *)&m->fallback)[1] >= 0x10) // >= _1m ?
56 ((u16 *)&m->fallback)[1] = 0x10;
57 q = m->bufv;
58 if(q==0) {
59 // Move kernel
60 memcpy_image(m);
61 // Move initrd
62 memcpy_image(pm2initrd(m));
63 } else { //vcpi
64 #if defined(__BORLANDC__) && defined(NO386)
65 #pragma option -3
66 asm{
67 .386p
68 }
69 #endif
70 // Move kernel
71 // 'Gathering' copy in chunks of PAGE_SIZE
72 // No risk of overlapping: kernel is copied from above to 1m mark
73 m->size = pm2initrd(m)->size = PAGE_SIZE;
74 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256)
75 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256)
76 reset_bufv(q);
77 do {
78 m->buf = *q;
79 memcpy_image(m);
80 next(q); ADD_PAGE(m->fallback);
81 } while(*q);
82 // Move initrd
83 m = pm2initrd(m);
84 if(((u16 *)&m->fallback)[1]) {
85 // This is tricky: copy initrd backwards to reduce
86 // risk of overlapping: use the fact that initrd is copied
87 // to the very top of ram
88 // (overlapping still can happen with more than 256mb ram)
89 // (generic solution for this overwrite problem, anyone?)
90 q=m->bufv;
91 reset_bufv(q);
92 do {
93 next(q); ADD_PAGE(m->fallback);
94 } while(*q);
95 do {
96 prev(q); SUB_PAGE(m->fallback);
97 m->buf = *q;
98 memcpy_image(m);
99 } while(q != m->bufv);
100 }
101 }
102 asm {
103 # ifdef NO386
104 pop dx
105 pop cx
106 pop bx
107 pop ax
108 # else
109 popa
110 # endif
111 pop ds
112 }
113 }