feat: revision des fichiers, ajouts commentaires, ménage & indentation

This commit is contained in:
Nicolas Hordé 2018-08-17 16:46:56 +02:00
parent 3aa3adb92c
commit 56da8273e8
35 changed files with 2825 additions and 3072 deletions

View File

@ -49,100 +49,107 @@ Boot_Ok:
Boot: Boot:
push cs push cs
push cs push cs
pop es pop es
pop ds pop ds
mov [Boot_Drive],dl mov [Boot_Drive],dl
cli cli
mov ax,0x9000 mov ax,0x9000
mov ss,ax mov ss,ax
mov sp,0xFFFF mov sp,0xFFFF
sti sti
mov si,Boot_Message mov si,Boot_Message
call ShowString call ShowString
xor ax,ax ; Initialisation du lecteur de disquette
int 0x13 xor ax,ax
jc Boot_Error int 0x13
mov cx,[Reserved_Sectors] jc Boot_Error
add cx,[Sectors_Hidden] ; Calcul de la position de la FAT12
adc cx,[Sectors_Hidden+2] mov cx,[Reserved_Sectors]
mov bx,[Sectors_Per_Fat] add cx,[Sectors_Hidden]
mov di,Fat_Buffer adc cx,[Sectors_Hidden+2]
push bx mov bx,[Sectors_Per_Fat]
push cx mov di,Fat_Buffer
push bx
push cx
; Lecture de la FAT en mémoire
readfat: readfat:
call ReadSector call ReadSector
jc Boot_Error jc Boot_Error
inc cx inc cx
add di,[Sectors_Size] add di,[Sectors_Size]
dec bx dec bx
jnz readfat jnz readfat
pop cx pop cx
pop bx pop bx
xor ax,ax xor ax,ax
mov al,[Fats_Number] mov al,[Fats_Number]
mul bx mul bx
add cx,ax add cx,ax
mov ax,32 mov ax,32
mul word [Fits_Number] mul word [Fits_Number]
div word [Sectors_Size] div word [Sectors_Size]
add ax,cx add ax,cx
sub ax,2 sub ax,2
mov word [Serial_Number],ax mov word [Serial_Number],ax
xor dx,dx xor dx,dx
call Boot_Ok call Boot_Ok
mov si,Loading_Message mov si,Loading_Message
call ShowString call ShowString
; Recherche du système dans les entrèes de répertoire
Find_System: Find_System:
mov di,Buffer mov di,Buffer
call ReadSector call ReadSector
jc Near Boot_Error jc Near Boot_Error
xor bx,bx xor bx,bx
Next_Root_Entrie: Next_Root_Entrie:
cmp byte [di],0 cmp byte [di],0
je near Boot_Error je near Boot_Error
push di push di
push cx push cx
mov si,System_File mov si,System_File
mov cx,32 mov cx,32
rep cmpsb rep cmpsb
pop cx pop cx
pop di pop di
je System_Found je System_Found
add di,32 add di,32
add bx,32 add bx,32
inc dx inc dx
cmp dx,[Fits_Number] cmp dx,[Fits_Number]
ja near Boot_Error ja near Boot_Error
cmp bx,[Sectors_Size] cmp bx,[Sectors_Size]
jb Next_Root_Entrie jb Next_Root_Entrie
inc cx inc cx
jmp Find_System jmp Find_System
System_Found: System_Found:
call Boot_Ok ; Système trouvé
mov si,Entre_Message call Boot_Ok
call ShowString mov si,Entre_Message
mov cx,[di+26+32] call ShowString
mov ax,0x0080 mov cx,[di+26+32]
mov es,ax mov ax,0x0080
mov es,ax
push es push es
mov di,0x0 mov di,0x0
push di push di
mov si,The_Dot mov si,The_Dot
Resume_Loading: Resume_Loading:
cmp cx,0x0FF0 ; Chargement des secteur en mémoire à l'adresse 0080:0000
jae Finish_Loading cmp cx,0x0FF0
jae Finish_Loading
push cx push cx
add cx,word [Serial_Number] add cx,word [Serial_Number]
call ReadSector call ReadSector
pop cx pop cx
jc near Boot_Error jc near Boot_Error
call ShowString call ShowString
add di,[Sectors_Size] add di,[Sectors_Size]
call NextFatGroup call NextFatGroup
jc near Boot_Error jc near Boot_Error
jmp Resume_Loading jmp Resume_Loading
Finish_Loading: Finish_Loading:
call Boot_Ok call Boot_Ok
; Exécution du chargeur ELF
retf retf
;====================READSECTOR======================= ;====================READSECTOR=======================
@ -152,28 +159,28 @@ Finish_Loading:
;===================================================== ;=====================================================
ReadSector: ReadSector:
pusha pusha
mov ax,cx mov ax,cx
xor dx,dx xor dx,dx
div word [Sectors_Per_Track] div word [Sectors_Per_Track]
inc dl inc dl
mov bl,dl mov bl,dl
xor dx,dx xor dx,dx
div word [Heads_Number] div word [Heads_Number]
mov dh, [Boot_Drive] mov dh, [Boot_Drive]
xchg dl,dh xchg dl,dh
mov cx,ax mov cx,ax
xchg cl,ch xchg cl,ch
shl cl,6 shl cl,6
or cl, bl or cl, bl
mov bx,di mov bx,di
mov si, 4 mov si, 4
mov al, 1 mov al, 1
Read_Again: Read_Again:
mov ah, 2 mov ah, 2
int 0x13 int 0x13
jnc Read_Done jnc Read_Done
dec si dec si
jnz Read_Again jnz Read_Again
Read_Done: Read_Done:
popa popa
ret ret
@ -219,18 +226,18 @@ Next_Group_Found:
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;=====================================================
ShowString: ShowString:
pusha pusha
Next_Char: Next_Char:
lodsb lodsb
or al,al or al,al
jz End_Show jz End_Show
mov ah,0x0E mov ah,0x0E
mov bx,0x07 mov bx,0x07
int 0x10 int 0x10
jmp Next_Char jmp Next_Char
End_Show: End_Show:
popa popa
ret ret
times 510-($-$$) db ' ' times 510-($-$$) db ' '

View File

@ -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 incrmente 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

File diff suppressed because it is too large Load Diff

View File

@ -2,14 +2,11 @@ CC=nasm -f bin -o
all: makall all: makall
makall: boot12.bin boot16.bin loader.sys makall: boot12.bin loader.sys
boot12.bin: boot12.asm boot12.bin: boot12.asm
$(CC) $@ $^ $(CC) $@ $^
boot16.bin: boot16.asm
$(CC) $@ $^
loader.sys: loader.asm loader.sys: loader.asm
$(CC) $@ $^ $(CC) $@ $^

View File

@ -3,6 +3,7 @@ all: cos2000.img
cos2000.img: cos2000.img:
(dd if=/dev/zero of=cos2000.img count=2880 bs=512) (dd if=/dev/zero of=cos2000.img count=2880 bs=512)
(mkfs.msdos -F 12 -n "COS2000" cos2000.img) (mkfs.msdos -F 12 -n "COS2000" cos2000.img)
(mkdir ./mnt)
(fusefat cos2000.img ./mnt -o rw+) (fusefat cos2000.img ./mnt -o rw+)
(cp ../boot/loader.sys ./mnt/) (cp ../boot/loader.sys ./mnt/)
(cp ../system/system.sys ./mnt/;sync) (cp ../system/system.sys ./mnt/;sync)

