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