Exemplo n.º 1
0
/*
 * Save current CPU's FPU state.  Must be called at IPL_HIGH.
 */
void
fpusave_cpu(bool save)
{
	struct cpu_info *ci;
	struct pcb *pcb;
	struct lwp *l;

	KASSERT(curcpu()->ci_ilevel == IPL_HIGH);

	ci = curcpu();
	l = ci->ci_fpcurlwp;
	if (l == NULL) {
		return;
	}
	pcb = lwp_getpcb(l);

	if (save) {
		 /*
		  * Set ci->ci_fpsaving, so that any pending exception will
		  * be thrown away.  It will be caught again if/when the
		  * FPU state is restored.
		  */
		KASSERT(ci->ci_fpsaving == 0);
		clts();
		ci->ci_fpsaving = 1;
		fxsave(&pcb->pcb_savefpu);
		ci->ci_fpsaving = 0;
	}

	stts();
	pcb->pcb_fpcpu = NULL;
	ci->ci_fpcurlwp = NULL;
}
Exemplo n.º 2
0
static inline int save_i387(struct _fpstate __user *buf)
{
	struct task_struct *tsk = current;
	int err = 0;

	BUILD_BUG_ON(sizeof(struct user_i387_struct) !=
			sizeof(tsk->thread.xstate->fxsave));

	if ((unsigned long)buf % 16)
		printk("save_i387: bad fpstate %p\n", buf);

	if (!used_math())
		return 0;
	clear_used_math(); /* trigger finit */
	if (task_thread_info(tsk)->status & TS_USEDFPU) {
		err = save_i387_checking((struct i387_fxsave_struct __user *)
					 buf);
		if (err)
			return err;
		task_thread_info(tsk)->status &= ~TS_USEDFPU;
		stts();
	} else {
		if (__copy_to_user(buf, &tsk->thread.xstate->fxsave,
				   sizeof(struct i387_fxsave_struct)))
			return -1;
	}
	return 1;
}
Exemplo n.º 3
0
/*
 * Init the FPU.
 */
void
fpuinit(struct cpu_info *ci)
{
	clts();
	fninit();
	stts();
}
Exemplo n.º 4
0
Arquivo: traps.c Projeto: 8l/glendix
/*
 * 'math_state_restore()' saves the current math information in the
 * old math state array, and gets the new ones from the current task
 *
 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
 * Don't touch unless you *really* know how it works.
 *
 * Must be called with kernel preemption disabled (in this case,
 * local interrupts are disabled at the call-site in entry.S).
 */
asmlinkage void math_state_restore(void)
{
	struct thread_info *thread = current_thread_info();
	struct task_struct *tsk = thread->task;

	if (!tsk_used_math(tsk)) {
		local_irq_enable();
		/*
		 * does a slab alloc which can sleep
		 */
		if (init_fpu(tsk)) {
			/*
			 * ran out of memory!
			 */
			do_group_exit(SIGKILL);
			return;
		}
		local_irq_disable();
	}

	clts();				/* Allow maths ops (or we recurse) */
	/*
	 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
	 */
	if (unlikely(restore_fpu_checking(tsk))) {
		stts();
		force_sig(SIGSEGV, tsk);
		return;
	}

	thread->status |= TS_USEDFPU;	/* So we fnsave on switch_to() */
	tsk->fpu_counter++;
}
Exemplo n.º 5
0
static inline void restore_i387_hard(struct _fpstate *buf)
{
#ifdef __SMP__
	if (current->flags & PF_USEDFPU) {
		stts();
	}
#else
	if (current == last_task_used_math) {
		last_task_used_math = NULL;
		stts();
	}
#endif
	current->used_math = 1;
	current->flags &= ~PF_USEDFPU;
	memcpy_fromfs(&current->tss.i387.hard, buf, sizeof(*buf));
}
Exemplo n.º 6
0
/*
 * Initialize the TS bit in CR0 according to the style of context-switches
 * we are using:
 */