View File

@ -1 +1,3 @@
#include "types.h"
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color); void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color);

View File

@ -0,0 +1 @@
#include "types.h"

View File

@ -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);

View File

@ -35,3 +35,7 @@ void enableblink();
void disableblink(); void disableblink();
u8 (*getchar)(u16 coordx,u16 coordy); u8 (*getchar)(u16 coordx,u16 coordy);
u8 (*getattrib)(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);

51
lib/2d.c Executable file
View File

@ -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);
}
}
}

View File

@ -1,5 +1,6 @@
#include "3d.h" #include "3d.h"
#include "2d.h"
#include "vga.h" #include "vga.h"
#include "types.h" #include "types.h"
#include "video.h" #include "video.h"
#include "graph.h"

219
lib/VGA/modes.c Executable file
View File

@ -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}
};

327
lib/cpu.c
View File

@ -4,214 +4,193 @@
#include "memory.h" #include "memory.h"
#include "string.h" #include "string.h"
/* Technologies supportées */
static u8 *msg[] = {
static u8 *msg[] = "mmx",
{ "mmx2",
"mmx", "sse",
"mmx2", "sse2",
"sse", "sse3",
"sse2", "fpu",
"sse3", "3dNow!",
"fpu", "3dNow Extended!",
"3dNow!", "HyperThreading",
"3dNow Extended!", "apic",
"HyperThreading",
"apic",
}; };
static u8 space[]=" "; static u8 space[] = " ";
bool cansetflag (u32 flag) /******************************************************************************/
/* Annule les FLAGs CPU */
bool cansetflag(u32 flag)
{ {
u32 r1, r2; u32 r1, r2;
asm("pushfl\n" 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));
"popl %0\n" return ((r1 ^ r2) & flag) != 0;
"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; u32 i, maxfunction, maxextended, unused, regeax, regebx, regecx, regedx;
bool *boolean; bool *boolean;
if (!cansetflag (0x00040000)) return 1; /*386 processor - no cpuid*/ if (!cansetflag(0x00040000))
if (!cansetflag (0x00200000)) return 2; /*486 processor with no cpuid*/ return 1; /*386 processor - no cpuid */
if (!cansetflag(0x00200000))
return 2; /*486 processor with no cpuid */
cpuid(0, &maxfunction, &unused, &unused, &unused); cpuid(0, &maxfunction, &unused, &unused, &unused);
maxfunction &= 0xffff; maxfunction &= 0xffff;
cpuid(0x80000000, &maxextended, &unused, &unused, &unused); cpuid(0x80000000, &maxextended, &unused, &unused, &unused);
maxextended &= 0xffff; maxextended &= 0xffff;
if (maxfunction >= 1) if (maxfunction >= 1) {
{ cpuid(1, &regeax, &regebx, &regecx, &regedx);
cpuid(1, &regeax, &regebx, &regecx, &regedx); proc->stepping = (regeax & 0x0000000F);
proc->stepping = (regeax & 0x0000000F); proc->models = ((regeax >> 4) & 0x0000000F);
proc->models = ((regeax>>4) & 0x0000000F); proc->family = ((regeax >> 8) & 0x0000000F);
proc->family = ((regeax>>8) & 0x0000000F); proc->types = ((regeax >> 12) & 0x00000003);
proc->types = ((regeax>>12) & 0x00000003); proc->emodels = ((regeax >> 16) & 0x0000000F);
proc->emodels = ((regeax>>16) & 0x0000000F); proc->efamily = ((regeax >> 20) & 0x000000FF);
proc->efamily = ((regeax>>20) & 0x000000FF);
proc->brandid = (regeax & 0xF); proc->brandid = (regeax & 0xF);
proc->linesize = ((regeax>>8) & 0xF); proc->linesize = ((regeax >> 8) & 0xF);
proc->count = ((regeax>>16) & 0xF); proc->count = ((regeax >> 16) & 0xF);
proc->apicid = ((regeax>>24) & 0xF); proc->apicid = ((regeax >> 24) & 0xF);
proc->mmx=((regedx>>23) & 0x00000001); proc->mmx = ((regedx >> 23) & 0x00000001);
proc->sse=((regedx>>25) & 0x00000001); proc->sse = ((regedx >> 25) & 0x00000001);
proc->sse2=((regedx>>26) & 0x00000001); proc->sse2 = ((regedx >> 26) & 0x00000001);
proc->sse3=(regecx & 0x00000001); proc->sse3 = (regecx & 0x00000001);
proc->fpu=(regedx & 0x00000001); proc->fpu = (regedx & 0x00000001);
proc->htt=((regedx>>28) & 0x00000001); proc->htt = ((regedx >> 28) & 0x00000001);
} }
if (maxextended >= 1) if (maxextended >= 1) {
{ cpuid(0x80000001, &regeax, &regebx, &regecx, &regedx);
cpuid(0x80000001, &regeax, &regebx, &regecx, &regedx); proc->mmx2 = ((regedx >> 22) & 0x00000001);
proc->mmx2=((regedx>>22) & 0x00000001); proc->apic = ((regedx >> 9) & 0x00000001);
proc->apic=((regedx>>9) & 0x00000001); proc->now3d = ((regedx >> 30) & 0x00000001);
proc->now3d=((regedx>>30) & 0x00000001); proc->now3d2 = ((regedx >> 31) & 0x00000001);
proc->now3d2=((regedx>>31) & 0x00000001); }
} if (maxextended >= 4) {
if (maxextended >= 4) int i;
{ for (i = 0; i < 3; i++) {
int i; cpuid(0x80000002 + i, &regeax, &regebx, &regecx,
for(i=0;i<3;i++) &regedx);
{ memcpy(&regeax, &proc->detectedname[0 + i * 16], 4, 1);
cpuid(0x80000002+i, &regeax, &regebx, &regecx, &regedx); memcpy(&regebx, &proc->detectedname[4 + i * 16], 4, 1);
memcpy(&regeax,&proc->detectedname[0+i*16],4,1); memcpy(&regecx, &proc->detectedname[8 + i * 16], 4, 1);
memcpy(&regebx,&proc->detectedname[4+i*16],4,1); memcpy(&regedx, &proc->detectedname[12 + i * 16], 4, 1);
memcpy(&regecx,&proc->detectedname[8+i*16],4,1); }
memcpy(&regedx,&proc->detectedname[12+i*16],4,1); }
} boolean = &proc->mmx;
} i = 0;
boolean=&proc->mmx;
i=0;
for(i=0;i<10;i++) for (i = 0; i < 10; i++)
if (*(boolean++)==1) if (*(boolean++) == 1) {
{ strcat(msg[i], &proc->techs);
strcat(msg[i],&proc->techs); strcat(space, &proc->techs);
strcat(space,&proc->techs); }
} return 0;
return 0;
} }
/******************************************************************************/
/* Retourne un élément de la pile */
u32 viewstack(u32 number) u32 viewstack(u32 number)
{ {
u32 stack = 0; u32 stack = 0;
asm ( asm("movl %[a1],%%esi;" "addl %%esp,%%esi;" "movl (%%esi), %[a1] ;": [result] "=r"(stack): [a1] "r"(number):"%esi");
"movl %[a1],%%esi;" return stack;
"addl %%esp,%%esi;"
"movl (%%esi), %[a1] ;"
:[result] "=r" (stack)
:[a1] "r" (number)
:"%esi"
);
return stack;
} }
/******************************************************************************/
/* Affiche les registres CPU */
void dump_regs() void dump_regs()
{ {
u32 eax = 0; u32 eax = 0;
u32 ebx = 0; u32 ebx = 0;
u32 ecx = 0; u32 ecx = 0;
u32 edx = 0; u32 edx = 0;
u32 esi = 0; u32 esi = 0;
u32 edi = 0; u32 edi = 0;
u32 ebp = 0; u32 ebp = 0;
u32 esp = 0; u32 esp = 0;
u16 cs = 0; u16 cs = 0;
u16 ds = 0; u16 ds = 0;
u16 es = 0; u16 es = 0;
u16 fs = 0; u16 fs = 0;
u16 gs = 0; u16 gs = 0;
u16 ss = 0; u16 ss = 0;
u32 flags = 0; u32 flags = 0;
asm ( 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] ;":
"movl %%eax, %[a1] ;" [a1] "=m"(eax),[b1] "=m"(ebx),[c1] "=m"(ecx),[d1] "=m"(edx),[e1] "=m"(esi),
"movl %%ebx, %[b1] ;" [f1] "=m"(edi),[g1] "=m"(ebp),[h1] "=m"(esp),[i1] "=m"(cs),[j1] "=m"(ds),
"movl %%ecx, %[c1] ;" [k1] "=m"(es),[l1] "=m"(fs),[m1] "=m"(gs),[n1] "=m"(ss));
"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("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax, ebx,
printf("esi=%x edi=%x\r\n", esi,edi); ecx, edx);
printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n", cs,ds,es,fs,gs); printf("esi=%x edi=%x\r\n", esi, edi);
printf("ss=%x esp=%x ebp=%x\r\n",ss,esp,ebp); 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 ( asm("pushf ;" "pop %[f1] ;":
"pushf ;" [f1] "=m"(flags));
"pop %[f1] ;"
:
[f1] "=m" (flags)
);
printf("FLAGS"); printf("FLAGS");
if(flags & (1 << 0)) // Carry if (flags & (1 << 0)) // Carry
printf(" (C1"); printf(" (C1");
else else
printf(" (C0"); printf(" (C0");
if(flags & (1 << 2)) // Parity if (flags & (1 << 2)) // Parity
printf(" P1"); printf(" P1");
else else
printf(" P0"); printf(" P0");
if(flags & (1 << 4)) // Adjust if (flags & (1 << 4)) // Adjust
printf(" A1"); printf(" A1");
else else
printf(" A0"); printf(" A0");
if(flags & (1 << 6)) // Zero if (flags & (1 << 6)) // Zero
printf(" Z1"); printf(" Z1");
else else
printf(" Z0"); printf(" Z0");
if(flags & (1 << 7)) // Sign if (flags & (1 << 7)) // Sign
printf(" S1"); printf(" S1");
else else
printf(" S0"); printf(" S0");
if(flags & (1 << 11)) // Overflow if (flags & (1 << 11)) // Overflow
printf(" O1)\n"); printf(" O1)\n");
else else
printf(" O0)\n"); 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));
printf("STACK\r\n");
for (u8 i = 0; i < 25; i++)
printf("+%d\t\t%x\r\n", i, viewstack(i * 4));
} }

