wok annotate 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 |
rev | line source |
---|---|
pascal@19515 | 1 // This file is distributed under GPL |
pascal@19515 | 2 // |
pascal@19515 | 3 // High mem handling routines |
pascal@19515 | 4 // C++ part of VCPI madness is here |
pascal@19515 | 5 |
pascal@19515 | 6 #include "crtl.h" |
pascal@19515 | 7 #include "common.h" |
pascal@19515 | 8 |
pascal@23996 | 9 extern u32 himem_buf; |
pascal@19571 | 10 |
pascal@19515 | 11 void load_image(struct image_himem *m) { |
pascal@19515 | 12 m->remaining = m->size; |
pascal@24013 | 13 u32* bufv= &himem_buf; |
pascal@24013 | 14 #ifdef WITH_XMM_ALLOC |
pascal@22152 | 15 m->buf = m->fallback; // set no_exit btw: die() won't return to DOS |
pascal@23992 | 16 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ? |
pascal@19538 | 17 if(vcpi) { |
pascal@20528 | 18 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv |
pascal@19515 | 19 } |
pascal@19580 | 20 else { |
pascal@19562 | 21 xmm_alloc(m); // update m->buf |
pascal@19538 | 22 } |
pascal@19515 | 23 } |
pascal@23996 | 24 himem_buf = m->buf; |
pascal@24013 | 25 #else |
pascal@24013 | 26 *bufv = m->buf = m->fallback; // set no_exit btw: die() won't return to DOS |
pascal@24013 | 27 if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ? |
pascal@24013 | 28 if(vcpi) { |
pascal@24013 | 29 bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv |
pascal@24013 | 30 } |
pascal@24013 | 31 } |
pascal@24013 | 32 #endif |
pascal@19538 | 33 do { |
pascal@19571 | 34 u16 size; |
pascal@21735 | 35 if(s16(size = read_image(m)) -1 < 0) break; |
pascal@20538 | 36 storepage(bufv); |
pascal@23996 | 37 if (bufv != &himem_buf) next(bufv); |
pascal@23996 | 38 himem_buf += size; |
pascal@19538 | 39 } while (*bufv); |
pascal@23996 | 40 if(m->remaining) loadfailure(); |
pascal@19538 | 41 close(m->fd2close); |
pascal@19515 | 42 } |
pascal@20538 | 43 |
pascal@20538 | 44 // Called just before rm->pm |
pascal@21332 | 45 void far last_ditch() { |
pascal@21332 | 46 asm { |
pascal@24013 | 47 pushf |
pascal@24013 | 48 ;cli |
pascal@21332 | 49 push ds |
pascal@21332 | 50 push cs |
pascal@21332 | 51 pop ds |
pascal@21332 | 52 # ifdef NO386 |
pascal@21332 | 53 push ax |
pascal@21332 | 54 push bx |
pascal@21332 | 55 push cx |
pascal@21332 | 56 push dx |
pascal@21332 | 57 # else |
pascal@21332 | 58 pusha |
pascal@21332 | 59 # endif |
pascal@21332 | 60 } |
pascal@23996 | 61 vm2rm(); |
pascal@20538 | 62 struct image_himem *m = ± |
pascal@24013 | 63 #define KERNEL 0 |
pascal@24013 | 64 #define INITRD 1 |
pascal@20538 | 65 u32 *q; |
pascal@24013 | 66 if(((u16 *)&m[KERNEL].fallback)[1] >= 0x10) // >= _1m ? |
pascal@24013 | 67 ((u16 *)&m[KERNEL].fallback)[1] = 0x10; |
pascal@24013 | 68 q = m[KERNEL].bufv; |
pascal@20538 | 69 if(q==0) { |
pascal@20538 | 70 // Move kernel |
pascal@24013 | 71 memcpy_image_kernel(); |
pascal@20538 | 72 // Move initrd |
pascal@24013 | 73 memcpy_image_initrd(); |
pascal@20538 | 74 } else { //vcpi |
pascal@20538 | 75 #if defined(__BORLANDC__) && defined(NO386) |
pascal@20538 | 76 #pragma option -3 |
pascal@20538 | 77 asm{ |
pascal@20538 | 78 .386p |
pascal@20538 | 79 } |
pascal@20538 | 80 #endif |
pascal@20538 | 81 // Move kernel |
pascal@20538 | 82 // 'Gathering' copy in chunks of PAGE_SIZE |
pascal@20538 | 83 // No risk of overlapping: kernel is copied from above to 1m mark |
pascal@24013 | 84 m[KERNEL].size = m[INITRD].size = PAGE_SIZE; |
pascal@20543 | 85 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256) |
pascal@20543 | 86 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256) |
pascal@20538 | 87 reset_bufv(q); |
pascal@20538 | 88 do { |
pascal@24013 | 89 m[KERNEL].buf = *q; |
pascal@24013 | 90 memcpy_image_kernel(); |
pascal@24013 | 91 next(q); ADD_PAGE(m[KERNEL].fallback); |
pascal@20538 | 92 } while(*q); |
pascal@20538 | 93 // Move initrd |
pascal@24013 | 94 if(((u16 *)&m[INITRD].fallback)[1]) { |
pascal@20538 | 95 // This is tricky: copy initrd backwards to reduce |
pascal@20538 | 96 // risk of overlapping: use the fact that initrd is copied |
pascal@20538 | 97 // to the very top of ram |
pascal@20538 | 98 // (overlapping still can happen with more than 256mb ram) |
pascal@20538 | 99 // (generic solution for this overwrite problem, anyone?) |
pascal@24013 | 100 q=m[INITRD].bufv; |
pascal@20538 | 101 reset_bufv(q); |
pascal@20538 | 102 do { |
pascal@24013 | 103 next(q); ADD_PAGE(m[INITRD].fallback); |
pascal@20538 | 104 } while(*q); |
pascal@20538 | 105 do { |
pascal@24013 | 106 prev(q); SUB_PAGE(m[INITRD].fallback); |
pascal@24013 | 107 m[INITRD].buf = *q; |
pascal@24013 | 108 memcpy_image_initrd(); |
pascal@24013 | 109 } while(q != m[INITRD].bufv); |
pascal@20538 | 110 } |
pascal@20538 | 111 } |
pascal@21332 | 112 asm { |
pascal@21332 | 113 # ifdef NO386 |
pascal@21332 | 114 pop dx |
pascal@21332 | 115 pop cx |
pascal@21332 | 116 pop bx |
pascal@21332 | 117 pop ax |
pascal@21332 | 118 # else |
pascal@21332 | 119 popa |
pascal@21332 | 120 # endif |
pascal@21332 | 121 pop ds |
pascal@24013 | 122 popf |
pascal@21332 | 123 } |
pascal@20538 | 124 } |