feat: suppression de NASM en tant qu'assembleur et utilisateur de GAS, bascule des handlers sur un nouveau fichier et modification progressive des interruptions/exceptions

This commit is contained in:
Nicolas Hordé 2018-12-15 19:13:26 +01:00
parent ddfba60973
commit 3c3f0bb88e
25 changed files with 612 additions and 649 deletions

View File

@ -63,7 +63,6 @@ Compilation:
Nom | Paquet | Version Nom | Paquet | Version
--- | --- | --- --- | --- | ---
NASM | nasm | 2.11.08
gcc | gcc | 5.4.0 20160609 gcc | gcc | 5.4.0 20160609
GNU Make | make | 4.1 GNU Make | make | 4.1
Outils divers | binutils | 2.26-8 Outils divers | binutils | 2.26-8
@ -106,7 +105,7 @@ Puis cloner le source chez vous avec la commande :
Sous linux - Debian & Ubuntu like Sous linux - Debian & Ubuntu like
`sudo apt-get install nasm gcc qemu fusefat fuseext2 cgdb ovmf bsdmainutils tar bsdmainutils indent binutils` `sudo apt-get install gcc qemu fusefat fuseext2 cgdb ovmf bsdmainutils tar bsdmainutils indent binutils`
ou sinon, depuis un terminal disposé sur le répertoire cos2000 ou sinon, depuis un terminal disposé sur le répertoire cos2000

View File

@ -43,3 +43,4 @@ bool cansetflag(u32 flag);
void cpuid(u32 op, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx); void cpuid(u32 op, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx);
u8 getcpuinfos(cpuinfo * inf); u8 getcpuinfos(cpuinfo * inf);
void show_cpu(regs * stack); void show_cpu(regs * stack);
void cpuerror(const u8 * src, const regs * stack, bool returnto);

41
include/handlers.h Normal file
View File