View File

@ -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;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);
}
}
}

511
lib/idt.c
View File

@ -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);
}

549
lib/interrupts.c Executable file
View File

@ -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);
}

View File

@ -1,4 +1,4 @@
#include "idt.h" #include "interrupts.h"
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "memory.h" #include "memory.h"
@ -6,273 +6,288 @@
#include "video.h" #include "video.h"
static u8 bufferscan[256]={0}; static u8 bufferscan[256] = { 0 };
static u8 bufferascii[256]={0}; static u8 bufferascii[256] = { 0 };
static u8 ptrscan=0;
static u8 ptrascii=0;
static u16 kbdstatus,breakcode ;
static const u8 set1_normal[] = static u8 ptrscan = 0;
{ static u8 ptrascii = 0;
0, 0x1B, '&', 'é', '\"', '\'', '(', '-', static u16 kbdstatus, breakcode;
'è', '_', 'ç', 'à', ')', '=', '\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_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_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
};
/******************************************************************************/ /******************************************************************************/
/* 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_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_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 waitascii()
{ {
u8 oldptrscan=ptrscan; u8 oldptrscan = ptrscan;
u8 oldptrascii=ptrascii; u8 oldptrascii = ptrascii;
while((oldptrascii==ptrascii));/*(oldptrscan==ptrscan)&&*/ while ((oldptrascii == ptrascii)) ;
return bufferascii[ptrascii]; return bufferascii[ptrascii];
} }
/******************************************************************************/ /******************************************************************************/
/* Envoi d'une commande vers le contrôleur de clavier */
void outkbd(u8 port, u8 data) void outkbd(u8 port, u8 data)
{ {
u32 timeout; u32 timeout;
u8 state; u8 state;
/* timeout */ /* timeout */
for(timeout = 500000L; timeout != 0; timeout--) for (timeout = 500000L; timeout != 0; timeout--) {
{
state = inb(0x64); state = inb(0x64);
/* vide le buffer du 8042 */ /* vide le buffer du 8042 */
if((state & 0x02) == 0) break; if ((state & 0x02) == 0)
break;
} }
if(timeout != 0) if (timeout != 0)
outb(port, data); outb(port, data);
} }
/******************************************************************************/ /******************************************************************************/
/* Redemarre l'ordinateur */
static void reboot(void) static void reboot(void)
{ {
u8 temp; u8 temp;
cli(); cli();
/* vide le 8042 */ /* vide le 8042 */
do do {
{
temp = inb(0x64); temp = inb(0x64);
if((temp & 0x01) != 0) if ((temp & 0x01) != 0) {
{
(void)inb(0x60); (void)inb(0x60);
continue; continue;
} }
} while((temp & 0x02) != 0); } while ((temp & 0x02) != 0);
/* active le reset CPU */ /* active le reset CPU */
outb(0x64, 0xFE); outb(0x64, 0xFE);
while(1) while (1)
/* boucle infinie */; /* boucle infinie */ ;
} }
/******************************************************************************/ /******************************************************************************/
/* Converti un scancode vers une code ASCII */
unsigned convert(u32 keypressed) unsigned convert(u32 keypressed)
{ {
u8 temp,key,lastscan; u8 temp, key, lastscan;
/* garde le dernier pointeur du buffer scan */ /* garde le dernier pointeur du buffer scan */
lastscan=ptrscan; lastscan = ptrscan;
/* incrémente le pointeur est assigne au buffer le dernier scancode */ /* incrémente le pointeur est assigne au buffer le dernier scancode */
ptrscan++; ptrscan++;
if (ptrscan==255) ptrscan==0; if (ptrscan == 255)
bufferscan[ptrscan]=keypressed; ptrscan == 0;
bufferscan[ptrscan] = keypressed;
/* break key (touche relaché) ? */ /* break key (touche relaché) ? */
if(keypressed >= 0x80) breakcode = 1; if (keypressed >= 0x80)
key = (keypressed&0x7F); breakcode = 1;
key = (keypressed & 0x7F);
/* Mise a jour des flags lors du relachement de touches de controle */ /* Mise a jour des flags lors du relachement de touches de controle */
if(breakcode) if (breakcode) {
{ if (key == SCAN_ALT) {
if(key == SCAN_ALT)
{
kbdstatus &= ~STATUS_ALT; kbdstatus &= ~STATUS_ALT;
/* si ALT GR (E01D) alors activer aussi control */ /* si ALT GR (E01D) alors activer aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL; if (bufferscan[lastscan] == 0xE0)
} kbdstatus &= ~STATUS_CTRL;
else if(key == SCAN_CTRL) } else if (key == SCAN_CTRL)
kbdstatus &= ~STATUS_CTRL; kbdstatus &= ~STATUS_CTRL;
else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) else if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
kbdstatus &= ~STATUS_SHIFT; kbdstatus &= ~STATUS_SHIFT;
breakcode = 0; breakcode = 0;
return 0; return 0;
} }
/* Mise a jour des flags lors de l'appuie de touches de controle */ /* Mise a jour des flags lors de l'appuie de touches de controle */
if(key == SCAN_ALT) if (key == SCAN_ALT) {
{
kbdstatus |= STATUS_ALT; kbdstatus |= STATUS_ALT;
/* si ALT GR (E01D) alors desactiver aussi control */ /* si ALT GR (E01D) alors desactiver aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL; if (bufferscan[lastscan] == 0xE0)
return 0; kbdstatus |= STATUS_CTRL;
return 0;
} }
if(key == SCAN_CTRL) if (key == SCAN_CTRL) {
{
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
{
kbdstatus |= STATUS_SHIFT; kbdstatus |= STATUS_SHIFT;
return 0; return 0;
} }
if ((key >= SCAN_F1) && (key <= SCAN_F8)) if ((key >= SCAN_F1) && (key <= SCAN_F8)) {
{ changevc(key - SCAN_F1);
changevc(key-SCAN_F1); }
}
/* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
if(key == SCAN_SCROLLLOCK) if (key == SCAN_SCROLLLOCK) {
{
kbdstatus ^= STATUS_SCRL; kbdstatus ^= STATUS_SCRL;
goto LEDS; goto LEDS;
} }
if(key == SCAN_NUMLOCK) if (key == SCAN_NUMLOCK) {
{
kbdstatus ^= STATUS_NUM; kbdstatus ^= STATUS_NUM;
goto LEDS; goto LEDS;
} }
if(key == SCAN_CAPSLOCK) if (key == SCAN_CAPSLOCK) {
{
kbdstatus ^= STATUS_CAPS; kbdstatus ^= STATUS_CAPS;
LEDS: LEDS:
outkbd(0x60, 0xED); /* "mise a jour des LEDS */ outkbd(0x60, 0xED); /* "mise a jour des LEDS */
temp = 0; temp = 0;
if(kbdstatus & STATUS_SCRL) if (kbdstatus & STATUS_SCRL)
temp |= 1; temp |= 1;
if(kbdstatus & STATUS_NUM) if (kbdstatus & STATUS_NUM)
temp |= 2; temp |= 2;
if(kbdstatus & STATUS_CAPS) if (kbdstatus & STATUS_CAPS)
temp |= 4; temp |= 4;
outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */ outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */
return 0; return 0;
} }
/* est ce un code etendu */ /* est ce un code etendu */
if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e))) if ((bufferscan[lastscan] == 0xE0)
/* exceptions */ || ((kbdstatus & STATUS_NUM) && (key >= 0x47) && (key <= 0x53)
{ && (key != 0x4A) && (key != 0x4e)))
/* '/' (E035) */ /* exceptions */
if (key==0x35) return '/'; {
/* '\r' (E01C) 2ème enter numérique*/ /* '/' (E035) */
if (key==0x1C) return '\r'; if (key == 0x35)
/* 0x11 (E048) device control 1)*/ return '/';
if (key==0x48) return 0x11; /* '\r' (E01C) 2ème enter numérique */
/* 0x12 (E050) device control 2)*/ if (key == 0x1C)
if (key==0x50) return 0x12; return '\r';
/* 0x13 (E04b) device control 3)*/ /* 0x11 (E048) device control 1) */
if (key==0x4b) return 0x13; if (key == 0x48)
/* 0x14 (E04d) device control 4)*/ return 0x11;
if (key==0x4d) return 0x14; /* 0x12 (E050) device control 2) */
/* 0x02 (E049) start of text)*/ if (key == 0x50)
if (key==0x49) return 0x2; return 0x12;
/* 0x03 (E051) end of text)*/ /* 0x13 (E04b) device control 3) */
if (key==0x51) return 0x3; if (key == 0x4b)
/* 0x10 (E047) Line feed)*/ return 0x13;
if (key==0x47) return '\n'; /* 0x14 (E04d) device control 4) */
/* 0x1A (E052) Substitution)*/ if (key == 0x4d)
if (key==0x52) return 0x1A; return 0x14;
/* 0x18 (E053) Cancel)*/ /* 0x02 (E049) start of text) */
if (key==0x53) return 0x18; if (key == 0x49)
/* 0x19 (E04f) End of medium)*/ return 0x2;
if (key==0x4f) return 0x19; /* 0x03 (E051) end of text) */
return 0x00; if (key == 0x51)
} return 0x3;
else /* 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 */ /* detecte les SCANCODES invalides */
if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0; if (key >= sizeof(set1_normal) / sizeof(set1_normal[0]))
return 0;
/* converti le scancode en code ASCII en fonction du statut*/ /* converti le scancode en code ASCII en fonction du statut*/
if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS) if (kbdstatus & STATUS_SHIFT || kbdstatus & STATUS_CAPS)
temp = set1_shift[key]; temp = set1_shift[key];
else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL)) else if ((kbdstatus & STATUS_ALT) && (kbdstatus & STATUS_CTRL))
temp = set1_altgr[key]; temp = set1_altgr[key];
else if (kbdstatus & STATUS_CTRL) else if (kbdstatus & STATUS_CTRL)
temp = set1_ctrl[key]; temp = set1_ctrl[key];
else if (kbdstatus & STATUS_ALT) else if (kbdstatus & STATUS_ALT)
temp = set1_alt[key]; temp = set1_alt[key];
else else
temp = set1_normal[key]; temp = set1_normal[key];
} }
/* si scancode non reconnu fin de fonction */ /* si scancode non reconnu fin de fonction */
if(temp == 0) return temp; if (temp == 0)
return temp;
/* Appuie de CRTL + ALT + SUPR ? */ /* Appuie de CRTL + ALT + SUPR ? */
if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && if ((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) &&
(key == 76)) (key == 76)) {
{
print("redemarrage du systeme"); print("redemarrage du systeme");
reboot(); reboot();
} }
@ -280,31 +295,32 @@ if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=
return temp; return temp;
} }
/******************************************************************************/ /******************************************************************************/
/* Handler d'interruption IRQ 1 pour le clavier */
void keyboard() void keyboard()
{ {
cli(); cli();
pushf(); pushf();
pushad(); pushad();
u8 scancode,ascii; u8 scancode, ascii;
cli(); cli();
while ((inb(0x64)&1)==0); while ((inb(0x64) & 1) == 0) ;
scancode=inb(0x60); scancode = inb(0x60);
ascii = convert(scancode); ascii = convert(scancode);
if(ascii != 0) if (ascii != 0) {
{ ptrascii++;
ptrascii++; if (ptrascii == 255)
if (ptrascii==255) ptrascii==0; ptrascii == 0;
bufferascii[ptrascii]=ascii; bufferascii[ptrascii] = ascii;
} }
irqendmaster(); irqendmaster();
popad(); popad();
popf(); popf();
sti(); sti();
asm("addl $0x01C, %esp;"); asm("addl $0x01C, %esp;");
iret(); iret();
} }
/******************************************************************************/ /******************************************************************************/

