# HG changeset patch # User Pascal Bellard # Date 1484558115 -3600 # Node ID 38eb1fe036b454be5db8c33e199d0fb76249a90a # Parent 7c138665bd75142cf93fe2feaea0670284fe516c linld: some fixes for strtoul diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/CRTL.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -39,6 +39,7 @@ ;*************************************************************** ;char* strcpy(const char* a, const char* b); ;char* strcat(const char* a, const char* b); +;char* strcatb(const char* a, const char* b); ;*************************************************************** global _strcpy:near proc _strcpy near @@ -48,7 +49,10 @@ global _strcat:near _strcat: mov dl,1 -cat: + db 0bbh ; mov bx,imm opcode + global _strcatb:near +_strcatb: + mov dl,3 pop ax ;caller return address pop cx ; a pop bx ; b @@ -86,18 +90,6 @@ ;*************************************************************** -;char* strcatb(const char* a, const char* b); -;*************************************************************** - global _strcatb:near - proc _strcatb near - - mov dl,3 - jmp cat - - endp _strcatb - - -;*************************************************************** ;void* malloc(unsigned sz); ;*************************************************************** global _malloc:near @@ -129,7 +121,6 @@ ;*************************************************************** ;void puts(const char* s): -;void putsz(const char* s): ;*************************************************************** global _puts:near proc _puts near @@ -142,14 +133,7 @@ puts: call putsz mov bx,offset msg_crlf - jmp putsz - global _putsz:near -_putsz: - pop ax ;caller return address - pop bx ; s - push bx - push ax global putsz:near ; putsz(bx) putsz: push bx @@ -243,7 +227,7 @@ proc _read near stc - db 73h ; jnc + db 0B0h ; mov al,im global _write:near clc pop ax ;caller return address @@ -256,7 +240,6 @@ push ax mov ah,40h sbb ah,0 - clc jcxz fail jmp dos @@ -280,8 +263,10 @@ global lseekset:near lseekset: clc + db 0B0h ; mov al,im global rewind:near -rewind: ; rewind(bx,C=1) +rewind: ; rewind(bx) + stc mov ax,4200h jnc dos lseek0: ; lseek0(bx,ax=dir) @@ -326,24 +311,23 @@ proc _strhead near pop cx ;caller return address - pop ax ; a - pop bx ; b + pop bx ; a + pop ax ; b + push ax push bx - push ax push cx @@loop: + xchg ax,bx mov cl,[bx] ; cl = *b++ inc bx or cl,cl ; clear C jz fail ; return 0 xchg ax,bx xor cl,[bx] ; cl -= *a++ + inc bx and cl,0dfh ; case insensitive - stc - jnz fail ; return -1 - inc bx - xchg ax,bx - jmp @@loop + jz @@loop + ret ; return b (is not 0) endp _strhead @@ -653,12 +637,11 @@ global _reset_bufv:near proc _reset_bufv near - pop bx ;caller return address - pop ax + pop ax ;caller return address + pop bx + push bx push ax - push bx - mov [curdata],ax - xchg ax,bx + mov [curdata],bx and [dword (data_himem bx).cacheidx],0 ret @@ -725,7 +708,7 @@ ;*************************************************************** -;void next_chunk(struct image_himem *m); +;void next_chunk(struct image_himem *di); ;*************************************************************** proc next_chunk near @@ -770,7 +753,6 @@ mov bx,[(image_himem di).fd] ifndef NO386 push eax - stc call rewind pop eax @@end: @@ -778,7 +760,6 @@ else push ax push dx - stc call rewind pop dx pop ax @@ -909,7 +890,6 @@ xor cx,cx ifndef NO386 cwde ; ax < 8000h - cwd sub [(image_himem di).chunk_size],eax else cwd ; ax < 8000h @@ -963,29 +943,30 @@ push cx push ax xor ebx,ebx - jcxz @@jncend push si + jcxz @@end mov si,cx xor ecx,ecx xor eax,eax lodsb - mov dl,20h - or dl,al - cmp dl,'n' ; vga=normal + mov dx,ax + or al,20h + cmp al,'n' ; vga=normal je @@vga dec cx - cmp dl,'e' ; vga=extended + cmp al,'e' ; vga=extended je @@vga dec cx - cmp dl,'a' ; vga=ask + cmp al,'a' ; vga=ask jne @@notvga @@vga: dec cx xchg ax,cx cwd - jmp popsiret + jmp @@popsiret @@notvga: mov cx,10 ; radix + xchg ax,dx cmp al,'+' je @@radixskip cmp al,'-' @@ -1000,19 +981,18 @@ jne @@radixok mov cl,8 lodsb - mov dl,20h - or dl,al - cmp dl,'x' + or al,20h + cmp al,'x' jne @@radixok mov cl,16 @@strtollp: lodsb @@radixok: + or al,20h sub al,'0' jb @@endstrtol cmp al,9 jbe @@digitok - or al,20h cmp al,'a'-'0' jb @@endstrtol sub al,'a'-'0'-10 @@ -1038,14 +1018,13 @@ shl ebx,cl @@noshift: popf -@@jncend: jnc @@end neg ebx @@end: push ebx pop ax pop dx -popsiret: +@@popsiret: pop si else pop ax ;caller return address @@ -1056,29 +1035,28 @@ push di xor ax,ax cwd + jcxz @@goend xchg ax,di - jcxz @@goend mov si,cx lodsb - mov dl,20h - or dl,al + mov bx,ax + or al,20h mov cx,-1 - cmp dl,'n' ; vga=normal + cmp al,'n' ; vga=normal je @@vga dec cx - cmp dl,'e' ; vga=extended + cmp al,'e' ; vga=extended je @@vga dec cx - cmp dl,'a' ; vga=ask + cmp al,'a' ; vga=ask jne @@notvga @@vga: xchg ax,cx - cwd - jmp popsiret @@goend: - jmp @@end + jmp @@popdisiret @@notvga: mov cx,10 ; radix + xchg ax,bx cmp al,'+' je @@radixskip cmp al,'-' @@ -1093,19 +1071,18 @@ jne @@radixok mov cl,8 lodsb - mov ah,20h - or ah,al - cmp ah,'x' + mov al,20h + cmp al,'x' jne @@radixok mov cl,16 @@strtollp: lodsb @@radixok: + or al,20h sub al,'0' jb @@endstrtol cmp al,9 jbe @@digitok - or al,20h cmp al,'a'-'0' jb @@endstrtol sub al,'a'-'0'-10 @@ -1155,8 +1132,8 @@ inc dx @@end: xchg ax,di +@@popdisiret: pop di -popsiret: pop si endif ret @@ -1175,7 +1152,7 @@ jnc @@max640k mov ax,640 ; 9000 @@max640k: - sub ax,028h + dec ax and al,0C0h mov cl,6 shl ax,cl diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/CRTL.H --- a/linld/stuff/src/CRTL.H Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/CRTL.H Mon Jan 16 10:15:15 2017 +0100 @@ -43,7 +43,6 @@ extern "C" long lseekset(int fd, long sz); extern "C" void* malloc(unsigned sz); extern "C" void puts(const char* s); -extern "C" void putsz(const char* s); extern "C" unsigned long strtol(const char *s); // Extensions diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/CRTLX.ASM --- a/linld/stuff/src/CRTLX.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/CRTLX.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -30,18 +30,18 @@ global _strcmp:near proc _strcmp near - pop ax ;caller return address - pop cx ; a - pop bx ; b + pop cx ;caller return address + pop bx ; a + pop ax ; b + push ax push bx push cx - push ax push si - mov si,cx + xchg ax,si sub bx,si @@lp: - mov al,[bx+si] - sub al,[si] + mov al,[si] + sub al,[bx+si] jnz @@out lodsb cmp al,0 @@ -295,16 +295,16 @@ global _kver2ul:near proc _kver2ul near + pop bx pop ax - pop dx - push dx push ax + push bx push bp si di + xchg ax,si xor di,di push di push di mov bp,sp - mov si,dx inc di inc di mov cl,4 @@ -372,7 +372,6 @@ push cx push dx push ax - xor ax,ax extrn _isostate:isostate mov bx,[_isostate.fd] extrn lseekset:near diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/MEMCPY32.ASM --- a/linld/stuff/src/MEMCPY32.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/MEMCPY32.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -113,15 +113,13 @@ oldGDTR :pword = TEMP_SIZE ;****** Init *************************************************** - push bp - mov bp,sp - sub sp,TEMP_SIZE + + ifndef NO386 + + enter TEMP_SIZE,0 ;cld pushf push ds es - - ifndef NO386 - pushad mov cl,4 movzx esi,[srcseg] @@ -156,6 +154,12 @@ @@pmcopy: else + push bp + mov bp,sp + sub sp,TEMP_SIZE + ;cld + pushf + push ds es push si xor bx,bx xor dx,dx @@ -233,7 +237,7 @@ mov eax,cs shl eax,4 addzx_e ax, - mov [word GDTR],-1 ;GDT limit = 0FFFFh + or [word GDTR],-1 ;GDT limit = 0FFFFh mov [dword GDTR+2],eax ;GDT base lgdt [GDTR] @@ -248,7 +252,7 @@ pop ds ;base=0, lim = 4gb push ds ; pop es ; - db 66h ;operand width override for ecx + ;db 66h ;operand width override for ecx db 67h ;address width override for esi/edi rep movsb cld @@ -266,8 +270,12 @@ @@done16: pop es ds popf + ifndef NO386 + leave + else mov sp,bp pop bp + endif ret ;****** Const data ********************************************* diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/MEMTOP.ASM --- a/linld/stuff/src/MEMTOP.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/MEMTOP.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -78,10 +78,11 @@ jnc @@ok ; error: cf=1 or ax=0 xor ax,ax ; @@ok: - xor dx,dx +; xor dx,dx test ax,ax ;happens on big mem systems jz @@fail tokb: + xor dx,dx add ah,4h ;account for 1024 low kb adc dx,dx ; (optimized to death) ifndef NO386 @@ -117,7 +118,6 @@ cli call rdcmos17 popf - xor dx,dx jmp tokb rdcmos17: mov al,18h ; read bytes 17-18 from CMOS diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/VCPI.ASM --- a/linld/stuff/src/VCPI.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/VCPI.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -65,11 +65,6 @@ use_32 = 01000000b ;****** rm32,imm16 helpers -macro movzx_e rm,i - db 66h - mov rm,i - dw 0 -endm macro addzx_e rm,i db 66h add rm,i @@ -77,13 +72,11 @@ endm - group DGROUP _TEXT,_DATA + group DGROUP _TEXT,_DATA,_BSS assume cs:DGROUP,ds:DGROUP segment _DATA byte public use16 'DATA' -tss dd 0,0 ;enough, we'll never use it anyway - label gdt byte gdt_null descr ;0000 gdt_vcpi descr ;0008 @@ -104,39 +97,42 @@ label gdtr pword gdt_lim dw 0ffffh gdt_base dw offset gdt,0 -label idtr pword -idt_lim dw 03ffh ;we won't enable ints, -idt_base dd 0 ; so let's leave it the same as for rm ;Note: layout dictated by vcpi api, don't rearrange! label sw2pm_params byte ;Note: base addrs will be fixed up in prepare_vcpi() +label pagedir_laddr dword sw2pm_cr3 dd ? sw2pm_gdtr_ptr dw offset gdtr,0 sw2pm_idtr_ptr dw offset idtr,0 sw2pm_ldtr dw 0 ;we don't need it sw2pm_tr dw SEL_TSS ;vcpi thinks we need it... can't set to 0 -sw2pm_jumpaddr dd ? +sw2pm_jumpaddr dd 0 dw SEL_CODE +vcpi_pm_entry dd 0 + dw SEL_VCPI + +label idtr pword +idt_lim dw 03ffh ;we won't enable ints, +idt_base dd 0 ; so let's leave it the same as for rm + + ends _DATA + + segment _BSS byte public use16 'BSS' + ;Pagedir/page0 addrs: linear, seg:0 and cs:ofs -pagedir_laddr dd ? page0_laddr dd ? -;;pagedir_seg dw ? -;;page0_seg dw ? -pagedir_ofs dw ? -page0_ofs dw ? - -vcpi_pm_entry dd ? - dw SEL_VCPI +;pagedir_ofs dw ? +;page0_ofs dw ? label saved_ss_sp dword saved_sp dw ? saved_ss dw ? +tss dd ?,? ;enough, we'll never use it anyway - ends _DATA - + ends _BSS segment _TEXT byte public use16 'CODE' @@ -166,45 +162,51 @@ mov cl,4 mov edx,cs - shl edx,cl ;ebx = linear addr of CS - mov bx, offset page0_laddr + shl edx,cl ;edx = linear addr of CS + mov si,offset gdt_vcpi ; Fix up base of some gdt descriptors ; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity! ; Do NOT replace with mov! - add [dword bx+gdt_base-page0_laddr],edx - add [dword bx+sw2pm_gdtr_ptr-page0_laddr],edx - add [dword bx+sw2pm_idtr_ptr-page0_laddr],edx - add [dword bx+(gdt_code.base0)-page0_laddr],edx - add [dword bx+(gdt_data.base0)-page0_laddr],edx - add [dword bx+(gdt_tss.base0)-page0_laddr],edx + xor ebx,ebx + add [dword bx+si+sw2pm_idtr_ptr-gdt_vcpi],edx +@@fixup: + add [dword bx+si+(gdt_code.base0)-gdt_vcpi],edx + add bl,8 + cmp bl,28h + jb @@fixup + ;add [dword si+(gdt_data.base0)-gdt_vcpi],edx + ;add [dword si+(gdt_tss.base0)-gdt_vcpi],edx + ;add [dword si+gdt_base-gdt_vcpi],edx + ;add [dword si+sw2pm_gdtr_ptr-gdt_vcpi],edx + ;add [dword si+sw2pm_idtr_ptr-gdt_vcpi],edx add eax,edx - mov esi,0FFFh - add eax,esi - inc si ;esi=00001000h + mov bx,0FFFh + add eax,ebx + inc bx ;ebx=00001000h shr eax,cl mov al,0 ;eax = 4k aligned linear addr of pagebuf mov es,ax ;es:0->page0,es:1000h->pagedir shl eax,cl ;eax=page0 linear addr - mov [bx+page0_laddr-page0_laddr],eax mov al,3 ;add present+writable bits - mov [es:si],eax ;stuff it into pagedir[0] + mov [es:bx],eax ;stuff it into pagedir[0] + push ds + pop es - add eax,esi mov al,0 - mov [bx+pagedir_laddr-page0_laddr],eax + mov [page0_laddr],eax + add eax,ebx + ;mov [pagedir_laddr],eax ;page directory will use only one entry (4 bytes): ;cr3 => pagedir => page0 => ######## ; (1 entry) (1024 => # 4M # ; entries)=> # page # ; => ######## - mov [bx+sw2pm_cr3-page0_laddr],eax + mov [sw2pm_cr3],eax sub eax,edx ;ax = offset in CS of pagedir - mov [bx+pagedir_ofs-page0_laddr],ax - sub ax,si ;ax-=1000 - mov [bx+page0_ofs-page0_laddr],ax - push ds - pop es + ;mov [pagedir_ofs],ax + sub ax,bx ;ax-=1000 + ;mov [page0_ofs],ax mov di,ax ;ES:DI => page0 ; Return ;pop es @@ -219,8 +221,8 @@ ;*************************************************************** ;int get_vcpi_interface(); -;****** Return: AX=1 - page mapping for low 640k is 1:1 -;****** AX=0 - otherwise (it's bad) +;****** Return: Z - page mapping for low 640k is 1:1 +;****** NZ - otherwise (it's bad) ;****** Uses: Flags ;*************************************************************** global _get_vcpi_interface:near @@ -229,32 +231,29 @@ ;push si di ; Get and save VCPI pm interface - mov si,offset gdt_vcpi ;DS:DI => 3 GDT entries for VCPI + ;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 + push di mov ax,0DE01h ;get vcpi pm interface int 67h - mov [vcpi_pm_entry],ebx + xchg [vcpi_pm_entry],ebx ;clear ebx + ;xor bx,bx ; Check that mapping for low 640k is 1:1 - mov si,[page0_ofs] - xor bx,bx + pop si ; [page0_ofs] ;cld @@map_chk: lodsd shr eax,12 cmp ax,bx - stc jne @@bad inc bx - cmp ax,((640*1024) shr 12)-1 + cmp al,((640*1024) shr 12)-1 jne @@map_chk ; Return @@bad: - sbb ax,ax - inc ax ; update Z - ;pop di si ret endp _get_vcpi_interface @@ -302,17 +301,10 @@ push ax ;\eip push offset @@vm_ret ;/ - cli ;;mov [saved_xx],xx ;use if your vcpi trashes bp/etc - movzx_e <[word sw2pm_jumpaddr]>, - ;mov [word sw2pm_jumpaddr+4],SEL_CODE - mov esi,cs - shl esi,4 - addzx_e si, - mov ax,0DE0Ch ; vcpi: switch to pm - int 67h -@@pm_entry: + call switch_to_pm + ; Now we are in 16-bit protected mode mov ax,SEL_DATA mov ss,ax @@ -332,17 +324,30 @@ call ax ; Ok, let's return to vm + mov ax,0DE0Ch ; maybe we need whole eax? cli ; to be safe clts ; push SEL_ABS ; vcpi wants ds=all_addrspace pop ds ; - mov ax,0DE0Ch ; maybe we need whole eax? call [pword cs:vcpi_pm_entry] @@vm_ret: ; Now we are in vm86 mode. Sregs, esp, eflags (IF) restored from IRET stack ret ;*************************************************************** +switch_to_pm: + assume cs:DGROUP,ds:DGROUP + pop [word sw2pm_jumpaddr] + ;mov [word sw2pm_jumpaddr+2],0 + ;mov [word sw2pm_jumpaddr+4],SEL_CODE + mov esi,cs + shl esi,4 + addzx_e si, + mov ax,0DE0Ch ; vcpi: switch to pm + cli + int 67h + +;*************************************************************** ;****** Helper: This is where real copy is done ;*************************************************************** global do_memcpy_vcpi:near @@ -350,29 +355,27 @@ ; Note: ss:bp => params ; Move data - mov cx,SEL_ABS - mov ds,cx - mov es,cx + mov ax,SEL_ABS + mov ds,ax + mov es,ax assume nothing assume cs:DGROUP ; Set up target addr: ; replace page mapping for page at 0 so ; that it points to dstofs - mov esi,[cs:page0_laddr] mov eax,[dstofs] mov al,03h ; writeable, present - xchg [esi],eax ; replace page0[0] + call @@set_mapping ;push eax ;X we'll need to restore mapping... - mov ecx,cr3 ; reload TLB cache - mov cr3,ecx ; xor edi,edi ;es:edi => remapped page ; Set up source addr mov esi,[srcofs] ; Do copying - mov ecx,4096/2 + xor ecx,ecx + mov ch,4096/256 ;cld ;; cmp esi,edi ;; jae @@do_copy @@ -383,13 +386,14 @@ ;; std ; ;;@@do_copy: db 67h ;address width override for esi/edi - rep movsw + rep movsb ;; cld ; Restore page mapping for page at 0 ;pop eax ;X +@@set_mapping: mov esi,[cs:page0_laddr] - mov [esi],eax ; restore page0[0] + xchg [esi],eax ; restore page0[0] mov ecx,cr3 ; reload TLB cache mov cr3,ecx ; ; Return @@ -410,29 +414,22 @@ extrn _vcpi:byte test [_vcpi],-1 jz @@ret - push esi + push si ;;pushf - ;;cli ;;pushad push cs ;* push ds - push es + ;push es mov [saved_ss],ss mov [saved_sp],sp - movzx_e <[word sw2pm_jumpaddr]>, - ;mov [word sw2pm_jumpaddr+4],SEL_CODE - mov esi,cs - shl esi,4 - addzx_e si, - mov ax,0DE0Ch ; vcpi: switch to pm - int 67h + call switch_to_pm + ; Now we are in 16-bit protected mode -@@pm_entry: mov ax,SEL_DATA ; load data sregs with limit >=64k mov ss,ax ; or you may get limit violations mov ds,ax ; later in rm - mov es,ax ; (actually I prefer 4gig limits :-) + ;mov es,ax ; (actually I prefer 4gig limits :-) ;mov fs,ax ; ;mov gs,ax ; @@ -446,7 +443,7 @@ ; Now we are in rm, but not yet: have to restore sregs: lss sp,[saved_ss_sp]; SS - pop es ; ES + ;pop es ; ES pop ds ; DS ;push cs ;* done earlier push offset @@next @@ -454,7 +451,7 @@ @@next: ;;popad ;;popf - pop esi + pop si @@ret: ret ; We don't care much about rest (FS/GS) diff -r 7c138665bd75 -r 38eb1fe036b4 linld/stuff/src/_BEG.ASM --- a/linld/stuff/src/_BEG.ASM Sun Jan 15 10:32:17 2017 +0100 +++ b/linld/stuff/src/_BEG.ASM Mon Jan 16 10:15:15 2017 +0100 @@ -100,7 +100,7 @@ ;extrn _get_vcpi_interface:near ;call _get_vcpi_interface mov bx,offset msg_badmapping - jnz endcpu + jz endcpu no_vcpi: ;;pop dx ;$ handle ;;mov ax,4500h ; DEALLOCATE PAGES