Lines Matching refs:pic
188 let pic = if irq <= PRIMARY_PIC_MAX_IRQ { in service_irq() localVariable
193 Pic::set_irq_internal(&mut self.pics[pic as usize], irq & 7, level); in service_irq()
320 fn reset_pic(pic: &mut PicState) { in reset_pic()
321 let edge_irr = pic.irr & !pic.elcr; in reset_pic()
323 pic.last_irr = 0; in reset_pic()
324 pic.irr &= pic.elcr; in reset_pic()
325 pic.imr = 0; in reset_pic()
326 pic.priority_add = 0; in reset_pic()
327 pic.special_mask = false; in reset_pic()
328 pic.read_reg_select = false; in reset_pic()
329 if !pic.use_4_byte_icw { in reset_pic()
330 pic.special_fully_nested_mode = false; in reset_pic()
331 pic.auto_eoi = false; in reset_pic()
333 pic.init_state = Some(PicInitState::Icw2); in reset_pic()
337 Pic::clear_isr(pic, irq); in reset_pic()
362 let pic = &self.pics[pic_type as usize]; in get_irq() localVariable
363 let mut irq_bitmap = pic.irr & !pic.imr; in get_irq()
364 let priority = if let Some(p) = Pic::get_priority(pic, irq_bitmap) { in get_irq()
372 irq_bitmap = pic.isr; in get_irq()
373 if pic_type == PicSelect::Primary && pic.special_fully_nested_mode { in get_irq()
376 let new_priority = Pic::get_priority(pic, irq_bitmap).unwrap_or(INVALID_PRIORITY); in get_irq()
379 Some((priority + pic.priority_add) & 7) in get_irq()
385 fn clear_isr(pic: &mut PicState, irq: u8) { in clear_isr()
387 pic.isr &= !(1 << irq); in clear_isr()
416 fn set_irq_internal(pic: &mut PicState, irq: u8, level: bool) { in set_irq_internal()
419 if (pic.elcr & irq_bitmap) != 0 { in set_irq_internal()
423 pic.irr |= irq_bitmap; in set_irq_internal()
424 pic.last_irr |= irq_bitmap; in set_irq_internal()
426 pic.irr &= !irq_bitmap; in set_irq_internal()
427 pic.last_irr &= !irq_bitmap; in set_irq_internal()
432 if (pic.last_irr & irq_bitmap) == 0 { in set_irq_internal()
434 pic.irr |= irq_bitmap; in set_irq_internal()
436 pic.last_irr |= irq_bitmap; in set_irq_internal()
438 pic.last_irr &= !irq_bitmap; in set_irq_internal()
443 fn get_priority(pic: &PicState, irq_bitmap: u8) -> Option<u8> { in get_priority()
450 let mut priority_mask = 1 << ((priority + pic.priority_add) & 7); in get_priority()
453 priority_mask = 1 << ((priority + pic.priority_add) & 7); in get_priority()
462 fn interrupt_ack(pic: &mut PicState, irq: u8) { in interrupt_ack()
466 pic.isr |= irq_bitmap; in interrupt_ack()
468 if (pic.elcr & irq_bitmap) == 0 { in interrupt_ack()
469 pic.irr &= !irq_bitmap; in interrupt_ack()
472 if pic.auto_eoi { in interrupt_ack()
473 if pic.rotate_on_auto_eoi { in interrupt_ack()
474 pic.priority_add = (irq + 1) & 7; in interrupt_ack()
476 Pic::clear_isr(pic, irq); in interrupt_ack()
480 fn init_command_word_1(pic: &mut PicState, value: u8) { in init_command_word_1()
481 pic.use_4_byte_icw = (value & ICW1_NEED_ICW4) != 0; in init_command_word_1()
488 Pic::reset_pic(pic); in init_command_word_1()
528 fn operation_command_word_3(pic: &mut PicState, value: u8) { in operation_command_word_3()
530 pic.poll = true; in operation_command_word_3()
534 pic.read_reg_select = value & OCW3_READ_ISR != 0; in operation_command_word_3()
537 pic.special_mask = value & OCW3_SPECIAL_MASK_VALUE != 0; in operation_command_word_3()
549 pic: Pic, field
553 let mut pic = Pic::new(); in set_up() localVariable
555 pic.write(PIC_PRIMARY_ELCR, &[0]); in set_up()
556 pic.write(PIC_SECONDARY_ELCR, &[0]); in set_up()
557 TestData { pic } in set_up()
561 fn icw_init(pic: &mut Pic, pic_type: PicSelect, icw1: u8, icw2: u8, icw3: u8, icw4: u8) { in icw_init()
571 pic.write(command_offset, &[icw1]); in icw_init()
572 pic.write(data_offset, &[icw2]); in icw_init()
573 pic.write(data_offset, &[icw3]); in icw_init()
574 pic.write(data_offset, &[icw4]); in icw_init()
578 fn icw_init_primary(pic: &mut Pic) { in icw_init_primary()
583 icw_init(pic, PicSelect::Primary, 0x11, 0x08, 0xff, 0x13); in icw_init_primary()
587 fn icw_init_secondary(pic: &mut Pic) { in icw_init_secondary()
592 icw_init(pic, PicSelect::Secondary, 0x11, 0x70, 0xff, 0x13); in icw_init_secondary()
596 fn icw_init_both_with_icw4(pic: &mut Pic, icw4: u8) { in icw_init_both_with_icw4()
600 icw_init(pic, PicSelect::Primary, 0x11, 0x08, 0xff, icw4); in icw_init_both_with_icw4()
604 icw_init(pic, PicSelect::Secondary, 0x11, 0x70, 0xff, icw4); in icw_init_both_with_icw4()
607 fn icw_init_both(pic: &mut Pic) { in icw_init_both()
608 icw_init_primary(pic); in icw_init_both()
609 icw_init_secondary(pic); in icw_init_both()
619 data.pic.write(PIC_PRIMARY_ELCR, &data_write); in write_read_elcr()
620 data.pic.read(PIC_PRIMARY_ELCR, &mut data_read); in write_read_elcr()
623 data.pic.write(PIC_SECONDARY_ELCR, &data_write); in write_read_elcr()
624 data.pic.read(PIC_SECONDARY_ELCR, &mut data_read); in write_read_elcr()
635 data.pic.write(PIC_PRIMARY_COMMAND, &data_write); in icw_2_step()
638 data.pic.write(PIC_PRIMARY_DATA, &data_write); in icw_2_step()
641 data.pic.write(PIC_PRIMARY_DATA, &data_write); in icw_2_step()
644 data.pic.pics[PicSelect::Primary as usize].init_state, in icw_2_step()
647 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irq_base, 0x08); in icw_2_step()
649 data.pic.pics[PicSelect::Primary as usize].use_4_byte_icw, in icw_2_step()
658 icw_init_primary(&mut data.pic); in initial_values()
660 let primary_pic = &data.pic.pics[PicSelect::Primary as usize]; in initial_values()
684 icw_init_secondary(&mut data.pic); in ocw()
687 data.pic.write(PIC_SECONDARY_DATA, &[0x5f]); in ocw()
690 data.pic.write(PIC_SECONDARY_COMMAND, &[0x80]); in ocw()
693 data.pic.write(PIC_SECONDARY_COMMAND, &[0xc0]); in ocw()
696 data.pic.write(PIC_SECONDARY_COMMAND, &[0x6b]); in ocw()
699 data.pic.read(PIC_SECONDARY_DATA, &mut data_read); in ocw()
702 let secondary_pic = &data.pic.pics[PicSelect::Secondary as usize]; in ocw()
722 icw_init_secondary(&mut data.pic); in ocw_auto_rotate_set_and_clear()
725 data.pic.write(PIC_SECONDARY_COMMAND, &[0x80]); in ocw_auto_rotate_set_and_clear()
727 let secondary_pic = &data.pic.pics[PicSelect::Secondary as usize]; in ocw_auto_rotate_set_and_clear()
731 data.pic.write(PIC_SECONDARY_COMMAND, &[0x00]); in ocw_auto_rotate_set_and_clear()
733 let secondary_pic = &data.pic.pics[PicSelect::Secondary as usize]; in ocw_auto_rotate_set_and_clear()
742 icw_init_both(&mut data.pic); in auto_eoi()
745 data.pic.service_irq(/*irq=*/ 12, /*level=*/ true); in auto_eoi()
748 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, (1 << 4)); in auto_eoi()
749 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 0); in auto_eoi()
750 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, (1 << 2)); in auto_eoi()
751 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in auto_eoi()
754 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 4)); in auto_eoi()
757 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 0); in auto_eoi()
758 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 0); in auto_eoi()
759 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 0); in auto_eoi()
760 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in auto_eoi()
771 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in fully_nested_mode_on()
774 data.pic.service_irq(/*irq=*/ 12, /*level=*/ true); in fully_nested_mode_on()
775 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 4)); in fully_nested_mode_on()
779 data.pic.service_irq(/*irq=*/ 8, /*level=*/ true); in fully_nested_mode_on()
780 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 0)); in fully_nested_mode_on()
783 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 0); in fully_nested_mode_on()
785 data.pic.pics[PicSelect::Secondary as usize].isr, in fully_nested_mode_on()
788 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 0); in fully_nested_mode_on()
789 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 2); in fully_nested_mode_on()
800 icw_init_both_with_icw4(&mut data.pic, 0x01); in fully_nested_mode_off()
803 data.pic.service_irq(/*irq=*/ 12, /*level=*/ true); in fully_nested_mode_off()
804 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 4)); in fully_nested_mode_off()
806 data.pic.service_irq(/*irq=*/ 8, /*level=*/ true); in fully_nested_mode_off()
808 assert_eq!(data.pic.get_external_interrupt(), None); in fully_nested_mode_off()
810 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 1 << 0); in fully_nested_mode_off()
811 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 1 << 4); in fully_nested_mode_off()
812 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 1 << 2); in fully_nested_mode_off()
813 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 2); in fully_nested_mode_off()
819 data.pic.write(PIC_PRIMARY_COMMAND, &[0x20]); in fully_nested_mode_off()
820 data.pic.write(PIC_SECONDARY_COMMAND, &[0x20]); in fully_nested_mode_off()
823 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 0)); in fully_nested_mode_off()
825 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 0); in fully_nested_mode_off()
826 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 1 << 0); in fully_nested_mode_off()
827 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 0); in fully_nested_mode_off()
828 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 2); in fully_nested_mode_off()
836 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in mask_irq()
839 data.pic.write(PIC_SECONDARY_DATA, &[0x40]); in mask_irq()
841 data.pic.service_irq(/*irq=*/ 14, /*level=*/ true); in mask_irq()
842 assert_eq!(data.pic.get_external_interrupt(), None); in mask_irq()
844 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 1 << 6); in mask_irq()
845 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 0); in mask_irq()
846 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 0); in mask_irq()
847 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in mask_irq()
851 data.pic.write(PIC_SECONDARY_DATA, &[0x00]); in mask_irq()
854 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 6)); in mask_irq()
856 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 0); in mask_irq()
857 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 1 << 6); in mask_irq()
858 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 0); in mask_irq()
859 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 2); in mask_irq()
868 icw_init_both(&mut data.pic); in mask_multiple_irq()
871 data.pic.write(PIC_PRIMARY_DATA, &[0xff]); in mask_multiple_irq()
872 data.pic.write(PIC_SECONDARY_DATA, &[0xff]); in mask_multiple_irq()
874 data.pic.service_irq(/*irq=*/ 14, /*level=*/ true); in mask_multiple_irq()
875 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in mask_multiple_irq()
876 data.pic.service_irq(/*irq=*/ 12, /*level=*/ true); in mask_multiple_irq()
879 assert_eq!(data.pic.get_external_interrupt(), None); in mask_multiple_irq()
882 data.pic.write(PIC_SECONDARY_DATA, &[0x00]); in mask_multiple_irq()
885 assert_eq!(data.pic.get_external_interrupt(), None); in mask_multiple_irq()
889 data.pic.write(PIC_PRIMARY_DATA, &[0xfb]); in mask_multiple_irq()
893 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 4)); in mask_multiple_irq()
894 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 6)); in mask_multiple_irq()
898 data.pic.write(PIC_PRIMARY_DATA, &[0x00]); in mask_multiple_irq()
899 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 4)); in mask_multiple_irq()
906 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in ocw3()
910 data.pic.service_irq(/*irq=*/ 5, /*level=*/ true); in ocw3()
911 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in ocw3()
912 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 4)); in ocw3()
915 data.pic.write(PIC_PRIMARY_COMMAND, &[0x0a]); in ocw3()
917 data.pic.read(PIC_PRIMARY_COMMAND, &mut data_read); in ocw3()
921 data.pic.write(PIC_PRIMARY_COMMAND, &[0x0b]); in ocw3()
923 data.pic.read(PIC_PRIMARY_COMMAND, &mut data_read); in ocw3()
928 data.pic.write(PIC_PRIMARY_COMMAND, &[0x20]); in ocw3()
931 data.pic.write(PIC_PRIMARY_COMMAND, &[0x0c]); in ocw3()
933 data.pic.read(PIC_PRIMARY_COMMAND, &mut data_read); in ocw3()
942 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in fake_irq_on_primary_irq2()
945 data.pic.service_irq(/*irq=*/ 2, /*level=*/ true); in fake_irq_on_primary_irq2()
947 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 7)); in fake_irq_on_primary_irq2()
954 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in edge_trigger_mode()
957 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in edge_trigger_mode()
959 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 4)); in edge_trigger_mode()
961 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in edge_trigger_mode()
965 data.pic.write(PIC_PRIMARY_COMMAND, &[0x20]); in edge_trigger_mode()
972 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in level_trigger_mode()
975 data.pic.write(PIC_PRIMARY_ELCR, &[0x10]); in level_trigger_mode()
978 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in level_trigger_mode()
980 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 4)); in level_trigger_mode()
982 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in level_trigger_mode()
986 data.pic.write(PIC_PRIMARY_COMMAND, &[0x20]); in level_trigger_mode()
993 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in specific_eoi()
996 data.pic.service_irq(/*irq=*/ 4, /*level=*/ true); in specific_eoi()
997 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 4)); in specific_eoi()
1001 data.pic.write(PIC_PRIMARY_COMMAND, &[0x63]); in specific_eoi()
1002 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 4); in specific_eoi()
1005 data.pic.write(PIC_PRIMARY_COMMAND, &[0x64]); in specific_eoi()
1006 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in specific_eoi()
1013 icw_init_both(&mut data.pic); in rotate_on_auto_eoi()
1016 data.pic.write(PIC_PRIMARY_COMMAND, &[0x00]); in rotate_on_auto_eoi()
1019 data.pic.service_irq(/*irq=*/ 5, /*level=*/ true); in rotate_on_auto_eoi()
1020 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 5)); in rotate_on_auto_eoi()
1021 data.pic.service_irq(/*irq=*/ 5, /*level=*/ false); in rotate_on_auto_eoi()
1024 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in rotate_on_auto_eoi()
1025 assert_eq!(data.pic.pics[PicSelect::Primary as usize].imr, 0); in rotate_on_auto_eoi()
1026 assert_eq!(data.pic.pics[PicSelect::Primary as usize].last_irr, 0); in rotate_on_auto_eoi()
1027 assert_eq!(data.pic.pics[PicSelect::Primary as usize].priority_add, 0); in rotate_on_auto_eoi()
1030 data.pic.write(PIC_PRIMARY_COMMAND, &[0x80]); in rotate_on_auto_eoi()
1033 data.pic.service_irq(/*irq=*/ 5, /*level*/ true); in rotate_on_auto_eoi()
1034 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 5)); in rotate_on_auto_eoi()
1035 data.pic.service_irq(/*irq=*/ 5, /*level=*/ false); in rotate_on_auto_eoi()
1038 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in rotate_on_auto_eoi()
1039 assert_eq!(data.pic.pics[PicSelect::Primary as usize].priority_add, 6); in rotate_on_auto_eoi()
1046 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in rotate_on_specific_eoi()
1049 data.pic.service_irq(/*irq=*/ 5, /*level=*/ true); in rotate_on_specific_eoi()
1050 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 5)); in rotate_on_specific_eoi()
1051 data.pic.service_irq(/*irq=*/ 5, /*level=*/ false); in rotate_on_specific_eoi()
1055 data.pic.write(PIC_PRIMARY_COMMAND, &[0xe4]); in rotate_on_specific_eoi()
1057 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 1 << 5); in rotate_on_specific_eoi()
1060 data.pic.write(PIC_PRIMARY_COMMAND, &[0xe5]); in rotate_on_specific_eoi()
1062 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in rotate_on_specific_eoi()
1063 assert_eq!(data.pic.pics[PicSelect::Primary as usize].priority_add, 6); in rotate_on_specific_eoi()
1070 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in rotate_non_specific_eoi()
1073 data.pic.service_irq(/*irq=*/ 5, /*level=*/ true); in rotate_non_specific_eoi()
1074 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 5)); in rotate_non_specific_eoi()
1075 data.pic.service_irq(/*irq=*/ 5, /*level=*/ false); in rotate_non_specific_eoi()
1078 data.pic.write(PIC_PRIMARY_COMMAND, &[0xa0]); in rotate_non_specific_eoi()
1081 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in rotate_non_specific_eoi()
1082 assert_eq!(data.pic.pics[PicSelect::Primary as usize].priority_add, 6); in rotate_non_specific_eoi()
1089 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in no_op_ocw2()
1092 data.pic.service_irq(/*irq=*/ 5, /*level=*/ true); in no_op_ocw2()
1093 assert_eq!(data.pic.get_external_interrupt(), Some(0x08 + 5)); in no_op_ocw2()
1094 data.pic.service_irq(/*irq=*/ 5, /*level=*/ false); in no_op_ocw2()
1096 let orig = data.pic.pics[PicSelect::Primary as usize].clone(); in no_op_ocw2()
1099 data.pic.write(PIC_PRIMARY_COMMAND, &[0x40]); in no_op_ocw2()
1102 assert_eq!(orig, data.pic.pics[PicSelect::Primary as usize]); in no_op_ocw2()
1109 icw_init_both_with_icw4(&mut data.pic, FULLY_NESTED_NO_AUTO_EOI); in cascade_irq()
1112 data.pic.service_irq(/*irq=*/ 12, /*level=*/ true); in cascade_irq()
1114 assert_eq!(data.pic.pics[PicSelect::Primary as usize].irr, 1 << 2); in cascade_irq()
1115 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 1 << 4); in cascade_irq()
1117 assert_eq!(data.pic.get_external_interrupt(), Some(0x70 + 4)); in cascade_irq()
1120 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].irr, 0); in cascade_irq()
1121 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 1 << 4); in cascade_irq()
1128 data.pic.write(PIC_PRIMARY_COMMAND, &[0x20]); in cascade_irq()
1130 data.pic.write(PIC_SECONDARY_COMMAND, &[0xa0]); in cascade_irq()
1132 assert_eq!(data.pic.pics[PicSelect::Primary as usize].isr, 0); in cascade_irq()
1133 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].isr, 0); in cascade_irq()
1134 assert_eq!(data.pic.pics[PicSelect::Secondary as usize].priority_add, 5); in cascade_irq()