@ -0,0 +1,41 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "types.h"
__attribute__((interrupt)) void interruption(exception_stack_noerror *caller);
void exception0();
void exception1();
void exception2();
void exception3();
void exception4();
void exception5();
void exception6();
void exception7();
void exception8();
void exception9();
void exception10();
void exception11();
void exception12();
void exception13();
void exception14();
void exception15();
void exception16();
void exception17();
void exception18();
__attribute__((interrupt)) void irq0(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq1(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq2(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq3(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq4(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq5(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq6(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq7(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq8(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq9(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq10(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq11(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq12(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq13(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq14(exception_stack_noerror *caller);
__attribute__((interrupt)) void irq15(exception_stack_noerror *caller);

View File

@ -339,5 +339,5 @@ void makeidtdes(u32 offset, u16 select, u16 type, idtdes * desc);
void initpic(void); void initpic(void);
void enableirq(u8 irq); void enableirq(u8 irq);
void disableirq(u8 irq); void disableirq(u8 irq);
void cpuerror(const u8 * src, const regs * stack); void cpuerror(const u8 * src, const regs * stack, bool returnto);
#endif #endif

View File

@ -1,6 +1,9 @@
/*******************************************************************************/ /*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "interrupts.h"
#define SCAN_CTRL 0x1D #define SCAN_CTRL 0x1D
#define SCAN_LEFTSHIFT 0x2A #define SCAN_LEFTSHIFT 0x2A
#define SCAN_RIGHTSHIFT 0x36 #define SCAN_RIGHTSHIFT 0x36
@ -31,7 +34,7 @@
#define STATUS_NUM 0x2000 #define STATUS_NUM 0x2000
#define STATUS_SCRL 0x4000 #define STATUS_SCRL 0x4000
void keyboard(void); __attribute__((interrupt)) void keyboard_handler(exception_stack_noerror *caller);
void reboot(void); void reboot(void);
void outkbd(u8 port, u8 data); void outkbd(u8 port, u8 data);
u8 waitascii(void); u8 waitascii(void);

View File

@ -1,7 +1,10 @@
/*******************************************************************************/ /*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "interrupts.h"
bool initmouse(void); bool initmouse(void);
void mouse(void); __attribute__((interrupt)) void mouse_handler(exception_stack_noerror *caller);
void outmseack(u8 value); void outmseack(u8 value);
void outmsecmd(u8 command); void outmsecmd(u8 command);

13
include/multiboot.h Normal file
View File

@ -0,0 +1,13 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "types.h"
#include "multiboot2.h"
u32 getgrubinfo(u8 type);
u8 *getgrubinfo_cmdline(void);
u32 getgrubinfo_ram(void);
struct multiboot_tag_mmap *getgrubinfo_mem(void);
struct multiboot_tag_framebuffer *getgrubinfo_fb(void);
void getgrubinfo_all(void);
void initmultiboot(const u32 addr);

View File

@ -1,8 +1,6 @@
/*******************************************************************************/ /*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "types.h"
#ifndef MULTIBOOT #ifndef MULTIBOOT
# define MULTIBOOT # define MULTIBOOT
@ -71,6 +69,7 @@
# define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 # define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
# define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 # define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
#include "types.h"
struct multiboot_header struct multiboot_header
{ {
/* Must be MULTIBOOT_MAGIC - see above. */ /* Must be MULTIBOOT_MAGIC - see above. */
@ -389,12 +388,4 @@ struct multiboot_tag_load_base_addr
u32 load_base_addr; u32 load_base_addr;
}; };
u32 getgrubinfo(u8 type);
u8 *getgrubinfo_cmdline(void);
u32 getgrubinfo_ram(void);
struct multiboot_tag_mmap *getgrubinfo_mem(void);
struct multiboot_tag_framebuffer *getgrubinfo_fb(void);
void getgrubinfo_all(void);
void initmultiboot(const u32 addr);
#endif #endif

View File

@ -47,4 +47,4 @@
/* Vers 6 arguments maximum */ /* Vers 6 arguments maximum */
void initsyscall(void); void initsyscall(void);
void sysenter_handler(void); __attribute__ ((noreturn)) void sysenter_handler(void);

View File

@ -33,6 +33,25 @@ static u8 *msg[] = {
static u8 space[] = " "; static u8 space[] = " ";
/******************************************************************************/
/* Affiche une erreur CPU et fige l'ordinateur */
void cpuerror(const u8 * src, const regs * stack, bool returnto)
{
printf("\033[31m*** ERREUR CPU : %s *** \r\n", src);
if (stack != NULL)
show_cpu(stack);
print("<Appuyer une touche pour continuer>\033[0m\r\n");
sti();
waitascii();
if (!returnto)
{
print("Retour en force au SHELL\r\n");
initselectors(getinitretry());
}
}
/******************************************************************************/ /******************************************************************************/
/* Annule les FLAGs CPU */ /* Annule les FLAGs CPU */

376
lib/handlers.c Normal file
View File

@ -0,0 +1,376 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "interrupts.h"
#include "types.h"
#include "asm.h"
#include "memory.h"
#include "video.h"
#include "gdt.h"
#include "system.h"
#include "debug.h"
#include "process.h"
/******************************************************************************/
/* Déclenché lors de l'appel d'une interruption */
__attribute__((interrupt)) void interruption(exception_stack_noerror *caller)
{
print("Appel d'une interruption\r\n");
}
/******************************************************************************/
/* Les expections */
void exception0()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DE Divide error", dump, false);
}
void exception1()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
changevc(6);
clearscreen();
show_lightcpu(dump);
printf("\r\n\033[7m[P]\033[0m PAS A PAS \033[7m D \033[0m PAS A PAS DETAILLE \033[7m C \033[0m CONTINUER \033[7m S \033[0m STOPPER \033[7m V \033[0m VOIR \033[7m S \033[0m SCINDER");
sti();
u8 ascii = waitascii();
cli();
if (ascii == 'P' || ascii == 'p')
setdebugreg(0,
caller->eip + disasm(caller->eip, NULL, false),
DBG_EXEC);
else if (ascii == 'D' || ascii == 'd')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'C' || ascii == 'c')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'S' || ascii == 's')
{
changevc(0);
sti();
initselectors(getinitretry());
}
changevc(0);
restdebugcpu();
iret();
}
void exception2()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("NMI Non-maskable hardware interrupt", dump, false);
}
void exception3()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BP INT3 instruction", dump, true);
iret();
}
void exception4()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#OF INTO instruction detected overflow", dump, false);
}
void exception5()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BR BOUND instruction detected overrange", dump, false);
}
void exception6()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#UD Invalid instruction opcode", dump, false);
}
void exception7()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NM No coprocessor", dump, false);
}
void exception8()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DF Double fault", dump, false);
}
void exception9()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("Coprocessor segment overrun", dump, false);
}
void exception10()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#TS Invalid task state segment (TSS)", dump, false);
}
void exception11()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NP Segment not present", dump, false);
}
void exception12()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#SS Stack fault", dump, false);
}
void exception13()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu(dump, caller, oldesp);
cpuerror("#GP General protection fault (GPF)", dump, false);
}
static u8 ex14_errors1[] =
"Supervisory process tried to read a non-present page entry";
static u8 ex14_errors2[] =
"Supervisory process tried to read a page and caused a protection fault";
static u8 ex14_errors3[] =
"Supervisory process tried to write to a non-present page entry";
static u8 ex14_errors4[] =
"Supervisory process tried to write a page and caused a protection fault";
static u8 ex14_errors5[] =
"User process tried to read a non-present page entry";
static u8 ex14_errors6[] =
"User process tried to read a page and caused a protection fault";
static u8 ex14_errors7[] =
"User process tried to write to a non-present page entry";
static u8 ex14_errors8[] =
"User process tried to write a page and caused a protection fault";
static u8 *ex14_errors[] =
{ &ex14_errors1, &ex14_errors2, &ex14_errors3, &ex14_errors4,
&ex14_errors5, &ex14_errors6, &ex14_errors7, &ex14_errors8
};
void exception14()
{
regs *dump;
exception_stack *caller;
u32 *oldesp;
getEBP(oldesp);
dumpcpu();
getESP(dump);
dump->ebp = *oldesp;
dump->eip = caller->eip;
dump->cs = caller->cs;
if (caller->cs == SEL_KERNEL_CODE)
dump->esp = (u32) oldesp + sizeof(exception_stack);
else
{
dump->esp = (u32) ((exception_stack_user *) caller)->esp;
dump->ss = (u32) ((exception_stack_user *) caller)->ss;
}
if (dump->cr2 >= USER_CODE && dump->cr2 < USER_STACK)
{
virtual_range_new(getcurrentprocess()->pdd,
(u8 *) (dump->cr2 & 0xFFFFF000),
PAGESIZE, PAGE_ALL);
}
else
{
printf("Page fault - %s at adress %Y cs:eip - %Y:%Y\r\n",
ex14_errors[caller->error_code & 0xF], dump->cr2,
dump->cs, dump->eip);
cpuerror("#PGF Page fault", dump, false);
}
restdebugcpu();
iret();
}
void exception15()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("(reserved)", dump, false);
}
void exception16()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#MF Coprocessor error", dump, false);
}
void exception17()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#AC Alignment check", dump, false);
}
void exception18()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#MC Machine check", dump, false);
}
/******************************************************************************/
/* Les IRQ par défaut */
__attribute__((interrupt)) void irq0(exception_stack_noerror *caller)
{ print("irq 0");
irqendmaster();
}
__attribute__((interrupt)) void irq1(exception_stack_noerror *caller)
{
print("irq 1");
while ((inb(0x64) & 1) == 0);
inb(0x60);
irqendmaster();
}
__attribute__((interrupt)) void irq2(exception_stack_noerror *caller)
{ print("irq 2");
irqendmaster();
}
__attribute__((interrupt)) void irq3(exception_stack_noerror *caller)
{
print("irq 3");
irqendmaster();
}
__attribute__((interrupt)) void irq4(exception_stack_noerror *caller)
{
print("irq 4");
irqendmaster();
}
__attribute__((interrupt)) void irq5(exception_stack_noerror *caller)
{
print("irq 5");
irqendmaster();
}
__attribute__((interrupt)) void irq6(exception_stack_noerror *caller)
{
print("irq 6");
irqendmaster();
}
__attribute__((interrupt)) void irq7(exception_stack_noerror *caller)
{
print("irq 7");
irqendmaster();
}
__attribute__((interrupt)) void irq8(exception_stack_noerror *caller)
{
print("irq 8");
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq9(exception_stack_noerror *caller)
{
print("irq 9");
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq10(exception_stack_noerror *caller)
{
print("irq 10");
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq11(exception_stack_noerror *caller)
{
print("irq 11");
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq12(exception_stack_noerror *caller)
{
print("irq 12");
while ((inb(0x64) & 1) == 0);
inb(0x60);
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq13(exception_stack_noerror *caller)
{
print("irq 13");
irqendslave();
irqendmaster();
popad();
popf();
}
__attribute__((interrupt)) void irq14(exception_stack_noerror *caller)
{
print("irq 14");
irqendslave();
irqendmaster();
}
__attribute__((interrupt)) void irq15(exception_stack_noerror *caller)
{
print("irq 15");
irqendslave();
irqendmaster();
}

View File

@ -10,6 +10,7 @@
#include "system.h" #include "system.h"
#include "debug.h" #include "debug.h"
#include "process.h" #include "process.h"
#include "handlers.h"
#define IDT_SIZE 256 /* nombre de descripteurs */ #define IDT_SIZE 256 /* nombre de descripteurs */
@ -142,519 +143,6 @@ void putidt(u32 offset, u16 select, u16 type, u16 index)
idt[index] = temp; idt[index] = temp;
} }
/******************************************************************************/
/* Affiche une erreur CPU et fige l'ordinateur */
void cpuerror(const u8 * src, const regs * stack)
{
printf("\033[31m*** ERREUR CPU : %s *** \r\n", src);
if (stack != NULL)
show_cpu(stack);
print("<Appuyer une touche pour continuer>\033[0m\r\n");
sti();
waitascii();
initselectors(retry_address);
/*while (true) {
nop();
} */
}
/******************************************************************************/
/* Déclenché lors de l'appel d'une interruption */
void interruption()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
print("Appel d'une interruption\r\n");
restdebugcpu();
iret();
}
/******************************************************************************/
/* Les expections */
void exception0()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DE Divide error", dump);
}
void exception1()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
changevc(6);
clearscreen();
show_lightcpu(dump);
printf("\r\n\033[7m[P]\033[0m PAS A PAS \033[7m D \033[0m PAS A PAS DETAILLE \033[7m C \033[0m CONTINUER \033[7m S \033[0m STOPPER \033[7m V \033[0m VOIR \033[7m S \033[0m SCINDER");
sti();
u8 ascii = waitascii();
cli();
if (ascii == 'P' || ascii == 'p')
setdebugreg(0,
caller->eip + disasm(caller->eip, NULL, false),
DBG_EXEC);
else if (ascii == 'D' || ascii == 'd')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'C' || ascii == 'c')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'S' || ascii == 's')
{
changevc(0);
sti();
initselectors(retry_address);
}
changevc(0);
restdebugcpu();
iret();
}
void exception2()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("NMI Non-maskable hardware interrupt", dump);
}
void exception3()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BP INT3 instruction", dump);
}
void exception4()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#OF INTO instruction detected overflow", dump);
}
void exception5()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BR BOUND instruction detected overrange", dump);
}
void exception6()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#UD Invalid instruction opcode", dump);
}
void exception7()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NM No coprocessor", dump);
}
void exception8()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DF Double fault", dump);
}
void exception9()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("Coprocessor segment overrun", dump);
}
void exception10()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#TS Invalid task state segment (TSS)", dump);
}
void exception11()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NP Segment not present", dump);
}
void exception12()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#SS Stack fault", dump);
}
void exception13()
{
regs *dump;
exception_stack *caller;
u32 *oldesp;
savecpu(dump, caller, oldesp);
cpuerror("#GP General protection fault (GPF)", dump);
}
static u8 ex14_errors1[] =
"Supervisory process tried to read a non-present page entry";
static u8 ex14_errors2[] =
"Supervisory process tried to read a page and caused a protection fault";
static u8 ex14_errors3[] =
"Supervisory process tried to write to a non-present page entry";
static u8 ex14_errors4[] =
"Supervisory process tried to write a page and caused a protection fault";
static u8 ex14_errors5[] =
"User process tried to read a non-present page entry";
static u8 ex14_errors6[] =
"User process tried to read a page and caused a protection fault";
static u8 ex14_errors7[] =
"User process tried to write to a non-present page entry";
static u8 ex14_errors8[] =
"User process tried to write a page and caused a protection fault";
static u8 *ex14_errors[] =
{ &ex14_errors1, &ex14_errors2, &ex14_errors3, &ex14_errors4,
&ex14_errors5, &ex14_errors6, &ex14_errors7, &ex14_errors8
};
void exception14()
{
regs *dump;
exception_stack *caller;
u32 *oldesp;
getEBP(oldesp);
dumpcpu();
getESP(dump);
caller = (exception_stack *) (oldesp + 1);
dump->ebp = *oldesp;
dump->eip = caller->eip;
dump->cs = caller->cs;
if (caller->cs == SEL_KERNEL_CODE)
dump->esp = (u32) oldesp + sizeof(exception_stack);
else
{
dump->esp = (u32) ((exception_stack_user *) caller)->esp;
dump->ss = (u32) ((exception_stack_user *) caller)->ss;
}
if (dump->cr2 >= USER_CODE && dump->cr2 < USER_STACK)
{
virtual_range_new(getcurrentprocess()->pdd,
(u8 *) (dump->cr2 & 0xFFFFF000),
PAGESIZE, PAGE_ALL);
}
else
{
printf("Page fault - %s at adress %Y cs:eip - %Y:%Y\r\n",
ex14_errors[caller->error_code & 0xF], dump->cr2,
dump->cs, dump->eip);
cpuerror("#PGF Page fault", dump);
}
restdebugcpu();
iret();
}
void exception15()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("(reserved)", dump);
}
void exception16()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#MF Coprocessor error", dump);
}
void exception17()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#AC Alignment check", dump);
}
void exception18()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#MC Machine check", dump);
}
/******************************************************************************/
/* Les IRQ par défaut */
void irq0()
{
cli();
pushf();
pushad();
print("irq 0");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq1()
{
cli();
pushf();
pushad();
print("irq 1");
while ((inb(0x64) & 1) == 0);
inb(0x60);
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq2()
{
cli();
pushf();
pushad();
print("irq 2");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq3()
{
cli();
pushf();
pushad();
print("irq 3");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq4()
{
cli();
pushf();
pushad();
print("irq 4");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq5()
{
cli();
pushf();
pushad();
print("irq 5");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq6()
{
cli();
pushf();
pushad();
print("irq 6");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq7()
{
cli();
pushf();
pushad();
print("irq 7");
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq8()
{
cli();
pushf();
pushad();
print("irq 8");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq9()
{
cli();
pushf();
pushad();
print("irq 9");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq10()
{
cli();
pushf();
pushad();
print("irq 10");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq11()
{
cli();
pushf();
pushad();
print("irq 11");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq12()
{
cli();
pushf();
pushad();
print("irq 12");
while ((inb(0x64) & 1) == 0);
inb(0x60);
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq13()
{
cli();
pushf();
pushad();
print("irq 13");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq14()
{
cli();
pushf();
pushad();
print("irq 14");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
void irq15()
{
cli();
print("irq 15");
irqendslave();
irqendmaster();
popad();
popf();
sti();
leave();
iret();
}
/******************************************************************************/ /******************************************************************************/
/* Initialise une IDT */ /* Initialise une IDT */

View File

@ -361,11 +361,8 @@ unsigned convert(u32 keypressed)
/******************************************************************************/ /******************************************************************************/
/* Handler d'interruption IRQ 1 pour le clavier */ /* Handler d'interruption IRQ 1 pour le clavier */
void keyboard(void) __attribute__((interrupt)) void keyboard_handler(exception_stack_noerror *caller)
{ {
cli();
pushf();
pushad();
u8 scancode, ascii; u8 scancode, ascii;
cli(); cli();
while ((inb(0x64) & 1) == 0); while ((inb(0x64) & 1) == 0);
@ -379,11 +376,6 @@ void keyboard(void)
bufferascii[ptrascii] = ascii; bufferascii[ptrascii] = ascii;
} }
irqendmaster(); irqendmaster();
popad();
popf();
sti();
leave();
iret();
} }
/******************************************************************************/ /******************************************************************************/

View File

@ -1,4 +1,4 @@
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf_i386 -fno-pie -no-pie -I ../include CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf_i386 -fno-pie -no-pie -I ../include -c
LINK=ld -m elf_i386 -r -o LINK=ld -m elf_i386 -r -o
SRCS= $(wildcard *.c) SRCS= $(wildcard *.c)
OBJS= $(SRCS:.c=.o) OBJS= $(SRCS:.c=.o)
@ -15,6 +15,17 @@ togit: clean indent
libs.o:$(OBJS) libs.o:$(OBJS)
$(LINK) libs.o $(OBJS) $(LINK) libs.o $(OBJS)
handlers.o:handlers.c
$(CC) -mgeneral-regs-only $^
keyboard.o:keyboard.c
$(CC) -mgeneral-regs-only $^
mouse.o:mouse.c
$(CC) -mgeneral-regs-only $^
syscall.o:syscall.c
$(CC) -fomit-frame-pointer $^
.o: .c .o: .c
$(CC) $^ $(CC) $^

View File

@ -64,11 +64,8 @@ void outmsecmd(u8 command)
/******************************************************************************/ /******************************************************************************/
/* Handler d'interruption de la souris IRQ 12 */ /* Handler d'interruption de la souris IRQ 12 */
void mouse(void) __attribute__((interrupt)) void mouse_handler(exception_stack_noerror *caller)
{ {
cli();
pushf();
pushad();
u8 mbyte = inb(0x60); u8 mbyte = inb(0x60);
s8 changex, changey; s8 changex, changey;
@ -145,11 +142,6 @@ void mouse(void)
endofint: endofint:
irqendmaster(); irqendmaster();
irqendslave(); irqendslave();
popad();
popf();
sti();
leave();
iret();
} }
/*******************************************************************************/ /*******************************************************************************/

View File

@ -15,9 +15,19 @@
* %eax System call number. * %eax System call number.
* %ebx Arg1 * %ebx Arg1
* %esi Arg2 * %esi Arg2
* %edi Arg3 * %edi Arg3*/
/*******************************************************************************/
/*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */
void initsyscall(void)
{
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler, 0x0);
}
/*******************************************************************************/
/* Fonction permettant de tester le fonctionnement de SYSENTER */ /* Fonction permettant de tester le fonctionnement de SYSENTER */
/* SYSCALL /* SYSCALL
{ {
@ -43,26 +53,16 @@ u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump)
} }
/*******************************************************************************/ /*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */
void initsyscall(void)
{
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler + 6, 0x0);
}
/*******************************************************************************/
/* Entrée pour les appels système SYSENTER */ /* Entrée pour les appels système SYSENTER */
void sysenter_handler(void) __attribute__ ((noreturn)) void sysenter_handler(void)
{ {
cli(); cli();
regs *dump; regs *dump;
dumpcpu(); dumpcpu();
getESP(dump); getESP(dump);
dump->cs=SEL_USER_CODE;
dump->eip=dump->edx;
sti(); sti();
switch (dump->eax) switch (dump->eax)
{ {
@ -83,7 +83,7 @@ void sysenter_handler(void)
break; break;
default: default:
printf("Appel syscall vers fonction inexistante en %Y:%Y\r\n", dump->cs, dump->eip); printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip);
break; break;
} }
restdebugcpu(); restdebugcpu();
@ -92,4 +92,3 @@ void sysenter_handler(void)
/*******************************************************************************/ /*******************************************************************************/

View File

@ -22,7 +22,7 @@ harddisk: final/harddisk.img.final
uefi: final/harddiskuefi.img.final uefi: final/harddiskuefi.img.final
install: install:
(sudo apt-get install nasm gcc qemu fusefat fuseext2 cgdb ovmf bsdmainutils tar bsdmainutils indent binutils bochs bochs-x bochsbios dos2unix) (sudo apt-get install gcc qemu fusefat fuseext2 cgdb ovmf bsdmainutils tar bsdmainutils indent binutils bochs bochs-x bochsbios dos2unix)
togit: togit:
make -C system togit make -C system togit

View File

@ -146,9 +146,13 @@ for lib in alllibs:
if numargs>0: if numargs>0:
textargs=textargs+"," textargs=textargs+","
textargs=textargs+"(u32) "+syscall['ARGS'][i]['NAME'] textargs=textargs+"(u32) "+syscall['ARGS'][i]['NAME']
if syscall['RETURN']!='void':
textargs="return "+textargs+");"
else:
textargs=textargs+");\n return;"
text=text+getfunction(syscall)+""" text=text+getfunction(syscall)+"""
{ {
"""+textargs+"""); """+textargs+"""
} }
""" """

View File

@ -8,22 +8,23 @@
u32 getticks(void) u32 getticks(void)
{ {
syscall0(4); return syscall0(4);
} }
void exit(u32 resultcode) void exit(u32 resultcode)
{ {
syscall1(5,(u32) resultcode); syscall1(5,(u32) resultcode);
return;
} }
u8 waitkey(void) u8 waitkey(void)
{ {
syscall0(1); return syscall0(1);
} }
u32 testapi(u32 arg1, u32 arg2, u32 arg3) u32 testapi(u32 arg1, u32 arg2, u32 arg3)
{ {
syscall3(0,(u32) arg1,(u32) arg2,(u32) arg3); return syscall3(0,(u32) arg1,(u32) arg2,(u32) arg3);
} }

View File

@ -8,7 +8,7 @@
u32 print(u8* string) u32 print(u8* string)
{ {
syscall1(2,(u32) string); return syscall1(2,(u32) string);
} }

View File

@ -1,5 +1,5 @@
GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -I ../include -m32 -fno-pie -no-pie -c -o GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -I ../include -m32 -fno-pie -no-pie -c -o
ASM=nasm -f elf -o ASM=gcc -nostdinc -ffreestanding -fno-builtin -m32 -c -fno-pie -no-pie
LINK=ld -m elf_i386 -T linker.lds -n -o LINK=ld -m elf_i386 -T linker.lds -n -o
CONVERT=dos2unix CONVERT=dos2unix
INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl
@ -18,7 +18,7 @@ system.o:
$(GCC) system.o system.c $(GCC) system.o system.c
multiboot.o: multiboot.o:
$(ASM) multiboot.o multiboot.asm -dVESA=$(VESA) $(ASM) multiboot.S -DVESA=$(VESA)
clean: clean:
$(REMOVE) *.o $(REMOVE) *.o

88
system/multiboot.S Normal file
View File

@ -0,0 +1,88 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#define MULTIBOOT_SEARCH 32768
#define MULTIBOOT_HEADER_ALIGN 8
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
#define MULTIBOOT_MOD_ALIGN 0x00001000
#define MULTIBOOT_INFO_ALIGN 0x00000008
#define MULTIBOOT_TAG_ALIGN 8
#define MULTIBOOT_TAG_TYPE_END 0
#define MULTIBOOT_TAG_TYPE_CMDLINE 1
#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2
#define MULTIBOOT_TAG_TYPE_MODULE 3
#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
#define MULTIBOOT_TAG_TYPE_BOOTDEV 5
#define MULTIBOOT_TAG_TYPE_MMAP 6
#define MULTIBOOT_TAG_TYPE_VBE 7
#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9
#define MULTIBOOT_TAG_TYPE_APM 10
#define MULTIBOOT_TAG_TYPE_EFI32 11
#define MULTIBOOT_TAG_TYPE_EFI64 12
#define MULTIBOOT_TAG_TYPE_SMBIOS 13
#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14
#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15
#define MULTIBOOT_TAG_TYPE_NETWORK 16
#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21
#define MULTIBOOT_HEADER_TAG_END 0
#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
#define MULTIBOOT_HEADER_TAG_ADDRESS 2
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3
#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
#define MULTIBOOT_HEADER_TAG_EFI_BS 7
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32 8
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10
#define MULTIBOOT_ARCHITECTURE_I386 0
#define MULTIBOOT_ARCHITECTURE_MIPS32 4
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
.section .multiboot, "a"
.align MULTIBOOT_HEADER_ALIGN
multiboot_header:
.long MULTIBOOT2_HEADER_MAGIC
.long MULTIBOOT_ARCHITECTURE_I386
.long multiboot_header_end - multiboot_header
.long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
#ifdef VESA
#warning VESA active
framebuffer_tag_start:
.align MULTIBOOT_HEADER_ALIGN
.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
.short MULTIBOOT_HEADER_TAG_OPTIONAL
.long framebuffer_tag_end - framebuffer_tag_start
.long 1024
.long 768
.long 32
framebuffer_tag_end:
#endif
.align MULTIBOOT_HEADER_ALIGN
.short MULTIBOOT_HEADER_TAG_END
.short 0
.long 8
multiboot_header_end:
.section .text
.globl start
start:
pushl %ebx
pushl %eax
call main
hlt

View File

@ -1,58 +0,0 @@
;/*******************************************************************************/
;/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
;/* */
[BITS 32]
SECTION .multiboot
%define MULTIBOOT_TAG_ALIGN 8
%define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
%define MULTIBOOT_ARCHITECTURE_I386 0
%define MULTIBOOT_HEADER_TAG_OPTIONAL 1
%define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
%define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
%define MULTIBOOT_HEADER_TAG_END 0
%define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
%defstr vesa VESA
multiboot_header:
align MULTIBOOT_TAG_ALIGN
dd MULTIBOOT2_HEADER_MAGIC ; magic
dd MULTIBOOT_ARCHITECTURE_I386 ; architecture
dd multiboot_header_end - multiboot_header
dd -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
align MULTIBOOT_TAG_ALIGN
%if vesa = "no"
%warning "Avec la console VGA/EGA."
%else
framebuffer_tag_start:
%warning "Avec le FRAMEBUFFER VESA."
dw MULTIBOOT_HEADER_TAG_FRAMEBUFFER ; type
dw MULTIBOOT_HEADER_TAG_OPTIONAL ; flags
dd framebuffer_tag_end - framebuffer_tag_start
dd 1024 ; width
dd 768 ; height
dd 32 ; depth
align MULTIBOOT_TAG_ALIGN
framebuffer_tag_end:
%endif
dw MULTIBOOT_HEADER_TAG_END
dw 0
dd 8
multiboot_header_end:
SECTION .text
global start
extern main
start:
push ebx
push eax
call main
hlt

View File

@ -85,13 +85,13 @@ int main(u32 magic, u32 addr)
ok(); ok();
print(" -Installation du pilote clavier (IRQ 1)"); print(" -Installation du pilote clavier (IRQ 1)");
setidt((u32) keyboard, SEL_KERNEL_CODE, setidt((u32) keyboard_handler, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 33); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 33);
enableirq(1); enableirq(1);
ok(); ok();
print(" -Installation du pilote souris (IRQ12+IRQ2)"); print(" -Installation du pilote souris (IRQ12+IRQ2)");
setidt((u32) mouse, SEL_KERNEL_CODE, setidt((u32) mouse_handler, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 100); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 100);
enableirq(2); enableirq(2);
enableirq(12); enableirq(12);

View File

@ -15,9 +15,20 @@
* %eax System call number. * %eax System call number.
* %ebx Arg1 * %ebx Arg1
* %esi Arg2 * %esi Arg2
* %edi Arg3 * %edi Arg3*/
/*******************************************************************************/
/*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */
void initsyscall(void)
{
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler, 0x0);
return;
}
/*******************************************************************************/
/* Fonction permettant de tester le fonctionnement de SYSENTER */ /* Fonction permettant de tester le fonctionnement de SYSENTER */
/* SYSCALL /* SYSCALL
{ {
@ -43,26 +54,16 @@ u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump)
} }
/*******************************************************************************/ /*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */
void initsyscall(void)
{
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler + 6, 0x0);
}
/*******************************************************************************/
/* Entrée pour les appels système SYSENTER */ /* Entrée pour les appels système SYSENTER */
void sysenter_handler(void) __attribute__ ((noreturn)) void sysenter_handler(void)
{ {
cli(); cli();
regs *dump; regs *dump;
dumpcpu(); dumpcpu();
getESP(dump); getESP(dump);
dump->cs=SEL_USER_CODE;
dump->eip=dump->edx;
sti(); sti();
switch (dump->eax) switch (dump->eax)
{ {
@ -77,4 +78,3 @@ void sysenter_handler(void)
/*******************************************************************************/ /*******************************************************************************/