wok diff linld/stuff/src/HIMEM.CPP @ rev 19538
linld: add 'linld <kernel> <cmdline>' syntax
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Dec 02 12:37:59 2016 +0100 (2016-12-02) |
parents | bb42796dcd3b |
children | 31c5cbbd9380 |
line diff
1.1 --- a/linld/stuff/src/HIMEM.CPP Tue Nov 22 21:19:01 2016 +0100 1.2 +++ b/linld/stuff/src/HIMEM.CPP Fri Dec 02 12:37:59 2016 +0100 1.3 @@ -6,91 +6,29 @@ 1.4 #include "crtl.h" 1.5 #include "common.h" 1.6 1.7 -// Returns physical addr of allocated himem chunk 1.8 -// Never fails (will use fallback if not enough mem/no xmm) 1.9 -// TODO: with proper cleanup it is possible to exit to DOS 1.10 -// even after XMM alloc - do dealloc, then exit... 1.11 -// don't forget to clean up the mess then, especially 1.12 -// XMM handle which is lost inside xmm_alloc()... 1.13 -// (don't drop fallback: use it if no XMM driver detected) 1.14 -static void read2mem(struct image_himem *m) { 1.15 - u32 buf=m->buf; 1.16 - while(1) { 1.17 - u8 xfer_buf[PAGE_SIZE]; 1.18 - u16 size = read_image(m, xfer_buf, sizeof(xfer_buf)); 1.19 - if(s16(size) <= 0) break; 1.20 - memcpy32(0, buf, seg(xfer_buf), ofs(xfer_buf), size); 1.21 - buf += size; 1.22 - m->remaining -= size; 1.23 - } 1.24 -} 1.25 - 1.26 -extern "C" void sort(u32* v, int size); 1.27 - 1.28 -// Returns ptr to mallocated zero-terminated list of physical page addrs 1.29 -// Never fails (will die if not enough mem) 1.30 -// Addresses are sorted in ascending order 1.31 -// static void malloc_vcpi(struct image_himem *m) { 1.32 -static void read2vcpi(struct image_himem *m) { 1.33 - u16 cnt = (m->size+PAGE_MASK)/PAGE_SIZE; 1.34 - u32* bufv = (u32*)malloc_or_die((cnt+1)*sizeof(u32)); 1.35 - // our malloc zeroes allocated mem: buf[cnt]=0; 1.36 - // Allocate pages, storing addrs in addrbuf 1.37 - {for(int i=0;i<cnt;i++) { 1.38 - u32 v; 1.39 - asm { 1.40 - db 66h 1.41 - xor dx,dx 1.42 - mov ax,0DE04h 1.43 - int 67h 1.44 - db 66h 1.45 - mov [word ptr v],dx 1.46 - } 1.47 - extern const char vcpi_alloc_err[]; 1.48 - if(!v) die(vcpi_alloc_err); 1.49 - bufv[i] = v; 1.50 - }} 1.51 - // Sanitize addresses: ascending sort 1.52 - sort(bufv,cnt); 1.53 - m->bufv = bufv; 1.54 -//} 1.55 - 1.56 -// Reads opened fd data into malloc_vcpi'ed memory 1.57 -// Dies if file isn't exactly 'size' bytes long 1.58 -// Needs intermediate buffer of exactly Nx4k bytes 1.59 -// static void read2vcpi(struct image_himem *m) { 1.60 - while(1) { 1.61 - u8 xfer_buf[PAGE_SIZE]; 1.62 - u16 size = read_image(m, xfer_buf, PAGE_SIZE); 1.63 - if(s16(size) <= 0 || !*bufv) break; 1.64 - m->remaining -= size; 1.65 - memcpy_vcpi(*bufv++, seg(xfer_buf), ofs(xfer_buf)); 1.66 - } 1.67 -} 1.68 - 1.69 -void init_vcpi() { 1.70 - heap_top = prepare_vcpi(malloc_or_die(8*1024+4)); 1.71 - get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping"); 1.72 -} 1.73 - 1.74 int skip_xmmalloc; 1.75 void load_image(struct image_himem *m) { 1.76 no_exit++; // die() won't return to DOS 1.77 m->remaining = m->size; 1.78 - m->buf = m->fallback; 1.79 - if(m->fallback < _1m) { 1.80 - read2mem(m); 1.81 - } else if(vcpi==0) { 1.82 - if (!skip_xmmalloc) { 1.83 - u32 v = xmm_alloc(m->size); 1.84 - if(v) m->buf = v; 1.85 + u32 buf= m->buf = m->fallback; 1.86 + u32* bufv= &buf; 1.87 + if(m->fallback >= _1m) { 1.88 + if(vcpi) { 1.89 + bufv = malloc_bufv_or_die(m); 1.90 } 1.91 - read2mem(m); 1.92 - } else { 1.93 - //malloc_vcpi(m); 1.94 - read2vcpi(m); 1.95 + else if (!skip_xmmalloc) { 1.96 + xmm_alloc(m); 1.97 + } 1.98 } 1.99 + do { 1.100 + u8 xfer_buf[PAGE_SIZE]; 1.101 + u16 size = read_image(m, xfer_buf, PAGE_SIZE); 1.102 + if(s16(size) <= 0) break; 1.103 + memcpy32(*bufv, seg(xfer_buf), ofs(xfer_buf), size); 1.104 + if (bufv != &buf) bufv++; 1.105 + buf += size; 1.106 + } while (*bufv); 1.107 if(m->remaining) die("Read error"); 1.108 -//break iso case close(m->fd); 1.109 + close(m->fd2close); 1.110 } 1.111