diff --git a/boot/boot12.asm b/boot/boot12.asm index 6b2242f..550d4ed 100755 --- a/boot/boot12.asm +++ b/boot/boot12.asm @@ -49,100 +49,107 @@ Boot_Ok: Boot: push cs push cs - pop es - pop ds - mov [Boot_Drive],dl + pop es + pop ds + mov [Boot_Drive],dl cli - mov ax,0x9000 - mov ss,ax - mov sp,0xFFFF + mov ax,0x9000 + mov ss,ax + mov sp,0xFFFF sti - mov si,Boot_Message - call ShowString - xor ax,ax - int 0x13 - jc Boot_Error - mov cx,[Reserved_Sectors] - add cx,[Sectors_Hidden] - adc cx,[Sectors_Hidden+2] - mov bx,[Sectors_Per_Fat] - mov di,Fat_Buffer - push bx - push cx + mov si,Boot_Message + call ShowString +; Initialisation du lecteur de disquette + xor ax,ax + int 0x13 + jc Boot_Error +; Calcul de la position de la FAT12 + mov cx,[Reserved_Sectors] + add cx,[Sectors_Hidden] + adc cx,[Sectors_Hidden+2] + mov bx,[Sectors_Per_Fat] + mov di,Fat_Buffer + push bx + push cx +; Lecture de la FAT en mémoire readfat: call ReadSector - jc Boot_Error - inc cx - add di,[Sectors_Size] - dec bx - jnz readfat - pop cx - pop bx - xor ax,ax - mov al,[Fats_Number] - mul bx - add cx,ax - mov ax,32 - mul word [Fits_Number] - div word [Sectors_Size] - add ax,cx - sub ax,2 - mov word [Serial_Number],ax - xor dx,dx + jc Boot_Error + inc cx + add di,[Sectors_Size] + dec bx + jnz readfat + pop cx + pop bx + xor ax,ax + mov al,[Fats_Number] + mul bx + add cx,ax + mov ax,32 + mul word [Fits_Number] + div word [Sectors_Size] + add ax,cx + sub ax,2 + mov word [Serial_Number],ax + xor dx,dx call Boot_Ok - mov si,Loading_Message - call ShowString + mov si,Loading_Message + call ShowString +; Recherche du système dans les entrèes de répertoire Find_System: - mov di,Buffer + mov di,Buffer call ReadSector - jc Near Boot_Error - xor bx,bx + jc Near Boot_Error + xor bx,bx Next_Root_Entrie: - cmp byte [di],0 - je near Boot_Error + cmp byte [di],0 + je near Boot_Error push di push cx - mov si,System_File - mov cx,32 - rep cmpsb - pop cx - pop di - je System_Found - add di,32 - add bx,32 - inc dx - cmp dx,[Fits_Number] - ja near Boot_Error - cmp bx,[Sectors_Size] - jb Next_Root_Entrie - inc cx - jmp Find_System + mov si,System_File + mov cx,32 + rep cmpsb + pop cx + pop di + je System_Found + add di,32 + add bx,32 + inc dx + cmp dx,[Fits_Number] + ja near Boot_Error + cmp bx,[Sectors_Size] + jb Next_Root_Entrie + inc cx + jmp Find_System System_Found: - call Boot_Ok - mov si,Entre_Message - call ShowString - mov cx,[di+26+32] - mov ax,0x0080 - mov es,ax +; Système trouvé + call Boot_Ok + mov si,Entre_Message + call ShowString + mov cx,[di+26+32] + mov ax,0x0080 + mov es,ax push es - mov di,0x0 + mov di,0x0 push di - mov si,The_Dot + mov si,The_Dot Resume_Loading: - cmp cx,0x0FF0 - jae Finish_Loading +; Chargement des secteur en mémoire à l'adresse 0080:0000 + cmp cx,0x0FF0 + jae Finish_Loading push cx - add cx,word [Serial_Number] + add cx,word [Serial_Number] call ReadSector - pop cx - jc near Boot_Error + pop cx + jc near Boot_Error call ShowString add di,[Sectors_Size] call NextFatGroup - jc near Boot_Error - jmp Resume_Loading + jc near Boot_Error + jmp Resume_Loading Finish_Loading: call Boot_Ok +; Exécution du chargeur ELF retf ;====================READSECTOR======================= @@ -152,28 +159,28 @@ Finish_Loading: ;===================================================== ReadSector: pusha - mov ax,cx - xor dx,dx - div word [Sectors_Per_Track] - inc dl - mov bl,dl - xor dx,dx - div word [Heads_Number] - mov dh, [Boot_Drive] + mov ax,cx + xor dx,dx + div word [Sectors_Per_Track] + inc dl + mov bl,dl + xor dx,dx + div word [Heads_Number] + mov dh, [Boot_Drive] xchg dl,dh - mov cx,ax + mov cx,ax xchg cl,ch - shl cl,6 - or cl, bl - mov bx,di - mov si, 4 - mov al, 1 + shl cl,6 + or cl, bl + mov bx,di + mov si, 4 + mov al, 1 Read_Again: - mov ah, 2 - int 0x13 - jnc Read_Done - dec si - jnz Read_Again + mov ah, 2 + int 0x13 + jnc Read_Done + dec si + jnz Read_Again Read_Done: popa ret @@ -219,18 +226,18 @@ Next_Group_Found: ;<- Flag Carry si erreur ;===================================================== ShowString: - pusha + pusha Next_Char: - lodsb - or al,al - jz End_Show - mov ah,0x0E - mov bx,0x07 - int 0x10 - jmp Next_Char + lodsb + or al,al + jz End_Show + mov ah,0x0E + mov bx,0x07 + int 0x10 + jmp Next_Char End_Show: - popa - ret + popa + ret times 510-($-$$) db ' ' diff --git a/boot/boot16.asm b/boot/boot16.asm deleted file mode 100755 index 813f14c..0000000 --- a/boot/boot16.asm +++ /dev/null @@ -1,270 +0,0 @@ -[BITS 16] -[ORG 0x7C00] - -section .text - -start: - jmp near Boot - -Disk_ID db "COS2000A" ;Fabricant + n° de série Formatage -Sectors_Size dw 512 ;Nombre d'octets/secteur -Sectors_Per_Cluster db 4 ;Nombre de secteurs/cluster -Reserved_Sectors dw 1 ;Nombre de secteurs réservé -Fats_Number db 2 ;Nombre de copies de la FAT -Fits_Number dw 512 ;Taille du répertoire racine -Sectors_Per_Disk dw 2880 ;Nombre secteurs du volume si < 32 Mo -Media_Descriptor db 0xF8 ;Descripteur de média -Sectors_Per_Fat dw 207 ;Nombre secteurs/FAT -Sectors_Per_Track dw 18 ;Nombre secteurs/piste -Heads_Number dw 38 ;Nombre de tete de lecture/écriture -Sectors_Hidden dd 16 ;Nombre de secteurs cachés -Sectors_Per_Disk2 dd 39 ;Nombre secteurs du volume si > 32 Mo -Boot_Drive db 0x80 ;Lecteur de démarrage -Reserved db 0 ;NA (pour NT seulement) -Extended_Boot_ID db 0x29 ;Signature Boot étendu 29h -Serial_Number dd 0x01020304 ;N° de série -Disk_Name db "COS2000 " ;Nom de volume -Fat_Type db "FAT16 " ;Type de système de fichiers - -;Cpu_Message db "CPU test",0 -;Boot_Message db "Booting ",0 -;Finding_Message db "System ",0 -;Loading_Message db "Loading ",0 -System_File db "SYSTEM SYS" -Is_Ok db "[ OK ]",0x0A,0x0D,0 -Is_Failed db "[Failed]",0x0A,0x0D,"Press a key",0x0A,0x0D,0 -The_Dot db '.',0 - -Boot_Error: - mov si,Is_Failed - call ShowString - mov ah,0 - int 0x16 - int 0x19 - -Boot_Ok: -; mov al,[Stage] -; cmp al,0 -; jz No_Ok - mov si,Is_Ok - call ShowString -;No_Ok: -; xor ah,ah -; mov si,ax -; add si,Boot_Message ;Cpu_Message -; call ShowString -; add byte [Stage],0x09 - ret -; -;Stage db 0 - -Boot: - push cs - push cs - pop es - pop ds - mov [Boot_Drive],dl - cli - mov ax,0x9000 - mov ss,ax - mov sp,0xFFFF - sti -; call Detect_Cpu -; jc Boot_Error -; call Boot_Ok - xor ax,ax - int 0x13 -; jc Boot_Error - xor eax,eax - add ax,[Reserved_Sectors] - add ecx,eax - mov di,Fat_Buffer - call ReadSector - jc Boot_Error - xor eax,eax - mov al,[Fats_Number] - mov bx,[Sectors_Per_Fat] - mul bx - add ecx,eax - mov ax,32 - mul word [Fits_Number] - div word [Sectors_Size] - add eax,ecx - mov dword [Serial_Number],eax - xor dx,dx -; call Boot_Ok -Find_System: - mov di,Buffer - call ReadSector - jc near Boot_Error - xor bx,bx -Next_Root_Entrie: - cmp byte [di],0 - je near Boot_Error - push di - push cx - mov si,System_File - mov cx,11 - rep cmpsb - pop cx - pop di - je System_Found - add di,32 - add bx,32 - inc dx - cmp dx,[Fits_Number] - ja near Boot_Error - cmp bx,[Sectors_Size] - jb Next_Root_Entrie - inc ecx - jmp Find_System -System_Found: - xor ecx,ecx - mov cx,[di+26] - mov ax,0x0071 - mov es,ax - push es - mov di,0x100 - push di -; call Boot_Ok - mov si,The_Dot -Resume_Loading: - cmp cx,0x0FFF0 - jae Finish_Loading - call ReadGroup - jc near Boot_Error - call ShowString - mov bx,cx - shl bx,1 - mov cx,[bx+Fat_Buffer] - jmp Resume_Loading -Finish_Loading: - call Boot_Ok - retf - -;====================READSECTOR======================= -;Lit le secteur logique LBA ECX et le met en es:di -;-> ECX (limité à 2^32 secteurs, soit 2 To avec secteur 512 octets) -;<- Flag Carry si erreur -;===================================================== -ReadSector: - pushad - mov ax, cx - ror ecx,16 - mov dx,cx - rol ecx,16 - cmp ecx,4128705 - ja Extended_CHS - div word [Sectors_Per_Track] - inc dl - mov bl, dl - xor dx,dx - div word [Heads_Number] - mov dh, [Boot_Drive] - xchg dl, dh - mov cx, ax - xchg cl, ch - shl cl, 6 - or cl, bl - mov bx, di - mov si, 4 - mov al, 1 -Read_Again: - mov ah, 2 - int 0x13 - jnc Read_Done - dec si - jnz Read_Again -Read_Done: - popad - ret -Extended_CHS: - mov si,ECHS_Block - mov byte [si+Sizes],0x10 - mov byte [si+Reserve],0x01 - mov byte [si+NumSectors],0x01 - mov [si+Adressseg],es - mov [si+Adressoff],di - mov [si+SectorLow],ax - mov [si+SectorHigh],dx - mov di,4 - mov dl,[Boot_Drive] -Read_AgainX: - mov ah, 42h - int 13h - jnc Read_Done - dec di - jnz Read_AgainX - -;======================READGROUP====================== -;lit le groupe cx en es:di et incr‚mente DI -;-> cx, es:di -;<- di, Flag Carry si erreur -;===================================================== -ReadGroup: - push ax - push cx - push dx - mov al,[Sectors_Per_Cluster] - sub cx,2 - xor ah,ah - mul cx - mov cx,dx - shl ecx,16 - mov cx,ax - add ecx,dword [Serial_Number] - mov al,[Sectors_Per_Cluster] -read: - call ReadSector - jc errors - inc ecx - add di,[Sectors_Size] - dec al - jnz read - clc -errors: - pop dx - pop cx - pop ax - ret - -;======================SHOWSTR======================== -;Affiche la chaine de caractère pointé par ds:si à l'écran -;-> DS, SI -;<- Flag Carry si erreur -;===================================================== -ShowString: - ;push ax - ;push bx - ;push si - pusha -Next_Char: - lodsb - or al,al - jz End_Show - mov ah,0x0E - mov bx,0x07 - int 0x10 - jmp Next_Char -End_Show: - ;pop si - ;pop bx - ;pop ax - popa - ret - -times 510-($-$$) db ' ' - -dw 0xAA55 - -ECHS_Block equ $ -Buffer equ $+26 -Fat_Buffer equ $+26+512 - -section .bss - -%include "echs.h" - -;ECHS_Block resb 24 -;Buffer resb 512 -;Fat_Buffer resb 10000 \ No newline at end of file diff --git a/boot/loader.asm b/boot/loader.asm index a7eb206..35c8fdf 100755 --- a/boot/loader.asm +++ b/boot/loader.asm @@ -1,112 +1,113 @@ [BITS 16] [ORG 0x0] - SECTION .text - push cs - push cs - pop ds - pop es - mov si,msg0 - call showstr - - mov si,msg1 - call showstr - call initfat - call ok - - mov si,msg2 - call showstr - mov si,System_File - call search - call ok - - mov si,msg3 - call showstr - call EnableA20 - call ok - - mov si,msg4 - call showstr - mov eax,cs - shl eax,4 - mov [GDT.Entry1+2],ax - mov [GDT.Entry2+2],ax - shr eax,16 - mov [GDT.Entry1+4],al - mov [GDT.Entry2+4],al - mov eax,cs - shl eax,4 - add eax,gdt0 - mov [GDTR.Address],eax - lgdt [GDTR] -call ok - - mov si,msg5 - call showstr - cli - mov eax,cr0 - or al,1 - mov cr0,eax - jmp short $+2 - mov bx,SYS_DATA_SEL - mov fs,bx - mov ds,bx - mov es,bx - mov gs,bx - and al,0FEh - mov cr0,eax - jmp short $+2 - mov bx,cs - mov fs,bx - mov ds,bx - mov es,bx - mov gs,bx - sti -call ok - - - - mov si,msg6 - call showstr - mov ebx,0x300000 - call load -call ok - - mov si,msg7 - call showstr - call initpe -call ok - suite: - ;mov cx,suite - ;call debug - mov si,msg8 - call showstr - cli - mov al,0x80 - out 0x70,al - mov eax,cr0 - or al,1 - mov cr0,eax - jmp SYS_CODE_SEL:GoPMode32 +SECTION .text + push cs + push cs + pop ds + pop es + mov si,msg0 + call showstr +;Projection de la FAT12 en mémoire + mov si,msg1 + call showstr + call initfat + call ok +;Recherche du système + mov si,msg2 + call showstr + mov si,System_File + call search + call ok +;Activation du BUS A20 + mov si,msg3 + call showstr + call EnableA20 + call ok +;Chargement d'une GDT pour le mode FLAT REAL + mov si,msg4 + call showstr + mov eax,cs + shl eax,4 + mov [GDT.Entry1+2],ax + mov [GDT.Entry2+2],ax + shr eax,16 + mov [GDT.Entry1+4],al + mov [GDT.Entry2+4],al + mov eax,cs + shl eax,4 + add eax,gdt0 + mov [GDTR.Address],eax + lgdt [GDTR] + call ok +;Passage en mode FLAT REAL + mov si,msg5 + call showstr + cli + mov eax,cr0 + or al,1 + mov cr0,eax + jmp short $+2 + mov bx,SYS_DATA_SEL + mov fs,bx + mov ds,bx + mov es,bx + mov gs,bx + and al,0FEh + mov cr0,eax + jmp short $+2 + mov bx,cs + mov fs,bx + mov ds,bx + mov es,bx + mov gs,bx + sti + call ok +;Chargement du noyau en 0x30000 + mov si,msg6 + call showstr + mov ebx,0x300000 + call load + call ok +;Chargement du fichier PE + mov si,msg7 + call showstr + call initpe + call ok + + ;suite: + ;mov cx,suite + ;call debug + mov si,msg8 + call showstr + cli +;Passage en mode protégé + mov al,0x80 + out 0x70,al + mov eax,cr0 + or al,1 + mov cr0,eax +;Exécution du code 32 bits + jmp SYS_CODE_SEL:GoPMode32 Boot_Error: - mov si,error - call showstr - xor ax,ax - int 16h - jmp 0xFFFF:0x0 + mov si,error + call showstr + xor ax,ax + int 16h + jmp 0xFFFF:0x0 ok: - push si - push cx - mov cl,67 - call eol - mov si,okay - call showstr - pop cx - pop si - ret + push si + push cx + mov cl,67 + call eol + mov si,okay + call showstr + pop cx + pop si + ret ;======================INITPE======================== ;Initialise le PE de l'adresse EBX @@ -114,143 +115,143 @@ ok: ;<- Flag Carry si erreur ;===================================================== initpe: - pusha - push es - xor ax,ax - mov es,ax - mov [begin],ebx - cmp word [es:ebx+ELFheader.Magic],0x457F ; bien l'entete .elf ? - jne near errorelf - cmp word [es:ebx+ELFheader.Magic+2],"LF" ; bien l'entete .elf ? - jne near errorelf - cmp byte [es:ebx+ELFheader.Computertype],0x1 ; type ok ? - jne near errorelf - cmp byte [es:ebx+ELFheader.Endianness],0x1 ; type ok ? - jne near errorelf - cmp byte [es:ebx+ELFheader.Original],0x1 ; type ok ? - jne near errorelf - cmp byte [es:ebx+ELFheader.OS],0x0 ; type ok ? - jne near errorelf - cmp byte [es:ebx+ELFheader.ABI],0x0 ; type ok ? - jne near errorelf - cmp byte [es:ebx+ELFheader.Dummy],0x0 ; type ok ? - jne near errorelf - mov si,info1 - call showstr - mov esi,[es:ebx+ELFheader.Entrypoint] - mov [entriepoint],esi - mov esi,[es:ebx+ELFheader.Offsetprogram] - add esi,ebx - mov [offsetheader],esi - mov esi,[es:ebx+ELFheader.Offsetsection] - add esi,ebx - mov [offsetsection],esi - mov cx,[es:ebx+ELFheader.Nbprogram] - mov [cs:nbprogram],cx - mov cx,[es:ebx+ELFheader.Nbsection] - mov [cs:nbsection],cx - xor eax,eax - mov ax,[es:ebx+ELFheader.Index] - xor edx,edx - mov dx,[es:ebx+ELFheader.Sizesection] - mul edx - add eax,esi - mov eax,[es:eax+Sections.Offset] - add eax,ebx - mov [cs:symbol],eax - xor eax,eax - add ax,[es:ebx+ELFheader.Sizesection] - add esi,eax + pusha + push es + xor ax,ax + mov es,ax + mov [begin],ebx + cmp word [es:ebx+ELFheader.Magic],0x457F ; bien l'entete .elf ? + jne near errorelf + cmp word [es:ebx+ELFheader.Magic+2],"LF" ; bien l'entete .elf ? + jne near errorelf + cmp byte [es:ebx+ELFheader.Computertype],0x1 ; type ok ? + jne near errorelf + cmp byte [es:ebx+ELFheader.Endianness],0x1 ; type ok ? + jne near errorelf + cmp byte [es:ebx+ELFheader.Original],0x1 ; type ok ? + jne near errorelf + cmp byte [es:ebx+ELFheader.OS],0x0 ; type ok ? + jne near errorelf + cmp byte [es:ebx+ELFheader.ABI],0x0 ; type ok ? + jne near errorelf + cmp byte [es:ebx+ELFheader.Dummy],0x0 ; type ok ? + jne near errorelf + mov si,info1 + call showstr + mov esi,[es:ebx+ELFheader.Entrypoint] + mov [entriepoint],esi + mov esi,[es:ebx+ELFheader.Offsetprogram] + add esi,ebx + mov [offsetheader],esi + mov esi,[es:ebx+ELFheader.Offsetsection] + add esi,ebx + mov [offsetsection],esi + mov cx,[es:ebx+ELFheader.Nbprogram] + mov [cs:nbprogram],cx + mov cx,[es:ebx+ELFheader.Nbsection] + mov [cs:nbsection],cx + xor eax,eax + mov ax,[es:ebx+ELFheader.Index] + xor edx,edx + mov dx,[es:ebx+ELFheader.Sizesection] + mul edx + add eax,esi + mov eax,[es:eax+Sections.Offset] + add eax,ebx + mov [cs:symbol],eax + xor eax,eax + add ax,[es:ebx+ELFheader.Sizesection] + add esi,eax sections: - mov edi,esi - cmp dword [es:edi+Sections.Type],0x00 - jz nothing - mov esi,info2 - call showstr - push ds - push es - pop ds - mov esi,[es:edi+Sections.Name] - add esi,[cs:symbol] - call showstr - pop ds - mov esi,info3 - call showstr - mov edx,[es:edi+Sections.Offset] - push cx - mov cx,32 - call ShowHex - pop cx - mov esi,info4 - call showstr - mov edx,[es:edi+Sections.Size] - push cx - mov cx,32 - call ShowHex - pop cx - mov esi,info5 - call showstr - mov edx,[es:edi+Sections.Vadress] - push cx - mov cx,32 - call ShowHex - pop cx - and dword [es:edi+Sections.Flags],SF_ALLOC - jne itsok - mov esi,info6 - call showstr - jmp itsok2 + mov edi,esi + cmp dword [es:edi+Sections.Type],0x00 + jz nothing + mov esi,info2 + call showstr + push ds + push es + pop ds + mov esi,[es:edi+Sections.Name] + add esi,[cs:symbol] + call showstr + pop ds + mov esi,info3 + call showstr + mov edx,[es:edi+Sections.Offset] + push cx + mov cx,32 + call ShowHex + pop cx + mov esi,info4 + call showstr + mov edx,[es:edi+Sections.Size] + push cx + mov cx,32 + call ShowHex + pop cx + mov esi,info5 + call showstr + mov edx,[es:edi+Sections.Vadress] + push cx + mov cx,32 + call ShowHex + pop cx + and dword [es:edi+Sections.Flags],SF_ALLOC + jne itsok + mov esi,info6 + call showstr + jmp itsok2 itsok: - mov esi,info10 - call showstr -call copy2mem - cmp dword [es:edi+Sections.Type],ST_NOBITS - jne itsok2 - mov esi,info9 - call showstr - mov esi,info10 - call showstr -call zero2mem + mov esi,info10 + call showstr + call copy2mem + cmp dword [es:edi+Sections.Type],ST_NOBITS + jne itsok2 + mov esi,info9 + call showstr + mov esi,info10 + call showstr + call zero2mem itsok2: - push cx - xor cx,cx - mov edx,[es:edi+Sections.Align] - mov esi,info8 - call showstr + push cx + xor cx,cx + mov edx,[es:edi+Sections.Align] + mov esi,info8 + call showstr nextpower: - cmp edx,0 - je powerok - cmp edx,1 - je powerok - cmp cx,32 - je powerok - inc cx - shr edx,1 - jnc nextpower + cmp edx,0 + je powerok + cmp edx,1 + je powerok + cmp cx,32 + je powerok + inc cx + shr edx,1 + jnc nextpower powerok: - mov edx,ecx - mov cx,4 - call ShowHex - pop cx - call showrtn - mov esi,edi + mov edx,ecx + mov cx,4 + call ShowHex + pop cx + call showrtn + mov esi,edi nothing: - add esi,eax - dec cx - jnz sections - mov esi,info7 - call showstr - mov edx,[cs:entriepoint] - mov cx,32 - call ShowHex - clc - pop es - popa - ret + add esi,eax + dec cx + jnz sections + mov esi,info7 + call showstr + mov edx,[cs:entriepoint] + mov cx,32 + call ShowHex + clc + pop es + popa + ret errorelf: stc - pop es + pop es popa ret @@ -258,76 +259,75 @@ errorelf: ;CX adresse ;->CX ;<- -;=========================================== +;========================== debug: - mov esi,info11 - call showstr - xor edx,edx - mov dx,cs - shl edx,4 - add edx,ecx - mov cx,32 - call ShowHex + mov esi,info11 + call showstr + xor edx,edx + mov dx,cs + shl edx,4 + add edx,ecx + mov cx,32 + call ShowHex infini: - jmp infini - + jmp infini ;==========COPY2MEM=========== ;Copie de es:esi vers es:edi ;->ES:ESI ES:EDI CX ;<- Flag -;=========================================== +;============================= copy2mem: - push eax - push esi - push edi -push ecx -mov esi,[es:edi+Sections.Offset] -add esi,[cs:begin] -mov ecx,[es:edi+Sections.Size] -shr ecx,2 -inc ecx -mov edi,[es:edi+Sections.Vadress] + push eax + push esi + push edi + push ecx + mov esi,[es:edi+Sections.Offset] + add esi,[cs:begin] + mov ecx,[es:edi+Sections.Size] + shr ecx,2 + inc ecx + mov edi,[es:edi+Sections.Vadress] copietomem: - mov eax,[es:esi] - mov [es:edi],eax - add edi,4 - add esi,4 - dec ecx - jnz copietomem -pop ecx -pop edi -pop esi -pop eax -ret + mov eax,[es:esi] + mov [es:edi],eax + add edi,4 + add esi,4 + dec ecx + jnz copietomem + pop ecx + pop edi + pop esi + pop eax + ret ;==========ZERO2MEM=========== ;Remise à zero de es:edi ;->ES:EDI CX ;<- Flag -;=========================================== +;============================= zero2mem: - push eax - push esi - push edi -push ecx -mov esi,[es:edi+Sections.Offset] -add esi,[cs:begin] -mov ecx,[es:edi+Sections.Size] -shr ecx,2 -inc ecx -mov edi,[es:edi+Sections.Vadress] - mov eax,0 + push eax + push esi + push edi + push ecx + mov esi,[es:edi+Sections.Offset] + add esi,[cs:begin] + mov ecx,[es:edi+Sections.Size] + shr ecx,2 + inc ecx + mov edi,[es:edi+Sections.Vadress] + mov eax,0 zerotomem: - mov [es:edi],eax - add edi,4 - dec ecx - jnz zerotomem -pop ecx -pop edi -pop esi -pop eax -ret + mov [es:edi],eax + add edi,4 + dec ecx + jnz zerotomem + pop ecx + pop edi + pop esi + pop eax + ret begin dd 0 entriepoint dd 0 @@ -341,399 +341,402 @@ symbol dd 0 ;Affiche un nombre hexadécimal EDX de taille CX aprés le curseur ;-> EDX un entier, CX la taille ;<- -;=========================================== +;============================ ShowHex: - push ax - push bx - push cx - push edx - push si - mov ax,cx - shr ax,2 - sub cx,32 - neg cx - shl edx,cl - xor cx,cx - inc cx + push ax + push bx + push cx + push edx + push si + mov ax,cx + shr ax,2 + sub cx,32 + neg cx + shl edx,cl + xor cx,cx + inc cx Hexaize: - rol edx,4 - mov bx,dx - and bx,0fh - mov si,ax - mov al,[cs:bx+Tab] - xor bx,bx - mov ah,0x09 - mov bl,[cs:thecolor] - int 0x10 - mov ah,0x0E - int 0x10 - mov ax,si - dec al - jnz Hexaize - pop si - pop edx - pop cx - pop bx - pop ax - ret + rol edx,4 + mov bx,dx + and bx,0fh + mov si,ax + mov al,[cs:bx+Tab] + xor bx,bx + mov ah,0x09 + mov bl,[cs:thecolor] + int 0x10 + mov ah,0x0E + int 0x10 + mov ax,si + dec al + jnz Hexaize + pop si + pop edx + pop cx + pop bx + pop ax + ret Tab db '0123456789ABCDEF' -;======================EOL======================== +;============EOL============= ;Va en colonne CX ;-> ;<- Flag Carry si erreur -;===================================================== +;============================ eol: - pusha - mov bp,cx - mov ah,03 - xor bx,bx - int 10h - mov ah,02 - mov cx,bp - mov dl,cl - int 10h + pusha + mov bp,cx + mov ah,03 + xor bx,bx + int 10h + mov ah,02 + mov cx,bp + mov dl,cl + int 10h popa ret - -;======================LOAD======================== -;Charge le groupe en mémoire en ebx -;-> +;============LOAD============== +;Charge le groupe en mémoire en EBX pour le groupe CX +;-> CX ;<- Flag Carry si erreur -;===================================================== +;============================== load: - push ax - push ebx - push ecx - push edx - push esi - push edi - push fs - xor edx,edx - xor ax,ax - mov fs,ax - mov si,The_Dot - mov dx,[Sectors_Size] + push ax + push ebx + push ecx + push edx + push esi + push edi + push fs + xor edx,edx + xor ax,ax + mov fs,ax + mov si,The_Dot + mov dx,[Sectors_Size] Resume_Loading: - cmp cx,0x0FF0 - jae Finish_Loading - push cx - add cx,word [data] - mov edi,Buffer - call ReadSector - pop cx - jc near Boot_Error - call showstr - push esi - push ebx - push cx - mov esi,Buffer - mov cx,dx - shr cx,2 + cmp cx,0x0FF0 + jae Finish_Loading + push cx + add cx,word [data] + mov edi,Buffer + call ReadSector + pop cx + jc near Boot_Error + call showstr + push esi + push ebx + push cx + mov esi,Buffer + mov cx,dx + shr cx,2 copie: - mov eax,[ds:esi] - mov [fs:ebx],eax - add ebx,4 - add esi,4 - dec cx - jnz copie - pop cx - pop ebx - pop esi - add ebx,edx - call NextFatGroup - jc near Boot_Error - jmp Resume_Loading + mov eax,[ds:esi] + mov [fs:ebx],eax + add ebx,4 + add esi,4 + dec cx + jnz copie + pop cx + pop ebx + pop esi + add ebx,edx + call NextFatGroup + jc near Boot_Error + jmp Resume_Loading Finish_Loading: - pop fs - pop edi - pop esi - pop edx - pop ecx - pop ebx - pop ax - ret + pop fs + pop edi + pop esi + pop edx + pop ecx + pop ebx + pop ax + ret -;======================INITFAT======================== +;===========INITFAT============= ;Initialise les variables de la fat ;-> ;<- Flag Carry si erreur -;===================================================== +;=============================== initfat: - pusha - push ds - xor ax,ax - mov ds,ax - mov si,0x7C0B - mov di,bootsector - mov cx, 512 - rep movsb - pop ds - mov cx,[Reserved_Sectors] - add cx,[Sectors_Hidden] - adc cx,[Sectors_Hidden+2] - mov bx,[Sectors_Per_Fat] - mov di,Fat_Buffer - push bx - push cx + pusha + push ds + xor ax,ax + mov ds,ax + mov si,0x7C0B + mov di,bootsector + mov cx, 512 + rep movsb + pop ds + mov cx,[Reserved_Sectors] + add cx,[Sectors_Hidden] + adc cx,[Sectors_Hidden+2] + mov bx,[Sectors_Per_Fat] + mov di,Fat_Buffer + push bx + push cx readfat: - call ReadSector - jc Boot_Error - inc cx - add di,[Sectors_Size] - dec bx - jnz readfat - pop cx - pop bx - xor ax,ax - mov al,[Fats_Number] - mul bx - add cx,ax - mov [entries],cx - mov ax,32 - mul word [Fits_Number] - div word [Sectors_Size] - add cx,ax - sub cx,2 - mov word [data],cx - popa - ret + call ReadSector + jc Boot_Error + inc cx + add di,[Sectors_Size] + dec bx + jnz readfat + pop cx + pop bx + xor ax,ax + mov al,[Fats_Number] + mul bx + add cx,ax + mov [entries],cx + mov ax,32 + mul word [Fits_Number] + div word [Sectors_Size] + add cx,ax + sub cx,2 + mov word [data],cx + popa + ret -;======================SEARCH======================== +;===========SEARCH============ ;Recherche le groupe d'un fichier ;-> si nom du fichier ;<- Flag Carry si erreur CX -;===================================================== +;============================= search: - push bx - push dx - push di - mov cx,[entries] - mov di,Buffer - call ReadSector - jc Boot_Error - xor bx,bx + push bx + push dx + push di + mov cx,[entries] + mov di,Buffer + call ReadSector + jc Boot_Error + xor bx,bx Next_Root_Entrie: - cmp byte [di],0 - je Boot_Error - push si - push di - push cx - mov cx,32 - rep cmpsb - pop cx - pop di - pop si - je Found - add di,32 - add bx,32 - inc dx - cmp dx,[Fits_Number] - ja Boot_Error - cmp bx,[Sectors_Size] - jb Next_Root_Entrie - inc cx + cmp byte [di],0 + je Boot_Error + push si + push di + push cx + mov cx,32 + rep cmpsb + pop cx + pop di + pop si + je Found + add di,32 + add bx,32 + inc dx + cmp dx,[Fits_Number] + ja Boot_Error + cmp bx,[Sectors_Size] + jb Next_Root_Entrie + inc cx Found: - mov cx,[di+26+32] - pop di - pop dx - pop bx - ret + mov cx,[di+26+32] + pop di + pop dx + pop bx + ret -;======================SHOWRTN======================== +;============SHOWRTN============ ;Affiche la chaine de caractère return ;-> ;<- Flag Carry si erreur -;===================================================== +;=============================== showrtn: - push ds - push ax - push esi - mov esi,return - mov ax,cs - mov ds,ax - call showstr - pop esi - pop ax - pop ds + push ds + push ax + push esi + mov esi,return + mov ax,cs + mov ds,ax + call showstr + pop esi + pop ax + pop ds ret -;======================SHOWSTR======================== +;==============SHOWSTR============= ;Affiche la chaine de caractère pointé par ds:esi à l'écran -;-> DS, SI +;-> DS, ESI ;<- Flag Carry si erreur -;===================================================== +;================================== showstr: - pushad - xor bh,bh + pushad + xor bh,bh nextchar: - mov al,[ds:esi] - inc esi - or al,al - jz endshow - cmp al,' ' - jb justchar - cmp al,'#' - jne nocolor - mov al,[ds:esi] - inc esi - sub al,'0' - shl al,3 - mov [cs:thecolor],al - shr al,2 - add [cs:thecolor],al - mov al,[ds:esi] - inc esi - sub al,'0' - add [cs:thecolor],al - jmp nextchar + mov al,[ds:esi] + inc esi + or al,al + jz endshow + cmp al,' ' + jb justchar + cmp al,'#' + jne nocolor + mov al,[ds:esi] + inc esi + sub al,'0' + shl al,3 + mov [cs:thecolor],al + shr al,2 + add [cs:thecolor],al + mov al,[ds:esi] + inc esi + sub al,'0' + add [cs:thecolor],al + jmp nextchar nocolor: - cmp al,'@' - jne nocolor2 - mov al,[ds:esi] - inc esi - sub al,'0' - shl al,3 - mov cl,al - shr al,2 - add cl,al - mov al,[ds:esi] - inc esi - sub cl,'0' - add cl,al - call eol - jmp nextchar + cmp al,'@' + jne nocolor2 + mov al,[ds:esi] + inc esi + sub al,'0' + shl al,3 + mov cl,al + shr al,2 + add cl,al + mov al,[ds:esi] + inc esi + sub cl,'0' + add cl,al + call eol + jmp nextchar nocolor2: - xor bx,bx - mov ah,0x09 - mov bl,[cs:thecolor] - xor cx,cx - inc cx - int 0x10 + xor bx,bx + mov ah,0x09 + mov bl,[cs:thecolor] + xor cx,cx + inc cx + int 0x10 justchar: - mov ah,0x0E - int 0x10 - jmp nextchar + mov ah,0x0E + int 0x10 + jmp nextchar endshow: - popad - ret - + popad + ret -;====================READSECTOR======================= +;==========READSECTOR============ ;Lit le secteur logique LBA CX et le met en es:di ;-> CX (limité à 65536 secteurs, soit 32 Mo avec secteur 512 octets) ;<- Flag Carry si erreur -;===================================================== +;================================ ReadSector: pusha - mov ax,cx - xor dx,dx - div word [Sectors_Per_Track] - inc dl - mov bl,dl - xor dx,dx - div word [Heads_Number] - mov dh, [Boot_Drive] + mov ax,cx + xor dx,dx + div word [Sectors_Per_Track] + inc dl + mov bl,dl + xor dx,dx + div word [Heads_Number] + mov dh, [Boot_Drive] xchg dl,dh - mov cx,ax + mov cx,ax xchg cl,ch - shl cl,6 - or cl, bl - mov bx,di - mov si, 4 - mov al, 1 + shl cl,6 + or cl, bl + mov bx,di + mov si, 4 + mov al, 1 Read_Again: - mov ah, 2 - int 0x13 - jnc Read_Done - dec si - jnz Read_Again + mov ah, 2 + int 0x13 + jnc Read_Done + dec si + jnz Read_Again Read_Done: popa ret -;===================NEXTFATGROUP====================== +;============NEXTFATGROUP=========== ;Renvoie en CX le groupe qui succède dans la FAT le groupe CX ;-> CX -;<- -;===================================================== +;<- CX +;=================================== NextFatGroup: push bx push dx push di - mov ax,cx - mov bx,ax - and bx,0000000000000001b - shr ax,1 - mov cx,3 - mul cx - mov di,Fat_Buffer - add di,ax - cmp bx,0 - jnz Even_Group + mov ax,cx + mov bx,ax + and bx,0000000000000001b + shr ax,1 + mov cx,3 + mul cx + mov di,Fat_Buffer + add di,ax + cmp bx,0 + jnz Even_Group Odd_Group: - mov dx,[di] - and dx,0x0FFF - mov cx,dx - jmp Next_Group_Found + mov dx,[di] + and dx,0x0FFF + mov cx,dx + jmp Next_Group_Found Even_Group: - mov dx,[di+1] - and dx,0xFFF0 - shr dx,4 - mov cx,dx + mov dx,[di+1] + and dx,0xFFF0 + shr dx,4 + mov cx,dx Next_Group_Found: - pop di - pop dx - pop bx + pop di + pop dx + pop bx ret -;***********************EnableA20******************************* +;============EnableA20============ ;-> ;<- ;Ouvre l'autoroute A20 -;*************************************************************** +;================================= EnableA20: - cli - call ClearKeybBuffer - call WaitKeybCommand - mov al,0xd1 - out 0x64,al - call WaitKeybCommand - mov al,0xdf - out 0x60,al - call WaitKeybCommand - jmp A20Enabled + cli + call ClearKeybBuffer + call WaitKeybCommand + mov al,0xd1 + out 0x64,al + call WaitKeybCommand + mov al,0xdf + out 0x60,al + call WaitKeybCommand + jmp A20Enabled WaitKeybCommand: - in al,0x64 - test al,0x02 - jnz WaitKeybCommand - ret + in al,0x64 + test al,0x02 + jnz WaitKeybCommand + ret ClearKeybBuffer: - in al,0x64 - test al,0x01 - jnz ReadKeyb - ret + in al,0x64 + test al,0x01 + jnz ReadKeyb + ret ReadKeyb: - in al,0x60 - jmp ClearKeybBuffer + in al,0x60 + jmp ClearKeybBuffer A20Enabled: - sti - ret + sti + ret +;================================= +;CODE 32 bits mode protégé +;================================= GoPMode32: [BITS 32] - mov ax,ALL_DATA_SEL - mov es,ax - mov gs,ax - mov fs,ax - mov ss,ax - mov ds,ax - mov esp,0x3fffff - push KERNEL_SEL - push dword [cs:entriepoint] - retf +;Initialisation des selecteurs + mov ax,ALL_DATA_SEL + mov es,ax + mov gs,ax + mov fs,ax + mov ss,ax + mov ds,ax + mov esp,0x3fffff + push KERNEL_SEL + push dword [cs:entriepoint] +;Execution du système + retf section .data diff --git a/boot/makefile b/boot/makefile index 6f6f26a..9e2c569 100755 --- a/boot/makefile +++ b/boot/makefile @@ -2,14 +2,11 @@ CC=nasm -f bin -o all: makall -makall: boot12.bin boot16.bin loader.sys +makall: boot12.bin loader.sys boot12.bin: boot12.asm $(CC) $@ $^ -boot16.bin: boot16.asm - $(CC) $@ $^ - loader.sys: loader.asm $(CC) $@ $^ diff --git a/final/makefile b/final/makefile index b434092..6d99afc 100755 --- a/final/makefile +++ b/final/makefile @@ -3,6 +3,7 @@ all: cos2000.img cos2000.img: (dd if=/dev/zero of=cos2000.img count=2880 bs=512) (mkfs.msdos -F 12 -n "COS2000" cos2000.img) + (mkdir ./mnt) (fusefat cos2000.img ./mnt -o rw+) (cp ../boot/loader.sys ./mnt/) (cp ../system/system.sys ./mnt/;sync) diff --git a/include/graph.h b/include/2d.h similarity index 69% rename from include/graph.h rename to include/2d.h index 949bbd3..7a2d3d7 100755 --- a/include/graph.h +++ b/include/2d.h @@ -1 +1,3 @@ +#include "types.h" + void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color); diff --git a/include/3d.h b/include/3d.h index e69de29..8e71fd1 100755 --- a/include/3d.h +++ b/include/3d.h @@ -0,0 +1 @@ +#include "types.h" diff --git a/include/idt.h b/include/interrupts.h similarity index 100% rename from include/idt.h rename to include/interrupts.h diff --git a/include/port.h b/include/port.h deleted file mode 100755 index e81042a..0000000 --- a/include/port.h +++ /dev/null @@ -1,6 +0,0 @@ -#include "types.h" - -void outreg(u16 port,u8 *src,u16 num); -void outregsame(u16 port,u8 *src,u16 num); -void inreg(u16 port,u8 *src,u16 num); -void inregsame(u16 port,u8 *src,u16 num); diff --git a/include/vga.h b/include/vga.h index b8c9eec..8577424 100755 --- a/include/vga.h +++ b/include/vga.h @@ -35,3 +35,7 @@ void enableblink(); void disableblink(); u8 (*getchar)(u16 coordx,u16 coordy); u8 (*getattrib)(u16 coordx,u16 coordy); +void outreg(u16 port,u8 *src,u16 num); +void outregsame(u16 port,u8 *src,u16 num); +void inreg(u16 port,u8 *src,u16 num); +void inregsame(u16 port,u8 *src,u16 num); diff --git a/lib/2d.c b/lib/2d.c new file mode 100755 index 0000000..36576f5 --- /dev/null +++ b/lib/2d.c @@ -0,0 +1,51 @@ +#include "types.h" +#include "vga.h" +#include "video.h" +#include "2d.h" +#include "math.h" + +/******************************************************************************/ + +/* Affiche une ligne entre les points spécifiés */ + +void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color) +{ + s32 dx, dy, sdx, sdy; + u32 i, dxabs, dyabs, x, y, px, py; + + dx = x2 - x1; /* distance horizontale de la line */ + dy = y2 - y1; /* distance verticale de la line * */ + dxabs = abs(dx); + dyabs = abs(dy); + sdx = sgn(dx); + sdy = sgn(dy); + x = dyabs >> 1; + y = dxabs >> 1; + px = x1; + py = y1; + + writepxl(px, py, color); + + if (dxabs >= dyabs) { /* la ligne est plus horizontale que verticale */ + for (i = 0; i < dxabs; i++) { + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + py += sdy; + } + px += sdx; + writepxl(px, py, color); + } + } else { /* la ligne est plus verticale que horizontale */ + + for (i = 0; i < dyabs; i++) { + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + px += sdx; + } + py += sdy; + writepxl(px, py, color); + } + } +} diff --git a/lib/3d.c b/lib/3d.c index 1e51ac1..b00ae66 100755 --- a/lib/3d.c +++ b/lib/3d.c @@ -1,5 +1,6 @@ -#include "3d.h" +#include "3d.h" +#include "2d.h" #include "vga.h" #include "types.h" #include "video.h" -#include "graph.h" + diff --git a/lib/8x16fnt.c b/lib/VGA/8x16fnt.c similarity index 100% rename from lib/8x16fnt.c rename to lib/VGA/8x16fnt.c diff --git a/lib/8x8fnt.c b/lib/VGA/8x8fnt.c similarity index 100% rename from lib/8x8fnt.c rename to lib/VGA/8x8fnt.c diff --git a/lib/VGA/modes.c b/lib/VGA/modes.c new file mode 100755 index 0000000..26cf16f --- /dev/null +++ b/lib/VGA/modes.c @@ -0,0 +1,219 @@ +/* definition des registres de la carte VGA pour differents modes */ + +#define maxgraphmode 11 +#define maxtextmode 5 + +static mode_def textmodes[maxtextmode] = { + + /*40*25 16 couleurs mode 0x00 */ + { + 0x67, + 0x03, 0x08, 0x03, 0x00, 0x02, + 0x2D, 0x27, 0x28, 0x90, 0x2B, 0xA0, 0xBF, 0x1F, 0x00, + 0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x8E, 0x8F, 0x14, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x08, 0x00, + 45, 25, 4}, + + /*80*25 16 couleurs mode 0x01 */ + { + 0x67, + 0x03, 0x00, 0x03, 0x00, 0x02, + 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, + 0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x08, 0x00, + 80, 25, 4}, + + /*80*50 16 couleurs mode 0x02 */ + { + 0x63, + 0x03, 0x01, 0x03, 0x05, 0x02, + 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, + 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x00, 0x00, + 80, 50, 4}, + + /*100*50 16 couleurs mode 0x03 */ + { + 0x67, + 0x03, 0x01, 0x03, 0x05, 0x02, + 0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xBF, 0x1F, 0x00, + 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x8E, 0x8F, 0x32, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x00, 0x00, + 100, 50, 4}, + + /*100*60 16 couleurs mode 0x04 */ + { + 0xA7, + 0x03, 0x01, 0x03, 0x05, 0x02, + 0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xFF, 0x1F, 0x00, + 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, + 0xE7, 0x8E, 0xDF, 0x32, 0x1F, 0xDF, 0xE5, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x00, 0x00, + 100, 60, 4} +}; + +static mode_def graphmodes[maxgraphmode] = { + + /*640*480 n&b mode 0x80 */ + { + 0xE3, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x0F, 0x00, 0x00, + 80, 60, 1}, + + /*320*200 4 couleurs mode 0x81 */ + { + 0x63, + 0x03, 0x09, 0x03, 0x00, 0x02, + 0x2D, 0x27, 0x28, 0x90, 0x2B, 0x80, 0xBF, 0x1F, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x0E, 0x8F, 0x14, 0x00, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x03, 0x00, 0x00, + 40, 25, + }, + + /*640*480 16 couleurs mode 0x82 */ + { + 0xE3, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x5F, 0x4F, 0x50, 0x82, 0x53, 0x9F, 0x0B, 0x3E, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE9, 0x8B, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x0F, 0x00, 0x00, + 80, 60, 4}, + + /*720*480 16 couleurs mode 0x83 */ + { + 0xE7, + 0x03, 0x01, 0x08, 0x00, 0x06, + 0x6B, 0x59, 0x5A, 0x82, 0x60, 0x8D, 0x0B, 0x3E, 0x00, + 0x40, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0x0C, 0xDF, 0x2D, 0x08, 0xE8, 0x05, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x0F, 0x00, 0x00, + 90, 60, 4}, + + /*800*600 16 couleurs mode 0x84 */ + { + 0xE7, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x70, 0x63, 0x64, 0x92, 0x65, 0x82, 0x70, 0xF0, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5B, 0x8C, 0x57, 0x32, 0x00, 0x58, 0x70, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x0F, 0x00, 0x00, + 100, 75, 4}, + + /*320*200 256 couleurs RAPIDE mode 0x85 */ + { + 0x63, + 0x03, 0x01, 0x0F, 0x00, 0x0E, + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 40, 25, 8}, + + /*320*200 256 couleurs mode 0x86 */ + { + 0x63, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x0E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 40, 25, 8}, + + /*320*400 256 couleurs mode 0x87 */ + { + 0x63, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x8E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 40, 50, 8}, + + /*320*480 256 couleurs mode 0x88 */ + { + 0xE3, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0xAC, 0xDF, 0x28, 0x00, 0xE7, 0x06, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 40, 60, 8}, + + /*360*480 256 couleurs mode 0x89 */ + { + 0xE7, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x6B, 0x59, 0x5A, 0x8E, 0x5E, 0x8A, 0x0D, 0x3E, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0xAC, 0xDF, 0x2D, 0x00, 0xE7, 0x06, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 45, 60, 8}, + + /*400*600 256 couleurs mode 0x8A */ + { + 0xE7, + 0x03, 0x01, 0x0F, 0x00, 0x06, + 0x74, 0x63, 0x64, 0x97, 0x68, 0x95, 0x86, 0xF0, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5B, 0x8D, 0x57, 0x32, 0x00, 0x60, 0x80, 0xE3, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x41, 0x00, 0x0F, 0x00, 0x00, + 50, 75, 8} +}; diff --git a/lib/cpu.c b/lib/cpu.c index 1d23680..61034d7 100755 --- a/lib/cpu.c +++ b/lib/cpu.c @@ -4,214 +4,193 @@ #include "memory.h" #include "string.h" +/* Technologies supportées */ - -static u8 *msg[] = -{ - "mmx", - "mmx2", - "sse", - "sse2", - "sse3", - "fpu", - "3dNow!", - "3dNow Extended!", - "HyperThreading", - "apic", +static u8 *msg[] = { + "mmx", + "mmx2", + "sse", + "sse2", + "sse3", + "fpu", + "3dNow!", + "3dNow Extended!", + "HyperThreading", + "apic", }; -static u8 space[]=" "; +static u8 space[] = " "; -bool cansetflag (u32 flag) +/******************************************************************************/ + +/* Annule les FLAGs CPU */ + +bool cansetflag(u32 flag) { -u32 r1, r2; -asm("pushfl\n" -"popl %0\n" -"movl %0, %1\n" -"xorl %2, %0\n" -"pushl %0\n" -"popfl\n" -"pushfl\n" -"popl %0\n" -"pushl %1\n" -"popfl\n" -: "=&r" (r1), "=&r" (r2) -: "ir" (flag) -); -return ((r1 ^ r2) & flag) != 0; + u32 r1, r2; + asm("pushfl\n" "popl %0\n" "movl %0, %1\n" "xorl %2, %0\n" "pushl %0\n" "popfl\n" "pushfl\n" "popl %0\n" "pushl %1\n" "popfl\n": "=&r"(r1), "=&r"(r2):"ir"(flag)); + return ((r1 ^ r2) & flag) != 0; } -void cpuid(u32 op, u32 *eax, u32 *ebx,u32 *ecx, u32 *edx) +/******************************************************************************/ + +/* Lance l'instruction CPUID */ + +void cpuid(u32 op, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx) { - asm("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) : "cc"); + asm("cpuid": "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx): "a"(op):"cc"); } -u8 getcpuinfos(cpuinfo *proc) +/******************************************************************************/ + +/* Retourne les informations sur le CPU dans une structure cpuinfo */ + +u8 getcpuinfos(cpuinfo * proc) { -u32 i,maxfunction,maxextended,unused,regeax,regebx,regecx,regedx; -bool *boolean; - -if (!cansetflag (0x00040000)) return 1; /*386 processor - no cpuid*/ -if (!cansetflag (0x00200000)) return 2; /*486 processor with no cpuid*/ + u32 i, maxfunction, maxextended, unused, regeax, regebx, regecx, regedx; + bool *boolean; - cpuid(0, &maxfunction, &unused, &unused, &unused); - maxfunction &= 0xffff; - cpuid(0x80000000, &maxextended, &unused, &unused, &unused); - maxextended &= 0xffff; - if (maxfunction >= 1) - { - cpuid(1, ®eax, ®ebx, ®ecx, ®edx); - proc->stepping = (regeax & 0x0000000F); - proc->models = ((regeax>>4) & 0x0000000F); - proc->family = ((regeax>>8) & 0x0000000F); - proc->types = ((regeax>>12) & 0x00000003); - proc->emodels = ((regeax>>16) & 0x0000000F); - proc->efamily = ((regeax>>20) & 0x000000FF); - - proc->brandid = (regeax & 0xF); - proc->linesize = ((regeax>>8) & 0xF); - proc->count = ((regeax>>16) & 0xF); - proc->apicid = ((regeax>>24) & 0xF); - - proc->mmx=((regedx>>23) & 0x00000001); - proc->sse=((regedx>>25) & 0x00000001); - proc->sse2=((regedx>>26) & 0x00000001); - proc->sse3=(regecx & 0x00000001); - proc->fpu=(regedx & 0x00000001); - proc->htt=((regedx>>28) & 0x00000001); + if (!cansetflag(0x00040000)) + return 1; /*386 processor - no cpuid */ + if (!cansetflag(0x00200000)) + return 2; /*486 processor with no cpuid */ - } - if (maxextended >= 1) - { - cpuid(0x80000001, ®eax, ®ebx, ®ecx, ®edx); - proc->mmx2=((regedx>>22) & 0x00000001); - proc->apic=((regedx>>9) & 0x00000001); - proc->now3d=((regedx>>30) & 0x00000001); - proc->now3d2=((regedx>>31) & 0x00000001); - } - if (maxextended >= 4) - { - int i; - for(i=0;i<3;i++) - { - cpuid(0x80000002+i, ®eax, ®ebx, ®ecx, ®edx); - memcpy(®eax,&proc->detectedname[0+i*16],4,1); - memcpy(®ebx,&proc->detectedname[4+i*16],4,1); - memcpy(®ecx,&proc->detectedname[8+i*16],4,1); - memcpy(®edx,&proc->detectedname[12+i*16],4,1); - } - } - boolean=&proc->mmx; - i=0; + cpuid(0, &maxfunction, &unused, &unused, &unused); + maxfunction &= 0xffff; + cpuid(0x80000000, &maxextended, &unused, &unused, &unused); + maxextended &= 0xffff; + if (maxfunction >= 1) { + cpuid(1, ®eax, ®ebx, ®ecx, ®edx); + proc->stepping = (regeax & 0x0000000F); + proc->models = ((regeax >> 4) & 0x0000000F); + proc->family = ((regeax >> 8) & 0x0000000F); + proc->types = ((regeax >> 12) & 0x00000003); + proc->emodels = ((regeax >> 16) & 0x0000000F); + proc->efamily = ((regeax >> 20) & 0x000000FF); - for(i=0;i<10;i++) - if (*(boolean++)==1) - { - strcat(msg[i],&proc->techs); - strcat(space,&proc->techs); - } - return 0; + proc->brandid = (regeax & 0xF); + proc->linesize = ((regeax >> 8) & 0xF); + proc->count = ((regeax >> 16) & 0xF); + proc->apicid = ((regeax >> 24) & 0xF); + + proc->mmx = ((regedx >> 23) & 0x00000001); + proc->sse = ((regedx >> 25) & 0x00000001); + proc->sse2 = ((regedx >> 26) & 0x00000001); + proc->sse3 = (regecx & 0x00000001); + proc->fpu = (regedx & 0x00000001); + proc->htt = ((regedx >> 28) & 0x00000001); + + } + if (maxextended >= 1) { + cpuid(0x80000001, ®eax, ®ebx, ®ecx, ®edx); + proc->mmx2 = ((regedx >> 22) & 0x00000001); + proc->apic = ((regedx >> 9) & 0x00000001); + proc->now3d = ((regedx >> 30) & 0x00000001); + proc->now3d2 = ((regedx >> 31) & 0x00000001); + } + if (maxextended >= 4) { + int i; + for (i = 0; i < 3; i++) { + cpuid(0x80000002 + i, ®eax, ®ebx, ®ecx, + ®edx); + memcpy(®eax, &proc->detectedname[0 + i * 16], 4, 1); + memcpy(®ebx, &proc->detectedname[4 + i * 16], 4, 1); + memcpy(®ecx, &proc->detectedname[8 + i * 16], 4, 1); + memcpy(®edx, &proc->detectedname[12 + i * 16], 4, 1); + } + } + boolean = &proc->mmx; + i = 0; + + for (i = 0; i < 10; i++) + if (*(boolean++) == 1) { + strcat(msg[i], &proc->techs); + strcat(space, &proc->techs); + } + return 0; } +/******************************************************************************/ + +/* Retourne un élément de la pile */ + u32 viewstack(u32 number) { - u32 stack = 0; - asm ( - "movl %[a1],%%esi;" - "addl %%esp,%%esi;" - "movl (%%esi), %[a1] ;" - :[result] "=r" (stack) - :[a1] "r" (number) - :"%esi" - ); - return stack; + u32 stack = 0; + asm("movl %[a1],%%esi;" "addl %%esp,%%esi;" "movl (%%esi), %[a1] ;": [result] "=r"(stack): [a1] "r"(number):"%esi"); + return stack; } +/******************************************************************************/ + +/* Affiche les registres CPU */ + void dump_regs() { - u32 eax = 0; - u32 ebx = 0; - u32 ecx = 0; - u32 edx = 0; - u32 esi = 0; - u32 edi = 0; - u32 ebp = 0; - u32 esp = 0; - u16 cs = 0; - u16 ds = 0; - u16 es = 0; - u16 fs = 0; - u16 gs = 0; - u16 ss = 0; - u32 flags = 0; - asm ( - "movl %%eax, %[a1] ;" - "movl %%ebx, %[b1] ;" - "movl %%ecx, %[c1] ;" - "movl %%edx, %[d1] ;" - "movl %%esi, %[e1] ;" - "movl %%edi, %[f1] ;" - "movl %%esp, %[g1] ;" - "movl %%ebp, %[h1] ;" - "movw %%cs, %[i1] ;" - "movw %%ds, %[j1] ;" - "movw %%es, %[k1] ;" - "movw %%fs, %[l1] ;" - "movw %%gs, %[m1] ;" - "movw %%ss, %[n1] ;" - : - [a1] "=m" (eax), [b1] "=m" (ebx), [c1] "=m" (ecx), [d1] "=m" (edx), [e1] "=m" (esi), [f1] "=m" (edi), - [g1] "=m" (ebp), [h1] "=m" (esp), [i1] "=m" (cs), [j1] "=m" (ds), [k1] "=m" (es), [l1] "=m" (fs), [m1] "=m" (gs), [n1] "=m" (ss) - ); + u32 eax = 0; + u32 ebx = 0; + u32 ecx = 0; + u32 edx = 0; + u32 esi = 0; + u32 edi = 0; + u32 ebp = 0; + u32 esp = 0; + u16 cs = 0; + u16 ds = 0; + u16 es = 0; + u16 fs = 0; + u16 gs = 0; + u16 ss = 0; + u32 flags = 0; + asm("movl %%eax, %[a1] ;" "movl %%ebx, %[b1] ;" "movl %%ecx, %[c1] ;" "movl %%edx, %[d1] ;" "movl %%esi, %[e1] ;" "movl %%edi, %[f1] ;" "movl %%esp, %[g1] ;" "movl %%ebp, %[h1] ;" "movw %%cs, %[i1] ;" "movw %%ds, %[j1] ;" "movw %%es, %[k1] ;" "movw %%fs, %[l1] ;" "movw %%gs, %[m1] ;" "movw %%ss, %[n1] ;": +[a1] "=m"(eax),[b1] "=m"(ebx),[c1] "=m"(ecx),[d1] "=m"(edx),[e1] "=m"(esi), +[f1] "=m"(edi),[g1] "=m"(ebp),[h1] "=m"(esp),[i1] "=m"(cs),[j1] "=m"(ds), +[k1] "=m"(es),[l1] "=m"(fs),[m1] "=m"(gs),[n1] "=m"(ss)); - printf("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax,ebx,ecx,edx); - printf("esi=%x edi=%x\r\n", esi,edi); - printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n", cs,ds,es,fs,gs); - printf("ss=%x esp=%x ebp=%x\r\n",ss,esp,ebp); + printf("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax, ebx, + ecx, edx); + printf("esi=%x edi=%x\r\n", esi, edi); + printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n", + cs, ds, es, fs, gs); + printf("ss=%x esp=%x ebp=%x\r\n", ss, esp, ebp); - asm ( - "pushf ;" - "pop %[f1] ;" - : - [f1] "=m" (flags) - ); + asm("pushf ;" "pop %[f1] ;": +[f1] "=m"(flags)); - printf("FLAGS"); + printf("FLAGS"); - if(flags & (1 << 0)) // Carry - printf(" (C1"); - else - printf(" (C0"); + if (flags & (1 << 0)) // Carry + printf(" (C1"); + else + printf(" (C0"); - if(flags & (1 << 2)) // Parity - printf(" P1"); - else - printf(" P0"); + if (flags & (1 << 2)) // Parity + printf(" P1"); + else + printf(" P0"); - if(flags & (1 << 4)) // Adjust - printf(" A1"); - else - printf(" A0"); + if (flags & (1 << 4)) // Adjust + printf(" A1"); + else + printf(" A0"); - if(flags & (1 << 6)) // Zero - printf(" Z1"); - else - printf(" Z0"); + if (flags & (1 << 6)) // Zero + printf(" Z1"); + else + printf(" Z0"); - if(flags & (1 << 7)) // Sign - printf(" S1"); - else - printf(" S0"); + if (flags & (1 << 7)) // Sign + printf(" S1"); + else + printf(" S0"); - if(flags & (1 << 11)) // Overflow - printf(" O1)\n"); - else - printf(" O0)\n"); - - printf("STACK\r\n"); - for(u8 i=0;i<25;i++) - printf("+%d\t\t%x\r\n",i,viewstack(i*4)); + if (flags & (1 << 11)) // Overflow + printf(" O1)\n"); + else + printf(" O0)\n"); + printf("STACK\r\n"); + for (u8 i = 0; i < 25; i++) + printf("+%d\t\t%x\r\n", i, viewstack(i * 4)); } - diff --git a/lib/graph.c b/lib/graph.c deleted file mode 100755 index 8856668..0000000 --- a/lib/graph.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "types.h" -#include "vga.h" -#include "video.h" -#include "graph.h" -#include "math.h" - -/******************************************************************************/ - -/* Affiche une ligne entre les points spécifiés */ - -void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color) -{ - s32 dx,dy,sdx,sdy; - u32 i,dxabs,dyabs,x,y,px,py; - - dx=x2-x1; /* distance horizontale de la line */ - dy=y2-y1; /* distance verticale de la line **/ - dxabs=abs(dx); - dyabs=abs(dy); - sdx=sgn(dx); - sdy=sgn(dy); - x=dyabs>>1; - y=dxabs>>1; - px=x1; - py=y1; - - writepxl(px,py,color); - - if (dxabs>=dyabs) /* la ligne est plus horizontale que verticale */ - { - for(i=0;i=dxabs) - { - y-=dxabs; - py+=sdy; - } - px+=sdx; - writepxl(px,py,color); - } - } - else /* la ligne est plus verticale que horizontale */ - { - for(i=0;i=dyabs) - { - x-=dyabs; - px+=sdx; - } - py+=sdy; - writepxl(px,py,color); - } - } -} - diff --git a/lib/idt.c b/lib/idt.c deleted file mode 100755 index cf2b084..0000000 --- a/lib/idt.c +++ /dev/null @@ -1,511 +0,0 @@ -#include "idt.h" -#include "types.h" -#include "asm.h" -#include "memory.h" -#include "video.h" - - /* registre idt */ -static struct dtr idtreg; - -/* table de IDT */ -static idtdes idt[256]; - - -void initpic(void) -{ - /* MASTER */ - /* Initialisation de ICW1 */ - outb(0x20,0x11); - nop(); - /* Initialisation de ICW2 - vecteur de depart = 32 */ - outb(0x21,0x20); - nop(); - /* Initialisation de ICW3 */ - outb(0x21,0x04); - nop(); - /* Initialisation de ICW4 */ - outb(0x21,0x01); - nop(); - /* masquage des interruptions */ - outb(0x21,0xFF); - nop(); - /* SLAVE */ - /* Initialisation de ICW1 */ - outb(0xA0,0x11); - nop(); - /* Initialisation de ICW2 - vecteur de depart = 96 */ - outb(0xA1,0x60); - nop(); - /* Initialisation de ICW3 */ - outb(0xA1,0x02); - nop(); - /* Initialisation de ICW4 */ - outb(0xA1,0x01); - nop(); - /* masquage des interruptions */ - outb(0xA1,0xFF); - nop(); - /* Demasquage des irqs sauf clavier - outb(0x21,0xFD); - nop(); - */ -} - -void enableirq(u8 irq) -{ -u16 port; -cli(); -port = (((irq & 0x08) << 4) + 0x21); -outb(port,inb(port) & ~(1 << (irq & 7))); -sti(); -} - -void disableirq(u8 irq) -{ -u16 port; -cli(); -port = (((irq & 0x08) << 4) + 0x21); -outb(port,inb(port) | (1 << (irq & 7))); -sti(); -} - -void makeidtdes(u32 offset, u16 select, u16 type, idtdes* desc) -{ - desc->offset0_15 = (offset & 0xffff); - desc->select = select; - desc->type = type; - desc->offset16_31 = (offset & 0xffff0000) >> 16; - return; -} - -void setidt(u32 offset, u16 select, u16 type,u16 index) -{ -cli(); -idtdes *desc; -desc=idtreg.base; - desc[index].offset0_15 = (offset & 0xffff); - desc[index].select = select; - desc[index].type = type; - desc[index].offset16_31 = (offset & 0xffff0000) >> 16; -sti(); -} - -void putidt(u32 offset, u16 select, u16 type,u16 index) -{ -idtdes temp; -makeidtdes(offset,select,type,&temp); -idt[index]=temp; -} - -void cpuerror(const u8 *src) -{ - print("\033[31m***** ERREUR CPU ****\r\n -"); - print(src); - dump_regs(); - while(1) - { - nop(); - } -} - -void interruption() -{ - cli(); - pushf(); - pushad(); - print("Appel d'une interruption\r\n"); - popad(); - popf(); - sti(); - iret(); -} - -void exception0() -{ - print("divide error\r\n"); - } - -void exception1() -{ - cpuerror("debug exception\r\n"); - } - -void exception2() - { - cpuerror("non-maskable hardware interrupt\r\n"); - } - -void exception3() -{ - cpuerror("INT3 instruction\r\n"); - } - -void exception4() - { - cpuerror("INTO instruction detected overflow\r\n"); - } - -void exception5() - { - print("BOUND instruction detected overrange\r\n"); - } - -void exception6() -{ - cpuerror("invalid instruction opcode\r\n"); - } - -void exception7() - { - cpuerror("no coprocessor\r\n"); - } - -void exception8() -{ - cpuerror("double fault\r\n"); - } - -void exception9() - { - cpuerror("coprocessor segment overrun\r\n"); - } - -void exception10() -{ - cpuerror("invalid task state segment (TSS)\r\n"); - } - -void exception11() - { - cpuerror("segment not present\r\n"); - } - -void exception12() -{ - cpuerror("stack fault"); - } - -void exception13() - { - cpuerror("general protection fault (GPF)\r\n"); - } - -void exception14() - { - cpuerror("page fault\r\n"); - } - -void exception15() -{ - cpuerror("(reserved)\r\n"); - } - -void exception16() - { - cpuerror("coprocessor error\r\n"); - } - -void exception17() -{ - cpuerror("alignment check\r\n"); - } - -void exception18() - { - cpuerror("machine check"); - } - -void irq0() - { - cli(); - pushf(); - pushad(); - print("irq 0"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq1() - { - cli(); - pushf(); - pushad(); - print("irq 1"); - while ((inb(0x64)&1)==0); - inb(0x60); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq2() - { - cli(); - pushf(); - pushad(); - print("irq 2"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq3() - { - cli(); - pushf(); - pushad(); - print("irq 3"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq4() - { - cli(); - pushf(); - pushad(); - print("irq 4"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq5() - { - cli(); - pushf(); - pushad(); - print("irq 5"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq6() - { - cli(); - pushf(); - pushad(); - print("irq 6"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq7() - { - cli(); - pushf(); - pushad(); - print("irq 7"); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq8() - { - cli(); - pushf(); - pushad(); - print("irq 8"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq9() - { - cli(); - pushf(); - pushad(); - print("irq 9"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq10() - { - cli(); - pushf(); - pushad(); - print("irq 10"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq11() - { - cli(); - pushf(); - pushad(); - print("irq 11"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq12() - { - cli(); - pushf(); - pushad(); - print("irq 12"); - while ((inb(0x64)&1)==0); - inb(0x60); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void irq13() - { - cli(); - pushf(); - pushad(); - print("irq 13"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq14() - { - cli(); - pushf(); - pushad(); - print("irq 14"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - -void irq15() - { - cli(); - print("irq 15"); - irqendslave(); - irqendmaster(); - popad(); - popf(); - sti(); - asm("addl $0x01C, %esp;"); - iret(); - } - - void initidt(void) -{ -u16 i; - putidt((u32)exception0, 0x20, INTGATE, 0); - putidt((u32)exception1, 0x20, INTGATE, 1); - putidt((u32)exception2, 0x20, INTGATE, 2); - putidt((u32)exception3, 0x20, INTGATE, 3); - putidt((u32)exception4, 0x20, INTGATE, 4); - putidt((u32)exception5, 0x20, INTGATE, 5); - putidt((u32)exception6, 0x20, INTGATE, 6); - putidt((u32)exception7, 0x20, INTGATE, 7); - putidt((u32)exception8, 0x20, INTGATE, 8); - putidt((u32)exception9, 0x20, INTGATE, 9); - putidt((u32)exception10, 0x20, INTGATE, 10); - putidt((u32)exception11, 0x20, INTGATE, 11); - putidt((u32)exception12, 0x20, INTGATE, 12); - putidt((u32)exception13, 0x20, INTGATE, 13); - putidt((u32)exception14, 0x20, INTGATE, 14); - putidt((u32)exception15, 0x20, INTGATE, 15); - putidt((u32)exception16, 0x20, INTGATE, 16); - putidt((u32)exception17, 0x20, INTGATE, 17); - putidt((u32)exception18, 0x20, INTGATE, 18); - for(i=19;i<32;i++) - { - putidt((u32)interruption, 0x20, INTGATE, i); - } - putidt((u32)irq0, 0x20, INTGATE, 32); - putidt((u32)irq1, 0x20, INTGATE, 33); - putidt((u32)irq2, 0x20, INTGATE, 34); - putidt((u32)irq3, 0x20, INTGATE, 35); - putidt((u32)irq4, 0x20, INTGATE, 36); - putidt((u32)irq5, 0x20, INTGATE, 37); - putidt((u32)irq6, 0x20, INTGATE, 38); - putidt((u32)irq7, 0x20, INTGATE, 39); - for(i=40;i<96;i++) - { - putidt((u32)interruption, 0x20, INTGATE, i); - } - putidt((u32)irq8, 0x20, INTGATE, 96); - putidt((u32)irq9, 0x20, INTGATE, 97); - putidt((u32)irq10, 0x20, INTGATE, 98); - putidt((u32)irq11, 0x20, INTGATE, 99); - putidt((u32)irq12, 0x20, INTGATE, 100); - putidt((u32)irq13, 0x20, INTGATE, 101); - putidt((u32)irq14, 0x20, INTGATE, 102); - putidt((u32)irq15, 0x20, INTGATE, 103); - for(i=104;i<255;i++) - { - putidt((u32)interruption, 0x20, INTGATE, i); - } - /* initialise le registre idt */ - idtreg.limite = 256*8; - idtreg.base = 0x0000000; - /* recopie de la IDT a son adresse */ - memcpy(&idt, (u8*)idtreg.base, idtreg.limite,1); - /* chargement du registre IDTR */ - lidt(&idtreg); - -} - diff --git a/lib/interrupts.c b/lib/interrupts.c new file mode 100755 index 0000000..3d4056e --- /dev/null +++ b/lib/interrupts.c @@ -0,0 +1,549 @@ +#include "interrupts.h" +#include "types.h" +#include "asm.h" +#include "memory.h" +#include "video.h" + + /* registre idt */ +static struct dtr idtreg; + +/* table de IDT */ +static idtdes idt[256]; + +/******************************************************************************/ + +/* Initialise le controleur d'interruption 8259A */ + +void initpic(void) +{ + /* MASTER */ + /* Initialisation de ICW1 */ + outb(0x20, 0x11); + nop(); + /* Initialisation de ICW2 - vecteur de depart = 32 */ + outb(0x21, 0x20); + nop(); + /* Initialisation de ICW3 */ + outb(0x21, 0x04); + nop(); + /* Initialisation de ICW4 */ + outb(0x21, 0x01); + nop(); + /* masquage des interruptions */ + outb(0x21, 0xFF); + nop(); + /* SLAVE */ + /* Initialisation de ICW1 */ + outb(0xA0, 0x11); + nop(); + /* Initialisation de ICW2 - vecteur de depart = 96 */ + outb(0xA1, 0x60); + nop(); + /* Initialisation de ICW3 */ + outb(0xA1, 0x02); + nop(); + /* Initialisation de ICW4 */ + outb(0xA1, 0x01); + nop(); + /* masquage des interruptions */ + outb(0xA1, 0xFF); + nop(); + /* Demasquage des irqs sauf clavier + outb(0x21,0xFD); + nop(); + */ +} + +/******************************************************************************/ + +/* Active une IRQ */ + +void enableirq(u8 irq) +{ + u16 port; + cli(); + port = (((irq & 0x08) << 4) + 0x21); + outb(port, inb(port) & ~(1 << (irq & 7))); + sti(); +} + +/******************************************************************************/ + +/* Désactive une IRQ */ + +void disableirq(u8 irq) +{ + u16 port; + cli(); + port = (((irq & 0x08) << 4) + 0x21); + outb(port, inb(port) | (1 << (irq & 7))); + sti(); +} + +/******************************************************************************/ + +/* Créé un descripteur pour l'IDT */ + +void makeidtdes(u32 offset, u16 select, u16 type, idtdes * desc) +{ + desc->offset0_15 = (offset & 0xffff); + desc->select = select; + desc->type = type; + desc->offset16_31 = (offset & 0xffff0000) >> 16; + return; +} + +/******************************************************************************/ + +/* Change une entrée dans l'IDT */ + +void setidt(u32 offset, u16 select, u16 type, u16 index) +{ + cli(); + idtdes *desc; + desc = idtreg.base; + desc[index].offset0_15 = (offset & 0xffff); + desc[index].select = select; + desc[index].type = type; + desc[index].offset16_31 = (offset & 0xffff0000) >> 16; + sti(); +} + +/******************************************************************************/ + +/* Met une entrée dans l'IDT */ + +void putidt(u32 offset, u16 select, u16 type, u16 index) +{ + idtdes temp; + makeidtdes(offset, select, type, &temp); + idt[index] = temp; +} + +/******************************************************************************/ + +/* Affiche une erreur CPU et fige l'ordinateur */ + +void cpuerror(const u8 * src) +{ + print("\033[31m***** ERREUR CPU ****\r\n -"); + print(src); + dump_regs(); + while (1) { + nop(); + } +} + +/******************************************************************************/ + +/* Déclenché lors de l'appel d'une interruption */ + +void interruption() +{ + cli(); + pushf(); + pushad(); + print("Appel d'une interruption\r\n"); + popad(); + popf(); + sti(); + iret(); +} + +/******************************************************************************/ + +/* Les expections */ + +void exception0() +{ + print("divide error\r\n"); +} + +void exception1() +{ + cpuerror("debug exception\r\n"); +} + +void exception2() +{ + cpuerror("non-maskable hardware interrupt\r\n"); +} + +void exception3() +{ + cpuerror("INT3 instruction\r\n"); +} + +void exception4() +{ + cpuerror("INTO instruction detected overflow\r\n"); +} + +void exception5() +{ + print("BOUND instruction detected overrange\r\n"); +} + +void exception6() +{ + cpuerror("invalid instruction opcode\r\n"); +} + +void exception7() +{ + cpuerror("no coprocessor\r\n"); +} + +void exception8() +{ + cpuerror("double fault\r\n"); +} + +void exception9() +{ + cpuerror("coprocessor segment overrun\r\n"); +} + +void exception10() +{ + cpuerror("invalid task state segment (TSS)\r\n"); +} + +void exception11() +{ + cpuerror("segment not present\r\n"); +} + +void exception12() +{ + cpuerror("stack fault"); +} + +void exception13() +{ + cpuerror("general protection fault (GPF)\r\n"); +} + +void exception14() +{ + cpuerror("page fault\r\n"); +} + +void exception15() +{ + cpuerror("(reserved)\r\n"); +} + +void exception16() +{ + cpuerror("coprocessor error\r\n"); +} + +void exception17() +{ + cpuerror("alignment check\r\n"); +} + +void exception18() +{ + cpuerror("machine check"); +} + +/******************************************************************************/ + +/* Les IRQ par défaut */ + +void irq0() +{ + cli(); + pushf(); + pushad(); + print("irq 0"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq1() +{ + cli(); + pushf(); + pushad(); + print("irq 1"); + while ((inb(0x64) & 1) == 0) ; + inb(0x60); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq2() +{ + cli(); + pushf(); + pushad(); + print("irq 2"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq3() +{ + cli(); + pushf(); + pushad(); + print("irq 3"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq4() +{ + cli(); + pushf(); + pushad(); + print("irq 4"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq5() +{ + cli(); + pushf(); + pushad(); + print("irq 5"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq6() +{ + cli(); + pushf(); + pushad(); + print("irq 6"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq7() +{ + cli(); + pushf(); + pushad(); + print("irq 7"); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq8() +{ + cli(); + pushf(); + pushad(); + print("irq 8"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq9() +{ + cli(); + pushf(); + pushad(); + print("irq 9"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq10() +{ + cli(); + pushf(); + pushad(); + print("irq 10"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq11() +{ + cli(); + pushf(); + pushad(); + print("irq 11"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq12() +{ + cli(); + pushf(); + pushad(); + print("irq 12"); + while ((inb(0x64) & 1) == 0) ; + inb(0x60); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq13() +{ + cli(); + pushf(); + pushad(); + print("irq 13"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq14() +{ + cli(); + pushf(); + pushad(); + print("irq 14"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +void irq15() +{ + cli(); + print("irq 15"); + irqendslave(); + irqendmaster(); + popad(); + popf(); + sti(); + asm("addl $0x01C, %esp;"); + iret(); +} + +/******************************************************************************/ + +/* Initialise une IDT */ + +void initidt(void) +{ + u16 i; + putidt((u32) exception0, 0x20, INTGATE, 0); + putidt((u32) exception1, 0x20, INTGATE, 1); + putidt((u32) exception2, 0x20, INTGATE, 2); + putidt((u32) exception3, 0x20, INTGATE, 3); + putidt((u32) exception4, 0x20, INTGATE, 4); + putidt((u32) exception5, 0x20, INTGATE, 5); + putidt((u32) exception6, 0x20, INTGATE, 6); + putidt((u32) exception7, 0x20, INTGATE, 7); + putidt((u32) exception8, 0x20, INTGATE, 8); + putidt((u32) exception9, 0x20, INTGATE, 9); + putidt((u32) exception10, 0x20, INTGATE, 10); + putidt((u32) exception11, 0x20, INTGATE, 11); + putidt((u32) exception12, 0x20, INTGATE, 12); + putidt((u32) exception13, 0x20, INTGATE, 13); + putidt((u32) exception14, 0x20, INTGATE, 14); + putidt((u32) exception15, 0x20, INTGATE, 15); + putidt((u32) exception16, 0x20, INTGATE, 16); + putidt((u32) exception17, 0x20, INTGATE, 17); + putidt((u32) exception18, 0x20, INTGATE, 18); + for (i = 19; i < 32; i++) { + putidt((u32) interruption, 0x20, INTGATE, i); + } + putidt((u32) irq0, 0x20, INTGATE, 32); + putidt((u32) irq1, 0x20, INTGATE, 33); + putidt((u32) irq2, 0x20, INTGATE, 34); + putidt((u32) irq3, 0x20, INTGATE, 35); + putidt((u32) irq4, 0x20, INTGATE, 36); + putidt((u32) irq5, 0x20, INTGATE, 37); + putidt((u32) irq6, 0x20, INTGATE, 38); + putidt((u32) irq7, 0x20, INTGATE, 39); + for (i = 40; i < 96; i++) { + putidt((u32) interruption, 0x20, INTGATE, i); + } + putidt((u32) irq8, 0x20, INTGATE, 96); + putidt((u32) irq9, 0x20, INTGATE, 97); + putidt((u32) irq10, 0x20, INTGATE, 98); + putidt((u32) irq11, 0x20, INTGATE, 99); + putidt((u32) irq12, 0x20, INTGATE, 100); + putidt((u32) irq13, 0x20, INTGATE, 101); + putidt((u32) irq14, 0x20, INTGATE, 102); + putidt((u32) irq15, 0x20, INTGATE, 103); + for (i = 104; i < 255; i++) { + putidt((u32) interruption, 0x20, INTGATE, i); + } + /* initialise le registre idt */ + idtreg.limite = 256 * 8; + idtreg.base = 0x0000000; + /* recopie de la IDT a son adresse */ + memcpy(&idt, (u8 *) idtreg.base, idtreg.limite, 1); + /* chargement du registre IDTR */ + lidt(&idtreg); + +} diff --git a/lib/keyboard.c b/lib/keyboard.c index c345022..f6111e9 100755 --- a/lib/keyboard.c +++ b/lib/keyboard.c @@ -1,4 +1,4 @@ -#include "idt.h" +#include "interrupts.h" #include "types.h" #include "asm.h" #include "memory.h" @@ -6,103 +6,107 @@ #include "video.h" -static u8 bufferscan[256]={0}; -static u8 bufferascii[256]={0}; -static u8 ptrscan=0; -static u8 ptrascii=0; -static u16 kbdstatus,breakcode ; - -static const u8 set1_normal[] = -{ -0, 0x1B, '&', 'é', '\"', '\'', '(', '-', - 'è', '_', 'ç', 'à', ')', '=', '\b', '\t', - 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '^', '$', '\r', 0, 'q', 's', -'d', 'f', 'g', 'h', 'j', 'k', 'l', 'm', -'ù', '²', 0, '*', 'w', 'x', 'c', 'v', -'b', 'n', ',', ';', ':', '!', 0, '*', -0, ' ', 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, '7', -'8', '9','-', '4','5','6', '+', '1', -'2', '3','0','.',0, 0, '<', 0, -0 +static u8 bufferscan[256] = { 0 }; +static u8 bufferascii[256] = { 0 }; + +static u8 ptrscan = 0; +static u8 ptrascii = 0; +static u16 kbdstatus, breakcode; + +/******************************************************************************/ + +/* Tables clavier */ + +static const u8 set1_normal[] = { + 0, 0x1B, '&', 'é', '\"', '\'', '(', '-', + 'è', '_', 'ç', 'à', ')', '=', '\b', '\t', + 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', + 'o', 'p', '^', '$', '\r', 0, 'q', 's', + 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', + 'ù', '²', 0, '*', 'w', 'x', 'c', 'v', + 'b', 'n', ',', ';', ':', '!', 0, '*', + 0, ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '7', + '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.', 0, 0, '<', 0, + 0 }; -static const u8 set1_shift[] = -{ -0, 0x1B, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '°', '+', '\b', '\t', - 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', - 'O', 'P', '¨', '£', '\r', 0, 'Q', 'S', -'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', -'%', 0, 0, 'µ', 'W', 'X', 'C', 'V', -'B', 'N', '?', '.', '/', '§', 0, '*', -0, ' ', 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0,0, 0, '7', -'8', '9','-', '4','5','6', '+', '1', -'2', '3','0','.',0, 0, '>', 0, -0 +static const u8 set1_shift[] = { + 0, 0x1B, '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '°', '+', '\b', '\t', + 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', + 'O', 'P', '¨', '£', '\r', 0, 'Q', 'S', + 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', + '%', 0, 0, 'µ', 'W', 'X', 'C', 'V', + 'B', 'N', '?', '.', '/', '§', 0, '*', + 0, ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '7', + '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.', 0, 0, '>', 0, + 0 }; -static const u8 set1_alt[] = -{ -0, 0x1B, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, '\r', 0, 0, 0, -0, 0, 0,0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, '*', -0, ' ', 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0,0, 0, '7', -'8', '9','-', '4','5','6', '+', '1', -'2', '3','0','.',0, 0, 0, 0, -0 +static const u8 set1_alt[] = { + 0, 0x1B, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, '\r', 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '*', + 0, ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '7', + '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.', 0, 0, 0, 0, + 0 }; - -static const u8 set1_altgr[] = -{ -0, 0x1B, 0, '~', '#', '{', '[', '|', - '`', '\\', '^', '@', ']', '}', '\b', '\t', - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, '¤', '\r', 0, 0, 0, -0, 0, 0,0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, '*', -0, ' ', 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0,0, 0, '7', -'8', '9','-', '4','5','6', '+', '1', -'2', '3','0','.',0, 0, 0, 0, -0 +static const u8 set1_altgr[] = { + 0, 0x1B, 0, '~', '#', '{', '[', '|', + '`', '\\', '^', '@', ']', '}', '\b', '\t', + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, '¤', '\r', 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '*', + 0, ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '7', + '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.', 0, 0, 0, 0, + 0 }; -static const u8 set1_ctrl[] = -{ -0, 0x1B, 0, 0,0, 0, 0x1B, 0, - 0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F, - 0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09, - 0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13, -0x04, 0x06, 0x07,0x08, 0x0A, 0x0B, 0x0C, 0x0D, -0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16, -0x02, 0x0E, 0, 0, 0, 0, 0, '*', -0, ' ', 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0,0, 0, '7', -'8', '9','-', '4','5','6', '+', '1', -'2', '3','0','.',0, 0, 0, 0, -0 +static const u8 set1_ctrl[] = { + 0, 0x1B, 0, 0, 0, 0, 0x1B, 0, + 0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F, + 0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09, + 0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13, + 0x04, 0x06, 0x07, 0x08, 0x0A, 0x0B, 0x0C, 0x0D, + 0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16, + 0x02, 0x0E, 0, 0, 0, 0, 0, '*', + 0, ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, '7', + '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.', 0, 0, 0, 0, + 0 }; -/******************************************************************************/ + +/******************************************************************************/ + +/* Fonction qui attend l'appuie d'une touche générant un code ASCII puis le retourne */ u8 waitascii() -{ -u8 oldptrscan=ptrscan; -u8 oldptrascii=ptrascii; -while((oldptrascii==ptrascii));/*(oldptrscan==ptrscan)&&*/ -return bufferascii[ptrascii]; +{ + u8 oldptrscan = ptrscan; + u8 oldptrascii = ptrascii; + while ((oldptrascii == ptrascii)) ; + return bufferascii[ptrascii]; } -/******************************************************************************/ +/******************************************************************************/ + +/* Envoi d'une commande vers le contrôleur de clavier */ void outkbd(u8 port, u8 data) { @@ -110,169 +114,180 @@ void outkbd(u8 port, u8 data) u8 state; /* timeout */ - for(timeout = 500000L; timeout != 0; timeout--) - { + for (timeout = 500000L; timeout != 0; timeout--) { state = inb(0x64); /* vide le buffer du 8042 */ - if((state & 0x02) == 0) break; + if ((state & 0x02) == 0) + break; } - if(timeout != 0) + if (timeout != 0) outb(port, data); } /******************************************************************************/ + +/* Redemarre l'ordinateur */ + static void reboot(void) { u8 temp; cli(); /* vide le 8042 */ - do - { + do { temp = inb(0x64); - if((temp & 0x01) != 0) - { + if ((temp & 0x01) != 0) { (void)inb(0x60); continue; } - } while((temp & 0x02) != 0); + } while ((temp & 0x02) != 0); /* active le reset CPU */ outb(0x64, 0xFE); - while(1) - /* boucle infinie */; + while (1) + /* boucle infinie */ ; } /******************************************************************************/ + +/* Converti un scancode vers une code ASCII */ + unsigned convert(u32 keypressed) { - u8 temp,key,lastscan; + u8 temp, key, lastscan; /* garde le dernier pointeur du buffer scan */ - lastscan=ptrscan; + lastscan = ptrscan; /* incrémente le pointeur est assigne au buffer le dernier scancode */ - ptrscan++; - if (ptrscan==255) ptrscan==0; - bufferscan[ptrscan]=keypressed; + ptrscan++; + if (ptrscan == 255) + ptrscan == 0; + bufferscan[ptrscan] = keypressed; /* break key (touche relaché) ? */ - if(keypressed >= 0x80) breakcode = 1; - key = (keypressed&0x7F); + if (keypressed >= 0x80) + breakcode = 1; + key = (keypressed & 0x7F); /* Mise a jour des flags lors du relachement de touches de controle */ - if(breakcode) - { - if(key == SCAN_ALT) - { + if (breakcode) { + if (key == SCAN_ALT) { kbdstatus &= ~STATUS_ALT; /* si ALT GR (E01D) alors activer aussi control */ - if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL; - } - else if(key == SCAN_CTRL) + if (bufferscan[lastscan] == 0xE0) + kbdstatus &= ~STATUS_CTRL; + } else if (key == SCAN_CTRL) kbdstatus &= ~STATUS_CTRL; - else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) + else if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) kbdstatus &= ~STATUS_SHIFT; breakcode = 0; return 0; } /* Mise a jour des flags lors de l'appuie de touches de controle */ - if(key == SCAN_ALT) - { + if (key == SCAN_ALT) { kbdstatus |= STATUS_ALT; - /* si ALT GR (E01D) alors desactiver aussi control */ - if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL; - return 0; + /* si ALT GR (E01D) alors desactiver aussi control */ + if (bufferscan[lastscan] == 0xE0) + kbdstatus |= STATUS_CTRL; + return 0; } - if(key == SCAN_CTRL) - { + if (key == SCAN_CTRL) { kbdstatus |= STATUS_CTRL; return 0; } - if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) - { + if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) { kbdstatus |= STATUS_SHIFT; return 0; } - - if ((key >= SCAN_F1) && (key <= SCAN_F8)) - { - changevc(key-SCAN_F1); - } - + + if ((key >= SCAN_F1) && (key <= SCAN_F8)) { + changevc(key - SCAN_F1); + } + /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ - if(key == SCAN_SCROLLLOCK) - { + if (key == SCAN_SCROLLLOCK) { kbdstatus ^= STATUS_SCRL; goto LEDS; } - if(key == SCAN_NUMLOCK) - { + if (key == SCAN_NUMLOCK) { kbdstatus ^= STATUS_NUM; goto LEDS; } - if(key == SCAN_CAPSLOCK) - { + if (key == SCAN_CAPSLOCK) { kbdstatus ^= STATUS_CAPS; -LEDS: - outkbd(0x60, 0xED); /* "mise a jour des LEDS */ - temp = 0; - if(kbdstatus & STATUS_SCRL) + LEDS: + outkbd(0x60, 0xED); /* "mise a jour des LEDS */ + temp = 0; + if (kbdstatus & STATUS_SCRL) temp |= 1; - if(kbdstatus & STATUS_NUM) + if (kbdstatus & STATUS_NUM) temp |= 2; - if(kbdstatus & STATUS_CAPS) + if (kbdstatus & STATUS_CAPS) temp |= 4; outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */ return 0; } /* est ce un code etendu */ -if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e))) - /* exceptions */ - { - /* '/' (E035) */ - if (key==0x35) return '/'; - /* '\r' (E01C) 2ème enter numérique*/ - if (key==0x1C) return '\r'; - /* 0x11 (E048) device control 1)*/ - if (key==0x48) return 0x11; - /* 0x12 (E050) device control 2)*/ - if (key==0x50) return 0x12; - /* 0x13 (E04b) device control 3)*/ - if (key==0x4b) return 0x13; - /* 0x14 (E04d) device control 4)*/ - if (key==0x4d) return 0x14; - /* 0x02 (E049) start of text)*/ - if (key==0x49) return 0x2; - /* 0x03 (E051) end of text)*/ - if (key==0x51) return 0x3; - /* 0x10 (E047) Line feed)*/ - if (key==0x47) return '\n'; - /* 0x1A (E052) Substitution)*/ - if (key==0x52) return 0x1A; - /* 0x18 (E053) Cancel)*/ - if (key==0x53) return 0x18; - /* 0x19 (E04f) End of medium)*/ - if (key==0x4f) return 0x19; - return 0x00; - } - else - { -/* detecte les SCANCODES invalides */ - if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0; -/* converti le scancode en code ASCII en fonction du statut*/ - if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS) - temp = set1_shift[key]; - else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL)) - temp = set1_altgr[key]; - else if (kbdstatus & STATUS_CTRL) - temp = set1_ctrl[key]; - else if (kbdstatus & STATUS_ALT) - temp = set1_alt[key]; - else - temp = set1_normal[key]; - } - -/* si scancode non reconnu fin de fonction */ - if(temp == 0) return temp; -/* Appuie de CRTL + ALT + SUPR ? */ - if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && - (key == 76)) + if ((bufferscan[lastscan] == 0xE0) + || ((kbdstatus & STATUS_NUM) && (key >= 0x47) && (key <= 0x53) + && (key != 0x4A) && (key != 0x4e))) + /* exceptions */ { + /* '/' (E035) */ + if (key == 0x35) + return '/'; + /* '\r' (E01C) 2ème enter numérique */ + if (key == 0x1C) + return '\r'; + /* 0x11 (E048) device control 1) */ + if (key == 0x48) + return 0x11; + /* 0x12 (E050) device control 2) */ + if (key == 0x50) + return 0x12; + /* 0x13 (E04b) device control 3) */ + if (key == 0x4b) + return 0x13; + /* 0x14 (E04d) device control 4) */ + if (key == 0x4d) + return 0x14; + /* 0x02 (E049) start of text) */ + if (key == 0x49) + return 0x2; + /* 0x03 (E051) end of text) */ + if (key == 0x51) + return 0x3; + /* 0x10 (E047) Line feed) */ + if (key == 0x47) + return '\n'; + /* 0x1A (E052) Substitution) */ + if (key == 0x52) + return 0x1A; + /* 0x18 (E053) Cancel) */ + if (key == 0x53) + return 0x18; + /* 0x19 (E04f) End of medium) */ + if (key == 0x4f) + return 0x19; + return 0x00; + } else { +/* detecte les SCANCODES invalides */ + if (key >= sizeof(set1_normal) / sizeof(set1_normal[0])) + return 0; +/* converti le scancode en code ASCII en fonction du statut*/ + if (kbdstatus & STATUS_SHIFT || kbdstatus & STATUS_CAPS) + temp = set1_shift[key]; + else if ((kbdstatus & STATUS_ALT) && (kbdstatus & STATUS_CTRL)) + temp = set1_altgr[key]; + else if (kbdstatus & STATUS_CTRL) + temp = set1_ctrl[key]; + else if (kbdstatus & STATUS_ALT) + temp = set1_alt[key]; + else + temp = set1_normal[key]; + } + +/* si scancode non reconnu fin de fonction */ + if (temp == 0) + return temp; +/* Appuie de CRTL + ALT + SUPR ? */ + if ((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && + (key == 76)) { print("redemarrage du systeme"); reboot(); } @@ -280,31 +295,32 @@ if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<= return temp; } - /******************************************************************************/ +/* Handler d'interruption IRQ 1 pour le clavier */ + void keyboard() -{ -cli(); -pushf(); -pushad(); -u8 scancode,ascii; -cli(); -while ((inb(0x64)&1)==0); -scancode=inb(0x60); -ascii = convert(scancode); -if(ascii != 0) { -ptrascii++; -if (ptrascii==255) ptrascii==0; -bufferascii[ptrascii]=ascii; -} -irqendmaster(); - popad(); - popf(); + cli(); + pushf(); + pushad(); + u8 scancode, ascii; + cli(); + while ((inb(0x64) & 1) == 0) ; + scancode = inb(0x60); + ascii = convert(scancode); + if (ascii != 0) { + ptrascii++; + if (ptrascii == 255) + ptrascii == 0; + bufferascii[ptrascii] = ascii; + } + irqendmaster(); + popad(); + popf(); sti(); - asm("addl $0x01C, %esp;"); - iret(); + asm("addl $0x01C, %esp;"); + iret(); } /******************************************************************************/ diff --git a/lib/keymap.c b/lib/keymap.c deleted file mode 100755 index e69de29..0000000 diff --git a/lib/makefile b/lib/makefile index 96ec60e..fe0fea5 100755 --- a/lib/makefile +++ b/lib/makefile @@ -1,6 +1,6 @@ CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include LINK=ld -m elf_i386 -r -o -OBJS=memory.o vga.o port.o video.o mouse.o idt.o timer.o keyboard.o types.o string.o graph.o 3d.o math.o cpu.o +OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o all: makeall diff --git a/lib/math.c b/lib/math.c index a83d8f1..02bda38 100755 --- a/lib/math.c +++ b/lib/math.c @@ -1,7 +1,12 @@ #include "types.h" -u32 abs(int x) -{ -if (x<0) x=-x; -return (u32)x; -} +/******************************************************************************/ + +/* Fonction qui retourne la valeur absolue */ + +u32 abs(int x) { + if (x < 0) + x = -x; + return (u32) x; +} + diff --git a/lib/memory.c b/lib/memory.c index fc4a75b..c032927 100755 --- a/lib/memory.c +++ b/lib/memory.c @@ -1,46 +1,46 @@ #include "types.h" -/*******************************************************************************/ +/*******************************************************************************/ + +/* Copie un octet une ou plusieurs fois en mémoire */ -/* Copie un octet une ou plusieurs fois en mémoire */ -void memset(void *dst, u8 val, u32 count,u32 size) +void memset(void *dst, u8 val, u32 count, u32 size) { - u8 *temp; - for(temp = (u8 *)dst; count != 0; count--) - { - temp+=size; - *temp = val; + u8 * temp; + for (temp = (u8 *) dst; count != 0; count--) { + temp += size; + *temp = val; + } +} + +/*******************************************************************************/ + +/* Copie une portion de mémoire vers une autre */ + +void memcpy(void *src, void *dst, u32 count, u32 size) { + char *s, *d; + u32 i; + s = (u8 *) src; + d = (u8 *) dst; + for (i = 0; i < count; i++) { + *(d + i * size) = *(s + i); } } - -/*******************************************************************************/ - -/* Copie une portion de mémoire vers une autre */ -void memcpy(void *src, void *dst, u32 count, u32 size) + +/*******************************************************************************/ + +/* Compare 2 portions de mémoire */ + +u32 memcmp(void *src, void *dst, u32 count, u32 size) { - char *s, *d; - u32 i; - s = (u8*) src; - d = (u8*) dst; - for(i=0;i0) if (inb(0x60)==250) return 1; -return 0; + while (i-- > 0) + if (inb(0x60) == 250) + return 1; + return 0; } -static u8 bytepos=0,mousereplies=0; -static u8 mpacket[3]; -static s32 mousex=40, mousey=12; -static u16 oldx=0, oldy=0; -static u8 oldchar=0x00,oldattr=0x07; -static bool mousebut1=0,mousebut2=0,mousebut3=0; -static u8 speed=6; +static u8 bytepos = 0, mousereplies = 0; +static u8 mpacket[3]; +static s32 mousex = 40, mousey = 12; +static u16 oldx = 0, oldy = 0; +static u8 oldchar = 0x00, oldattr = 0x07; +static bool mousebut1 = 0, mousebut2 = 0, mousebut3 = 0; +static u8 speed = 6; +/******************************************************************************/ + +/* ecriture vers souris */ void outmseack(u8 value) { -outkbd(0x64,0xD4); /* ecriture vers souris */ -outb(0x60,value); -mousereplies++; + outkbd(0x64, 0xD4); + outb(0x60, value); + mousereplies++; } +/* ecriture vers mode */ + void outmsecmd(u8 command) { -outkbd(0x64,0x60); /* ecriture vers mode */ -outb(0x60,command); + outkbd(0x64, 0x60); + outb(0x60, command); } +/******************************************************************************/ + +/* Handler d'interruption de la souris IRQ 12 */ + void mouse() { -u8 mbyte=inb(0x60); -s8 changex,changey; -cli(); + cli(); + pushf(); + pushad(); + u8 mbyte = inb(0x60); + s8 changex, changey; - if (mousereplies > 0) - { - if (mbyte == 0xFA) - { - mousereplies--; - goto endofint; - } - mousereplies = 0; - } + if (mousereplies > 0) { + if (mbyte == 0xFA) { + mousereplies--; + goto endofint; + } + mousereplies = 0; + } - mpacket[bytepos]=mbyte; - bytepos++; - -if(bytepos==3) { -bytepos=0; -if ( mpacket[1] == 0) - { - changex = 0; - } - else - { - changex = (mpacket[0] & 0x10) ? - mpacket[1] - 256 : - mpacket[1]; - } - if (mpacket[2] == 0) - { - changey = 0; - } - else - { - changey = -((mpacket[0] & 0x20) ? - mpacket[2] - 256 : - mpacket[2]); - } + mpacket[bytepos] = mbyte; + bytepos++; - mousex+= (changex<=65535) { mousex=65535; } - if(mousey<0) { mousey=0; } - if(mousey>=65535) { mousey=65535; } - - u16 newx=(u32)mousex*getxres()/65536; - u16 newy=(u32)mousey*getyres()/65536; + if (bytepos == 3) { + bytepos = 0; + if (mpacket[1] == 0) { + changex = 0; + } else { + changex = (mpacket[0] & 0x10) ? + mpacket[1] - 256 : mpacket[1]; + } + if (mpacket[2] == 0) { + changey = 0; + } else { + changey = -((mpacket[0] & 0x20) ? + mpacket[2] - 256 : mpacket[2]); + } + + mousex += (changex << speed); + mousey += (changey << speed); + + if (mousex < 0) { + mousex = 0; + } + if (mousex >= 65535) { + mousex = 65535; + } + if (mousey < 0) { + mousey = 0; + } + if (mousey >= 65535) { + mousey = 65535; + } + + u16 newx = (u32) mousex * getxres() / 65536; + u16 newy = (u32) mousey * getyres() / 65536; + + // Retrieve mouse button status from packet + mousebut1 = mpacket[0] & 1; + mousebut2 = mpacket[0] & 2; + mousebut3 = mpacket[0] & 4; - // Retrieve mouse button status from packet - mousebut1=mpacket[0] & 1; - mousebut2=mpacket[0] & 2; - mousebut3=mpacket[0] & 4; - // printf("RX:%d\tRY:%d\tX:%d\tY:%d\tB1:%d\tB2:%d\tB3:%d\t\r\n",changex,changey,mousex,mousey,mousebut1,mousebut2,mousebut3); -if ((newx!=oldx)||(newy!=oldy)) -{ - showchar(oldx,oldy,oldchar,oldattr); - oldx=newx; - oldy=newy; - oldchar=getchar(oldx,oldy); - oldattr=getattrib(oldx,oldy); - showchar(newx,newy,0xDB,0x0F); -} -} -endofint: -irqendmaster(); -irqendslave(); -sti(); -//asm("movl 0x2C(%esp), %ebx;movl 0x30(%esp), %esi;movl 0x34(%esp), %edi;movl 0x38(%esp), %ebp;addl $0x3C, %esp;iret;"); -asm( -"addl $0x18,%esp;\ + if ((newx != oldx) || (newy != oldy)) { + showchar(oldx, oldy, oldchar, oldattr); + oldx = newx; + oldy = newy; + oldchar = getchar(oldx, oldy); + oldattr = getattrib(oldx, oldy); + showchar(newx, newy, 0xDB, 0x0F); + } + } + endofint: + irqendmaster(); + irqendslave(); + popad(); + popf(); + sti(); + asm("addl $0x18,%esp;\ popl %bx;\ iret;"); + iret(); } - - - - - - - diff --git a/lib/port.c b/lib/port.c deleted file mode 100755 index bf5fe3c..0000000 --- a/lib/port.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "types.h" -#include "asm.h" - -/*******************************************************************************/ - -/* Envoie une série d'octet a destination d'une portion de mémoire -vers le registre video spécifié */ - -void outreg(u16 port,u8 *src,u16 num) -{ -int i; -for(i=0;i +/******************************************************************************/ + /* Compare 2 chaines de caractère et renvoie la premiere distance (diff) */ -s8 strcmp(const u8 *src,const u8 *des) + +s8 strcmp(const u8 * src, const u8 * des) { register s8 result; - do - { - if ((result = *src - *des++) != 0) break; + do { + if ((result = *src - *des++) != 0) + break; } - while (*src++!=0); - return result; + while (*src++ != 0); + return result; } +/******************************************************************************/ /* Trouve la premiere occurence d'un caractère dans une chaine */ - -u8 * strchr(const u8 *src, u8 achar) + +u8 *strchr(const u8 * src, u8 achar) { - for(; *src!= achar; ++src) - if (*src == 0) return 0; - return (u8*)src; + for (; *src != achar; ++src) + if (*src == 0) + return 0; + return (u8 *) src; } +/******************************************************************************/ + /* Renvoie la taille de la chaine */ - -u32 strlen(const u8 *src) + +u32 strlen(const u8 * src) { u32 size; - for (size = 0; *(src+size) != 0; size++); + for (size = 0; *(src + size) != 0; size++) ; return size; } +/******************************************************************************/ /* copie une chaine dans une autre */ -u8* strcpy(const u8 *src, u8 *des) +u8 *strcpy(const u8 * src, u8 * des) { u8 *temp = des; - while ((*des++ = *src++) != 0); + while ((*des++ = *src++) != 0) ; return temp; } +/******************************************************************************/ /* copie une portion limité d'une chaine asciiZ*/ -u8 *strncpy(const u8 *src,u8 *des,u32 count) +u8 *strncpy(const u8 * src, u8 * des, u32 count) { u8 *temp = des; while (count) { - if ((*temp = *src) != 0) src++; + if ((*temp = *src) != 0) + src++; temp++; count--; } return des; } +/******************************************************************************/ + /* concatene 2 chaines de caractère */ -u8 *strcat( const u8 *src,u8 *des) +u8 *strcat(const u8 * src, u8 * des) { u8 *temp = des; - while (*des!=0) des++; - while ((*des++ = *src++) != 0); + while (*des != 0) + des++; + while ((*des++ = *src++) != 0) ; return temp; } diff --git a/lib/timer.c b/lib/timer.c index 8d19346..ff9e218 100755 --- a/lib/timer.c +++ b/lib/timer.c @@ -1,27 +1,29 @@ -#include "idt.h" +#include "interrupts.h" #include "types.h" #include "asm.h" #include "memory.h" #include "timer.h" #include "vga.h" +static u8 curs[4] = { "-\\|/" }; -static u8 curs[4]={"-\\|/"}; +static u8 curspos = 0; -static u8 curspos=0; +/******************************************************************************/ +/* Handler d'interruption de la souris IRQ 0 */ void timer() - { -cli(); -pushf(); -pushad(); - showchar(0,0,curs[curspos],7); - curspos=(curspos+1)&0x3; -irqendmaster(); - popad(); - popf(); +{ + cli(); + pushf(); + pushad(); + showchar(0, 0, curs[curspos], 7); + curspos = (curspos + 1) & 0x3; + irqendmaster(); + popad(); + popf(); sti(); - asm("addl $0x0C, %esp;"); - iret(); - } + asm("addl $0x0C, %esp;"); + iret(); +} diff --git a/lib/types.c b/lib/types.c index f8b7ee2..93b8023 100755 --- a/lib/types.c +++ b/lib/types.c @@ -1,46 +1,45 @@ #include -char ctype[] = -{ +char ctype[] = { 0x00, -/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, +/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL, -/* 16 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* 16 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* 24 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* 24 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* ' ' */CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN, +/* ' ' */ CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '(' */CT_PUN, CT_PUN, CT_PUN, CT_PUN, +/* '(' */ CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '0' */CT_DIG, CT_DIG, CT_DIG, CT_DIG, +/* '0' */ CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, -/* '8' */CT_DIG, CT_DIG, CT_PUN, CT_PUN, +/* '8' */ CT_DIG, CT_DIG, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '@' */CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, +/* '@' */ CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP, -/* 'H' */CT_UP, CT_UP, CT_UP, CT_UP, +/* 'H' */ CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, -/* 'P' */CT_UP, CT_UP, CT_UP, CT_UP, +/* 'P' */ CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, -/* 'X' */CT_UP, CT_UP, CT_UP, CT_PUN, +/* 'X' */ CT_UP, CT_UP, CT_UP, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '`' */CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, +/* '`' */ CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW, -/* h' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, +/* h' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, -/* 'p' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, +/* 'p' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, -/* 'x' */CT_LOW, CT_LOW, CT_LOW, CT_PUN, +/* 'x' */ CT_LOW, CT_LOW, CT_LOW, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_CTL, -/* 128 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 144 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 160 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 176 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 192 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 208 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 224 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 240 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +/* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; diff --git a/lib/vga.c b/lib/vga.c index ad9d48e..d745548 100755 --- a/lib/vga.c +++ b/lib/vga.c @@ -1,11 +1,10 @@ #include "vga.h" #include "memory.h" #include "asm.h" -#include "port.h" #include "types.h" -#include "modes.c" -#include "8x8fnt.c" -#include "8x16fnt.c" +#include "VGA/modes.c" +#include "VGA/8x8fnt.c" +#include "VGA/8x16fnt.c" /* Registres VGAs */ @@ -20,13 +19,13 @@ #define planesize 0x10000 -static u16 resX,resY,color,splitY; /* resolution x,y en caractères et profondeur */ +static u16 resX, resY, color, splitY; /* resolution x,y en caractères et profondeur */ -static u8 pages,activepage,showedpage; /* nombre de pages disponibles N° de la page active*/ -static u32 linesize,pagesize;/* Taille d'une ligne et d'une page */ -static u8 vmode=0xFF; /* mode en cours d'utilisation */ -static u32 basemem; /* Adresse de la mémoire vidéo */ -static bool scrolling,graphic,blink;/* Activation du défilement, Flag du mode graphique */ +static u8 pages, activepage, showedpage; /* nombre de pages disponibles N° de la page active */ +static u32 linesize, pagesize; /* Taille d'une ligne et d'une page */ +static u8 vmode = 0xFF; /* mode en cours d'utilisation */ +static u32 basemem; /* Adresse de la mémoire vidéo */ +static bool scrolling, graphic, blink; /* Activation du défilement, Flag du mode graphique */ /*******************************************************************************/ @@ -34,7 +33,7 @@ static bool scrolling,graphic,blink;/* Activation du d u16 getxres() { -return resX; + return resX; } /*******************************************************************************/ @@ -43,7 +42,7 @@ return resX; u8 getdepth() { -return color; + return color; } /*******************************************************************************/ @@ -52,7 +51,7 @@ return color; u16 getyres() { -return resY-splitY; + return resY - splitY; } /*******************************************************************************/ @@ -61,7 +60,7 @@ return resY-splitY; u16 getnbpages() { -return pages; + return pages; } /*******************************************************************************/ @@ -70,7 +69,8 @@ return pages; void setpage(u8 page) { -if (page>8)); - outb(ccrt, 0x0D); - outb(ccrt+1,(addr&0xFF)); - showedpage=page; -} + if (page < pages) { + u16 addr; + addr = page * pagesize / 2; + outb(ccrt, 0x0C); + outb(ccrt + 1, (addr >> 8)); + outb(ccrt, 0x0D); + outb(ccrt + 1, (addr & 0xFF)); + showedpage = page; + } } + /*******************************************************************************/ /* Sépare l'écran en 2 a partir de la ligne Y */ void split(u16 y) { -u16 addr; -if (graphic==0) - addr=(y<<3); -else - addr=y; - /* line compare pour ligne atteinte */ - outb(ccrt, 0x18); - outb(ccrt+1,(addr&0xFF)); - /* overflow pour le bit 8 */ - - outb(ccrt, 0x07); - outb(ccrt+1,(inb(ccrt+1) & ~16)|((addr>>4)&16)); + u16 addr; + if (graphic == 0) + addr = (y << 3); + else + addr = y; + /* line compare pour ligne atteinte */ + outb(ccrt, 0x18); + outb(ccrt + 1, (addr & 0xFF)); + /* overflow pour le bit 8 */ - /* Maximum Scan Line pour le bit 9 */ - - outb(ccrt, 0x09); - outb(ccrt+1,(inb(ccrt+1) & ~64)|((addr>>3)&64)); - splitY=y; + outb(ccrt, 0x07); + outb(ccrt + 1, (inb(ccrt + 1) & ~16) | ((addr >> 4) & 16)); + + /* Maximum Scan Line pour le bit 9 */ + + outb(ccrt, 0x09); + outb(ccrt + 1, (inb(ccrt + 1) & ~64) | ((addr >> 3) & 64)); + splitY = y; } + /*******************************************************************************/ /* Sépare l'écran en 2 a partir de la ligne Y */ void unsplit() { - /* line compare pour ligne atteinte */ - outb(ccrt, 0x18); - outb(ccrt+1,0); - /* overflow pour le bit 8 */ - - outb(ccrt, 0x07); - outb(ccrt+1,inb(ccrt+1) & ~16); + /* line compare pour ligne atteinte */ + outb(ccrt, 0x18); + outb(ccrt + 1, 0); + /* overflow pour le bit 8 */ - /* Maximum Scan Line pour le bit 9 */ - - outb(ccrt, 0x09); - outb(ccrt+1,inb(ccrt+1) & ~64); - splitY=0; + outb(ccrt, 0x07); + outb(ccrt + 1, inb(ccrt + 1) & ~16); + + /* Maximum Scan Line pour le bit 9 */ + + outb(ccrt, 0x09); + outb(ccrt + 1, inb(ccrt + 1) & ~64); + splitY = 0; } /*******************************************************************************/ /* Attend la retrace verticale */ -void waitvretrace (void) +void waitvretrace(void) { - while ((inb(state)&8)==0); + while ((inb(state) & 8) == 0) ; } /*******************************************************************************/ /* Attend la retrace horizontale */ -void waithretrace (void) +void waithretrace(void) { - while ((inb(state)&1)==0); + while ((inb(state) & 1) == 0) ; } /*******************************************************************************/ /* Active l'affichage du curseur de texte */ -void enablecursor (void) +void enablecursor(void) { u8 curs; /* active le curseur hardware */ outb(ccrt, 10); - curs = inb(ccrt+1)&~32; - outb(ccrt+1, curs); + curs = inb(ccrt + 1) & ~32; + outb(ccrt + 1, curs); } /*******************************************************************************/ /* Desactive l'affichage du curseur de texte */ -void disablecursor (void) +void disablecursor(void) { u8 curs; /* Desactive le curseur hardware */ outb(ccrt, 10); - curs = inb(ccrt+1)|32; - outb(ccrt+1, curs); + curs = inb(ccrt + 1) | 32; + outb(ccrt + 1, curs); } /*******************************************************************************/ /* Active le scrolling en cas de débordement d'écran */ -void enablescroll (void) - +void enablescroll(void) { - scrolling=true; + scrolling = true; } /*******************************************************************************/ /* Desactive le scrolling en cas de débordement d'écran */ -void disablescroll (void) +void disablescroll(void) { - scrolling=false; + scrolling = false; } /*******************************************************************************/ @@ -219,10 +219,10 @@ void useplane(u8 plan) mask = 1 << plan; /* choisi le plan de lecture */ outb(graphics, 4); - outb(graphics+1, plan); + outb(graphics + 1, plan); /* choisi le plan d'ecriture */ outb(sequencer, 2); - outb(sequencer+1, mask); + outb(sequencer + 1, mask); } /*******************************************************************************/ @@ -233,11 +233,10 @@ u32 getbase(void) { u32 base; outb(graphics, 6); - base = inb(graphics+1); + base = inb(graphics + 1); base >>= 2; base &= 3; - switch(base) - { + switch (base) { case 0: case 1: base = 0xA0000; @@ -256,27 +255,28 @@ u32 getbase(void) /* efface l'écran */ -void (*fill)(u8 attrib); +void (*fill) (u8 attrib); - -void fill_text (u8 attrib) +void fill_text(u8 attrib) { - memset((u8 *)(basemem+activepage*pagesize),' ',pagesize/2,2); - memset((u8 *)(basemem+activepage*pagesize+1),attrib,pagesize/2,2); + memset((u8 *) (basemem + activepage * pagesize), ' ', pagesize / 2, 2); + memset((u8 *) (basemem + activepage * pagesize + 1), attrib, + pagesize / 2, 2); } -void fill_chain (u8 attrib) +void fill_chain(u8 attrib) { - memset((u8 *)(basemem+activepage*pagesize),attrib&0x0F,pagesize,1); + memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F, + pagesize, 1); } -void fill_unchain (u8 attrib) +void fill_unchain(u8 attrib) { int i; - for(i=0;i<4;i++) - { + for (i = 0; i < 4; i++) { useplane(i); - memset((u8 *)(basemem+activepage*pagesize),attrib&0x0F,pagesize,1); + memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F, + pagesize, 1); } } @@ -284,103 +284,114 @@ void fill_unchain (u8 attrib) /* fixe la position du curseur texte */ -void gotoscr(u16 x,u16 y) +void gotoscr(u16 x, u16 y) { u16 pos; - if (splitY==0) - pos=(showedpage*pagesize/2+x+y*resX); - else - pos=(x+y*resX); - outb(ccrt,0x0F); - outb(ccrt+1,(u8)(pos&0x00FF)); - outb(ccrt,0x0E); - outb(ccrt+1,(u8)((pos&0xFF00)>>8)); + if (splitY == 0) + pos = (showedpage * pagesize / 2 + x + y * resX); + else + pos = (x + y * resX); + outb(ccrt, 0x0F); + outb(ccrt + 1, (u8) (pos & 0x00FF)); + outb(ccrt, 0x0E); + outb(ccrt + 1, (u8) ((pos & 0xFF00) >> 8)); } /*******************************************************************************/ /* Fait defiler l'ecran de n lignes vers le haut */ -void (*scroll)(u8 lines,u8 attrib); +void (*scroll) (u8 lines, u8 attrib); -void scroll_unchain(u8 lines,u8 attrib) +void scroll_unchain(u8 lines, u8 attrib) { -if (scrolling) -{ - u8 i; - for(i=0;i<4;i++) - { - useplane(i); - memcpy((u8*)(basemem+activepage*pagesize+linesize*8*lines),(u8*)basemem,pagesize-linesize*8*lines,1); - memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*8*lines),attrib&0x0F,linesize*8*lines,1); - } + if (scrolling) { + u8 i; + for (i = 0; i < 4; i++) { + useplane(i); + memcpy((u8 *) (basemem + activepage * pagesize + + linesize * 8 * lines), (u8 *) basemem, + pagesize - linesize * 8 * lines, 1); + memset((u8 *) (basemem + activepage * pagesize + + pagesize - linesize * 8 * lines), + attrib & 0x0F, linesize * 8 * lines, 1); + } } } -void scroll_chain(u8 lines,u8 attrib) +void scroll_chain(u8 lines, u8 attrib) { -if (scrolling) -{ - memcpy((u8*)basemem+activepage*pagesize+linesize*8*lines,(u8*)basemem+activepage*pagesize,pagesize-linesize*8*lines,1); - memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*8*lines),attrib&0x0F,linesize*8*lines,1); -} + if (scrolling) { + memcpy((u8 *) basemem + activepage * pagesize + + linesize * 8 * lines, + (u8 *) basemem + activepage * pagesize, + pagesize - linesize * 8 * lines, 1); + memset((u8 *) (basemem + activepage * pagesize + pagesize - + linesize * 8 * lines), attrib & 0x0F, + linesize * 8 * lines, 1); + } } -void scroll_text(u8 lines,u8 attrib) +void scroll_text(u8 lines, u8 attrib) { -if (scrolling) -{ - memcpy((u8*)basemem+activepage*pagesize+linesize*lines,(u8*)basemem+activepage*pagesize,pagesize-linesize*lines,1); - memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*lines-2),' ',(linesize*lines)/2,2); - memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*lines-1),attrib,(linesize*lines)/2,2); -} + if (scrolling) { + memcpy((u8 *) basemem + activepage * pagesize + + linesize * lines, (u8 *) basemem + activepage * pagesize, + pagesize - linesize * lines, 1); + memset((u8 *) (basemem + activepage * pagesize + pagesize - + linesize * lines - 2), ' ', + (linesize * lines) / 2, 2); + memset((u8 *) (basemem + activepage * pagesize + pagesize - + linesize * lines - 1), attrib, + (linesize * lines) / 2, 2); + } } /*******************************************************************************/ /* Affiche le caractère a l'écran */ -void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib); +void (*showchar) (u16 coordx, u16 coordy, u8 thechar, u8 attrib); -void showchar_graphic(u16 coordx,u16 coordy,u8 thechar,u8 attrib) +void showchar_graphic(u16 coordx, u16 coordy, u8 thechar, u8 attrib) { - u8 x,y,pattern,set; - for(y=0;y<8;y++) - { - pattern=font8x8[thechar*8+y]; - for(x=0;x<8;x++) - { - set=((pattern>>(7-x))&0x1); /* mettre un ROL importé depuis asm */ - if (set==0) - writepxl(coordx*8+x,coordy*8+y,((attrib&0xF0)>>8)*set); + u8 x, y, pattern, set; + for (y = 0; y < 8; y++) { + pattern = font8x8[thechar * 8 + y]; + for (x = 0; x < 8; x++) { + set = ((pattern >> (7 - x)) & 0x1); /* mettre un ROL importé depuis asm */ + if (set == 0) + writepxl(coordx * 8 + x, coordy * 8 + y, + ((attrib & 0xF0) >> 8) * set); else - writepxl(coordx*8+x,coordy*8+y,(attrib&0x0F)*set); + writepxl(coordx * 8 + x, coordy * 8 + y, + (attrib & 0x0F) * set); } } } - - -void showchar_text(u16 coordx,u16 coordy,u8 thechar,u8 attrib) - +void showchar_text(u16 coordx, u16 coordy, u8 thechar, u8 attrib) { - u8 *screen; - screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX); + u8 *screen; + screen = + (u8 *) basemem + activepage * pagesize + 2 * (coordx + + coordy * resX); *screen = thechar; - *(++screen) =attrib; + *(++screen) = attrib; } /*******************************************************************************/ /* Recupere le caractère a l'écran */ -u8 (*getchar)(u16 coordx,u16 coordy); - -u8 getchar_text(u16 coordx,u16 coordy) +u8(*getchar) (u16 coordx, u16 coordy); +u8 getchar_text(u16 coordx, u16 coordy) { - u8 *screen; - screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX); + u8 *screen; + screen = + (u8 *) basemem + activepage * pagesize + 2 * (coordx + + coordy * resX); return *screen; } @@ -388,32 +399,32 @@ u8 getchar_text(u16 coordx,u16 coordy) /* Recupere les attributs a l'écran */ -u8 (*getattrib)(u16 coordx,u16 coordy); - -u8 getattrib_text(u16 coordx,u16 coordy) +u8(*getattrib) (u16 coordx, u16 coordy); +u8 getattrib_text(u16 coordx, u16 coordy) { - u8 *screen; - screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX)+1; + u8 *screen; + screen = + (u8 *) basemem + activepage * pagesize + 2 * (coordx + + coordy * resX) + 1; return *screen; } - /*******************************************************************************/ /* Ecrit un pixel a l'écran */ -void (*writepxl)(u16 x, u16 y, u32 c); +void (*writepxl) (u16 x, u16 y, u32 c); void writepxl_1bit(u16 x, u16 y, u32 c) { - u8* off; + u8 *off; u8 mask; c = (c & 1) * 0xFF; - off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 8); + off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8); x = (x & 7) * 1; mask = 0x80 >> x; - *off= ((*off) & ~mask) | (c & mask); + *off = ((*off) & ~mask) | (c & mask); } void writepxl_2bits(u16 x, u16 y, u32 c) @@ -421,44 +432,43 @@ void writepxl_2bits(u16 x, u16 y, u32 c) u8 *off; u8 mask; c = (c & 3) * 0x55; - off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 4); + off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4); x = (x & 3) * 2; mask = 0xC0 >> x; - *off= ((*off) & ~mask) | (c & mask); + *off = ((*off) & ~mask) | (c & mask); } void writepxl_4bits(u16 x, u16 y, u32 c) { - u8* off; - u8 mask, p, pmask; - off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 8); + u8 *off; + u8 mask, p, pmask; + off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8); x = (x & 7) * 1; mask = 0x80 >> x; pmask = 1; - for(p = 0; p < 4; p++) - { + for (p = 0; p < 4; p++) { useplane(p); - if(pmask & c) - *off= ((*off) | mask); + if (pmask & c) + *off = ((*off) | mask); else - *off= ((*off) & ~mask); + *off = ((*off) & ~mask); pmask <<= 1; } } void writepxl_8bits(u16 x, u16 y, u32 c) { - u8* off; - off = (u8*)(basemem+activepage*pagesize+linesize * y + x); - *off=c; + u8 *off; + off = (u8 *) (basemem + activepage * pagesize + linesize * y + x); + *off = c; } void writepxl_8bitsunchain(u16 x, u16 y, u32 c) { - u8* off; - off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 4); + u8 *off; + off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4); useplane(x & 3); - *off=c; + *off = c; } /*******************************************************************************/ @@ -467,121 +477,113 @@ void writepxl_8bitsunchain(u16 x, u16 y, u32 c) u32 setvmode(u8 mode) { - u8 *def,gmode; + u8 *def, gmode; /* Récupere la definition des registres VGA en fonction du mode -graphique : >0x80 -text : 0x00 - 0x7F -*/ - if (mode>=0x80) - { - gmode=mode-0x80; - if (gmode>maxgraphmode) return 1; /* mode inexistant */ - def=graphmodes[gmode]; - graphic=true; - } - else - { - if (mode>maxtextmode) return 1; /* mode inexistant */ - def=textmodes[mode]; - graphic=false; - loadfont(font8x8,8,1); - loadfont(font8x16,16,0); + graphique : >0x80 + text : 0x00 - 0x7F + */ + if (mode >= 0x80) { + gmode = mode - 0x80; + if (gmode > maxgraphmode) + return 1; /* mode inexistant */ + def = graphmodes[gmode]; + graphic = true; + } else { + if (mode > maxtextmode) + return 1; /* mode inexistant */ + def = textmodes[mode]; + graphic = false; + loadfont(font8x8, 8, 1); + loadfont(font8x16, 16, 0); } /* Initialise les registre "divers" */ - outb(misc,def[0]); + outb(misc, def[0]); /* Initialise les registre d'etat */ - outb(state,0x00); + outb(state, 0x00); /* Initialise le séquenceur */ - outreg(sequencer,&def[1],5); + outreg(sequencer, &def[1], 5); /* Debloque le verouillage des registres controleur CRT */ - outb(ccrt,0x11); - outb(ccrt+1,0x0E); - /* Initialise le controleur CRT */ - outreg(ccrt,&def[6],25); - /* Initialise le controleur graphique */ - outreg(graphics,&def[31],9); - inb(state); - /* Initialise le controleur d'attributs */ - outregsame(attribs,&def[40],21); + outb(ccrt, 0x11); + outb(ccrt + 1, 0x0E); + /* Initialise le controleur CRT */ + outreg(ccrt, &def[6], 25); + /* Initialise le controleur graphique */ + outreg(graphics, &def[31], 9); inb(state); - outb(attribs,0x20); + /* Initialise le controleur d'attributs */ + outregsame(attribs, &def[40], 21); + inb(state); + outb(attribs, 0x20); /* Récupere depuis la table de définition des mode la résolution et la -profondeur (en bits) */ - resX=def[61]; - resY=def[62]; - color=def[63]; + profondeur (en bits) */ + resX = def[61]; + resY = def[62]; + color = def[63]; /* Initialise l'adresse des procedures de gestion graphique et les differentes -variables en fonction de la profondeur et du mode*/ - if (!graphic) - { + variables en fonction de la profondeur et du mode */ + if (!graphic) { /* mode texte */ - linesize=resX*2; - writepxl=NULL; /* pas d'affichage de pixels */ - showchar=showchar_text; - scroll=scroll_text; - fill=fill_text; - pagesize=resY*linesize; - getchar=getchar_text; - getattrib=getattrib_text; - } - else - { - switch(color) - { + linesize = resX * 2; + writepxl = NULL; /* pas d'affichage de pixels */ + showchar = showchar_text; + scroll = scroll_text; + fill = fill_text; + pagesize = resY * linesize; + getchar = getchar_text; + getattrib = getattrib_text; + } else { + switch (color) { case 1: /* mode N&B */ - linesize=resX; - writepxl=writepxl_1bit; - fill=fill_chain; - scroll=scroll_chain; + linesize = resX; + writepxl = writepxl_1bit; + fill = fill_chain; + scroll = scroll_chain; break; case 2: /* mode 4 couleurs */ - linesize=(resX<<1); - writepxl=writepxl_2bits; - fill=fill_chain; - scroll=scroll_chain; + linesize = (resX << 1); + writepxl = writepxl_2bits; + fill = fill_chain; + scroll = scroll_chain; break; case 4: /* mode 16 couleurs */ - linesize=resX; - writepxl=writepxl_4bits; - fill=fill_unchain; - scroll=scroll_unchain; + linesize = resX; + writepxl = writepxl_4bits; + fill = fill_unchain; + scroll = scroll_unchain; break; case 8: /* mode 256 couleurs */ - if (def[5]==0x0E) - { + if (def[5] == 0x0E) { /* mode chainé (plus rapide mais limité en mémoire) */ - linesize=(resX<<3); - writepxl=writepxl_8bits; - scroll=scroll_chain; - fill=fill_chain; - } - else - { + linesize = (resX << 3); + writepxl = writepxl_8bits; + scroll = scroll_chain; + fill = fill_chain; + } else { /* mode non chainé */ - linesize=(resX<<1); - writepxl=writepxl_8bitsunchain; - scroll=scroll_unchain; - fill=fill_unchain; + linesize = (resX << 1); + writepxl = writepxl_8bitsunchain; + scroll = scroll_unchain; + fill = fill_unchain; } break; default: break; } - showchar=showchar_graphic; - pagesize=((resY*linesize)<<3); + showchar = showchar_graphic; + pagesize = ((resY * linesize) << 3); } /* calcul des variables d'état video */ - activepage=0; - showedpage=0; - splitY=0; - vmode=mode; - scrolling=1; - pages=(planesize/pagesize); - basemem=(def[20]<<8)+def[21]+getbase(); + activepage = 0; + showedpage = 0; + splitY = 0; + vmode = mode; + scrolling = 1; + pages = (planesize / pagesize); + basemem = (def[20] << 8) + def[21] + getbase(); return 0; } @@ -598,52 +600,52 @@ u8 getvmode(void) /* Charge une nouvelle police de caractère */ -u32 loadfont(u8* def,u8 size,u8 font) - +u32 loadfont(u8 * def, u8 size, u8 font) { - if (graphics==1) return 1; - u8 oldregs[5]={0,0,0,0,0}; - u8* base; + if (graphics == 1) + return 1; + u8 oldregs[5] = { 0, 0, 0, 0, 0 }; + u8 *base; u16 i; - if (font>7) return 1; - if (font<4) - base = (u8 *)(getbase()+(font<<14)); + if (font > 7) + return 1; + if (font < 4) + base = (u8 *) (getbase() + (font << 14)); else - base = (u8 *)(getbase()+((((font-4)<<1)+1)<<13)); + base = (u8 *) (getbase() + ((((font - 4) << 1) + 1) << 13)); /* sauve les anciens registres */ - outb(sequencer,2); - oldregs[0]=inb(sequencer+1); - outb(sequencer,4); - oldregs[1]=inb(sequencer+1); + outb(sequencer, 2); + oldregs[0] = inb(sequencer + 1); + outb(sequencer, 4); + oldregs[1] = inb(sequencer + 1); /* Adressage paire/impair desactivé (lineaire) */ - outb(sequencer+1, oldregs[1]|0x04); - outb(graphics,4); - oldregs[2]=inb(graphics+1); - outb(graphics,5); - oldregs[3]=inb(graphics+1); + outb(sequencer + 1, oldregs[1] | 0x04); + outb(graphics, 4); + oldregs[2] = inb(graphics + 1); + outb(graphics, 5); + oldregs[3] = inb(graphics + 1); /* Adressage paire/impair desactivé (lineaire) */ - outb(graphics+1, oldregs[3]&~0x10); - outb(graphics,6); - oldregs[4]=inb(graphics+1); + outb(graphics + 1, oldregs[3] & ~0x10); + outb(graphics, 6); + oldregs[4] = inb(graphics + 1); /* Adressage paire/impair desactivé (lineaire) */ - outb(graphics+1, oldregs[4] & ~0x02); + outb(graphics + 1, oldregs[4] & ~0x02); /* utilisation du plan N°2 */ - useplane(2); - for(i=0; i < 256; i++) - { - memcpy(def,base+i*32,size,1); + useplane(2); + for (i = 0; i < 256; i++) { + memcpy(def, base + i * 32, size, 1); def += size; } - outb(sequencer,2); - outb(sequencer+1,oldregs[0]); - outb(sequencer,4); - outb(sequencer+1,oldregs[1]); - outb(graphics,4); - outb(graphics+1,oldregs[2]); - outb(graphics,5); - outb(graphics+1,oldregs[3]); - outb(graphics,6); - outb(graphics+1,oldregs[4]); + outb(sequencer, 2); + outb(sequencer + 1, oldregs[0]); + outb(sequencer, 4); + outb(sequencer + 1, oldregs[1]); + outb(graphics, 4); + outb(graphics + 1, oldregs[2]); + outb(graphics, 5); + outb(graphics + 1, oldregs[3]); + outb(graphics, 6); + outb(graphics + 1, oldregs[4]); return 0; } @@ -653,11 +655,11 @@ u32 loadfont(u8* def,u8 size,u8 font) u8 getfont() { - u8 num,tmp; - outb(sequencer,3); - tmp=inb(sequencer+1); - num=(tmp&0x03)|((tmp&0x10)>>2); - return num; + u8 num, tmp; + outb(sequencer, 3); + tmp = inb(sequencer + 1); + num = (tmp & 0x03) | ((tmp & 0x10) >> 2); + return num; } /*******************************************************************************/ @@ -666,23 +668,24 @@ u8 getfont() u8 getfont2() { - u8 num,tmp; - outb(sequencer,3); - tmp=inb(sequencer+1); - num=((tmp&0x0C)>>2)|((tmp&0x20)>>3); - return num; + u8 num, tmp; + outb(sequencer, 3); + tmp = inb(sequencer + 1); + num = ((tmp & 0x0C) >> 2) | ((tmp & 0x20) >> 3); + return num; } - /*******************************************************************************/ /* Fixe le N° de la police de caractère a utiliser */ void setfont(u8 num) { - num&=0x07; - outb(sequencer,3); - outb(sequencer+1,(inb(sequencer+1)&0xEC)|((num&0x03)+((num&0x04)<<2))); + num &= 0x07; + outb(sequencer, 3); + outb(sequencer + 1, + (inb(sequencer + 1) & 0xEC) | ((num & 0x03) + + ((num & 0x04) << 2))); } /*******************************************************************************/ @@ -691,30 +694,89 @@ void setfont(u8 num) void setfont2(u8 num) { - num&=0x07; - outb(sequencer,3); - outb(sequencer+1,(inb(sequencer+1)&0xD3)|(((num&0x03)<<2)+((num&0x04)<<3))); + num &= 0x07; + outb(sequencer, 3); + outb(sequencer + 1, + (inb(sequencer + 1) & 0xD3) | (((num & 0x03) << 2) + + ((num & 0x04) << 3))); } /*******************************************************************************/ -/* Fixe le N° de la police de caractère a utiliser */ +/* Autorise le clignotement */ void enableblink() { - outb(ccrt,0x10); - outb(ccrt+1,(inb(sequencer+1)|0x04)); + outb(ccrt, 0x10); + outb(ccrt + 1, (inb(sequencer + 1) | 0x04)); } /*******************************************************************************/ -/* Fixe le N° de la police de caractère a utiliser */ +/* Annule le clignotement */ void disableblink() { - outb(ccrt,0x10); - outb(ccrt+1,(inb(sequencer+1)&~0x04)); + outb(ccrt, 0x10); + outb(ccrt + 1, (inb(sequencer + 1) & ~0x04)); } /*******************************************************************************/ +/* Envoie une série d'octet a destination d'une portion de mémoire +vers le registre spécifié */ + +void outreg(u16 port, u8 * src, u16 num) +{ + int i; + for (i = 0; i < num; i++) { + outb(port, i); + outb(port + 1, *src++); + } +} + +/*******************************************************************************/ + +/* Envoie une série d'octet a destination d'une portion de mémoire +vers le registre spécifié (accés data et index confondu) */ + +void outregsame(u16 port, u8 * src, u16 num) +{ + int i; + for (i = 0; i < num; i++) { + inb(port); + outb(port, i); + outb(port, *src++); + } +} + +/*******************************************************************************/ + +/* Récupère une série d'octet en provenance d'un registre spécifié +vers portion de mémoire */ + +void inreg(u16 port, u8 * src, u16 num) +{ + int i; + for (i = 0; i < num; i++) { + outb(port, i); + *src++ = inb(port + 1); + } +} + +/*******************************************************************************/ + +/* Récupère une série d'octet en provenance d'un registre spécifié +vers portion de mémoire (accés data et index confondu) */ + +void inregsame(u16 port, u8 * src, u16 num) +{ + int i; + for (i = 0; i < num; i++) { + inb(port); + outb(port, i); + *src++ = inb(port); + } +} + +/*******************************************************************************/ diff --git a/lib/video.c b/lib/video.c index 2d29345..a557ff1 100755 --- a/lib/video.c +++ b/lib/video.c @@ -2,19 +2,25 @@ #include "video.h" #include "stdarg.h" +console vc[8] = { + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} + , + {0x07, 0, 0, 0, 0, 0, 0, 0} +}; -console vc[8]={ -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}, -{0x07,0,0,0,0,0,0,0}}; - -u8 usedvc=0; - +u8 usedvc = 0; /*******************************************************************************/ @@ -22,32 +28,28 @@ u8 usedvc=0; void setattrib(u8 att) { - static const u8 ansitovga[] = - { + static const u8 ansitovga[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; u8 tempattr; tempattr = vc[usedvc].attrib; - if(att == 0) - tempattr = 0x07; /* Couleur Grise sur fond noir */ + if (att == 0) + tempattr = 0x07; /* Couleur Grise sur fond noir */ else if (att == 5) - tempattr |= 0x80; + tempattr |= 0x80; else if (att == 7) - tempattr = ((tempattr&0x0F)<<4)+((tempattr&0xF0)>>4); + tempattr = ((tempattr & 0x0F) << 4) + ((tempattr & 0xF0) >> 4); else if (att == 8) - tempattr = 0; + tempattr = 0; else if (att == 1) - tempattr |= 0x08; /* Forte intensité */ - else if(att >= 30 && att <= 37) - { + tempattr |= 0x08; /* Forte intensité */ + else if (att >= 30 && att <= 37) { att = ansitovga[att - 30]; - tempattr = (tempattr & ~0x07) | att;/* couleur de premier plan */ - } - else if(att >= 40 && att <= 47) - { + tempattr = (tempattr & ~0x07) | att; /* couleur de premier plan */ + } else if (att >= 40 && att <= 47) { att = ansitovga[att - 40] << 4; - tempattr = (tempattr & ~0x70) | att;/* couleur de fond */ + tempattr = (tempattr & ~0x70) | att; /* couleur de fond */ } vc[usedvc].attrib = tempattr; } @@ -59,20 +61,17 @@ void setattrib(u8 att) bool makeansi(u8 c) { /* state machine to handle the escape sequences */ - switch(vc[usedvc].ansi) - { + switch (vc[usedvc].ansi) { case 0: /* ESC -- next state */ - if(c == 0x1B) - { + if (c == 0x1B) { vc[usedvc].ansi++; - return 1; /* "I handled it" */ + return 1; /* "I handled it" */ } break; /* ESC */ case 1: - if(c == '[') - { + if (c == '[') { vc[usedvc].ansi++; vc[usedvc].param1 = 0; return 1; @@ -80,101 +79,90 @@ bool makeansi(u8 c) break; /* ESC[ */ case 2: - if(isdigit(c)) - { + if (isdigit(c)) { vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0'; return 1; - } - else if(c == ';') - { + } else if (c == ';') { vc[usedvc].ansi++; vc[usedvc].param2 = 0; return 1; } /* ESC[2J -- efface l'ecran */ - else if(c == 'J') - { - if(vc[usedvc].param1 == 2) - { + else if (c == 'J') { + if (vc[usedvc].param1 == 2) { fill(vc[usedvc].attrib); - vc[usedvc].cursX=0; - vc[usedvc].cursY=0; - gotoscr(0,0); + vc[usedvc].cursX = 0; + vc[usedvc].cursY = 0; + gotoscr(0, 0); vc[usedvc].ansi = 0; return 1; } } /* ESC[num1m -- met l'attribut num1 */ - else if(c == 'm') - { + else if (c == 'm') { setattrib(vc[usedvc].param1); vc[usedvc].ansi = 0; return 1; } /* ESC[num1A -- bouge le curseur de num1 vers le haut */ - else if(c == 'A') - { - vc[usedvc].cursY-=vc[usedvc].param1; - if (vc[usedvc].cursY<0) vc[usedvc].cursY=0; + else if (c == 'A') { + vc[usedvc].cursY -= vc[usedvc].param1; + if (vc[usedvc].cursY < 0) + vc[usedvc].cursY = 0; vc[usedvc].ansi = 0; - gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); - return 1; - } + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); + return 1; + } /* ESC[num1B -- bouge le curseur de num1 vers le bas */ - else if(c == 'B') - { - vc[usedvc].cursY+=vc[usedvc].param1; - if (vc[usedvc].cursY>=getyres()-1) vc[usedvc].cursY=getyres(); + else if (c == 'B') { + vc[usedvc].cursY += vc[usedvc].param1; + if (vc[usedvc].cursY >= getyres() - 1) + vc[usedvc].cursY = getyres(); vc[usedvc].ansi = 0; - gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); - return 1; - } + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); + return 1; + } /* ESC[num1D -- bouge le curseur de num1 vers la gauche */ - else if(c == 'D') - { - vc[usedvc].cursX-=vc[usedvc].param1; - if (vc[usedvc].cursX<0) vc[usedvc].cursX=0; + else if (c == 'D') { + vc[usedvc].cursX -= vc[usedvc].param1; + if (vc[usedvc].cursX < 0) + vc[usedvc].cursX = 0; vc[usedvc].ansi = 0; - gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); - return 1; - } + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); + return 1; + } /* ESC[num1C -- bouge le curseur de num1 vers la droite */ - else if(c == 'C') - { - vc[usedvc].cursX+=vc[usedvc].param1; - if (vc[usedvc].cursX>=getxres()-1) vc[usedvc].cursX=getxres(); + else if (c == 'C') { + vc[usedvc].cursX += vc[usedvc].param1; + if (vc[usedvc].cursX >= getxres() - 1) + vc[usedvc].cursX = getxres(); vc[usedvc].ansi = 0; - gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); - return 1; - } + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); + return 1; + } break; /* ESC[num1; */ case 3: - if(isdigit(c)) - { + if (isdigit(c)) { vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0'; return 1; - } - else if(c == ';') - { + } else if (c == ';') { vc[usedvc].ansi++; vc[usedvc].param3 = 0; return 1; } /* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */ - else if((c == 'H')||(c == 'f')) - { - /* Remet la position du curseur matériel a num1,num2 */ - gotoscr(vc[usedvc].param2,vc[usedvc].param1); - /* Remet la position du curseur logiciel a num1,num2 */ - vc[usedvc].cursX=vc[usedvc].param2; - vc[usedvc].cursY=vc[usedvc].param1; + else if ((c == 'H') || (c == 'f')) { + /* Remet la position du curseur matériel a num1,num2 */ + gotoscr(vc[usedvc].param2, vc[usedvc].param1); + /* Remet la position du curseur logiciel a num1,num2 */ + vc[usedvc].cursX = vc[usedvc].param2; + vc[usedvc].cursY = vc[usedvc].param1; vc[usedvc].ansi = 0; return 1; } /* ESC[num1;num2m -- met les attributs num1,num2 */ - else if(c == 'm') - { + else if (c == 'm') { setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param2); vc[usedvc].ansi = 0; @@ -183,14 +171,12 @@ bool makeansi(u8 c) break; /* ESC[num1;num2;num3 */ case 4: - if(isdigit(c)) - { + if (isdigit(c)) { vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0'; return 1; } /* ESC[num1;num2;num3m -- met les attributs num1,num2,num3 */ - else if(c == 'm') - { + else if (c == 'm') { setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param2); setattrib(vc[usedvc].param3); @@ -204,7 +190,7 @@ bool makeansi(u8 c) break; } vc[usedvc].ansi = 0; - return 0; /* Ansi fini ;)*/ + return 0; /* Ansi fini ;) */ } /*******************************************************************************/ @@ -213,10 +199,10 @@ bool makeansi(u8 c) void changevc(u8 avc) { -usedvc=avc; -showpage(usedvc); -setpage(usedvc); -gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); + usedvc = avc; + showpage(usedvc); + setpage(usedvc); + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); } /*******************************************************************************/ @@ -225,178 +211,173 @@ gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); void putchar(u8 thechar) { -showpage(usedvc); -setpage(usedvc); -if(makeansi(thechar)) return; -switch (thechar) -{ -case 0x11: -if (vc[usedvc].cursY>0) vc[usedvc].cursY--; -break; -case 0x12: -if (vc[usedvc].cursY0) vc[usedvc].cursX--; -break; -case 0x14: -if (vc[usedvc].cursX0) -{ -vc[usedvc].cursX=getxres()-1; -vc[usedvc].cursY--; -} -} -else -{ -vc[usedvc].cursX--; -} -showchar(vc[usedvc].cursX,vc[usedvc].cursY,' ',vc[usedvc].attrib); -break; -case '\t': -vc[usedvc].cursX=(vc[usedvc].cursX + 8) & ~(8 - 1); -break; -case '\n': -vc[usedvc].cursX=0; -break; -case '\r': -vc[usedvc].cursX=0; -vc[usedvc].cursY++; -break; -default: -if (thechar>=' ') -{ -showchar(vc[usedvc].cursX,vc[usedvc].cursY,thechar,vc[usedvc].attrib); -vc[usedvc].cursX++; -} -break; -} -if (vc[usedvc].cursX>=getxres()) - { - vc[usedvc].cursX=0; + showpage(usedvc); + setpage(usedvc); + if (makeansi(thechar)) + return; + switch (thechar) { + case 0x11: + if (vc[usedvc].cursY > 0) + vc[usedvc].cursY--; + break; + case 0x12: + if (vc[usedvc].cursY < getyres() - 1) + vc[usedvc].cursY++; + break; + case 0x13: + if (vc[usedvc].cursX > 0) + vc[usedvc].cursX--; + break; + case 0x14: + if (vc[usedvc].cursX < getxres() - 1) + vc[usedvc].cursX++; + break; + case 0x2: + vc[usedvc].cursX = 0; + vc[usedvc].cursY = 0; + break; + case 0x3: + vc[usedvc].cursX = 0; + vc[usedvc].cursY = getyres() - 1; + break; + case 0x19: + vc[usedvc].cursX = getxres() - 1; + break; + case '\b': + if (vc[usedvc].cursX == 0) { + if (vc[usedvc].cursY > 0) { + vc[usedvc].cursX = getxres() - 1; + vc[usedvc].cursY--; + } + } else { + vc[usedvc].cursX--; + } + showchar(vc[usedvc].cursX, vc[usedvc].cursY, ' ', + vc[usedvc].attrib); + break; + case '\t': + vc[usedvc].cursX = (vc[usedvc].cursX + 8) & ~(8 - 1); + break; + case '\n': + vc[usedvc].cursX = 0; + break; + case '\r': + vc[usedvc].cursX = 0; + vc[usedvc].cursY++; + break; + default: + if (thechar >= ' ') { + showchar(vc[usedvc].cursX, vc[usedvc].cursY, thechar, + vc[usedvc].attrib); + vc[usedvc].cursX++; + } + break; + } + if (vc[usedvc].cursX >= getxres()) { + vc[usedvc].cursX = 0; vc[usedvc].cursY++; } -if (vc[usedvc].cursY>=getyres()) - { - scroll(1,vc[usedvc].attrib); - vc[usedvc].cursY=getyres()-1; - } - gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); + if (vc[usedvc].cursY >= getyres()) { + scroll(1, vc[usedvc].attrib); + vc[usedvc].cursY = getyres() - 1; + } + gotoscr(vc[usedvc].cursX, vc[usedvc].cursY); } /*******************************************************************************/ /* affiche une chaine de caractère a l'écran */ -void print(u8* string) +void print(u8 * string) { - u8 *source; + u8 *source; source = string; - while(*source!=0) - { - putchar(*source++); - } + while (*source != 0) { + putchar(*source++); + } } /*******************************************************************************/ /* affiche une chaine de caractère formaté a l'ecran */ -void printf (const u8 *string, ...) +void printf(const u8 * string, ...) { - va_list ap; - u8 buffer[50]; - u8 *pointer; - - u8 radix; - bool signe; - long num; - - - va_start(ap, string); - while(*string!= 0) - { - if (*string != '%') - putchar (*string); - else - { - switch (*++string) - { - case 'c': - putchar (va_arg(ap, int)); - break; - case 'u': - radix=10; - signe=0; -showstring: - num=va_arg(ap, int); - pointer = buffer + 50 - 1; - *pointer = '\0'; - if ((signe==1)&&(num<0)) - { - num = -num; - signe++; - } - do - { + va_list ap; + u8 buffer[50]; + u8 *pointer; + + u8 radix; + bool signe; + long num; + + va_start(ap, string); + while (*string != 0) { + if (*string != '%') + putchar(*string); + else { + switch (*++string) { + case 'c': + putchar(va_arg(ap, int)); + break; + case 'u': + radix = 10; + signe = 0; + showstring: + num = va_arg(ap, int); + pointer = buffer + 50 - 1; + *pointer = '\0'; + if ((signe == 1) && (num < 0)) { + num = -num; + signe++; + } + do { unsigned long temp; temp = (unsigned long)num % radix; pointer--; - if(temp < 10) + if (temp < 10) *pointer = temp + '0'; else *pointer = temp - 10 + 'a'; num = (unsigned long)num / radix; } - while(num != 0); - if (signe>1) *(--pointer)='-'; - while (*pointer!=0) putchar(*pointer++); - break; - case 'o': - radix = 8; - signe=0; - goto showstring; - case 'd': - case 'i': - radix=10; - signe=1; - goto showstring; - case 'x': - radix=16; - signe=0; - goto showstring; - case 's': - pointer=va_arg(ap, u8*); - if (!pointer) pointer="(null)"; - while (*pointer!=0) putchar(*pointer++); - break; - case '%': - putchar ('%'); - break; - default: - putchar (va_arg(ap, int)); - break; - } - } - string++; - } - va_end(ap); + while (num != 0); + if (signe > 1) + *(--pointer) = '-'; + while (*pointer != 0) + putchar(*pointer++); + break; + case 'o': + radix = 8; + signe = 0; + goto showstring; + case 'd': + case 'i': + radix = 10; + signe = 1; + goto showstring; + case 'x': + radix = 16; + signe = 0; + goto showstring; + case 's': + pointer = va_arg(ap, u8 *); + if (!pointer) + pointer = "(null)"; + while (*pointer != 0) + putchar(*pointer++); + break; + case '%': + putchar('%'); + break; + default: + putchar(va_arg(ap, int)); + break; + } + } + string++; + } + va_end(ap); } /*******************************************************************************/ - diff --git a/system/makefile b/system/makefile index 270d3a1..9b6a5d3 100755 --- a/system/makefile +++ b/system/makefile @@ -1,4 +1,3 @@ -FINALCC=gcc -O4 -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o LINK=ld -m elf_i386 -T linker.lds -e main -o @@ -7,9 +6,8 @@ all: system.sys sync system.sys: - nasm -f elf -o system.o system.asm - $(GCC) systemc.o system.c - $(LINK) system.sys systemc.o system.o ../lib/libs.o + $(GCC) system.o system.c + $(LINK) system.sys system.o ../lib/libs.o clean: rm -f *.o diff --git a/system/system.asm b/system/system.asm deleted file mode 100755 index 933909c..0000000 --- a/system/system.asm +++ /dev/null @@ -1,5 +0,0 @@ -[BITS 32] - - - SECTION .text - diff --git a/system/system.c b/system/system.c index dbb9a36..443aac8 100755 --- a/system/system.c +++ b/system/system.c @@ -1,6 +1,6 @@ #include "vga.h" #include "video.h" -#include "idt.h" +#include "interrupts.h" #include "timer.h" #include "keyboard.h" #include "mouse.h" @@ -10,81 +10,79 @@ #include "ansi.c" -static cpuinfo cpu; -static u8 noproc[]="\033[31mInconnu\033[0m\000"; -static u8 okmsg[]="\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000"; -static u8 key=0; +static cpuinfo cpu; +static u8 noproc[] = "\033[31mInconnu\033[0m\000"; +static u8 warnmsg[] = + "\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000"; +static u8 okmsg[] = + "\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000"; +static u8 errormsg[] = + "\033[99C\033[8D\033[37m\033[1m[\033[31mERREUR\033[37m]\033[0m\000"; +static u8 key = 0; void ok() { - print(okmsg); - return; + print(okmsg); + return; } -int main(void) { - - cli(); - setvmode(0x02); - /* Efface l'ecran */ - print("\033[2J\000"); - printf(ansilogo); - print("\033[0mNoyau charge en memoire\000"); - ok(); - - print("Initilisation de la table d'interruption\000"); - initidt(); - ok(); - - print("Initialisation du controleur d'interruption\000"); - initpic(); - sti(); - ok(); - - print("Installation du handler timer\000"); - setidt((u32)timer, 0x20, INTGATE, 32); - ok(); - - print("Activation de l'IRQ 0\000"); - enableirq(0); - ok(); - - print("Installation du handler clavier\000"); - setidt((u32)keyboard, 0x20, INTGATE, 33); - ok(); - - print("Activation de l'IRQ 1\000"); - enableirq(1); - ok(); - - print("Installation du handler souris\000"); - setidt((u32)mouse, 0x20, INTGATE, 100); - ok(); - - print("Initialisation du controleur souris :\000"); - if (initmouse()==1) - print(" \033[1m\033[32mSouris Presente\033[0m\000"); - else - print(" \033[1m\033[31mSouris non detecte\033[0m\000"); - ok(); - - print("Activation de l'IRQ 2 (Controleur esclave)\000"); - enableirq(2); - ok(); - - print("Activation de l'IRQ 12\000"); - enableirq(12); - ok(); - - strcpy(&noproc,&cpu.detectedname); - getcpuinfos(&cpu); - - printf("Processeur detecte\r Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux\t:%s\000",cpu.stepping,cpu.models,cpu.family,&cpu.detectedname,&cpu.techs); - ok(); - while(1) - { - key=waitascii(); - putchar(key); - } - +void warning() +{ + print(warnmsg); + return; } +void error() +{ + print(errormsg); + return; +} + +int main(void) +{ + + cli(); + setvmode(0x02); + /* Efface l'ecran */ + print("\033[2J\000"); + printf(ansilogo); + + print("\033[37m\033[0m -Initilisation des interruptions\000"); + initidt(); + initpic(); + sti(); + ok(); + + print(" -Installation du handler timer (IRQ 0)\000"); + setidt((u32) timer, 0x20, INTGATE, 32); + enableirq(0); + ok(); + + print(" -Installation du handler clavier (IRQ 1)\000"); + setidt((u32) keyboard, 0x20, INTGATE, 33); + enableirq(1); + ok(); + + print(" -Installation du handler souris (IRQ12+Cascade IRQ2)\000"); + setidt((u32) mouse, 0x20, INTGATE, 100); + enableirq(2); + enableirq(12); + if (initmouse() != 1) + warning(); + else + ok(); + + strcpy(&noproc, &cpu.detectedname); + getcpuinfos(&cpu); + + printf + (" -Detection du processeur\r\033[1m Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux d'instruction\t:%s\033[0m\000", + cpu.stepping, cpu.models, cpu.family, &cpu.detectedname, + &cpu.techs); + ok(); + while (1) { + key = waitascii(); + putchar(key); + } + +}