From 72bf3f35c2a6629bb3039361106872e6582b0e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Sat, 13 Jul 2019 20:49:22 +0200 Subject: [PATCH] fix: appel stdcall defaillant --- debug/system.txt | 2 +- include/mem.h | 24 +++++++----- lib/3d.asm | 3 ++ lib/bmp.asm | 3 ++ lib/detect.asm | 3 ++ lib/graphic.asm | 3 ++ lib/lib.asm | 3 ++ lib/math.asm | 32 +++++++++++++++ lib/str0.asm | 3 ++ lib/video.asm | 3 ++ makefile | 8 +++- noyau/8259a.asm | 24 ++++++------ noyau/mcb.asm | 90 +++++++++++++++++++++---------------------- noyau/systeme.asm | 2 + noyau/video.asm | 3 ++ programs/commande.asm | 3 ++ programs/editeur.asm | 3 ++ programs/exem.asm | 2 + programs/gestion.asm | 3 ++ programs/isa.asm | 3 ++ programs/logo.asm | 3 ++ programs/pmode.asm | 3 ++ programs/souris.asm | 3 ++ programs/test.asm | 3 ++ programs/test2d.asm | 3 ++ programs/test3d.asm | 3 ++ programs/verifier.asm | 3 ++ programs/volume.asm | 3 ++ 28 files changed, 175 insertions(+), 69 deletions(-) diff --git a/debug/system.txt b/debug/system.txt index 7900b10..b3824e4 100644 --- a/debug/system.txt +++ b/debug/system.txt @@ -1,6 +1,6 @@ target remote localhost:1234 set disassembly-flavor intel -set architecture i386 +set architecture i8086 display/20i $pc+$cs*16 break *0x80010 cont diff --git a/include/mem.h b/include/mem.h index ed0228b..d21b8e4 100644 --- a/include/mem.h +++ b/include/mem.h @@ -150,25 +150,35 @@ macro declare fonction* macro stdcall proc,[arg] ; directly call STDCALL procedure { -common + common + size@ccall = 0 if ~ arg eq reverse push arg + size@ccall = size@ccall+2 common end if push cs call proc + if size@ccall + add sp,size@ccall + end if } macro invoke proc,[arg] ; directly call STDCALL procedure { common + size@ccall = 0 if ~ arg eq reverse push arg + size@ccall = size@ccall+2 common end if call far [cs:proc] + if size@ccall + add sp,size@ccall + end if } macro proc [args] ; define procedure @@ -195,11 +205,7 @@ macro epiloguedef procname,flag,parmbytes,localbytes,reglist if parmbytes | localbytes leave end if - if flag and 10000b - retn - else - retn parmbytes - end if } + retf } macro define@proc name,statement { local params,flag,regs,parmbytes,localbytes,current @@ -211,7 +217,7 @@ macro define@proc name,statement flag = 11b \} match =params, params \{ params equ statement flag = 0 \} - virtual at bp+4 + virtual at bp+6 match =uses reglist=,args, params \{ regs equ reglist params equ args \} match =regs =uses reglist, regs params \{ regs equ reglist @@ -219,7 +225,7 @@ macro define@proc name,statement match =regs, regs \{ regs equ \} match =,args, params \{ defargs@proc args \} match =args@proc args, args@proc params \{ defargs@proc args \} - parmbytes = $ - (bp+4) + parmbytes = $ - (bp+6) end virtual name # % = parmbytes/2 all@vars equ @@ -248,7 +254,7 @@ macro define@proc name,statement current = $-(bp-localbytes) end virtual \} macro ret operand - \{ match any, operand \\{ retn operand \\} + \{ match any, operand \\{ retf operand \\} match , operand \\{ match epilogue:reglist, epilogue@proc: \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 diff --git a/lib/3d.asm b/lib/3d.asm index 718efd5..8bd6b38 100644 --- a/lib/3d.asm +++ b/lib/3d.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\graphic.h" include "..\include\3d.h" diff --git a/lib/bmp.asm b/lib/bmp.asm index fd65db7..985aa40 100644 --- a/lib/bmp.asm +++ b/lib/bmp.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" include "..\include\bmp.h" diff --git a/lib/detect.asm b/lib/detect.asm index 2c75c51..10e1e47 100644 --- a/lib/detect.asm +++ b/lib/detect.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\cpu.h" include "..\include\pci.h" diff --git a/lib/graphic.asm b/lib/graphic.asm index bef5871..ef7477f 100644 --- a/lib/graphic.asm +++ b/lib/graphic.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\graphic.h" diff --git a/lib/lib.asm b/lib/lib.asm index c6078fd..0e5968d 100644 --- a/lib/lib.asm +++ b/lib/lib.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/lib/math.asm b/lib/math.asm index e69de29..54a0d60 100644 --- a/lib/math.asm +++ b/lib/math.asm @@ -0,0 +1,32 @@ +use16 +align 1 + +include "..\include\mem.h" + +org 0h + +header exe 1 + +exporting +declare random +declare randomize +ende + +randseed dw 1234h + +proc random uses dx + mov ax,[cs:randseed] + mov dx,8405h + mul dx + inc ax + mov [cs:randseed],ax + mov ax,dx + retf +endp + +proc randomize uses ax cx dx + mov ah,0 + int 1ah + mov [cs:randseed],dx + retf +endp diff --git a/lib/str0.asm b/lib/str0.asm index 97c9ac2..59bfe21 100644 --- a/lib/str0.asm +++ b/lib/str0.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/lib/video.asm b/lib/video.asm index baeca5e..eef7229 100644 --- a/lib/video.asm +++ b/lib/video.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" org 0h diff --git a/makefile b/makefile index f6acef6..cf86b4d 100644 --- a/makefile +++ b/makefile @@ -26,6 +26,10 @@ view: final/cos2000.img view2: boot/boot12.bin (objdump -D -b binary -mi386 -Maddr16,data16 ./boot/boot12.bin) +debug: debug-system + +redebug: clean debug + debug-boot: all copy qemu-debug (sleep 2;cgdb -x ./debug/boot.txt) @@ -33,10 +37,10 @@ debug-system: all copy qemu-debug (sleep 2;cgdb -x ./debug/system.txt) qemu-debug: - (qemu-system-i386 -m 1G -fda ./final/cos2000.img -s -S &) + (killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/cos2000.img -s -S &) qemu: - (qemu-system-i386 -m 1G -fda ./final/cos2000.img -s) + (killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/cos2000.img -s) noyau/systeme.sys: make -C noyau diff --git a/noyau/8259a.asm b/noyau/8259a.asm index 943abae..0799eda 100644 --- a/noyau/8259a.asm +++ b/noyau/8259a.asm @@ -45,7 +45,7 @@ proc enableirq uses ax cx dx, irq:word in al,dx and al,ah out dx,al - retf + ret endp ;Desactive une interruption ‚lectronique @@ -66,7 +66,7 @@ proc disableirq uses ax cx dx, irq:word in al,dx or al,ah out dx,al - retf + ret endp @@ -80,7 +80,7 @@ proc seteoi uses ax dx, irq:word .master: mov al,EOI out MASTERPIC,al - retf + ret endp @@ -95,7 +95,7 @@ proc readimr uses bx dx, controleur:word xor ah,ah in al,dx pop dx - retf + ret endp ;Lit le registre d'‚tat d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1 @@ -110,7 +110,7 @@ proc readisr uses bx dx, controleur:word out dx,al xor ah,ah in al,dx - retf + ret endp @@ -126,7 +126,7 @@ proc readirr uses bx dx, controleur:word out dx,al xor ah,ah in al,dx - retf + ret endp ;carry si enable et pas carry si pas enable @@ -142,7 +142,7 @@ proc isenableirq uses ax cx dx, irq:word in al,dx neg al bt ax,cx - retf + ret endp @@ -161,7 +161,7 @@ proc isinserviceirq uses ax cx dx, irq:word in al,dx neg al bt ax,cx - retf + ret endp @@ -180,7 +180,7 @@ proc isrequestirq uses ax cx dx, irq:word in al,dx neg al bt ax,cx - retf + ret endp @@ -258,7 +258,7 @@ proc installirqhandler uses eax bx cx edx si di ds es .end: pop fs sti - retf + ret endp @@ -309,7 +309,7 @@ pop [.regs.secx] pop [.regs.sebx] pop [.regs.seax] pop [.regs.seflags] -retf +ret endp proc restorecontextg, pointer:word @@ -332,7 +332,7 @@ mov ds,[cs:.regs.sds] popfd pop esi pop [cs:dummy] -db 0xCA,0x02,0x00 ;retf 2 +db 0xCA,0x02,0x00 ;ret 2 endp diff --git a/noyau/mcb.asm b/noyau/mcb.asm index f2d818d..5582f51 100644 --- a/noyau/mcb.asm +++ b/noyau/mcb.asm @@ -20,7 +20,7 @@ proc biosprinth uses ax bx cx edx si di, num:dword int 10h dec di jnz .hexaize - retf + ret .tab db '0123456789ABCDEF' endp @@ -42,7 +42,7 @@ proc biosprint uses ax bx cx si, pointer:word int 10h jmp .again .fin: - retf + ret endp proc enablea20 uses ax @@ -55,7 +55,7 @@ proc enablea20 uses ax ;mov al,0ffh ;out 64h,al ;call a20wait - retf + ret endp proc disablea20 uses ax @@ -68,7 +68,7 @@ proc disablea20 uses ax ;mov al,0ffh ;out 64h,al ;call a20wait - retf + ret endp a20wait: @@ -114,7 +114,7 @@ proc flatmode uses eax bx ds jmp .suite2 .suite2: sti ; resume handling interrupts - retf ; + ret ; .gdt: gdtitse descriptor .gdtend - .gdt - 1, .gdt, 0, 0, 0, 0 ; the GDT itself @@ -126,7 +126,7 @@ endp proc bioswaitkey uses ax xor ax,ax int 16h - retf + ret endp firstmb dw 0 @@ -184,16 +184,16 @@ popad dec si jmp .finishloading .finishdepands: - retf + ret .notace: stc - retf + ret .error: stc - retf + ret .depandserror: stc - retf + ret .toresov dw 60 dup (0) endp @@ -215,10 +215,10 @@ proc mbinit uses ax cx si di ds es mov cx,.mb.sizeof rep movsb clc - retf + ret .alreadyok: stc - retf + ret endp afree mb "HN",0,0,0,0A000h-memorystart,"Libre" @@ -294,7 +294,7 @@ proc mbcreate uses bx cx dx si di ds es, blocks:word, size:word mov ax,bx pop gs clc - retf + ret .notsogood: inc bx inc bx @@ -303,11 +303,11 @@ proc mbcreate uses bx cx dx si di ds es, blocks:word, size:word .memoryerror: pop gs stc - retf + ret .notenougtmem: pop gs stc - retf + ret endp ;Libère le bloc de mémoire %0 et ses sous blocs @@ -359,16 +359,16 @@ proc mbfree uses ax bx cx si di ds es, blocks:word cmp [es:.mb.isnotlast],true je .searchtofree stdcall mbclean - retf + ret .memoryerror: stc - retf + ret .wasfree: stc - retf + ret .wasresident: stc - retf + ret .isfree db "libre",0 endp @@ -422,13 +422,13 @@ proc mbclean uses ax bx dx es gs mov [es:.mb.isnotlast],false .reallyfinish: clc - retf + ret .notenougtmem: stc - retf + ret .memoryerror: stc - retf + ret endp ;Rend le segment %0 résident @@ -443,10 +443,10 @@ proc mbresident uses bx es, blocks:word cmp word [es:.mb.check],"NH" jne .memoryerror mov [es:.mb.isresident],true - retf + ret .memoryerror: stc - retf + ret endp ;Rend le segment %0 non résident @@ -461,10 +461,10 @@ proc mbnonresident uses bx es, blocks:word cmp word [es:.mb.check],"NH" jne .memoryerror mov [es:.mb.isresident],false - retf + ret .memoryerror: stc - retf + ret endp @@ -483,13 +483,13 @@ proc mbchown uses bx dx es,blocks:word, owner:word je .wasfree mov dx,[owner] mov [es:.mb.reference],dx - retf + ret .memoryerror: stc - retf + ret .wasfree: stc - retf + ret endp ;Alloue un bloc /data de CX caractere pour le process appelant -> ax @@ -498,7 +498,7 @@ proc mballoc uses si ds, size:word pop ds stdcall mbcreate,.data,[size] stdcall mbchown,ax,word [ss:bp+4] - retf + ret .data db '/data',0 endp @@ -529,16 +529,16 @@ proc mbget uses bx dx es, num:word je .searchfree .memoryerror: stc - retf + ret .foundmcb: mov ax,es inc ax inc ax clc - retf + ret .notfound: stc - retf + ret endp ;Renvoie en AX le MCB qui correspond a ds:%0 @@ -577,16 +577,16 @@ proc mbfind uses bx si di es, blocks:word je .search .notfound: stc - retf + ret .memoryerror: stc - retf + ret .foundmcb: mov ax,es inc ax inc ax clc - retf + ret endp @@ -630,16 +630,16 @@ proc mbfindsb uses bx dx si di es, blocks:word, owner:word je .search .notfound: stc - retf + ret .foundmcb: mov ax,es inc ax inc ax clc - retf + ret .memoryerror: stc - retf + ret endp ;Resouds les dépendances du bloc de mémoire %0 @@ -689,16 +689,16 @@ proc mbloadfuncs uses ax bx cx dx si ds, blocks:word jmp .loadfuncs .endofloading: clc - retf + ret .notace: stc - retf + ret .libnotexist: stc - retf + ret .erroronload: stc - retf + ret endp @@ -751,8 +751,8 @@ proc mbsearchfunc uses bx si di es, func:word mov dx,es mov ax,[es:di+1] clc - retf + ret .notfoundattallthesb: stc - retf + ret endp diff --git a/noyau/systeme.asm b/noyau/systeme.asm index e951ec6..2cddb7b 100644 --- a/noyau/systeme.asm +++ b/noyau/systeme.asm @@ -1,3 +1,5 @@ +use16 +align 1 include "..\include\mem.h" include "..\include\divers.h" diff --git a/noyau/video.asm b/noyau/video.asm index 2c970ee..b13cc00 100644 --- a/noyau/video.asm +++ b/noyau/video.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\graphic.h" diff --git a/programs/commande.asm b/programs/commande.asm index 156254c..b964975 100644 --- a/programs/commande.asm +++ b/programs/commande.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\fat.h" include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/editeur.asm b/programs/editeur.asm index 8d5b546..2e007a3 100644 --- a/programs/editeur.asm +++ b/programs/editeur.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" include "..\include\graphic.h" diff --git a/programs/exem.asm b/programs/exem.asm index 82a5c6b..bb6d622 100644 --- a/programs/exem.asm +++ b/programs/exem.asm @@ -1,3 +1,5 @@ +use16 +align 1 include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/gestion.asm b/programs/gestion.asm index c86b942..50d03ae 100644 --- a/programs/gestion.asm +++ b/programs/gestion.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\fat.h" include "..\include\divers.h" diff --git a/programs/isa.asm b/programs/isa.asm index ac8929c..e005e05 100644 --- a/programs/isa.asm +++ b/programs/isa.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/logo.asm b/programs/logo.asm index e11a447..af7f272 100644 --- a/programs/logo.asm +++ b/programs/logo.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/pmode.asm b/programs/pmode.asm index c68f0d8..cc445e6 100644 --- a/programs/pmode.asm +++ b/programs/pmode.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/souris.asm b/programs/souris.asm index 1efb39f..a5b4f01 100644 --- a/programs/souris.asm +++ b/programs/souris.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/test.asm b/programs/test.asm index 07e0706..8f48fa7 100644 --- a/programs/test.asm +++ b/programs/test.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/test2d.asm b/programs/test2d.asm index fd322d0..2811280 100644 --- a/programs/test2d.asm +++ b/programs/test2d.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\fat.h" include "..\include\divers.h" diff --git a/programs/test3d.asm b/programs/test3d.asm index 224f7a5..86030c6 100644 --- a/programs/test3d.asm +++ b/programs/test3d.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\fat.h" include "..\include\divers.h" diff --git a/programs/verifier.asm b/programs/verifier.asm index 5b15051..f761ec0 100644 --- a/programs/verifier.asm +++ b/programs/verifier.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" diff --git a/programs/volume.asm b/programs/volume.asm index 4853a51..1ecff11 100644 --- a/programs/volume.asm +++ b/programs/volume.asm @@ -1,3 +1,6 @@ +use16 +align 1 + include "..\include\mem.h" include "..\include\divers.h" include "..\include\graphic.h"