pc, xen: move fpu setup/fork/save/restore handlers to pc/fpu.c

This commit is contained in:
cinap_lenrek 2020-12-21 15:04:48 +01:00
parent 932995bb27
commit 5a059477f8
5 changed files with 69 additions and 71 deletions

View file

@ -17,6 +17,10 @@ int cmpswap486(long*, long, long);
void (*coherence)(void); void (*coherence)(void);
void cpuid(int, int, ulong regs[]); void cpuid(int, int, ulong regs[]);
void fpuinit(void); void fpuinit(void);
void fpuprocsetup(Proc*);
void fpuprocfork(Proc*);
void fpuprocsave(Proc*);
void fpuprocrestore(Proc*);
int cpuidentify(void); int cpuidentify(void);
void cpuidprint(void); void cpuidprint(void);
void (*cycles)(uvlong*); void (*cycles)(uvlong*);

View file

@ -307,3 +307,54 @@ fpuinit(void)
fprestore = fpx87restore; fprestore = fpx87restore;
} }
} }
void
fpuprocsetup(Proc *p)
{
p->fpstate = FPinit;
fpoff();
}
void
fpuprocfork(Proc *p)
{
int s;
s = splhi();
switch(up->fpstate & ~FPillegal){
case FPactive:
fpsave(up->fpsave);
up->fpstate = FPinactive;
case FPinactive:
while(p->fpsave == nil)
p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
memmove(p->fpsave, up->fpsave, sizeof(FPsave));
p->fpstate = FPinactive;
}
splx(s);
}
void
fpuprocsave(Proc *p)
{
if(p->fpstate == FPactive){
if(p->state == Moribund)
fpclear();
else{
/*
* Fpsave() stores without handling pending
* unmasked exeptions. Postnote() can't be called
* so the handling of pending exceptions is delayed
* until the process runs again and generates an
* emulation fault to activate the FPU.
*/
fpsave(p->fpsave);
}
p->fpstate = FPinactive;
}
}
void
fpuprocrestore(Proc*)
{
}

View file

@ -233,14 +233,10 @@ confinit(void)
} }
} }
/*
* set up floating point for a new process
*/
void void
procsetup(Proc *p) procsetup(Proc *p)
{ {
p->fpstate = FPinit; fpuprocsetup(p);
fpoff();
memset(p->gdt, 0, sizeof(p->gdt)); memset(p->gdt, 0, sizeof(p->gdt));
p->nldt = 0; p->nldt = 0;
@ -256,8 +252,6 @@ procsetup(Proc *p)
void void
procfork(Proc *p) procfork(Proc *p)
{ {
int s;
/* inherit user descriptors */ /* inherit user descriptors */
memmove(p->gdt, up->gdt, sizeof(p->gdt)); memmove(p->gdt, up->gdt, sizeof(p->gdt));
@ -268,19 +262,7 @@ procfork(Proc *p)
p->nldt = up->nldt; p->nldt = up->nldt;
} }
/* save floating point state */ fpuprocfork(p);
s = splhi();
switch(up->fpstate & ~FPillegal){
case FPactive:
fpsave(up->fpsave);
up->fpstate = FPinactive;
case FPinactive:
while(p->fpsave == nil)
p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
memmove(p->fpsave, up->fpsave, sizeof(FPsave));
p->fpstate = FPinactive;
}
splx(s);
} }
void void
@ -293,6 +275,8 @@ procrestore(Proc *p)
if(p->vmx != nil) if(p->vmx != nil)
vmxprocrestore(p); vmxprocrestore(p);
fpuprocrestore(p);
} }
/* /*
@ -309,21 +293,7 @@ procsave(Proc *p)
if(p->state == Moribund) if(p->state == Moribund)
p->dr[7] = 0; p->dr[7] = 0;
if(p->fpstate == FPactive){ fpuprocsave(p);
if(p->state == Moribund)
fpclear();
else{
/*
* Fpsave() stores without handling pending
* unmasked exeptions. Postnote() can't be called
* so the handling of pending exceptions is delayed
* until the process runs again and generates an
* emulation fault to activate the FPU.
*/
fpsave(p->fpsave);
}
p->fpstate = FPinactive;
}
/* /*
* While this processor is in the scheduler, the process could run * While this processor is in the scheduler, the process could run

View file

@ -11,6 +11,10 @@ int cmpswap486(long*, long, long);
void (*coherence)(void); void (*coherence)(void);
void cpuid(int, int, ulong regs[]); void cpuid(int, int, ulong regs[]);
void fpuinit(void); void fpuinit(void);
void fpuprocsetup(Proc*);
void fpuprocfork(Proc*);
void fpuprocsave(Proc*);
void fpuprocrestore(Proc*);
int cpuidentify(void); int cpuidentify(void);
void cpuidprint(void); void cpuidprint(void);
void (*cycles)(uvlong*); void (*cycles)(uvlong*);

View file

@ -322,39 +322,22 @@ confinit(void)
} }
} }
/*
* set up floating point for a new process
*/
void void
procsetup(Proc*p) procsetup(Proc *p)
{ {
p->fpstate = FPinit; fpuprocsetup(p);
fpoff();
} }
void void
procfork(Proc *p) procfork(Proc *p)
{ {
int s; fpuprocfork(p);
/* save floating point state */
s = splhi();
switch(up->fpstate & ~FPillegal){
case FPactive:
fpsave(up->fpsave);
up->fpstate = FPinactive;
case FPinactive:
while(p->fpsave == nil)
p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
memmove(p->fpsave, up->fpsave, sizeof(FPsave));
p->fpstate = FPinactive;
}
splx(s);
} }
void void
procrestore(Proc *p) procrestore(Proc *p)
{ {
fpuprocrestore(p);
} }
/* /*
@ -363,21 +346,7 @@ procrestore(Proc *p)
void void
procsave(Proc *p) procsave(Proc *p)
{ {
if(p->fpstate == FPactive){ fpuprocsave(p);
if(p->state == Moribund)
fpclear();
else{
/*
* Fpsave() stores without handling pending
* unmasked exeptions. Postnote() can't be called
* so the handling of pending exceptions is delayed
* until the process runs again and generates an
* emulation fault to activate the FPU.
*/
fpsave(p->fpsave);
}
p->fpstate = FPinactive;
}
/* /*
* While this processor is in the scheduler, the process could run * While this processor is in the scheduler, the process could run