# HG changeset patch # User Pascal Bellard # Date 1481046584 -3600 # Node ID 31c5cbbd93809ec427b0b1f2ea4a80b33f05402c # Parent de3143af6c92779d993254144717e5de86b641b4 linld/tazboot: default conf in tazboot.cmd diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/CRTL.ASM Tue Dec 06 18:49:44 2016 +0100 @@ -12,17 +12,18 @@ segment _DATA byte public use16 'DATA' -msg_hang db "High mem corrupted - not exiting to DOS",0 + global _heap_top:word + extrn _bss_end +_heap_top dw _bss_end +msg_hang db "High mem corrupted - not exiting to DOS" +msg_crlf db 13,10,0 vcpi_alloc_err db "vcpi " msg_malloc db "malloc() failure",0 -msg_crlf db 13,10,0 ends _DATA segment _BSS byte public use16 'BSS' - global _heap_top:word -_heap_top dw ? global _no_exit:byte _no_exit db ? filecnt db ? ; in fact 0 minus file count... @@ -187,21 +188,19 @@ ;*************************************************************** -;int open(const char* name, int flags); +;int open(const char* name, int flags=O_RDONLY); ;*************************************************************** global _open:near proc _open near - pop cx ;caller return address + pop ax ;caller return address pop bx ; name - pop ax ; flags + push bx push ax - push bx - push cx - global open:near ; open(bx,al) + global open:near ; open(bx) open: mov dx,bx - mov ah,3dh + mov ax,3d00h dos: int 21h chkc: @@ -431,6 +430,19 @@ endp _die +struc image_himem ;struct image_himem { +fd dw ? ; 0 int fd; +fallback dd ? ; 2 u32 fallback; +size dd ? ; 6 u32 size; +remaining dd ? ;10 u32 remaining; +buf dd ? ;14 u32 buf; +bufv dw ? ;18 u32 *bufv; +errmsg dw ? ;20 char *errmsg; +chunk_size dd ? ;22 u32 chunk_size; +next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *); +state dw ? ;28 u16 state; +fd2close dw ? ;30 u16 fd2close; +ends ;}; ;*************************************************************** ;u32* malloc_bufv_or_die(struct image_himem *m); @@ -444,7 +456,7 @@ push bx push si xchg ax,si - mov ecx,[si+6] ; m->size + mov ecx,[(image_himem si).size] dec ecx shr ecx,12 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE; @@ -457,7 +469,7 @@ pop cx push cx ; _sort:nel push ax ; _sort:base - mov [si+18],ax ; m->bufv + mov [(image_himem si).bufv],ax xchg ax,bx @@vcpi_alloc: xor edx,edx @@ -489,8 +501,8 @@ shl bx,2 add bx,ax ; m->bufv mov edx,[bx] ; m->bufv[i] - sub edx,[si+2] ; m->fallback - cmp edx,[si+6] ; m->size + sub edx,[(image_himem si).fallback] + cmp edx,[(image_himem si).size] jae @@chknext shr edx,12 cmp dx,cx @@ -524,7 +536,7 @@ push bx push si di xchg ax,di - mov bx,[di] ; m->fd + mov bx,[(image_himem di).fd] call close ifndef NO386 xor eax,eax @@ -532,8 +544,8 @@ xor ax,ax endif cwd - mov [di],ax ; m->fd - mov bx,[di+28] ; m->state + mov [(image_himem di).fd],ax + mov bx,[(image_himem di).state] cmp al,[bx] ; "" jz @@end mov si,bx @@ -546,16 +558,15 @@ jnz @@scan dec cx @@eos: - mov [di+28],cx ; m->state + mov [(image_himem di).state],cx dec si push [word si] mov [byte si],dl ; set temp eos - xchg ax,dx ; O_RDONLY call open pop [word si] ; restore string jc @@die - mov [di],ax ; m->fd - mov [di+30],ax ; m->fd2close + mov [(image_himem di).fd],ax + mov [(image_himem di).fd2close],ax mov dx,2 ; SEEK_END xchg ax,bx ifndef NO386 @@ -566,9 +577,9 @@ endif call lseek @@die: - mov bx,[di+20] ; m->errmsg + mov bx,[(image_himem di).errmsg] jc die - mov bx,[di] ; m->fd + mov bx,[(image_himem di).fd] ifndef NO386 push eax xor ecx,ecx @@ -576,7 +587,7 @@ call lseek ; rewind pop eax @@end: - mov [di+22],eax ; m->chunk_size + mov [(image_himem di).chunk_size],eax else push ax push dx @@ -587,8 +598,8 @@ pop dx pop ax @@end: - mov [di+22],ax ; m->chunk_size - mov [di+24],dx + mov [word (image_himem di).chunk_size],ax + mov [word ((image_himem di).chunk_size)+2],dx endif pop di si ret @@ -598,19 +609,6 @@ ;*************************************************************** ;void open_image(const char *name, struct image_himem *m); -;struct image_himem { -; 0 int fd; -; 2 u32 fallback; -; 6 u32 size; -;10 u32 remaining; -;14 u32 buf; -;18 u32 *bufv; -;20 char *errmsg; -;22 u32 chunk_size; -;26 void (*next_chunk)(struct image_himem *); -;28 u16 state; -;30 u16 fd2close; -;}; ;*************************************************************** global _open_image:near proc _open_image near @@ -627,25 +625,25 @@ xor ax,ax ; 1st loop flag + eos endif mov di,[m] - cmp [di],ax ; m->fd + cmp [(image_himem di).fd],ax jnz @@alreadydone ifndef NO386 - mov [di+6],eax ; m->size = 0L + mov [(image_himem di).size],eax ; m->size = 0L else - mov [di+6],ax ; m->size = 0L - mov [di+8],ax + mov [word (image_himem di).size],ax ; m->size = 0L + mov [word ((image_himem di).size)+2],ax endif - mov [word di+26],offset _next_chunk + mov [(image_himem di).next_chunk],offset _next_chunk mov si,[fname] - mov [di+28],si ; m->state + mov [(image_himem di).state],si @@next: push di - call [word di+26] ; m->next_chunk() + call [(image_himem di).next_chunk] ; m->next_chunk() pop di ifndef NO386 add eax,3 and al,0FCh - add [di+6],eax ; m->size += m->chunk_size + add [(image_himem di).size],eax ; m->size += m->chunk_size or eax,eax jnz @@next else @@ -654,14 +652,14 @@ add ax,3 adc dx,0 and al,0FCh - add [di+6],ax ; m->size += m->chunk_size - adc [di+8],dx + add [word (image_himem di).size],ax ; m->size += m->chunk_size + adc [word ((image_himem di).size)+2],dx inc cx ; jcxnz loop @@next endif - mov [di+28],si ; m->state + mov [(image_himem di).state],si push di - call [word di+26] ; m->next_chunk() + call [(image_himem di).next_chunk] ; m->next_chunk() pop di @@alreadydone: push ax @@ -698,17 +696,17 @@ xor ecx,ecx mov cx,[word sz] @@chksz: - mov eax,[di+22] ; m->chunk_size + mov eax,[(image_himem di).chunk_size] cmp ecx,eax jb @@szok xchg eax,ecx else mov cx,[word sz] @@chksz: - mov ax,[di+22] ; lo m->chunk_size + mov ax,[word (image_himem di).chunk_size] cmp cx,ax jb @@szok - cmp [word di+24],0 ; hi m->chunk_size + cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size jne @@szok xchg ax,cx endif @@ -727,13 +725,13 @@ ifndef NO386 cwde ; ax < 8000h cwd - sub [di+22],eax + sub [(image_himem di).chunk_size],eax else cwd ; ax < 8000h - sub [di+22],ax - sbb [di+24],dx + sub [word (image_himem di).chunk_size],ax + sbb [word ((image_himem di).chunk_size)+2],dx jnz @@fill - cmp [di+22],dx + cmp [word (image_himem di).chunk_size],dx endif jnz @@fill dec cx @@ -746,16 +744,16 @@ jmp @@fill @@filled: ifndef NO386 - sub [di+10],eax ; m->remaining + sub [(image_himem di).remaining],eax else - sub [di+10],ax ; m->remaining - sbb [di+12],dx + sub [word (image_himem di).remaining],ax + sbb [word ((image_himem di).remaining)+2],dx endif add [bp-4-2],ax add [word data],ax sub [word sz],ax pushf - and cx,[di+26] ; m->next_chunk + and cx,[(image_himem di).next_chunk] jz @@same_chunk push di call cx ; m->next_chunk() diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/CRTL.H --- a/linld/stuff/src/CRTL.H Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/CRTL.H Tue Dec 06 18:49:44 2016 +0100 @@ -37,7 +37,8 @@ extern "C" char* strcatb(const char* a,const char* b); extern "C" int strhead(const char* a,const char* b); extern "C" int fileattr(const char* name); -extern "C" int open(const char* name, int flags); +//extern "C" int open(const char* name, int flags); +extern "C" int open(const char* name); extern "C" int close(int fd); extern "C" void exit(int n); extern "C" void abort(); diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/CRTLX.ASM --- a/linld/stuff/src/CRTLX.ASM Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/CRTLX.ASM Tue Dec 06 18:49:44 2016 +0100 @@ -11,6 +11,9 @@ assume cs:DGROUP,ds:DGROUP segment _DATA byte public use16 'DATA' + +tazboot_cmd db "tazboot.cmd",0 + ends _DATA segment _BSS byte public use16 'BSS' @@ -96,14 +99,13 @@ pushf ; Check for oldies - mov ax, 0F000h - push ax ; < 286 : flags[12..15] are forced 1 + mov bh, 0F0h + push bx ; < 286 : flags[12..15] are forced 1 popf ; = 286 : flags[12..15] are forced 0 pushf ; > 286 : only flags[15] is forced 0 pop dx popf - add dh,ah ; NS=386+, NC=286 - cbw + add dh,bh ; NS=386+, NC=286 clc js @@bad ;it is a 86/186/286, not a 386+ pushfd @@ -121,7 +123,6 @@ jnc @@bad mov eax,80000001h ; Extended Processor Info and Feature Bits db 0Fh,0A2h ; cpuid - xor ax,ax shr edx,1+29 ; LM feature bit ? @@bad: sbb ax,ax @@ -323,10 +324,31 @@ pop ax pop dx pop di si bp +kver2ulret: ret endp _kver2ul + +;*************************************************************** +;void try_default_args(); +;*************************************************************** + global _try_default_args:near + proc _try_default_args near + + mov bx,offset tazboot_cmd + extrn open:near + call near open + jc kver2ulret + mov cx,4096 + extrn _heap_top:word + mov di,[_heap_top] + push cx + extrn read_cmdline:near + jmp near read_cmdline ; read_cmdline(ax,di,cx) + + endp _try_default_args + ends _TEXT end diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/CRTLX.H --- a/linld/stuff/src/CRTLX.H Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/CRTLX.H Tue Dec 06 18:49:44 2016 +0100 @@ -10,3 +10,5 @@ extern "C" int chdirname(char *path); extern "C" unsigned long kver2ul(char *kernel_version); extern "C" char *ultoa(unsigned long n); +extern "C" void try_default_args(); + diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/HIMEM.CPP --- a/linld/stuff/src/HIMEM.CPP Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/HIMEM.CPP Tue Dec 06 18:49:44 2016 +0100 @@ -24,7 +24,7 @@ u8 xfer_buf[PAGE_SIZE]; u16 size = read_image(m, xfer_buf, PAGE_SIZE); if(s16(size) <= 0) break; - memcpy32(*bufv, seg(xfer_buf), ofs(xfer_buf), size); + memcpy32(*bufv, seg(xfer_buf), ofs(xfer_buf), PAGE_SIZE); if (bufv != &buf) bufv++; buf += size; } while (*bufv); diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/ISO9660.CPP --- a/linld/stuff/src/ISO9660.CPP Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/ISO9660.CPP Tue Dec 06 18:49:44 2016 +0100 @@ -42,7 +42,8 @@ int isoreset(char *name) { if (name) - isofd = open(name, O_RDONLY); + //isofd = open(name, O_RDONLY); + isofd = open(name); if (!readsector(16UL * 2048) || strhead(buffer+1,"CD001")) { //close(isofd); return -1; diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/MEMCPY32.ASM --- a/linld/stuff/src/MEMCPY32.ASM Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/MEMCPY32.ASM Tue Dec 06 18:49:44 2016 +0100 @@ -11,114 +11,11 @@ assume cs:DGROUP,ds:DGROUP segment _DATA byte public use16 'DATA' -msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager",0 -msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0 ends _DATA segment _TEXT byte public use16 'CODE' ;*************************************************************** -;int _is_vm86(); -;****** Return: AX=1 - it is a 386+ in virtual86 mode with vcpi -;****** AX=0 - it is a 386+ in real mode -;****** otherwise abort program -;****** Uses: Flags -;*************************************************************** - global _is_vm86:near - proc _is_vm86 near - -; Check for oldies - mov ah, 0F0h - pushf - push ax ; < 286 : flags[12..15] are forced 1 - popf ; = 286 : flags[12..15] are forced 0 - pushf ; > 286 : only flags[15] is forced 0 - pop dx - popf - add dh,ah ; NS=386+, NC=286 - ifndef NO386 - js @@no_vcpi ;it is a 86/186/286, not a 386+ - else - js @@ret - endif -; Check for vm - smsw ax ;SMSW cannot be trapped! :-) - and ax,1 ;MSW_PE -; We're in vm - jnz check_vcpi - -; It's a 386 in real mode, chk for paging (crazy but possible) - mov edx,cr0 - shl edx,1 ;CR0_PG to CF - jc @@no_vcpi -@@ret: - ret - -;*************************************************************** -;****** Helper: checks for vcpi -;*************************************************************** -label check_vcpi near - push ds -; Check whether it is safe to call 67h (we trust only known EMM managers) - push 0 - pop ds - mov ds,[word 67h*4+2] - cmp [dword 10+4],'0XXX' - jne @@skip - mov eax,'XMME' - xor eax,[dword 10] - ; QMME also works (as told by ) - shl eax,8 -@@skip: - pop ds - jne @@no_vcpi - -; Check emm manager status and version - mov ah,40h ; get status - int 67h - test ah,ah - jnz @@no_vcpi - mov ah,46h ; get version - int 67h - test ah,ah - jnz @@no_vcpi - cmp al,40h ; version must be >= 4.0 - jb @@no_vcpi -; Check vcpi manager status - ;;mov ax,5A01h ; ALLOCATE RAW PAGES - ;;mov bx,4 - ;;int 67h - ;;test ah,ah - ;;jnz @@no_vcpi - ;;push dx ;$ save handle - mov ax,0DE00h ; check for vcpi present - int 67h - mov al,1 - test ah,ah - jz @@386vcpi - ;;pop dx ;$ handle - ;;mov ax,4500h ; DEALLOCATE PAGES - ;;int 67h -@@no_vcpi: - mov bx,offset msg_badcpu - extrn die:near -godie: - jmp near die -@@386vcpi: - mov [_vcpi],al - extrn prepare_vcpi:near - call prepare_vcpi -; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping"); - ;extrn _get_vcpi_interface:near - ;call _get_vcpi_interface - mov bx,offset msg_badmapping - jz godie - ret - - endp _is_vm86 - - -;*************************************************************** ;void dos_shutdown() ;*************************************************************** global dos_shutdown:near @@ -386,9 +283,6 @@ ; base_med P S D A G ??l_hi base_hi ; Pl E W D - global _vcpi:byte -_vcpi db 0 - endp _memcpy32 ifdef NO386 diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/TAZBOOT.CPP --- a/linld/stuff/src/TAZBOOT.CPP Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/TAZBOOT.CPP Tue Dec 06 18:49:44 2016 +0100 @@ -144,11 +144,9 @@ char *iso = NULL; argv[0] = progname(); bootiso(argv); // iso ? parsing is /init.exe stuff ! - if (argc >= 2) - bootiso(argv + 1); - chdirname(*argv); if (argc < 2) { + try_default_args(); dousage: die("Usage: tazboot [[@commands]|[-f][kernel=] \ [initrd=[,...]] [bootfrom=] ...]\r\n\n\ @@ -161,8 +159,12 @@ kernel=\\slitaz\\elks\r\n\ root=/dev/bda1 ro\r\n"); } + bootiso(argv + 1); + chdirname(*argv); for (int i=0;;) { - char *s=*++argv; + char *s; + argv++; + s=*argv; i++; if (!s) break; if (strhead(s,"kernel=") == 0) { diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/VCPI.ASM --- a/linld/stuff/src/VCPI.ASM Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/VCPI.ASM Tue Dec 06 18:49:44 2016 +0100 @@ -203,6 +203,9 @@ mov [bx+pagedir_ofs-page0_laddr],ax sub ax,si ;ax-=1000 mov [bx+page0_ofs-page0_laddr],ax + push ds + pop es + mov di,ax ;ES:DI => page0 ; Return ;pop es ;pop esi @@ -227,9 +230,9 @@ ; Get and save VCPI pm interface mov si,offset gdt_vcpi ;DS:DI => 3 GDT entries for VCPI - mov di,[si+page0_ofs-gdt_vcpi] ;ES:DI => page0 - push ds - pop es + ;mov di,[si+page0_ofs-gdt_vcpi] ;ES:DI => page0 + ;push ds + ;pop es mov ax,0DE01h ;get vcpi pm interface int 67h mov [vcpi_pm_entry],ebx diff -r de3143af6c92 -r 31c5cbbd9380 linld/stuff/src/_BEG.ASM --- a/linld/stuff/src/_BEG.ASM Tue Dec 06 15:51:50 2016 +0200 +++ b/linld/stuff/src/_BEG.ASM Tue Dec 06 18:49:44 2016 +0100 @@ -15,23 +15,115 @@ org 100h global _text_start:byte label _text_start byte - extrn _bss_end + ;*************************************************************** ; clear bss ;*************************************************************** - xor ax,ax - mov di,offset _bss_start + mov bx,offset _bss_start clearbss: - mov [di],al - inc di - cmp di,sp ; clear bss + heap - jbe clearbss - mov di,offset _bss_end + mov [byte bx],0 ; clear bss + heap + sp + inc bx + jne clearbss + +;*************************************************************** +; check CPU +;*************************************************************** + +; Check for oldies + mov bh, 0F0h + pushf + push bx ; < 286 : flags[12..15] are forced 1 + popf ; = 286 : flags[12..15] are forced 0 + pushf ; > 286 : only flags[15] is forced 0 + pop dx + popf + add dh,bh ; NS=386+, NC=286 + ifndef NO386 + js no_vcpi ;it is a 86/186/286, not a 386+ + else + js endcpu + endif +; Check for vm + smsw ax ;SMSW cannot be trapped! :-) + and ax,1 ;MSW_PE +; We're in vm + jnz check_vcpi + +; It's a 386 in real mode, chk for paging (crazy but possible) + mov edx,cr0 + shl edx,1 ;CR0_PG to CF + jc no_vcpi + jmp endcpu + +;*************************************************************** +; checks for vcpi +;*************************************************************** +label check_vcpi near + push ds +; Check whether it is safe to call 67h (we trust only known EMM managers) + push 0 + pop ds + mov ds,[word 67h*4+2] + cmp [dword 10+4],'0XXX' + jne skip + mov eax,'XMME' + xor eax,[dword 10] + ; QMME also works (as told by ) + shl eax,8 +skip: + pop ds + jne no_vcpi + +; Check emm manager status and version + mov ah,40h ; get status + int 67h + test ah,ah + jnz no_vcpi + mov ah,46h ; get version + int 67h + test ah,ah + jnz no_vcpi + cmp al,40h ; version must be >= 4.0 + jb no_vcpi +; Check vcpi manager status + ;;mov ax,5A01h ; ALLOCATE RAW PAGES + ;;mov bx,4 + ;;int 67h + ;;test ah,ah + ;;jnz no_vcpi + ;;push dx ;$ save handle + mov ax,0DE00h ; check for vcpi present + int 67h + mov al,1 + test ah,ah + jz is386vcpi + ;;pop dx ;$ handle + ;;mov ax,4500h ; DEALLOCATE PAGES + ;;int 67h +no_vcpi: + mov bx,offset msg_badcpu + extrn die:near +godie: + jmp near die +is386vcpi: + mov [_vcpi],al + extrn prepare_vcpi:near + call prepare_vcpi +; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping"); + ;extrn _get_vcpi_interface:near + ;call _get_vcpi_interface + mov bx,offset msg_badmapping + jz godie +endcpu: + ;*************************************************************** ; build argv & argc ;*************************************************************** -; push ax ; envp (int 20h do it for us) - ;mov [word di],ax ; argv[0] = 0 + extrn _heap_top:word + mov di,[_heap_top] + ;xor ax,ax + ;push ax ; envp (already cleared) + ;mov [word di],ax ; argv[0] = 0 (idem) mov si,80h cld lodsb @@ -39,6 +131,7 @@ jbe alok mov al,7Eh alok: + cbw xchg ax,bx mov [bx+si],bh ; set eos argbuild: @@ -73,9 +166,8 @@ jmp arglp argdone: ;mov [word bx+di],0 ; argv[argc] = 0 - lea si,[bx+di+2] - extrn _heap_top:word - mov [_heap_top],si + lea ax,[bx+di+2] + mov [_heap_top],ax push di ; argv shr bx,1 push bx ; argc @@ -83,11 +175,13 @@ mov bx,[di+2] ; argv[1] cmp [byte bx],'@' jne argend - inc bx ; al=0 RDONLY + inc bx extrn open:near call near open jc argend pop bx ; trash argc, argv >> 1Kb ! + global read_cmdline:near +read_cmdline: push di push ax extrn _read:near @@ -103,10 +197,6 @@ endif ;*************************************************************** - extrn _is_vm86:near - call _is_vm86 ; load_image needs that - -;*************************************************************** extrn _main:near call _main @@ -120,6 +210,11 @@ segment _DATA byte public use16 'DATA' global _data_start:byte label _data_start byte +msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager" + global _vcpi:byte +_vcpi db 0 +msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0 + ends _DATA segment _BSS byte public use16 'BSS'