# HG changeset patch # User Pascal Bellard # Date 1546966311 -3600 # Node ID 57d97be431f44ca0b52044e07fd7c08d1e88a77a # Parent 251d56fab8e3ecdb26dcd003bf42484c79ceee43 linld: fix open() diff -r 251d56fab8e3 -r 57d97be431f4 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Sat Jan 05 17:29:09 2019 +0100 +++ b/linld/stuff/src/CRTL.ASM Tue Jan 08 17:51:51 2019 +0100 @@ -204,6 +204,7 @@ xor cx,cx ; attributes xor di,di ; alias hint cwd ; action = open + stc int 21h pop si di bx jnc doret @@ -338,7 +339,7 @@ isolseek: extrn _isostate:isostate mov ax,[_isostate.fd] - global @lseekset2$qipul + global @lseekset2$qipul:near @lseekset2$qipul: mov dx,[bx] mov cx,[bx+2] diff -r 251d56fab8e3 -r 57d97be431f4 linld/stuff/src/LOAD.CPP --- a/linld/stuff/src/LOAD.CPP Sat Jan 05 17:29:09 2019 +0100 +++ b/linld/stuff/src/LOAD.CPP Tue Jan 08 17:51:51 2019 +0100 @@ -114,7 +114,6 @@ u16 rm_size; static u8 pm_high; // @ = @rm_size + 2, see JUMP.ASM static u8* rm_buf; // @ = @rm_size + 3, see JUMP.ASM -u32 base_himem = _1m+_64k; struct image_himem imgs[2]; // register value to launch the kernel real mode code @@ -125,15 +124,15 @@ u32 csip=0x90200000; #define topseg() 0x9000 #endif +u32 base_himem = _1m+_64k; static const char kernel_file_error[] = "Can't use kernel file"; char* load_kernel() { struct image_himem *m = ± -#define _base_himem (((u32*)(m))[-1]) -#define _rm_buf(m) (((u8**)(m))[-3]) -#define _pm_high (((u8*)(m))[-7]) -#define _rm_size (*(u16*)((u8*)(m)-9)) +#define _rm_buf(m) (((u8**)(m))[-1]) +#define _pm_high (((u8*)(m))[-3]) +#define _rm_size (*(u16*)((u8*)(m)-5)) #ifdef NO386 #define _csip (*(u32*)(m+2)) *((u16 *)&csip+1)=topseg()+0x20; @@ -229,7 +228,7 @@ struct image_himem *m = ± if((u16)(((m->fallback=(u32((u16(_CS)+0x1FFF)&0xF000)<<4))+m->size)>>4) > topseg() || _pm_high) { - m->fallback = _base_himem; + m->fallback = base_himem; } load_image(m); @@ -237,8 +236,22 @@ return version_string; } +struct initrdparams_t { + u32 header; // 0202 Magic signature "HdrS" + u16 version; // 0206 Boot protocol version supported + u16 realmode_switch_ofs; // 0208 Hook called just before rm->pm + u16 realmode_switch_seg; + u16 start_sys_seg; // 020E + u16 kernel_version; // 020C Points to kernel version string + u8 type_of_loader; // 0210 Boot loader identifier + u8 loadflags; // 0211 Boot protocol option flags + u16 setup_move_size;// 0212 Move to high memory size (used with hooks) + u32 code32_start; // 0214 Boot loader hook (see below) + u32 initrd_buf; // 0218 initrd load address (set by boot loader) + u32 initrd_size; // 021C initrd size (set by boot loader) +}; + // Read initrd if needed - void load_initrd() { struct image_himem *m = &initrd; if (!initrd_name && !m->fd) return; @@ -259,9 +272,10 @@ } load_image(m); - struct kernelparams_t *kernelparams = &(((first1k_t*) _rm_buf(m-1))->params); - if(kernelparams->header == HdrS) { - kernelparams->initrd_buf = m->fallback; - kernelparams->initrd_size = m->size; + + struct initrdparams_t *initrdparams = ((struct initrdparams_t *)&(((first1k_t*) _rm_buf(m-1))->params.header)); + if(initrdparams->header == HdrS) { + initrdparams->initrd_buf = m->fallback; + initrdparams->initrd_size = m->size; } } diff -r 251d56fab8e3 -r 57d97be431f4 linld/stuff/src/pipehole.awk --- a/linld/stuff/src/pipehole.awk Sat Jan 05 17:29:09 2019 +0100 +++ b/linld/stuff/src/pipehole.awk Tue Jan 08 17:51:51 2019 +0100 @@ -2,6 +2,7 @@ function isnum(n) { return match(n,/^[0-9+-]/) } { sub(/segment word public/,"segment byte public") + if (hold == 0) { s=$0 if (/^ mov .[ix],bx$/ || /^ mov .[ix],.i$/) { @@ -27,6 +28,13 @@ if (/^ cmp word ptr DGROUP:.*,0$/) { hold=8; split($2,regs,","); next } + if (/^ cbw/) { hold=11; kept=0; next } + if (/^ add [abcds][ix],2$/) { + split($2,regs,","); hold=12; next + } + if (/^ sub [abcds][ix],2$/) { + split($2,regs,","); hold=13; next + } } else if (hold == 1) { if (/^ ;/) { line[kept++]=$0; next } @@ -130,6 +138,39 @@ } for (i = 0; i < kept; i++) print line[i] } + else if (hold == 11) { + if (/^ inc ax$/ || /^ dec ax$/) { + line[kept++]=$0; next + } + split($2,args,",") + if (/^ mov cl,/) { + split($2,args,",") + if (args[2] >= 8) { + line[kept++]=$0; next + } + } + if (!/^ shl ax,/ || (args[2] != "cl" && args[2] < 8)) { + print " cbw " + } + for (i = 0; i < kept; i++) print line[i] + hold=kept=0 + } + else if (hold == 12) { + hold=0 + if ($1 != "adc" && $1 != "sbb" && ! /^ jn?[abc]/) { + print " inc " regs[1] + print " inc " regs[1] + } + else print " add " regs[1] ",2" + } + else if (hold == 13) { + hold=0 + if ($1 != "adc" && $1 != "sbb" && ! /^ jn?[abc]/) { + print " dec " regs[1] + print " dec " regs[1] + } + else print " sub " regs[1] ",2" + } s=$0 # These optimisation may break ZF or CF if (/^ sub sp,2$/) { print " push ax"; next }