From d2028e18039727b680a8e48e67ab7268c244a361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Sat, 6 Jul 2019 10:52:53 +0200 Subject: [PATCH] feat: migration progressive des sources vers fasm, noyau - systeme.asm --- include/cpu.h | 41 +-- include/fat.h | 4 +- include/mem.h | 299 ++++++++++++++++++++- include/pci.h | 38 +-- noyau/8259a.asm | 385 +++++++++++++------------- noyau/makefile | 87 +----- noyau/mcb.asm | 669 ++++++++++++++++++++++------------------------ noyau/systeme.asm | 180 ++++++------- 8 files changed, 924 insertions(+), 779 deletions(-) diff --git a/include/cpu.h b/include/cpu.h index e2dbe43..8b3a1af 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -1,20 +1,21 @@ -struc cpu -vendor db 13 dup(0) ;Chaine 0 du fabriquant -names db 32 dup(0) -stepping db 0 -models db 0 -family db 0 -types db 0 -emodels db 0 -efamily db 0 -mmx db 0 -mmx2 db 0 -sse db 0 -sse2 db 0 -sse3 db 0 -fpu db 0 -now3d db 0 -now3d2 db 0 -htt db 0 -apic db 0 -ends cpu +struc cpu +{ +.vendor db 13 dup(0) ;Chaine 0 du fabriquant +.names db 32 dup(0) +.stepping db 0 +.models db 0 +.family db 0 +.types db 0 +.emodels db 0 +.efamily db 0 +.mmx db 0 +.mmx2 db 0 +.sse db 0 +.sse2 db 0 +.sse3 db 0 +.fpu db 0 +.now3d db 0 +.now3d2 db 0 +.htt db 0 +.apic db 0 +} diff --git a/include/fat.h b/include/fat.h index 8d01fdb..eafd610 100644 --- a/include/fat.h +++ b/include/fat.h @@ -38,13 +38,13 @@ struc entries } ;Pour recherches -struc find +struc find files { .files db 13 dup (0) ;le fichier .entryplace dw 0 ;En octet .adressdirectory dw 0 ;En cluster .firstsearch db 1 ;Premiere requete ? -.result entries <> +.result entries } struc bootinfo vendor,drivename,serialnumber diff --git a/include/mem.h b/include/mem.h index 32979a3..ca5f254 100644 --- a/include/mem.h +++ b/include/mem.h @@ -26,17 +26,19 @@ struc regs ;.sst7 dt 0 } -struc tuple +struc tuple off,seg { .off dw 0 ;adresse .seg dw 0 ;segment } -;union vector -;{ -;.data tuple 0,0 -;.content dd 0 -;} +struc vector off,seg +{ +.data tuple off,seg +virtual at .data +.content dd 0 +end virtual +} struc ints ;bloc interruption { @@ -55,9 +57,11 @@ struc ints ;bloc interruption .vector6 vector ? .vector7 vector ? .vector8 vector ? +.sizeof = $ - .number } -struc mb ;Bloc de mémoire +struc mb check,isnotlast,isresident,reference,sizes,names +;Bloc de mémoire { .check db "NH" ;signature du bloc de mémoire. .isnotlast db 0 ;flag indiquant le dernier bloc @@ -65,9 +69,11 @@ struc mb ;Bloc de m .reference dw 0 ;pointeur vers le bloc parent .sizes dw 0 ;taille du bloc en paragraphe de 16 octet .names db 24 dup (0) ;nom du bloc +.sizeof = $ - .check } -struc exe ;Executable COS +struc exe major +;Executable COS { .checks db "CE" ;signature de l'exe .major db 1 ;N° version @@ -79,7 +85,7 @@ struc exe ;Executable COS .starting dw 15 } -struc descriptor +struc descriptor limit_low,base_low,base_middle,dpltype,limit_high,base_high { .limit_low dw 0 .base_low dw 0 @@ -87,6 +93,7 @@ struc descriptor .dpltype db 0 .limit_high db 0 .base_high db 0 +.sizeof = $ - .limit_low } free equ 0 ;Reference quand libre @@ -137,7 +144,273 @@ macro declare fonction* dw fonction } -macro heading versmaj*,versmin*,start* -{ -header exe "CE",versmaj,versmin,0,exports,imports,0,start -} + +; Macroinstructions for defining and calling procedures + +macro stdcall proc,[arg] ; directly call STDCALL procedure + { common + if ~ arg eq + reverse + pushw arg + common + end if + call proc } + +macro invoke proc,[arg] ; indirectly call STDCALL procedure + { common + if ~ arg eq + reverse + pushw arg + common + end if + call [proc] } + +macro ccall proc,[arg] ; directly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushw arg + size@ccall = size@ccall+2 + common + end if + call proc + if size@ccall + add sp,size@ccall + end if } + +macro cinvoke proc,[arg] ; indirectly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushw arg + size@ccall = size@ccall+2 + common + end if + call [proc] + if size@ccall + add sp,size@ccall + end if } + +macro proc [args] ; define procedure + { common + match name params, args> + \{ define@proc name, \{ prologue name,flag,parmbytes,localbytes,reglist \} + macro locals + \{ virtual at bp-localbytes+current + macro label . \\{ deflocal@proc .,:, \\} + struc db [val] \\{ \common deflocal@proc .,db,val \\} + struc du [val] \\{ \common deflocal@proc .,du,val \\} + struc dw [val] \\{ \common deflocal@proc .,dw,val \\} + struc dp [val] \\{ \common deflocal@proc .,dp,val \\} + struc dd [val] \\{ \common deflocal@proc .,dd,val \\} + struc dt [val] \\{ \common deflocal@proc .,dt,val \\} + struc dq [val] \\{ \common deflocal@proc .,dq,val \\} + struc rb cnt \\{ deflocal@proc .,rb cnt, \\} + struc rw cnt \\{ deflocal@proc .,rw cnt, \\} + struc rp cnt \\{ deflocal@proc .,rp cnt, \\} + struc rd cnt \\{ deflocal@proc .,rd cnt, \\} + struc rt cnt \\{ deflocal@proc .,rt cnt, \\} + struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} + macro endl + \{ purge label + restruc db,du,dw,dp,dd,dt,dq + restruc rb,rw,rp,rd,rt,rq + current = $-(bp-localbytes) + end virtual \} + macro ret operand + \{ match any, operand \\{ retn 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 + end if \} } + +macro defargs@proc [arg] + { common + if ~ arg eq + forward + local ..arg,current@arg + match argname:type, arg + \{ current@arg equ argname + label ..arg type + argname equ ..arg + if dqword eq type + dw ?,?,?,?,?,?,?,? + else if tbyte eq type + dw ?,?,?,?,? + else if qword eq type | pword eq type + dw ?,?,?,? + else if dword eq type + dw ?,? + else + dw ? + end if \} + match =current@arg,current@arg + \{ current@arg equ arg + arg equ ..arg + ..arg dw ? \} + common + args@proc equ current@arg + forward + restore current@arg + common + end if } + +macro deflocal@proc name,def,[val] + { common + match vars, all@vars \{ all@vars equ all@vars, \} + all@vars equ all@vars name + forward + local ..var,..tmp + ..var def val + match =?, val \{ ..tmp equ \} + match any =dup (=?), val \{ ..tmp equ \} + match tmp : value, ..tmp : val + \{ tmp: end virtual + initlocal@proc ..var,def value + virtual at tmp\} + common + match first rest, ..var, \{ name equ first \} } + +macro initlocal@proc name,def + { virtual at name + def + size@initlocal = $ - name + end virtual + position@initlocal = 0 + while size@initlocal > position@initlocal + virtual at name + def + if size@initlocal - position@initlocal < 2 + current@initlocal = 1 + load byte@initlocal byte from name+position@initlocal + else if size@initlocal - position@initlocal < 4 + current@initlocal = 2 + load word@initlocal word from name+position@initlocal + else + current@initlocal = 4 + load dword@initlocal dword from name+position@initlocal + end if + end virtual + if current@initlocal = 1 + mov byte [name+position@initlocal],byte@initlocal + else if current@initlocal = 2 + mov word [name+position@initlocal],word@initlocal + else + mov dword [name+position@initlocal],dword@initlocal + end if + position@initlocal = position@initlocal + current@initlocal + end while } + +macro endp + { purge ret,locals,endl + finish@proc + purge finish@proc + restore regs@proc + match all,args@proc \{ restore all \} + restore args@proc + match all,all@vars \{ restore all \} } + +macro local [var] + { common + locals + forward done@local equ + match varname[count]:vartype, var + \{ match =BYTE, vartype \\{ varname rb count + restore done@local \\} + match =WORD, vartype \\{ varname rw count + restore done@local \\} + match =DWORD, vartype \\{ varname rd count + restore done@local \\} + match =PWORD, vartype \\{ varname rp count + restore done@local \\} + match =QWORD, vartype \\{ varname rq count + restore done@local \\} + match =TBYTE, vartype \\{ varname rt count + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + rq count+count + restore done@local \\} + match , done@local \\{ virtual + varname vartype + end virtual + rb count*sizeof.\#vartype + restore done@local \\} \} + match :varname:vartype, done@local:var + \{ match =BYTE, vartype \\{ varname db ? + restore done@local \\} + match =WORD, vartype \\{ varname dw ? + restore done@local \\} + match =DWORD, vartype \\{ varname dd ? + restore done@local \\} + match =PWORD, vartype \\{ varname dp ? + restore done@local \\} + match =QWORD, vartype \\{ varname dq ? + restore done@local \\} + match =TBYTE, vartype \\{ varname dt ? + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + dq ?,? + restore done@local \\} + match , done@local \\{ varname vartype + restore done@local \\} \} + match ,done@local + \{ var + restore done@local \} + common + endl } diff --git a/include/pci.h b/include/pci.h index 936321d..9d8373c 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1,29 +1,31 @@ struc pcidata -vendor dw 0 ;vendor ID (read-only), FFFFh returned if requested device non-existent -device dw 0 ;device ID (read-only) -command dw 0 ;command register -status dw 0 ;status register -revision db 0 ;revision ID -interface db 0 ;programming interface -subclass db 0 ;sub-class -class db 0 ;class code -cache db 0 ;cache line size -timer db 0 ;latency timer -typed db 0 ;header type +{ +.vendor dw 0 ;vendor ID (read-only), FFFFh returned if requested device non-existent +.device dw 0 ;device ID (read-only) +.command dw 0 ;command register +.status dw 0 ;status register +.revision db 0 ;revision ID +.interface db 0 ;programming interface +.subclass db 0 ;sub-class +.class db 0 ;class code +.cache db 0 ;cache line size +.timer db 0 ;latency timer +.typed db 0 ;header type ;bits 6-0: header format ;00h other ;01h PCI-to-PCI bridge ;02h PCI-to-CardBus bridge ;bit 7: multi-function device -result db 0 ;Built-In Self-Test result -ends pcidata +.result db 0 ;Built-In Self-Test result +} struc pciinf -version_major db 0 -version_minor db 0 -types db 0 -maxbus db 0 -ends pciinf +{ +.version_major db 0 +.version_minor db 0 +.types db 0 +.maxbus db 0 +} multifunction equ 80h othercard equ 00h diff --git a/noyau/8259a.asm b/noyau/8259a.asm index 2349253..176d275 100644 --- a/noyau/8259a.asm +++ b/noyau/8259a.asm @@ -1,4 +1,4 @@ -;Adresses de port du contr“leur IRQ +;Adresses de port du controleur IRQ MASTERPIC = 020h ;Adresse de base du PIC maŒtre SLAVEPIC = 0A0h ;Adresse de base du PIC esclave IRQMASK = 001h ;Offset sur port de masquage @@ -14,7 +14,7 @@ ;Position des vecteurs d'interruptions MASTERFIRSTVECTOR = 008h ;Vecteurs logiciels des interruptions - SLAVEFIRSTVECTOR = 070h ;‚lectroniques + SLAVEFIRSTVECTOR = 070h ;electroniques ;OCW3 codes registres IRR = 002h ;Interrupt Request Register @@ -24,20 +24,18 @@ POLLING = 004h ;Polling bit -ISR = 0Bh ; Pas d'op‚ration, pas de Poll, lire ISR OCW3 -IRR = 0Ah ; Pas d'op‚ration, pas de Poll, lire IRR +ISR = 0Bh ; Pas d'operation, pas de Poll, lire ISR OCW3 +IRR = 0Ah ; Pas d'operation, pas de Poll, lire IRR -;Autorise une interruption ‚lectronique -;Entr‚e : %1 - Num‚ro de l'interruption (0-15) … autoriser 0-7 = MASTERPIC , 8-15 = SLAVEPIC -PROC enableirq FAR - ARG @irq:word - USES ax,cx,dx - mov ax,[@irq] +;Autorise une interruption electronique +;Entree : %1 - Numero de l'interruption (0-15) à autoriser 0-7 = MASTERPIC , 8-15 = SLAVEPIC +proc enableirq, irq + mov ax,[irq] mov dx,MASTERPIC+IRQMASK cmp al,7 - jbe @@master + jbe .master mov dx,SLAVEPIC+IRQMASK -@@master: +.master: mov cl,al and cl,7 mov al,1 @@ -47,20 +45,18 @@ PROC enableirq FAR in al,dx and al,ah out dx,al - ret -endp enableirq + retf +endp ;Desactive une interruption ‚lectronique ;Entr‚e : %0 - Num‚ro de l'interruption (0-15) … desactiver 0-7 = MASTERPIC , 8-15 = SLAVEPIC -PROC disableirq FAR - ARG @irq:word - USES ax,cx,dx - mov ax,[@irq] +proc disableirq, irq + mov ax,[irq] mov dx,MASTERPIC+IRQMASK cmp al,7 - jbe @@master + jbe .master mov dx,SLAVEPIC+IRQMASK -@@master: +.master: mov cl,al and cl,7 mov al,1 @@ -70,106 +66,94 @@ PROC disableirq FAR in al,dx or al,ah out dx,al - ret -endp disableirq + retf +endp ;Signale "End Of Interrupt" de l'interruption %0 -PROC seteoi FAR - ARG @irq:word - USES ax,dx - mov ax,[@irq] +proc seteoi, irq + mov ax,[irq] cmp al,7 - jbe @@master + jbe .master mov al,EOI out SLAVEPIC,al -@@master: +.master: mov al,EOI out MASTERPIC,al - ret -endp seteoi + retf +endp ;Lit les masques d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1 -PROC readimr FAR - ARG @controleur:word - USES bx,dx - mov bx,[@controleur] +proc readimr, controleurx + mov bx,[controleur] mov dx,MASTERPIC+ IRQMASK cmp bl,0 - jne @@master + jne .master mov dx,SLAVEPIC+ IRQMASK -@@master: +.master: xor ah,ah in al,dx pop dx - ret -endp readimr + retf +endp ;Lit le registre d'‚tat d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1 -PROC readisr FAR - ARG @controleur:word - USES bx,dx - mov bx,[@controleur] +proc readisr, controleur + mov bx,[controleur] mov dx,MASTERPIC cmp bh,0 - jne @@master + jne .master mov dx,SLAVEPIC -@@master: +.master: mov al,ISR out dx,al xor ah,ah in al,dx - ret -endp readisr + retf +endp ;Lit le registre d'‚tat d'un contr“leur IRQ dans al, 0 master ou slave 1 ds bh -PROC readirr FAR - ARG @controleur:word - USES bx,dx - mov bx,[@controleur] +proc readirr, controleur + mov bx,[controleur] mov dx,MASTERPIC cmp bh,0 - jne @@master + jne .master mov dx,SLAVEPIC -@@master: +.master: mov al,IRR out dx,al xor ah,ah in al,dx - ret -endp readirr + retf +endp ;carry si enable et pas carry si pas enable -PROC isenableirq FAR - ARG @irq:word - USES ax,cx,dx - mov ax,[@irq] +proc isenableirq, irq + mov ax,[irq] mov dx,MASTERPIC+IRQMASK cmp al,7 - jbe @@master + jbe .master mov dx,SLAVEPIC+IRQMASK -@@master: +.master: mov cl,al and cx,7 in al,dx neg al bt ax,cx - ret -endp isenableirq + retf +endp ;carry si enable et pas carry si pas enable -PROC isinserviceirq FAR - ARG @irq:word - USES ax,cx,dx - mov ax,[@irq] +proc isinserviceirq, irq + mov ax,[irq] mov dx,MASTERPIC cmp al,7 - jbe @@master + jbe .master mov dx,SLAVEPIC -@@master: +.master: mov cl,al mov al,ISR out dx,al @@ -177,20 +161,18 @@ PROC isinserviceirq FAR in al,dx neg al bt ax,cx - ret -endp isinserviceirq + retf +endp ;carry si enable et pas carry si pas enable -PROC isrequestirq FAR - ARG @irq:word - USES ax,cx,dx - mov ax,[@irq] +proc isrequestirq, irq + mov ax,[irq] mov dx,MASTERPIC cmp al,7 - jbe @@master + jbe .master mov dx,SLAVEPIC -@@master: +.master: mov cl,al mov al,IRR out dx,al @@ -198,83 +180,80 @@ PROC isrequestirq FAR in al,dx neg al bt ax,cx - ret -endp isrequestirq + retf +endp -PROC installirqhandler FAR - USES eax,bx,cx,edx,si,di,ds,es +proc installirqhandler push fs - call mbcreate,offset interruptionbloc,256*size ints + stdcall mbcreate,interruptionbloc,256*ints.sizeof mov es,ax mov ax,0x0000 mov ds,ax xor si,si -@@searchdummypointer: - mov fs,[(vector si).data.seg] - mov bx,[(vector si).data.off] - cmp [byte ptr fs:bx],0xCF ;iret - je @@founded - add si,size vector +.searchdummypointer: + mov fs,[si+vector.data.seg] + mov bx,[si+vector.data.off] + cmp byte [fs:bx],0xCF ;iret + je .founded + add si,vector.sizeof cmp si,256*4 - jb @@searchdummypointer + jb .searchdummypointer xor edx,edx - jmp @@suite -@@founded: - mov edx,[(vector si).content] -@@suite: + jmp .suite +.founded: + mov edx,[si+vector.content] +.suite: xor cx,cx xor si,si xor di,di cli -@@copy: - mov [es:(ints di).number],cl - mov [es:(ints di).locked],0 - mov [es:(ints di).vector1.content],0 - mov [es:(ints di).vector3.content],0 - mov [es:(ints di).vector4.content],0 - mov [es:(ints di).vector5.content],0 - mov [es:(ints di).vector6.content],0 - mov [es:(ints di).vector7.content],0 - mov [es:(ints di).vector8.content],0 - mov [es:(ints di).launchedlow],0 - mov [es:(ints di).launchedhigh],0 - mov [es:(ints di).calledlow],0 - mov [es:(ints di).calledhigh],0 - mov eax,[(vector si).content] +.copy: + mov [es:di+ints.number],cl + mov [es:di+ints.locked],0 + mov [es:di+ints.vector1.content],0 + mov [es:di+ints.vector3.content],0 + mov [es:di+ints.vector4.content],0 + mov [es:di+ints.vector5.content],0 + mov [es:di+ints.vector6.content],0 + mov [es:di+ints.vector7.content],0 + mov [es:di+ints.vector8.content],0 + mov [es:di+ints.launchedlow],0 + mov [es:di+ints.launchedhigh],0 + mov [es:di+ints.calledlow],0 + mov [es:di+ints.calledhigh],0 + mov eax,[si+vector.ints.content] cmp eax,edx - je @@notarealvector - mov [es:(ints di).vector1.content],eax - mov [es:(ints di).activated],1 - jmp @@copynext -@@notarealvector: - mov [es:(ints di).vector1.content],0 - mov [es:(ints di).activated],0 -@@copynext: + je .notarealvector + mov [es:di+ints.vector1.content],eax + mov [es:di+ints.activated],1 + jmp .copynext +.notarealvector: + mov [es:di+ints.vector1.content],0 + mov [es:di+ints.activated],0 +.copynext: mov bx,cx shl bx,3 sub bx,cx - add bx,offset coupling - mov [(vector si).data.seg],cs - mov [(vector si).data.off],bx - add si,size vector - add di,size ints + add bx,coupling + mov [si+vector.data.seg],cs + mov [si+vector.data.off],bx + add si,vector.sizeof + add di,ints.sizeof inc cl cmp cl,0 - jne @@copy -@@end: + jne .copy +.end: pop fs sti - ret -endp installirqhandler + retf +endp interruptionbloc db '/interrupts',0 -PROC savecontext FAR -ARG @pointer:word -USES eax,si,ds +proc savecontext, pointer pushfd push eax push ebx @@ -287,125 +266,121 @@ push es push fs push gs push ss -mov si,[@pointer] +mov si,[pointer] mov ds,[ss:bp+4] mov eax,ebp -mov ax,[word ptr ss:bp] +mov ax,word [ss:bp] push eax -push [word ptr ss:bp+4] +push word [ss:bp+4] xor eax,eax -mov ax,[word ptr ss:bp+2] +mov ax,word [ss:bp+2] push eax mov ax,bp add ax,4 push eax -pop [(regs si).sesp] -pop [(regs si).seip] -pop [(regs si).scs] -pop [(regs si).sebp] -pop [(regs si).sss] -pop [(regs si).sgs] -pop [(regs si).sfs] -pop [(regs si).ses] -pop [(regs si).sds] -pop [(regs si).sedi] -pop [(regs si).sesi] -pop [(regs si).sedx] -pop [(regs si).secx] -pop [(regs si).sebx] -pop [(regs si).seax] -pop [(regs si).seflags] -ret -endp savecontext +pop [si+regs.sesp] +pop [si+regs.seip] +pop [si+regs.scs] +pop [si+regs.sebp] +pop [si+regs.sss] +pop [si+regs.sgs] +pop [si+regs.sfs] +pop [si+regs.ses] +pop [si+regs.sds] +pop [si+regs.sedi] +pop [si+regs.sesi] +pop [si+regs.sedx] +pop [si+regs.secx] +pop [si+regs.sebx] +pop [si+regs.seax] +pop [si+regs.seflags] +retf +endp -PROC restorecontextg FAR -ARG @pointer:word -mov si,[@pointer] -pushd [cs:(regs si).sesi] -pushd [cs:(regs si).seflags] -mov eax,[cs:(regs si).seax] -mov ebx,[cs:(regs si).sebx] -mov ecx,[cs:(regs si).secx] -mov edx,[cs:(regs si).sedx] -mov edi,[cs:(regs si).sedi] -mov ebp,[cs:(regs si).sebp] -mov es,[cs:(regs si).ses] -mov fs,[cs:(regs si).sfs] -mov gs,[cs:(regs si).sgs] -mov ds,[cs:(regs si).sds] +proc restorecontextg, pointer +mov si,[pointer] +pushd [cs:si+regs.sesi] +pushd [cs:si+regs.seflags] +mov eax,[cs:si+regs.seax] +mov ebx,[cs:si+regs.sebx] +mov ecx,[cs:si+regs.secx] +mov edx,[cs:si+regs.sedx] +mov edi,[cs:si+regs.sedi] +mov ebp,[cs:si+regs.sebp] +mov es,[cs:si+regs.ses] +mov fs,[cs:si+regs.sfs] +mov gs,[cs:si+regs.sgs] +mov ds,[cs:si+regs.sds] popfd pop esi pop [cs:dummy] db 0xCA,0x02,0x00 ;retf 2 -endp restorecontextg +endp coupling: -counter = 0 -REPEAT 256 -push counter+256 +repeat 256 +push %+256 push offset irqhandlers ret -counter = counter + 1 -ENDM +end repeat interrupt dw 0 dummy dw 0 -calling_reg regs <> -function_reg regs <> +calling_reg regs +function_reg regs irqhandlers: cli pop [cs:interrupt] -call savecontext,offset calling_reg -call irqhandler,[cs:interrupt] -call restorecontextg,offset calling_reg +stdcall savecontext,offset calling_reg +stdcall irqhandler,[cs:interrupt] +stdcall restorecontextg,offset calling_reg sti iret -PROC irqhandler NEAR -ARG @int:word +proc irqhandler, int push cs pop ds -call mbfindsb,offset interruptionbloc,cs -jc @@end +stdcall mbfindsb,offset interruptionbloc,cs +jc .end mov es,ax -mov ax,[@int] +mov ax,[int] sub ax,256 -mov cx,size ints +mov cx,ints.sizeof mul cx mov si,ax -add [es:(ints si).calledlow],1 -adc [es:(ints si).calledhigh],0 -cmp [es:(ints si).activated],1 -jne @@end -add [es:(ints si).launchedlow],1 -adc [es:(ints si).launchedhigh],0 -lea si,[es:(ints si).vector1] +add [es:si+ints.calledlow],1 +adc [es:si+ints.calledhigh],0 +cmp [es:si+ints.activated],1 +jne .end +add [es:si+ints.launchedlow],1 +adc [es:si+ints.launchedhigh],0 +lea si,[es:si+ints.vector1] mov cl,8 -@@launchall: -cmp [es:(vector si).content],0 -je @@end -push [word ptr cs:calling_reg.seflags] +.launchall: +cmp [es:si+vector.content],0 +je .end +push word [cs:calling_reg.seflags] push cs -push offset @@back -push [es:(vector si).data.seg] -push [es:(vector si).data.off] -call savecontext,offset function_reg -call restorecontextg,offset calling_reg +push offset .back +push [es:si+vector.data.seg] +push [es:si+vector.data.off] +stdcall savecontext,offset function_reg +stdcall restorecontextg,offset calling_reg db 0xCB -@@back: +.back: cli -call savecontext,offset calling_reg -call restorecontextg,offset function_reg -@@next: -add si,size vector +stdcall savecontext,offset calling_reg +stdcall restorecontextg,offset function_reg +.next: +add si,vector.sizeof dec cl -jnz @@launchall -@@end: +jnz .launchall +.end: ret -endp irqhandler +endp diff --git a/noyau/makefile b/noyau/makefile index cd30103..87448dd 100644 --- a/noyau/makefile +++ b/noyau/makefile @@ -1,83 +1,16 @@ -GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -I ../include -m32 -fno-pie -no-pie -c -o -ASM=gcc -nostdinc -ffreestanding -fno-builtin -m32 -c -fno-pie -no-pie -I ../include -D__ASSEMBLY__ -c -o -LINK=ld -m elf_i386 -n -CONVERT=dos2unix -INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl -REMOVE=rm -f -CHANGEPERM=chmod 644 -NM=nm -OBJCOPY=objcopy -O binary -R .note -R .comment -S -OBJDEBUG=objcopy --only-keep-debug -ZOFFSET=sed -n -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p' -VOFFSET=sed -n -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' -COMP=gzip -9 -f -BUILD=../tools/build -MKPIGGY=../tools/mkpiggy +ASM=fasm +CLEAN=rm -rf -all: system.sys +all: systeme.sys disque.sys video.sys -system.sys: piggy.o voffset.h zoffset.h realmode/setup.bin - $(BUILD) realmode/setup.bin system.bin zoffset.h system.sys - sync +systeme.sys: systeme.asm + $(ASM) $^ -allpiggy.o: piggy.o decompress.o header.o - $(LINK) -T allpiggy piggy.o decompress.o header.o +disque.sys: disque.asm + $(ASM) $^ -voffset.h: system - $(NM) system|$(VOFFSET)>voffset.h - -zoffset.h: piggy.o - $(NM) piggy.o|$(ZOFFSET)>zoffset.h - -togit: clean indent - -piggy.o: piggy.S - $(ASM) $@ $^ - -system: system.o system_asm.o ../lib/libs.o - $(LINK) -T system.ld system.o system_asm.o ../lib/libs.o - $(OBJDEBUG) system system.sym - $(NM) system > system.map - -system.bin: system - $(OBJCOPY) $^ $@ - -system.bin.gz: system.bin - cat $^|$(COMP) > $@ - -piggy.S: system.bin.gz - $(MKPIGGY) $^ > $@ - -realmode/setup.bin: - make -C realmode - -system.o: system.c - $(GCC) $@ $^ - -system_asm.o: system_asm.S - $(ASM) $@ $^ +video.sys: video.asm + $(ASM) $^ clean: - make -C realmode clean - $(REMOVE) system - $(REMOVE) piggy.S - $(REMOVE) *.o - $(REMOVE) *.tmp - $(REMOVE) *.sym - $(REMOVE) *.map - $(REMOVE) *.gz - $(REMOVE) *.h - $(REMOVE) *.out - $(REMOVE) *.bin - $(REMOVE) *.sys - $(REMOVE) *.s - $(REMOVE) *.c~ - sync - -indent: - make -C realmode indent - $(CHANGEPERM) *.c - $(CONVERT) *.c - $(INDENT) *.c - $(REMOVE) *.c~ - sync + $(CLEAN) *.sys diff --git a/noyau/mcb.asm b/noyau/mcb.asm index 984dd98..fbf4850 100644 --- a/noyau/mcb.asm +++ b/noyau/mcb.asm @@ -1,56 +1,51 @@ ;Affiche le nombre hexa dans %0[dword] -PROC biosprinth FAR - ARG @num:dword - USES ax,bx,cx,edx,si,di - mov edx,[@num] +proc biosprinth, num:dword + mov edx,[num] mov ah,09h mov di,8 -@@hexaize: +.hexaize: rol edx,4 mov si,dx and si,1111b - mov al,[cs:si+offset @@tab] + mov al,[cs:si+.tab] mov cx,1 cmp al,32 - jb @@control + jb .control mov bx,7 mov ah,09h int 10h -@@control: +.control: mov ah,0Eh int 10h dec di - jnz @@hexaize - ret -@@tab db '0123456789ABCDEF' -endp biosprinth + jnz .hexaize + retf +.tab db '0123456789ABCDEF' +endp ;Affiche le texte ASCIIZ pointé par %0 -PROC biosprint FAR - ARG @pointer:word - USES ax,bx,cx,si - mov si,[@pointer] +proc biosprint, pointer + mov si,[pointer] mov cx,1 mov bx,7 -@@again: +.again: lodsb or al,al - jz @@fin + jz .fin cmp al,32 - jb @@control + jb .control mov ah,09h int 10h -@@control: +.control: mov ah,0Eh int 10h - jmp @@again -@@fin: - ret -endp biosprint + jmp .again +.fin: + retf +endp -PROC enablea20 FAR - USES ax +proc enablea20 mov al,0d1h out 64h,al call a20wait @@ -60,11 +55,10 @@ PROC enablea20 FAR ;mov al,0ffh ;out 64h,al ;call a20wait - ret -endp enablea20 + retf +endp -PROC disablea20 FAR - USES ax +proc disablea20 mov al,0d1h out 64h,al call a20wait @@ -74,13 +68,13 @@ PROC disablea20 FAR ;mov al,0ffh ;out 64h,al ;call a20wait - ret -endp disablea20 + retf +endp a20wait: in al,64h - jmp @@suite -@@suite: + jmp .suite +.suite: and al,2 jnz a20wait ret @@ -94,73 +88,69 @@ a20wait: ;and al,not 2 ;out 92h,al -PROC flatmode FAR - USES eax,bx,ds +proc flatmode push cs pop ds ; first, calculate the linear address of GDT xor eax,eax mov ax,ds shl eax,4 - add [dword ptr offset @@gdt+2],eax ; store as GDT linear base addr + add dword [.gdt+2],eax ; store as GDT linear base addr ; now load the GDT into the GDTR - lgdt [fword ptr offset @@gdt] ; load GDT base - mov bx,1 * size descriptor ; point to first descriptor + lgdt fword [.gdt] ; load GDT base + mov bx,1 * descriptor.sizeof ; point to first descriptor cli ; turn off interrupts mov eax,cr0 ; prepare to enter protected mode or al,1 ; flip the PE bit mov cr0,eax ; we're now in protected mode - jmp @@suite -@@suite: + jmp .suite +.suite: mov fs,bx ; load the FS segment register and al,0FEh ; clear the PE bit again mov cr0,eax ; back to real mode - jmp @@suite2 -@@suite2: + jmp .suite2 +.suite2: sti ; resume handling interrupts - ret ; + retf ; -@@gdt descriptor ; the GDT itself - descriptor <0ffffh, 0, 0, 091h, 0cfh, 0> ; 4G data segment -@@gdtend: -endp flatmode +.gdt: +gdtitse descriptor .gdtend - .gdt - 1, .gdt, 0, 0, 0, 0 ; the GDT itself +gdtdata descriptor 0ffffh, 0, 0, 091h, 0cfh, 0 ; 4G data segment +.gdtend: +endp ;Attend l'appuie sur une touche -PROC bioswaitkey FAR - USES ax +proc bioswaitkey xor ax,ax int 16h - ret -endp bioswaitkey + retf +endp firstmb dw 0 ;Charge les sections du block %0 -PROC mbloadsection FAR - ARG @blocks:word - USES ax,bx,cx,si,di,ds,es - LOCAL @@toresov:word:60 - mov ax,[@blocks] +proc mbloadsection, blocks + mov ax,[blocks] mov es,ax mov ds,ax - cmp [word ptr 0],"EC" - jne @@notace - lea si,[@@toresov] - mov [word ptr ss:si],0FFFFh + cmp word [0],"EC" + jne .notace + lea si,[.toresov] + mov word [ss:si],0FFFFh mov bx,[ds:exe.sections] cmp bx,0 - je @@finishloading -@@loading: - cmp [dword ptr bx],0 - je @@finishloading + je .finishloading +.loading: + cmp dword [bx],0 + je .finishloading mov ax,bx add ax,4 pushad -call biosprint,ax +stdcall biosprint,ax popad - call mbcreate,ax,[word ptr bx+2] - jc @@error + stdcall mbcreate,ax,word [bx+2] + jc .error inc si inc si mov [ss:si],ax @@ -173,101 +163,99 @@ popad rep movsb pop si add bx,4 -@@gonext: +.gonext: inc bx - cmp [byte ptr bx],0 - jne @@gonext + cmp byte [bx],0 + jne .gonext inc bx - jmp @@loading -@@finishloading: - cmp [word ptr ss:si],0FFFFh - je @@finishdepands - call mbloadfuncs,[word ptr ss:si] - jc @@depandserror + jmp .loading +.finishloading: + cmp word [ss:si],0FFFFh + je .finishdepands + stdcall mbloadfuncs,word [ss:si] + jc .depandserror dec si dec si - jmp @@finishloading -@@finishdepands: - ret -@@notace: + jmp .finishloading +.finishdepands: + retf +.notace: stc - ret -@@error: + retf +.error: stc - ret -@@depandserror: + retf +.depandserror: stc - ret -endp mbloadsection + retf + .toresov dw 60 dup (0) +endp ;Initialise les blocs de mémoire en prenant memorystart pour segment de base -PROC mbinit FAR - USES ax,cx,si,di,ds,es +proc mbinit cmp [cs:firstmb],0 - jne @@alreadyok + jne .alreadyok push cs pop ds mov [cs:firstmb],memorystart mov ax,memorystart-2 mov es,ax - mov si,offset afree + mov si,afree xor di,di - mov cx,size mb + mov cx,mb.sizeof rep movsb clc - ret -@@alreadyok: + retf +.alreadyok: stc - ret -endp mbinit + retf +endp -afree mb <"HN",0,0,0,0A000h-memorystart,"Libre"> +afree mb "HN",0,0,0,0A000h-memorystart,"Libre" db 0 ;Creér un bloc de nom %0 de taille %1 (octets) -> n°segment dans AX -PROC mbcreate FAR - ARG @blocks:word,@size:word - USES bx,cx,dx,si,di,ds,es +proc mbcreate , blocks, size push gs mov ax,[ss:bp+4] mov dx,ax dec dx dec dx mov gs,dx - cmp [word ptr gs:0x0],'NH' - je @@oktoset + cmp word [gs:0x0],'NH' + je .oktoset mov ax,memorystart -@@oktoset: +.oktoset: mov gs,ax - mov cx,[@size] + mov cx,[size] shr cx,4 inc cx mov bx,[cs:firstmb] dec bx dec bx mov dl,true -@@searchfree: +.searchfree: cmp dl,false - je @@notenougtmem + je .notenougtmem mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror cmp [es:mb.isnotlast],true sete dl cmp [es:mb.reference],free - jne @@notsogood + jne .notsogood mov ax,[es:mb.sizes] cmp cx,ax - ja @@notsogood - mov [word ptr es:mb.check],"NH" + ja .notsogood + mov word [es:mb.check],"NH" mov [es:mb.isnotlast],true mov [es:mb.reference],gs mov [es:mb.isresident],false lea di,[es:mb.names] push cx mov cx,24/4 - mov si,[@blocks] + mov si,[blocks] cld rep movsd pop cx @@ -275,60 +263,58 @@ PROC mbcreate FAR inc bx sub ax,cx cmp ax,0 - je @@nofree + je .nofree dec ax dec ax mov [es:mb.sizes],cx add cx,bx mov es,cx - mov si,offset afree + mov si,afree xor di,di - mov cx,size mb + mov cx,mb.sizeof push cs pop ds cld rep movsb mov [es:mb.isnotlast],dl mov [es:mb.sizes],ax -@@nofree: +.nofree: mov ax,bx pop gs clc - ret -@@notsogood: + retf +.notsogood: inc bx inc bx add bx,[es:mb.sizes] - jmp @@searchfree -@@memoryerror: + jmp .searchfree +.memoryerror: pop gs stc - ret -@@notenougtmem: + retf +.notenougtmem: pop gs stc - ret -endp mbcreate + retf +endp ;Libère le bloc de mémoire %0 et ses sous blocs -PROC mbfree FAR - ARG @blocks:word - USES ax,bx,cx,si,di,ds,es - mov bx,[@blocks] +proc mbfree, blocks + mov bx,[blocks] mov ax,bx dec bx dec bx mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror cmp [es:mb.reference],free - je @@wasfree + je .wasfree cmp [es:mb.isresident],true - je @@wasresident + je .wasresident mov [es:mb.reference],free push cs pop ds - mov si,offset @@isfree + mov si,.isfree lea di,[es:mb.names] mov cx,6 cld @@ -336,414 +322,395 @@ PROC mbfree FAR mov bx,[cs:firstmb] dec bx dec bx -@@searchtofree: +.searchtofree: mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror inc bx inc bx add bx,[es:mb.sizes] cmp [es:mb.sizes],0 - je @@nottofree + je .nottofree cmp ax,[es:mb.reference] - jne @@nottofree + jne .nottofree mov [es:mb.isresident],false mov [es:mb.reference],free - mov si,offset @@isfree + mov si,.isfree lea di,[es:mb.names] mov cx,6 cld rep movsb -@@nottofree: +.nottofree: cmp [es:mb.isnotlast],true - je @@searchtofree - call mbclean - ret -@@memoryerror: + je .searchtofree + stdcall mbclean + retf +.memoryerror: stc - ret -@@wasfree: + retf +.wasfree: stc - ret -@@wasresident: + retf +.wasresident: stc - ret + retf -@@isfree db "libre",0 -endp mbfree +.isfree db "libre",0 +endp ;Mise a nivo de la mémoire (jonction de blocs libre) -PROC mbclean FAR - USES ax,bx,dx,es,gs +proc mbclean mov bx,[cs:firstmb] dec bx dec bx xor ax,ax xor dx,dx -@@searchfree: +.searchfree: mov gs,bx - cmp [word ptr gs:mb.check],"NH" - jne @@memoryerror + cmp word [gs:mb.check],"NH" + jne .memoryerror inc bx inc bx add bx,[gs:mb.sizes] - cmp [word ptr gs:mb.sizes],0 - je @@notenougtmem + cmp word [gs:mb.sizes],0 + je .notenougtmem cmp [gs:mb.reference],free - jne @@notfree + jne .notfree cmp ax,0 - je @@notmeetfree + je .notmeetfree add dx,[gs:mb.sizes] - mov [word ptr gs:mb.check],0 - mov [dword ptr gs:mb.names],0 + mov word [gs:mb.check],0 + mov dword [gs:mb.names],0 inc dx inc dx - jmp @@nottrigered -@@notmeetfree: + jmp .nottrigered +.notmeetfree: xor dx,dx mov ax,gs - jmp @@nottrigered -@@notfree: + jmp .nottrigered +.notfree: cmp ax,0 - je @@nottrigered + je .nottrigered mov es,ax add [es:mb.sizes],dx xor ax,ax -@@nottrigered: +.nottrigered: cmp [gs:mb.isnotlast],true - je @@searchfree + je .searchfree cmp ax,0 - je @@reallyfinish + je .reallyfinish mov es,ax add [es:mb.sizes],dx mov [es:mb.isnotlast],false -@@reallyfinish: +.reallyfinish: clc - ret -@@notenougtmem: + retf +.notenougtmem: stc - ret -@@memoryerror: + retf +.memoryerror: stc - ret -endp mbclean + retf +endp ;Rend le segment %0 résident -PROC mbresident FAR - ARG @blocks:word - USES bx,es - mov bx,[@blocks] +proc mbresident, blocks + mov bx,[blocks] dec bx dec bx mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror mov [es:mb.isresident],true - ret -@@memoryerror: + retf +.memoryerror: stc - ret -endp mbresident + retf +endp ;Rend le segment %0 non résident -PROC mbnonresident FAR - ARG @blocks:word - USES bx,es - mov bx,[@blocks] +proc mbnonresident, blocks + mov bx,[blocks] dec bx dec bx mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror mov [es:mb.isresident],false - ret -@@memoryerror: + retf +.memoryerror: stc - ret -endp mbnonresident + retf +endp ;Change le proprietaire de %0 a %1 -PROC mbchown FAR - ARG @blocks:word,@owner:word - USES bx,dx,es - mov bx,[@blocks] +proc mbchown ,blocks, owner + mov bx,[blocks] dec bx dec bx mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror cmp [es:mb.reference],free - je @@wasfree - mov dx,[@owner] + je .wasfree + mov dx,[owner] mov [es:mb.reference],dx - ret -@@memoryerror: + retf +.memoryerror: stc - ret -@@wasfree: + retf +.wasfree: stc - ret -endp mbchown + retf +endp ;Alloue un bloc /data de CX caractere pour le process appelant -> ax -PROC mballoc FAR - ARG @size:word - USES si,ds +proc mballoc, size push cs pop ds - call mbcreate,offset @@data,[@size] - call mbchown,ax,[word ptr ss:bp+4] - ret + stdcall mbcreate,.data,[size] + stdcall mbchown,ax,word [ss:bp+4] + retf -@@data db '/data',0 -endp mballoc +.data db '/data',0 +endp ;Renvoie en AX le MB n° %0 carry quand terminé -PROC mbget FAR - ARG @num:word - USES bx,dx,es +proc mbget, num mov bx,[cs:firstmb] dec bx dec bx xor dx,dx -@@searchfree: +.searchfree: mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror inc bx inc bx add bx,[es:mb.sizes] cmp [es:mb.sizes],0 - je @@memoryerror - cmp dx,[@num] - je @@foundmcb - ja @@notfound + je .memoryerror + cmp dx,[num] + je .foundmcb + ja .notfound inc dx cmp [es:mb.isnotlast],true - je @@searchfree -@@memoryerror: + je .searchfree +.memoryerror: stc - ret -@@foundmcb: + retf +.foundmcb: mov ax,es inc ax inc ax clc - ret -@@notfound: + retf +.notfound: stc - ret -endp mbget + retf +endp ;Renvoie en AX le MCB qui correspond a ds:%0 -PROC mbfind FAR - ARG @blocks:word - USES bx,si,di,es +proc mbfind, blocks mov bx,[cs:firstmb] dec bx dec bx - mov si,[@blocks] -@@search: + mov si,[blocks] +.search: mov es,bx lea di,[es:mb.names] - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror inc bx inc bx add bx,[es:mb.sizes] cmp [es:mb.sizes],0 - je @@memoryerror + je .memoryerror push si di -@@cmpnames: +.cmpnames: mov al,[es:di] cmp al,[ds:si] - jne @@ok + jne .ok cmp al,0 - je @@ok + je .ok inc si inc di - jmp @@cmpnames -@@ok: + jmp .cmpnames +.ok: pop di si - je @@foundmcb + je .foundmcb cmp [es:mb.isnotlast],true - je @@search -@@notfound: + je .search +.notfound: stc - ret -@@memoryerror: + retf +.memoryerror: stc - ret -@@foundmcb: + retf +.foundmcb: mov ax,es inc ax inc ax clc - ret -endp mbfind + retf +endp ;Renvoie en AX le sous mcb qui correspond a %0 et qui appartien a %1 -PROC mbfindsb FAR - ARG @blocks:word,@owner:word - USES bx,dx,si,di,es +proc mbfindsb, blocks, owner mov bx,[cs:firstmb] dec bx dec bx - mov si,[@blocks] + mov si,[blocks] lea di,[es:mb.names] - mov dx,[@owner] -@@search: + mov dx,[owner] +.search: mov es,bx - cmp [word ptr es:mb.check],"NH" - jne @@memoryerror + cmp word [es:mb.check],"NH" + jne .memoryerror inc bx inc bx add bx,[es:mb.sizes] cmp [es:mb.sizes],0 - je @@memoryerror + je .memoryerror push si di -@@cmpnames: +.cmpnames: mov al,[es:di] cmp al,[ds:si] - jne @@ok + jne .ok cmp al,0 - je @@ok + je .ok inc si inc di - jmp @@cmpnames -@@ok: + jmp .cmpnames +.ok: pop di si - jne @@notfoundmcb + jne .notfoundmcb cmp [es:mb.reference],dx - je @@foundmcb -@@notfoundmcb: + je .foundmcb +.notfoundmcb: cmp [es:mb.isnotlast],true - je @@search -@@notfound: + je .search +.notfound: stc - ret -@@foundmcb: + retf +.foundmcb: mov ax,es inc ax inc ax clc - ret -@@memoryerror: + retf +.memoryerror: stc - ret -endp mbfindsb + retf +endp ;Resouds les dépendances du bloc de mémoire %0 -PROC mbloadfuncs FAR - ARG @blocks:word - USES ax,bx,cx,dx,si,ds - mov ds,[@blocks] - cmp [word ptr 0],"EC" - jne @@notace +proc mbloadfuncs, blocks + mov ds,[blocks] + cmp word [0],"EC" + jne .notace mov si,[ds:exe.imports] cmp si,0 - je @@endofloading -@@loadfuncs: - cmp [word ptr si],0 - je @@endofloading - call mbsearchfunc,si - jnc @@toendoftext + je .endofloading +.loadfuncs: + cmp word [si],0 + je .endofloading + stdcall mbsearchfunc,si + jnc .toendoftext mov bx,si ;pushad -;call biosprint,si +;stdcall biosprint,si ;popad -@@findend: +.findend: inc bx - cmp [byte ptr bx], ':' - jne @@findend - mov [byte ptr bx],0 - call [cs:projfile],si - mov [byte ptr bx],':' - jc @@erroronload + cmp byte [bx], ':' + jne .findend + mov byte [bx],0 + stdcall [cs:projfile],si + mov byte [bx],':' + jc .erroronload ;pushad -;call biosprint,si +;stdcall biosprint,si ;popad - call mbsearchfunc,si - jc @@libnotexist -@@toendoftext: + stdcall mbsearchfunc,si + jc .libnotexist +.toendoftext: mov cl,[si] cmp cl,0 - je @@oktonext + je .oktonext inc si - jmp @@toendoftext -@@oktonext: + jmp .toendoftext +.oktonext: inc si mov [si],ax mov [si+2],dx add si,4 - jmp @@loadfuncs -@@endofloading: + jmp .loadfuncs +.endofloading: clc - ret -@@notace: + retf +.notace: stc - ret -@@libnotexist: + retf +.libnotexist: stc - ret -@@erroronload: + retf +.erroronload: stc - ret -endp mbloadfuncs + retf +endp ;Recherche une fonction pointé par DS:%0 en mémoire et renvoie son adresse en DX:AX -PROC mbsearchfunc FAR - ARG @func:word - USES bx,si,di,es - mov bx,[@func] +proc mbsearchfunc, func + mov bx,[func] mov si,bx -@@findend: +.findend: inc bx - cmp [byte ptr bx], ':' - jne @@findend - mov [byte ptr bx],0 - call mbfind,si - mov [byte ptr bx],':' - jc @@notfoundattallthesb + cmp byte [bx], ':' + jne .findend + mov byte [bx],0 + stdcall mbfind,si + mov byte [bx],':' + jc .notfoundattallthesb mov es,ax - cmp [word ptr es:exe.checks],"EC" - jne @@notfoundattallthesb + cmp word [es:exe.checks],"EC" + jne .notfoundattallthesb mov di,[es:exe.exports] inc bx inc bx -@@functions: - cmp [word ptr es:di],0 - je @@notfoundattallthesb +.functions: + cmp word [es:di],0 + je .notfoundattallthesb mov si,bx -@@cmpnamesfunc: +.cmpnamesfunc: mov al,[es:di] cmp al,[ds:si] - jne @@notfoundthesb + jne .notfoundthesb cmp al,0 - je @@seemsok + je .seemsok inc si inc di - jmp @@cmpnamesfunc -@@notfoundthesb: + jmp .cmpnamesfunc +.notfoundthesb: mov al,[es:di] cmp al,0 - je @@oktonext + je .oktonext inc di - jmp @@notfoundthesb -@@oktonext: + jmp .notfoundthesb +.oktonext: inc di inc di inc di - jmp @@functions -@@seemsok: + jmp .functions +.seemsok: mov dx,es mov ax,[es:di+1] clc - ret -@@notfoundattallthesb: + retf +.notfoundattallthesb: stc - ret -endp mbsearchfunc + retf +endp diff --git a/noyau/systeme.asm b/noyau/systeme.asm index a7e2234..a61b7a1 100644 --- a/noyau/systeme.asm +++ b/noyau/systeme.asm @@ -1,9 +1,3 @@ -model tiny,stdcall -p586N -locals -jumps -codeseg -option procalign:byte include "..\include\mem.h" include "..\include\divers.h" @@ -16,7 +10,7 @@ memorystart equ 0052h ;premier bloc de la m org 0h mb0: -header exe <"CE",1,0,0,offset exports,offset imports,offset section,offset start> +header exe 1 start: push cs @@ -27,20 +21,20 @@ start: pop es pop fs pop gs - call biosprint,offset return - call biosprint,offset msg_memory - call biosprint,offset return - call biosprint,offset msg_memory_init - call mbinit + stdcall biosprint,makereturn + stdcall biosprint,msg_memory + stdcall biosprint,makereturn + stdcall biosprint,msg_memory_init + stdcall mbinit jc error - call biosprint,offset msg_ok - call biosprint,offset msg_memory_section + stdcall biosprint,msg_ok + stdcall biosprint,msg_memory_section mov ax,cs - call mbloadsection,ax + stdcall mbloadsection,ax jc error - call biosprint,offset msg_ok - call biosprint,offset msg_memory_jumps - jmp [dword ptr cs:pointer] + stdcall biosprint,msg_ok + stdcall biosprint,msg_memory_jumps + jmp dword [cs:pointer] pointer: dw suite dw memorystart @@ -53,29 +47,29 @@ suite: pop es pop fs pop gs - call biosprint,offset msg_ok - call biosprint,offset msg_video_init - call [cs:setvideomode],2 + stdcall biosprint,msg_ok + stdcall biosprint,msg_video_init + stdcall [cs:setvideomode],2 jc error - call [cs:clearscreen] - call [cs:print],offset msg_memory - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_memory_init - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_memory_section - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_memory_jumps - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_video_init - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_handler - ;call installirqhandler - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_cpu_detect - call [cs:cpuinfo],offset thecpu - call [cs:setinfo],offset thecpu,offset temp - call [cs:print],offset msg_ok2 - push offset temp + stdcall [cs:clearscreen] + stdcall [cs:print],msg_memory + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_memory_init + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_memory_section + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_memory_jumps + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_video_init + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_handler + ;stdcall installirqhandler + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_cpu_detect + stdcall [cs:cpuinfo],thecpu + stdcall [cs:setinfo],thecpu,temporary + stdcall [cs:print],msg_ok2 + push temporary xor eax,eax mov al,[thecpu.family] push eax @@ -83,13 +77,13 @@ suite: push eax mov al,[thecpu.stepping] push eax - push offset thecpu.names - push offset thecpu.vendor - call [cs:print],offset msg_cpu_detect_inf - call [cs:print],offset msg_pci - call [cs:pciinfo],offset thepci + push thecpu.names + push thecpu.vendor + stdcall [cs:print],msg_cpu_detect_inf + stdcall [cs:print],msg_pci + stdcall [cs:pciinfo],thepci jc nopci - call [cs:print],offset msg_ok2 + stdcall [cs:print],msg_ok2 xor eax,eax mov al,[thepci.maxbus] push eax @@ -97,25 +91,25 @@ suite: push eax mov al,[thepci.version_major] push eax - call [cs:print],offset msg_pci_info - call [cs:print],offset msg_pci_enum + stdcall [cs:print],msg_pci_info + stdcall [cs:print],msg_pci_enum xor ebx,ebx xor ecx,ecx xor si,si searchpci: - call [cs:getcardinfo],bx,cx,si,offset temp + stdcall [cs:getcardinfo],bx,cx,si,temporary jc stopthis - mov al,[(pcidata offset temp).subclass] + mov al,[temporary+pcidata.subclass] push ax - mov al,[(pcidata offset temp).class] + mov al,[temporary+pcidata.class] push ax - call [cs:getpcisubclass] + stdcall [cs:getpcisubclass] push dx push ax - mov al,[(pcidata offset temp).class] + mov al,[temporary+pcidata.class] xor ah,ah push ax - call [cs:getpciclass] + stdcall [cs:getpciclass] push dx push ax push 4 @@ -124,11 +118,11 @@ searchpci: push ecx push 4 push ebx - mov ax,[(pcidata offset temp).device] + mov ax,[temporary+pcidata.device] push eax - mov ax,[(pcidata offset temp).vendor] + mov ax,[temporary+pcidata.vendor] push eax - call [cs:print],offset msg_pci_card + stdcall [cs:print],msg_pci_card inc si cmp si,7 jbe searchpci @@ -143,42 +137,42 @@ stopthis: jbe searchpci jmp next nopci: - call [cs:print],offset msg_echec2 + stdcall [cs:print],msg_echec2 next: - ;call [cs:detectvmware] + ;stdcall [cs:detectvmware] ;jne novirtual - ;call [cs:print],offset msg_vmware + ;stdcall [cs:print],msg_vmware novirtual: - ;call [cs:print],offset msg_flat - ;call enablea20 - ;call flatmode + ;stdcall [cs:print],msg_flat + ;stdcall enablea20 + ;stdcall flatmode ;xor ax,ax ;mov fs,ax ;mov esi,0100000h ;mov [dword ptr fs:esi],"OKIN" - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_disk_init - call [cs:initdrive] + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_disk_init + stdcall [cs:initdrive] jc error2 - call [cs:print],offset msg_ok2 - call [cs:print],offset msg_launchcommand - call [cs:execfile],offset shell + stdcall [cs:print],msg_ok2 + stdcall [cs:print],msg_launchcommand + stdcall [cs:execfile],shell jc error2 error2: - call [cs:print],offset msg_error2 - call bioswaitkey + stdcall [cs:print],msg_error2 + stdcall bioswaitkey jmp far 0FFFFh:0000h error: - call biosprint,offset msg_error - call bioswaitkey + stdcall biosprint,msg_error + stdcall bioswaitkey jmp far 0FFFFh:0000h -shell find <"COMMANDE.CE",0,0,0,1,> -thepci pciinf <> -thecpu cpu <> -temp db 256 dup (0) -return db 0dh,0ah,0 +shell find "COMMANDE.CE\0" +thepci pciinf +thecpu cpu +temporary db 256 dup (0) +makereturn db 0dh,0ah,0 msg_memory db "Initialisation de la memoire",0 msg_memory_init db " -Creation du bloc primordial",0 msg_memory_section db " -Developpement des sections",0 @@ -260,37 +254,37 @@ endi include "mcb.asm" include "8259a.asm" -section: -dw offset mb0 -dw offset mb1-offset mb0 +allsection: +dw mb0 +dw mb1-mb0 db "SYSTEME",0 -dw offset mb1 -dw offset mb2-offset mb1 +dw mb1 +dw mb2-mb1 db "VIDEO",0 -dw offset mb2 -dw offset mb3-offset mb2 +dw mb2 +dw mb3-mb2 db "VIDEO.LIB",0 -dw offset mb3 -dw offset mb4-offset mb3 +dw mb3 +dw mb4-mb3 db "DETECT.LIB",0 -dw offset mb4 -dw offset mb5-offset mb4 +dw mb4 +dw mb5-mb4 db "DISQUE",0 dd 0 mb1: -includebin "video.sys" +file "video.sys" mb2: -includebin "..\lib\video.lib" +file "..\lib\video.lib" mb3: -includebin "..\lib\detect.lib" +file "..\lib\detect.lib" mb4: -includebin "disque.sys" +file "disque.sys" mb5: