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

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
makall: boot12.bin boot16.bin loader.sys
makall: boot12.bin loader.sys
boot12.bin: boot12.asm
$(CC) $@ $^
boot16.bin: boot16.asm
$(CC) $@ $^
loader.sys: loader.asm
$(CC) $@ $^

View File

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

View File

@ -1 +1,3 @@
#include "types.h"
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();
u8 (*getchar)(u16 coordx,u16 coordy);
u8 (*getattrib)(u16 coordx,u16 coordy);
void outreg(u16 port,u8 *src,u16 num);
void outregsame(u16 port,u8 *src,u16 num);
void inreg(u16 port,u8 *src,u16 num);
void inregsame(u16 port,u8 *src,u16 num);

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

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

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

View File

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

View File

@ -3,44 +3,44 @@
/*******************************************************************************/
/* Copie un octet une ou plusieurs fois en mémoire */
void memset(void *dst, u8 val, u32 count,u32 size)
void memset(void *dst, u8 val, u32 count, u32 size)
{
u8 *temp;
for(temp = (u8 *)dst; count != 0; count--)
{
temp+=size;
*temp = val;
}
u8 * temp;
for (temp = (u8 *) dst; count != 0; count--) {
temp += size;
*temp = val;
}
}
/*******************************************************************************/
/* Copie une portion de mémoire vers une autre */
void memcpy(void *src, void *dst, u32 count, u32 size)
{
char *s, *d;
u32 i;
s = (u8*) src;
d = (u8*) dst;
for(i=0;i<count;i++){
*(d+i*size) = *(s+i);
void memcpy(void *src, void *dst, u32 count, u32 size) {
char *s, *d;
u32 i;
s = (u8 *) src;
d = (u8 *) dst;
for (i = 0; i < count; i++) {
*(d + i * size) = *(s + i);
}
}
/*******************************************************************************/
/* Compare 2 portions de mémoire */
u32 memcmp(void *src, void *dst, u32 count, u32 size)
{
const u8 *mem1 = (const u8 *)src;
const u8 *mem2 = (const u8 *)dst;
for(; count != 0; count--)
{
if(*mem1 != *mem2)
return *mem1 - *mem2;
mem1+=size;
mem2+=size;
}
const u8 *mem1 = (const u8 *)src;
const u8 *mem2 = (const u8 *)dst;
for (; count != 0; count--) {
if (*mem1 != *mem2)
return *mem1 - *mem2;
mem1 += 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 "video.h"
/******************************************************************************/
/* initialise la souris */
bool initmouse()
{
u16 i=1024;
u16 i = 1024;
outkbd(0x64,0xA8); /* autorisé Aux */
outkbd(0x64, 0xA8); /* autorisé Aux */
outmseack(0xf3); /*sample*/
outmseack(100); /*sample donnée*/
outmseack(0xf3); /*sample */
outmseack(100); /*sample donnée */
outmseack(0xe8); /*resolution*/
outmseack(3); /*resolution donnée*/
outmseack(0xe8); /*resolution */
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;
return 0;
while (i-- > 0)
if (inb(0x60) == 250)
return 1;
return 0;
}
static u8 bytepos=0,mousereplies=0;
static u8 mpacket[3];
static s32 mousex=40, mousey=12;
static u16 oldx=0, oldy=0;
static u8 oldchar=0x00,oldattr=0x07;
static bool mousebut1=0,mousebut2=0,mousebut3=0;
static u8 speed=6;
static u8 bytepos = 0, mousereplies = 0;
static u8 mpacket[3];
static s32 mousex = 40, mousey = 12;
static u16 oldx = 0, oldy = 0;
static u8 oldchar = 0x00, oldattr = 0x07;
static bool mousebut1 = 0, mousebut2 = 0, mousebut3 = 0;
static u8 speed = 6;
/******************************************************************************/
/* ecriture vers souris */
void outmseack(u8 value)
{
outkbd(0x64,0xD4); /* ecriture vers souris */
outb(0x60,value);
mousereplies++;
outkbd(0x64, 0xD4);
outb(0x60, value);
mousereplies++;
}
/* ecriture vers mode */
void outmsecmd(u8 command)
{
outkbd(0x64,0x60); /* ecriture vers mode */
outb(0x60,command);
outkbd(0x64, 0x60);
outb(0x60, command);
}
/******************************************************************************/
/* Handler d'interruption de la souris IRQ 12 */
void mouse()
{
u8 mbyte=inb(0x60);
s8 changex,changey;
cli();
cli();
pushf();
pushad();
u8 mbyte = inb(0x60);
s8 changex, changey;
if (mousereplies > 0)
{
if (mbyte == 0xFA)
{
mousereplies--;
goto endofint;
}
mousereplies = 0;
}
if (mousereplies > 0) {
if (mbyte == 0xFA) {
mousereplies--;
goto endofint;
}
mousereplies = 0;
}
mpacket[bytepos]=mbyte;
bytepos++;
mpacket[bytepos] = mbyte;
bytepos++;
if(bytepos==3) {
bytepos=0;
if ( mpacket[1] == 0)
{
changex = 0;
}
else
{
changex = (mpacket[0] & 0x10) ?
mpacket[1] - 256 :
mpacket[1];
}
if (mpacket[2] == 0)
{
changey = 0;
}
else
{
changey = -((mpacket[0] & 0x20) ?
mpacket[2] - 256 :
mpacket[2]);
}
if (bytepos == 3) {
bytepos = 0;
if (mpacket[1] == 0) {
changex = 0;
} else {
changex = (mpacket[0] & 0x10) ?
mpacket[1] - 256 : mpacket[1];
}
if (mpacket[2] == 0) {
changey = 0;
} else {
changey = -((mpacket[0] & 0x20) ?
mpacket[2] - 256 : mpacket[2]);
}
mousex+= (changex<<speed);
mousey+= (changey<<speed);
mousex += (changex << speed);
mousey += (changey << speed);
if(mousex<0) { mousex=0; }
if(mousex>=65535) { mousex=65535; }
if(mousey<0) { mousey=0; }
if(mousey>=65535) { mousey=65535; }
if (mousex < 0) {
mousex = 0;
}
if (mousex >= 65535) {
mousex = 65535;
}
if (mousey < 0) {
mousey = 0;
}
if (mousey >= 65535) {
mousey = 65535;
}
u16 newx=(u32)mousex*getxres()/65536;
u16 newy=(u32)mousey*getyres()/65536;
u16 newx = (u32) mousex * getxres() / 65536;
u16 newy = (u32) mousey * getyres() / 65536;
// Retrieve mouse button status from packet
mousebut1=mpacket[0] & 1;
mousebut2=mpacket[0] & 2;
mousebut3=mpacket[0] & 4;
// Retrieve mouse button status from packet
mousebut1 = mpacket[0] & 1;
mousebut2 = mpacket[0] & 2;
mousebut3 = mpacket[0] & 4;
// printf("RX:%d\tRY:%d\tX:%d\tY:%d\tB1:%d\tB2:%d\tB3:%d\t\r\n",changex,changey,mousex,mousey,mousebut1,mousebut2,mousebut3);
if ((newx!=oldx)||(newy!=oldy))
{
showchar(oldx,oldy,oldchar,oldattr);
oldx=newx;
oldy=newy;
oldchar=getchar(oldx,oldy);
oldattr=getattrib(oldx,oldy);
showchar(newx,newy,0xDB,0x0F);
}
}
endofint:
irqendmaster();
irqendslave();
sti();
//asm("movl 0x2C(%esp), %ebx;movl 0x30(%esp), %esi;movl 0x34(%esp), %edi;movl 0x38(%esp), %ebp;addl $0x3C, %esp;iret;");
asm(
"addl $0x18,%esp;\
if ((newx != oldx) || (newy != oldy)) {
showchar(oldx, oldy, oldchar, oldattr);
oldx = newx;
oldy = newy;
oldchar = getchar(oldx, oldy);
oldattr = getattrib(oldx, oldy);
showchar(newx, newy, 0xDB, 0x0F);
}
}
endofint:
irqendmaster();
irqendslave();
popad();
popf();
sti();
asm("addl $0x18,%esp;\
popl %bx;\
iret;");
iret();
}

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

View File

@ -1,27 +1,29 @@
#include "idt.h"
#include "interrupts.h"
#include "types.h"
#include "asm.h"
#include "memory.h"
#include "timer.h"
#include "vga.h"
static u8 curs[4] = { "-\\|/" };
static u8 curs[4]={"-\\|/"};
static u8 curspos = 0;
static u8 curspos=0;
/******************************************************************************/
/* Handler d'interruption de la souris IRQ 0 */
void timer()
{
cli();
pushf();
pushad();
showchar(0,0,curs[curspos],7);
curspos=(curspos+1)&0x3;
irqendmaster();
popad();
popf();
{
cli();
pushf();
pushad();
showchar(0, 0, curs[curspos], 7);
curspos = (curspos + 1) & 0x3;
irqendmaster();
popad();
popf();
sti();
asm("addl $0x0C, %esp;");
iret();
}
asm("addl $0x0C, %esp;");
iret();
}

View File

@ -1,46 +1,45 @@
#include <types.h>
char ctype[] =
{
char ctype[] = {
0x00,
/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT,
/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT,
CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL,
/* 16 */CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 16 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 24 */CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 24 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* ' ' */CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN,
/* ' ' */ CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '(' */CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '(' */ CT_PUN, CT_PUN, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '0' */CT_DIG, CT_DIG, CT_DIG, CT_DIG,
/* '0' */ CT_DIG, CT_DIG, CT_DIG, CT_DIG,
CT_DIG, CT_DIG, CT_DIG, CT_DIG,
/* '8' */CT_DIG, CT_DIG, CT_PUN, CT_PUN,
/* '8' */ CT_DIG, CT_DIG, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '@' */CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX,
/* '@' */ CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX,
CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP,
/* 'H' */CT_UP, CT_UP, CT_UP, CT_UP,
/* 'H' */ CT_UP, CT_UP, CT_UP, CT_UP,
CT_UP, CT_UP, CT_UP, CT_UP,
/* 'P' */CT_UP, CT_UP, CT_UP, CT_UP,
/* 'P' */ CT_UP, CT_UP, CT_UP, CT_UP,
CT_UP, CT_UP, CT_UP, CT_UP,
/* 'X' */CT_UP, CT_UP, CT_UP, CT_PUN,
/* 'X' */ CT_UP, CT_UP, CT_UP, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '`' */CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX,
/* '`' */ CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX,
CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW,
/* h' */CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* h' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW,
CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* 'p' */CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* 'p' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW,
CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* 'x' */CT_LOW, CT_LOW, CT_LOW, CT_PUN,
/* 'x' */ CT_LOW, CT_LOW, CT_LOW, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_CTL,
/* 128 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 144 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 160 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 176 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 192 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 208 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 224 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 240 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
/* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

660
lib/vga.c

File diff suppressed because it is too large Load Diff

View File

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

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

View File

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

View File

@ -1,6 +1,6 @@
#include "vga.h"
#include "video.h"
#include "idt.h"
#include "interrupts.h"
#include "timer.h"
#include "keyboard.h"
#include "mouse.h"
@ -11,80 +11,78 @@
#include "ansi.c"
static cpuinfo cpu;
static u8 noproc[]="\033[31mInconnu\033[0m\000";
static u8 okmsg[]="\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000";
static u8 key=0;
static u8 noproc[] = "\033[31mInconnu\033[0m\000";
static u8 warnmsg[] =
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
static u8 okmsg[] =
"\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000";
static u8 errormsg[] =
"\033[99C\033[8D\033[37m\033[1m[\033[31mERREUR\033[37m]\033[0m\000";
static u8 key = 0;
void ok()
{
print(okmsg);
return;
print(okmsg);
return;
}
int main(void) {
cli();
setvmode(0x02);
/* Efface l'ecran */
print("\033[2J\000");
printf(ansilogo);
print("\033[0mNoyau charge en memoire\000");
ok();
print("Initilisation de la table d'interruption\000");
initidt();
ok();
print("Initialisation du controleur d'interruption\000");
initpic();
sti();
ok();
print("Installation du handler timer\000");
setidt((u32)timer, 0x20, INTGATE, 32);
ok();
print("Activation de l'IRQ 0\000");
enableirq(0);
ok();
print("Installation du handler clavier\000");
setidt((u32)keyboard, 0x20, INTGATE, 33);
ok();
print("Activation de l'IRQ 1\000");
enableirq(1);
ok();
print("Installation du handler souris\000");
setidt((u32)mouse, 0x20, INTGATE, 100);
ok();
print("Initialisation du controleur souris :\000");
if (initmouse()==1)
print(" \033[1m\033[32mSouris Presente\033[0m\000");
else
print(" \033[1m\033[31mSouris non detecte\033[0m\000");
ok();
print("Activation de l'IRQ 2 (Controleur esclave)\000");
enableirq(2);
ok();
print("Activation de l'IRQ 12\000");
enableirq(12);
ok();
strcpy(&noproc,&cpu.detectedname);
getcpuinfos(&cpu);
printf("Processeur detecte\r Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux\t:%s\000",cpu.stepping,cpu.models,cpu.family,&cpu.detectedname,&cpu.techs);
ok();
while(1)
{
key=waitascii();
putchar(key);
}
void warning()
{
print(warnmsg);
return;
}
void error()
{
print(errormsg);
return;
}
int main(void)
{
cli();
setvmode(0x02);
/* Efface l'ecran */
print("\033[2J\000");
printf(ansilogo);
print("\033[37m\033[0m -Initilisation des interruptions\000");
initidt();
initpic();
sti();
ok();
print(" -Installation du handler timer (IRQ 0)\000");
setidt((u32) timer, 0x20, INTGATE, 32);
enableirq(0);
ok();
print(" -Installation du handler clavier (IRQ 1)\000");
setidt((u32) keyboard, 0x20, INTGATE, 33);
enableirq(1);
ok();
print(" -Installation du handler souris (IRQ12+Cascade IRQ2)\000");
setidt((u32) mouse, 0x20, INTGATE, 100);
enableirq(2);
enableirq(12);
if (initmouse() != 1)
warning();
else
ok();
strcpy(&noproc, &cpu.detectedname);
getcpuinfos(&cpu);
printf
(" -Detection du processeur\r\033[1m Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux d'instruction\t:%s\033[0m\000",
cpu.stepping, cpu.models, cpu.family, &cpu.detectedname,
&cpu.techs);
ok();
while (1) {
key = waitascii();
putchar(key);
}
}