static void fpu__init_cpu_ctx_switch(void)
{
	if (!boot_cpu_has(X86_FEATURE_EAGER_FPU))
		stts();
	else
		clts();
}
Exemplo n.º 7
0
void cariDTK2()
{
  clrscr();
  baca_fileDTK();
  gotoxy(25,12);printf("Masukan Nama yang dicari : ");fflush(stdin);gets(nm);  
  tdkketemu=1;  
  while(!feof(Pfk))
  {
    if(strcmp(penggajian.nama,nm)==0)
     {              
      tdkketemu=0;
      clrscr();
      gotoxy(34,2);printf("Data  Karyawan\n");
      gotoxy(26,3);printf("Tampil Data Pencarian Karyawan\n");
      gotoxy(26,4);printf("==============================\n\n");
      gotoxy(19,5);printf("---------------------------------------------\n");
      gotoxy(19,6);printf("   Nama Karyawan   \t= %s\n", nm);
      gotoxy(19,7);printf("   NIK Karyawan    \t= %s\n", penggajian.NIK);
      gotoxy(19,8);printf("   Alamat          \t= %s\n", penggajian.alamat);
      gotoxy(19,9);printf("   Status          \t= %s\n", stts(penggajian.status));
      gotoxy(19,10);printf("   Jabatan         \t= %s\n", jbtn(penggajian.jabatan));
      gotoxy(19,11);printf("---------------------------------------------\n");
      break;
     }
      else
       fread(&penggajian,sizeof(penggajian),1,Pfk);    
  }
  if(tdkketemu==1)
  {
    gotoxy(30,16);printf("Data Tidak Ditemukan!!!");
  }
  
  //tutup file
  fclose(Pfk);
}
Exemplo n.º 8
0
void tampilDTK()
{   
   clrscr();
   baca_fileDTK();
   nomor=0;
   gotoxy(34,2);printf("Data  Karyawan");
   gotoxy(31,3);printf("Tampil Data Karyawan");
   gotoxy(28,4);printf("==========================\n\n");
   printf
   (" ==============================================================================\n");
   printf
   (" | No |  NIK  |        Nama         |    Alamat    |    Status    |  Jabatan  |\n");
   printf
   (" ==============================================================================\n");
   for(;;)
   {
    fread(&penggajian,sizeof(penggajian),1,Pfk);
    if(feof(Pfk))break;
    printf(" | %i%3c%-5s%3c%-21s%c%-10s%5c%-14s%c%-11s%c\n",++nomor,'|', penggajian.NIK,'|'
    , penggajian.nama,'|',penggajian.alamat,'|',stts(penggajian.status),'|', jbtn(penggajian.jabatan),'|'); 
   }
   printf
   (" ==============================================================================\n");
   
   //tutup file
   fclose(Pfk);
}
Exemplo n.º 9
0
/*H:040
 * This is the i386-specific code to setup and run the Guest.  Interrupts
 * are disabled: we own the CPU.
 */
void lguest_arch_run_guest(struct lg_cpu *cpu)
{
	/*
	 * Remember the awfully-named TS bit?  If the Guest has asked to set it
	 * we set it now, so we can trap and pass that trap to the Guest if it
	 * uses the FPU.
	 */
	if (cpu->ts && user_has_fpu())
		stts();

	/*
	 * SYSENTER is an optimized way of doing system calls.  We can't allow
	 * it because it always jumps to privilege level 0.  A normal Guest
	 * won't try it because we don't advertise it in CPUID, but a malicious
	 * Guest (or malicious Guest userspace program) could, so we tell the
	 * CPU to disable it before running the Guest.
	 */
	if (boot_cpu_has(X86_FEATURE_SEP))
		wrmsr(MSR_IA32_SYSENTER_CS, 0, 0);

	/*
	 * Now we actually run the Guest.  It will return when something
	 * interesting happens, and we can examine its registers to see what it
	 * was doing.
	 */
	run_guest_once(cpu, lguest_pages(raw_smp_processor_id()));

	/*
	 * Note that the "regs" structure contains two extra entries which are
	 * not really registers: a trap number which says what interrupt or
	 * trap made the switcher code come back, and an error code which some
	 * traps set.
	 */

	 /* Restore SYSENTER if it's supposed to be on. */
	 if (boot_cpu_has(X86_FEATURE_SEP))
		wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);

	/* Clear the host TS bit if it was set above. */
	if (cpu->ts && user_has_fpu())
		clts();

	/*
	 * If the Guest page faulted, then the cr2 register will tell us the
	 * bad virtual address.  We have to grab this now, because once we
	 * re-enable interrupts an interrupt could fault and thus overwrite
	 * cr2, or we could even move off to a different CPU.
	 */
	if (cpu->regs->trapnum == 14)
		cpu->arch.last_pagefault = read_cr2();
	/*
	 * Similarly, if we took a trap because the Guest used the FPU,
	 * we have to restore the FPU it expects to see.
	 * math_state_restore() may sleep and we may even move off to
	 * a different CPU. So all the critical stuff should be done
	 * before this.
	 */
	else if (cpu->regs->trapnum == 7 && !user_has_fpu())
		math_state_restore();
}
Exemplo n.º 10
0
/*
 * Initialize the TS bit in CR0 according to the style of context-switches
 * we are using:
 */