View File

View File

@ -1,6 +1,6 @@
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include 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 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 all: makeall

View File

@ -1,7 +1,12 @@
#include "types.h" #include "types.h"
u32 abs(int x) /******************************************************************************/
{
if (x<0) x=-x; /* Fonction qui retourne la valeur absolue */
return (u32)x;
u32 abs(int x) {
if (x < 0)
x = -x;
return (u32) x;
} }

View File

@ -3,44 +3,44 @@
/*******************************************************************************/ /*******************************************************************************/
/* 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; u8 * temp;
for(temp = (u8 *)dst; count != 0; count--) for (temp = (u8 *) dst; count != 0; count--) {
{ temp += size;
temp+=size; *temp = val;
*temp = val; }
}
} }
/*******************************************************************************/ /*******************************************************************************/
/* Copie une portion de mémoire vers une autre */ /* Copie une portion de mémoire vers une autre */
void memcpy(void *src, void *dst, u32 count, u32 size)
{ void memcpy(void *src, void *dst, u32 count, u32 size) {
char *s, *d; char *s, *d;
u32 i; u32 i;
s = (u8*) src; s = (u8 *) src;
d = (u8*) dst; d = (u8 *) dst;
for(i=0;i<count;i++){ for (i = 0; i < count; i++) {
*(d+i*size) = *(s+i); *(d + i * size) = *(s + i);
} }
} }
/*******************************************************************************/ /*******************************************************************************/
/* Compare 2 portions de mémoire */ /* Compare 2 portions de mémoire */
u32 memcmp(void *src, void *dst, u32 count, u32 size) u32 memcmp(void *src, void *dst, u32 count, u32 size)
{ {
const u8 *mem1 = (const u8 *)src; const u8 *mem1 = (const u8 *)src;
const u8 *mem2 = (const u8 *)dst; const u8 *mem2 = (const u8 *)dst;
for(; count != 0; count--) for (; count != 0; count--) {
{ if (*mem1 != *mem2)
if(*mem1 != *mem2) return *mem1 - *mem2;
return *mem1 - *mem2; mem1 += size;
mem1+=size; mem2 += size;
mem2+=size; }
}
} }
/*******************************************************************************/ /*******************************************************************************/

