# HG changeset patch # User Pascal Bellard # Date 1543587144 -3600 # Node ID c836f6d2eff8a9354fd77000a6ce1a4536b388e2 # Parent 25e3f390625ae871178aba15a81c0e902e3db503 linld: relative lseek for load.cpp diff -r 25e3f390625a -r c836f6d2eff8 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Thu Nov 29 13:49:52 2018 +0100 +++ b/linld/stuff/src/CRTL.ASM Fri Nov 30 15:12:24 2018 +0100 @@ -280,27 +280,41 @@ ;*************************************************************** ;_fastcall long lseekset(int fd, unsigned sz); +;_fastcall long lseekcur(int fd, int while); ;*************************************************************** + global @lseekcur$qii:near + proc @lseekcur$qii near + + xchg ax,bx + xchg ax,dx + cwd + xchg ax,dx + xchg ax,cx + mov al,1 + jmp lseek + ifdef EXTRA global @lseekset$qiui:near - proc @lseekset$qiui near - - xchg ax,bx ; fd - xor cx,cx ; sz hi +@lseekset$qiui: + mov bl,0 + jmp lseek0x lseekset: - clc - db 0B0h ; mov al,im -; global rewind:near -rewind: ; rewind(bx) - stc - mov ax,4200h - jnc dos + mov bl,0 + jmp lseekx + endif +rewind: ; rewind(ax) + mov bl,0 lseek0: ; lseek0(bx,ax=dir) - cwd + xor dx,dx +lseek0x: xor cx,cx +lseekx: + xchg ax,bx +lseek: + mov ah,42h jmp dos - endp @lseekset$qiui + endp @lseekcur$qii ifdef EXTRA @@ -483,8 +497,7 @@ jc @@die mov [(image_himem di).fd],ax mov [(image_himem di).fd2close],ax - xchg ax,bx - mov ax,4202h ; SEEK_END + mov bl,02h ; SEEK_END call lseek0 @@die: mov bx,[(image_himem di).errmsg] diff -r 25e3f390625a -r c836f6d2eff8 linld/stuff/src/CRTL.H --- a/linld/stuff/src/CRTL.H Thu Nov 29 13:49:52 2018 +0100 +++ b/linld/stuff/src/CRTL.H Fri Nov 30 15:12:24 2018 +0100 @@ -35,7 +35,7 @@ extern _fastcall int open(const char* name); extern _fastcall int close(int fd); extern _fastcall int read(int fd, void* data, int sz); -extern _fastcall long lseekset(int fd, unsigned sz); +extern _fastcall long lseekcur(int fd, int where); extern _fastcall int puts(const char* s); extern pascal unsigned long strtol(const char *s); diff -r 25e3f390625a -r c836f6d2eff8 linld/stuff/src/CRTLX.H --- a/linld/stuff/src/CRTLX.H Thu Nov 29 13:49:52 2018 +0100 +++ b/linld/stuff/src/CRTLX.H Fri Nov 30 15:12:24 2018 +0100 @@ -1,5 +1,6 @@ // This file is distributed under GPL // +extern _fastcall long lseekset(int fd, unsigned sz); extern _fastcall void strcpy(const char* a,const char* b); extern _fastcall void strcat(const char* a,const char* b); extern _fastcall int strcmp(const char* a,const char* b); diff -r 25e3f390625a -r c836f6d2eff8 linld/stuff/src/LOAD.CPP --- a/linld/stuff/src/LOAD.CPP Thu Nov 29 13:49:52 2018 +0100 +++ b/linld/stuff/src/LOAD.CPP Fri Nov 30 15:12:24 2018 +0100 @@ -142,17 +142,15 @@ struct kernelparams_t *kernelparams; kernelparams = &(((first1k_t*) (rm_buf = (u8 *)malloc_or_die(_32k)))->params); #define first1k ((first1k_t*)((u8 *)kernelparams-0x1F1)) - { - u16 rm_seek; do { // Do not use malloc below until heap_top adjustment (see <*>) - if (read(m->fd, rm_buf, rm_seek=0x400) == 0x400) { + if (read(m->fd, rm_buf, 0x200) == 0x200) { + lseekcur(m->fd,-0x200); if(kernelparams->setup_sects == 0) { #if 1 if(* (int *) &first1k->pad10[0x3F-0x24] == 0x3AE8) { - lseekset(m->fd,rm_seek=0x200); csip+=0xFFE00042; } else @@ -163,17 +161,14 @@ kernelparams->boot_flag != 0xAA55) die("Not a kernel"); heap_top = rm_buf+(rm_size=0x200*(kernelparams->setup_sects+1)); // <*> + m->size -= rm_size; + m->chunk_size -= rm_size; // Read remaining rm loader - - { - u16 cnt = rm_size-rm_seek; - if (read(m->fd, rm_buf+rm_seek, cnt) == cnt) break; - } + if (read(m->fd, rm_buf, rm_size) == rm_size) break; } die(kernel_file_error); } while (0); - } // Tell rm loader some info @@ -225,10 +220,8 @@ { struct image_himem *m = ± - m->fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4); - m->size -= rm_size; - m->chunk_size -= rm_size; - if((u16)((m->fallback+m->size)>>4) > topseg() || pm_high) { + if((u16)(((m->fallback=(u32((u16(_CS)+0x1FFF)&0xF000)<<4))+m->size)>>4) > + topseg() || pm_high) { m->fallback = base_himem; } @@ -252,7 +245,7 @@ open_image(initrd_name, m); - if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK)) < m[-1].fallback+m[-1].size) { + if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK))-m[-1].fallback < m[-1].size) { close(m->fd); puts(m->errmsg); return; diff -r 25e3f390625a -r c836f6d2eff8 linld/stuff/src/pipehole.awk --- a/linld/stuff/src/pipehole.awk Thu Nov 29 13:49:52 2018 +0100 +++ b/linld/stuff/src/pipehole.awk Fri Nov 30 15:12:24 2018 +0100 @@ -36,7 +36,7 @@ } else if (hold == 3) { hold=0 - if (/^ add [abcds][ix],/ || /^ sub [abcds][ix],/) { + if (/^ add [abcds][ix],/) { split($2,regs2,",") if (regs[1] == regs2[1] && (regs2[2] == "offset" || isnum(regs2[2]))) { t=$0; sub(/mov/,$1,s) @@ -118,6 +118,13 @@ print " and " substr(args[1],2) "," args[2]; next } } + if (/^ add [bcd]x,/ || /^ sub [bcd]x,/) { + split($0,args,",") + if (isnum(args[2]) && (args[2] % 256 == 0)) { + sub(/x,/,"h,",s) + print s "/256"; next + } + } if (/^ add word ptr/ || /^ sub word ptr/) { split($0,args,",") if (isnum(args[2]) && (args[2] % 256 == 0)) {