static void fpu__init_cpu_ctx_switch(void)
{
	if (!cpu_has_eager_fpu)
		stts();
	else
		clts();
}
Exemplo n.º 11
0
static inline struct _fpstate * save_i387_hard(struct _fpstate * buf)
{
#ifdef __SMP__
	if (current->flags & PF_USEDFPU) {
		__asm__ __volatile__("fnsave %0":"=m" (current->tss.i387.hard));
		stts();
		current->flags &= ~PF_USEDFPU;
	}
Exemplo n.º 12
0
void restore_rest_processor_state(void)
{
    struct vcpu *v = current;

    load_TR();

#if defined(CONFIG_X86_64)
    /* Recover syscall MSRs */
    wrmsrl(MSR_LSTAR, saved_lstar);
    wrmsrl(MSR_CSTAR, saved_cstar);
    wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
    wrmsr(MSR_SYSCALL_MASK, EF_VM|EF_RF|EF_NT|EF_DF|EF_IE|EF_TF, 0U);    

    if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
    {
        /* Recover sysenter MSRs */
        wrmsrl(MSR_IA32_SYSENTER_ESP, saved_sysenter_esp);
        wrmsrl(MSR_IA32_SYSENTER_EIP, saved_sysenter_eip);
        wrmsr(MSR_IA32_SYSENTER_CS, __HYPERVISOR_CS, 0);
    }
#else /* !defined(CONFIG_X86_64) */
    if ( supervisor_mode_kernel && cpu_has_sep )
        wrmsr(MSR_IA32_SYSENTER_ESP, &init_tss[smp_processor_id()].esp1, 0);
#endif

    /* Maybe load the debug registers. */
    BUG_ON(is_hvm_vcpu(v));
    if ( !is_idle_vcpu(v) && unlikely(v->arch.guest_context.debugreg[7]) )
    {
        write_debugreg(0, v->arch.guest_context.debugreg[0]);
        write_debugreg(1, v->arch.guest_context.debugreg[1]);
        write_debugreg(2, v->arch.guest_context.debugreg[2]);
        write_debugreg(3, v->arch.guest_context.debugreg[3]);
        write_debugreg(6, v->arch.guest_context.debugreg[6]);
        write_debugreg(7, v->arch.guest_context.debugreg[7]);
    }

    /* Reload FPU state on next FPU use. */
    stts();

    if (cpu_has_pat)
        wrmsrl(MSR_IA32_CR_PAT, host_pat);

    mtrr_ap_init();
    mcheck_init(&boot_cpu_data);
}
Exemplo n.º 13
0
/*
 * __math_state_restore assumes that cr0.TS is already clear and the
 * fpu state is all ready for use.  Used during context switch.
 */
void __math_state_restore(void)
{
	struct thread_info *thread = current_thread_info();
	struct task_struct *tsk = thread->task;

	/*
	 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
	 */
	if (unlikely(restore_fpu_checking(tsk))) {
		stts();
		force_sig(SIGSEGV, tsk);
		return;
	}

	thread->status |= TS_USEDFPU;	/* So we fnsave on switch_to() */
	tsk->fpu_counter++;
}
Exemplo n.º 14
0
void cari_DGK()
{
  baca_fileDTK();
  gotoxy(22,14);printf("Masukan Nama Karyawan: ");fflush(stdin);gets(z); 
  tdkketemu=1;
  while(!feof(Pfk))
  {
    if(strcmp(penggajian.nama,z)==0)
    {              
    tdkketemu=0;
    clrscr();
    gotoxy(34,2);printf("Data  Karyawan\n");
    gotoxy(26,3);printf("Tampil Data Penggajian Karyawan\n");
    gotoxy(26,4);printf("===============================\n\n");
    gotoxy(19,5);printf("---------------------------------------------\n");
    gotoxy(19,6);printf("Nama Karyawan         \t: %s\n", z);
    gotoxy(19,7);printf("Jabatan Karyawan      \t: %s\n", jbtn(penggajian.jabatan));
    gotoxy(19,8);printf("Status Karyawan       \t: %s\n", stts(penggajian.status));
    gotoxy(19,9);printf("Gaji Pokok            \t: Rp. %8ld\n", penggajian.gaji_pokok);
    gotoxy(19,10);printf("Tunjangan Jabatan     \t: Rp. %8.f\n", penggajian.tunja);
    gotoxy(19,11);printf("Tunjangan Keluarga    \t: Rp. %8.f\n", penggajian.tunga);
    gotoxy(19,12);printf("Gaji Kotor            \t: Rp. %8ld\n", penggajian.gaji_kotor);
    gotoxy(19,13);printf("Potongan              \t: Rp. %8ld\n", penggajian.potongan);
    gotoxy(19,14);printf("=============================================\n");
    gotoxy(19,15);printf("Gaji Bersih           \t: Rp. %8ld\n", penggajian.gaji_bersih);
    gotoxy(19,16);printf("---------------------------------------------\n");
    break;
  }
  else
  fread(&penggajian,sizeof(penggajian),1,Pfk);    
  }
  if(tdkketemu==1)
  {
    gotoxy(30,17);printf("Data Tidak Ditemukan!!!");
  }
  
  //tutup file
  fclose(Pfk);
}
Exemplo n.º 15
0
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
{
	int ret;

	*dst = *src;
	if (fpu_allocated(&src->thread.fpu)) {
		memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
		ret = fpu_alloc(&dst->thread.fpu);
		if (ret)
			return ret;
		fpu_copy(&dst->thread.fpu, &src->thread.fpu);
	}

#ifdef CONFIG_X86_EARLYMIC
	if (dst->thread.fpu.state) {
		/*
		 * No need to set this flag ? it should be inherited from the
		 * parent thread since the threadinfo is copied from the
		 * parent in setup_thread_stack()
		 */
		set_stopped_child_used_math(dst);
		/*
		 * Simulate FPU DNA
		 * Undo the effects of unlazy_fpu in prepare_to_copy()
		 */
		preempt_disable();
		clts();
#ifdef CONFIG_ML1OM
		__math_state_restore();
#else
		restore_mask_regs();
		stts();
#endif
		preempt_enable();
	}
#endif
	return 0;
}
Exemplo n.º 16
0
void tampil_DGK()
{
   clrscr();
   baca_fileDTK();
   nomor=0;
   gotoxy(34,2);printf("Data  Gaji Karyawan\n");
   gotoxy(31,3);printf("Tampil Data Gaji Karyawan\n");
   gotoxy(28,4);printf("==============================\n\n");
   printf("================================================================================");
   printf("| No |        Nama        |  Jabatan  |    Status    | Gaji Pokok |Gaji Bersih |");
   printf("================================================================================");
   for(;;)
   {
    fread(&penggajian,sizeof(penggajian),1,Pfk);
    if(feof(Pfk))break;
    printf("|%2i%3c%-20s%c%-11s%c%-14s%cRp.%-9ld%cRp.%-9ld%c",++nomor,'|', penggajian.nama,'|', 
    jbtn(penggajian.jabatan),'|', stts(penggajian.status),'|', penggajian.gaji_pokok,'|',penggajian.gaji_bersih,'|'); 
   }
   printf("================================================================================");

   //tutup file
   fclose(Pfk);
}
Exemplo n.º 17
0
/*
 * setup the xstate image representing the init state
 */
static void __init setup_xstate_init(void)
{
	setup_xstate_features();

	/*
	 * Setup init_xstate_buf to represent the init state of
	 * all the features managed by the xsave
	 */
	init_xstate_buf = alloc_bootmem_align(xstate_size,
					      __alignof__(struct xsave_struct));
	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;

	clts();
	/*
	 * Init all the features state with header_bv being 0x0
	 */
	xrstor_state(init_xstate_buf, -1);
	/*
	 * Dump the init state again. This is to identify the init state
	 * of any feature which is not represented by all zero's.
	 */
	xsave_state(init_xstate_buf, -1);
	stts();
}
Exemplo n.º 18
0
static void __init setup_xstate_init(void)
{
	setup_xstate_features();

	/*
                                                        
                                         
  */
	init_xstate_buf = alloc_bootmem_align(xstate_size,
					      __alignof__(struct xsave_struct));
	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;

	clts();
	/*
                                                        
  */
	xrstor_state(init_xstate_buf, -1);
	/*
                                                                 
                                                          
  */
	xsave_state(init_xstate_buf, -1);
	stts();
}
Exemplo n.º 19
0
void ubahDTK()
{
    awal: 
    tampilDTK();
    gotoxy(34,2);printf("Data  Karyawan");
    gotoxy(31,3);printf("Ubah Data Karyawan");
    gotoxy(28,4);printf("==========================\n\n");
    file_ubahDTK();
    do
    {
      
      gotoxy(28,20);printf("\n");
      printf(" Masukkan nomor record yang akan diubah [1..%i] : ",nomor);
             scanf("%d",&no_record);       
      /* atur penunjuk posisi file ke record yang di kehendaki */
      ofset_byte=(no_record-1)*sizeof(penggajian);
      fseek(Pfk,ofset_byte,SEEK_SET);
      /* baca record yang ditunjuk oleh penunjuk posisi file */
      hasil_baca=fread(&penggajian,sizeof(penggajian),1,Pfk);      
      if(hasil_baca==0)
        {
          printf(" Nomor record tak absah !\r\n");
        }
       else
        {
         printf("\n\n");
         printf(" ==============================================================\n");
         printf(" Edit Data Karyawan \n");
         printf(" ==============================================================\n\n");
         printf(" NIK Karyawan \t\t = %s\n",penggajian.NIK);
         printf("----------------------------------------------------\n");
         printf(" Data Sebelum Diubah\n");
         printf("----------------------------------------------------\n");
         printf("\n Nama Karyawan \t\t = %s\n", penggajian.nama);
         printf(" Alamat \t\t = %s\n", penggajian.alamat);
         printf(" Status \t\t = %s\n", stts(penggajian.status));
         printf(" Jabatan \t\t = %s\n", jbtn(penggajian.jabatan));

         printf("\n\n");
         printf("----------------------------------------------------\n");
         printf(" Data Yang Akan Diubah\n");
         printf("----------------------------------------------------\n");
         printf(" NIK          \t : ");fflush(stdin);gets(penggajian.NIK);
         printf(" Nama         \t : ");fflush(stdin);gets(penggajian.nama);
         printf(" Alamat       \t : ");fflush(stdin);gets(penggajian.alamat);
         printf("\n ================\n");
         printf(" Pilihan Status\n");
         printf(" ================\n");
         printf(" 1. Menikah \n");
         printf(" 2. Belum Menikah \n");
         printf(" ================\n");
         printf(" Silahkan masukan kode Status [1..2] : ");penggajian.status = getche();
         printf("\n =======\n");
         printf(" Pilihan Jabatan\n");
         printf(" =======\n");
         printf(" 1. Manager \n");
         printf(" 2. Sekretaris \n");
         printf(" 3. Bendahara \n");
         printf(" 4. Leader \n");
         printf(" 5. Operator \n");
         printf(" ================\n");
         printf(" Silahkan masukan kode Jabatan [1..5]: ");penggajian.jabatan = getche();printf("\n");
         printf("\n=================================\n");  

         /* atur penunjuk posisi file ke posisi sebelumnya*/
         fseek(Pfk,ofset_byte,SEEK_SET);

         /* rekam ulang */
         fwrite(&penggajian,sizeof(penggajian),1,Pfk);
       }//nelse
       cputs("\n\n Mau mengubah lagi (Y/T)?");
       jawab = getche();
       if((jawab=='Y'||jawab=='y'))
       { 
         clrscr();fclose(Pfk);goto awal;
       }         
    }while (jawab=='Y'||jawab=='y');
    
        
    /* tutup file */
   fclose(Pfk); 
}
Exemplo n.º 20
0
int save_i387_xstate(void __user *buf)
{
	struct task_struct *tsk = current;
	int err = 0;

	if (!access_ok(VERIFY_WRITE, buf, sig_xstate_size))
		return -EACCES;

	BUG_ON(sig_xstate_size < xstate_size);

	if ((unsigned long)buf % 64)
		printk("save_i387_xstate: bad fpstate %p\n", buf);

	if (!used_math())
		return 0;

	if (task_thread_info(tsk)->status & TS_USEDFPU) {
		if (use_xsave())
			err = xsave_user(buf);
		else
			err = fxsave_user(buf);

		if (err)
			return err;
		task_thread_info(tsk)->status &= ~TS_USEDFPU;
		stts();
	} else {
		sanitize_i387_state(tsk);
		if (__copy_to_user(buf, &tsk->thread.fpu.state->fxsave,
				   xstate_size))
			return -1;
	}

	clear_used_math(); /* trigger finit */

	if (use_xsave()) {
		struct _fpstate __user *fx = buf;
		struct _xstate __user *x = buf;
		u64 xstate_bv;

		err = __copy_to_user(&fx->sw_reserved, &fx_sw_reserved,
				     sizeof(struct _fpx_sw_bytes));

		err |= __put_user(FP_XSTATE_MAGIC2,
				  (__u32 __user *) (buf + sig_xstate_size
						    - FP_XSTATE_MAGIC2_SIZE));

		/*
		 * Read the xstate_bv which we copied (directly from the cpu or
		 * from the state in task struct) to the user buffers and
		 * set the FP/SSE bits.
		 */
		err |= __get_user(xstate_bv, &x->xstate_hdr.xstate_bv);

		/*
		 * For legacy compatible, we always set FP/SSE bits in the bit
		 * vector while saving the state to the user context. This will
		 * enable us capturing any changes(during sigreturn) to
		 * the FP/SSE bits by the legacy applications which don't touch
		 * xstate_bv in the xsave header.
		 *
		 * xsave aware apps can change the xstate_bv in the xsave
		 * header as well as change any contents in the memory layout.
		 * xrestore as part of sigreturn will capture all the changes.
		 */
		xstate_bv |= XSTATE_FPSSE;

		err |= __put_user(xstate_bv, &x->xstate_hdr.xstate_bv);

		if (err)
			return err;
	}

	return 1;
}
Exemplo n.º 21
0
void tambahDAK()
{
    awal:
    tampilDAK();
    gotoxy(34,2);printf("  Data Absensi");
    gotoxy(31,3);printf("Tambah Data Absensi");
    gotoxy(28,4);printf("==========================\n\n");
    file_ubahDTK();
     
    do
    {
      
      gotoxy(28,20);printf("\n");
      printf(" Masukkan nomor record yang akan dimasukkan Absen [1..%i] : ",nomor);
             scanf("%d",&no_record);       
      /* atur penunjuk posisi file ke record yang di kehendaki */
      ofset_byte=(no_record-1)*sizeof(penggajian);
      fseek(Pfk,ofset_byte,SEEK_SET);
      /* baca record yang ditunjuk oleh penunjuk posisi file */
      hasil_baca=fread(&penggajian,sizeof(penggajian),1,Pfk);      
      if(hasil_baca==0)
        {
          printf(" Nomor record tak absah !\r\n");
        }
       else
        {
         printf("\n\n");
         printf(" ==============================================================\n");
         printf(" Absensi Data Karyawan \n");
         printf(" ==============================================================\n\n");
         printf(" NIK Karyawan \t\t = %s\n",penggajian.NIK);
         printf("----------------------------------------------------\n");
         printf(" Data Karyawan\n");
         printf("----------------------------------------------------\n");
         printf("\n Nama Karyawan \t\t = %s\n", penggajian.nama);
         printf(" Alamat \t\t = %s\n", penggajian.alamat);
         printf(" Status \t\t = %s\n", stts(penggajian.status));
         printf(" Jabatan \t\t = %s\n", jbtn(penggajian.jabatan));

         printf("\n\n");
         printf("----------------------------------------------------\n");
         printf(" Data Absensi\n");
         printf("----------------------------------------------------\n");
         printf(" Pilihan Bulan\n");
         printf(" ================\n");
         printf(" a. Januari                g. Juli \n");
         printf(" b. Februari               h. Agustus \n");
         printf(" c. Maret                  i. September \n");
         printf(" d. April                  j. Oktober \n");
         printf(" e. Mei                    k. November \n");
         printf(" f. Juni                   l. Desember \n");
         printf(" ================\n");
         printf(" Silahkan masukkan pilihan Bulan [a..l] : ");penggajian.bulan = getche();printf("\n");
         printf(" \nKehadiran\n");
         printf(" ================\n");
         printf("\n Kehadiran Minggu Ke- 1 : ");scanf("%i",&penggajian.minggu1);
         printf("\n Kehadiran Minggu Ke- 2 : ");scanf("%i",&penggajian.minggu2);
         printf("\n Kehadiran Minggu Ke- 3 : ");scanf("%i",&penggajian.minggu3);
         printf("\n Kehadiran Minggu Ke- 4 : ");scanf("%i",&penggajian.minggu4);
         printf(" =================================\n");  
         penggajian.ket = (penggajian.minggu1 + penggajian.minggu2 + penggajian.minggu3 + penggajian.minggu4)/4;
         keuangan();
         /* atur penunjuk posisi file ke posisi sebelumnya*/
         fseek(Pfk,ofset_byte,SEEK_SET);

         /* rekam ulang */
         fwrite(&penggajian,sizeof(penggajian),1,Pfk);
       }//nelse
       cputs("\n\n Mau Input Absen lagi (Y/T)?");
       jawab = getche();
       if((jawab=='Y'||jawab=='y'))
       { 
         clrscr();fclose(Pfk);goto awal;
       }         
    }while (jawab=='Y'||jawab=='y');
      
      //tutup file
      fclose(Pfk);
}
Exemplo n.º 22
0
void keuangan()
{    
  
  if((strcmp((jbtn(penggajian.jabatan)), "Manager")==0)&&(strcmp((stts(penggajian.status)), "Menikah")==0))
   {
      penggajian.gaji_pokok=8000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
      penggajian.tunga=0.05 * penggajian.gaji_pokok;
   }  
   else if((strcmp((jbtn(penggajian.jabatan)), "Manager")==0)&&
          ((strcmp((stts(penggajian.status)), "Belum Menikah")==0)||(strcmp((stts(penggajian.status)), "Tidak Ada")==0)))
   {
      penggajian.gaji_pokok=8000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
   } 
   else if((strcmp((jbtn(penggajian.jabatan)), "Sekretaris")==0)&&(strcmp((stts(penggajian.status)), "Menikah")==0))
   {
      penggajian.gaji_pokok=6000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
      penggajian.tunga=0.05 * penggajian.gaji_pokok;
   }  
    else if((strcmp((jbtn(penggajian.jabatan)), "Sekretaris")==0)&&
           ((strcmp((stts(penggajian.status)), "Belum Menikah")==0)||(strcmp((stts(penggajian.status)), "Tidak Ada")==0)))
   {
      penggajian.gaji_pokok=6000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
   }  
    else if((strcmp((jbtn(penggajian.jabatan)), "Bendahara")==0)&&(strcmp((stts(penggajian.status)), "Menikah")==0))
   {
      penggajian.gaji_pokok=5000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
      penggajian.tunga=0.05 * penggajian.gaji_pokok;
   } 
   else if((strcmp((jbtn(penggajian.jabatan)), "Bendahara")==0)&&
          ((strcmp((stts(penggajian.status)), "Belum Menikah")==0)||(strcmp((stts(penggajian.status)), "Tidak Ada")==0)))
   {
      penggajian.gaji_pokok=5000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
   } 
    else if((strcmp((jbtn(penggajian.jabatan)), "Leader")==0)&&(strcmp((stts(penggajian.status)), "Menikah")==0))
   {
      penggajian.gaji_pokok=4000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
      penggajian.tunga=0.05 * penggajian.gaji_pokok;
   } 
    else if((strcmp((jbtn(penggajian.jabatan)), "Leader")==0)&&
           ((strcmp((stts(penggajian.status)), "Belum Menikah")==0)||(strcmp((stts(penggajian.status)), "Tidak Ada")==0)))
   {
      penggajian.gaji_pokok=4000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
   } 
    else if((strcmp((jbtn(penggajian.jabatan)), "Operator")==0)&&(strcmp((stts(penggajian.status)), "Menikah")==0))
   {
      penggajian.gaji_pokok=2000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
      penggajian.tunga=0.05 * penggajian.gaji_pokok;
   } 
   else if((strcmp((jbtn(penggajian.jabatan)), "Operator")==0)&&
          ((strcmp((stts(penggajian.status)), "Belum Menikah")==0)||(strcmp((stts(penggajian.status)), "Tidak Ada")==0)))
    {
      penggajian.gaji_pokok=2000000;
      penggajian.tunja=0.2 * penggajian.gaji_pokok;
   } 
   else
   {
      penggajian.gaji_pokok=0;
      penggajian.tunja=0;
      penggajian.tunga=0;
   }
   penggajian.gaji_kotor = penggajian.gaji_pokok + penggajian.tunja + penggajian.tunga;
   penggajian.potongan = penggajian.gaji_pokok *((100-penggajian.ket)/100);
   penggajian.gaji_bersih = penggajian.gaji_kotor - penggajian.potongan;
}