View File

@ -1,225 +0,0 @@
/* 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
}
};

View File

@ -5,134 +5,142 @@
#include "vga.h" #include "vga.h"
#include "video.h" #include "video.h"
/******************************************************************************/
/* initialise la souris */
bool initmouse() bool initmouse()
{ {
u16 i=1024; u16 i = 1024;
outkbd(0x64,0xA8); /* autorisé Aux */ outkbd(0x64, 0xA8); /* autorisé Aux */
outmseack(0xf3); /*sample*/ outmseack(0xf3); /*sample */
outmseack(100); /*sample donnée*/ outmseack(100); /*sample donnée */
outmseack(0xe8); /*resolution*/ outmseack(0xe8); /*resolution */
outmseack(3); /*resolution donnée*/ outmseack(3); /*resolution donnée */
outmseack(0xe7); /* echelle 2:1*/ outmseack(0xe7); /* echelle 2:1 */
outmseack(0xf4); /* Autorise peripherique */ outmseack(0xf4); /* Autorise peripherique */
outmsecmd(0x47); /* Autorise interruption */ outmsecmd(0x47); /* Autorise interruption */
while(i-->0) if (inb(0x60)==250) return 1; while (i-- > 0)
return 0; if (inb(0x60) == 250)
return 1;
return 0;
} }
static u8 bytepos=0,mousereplies=0; static u8 bytepos = 0, mousereplies = 0;
static u8 mpacket[3]; static u8 mpacket[3];
static s32 mousex=40, mousey=12; static s32 mousex = 40, mousey = 12;
static u16 oldx=0, oldy=0; static u16 oldx = 0, oldy = 0;
static u8 oldchar=0x00,oldattr=0x07; static u8 oldchar = 0x00, oldattr = 0x07;
static bool mousebut1=0,mousebut2=0,mousebut3=0; static bool mousebut1 = 0, mousebut2 = 0, mousebut3 = 0;
static u8 speed=6; static u8 speed = 6;
/******************************************************************************/
/* ecriture vers souris */
void outmseack(u8 value) void outmseack(u8 value)
{ {
outkbd(0x64,0xD4); /* ecriture vers souris */ outkbd(0x64, 0xD4);
outb(0x60,value); outb(0x60, value);
mousereplies++; mousereplies++;
} }
/* ecriture vers mode */
void outmsecmd(u8 command) void outmsecmd(u8 command)
{ {
outkbd(0x64,0x60); /* ecriture vers mode */ outkbd(0x64, 0x60);
outb(0x60,command); outb(0x60, command);
} }
/******************************************************************************/
/* Handler d'interruption de la souris IRQ 12 */
void mouse() void mouse()
{ {
u8 mbyte=inb(0x60); cli();
s8 changex,changey; pushf();
cli(); pushad();
u8 mbyte = inb(0x60);
s8 changex, changey;
if (mousereplies > 0) if (mousereplies > 0) {
{ if (mbyte == 0xFA) {
if (mbyte == 0xFA) mousereplies--;
{ goto endofint;
mousereplies--; }
goto endofint; mousereplies = 0;
} }
mousereplies = 0;
}
mpacket[bytepos]=mbyte; mpacket[bytepos] = mbyte;
bytepos++; bytepos++;
if(bytepos==3) { if (bytepos == 3) {
bytepos=0; bytepos = 0;
if ( mpacket[1] == 0) if (mpacket[1] == 0) {
{ changex = 0;
changex = 0; } else {
} changex = (mpacket[0] & 0x10) ?
else mpacket[1] - 256 : mpacket[1];
{ }
changex = (mpacket[0] & 0x10) ? if (mpacket[2] == 0) {
mpacket[1] - 256 : changey = 0;
mpacket[1]; } else {
} changey = -((mpacket[0] & 0x20) ?
if (mpacket[2] == 0) mpacket[2] - 256 : mpacket[2]);
{ }
changey = 0;
}
else
{
changey = -((mpacket[0] & 0x20) ?
mpacket[2] - 256 :
mpacket[2]);
}
mousex+= (changex<<speed); mousex += (changex << speed);
mousey+= (changey<<speed); mousey += (changey << speed);
if(mousex<0) { mousex=0; } if (mousex < 0) {
if(mousex>=65535) { mousex=65535; } mousex = 0;
if(mousey<0) { mousey=0; } }
if(mousey>=65535) { mousey=65535; } if (mousex >= 65535) {
mousex = 65535;
}
if (mousey < 0) {
mousey = 0;
}
if (mousey >= 65535) {
mousey = 65535;
}
u16 newx=(u32)mousex*getxres()/65536; u16 newx = (u32) mousex * getxres() / 65536;
u16 newy=(u32)mousey*getyres()/65536; u16 newy = (u32) mousey * getyres() / 65536;
// Retrieve mouse button status from packet // Retrieve mouse button status from packet
mousebut1=mpacket[0] & 1; mousebut1 = mpacket[0] & 1;
mousebut2=mpacket[0] & 2; mousebut2 = mpacket[0] & 2;
mousebut3=mpacket[0] & 4; 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); // 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)) if ((newx != oldx) || (newy != oldy)) {
{ showchar(oldx, oldy, oldchar, oldattr);
showchar(oldx,oldy,oldchar,oldattr); oldx = newx;
oldx=newx; oldy = newy;
oldy=newy; oldchar = getchar(oldx, oldy);
oldchar=getchar(oldx,oldy); oldattr = getattrib(oldx, oldy);
oldattr=getattrib(oldx,oldy); showchar(newx, newy, 0xDB, 0x0F);
showchar(newx,newy,0xDB,0x0F); }
} }
} endofint:
endofint: irqendmaster();
irqendmaster(); irqendslave();
irqendslave(); popad();
sti(); popf();
//asm("movl 0x2C(%esp), %ebx;movl 0x30(%esp), %esi;movl 0x34(%esp), %edi;movl 0x38(%esp), %ebp;addl $0x3C, %esp;iret;"); sti();
asm( asm("addl $0x18,%esp;\
"addl $0x18,%esp;\
popl %bx;\ popl %bx;\
iret;"); iret;");
iret();
} }

