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

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