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

Add openct
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 03 15:12:17 2017 +0200 (2017-04-03)
parents 76087975885f
children 9e8f9b54bd83
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 pm;
10 struct image_himem initrd;
11 int skip_alloc;
13 // Called from inside kernel just before rm->pm
14 // _loadds _saveregs: done by hand
15 void far last_ditch() {
16 cli(); // we start doing *really* destructive things to DOS/BIOS
17 // it means: do not even try to enable ints
18 // or call BIOS services after this
19 asm {
20 push ds
21 push cs
22 pop ds
23 #ifndef NO386
24 pusha
25 #else
26 push ax
27 push bx
28 push cx
29 push dx
30 #endif
31 }
32 struct image_himem *m = &pm;
33 vm2rm();
34 if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ?
35 if(m->bufv==0) {
36 // Move kernel
37 memcpy_image(m);
38 // Move initrd
39 memcpy_image(&initrd);
40 } else { //vcpi
41 // Move kernel
42 // 'Gathering' copy in chunks of PAGE_SIZE
43 // No risk of overlapping: kernel is copied from above to 1m mark
44 m->size = initrd.size = PAGE_SIZE;
45 u32 *p = m->bufv;
46 reset_bufv(p);
47 if (p) do {
48 m->buf = *p;
49 memcpy_image(m);
50 next(p); m->fallback+=PAGE_SIZE;
51 } while(*p);
52 // Move initrd
53 m = &initrd;
54 if(m->fallback) {
55 // This is tricky: copy initrd backwards to reduce
56 // risk of overlapping: use the fact that initrd is copied
57 // to the very top of ram
58 // (overlapping still can happen with more than 256mb ram)
59 // (generic solution for this overwrite problem, anyone?)
60 p=m->bufv;
61 reset_bufv(p);
62 do {
63 next(p); m->fallback+=PAGE_SIZE;
64 } while(*p);
65 do {
66 prev(p); m->fallback-=PAGE_SIZE;
67 m->buf = *p;
68 memcpy_image(m);
69 } while(p != m->bufv);
70 }
71 }
72 asm {
73 #ifndef NO386
74 popa
75 #else
76 pop dx
77 pop cx
78 pop bx
79 pop ax
80 #endif
81 pop ds
82 }
83 }
85 void load_image(struct image_himem *m) {
86 no_exit++; // die() won't return to DOS
87 m->remaining = m->size;
88 m->buf = m->fallback;
89 u32 buf;
90 u32* bufv= &buf;
91 if(((u16 *)&m->fallback)[1] >= 0x10 && !skip_alloc) { // >= _1m ?
92 if(vcpi) {
93 bufv = malloc_bufv_or_die(m); // update m->bufv
94 }
95 else {
96 xmm_alloc(m); // update m->buf
97 }
98 }
99 buf = m->buf;
100 do {
101 u8 xfer_buf[PAGE_SIZE];
102 u16 size;
103 if(s16(size = read_image(m, xfer_buf, PAGE_SIZE)) <= 0) break;
104 storepage(bufv, ofs(xfer_buf));
105 if (bufv != &buf) next(bufv);
106 buf += size;
107 } while (*bufv);
108 if(m->remaining) die("Read error");
109 close(m->fd2close);
110 }