View File

@ -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<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 video 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 video 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 video 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);
}
}
/*******************************************************************************/

View File

@ -1,65 +1,78 @@
#include <string.h> #include <string.h>
/******************************************************************************/
/* Compare 2 chaines de caractère et renvoie la premiere distance (diff) */ /* 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; register s8 result;
do do {
{ if ((result = *src - *des++) != 0)
if ((result = *src - *des++) != 0) break; break;
} }
while (*src++!=0); while (*src++ != 0);
return result; return result;
} }
/******************************************************************************/
/* Trouve la premiere occurence d'un caractère dans une chaine */ /* 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) for (; *src != achar; ++src)
if (*src == 0) return 0; if (*src == 0)
return (u8*)src; return 0;
return (u8 *) src;
} }
/******************************************************************************/
/* Renvoie la taille de la chaine */ /* Renvoie la taille de la chaine */
u32 strlen(const u8 *src) u32 strlen(const u8 * src)
{ {
u32 size; u32 size;
for (size = 0; *(src+size) != 0; size++); for (size = 0; *(src + size) != 0; size++) ;
return size; return size;
} }
/******************************************************************************/
/* copie une chaine dans une autre */ /* copie une chaine dans une autre */
u8* strcpy(const u8 *src, u8 *des) u8 *strcpy(const u8 * src, u8 * des)
{ {
u8 *temp = des; u8 *temp = des;
while ((*des++ = *src++) != 0); while ((*des++ = *src++) != 0) ;
return temp; return temp;
} }
/******************************************************************************/
/* copie une portion limité d'une chaine asciiZ*/ /* 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; u8 *temp = des;
while (count) { while (count) {
if ((*temp = *src) != 0) src++; if ((*temp = *src) != 0)
src++;
temp++; temp++;
count--; count--;
} }
return des; return des;
} }
/******************************************************************************/
/* concatene 2 chaines de caractère */ /* concatene 2 chaines de caractère */
u8 *strcat( const u8 *src,u8 *des) u8 *strcat(const u8 * src, u8 * des)
{ {
u8 *temp = des; u8 *temp = des;
while (*des!=0) des++; while (*des != 0)
while ((*des++ = *src++) != 0); des++;
while ((*des++ = *src++) != 0) ;
return temp; return temp;
} }

View File

@ -1,27 +1,29 @@
#include "idt.h" #include "interrupts.h"
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "memory.h" #include "memory.h"
#include "timer.h" #include "timer.h"
#include "vga.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() void timer()
{ {
cli(); cli();
pushf(); pushf();
pushad(); pushad();
showchar(0,0,curs[curspos],7); showchar(0, 0, curs[curspos], 7);
curspos=(curspos+1)&0x3; curspos = (curspos + 1) & 0x3;
irqendmaster(); irqendmaster();
popad(); popad();
popf(); popf();
sti(); sti();
asm("addl $0x0C, %esp;"); asm("addl $0x0C, %esp;");
iret(); iret();
} }

View File

