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

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