feat: dumpcpu inline & test concluant err 1

This commit is contained in:
Nicolas Hordé 2018-10-10 08:06:39 +02:00
parent 109738dca3
commit 5683c69311
7 changed files with 232 additions and 225 deletions

View File

@ -19,6 +19,90 @@
#define popf() asm("popf"::)
#define getESP() ({ \
u32 _v; \
asm volatile ("movl %%esp,%%eax;": "=a" (_v)); \
_v; \
})
u32 ss;
u32 gs;
u32 fs;
u32 es;
u32 ds;
u32 eip;
u32 cs;
#define dumpcpu() asm("\
mov $0x6666666, %%eax \n \
mov $0x8888888, %%ebx \n \
pushal \n \
pushf \n \
pushl %%cs\n \
pushl $0x0\n \
pushl %%ds\n \
pushl %%es\n \
pushl %%fs\n \
pushl %%gs\n \
pushl %%ss\n \
pushl $0x0\n \
mov %%cr0, %%eax \n \
pushl %%eax\n \
mov %%cr2, %%eax \n \
pushl %%eax\n \
mov %%cr3, %%eax \n \
pushl %%eax\n \
mov %%cr4, %%eax \n \
pushl %%eax \n \
mov %%dr0, %%eax \n \
pushl %%eax\n \
mov %%dr1, %%eax \n \
pushl %%eax\n \
mov %%dr2, %%eax \n \
pushl %%eax\n \
mov %%dr3, %%eax \n \
pushl %%eax\n \
mov %%dr4, %%eax \n \
pushl %%eax\n \
mov %%dr5, %%eax \n \
pushl %%eax\n \
mov %%dr6, %%eax \n \
pushl %%eax\n \
mov %%dr7, %%eax \n \
pushl %%eax\n \
mov $0xC0000080, %%ecx \n \
rdmsr \n \
pushl %%edx \n \
pushl %%eax":::)
#define restcpu() asm("\
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%eax \n \
popl %%ss\n \
popl %%gs\n \
popl %%fs\n \
popl %%es\n \
popl %%ds\n \
popl %%eax \n \
popl %%eax \n \
popf \n \
popal":::)
#define iret() asm("iret"::)
#define irqendmaster() asm("movb $0x20,%al; \

View File

@ -42,7 +42,4 @@ bool apic2;
bool cansetflag (u32 flag);
void cpuid(u32 op, u32 *eax, u32 *ebx,u32 *ecx, u32 *edx);
u8 getcpuinfos(cpuinfo *inf);
u32 getESP(void);
u32 setESP(u32 stack);
void dump_cpu(save_stack *stack);
void show_cpu(save_stack *stack);

View File