@ -1,46 +1,45 @@
#include <types.h> #include <types.h>
char ctype[] = char ctype[] = {
{
0x00, 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, 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, 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, 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_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,
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, 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_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, 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, 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, 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_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, 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, 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, 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, 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, /* 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, /* 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, /* 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, /* 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, /* 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, /* 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, /* 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 /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };

660
lib/vga.c

File diff suppressed because it is too large Load Diff

View File

@ -2,19 +2,25 @@
#include "video.h" #include "video.h"
#include "stdarg.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]={ u8 usedvc = 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},
{0x07,0,0,0,0,0,0,0}};
u8 usedvc=0;
/*******************************************************************************/ /*******************************************************************************/
@ -22,32 +28,28 @@ u8 usedvc=0;
void setattrib(u8 att) void setattrib(u8 att)
{ {
static const u8 ansitovga[] = static const u8 ansitovga[] = {
{
0, 4, 2, 6, 1, 5, 3, 7 0, 4, 2, 6, 1, 5, 3, 7
}; };
u8 tempattr; u8 tempattr;
tempattr = vc[usedvc].attrib; tempattr = vc[usedvc].attrib;
if(att == 0) if (att == 0)
tempattr = 0x07; /* Couleur Grise sur fond noir */ tempattr = 0x07; /* Couleur Grise sur fond noir */
else if (att == 5) else if (att == 5)
tempattr |= 0x80; tempattr |= 0x80;
else if (att == 7) else if (att == 7)
tempattr = ((tempattr&0x0F)<<4)+((tempattr&0xF0)>>4); tempattr = ((tempattr & 0x0F) << 4) + ((tempattr & 0xF0) >> 4);
else if (att == 8) else if (att == 8)
tempattr = 0; tempattr = 0;
else if (att == 1) else if (att == 1)
tempattr |= 0x08; /* Forte intensité */ tempattr |= 0x08; /* Forte intensité */
else if(att >= 30 && att <= 37) else if (att >= 30 && att <= 37) {
{
att = ansitovga[att - 30]; att = ansitovga[att - 30];
tempattr = (tempattr & ~0x07) | att;/* couleur de premier plan */ tempattr = (tempattr & ~0x07) | att; /* couleur de premier plan */
} } else if (att >= 40 && att <= 47) {
else if(att >= 40 && att <= 47)
{
att = ansitovga[att - 40] << 4; att = ansitovga[att - 40] << 4;
tempattr = (tempattr & ~0x70) | att;/* couleur de fond */ tempattr = (tempattr & ~0x70) | att; /* couleur de fond */
} }
vc[usedvc].attrib = tempattr; vc[usedvc].attrib = tempattr;
} }
@ -59,20 +61,17 @@ void setattrib(u8 att)
bool makeansi(u8 c) bool makeansi(u8 c)
{ {
/* state machine to handle the escape sequences */ /* state machine to handle the escape sequences */
switch(vc[usedvc].ansi) switch (vc[usedvc].ansi) {
{
case 0: case 0:
/* ESC -- next state */ /* ESC -- next state */
if(c == 0x1B) if (c == 0x1B) {
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
return 1; /* "I handled it" */ return 1; /* "I handled it" */
} }
break; break;
/* ESC */ /* ESC */
case 1: case 1:
if(c == '[') if (c == '[') {
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param1 = 0; vc[usedvc].param1 = 0;
return 1; return 1;
@ -80,101 +79,90 @@ bool makeansi(u8 c)
break; break;
/* ESC[ */ /* ESC[ */
case 2: case 2:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0'; vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0';
return 1; return 1;
} } else if (c == ';') {
else if(c == ';')
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param2 = 0; vc[usedvc].param2 = 0;
return 1; return 1;
} }
/* ESC[2J -- efface l'ecran */ /* ESC[2J -- efface l'ecran */
else if(c == 'J') else if (c == 'J') {
{ if (vc[usedvc].param1 == 2) {
if(vc[usedvc].param1 == 2)
{
fill(vc[usedvc].attrib); fill(vc[usedvc].attrib);
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY=0; vc[usedvc].cursY = 0;
gotoscr(0,0); gotoscr(0, 0);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
} }
/* ESC[num1m -- met l'attribut num1 */ /* ESC[num1m -- met l'attribut num1 */
else if(c == 'm') else if (c == 'm') {
{
setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param1);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
/* ESC[num1A -- bouge le curseur de num1 vers le haut */ /* ESC[num1A -- bouge le curseur de num1 vers le haut */
else if(c == 'A') else if (c == 'A') {
{ vc[usedvc].cursY -= vc[usedvc].param1;
vc[usedvc].cursY-=vc[usedvc].param1; if (vc[usedvc].cursY < 0)
if (vc[usedvc].cursY<0) vc[usedvc].cursY=0; vc[usedvc].cursY = 0;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1B -- bouge le curseur de num1 vers le bas */ /* ESC[num1B -- bouge le curseur de num1 vers le bas */
else if(c == 'B') else if (c == 'B') {
{ vc[usedvc].cursY += vc[usedvc].param1;
vc[usedvc].cursY+=vc[usedvc].param1; if (vc[usedvc].cursY >= getyres() - 1)
if (vc[usedvc].cursY>=getyres()-1) vc[usedvc].cursY=getyres(); vc[usedvc].cursY = getyres();
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1D -- bouge le curseur de num1 vers la gauche */ /* ESC[num1D -- bouge le curseur de num1 vers la gauche */
else if(c == 'D') else if (c == 'D') {
{ vc[usedvc].cursX -= vc[usedvc].param1;
vc[usedvc].cursX-=vc[usedvc].param1; if (vc[usedvc].cursX < 0)
if (vc[usedvc].cursX<0) vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1C -- bouge le curseur de num1 vers la droite */ /* ESC[num1C -- bouge le curseur de num1 vers la droite */
else if(c == 'C') else if (c == 'C') {
{ vc[usedvc].cursX += vc[usedvc].param1;
vc[usedvc].cursX+=vc[usedvc].param1; if (vc[usedvc].cursX >= getxres() - 1)
if (vc[usedvc].cursX>=getxres()-1) vc[usedvc].cursX=getxres(); vc[usedvc].cursX = getxres();
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
break; break;
/* ESC[num1; */ /* ESC[num1; */
case 3: case 3:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0'; vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0';
return 1; return 1;
} } else if (c == ';') {
else if(c == ';')
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param3 = 0; vc[usedvc].param3 = 0;
return 1; return 1;
} }
/* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */ /* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */
else if((c == 'H')||(c == 'f')) else if ((c == 'H') || (c == 'f')) {
{ /* Remet la position du curseur matériel a num1,num2 */
/* Remet la position du curseur matériel a num1,num2 */ gotoscr(vc[usedvc].param2, vc[usedvc].param1);
gotoscr(vc[usedvc].param2,vc[usedvc].param1); /* Remet la position du curseur logiciel a num1,num2 */
/* Remet la position du curseur logiciel a num1,num2 */ vc[usedvc].cursX = vc[usedvc].param2;
vc[usedvc].cursX=vc[usedvc].param2; vc[usedvc].cursY = vc[usedvc].param1;
vc[usedvc].cursY=vc[usedvc].param1;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
/* ESC[num1;num2m -- met les attributs num1,num2 */ /* ESC[num1;num2m -- met les attributs num1,num2 */
else if(c == 'm') else if (c == 'm') {
{
setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param1);
setattrib(vc[usedvc].param2); setattrib(vc[usedvc].param2);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
@ -183,14 +171,12 @@ bool makeansi(u8 c)
break; break;
/* ESC[num1;num2;num3 */ /* ESC[num1;num2;num3 */
case 4: case 4:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0'; vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0';
return 1; return 1;
} }
/* ESC[num1;num2;num3m -- met les attributs num1,num2,num3 */ /* 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].param1);
setattrib(vc[usedvc].param2); setattrib(vc[usedvc].param2);
setattrib(vc[usedvc].param3); setattrib(vc[usedvc].param3);
@ -204,7 +190,7 @@ bool makeansi(u8 c)
break; break;
} }
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 0; /* Ansi fini ;)*/ return 0; /* Ansi fini ;) */
} }
/*******************************************************************************/ /*******************************************************************************/
@ -213,10 +199,10 @@ bool makeansi(u8 c)
void changevc(u8 avc) void changevc(u8 avc)
{ {
usedvc=avc; usedvc = avc;
showpage(usedvc); showpage(usedvc);
setpage(usedvc); setpage(usedvc);
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
} }
/*******************************************************************************/ /*******************************************************************************/
@ -225,178 +211,173 @@ gotoscr(vc[usedvc].cursX,vc[usedvc].cursY);
void putchar(u8 thechar) void putchar(u8 thechar)
{ {
showpage(usedvc); showpage(usedvc);
setpage(usedvc); setpage(usedvc);
if(makeansi(thechar)) return; if (makeansi(thechar))
switch (thechar) return;
{ switch (thechar) {
case 0x11: case 0x11:
if (vc[usedvc].cursY>0) vc[usedvc].cursY--; if (vc[usedvc].cursY > 0)
break; vc[usedvc].cursY--;
case 0x12: break;
if (vc[usedvc].cursY<getyres()-1) vc[usedvc].cursY++; case 0x12:
break; if (vc[usedvc].cursY < getyres() - 1)
case 0x13: vc[usedvc].cursY++;
if (vc[usedvc].cursX>0) vc[usedvc].cursX--; break;
break; case 0x13:
case 0x14: if (vc[usedvc].cursX > 0)
if (vc[usedvc].cursX<getxres()-1) vc[usedvc].cursX++; vc[usedvc].cursX--;
break; break;
case 0x2: case 0x14:
vc[usedvc].cursX=0; if (vc[usedvc].cursX < getxres() - 1)
vc[usedvc].cursY=0; vc[usedvc].cursX++;
break; break;
case 0x3: case 0x2:
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY=getyres()-1; vc[usedvc].cursY = 0;
break; break;
case 0x19: case 0x3:
vc[usedvc].cursX=getxres()-1; vc[usedvc].cursX = 0;
break; vc[usedvc].cursY = getyres() - 1;
case '\b': break;
if (vc[usedvc].cursX==0) case 0x19:
{ vc[usedvc].cursX = getxres() - 1;
if (vc[usedvc].cursY>0) break;
{ case '\b':
vc[usedvc].cursX=getxres()-1; if (vc[usedvc].cursX == 0) {
vc[usedvc].cursY--; if (vc[usedvc].cursY > 0) {
} vc[usedvc].cursX = getxres() - 1;
} vc[usedvc].cursY--;
else }
{ } else {
vc[usedvc].cursX--; vc[usedvc].cursX--;
} }
showchar(vc[usedvc].cursX,vc[usedvc].cursY,' ',vc[usedvc].attrib); showchar(vc[usedvc].cursX, vc[usedvc].cursY, ' ',
break; vc[usedvc].attrib);
case '\t': break;
vc[usedvc].cursX=(vc[usedvc].cursX + 8) & ~(8 - 1); case '\t':
break; vc[usedvc].cursX = (vc[usedvc].cursX + 8) & ~(8 - 1);
case '\n': break;
vc[usedvc].cursX=0; case '\n':
break; vc[usedvc].cursX = 0;
case '\r': break;
vc[usedvc].cursX=0; case '\r':
vc[usedvc].cursY++; vc[usedvc].cursX = 0;
break; vc[usedvc].cursY++;
default: break;
if (thechar>=' ') default:
{ if (thechar >= ' ') {
showchar(vc[usedvc].cursX,vc[usedvc].cursY,thechar,vc[usedvc].attrib); showchar(vc[usedvc].cursX, vc[usedvc].cursY, thechar,
vc[usedvc].cursX++; vc[usedvc].attrib);
} vc[usedvc].cursX++;
break; }
} break;
if (vc[usedvc].cursX>=getxres()) }
{ if (vc[usedvc].cursX >= getxres()) {
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY++; vc[usedvc].cursY++;
} }
if (vc[usedvc].cursY>=getyres()) if (vc[usedvc].cursY >= getyres()) {
{ scroll(1, vc[usedvc].attrib);
scroll(1,vc[usedvc].attrib); vc[usedvc].cursY = getyres() - 1;
vc[usedvc].cursY=getyres()-1; }
} gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY);
} }
/*******************************************************************************/ /*******************************************************************************/
/* affiche une chaine de caractère a l'écran */ /* affiche une chaine de caractère a l'écran */
void print(u8* string) void print(u8 * string)
{ {
u8 *source; u8 *source;
source = string; source = string;
while(*source!=0) while (*source != 0) {
{ putchar(*source++);
putchar(*source++); }
}
} }
/*******************************************************************************/ /*******************************************************************************/
/* affiche une chaine de caractère formaté a l'ecran */ /* affiche une chaine de caractère formaté a l'ecran */
void printf (const u8 *string, ...) void printf(const u8 * string, ...)
{ {
va_list ap; va_list ap;
u8 buffer[50]; u8 buffer[50];
u8 *pointer; u8 *pointer;
u8 radix; u8 radix;
bool signe; bool signe;
long num; long num;
va_start(ap, string);
va_start(ap, string); while (*string != 0) {
while(*string!= 0) if (*string != '%')
{ putchar(*string);
if (*string != '%') else {
putchar (*string); switch (*++string) {
else case 'c':
{ putchar(va_arg(ap, int));
switch (*++string) break;
{ case 'u':
case 'c': radix = 10;
putchar (va_arg(ap, int)); signe = 0;
break; showstring:
case 'u': num = va_arg(ap, int);
radix=10; pointer = buffer + 50 - 1;
signe=0; *pointer = '\0';
showstring: if ((signe == 1) && (num < 0)) {
num=va_arg(ap, int); num = -num;
pointer = buffer + 50 - 1; signe++;
*pointer = '\0'; }
if ((signe==1)&&(num<0)) do {
{
num = -num;
signe++;
}
do
{
unsigned long temp; unsigned long temp;
temp = (unsigned long)num % radix; temp = (unsigned long)num % radix;
pointer--; pointer--;
if(temp < 10) if (temp < 10)
*pointer = temp + '0'; *pointer = temp + '0';
else else
*pointer = temp - 10 + 'a'; *pointer = temp - 10 + 'a';
num = (unsigned long)num / radix; num = (unsigned long)num / radix;
} }
while(num != 0); while (num != 0);
if (signe>1) *(--pointer)='-'; if (signe > 1)
while (*pointer!=0) putchar(*pointer++); *(--pointer) = '-';
break; while (*pointer != 0)
case 'o': putchar(*pointer++);
radix = 8; break;
signe=0; case 'o':
goto showstring; radix = 8;
case 'd': signe = 0;
case 'i': goto showstring;
radix=10; case 'd':
signe=1; case 'i':
goto showstring; radix = 10;
case 'x': signe = 1;
radix=16; goto showstring;
signe=0; case 'x':
goto showstring; radix = 16;
case 's': signe = 0;
pointer=va_arg(ap, u8*); goto showstring;
if (!pointer) pointer="(null)"; case 's':
while (*pointer!=0) putchar(*pointer++); pointer = va_arg(ap, u8 *);
break; if (!pointer)
case '%': pointer = "(null)";
putchar ('%'); while (*pointer != 0)
break; putchar(*pointer++);
default: break;
putchar (va_arg(ap, int)); case '%':
break; putchar('%');
} break;
} default:
string++; putchar(va_arg(ap, int));
} break;
va_end(ap); }
}
string++;
}
va_end(ap);
} }
/*******************************************************************************/ /*******************************************************************************/

View File

@ -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 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 LINK=ld -m elf_i386 -T linker.lds -e main -o
@ -7,9 +6,8 @@ all: system.sys
sync sync
system.sys: system.sys:
nasm -f elf -o system.o system.asm $(GCC) system.o system.c
$(GCC) systemc.o system.c $(LINK) system.sys system.o ../lib/libs.o
$(LINK) system.sys systemc.o system.o ../lib/libs.o
clean: clean:
rm -f *.o rm -f *.o

View File

@ -1,5 +0,0 @@
[BITS 32]
SECTION .text

View File

@ -1,6 +1,6 @@
#include "vga.h" #include "vga.h"
#include "video.h" #include "video.h"
#include "idt.h" #include "interrupts.h"
#include "timer.h" #include "timer.h"
#include "keyboard.h" #include "keyboard.h"
#include "mouse.h" #include "mouse.h"
@ -11,80 +11,78 @@
#include "ansi.c" #include "ansi.c"
static cpuinfo cpu; static cpuinfo cpu;
static u8 noproc[]="\033[31mInconnu\033[0m\000"; 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 warnmsg[] =
static u8 key=0; "\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() void ok()
{ {
print(okmsg); print(okmsg);
return; return;
} }
int main(void) { void warning()
{
cli(); print(warnmsg);
setvmode(0x02); return;
/* 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 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);
}
}