void _benmain(void) { int i; int c = 0; int keybuf[128]={0}; struct FIFO32 fifo; struct TIMER *timer; fifo32_init(&fifo, 128, keybuf); struct TSS32 tss_a, tss_c; env_init(); /* keyboard setting */ init_kb(&fifo, 256); i=0; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_c.ldtr = 0; tss_c.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); task_init(memman); /* Unfortunate try the switch back to 3*8 (_benmain) with farjmp but not working. * And the reason still unknown. * So that I use another thread_kb_io() to catch the keyboard interrupt. */ load_tr(3 * 8); // record current working task to tss_a task_create((int) &thread_kb_io, memman, "bshell"); /* strange issue encountered if run pci_init at the setup_hw() */ puts("pci scan bus\n"); pci_init(); for (;;) { asm_cli(); if (fifo32_status(&fifo) == 0) { asm_stihlt(); // wake while keyboard input // got a interrupt } else { /* scan_code input */ c=fifo32_get(&fifo); asm_sti(); if (c == 1) { farjmp(0, 4*8); } else { puts("disabled boot options.\n"); } } } puts("\nSystem Halted \n"); _syshalt(); }
void setup_hw(void) { asm_cli(); puts("init gdt and idt\n"); init_gdtidt(); puts("init pic\n"); init_pic(); outb(PIC0_IMR, 0xf8); /* allow PIT, PIC1 and keyboard */ outb(PIC1_IMR, 0xef); /* allow mouse */ outb(0x20, 0x20); asm_sti(); puts("init pit\n"); init_pit(); puts("setup hardware done\n"); }
void floppy_init_dma(uintptr_t buffer, size_t len, int write) { asm_cli(); outportb(0x0a, 0x06); /* mask DMA channel 2 */ floppy_reset_flipflop_dma(); outportb(0x4, buffer & 0xFF); outportb(0x4, (buffer >> 8) & 0xFF); floppy_reset_flipflop_dma(); len--; outportb(0x5, len & 0xFF); outportb(0x5, len >> 8); outportb(0x81, buffer >> 16); outportb(0x0b, (write ? 0x48: 0x44) + 2); /* single transfer, write or read, channel 2 */ outportb(0x0a, 0x02); /* unmask DMA channel 2 */ asm_sti(); }