@ -61,7 +61,7 @@ typedef struct save_stack {
u32 cr3;
u32 cr2;
u32 cr0;
u32 eflags;
u32 oldesp;
u32 ss;
u32 gs;
u32 fs;
@ -69,13 +69,14 @@ typedef struct save_stack {
u32 ds;
u32 eip;
u32 cs;
u32 esp;
u32 ebp;
u32 eflags;
u32 edi;
u32 esi;
u32 ebp;
u32 esp;
u32 ebx;
u32 edx;
u32 ecx;
u32 ebx;
u32 eax;
} save_stack __attribute__ ((packed));
/* exception pile */

View File

@ -126,83 +126,6 @@ u8 getcpuinfos(cpuinfo * proc)
return 0;
}
/******************************************************************************/
/* Retourne la tête de pile */
u32 getESP(void)
{
u32 stack = 0;
asm("movl %%esp,%[result];": [result] "=r"(stack));
return stack;
}
/******************************************************************************/
/* Fixe la tête de pile */
u32 setESP(u32 stack)
{
asm("movl %[param],%%esp;": [param] "=r"(stack));
}
/******************************************************************************/
/* Sauvegarde les registres CPU */
void dump_cpu(save_stack *stack)
{
asm(" movl %%eax,%%ebx":::);
asm(" addl %[size],%%esp \n \
addl $0x8,%%esp \n \
pushl %%eax \n \
pushl %%ebx \n \
pushl %%ecx \n \
pushl %%edx \n \
pushl %%esi \n \
pushl %%edi \n \
pushl %%ebp \n \
pushl %%esp \n \
pushl %%cs \n \
pushl $0x0 \n \
pushl %%ds \n \
pushl %%es \n \
pushl %%fs \n \
pushl %%gs \n \
pushl %%ss \n \
pushf \n \
mov %%eax,%%ebx \n \
mov %%cr0, %%eax \n \
pushl %%eax\n \
mov %%cr2, %%eax \n \
pushl %%eax\n \
mov %%cr3, %%eax \n \
pushl %%eax\n \
mov %%cr4, %%eax \n \
pushl %%eax \n \
mov %%dr0, %%eax \n \
pushl %%eax\n \
mov %%dr1, %%eax \n \
pushl %%eax\n \
mov %%dr2, %%eax \n \
pushl %%eax\n \
mov %%dr3, %%eax \n \
pushl %%eax\n \
mov %%dr4, %%eax \n \
pushl %%eax\n \
mov %%dr5, %%eax \n \
pushl %%eax\n \
mov %%dr6, %%eax \n \
pushl %%eax\n \
mov %%dr7, %%eax \n \
pushl %%eax\n \
mov $0xC0000080, %%ecx \n \
rdmsr \n \
pushl %%edx \n \
pushl %%eax \n \
subl $0x8,%%esp \n \
mov %%ebx,%%eax"::[size] "a" (sizeof(save_stack)):);
save_stack new;
memcpy(&new, stack, sizeof(save_stack), 1);
}
/******************************************************************************/
/* Affiche les registres CPU */
@ -210,7 +133,7 @@ void show_lightcpu(save_stack *stack)
{
u32 i;
printf("\33[0mEAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->esp, stack->ebp);
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->oldesp, stack->ebp);
printf("EIP=%Y EFL=%Y [%c%c%c%c%c%c%c%c%c]\r\n", stack->eip, stack->eflags,
(stack->eflags & (1 <<11)) ? 'O':'-',
(stack->eflags & (1 <<10)) ? 'D':'-',
@ -252,12 +175,12 @@ void show_lightcpu(save_stack *stack)
}
printf("\33[0m\r\n\r\n\r\nSTACK\r\n");
if (abs(KERNEL_STACK_ADDR-stack->esp)>0x10000)
if (abs(KERNEL_STACK_ADDR-stack->oldesp)>0x10000)
printf("Pile invalide !");
else
{
i=0;
for (u32 *pointer = stack->esp; pointer < KERNEL_STACK_ADDR; pointer ++) {
for (u32 *pointer = stack->oldesp; pointer < KERNEL_STACK_ADDR; pointer ++) {
if (i>0 && i % 10 == 0) print("\033[10A");
if (i>=10)
print("\033[25C");
@ -274,7 +197,7 @@ void show_lightcpu(save_stack *stack)
void show_cpu(save_stack *stack)
{
printf("EAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->esp, stack->ebp);
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->oldesp, stack->ebp);
printf("EIP=%Y EFL=%Y [%c%c%c%c%c%c%c%c%c]\r\n", stack->eip, stack->eflags,
(stack->eflags & (1 <<11)) ? 'O':'-',
(stack->eflags & (1 <<10)) ? 'D':'-',
@ -305,12 +228,12 @@ void show_cpu(save_stack *stack)
printf("DR4=%Y DR5=%Y DR6=%Y DR7=%Y\r\n",stack->dr4,stack->dr5,stack->dr6,stack->dr7);
printf("EFER=%lY\r\n",stack->efer);
printf("STACK\r\n");
if (abs(KERNEL_STACK_ADDR-stack->esp)>0x10000)
if (abs(KERNEL_STACK_ADDR-stack->oldesp)>0x10000)
printf("Pile invalide !");
else
{
u32 i=0;
for (u32 *pointer = stack->esp; pointer < KERNEL_STACK_ADDR; pointer ++) {
for (u32 *pointer = stack->oldesp; pointer < KERNEL_STACK_ADDR; pointer ++) {
if (i>0 && i % 10 == 0) print("\033[10A");
if (i>=10)
print("\033[25C");

View File

@ -171,186 +171,190 @@ void interruption()
void exception0()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#DE Divide error",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#DE Divide error",dump);
}
void exception1()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
changevc(6);
clearscreen();
show_lightcpu(&dump);
setdebugreg(0,0, DBG_CLEAR);
sti();
waitascii();
cli();
changevc(0);
restcpu();
asm("addl $0x01C, %esp;");
iret();
}
void exception2()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("NMI Non-maskable hardware interrupt",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("NMI Non-maskable hardware interrupt",dump);
}
void exception3()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#BP INT3 instruction",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#BP INT3 instruction",dump);
}
void exception4()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#OF INTO instruction detected overflow",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#OF INTO instruction detected overflow",dump);
}
void exception5()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#BR BOUND instruction detected overrange",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#BR BOUND instruction detected overrange",dump);
}
void exception6()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#UD Invalid instruction opcode",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#UD Invalid instruction opcode",dump);
}
void exception7()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#NM No coprocessor",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#NM No coprocessor",dump);
}
void exception8()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#DF Double fault",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#DF Double fault",dump);
}
void exception9()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("Coprocessor segment overrun",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("Coprocessor segment overrun",dump);
}
void exception10()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#TS Invalid task state segment (TSS)",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#TS Invalid task state segment (TSS)",dump);
}
void exception11()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#NP Segment not present",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#NP Segment not present",dump);
}
void exception12()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#SS Stack fault",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#SS Stack fault",dump);
}
void exception13()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#GP General protection fault (GPF)",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#GP General protection fault (GPF)",dump);
}
void exception14()
{
cli();
save_stack dump;
exception_stack *current = getESP()+0x28+255+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
dumpcpu();
save_stack *dump = getESP();
exception_stack *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
u8* errorstring;
u8 completeerrorstring[255];
switch (current->error_code & 0xF) {
@ -380,56 +384,56 @@ void exception14()
break;
}
// printf("%X",current->error_code);
sprintf(&completeerrorstring,"#PF Page fault - %s at adress %X",errorstring,dump.cr2);
cpuerror(&completeerrorstring,&dump);
sprintf(&completeerrorstring,"#PF Page fault - %s at adress %X",errorstring,dump->cr2);
cpuerror(&completeerrorstring,dump);
}
void exception15()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("(reserved)",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("(reserved)",dump);
}
void exception16()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#MF Coprocessor error",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#MF Coprocessor error",dump);
}
void exception17()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#AC Alignment check",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#AC Alignment check",dump);
}
void exception18()
{
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#MC Machine check",&dump);
dumpcpu();
save_stack *dump = getESP();
exception_stack_noerror *current = getESP()+36;
dump->eip=current->eip;
dump->cs=current->cs;
dump->oldesp=(current+1);
cpuerror("#MC Machine check",dump);
}
/******************************************************************************/

View File

@ -219,7 +219,6 @@ unsigned convert(u32 keypressed)
else if (key == SCAN_F9) {
save_stack dump;
dump_cpu(&dump);
show_cpu(&dump);
}

View File

@ -348,7 +348,6 @@ int info()
int regs()
{
save_stack dump;
dump_cpu(&dump);
show_cpu(&dump);
return 0;
}