wok annotate 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 |
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@22632 | 9 u16 skip_alloc; |
pascal@19571 | 10 |
pascal@19515 | 11 void load_image(struct image_himem *m) { |
pascal@19515 | 12 m->remaining = m->size; |
pascal@22152 | 13 m->buf = m->fallback; // set no_exit btw: die() won't return to DOS |
pascal@19562 | 14 u32 buf; |
pascal@19538 | 15 u32* bufv= &buf; |
pascal@22632 | 16 if(((u16 *)&m->fallback)[1] >= (skip_alloc|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@19562 | 24 buf = m->buf; |
pascal@19538 | 25 do { |
pascal@19571 | 26 u16 size; |
pascal@21735 | 27 if(s16(size = read_image(m)) -1 < 0) break; |
pascal@20538 | 28 storepage(bufv); |
pascal@19571 | 29 if (bufv != &buf) next(bufv); |
pascal@19538 | 30 buf += size; |
pascal@19538 | 31 } while (*bufv); |
pascal@19515 | 32 if(m->remaining) die("Read error"); |
pascal@19538 | 33 close(m->fd2close); |
pascal@19515 | 34 } |
pascal@20538 | 35 |
pascal@20538 | 36 // Called just before rm->pm |
pascal@21332 | 37 void far last_ditch() { |
pascal@21332 | 38 asm { |
pascal@21332 | 39 cli |
pascal@21332 | 40 push ds |
pascal@21332 | 41 push cs |
pascal@21332 | 42 pop ds |
pascal@21332 | 43 # ifdef NO386 |
pascal@21332 | 44 push ax |
pascal@21332 | 45 push bx |
pascal@21332 | 46 push cx |
pascal@21332 | 47 push dx |
pascal@21332 | 48 # else |
pascal@21332 | 49 pusha |
pascal@21332 | 50 # endif |
pascal@21332 | 51 } |
pascal@20538 | 52 struct image_himem *m = ± |
pascal@20538 | 53 u32 *q; |
pascal@20538 | 54 vm2rm(); |
pascal@21569 | 55 if(((u16 *)&m->fallback)[1] >= 0x10) // >= _1m ? |
pascal@21569 | 56 ((u16 *)&m->fallback)[1] = 0x10; |
pascal@20538 | 57 q = m->bufv; |
pascal@20538 | 58 if(q==0) { |
pascal@20538 | 59 // Move kernel |
pascal@20538 | 60 memcpy_image(m); |
pascal@20538 | 61 // Move initrd |
pascal@20538 | 62 memcpy_image(pm2initrd(m)); |
pascal@20538 | 63 } else { //vcpi |
pascal@20538 | 64 #if defined(__BORLANDC__) && defined(NO386) |
pascal@20538 | 65 #pragma option -3 |
pascal@20538 | 66 asm{ |
pascal@20538 | 67 .386p |
pascal@20538 | 68 } |
pascal@20538 | 69 #endif |
pascal@20538 | 70 // Move kernel |
pascal@20538 | 71 // 'Gathering' copy in chunks of PAGE_SIZE |
pascal@20538 | 72 // No risk of overlapping: kernel is copied from above to 1m mark |
pascal@20538 | 73 m->size = pm2initrd(m)->size = PAGE_SIZE; |
pascal@20543 | 74 #define ADD_PAGE(x) (*(unsigned long *)(((char *)&x)+1)+=PAGE_SIZE/256) |
pascal@20543 | 75 #define SUB_PAGE(x) (*(unsigned long *)(((char *)&x)+1)-=PAGE_SIZE/256) |
pascal@20538 | 76 reset_bufv(q); |
pascal@20538 | 77 do { |
pascal@20538 | 78 m->buf = *q; |
pascal@20538 | 79 memcpy_image(m); |
pascal@20543 | 80 next(q); ADD_PAGE(m->fallback); |
pascal@20538 | 81 } while(*q); |
pascal@20538 | 82 // Move initrd |
pascal@20538 | 83 m = pm2initrd(m); |
pascal@20538 | 84 if(((u16 *)&m->fallback)[1]) { |
pascal@20538 | 85 // This is tricky: copy initrd backwards to reduce |
pascal@20538 | 86 // risk of overlapping: use the fact that initrd is copied |
pascal@20538 | 87 // to the very top of ram |
pascal@20538 | 88 // (overlapping still can happen with more than 256mb ram) |
pascal@20538 | 89 // (generic solution for this overwrite problem, anyone?) |
pascal@20538 | 90 q=m->bufv; |
pascal@20538 | 91 reset_bufv(q); |
pascal@20538 | 92 do { |
pascal@20543 | 93 next(q); ADD_PAGE(m->fallback); |
pascal@20538 | 94 } while(*q); |
pascal@20538 | 95 do { |
pascal@20543 | 96 prev(q); SUB_PAGE(m->fallback); |
pascal@20538 | 97 m->buf = *q; |
pascal@20538 | 98 memcpy_image(m); |
pascal@20538 | 99 } while(q != m->bufv); |
pascal@20538 | 100 } |
pascal@20538 | 101 } |
pascal@21332 | 102 asm { |
pascal@21332 | 103 # ifdef NO386 |
pascal@21332 | 104 pop dx |
pascal@21332 | 105 pop cx |
pascal@21332 | 106 pop bx |
pascal@21332 | 107 pop ax |
pascal@21332 | 108 # else |
pascal@21332 | 109 popa |
pascal@21332 | 110 # endif |
pascal@21332 | 111 pop ds |
pascal@21332 | 112 } |
pascal@20538 | 113 } |