int main(int argc,char **argv) { unsigned int req_ver = 0; unsigned int dont_disconnect = 0; unsigned int req_mode = APM_CONNECT_NONE; const char *action = NULL; int i; for (i=1;i < argc;) { const char *a = argv[i++]; if (*a == '/' || *a == '-') { do { a++; } while (*a == '/' || *a == '-'); if (!strncmp(a,"v1.",3)) { a += 3; req_ver = 0x100 + (atoi(a) & 0xFF); } else if (!strcmp(a,"vn")) { req_ver = REQ_VER_NONE; } else if (!strcmp(a,"nd")) { dont_disconnect = 1; } else if (!strcmp(a,"h") || !strcmp(a,"help")) { help(); } else if (!strncmp(a,"if:",3)) { a += 3; if (!strcmp(a,"real")) req_mode = APM_CONNECT_REALMODE; else if (!strcmp(a,"16pm")) req_mode = APM_CONNECT_16_PM; else if (!strcmp(a,"32pm")) req_mode = APM_CONNECT_32_PM; else { fprintf(stderr,"Unknown interface %s\n",a); return 1; } } else { fprintf(stderr,"Unknown param '%s'\n",a); help(); return 1; } } else if (action == NULL) { action = a; } else { fprintf(stderr,"Unknown param\n"); return 1; } } if (!probe_8254()) { printf("Cannot init 8254 timer\n"); return 1; } if (!probe_8259()) { printf("Cannot init 8259 PIC\n"); return 1; } probe_dos(); detect_windows(); if (!apm_bios_probe()) { printf("APM BIOS not found\n"); return 1; } if (req_mode == APM_CONNECT_NONE) req_mode = APM_CONNECT_REALMODE; printf("APM BIOS v%u.%u: ",apm_bios->major,apm_bios->minor); if (apm_bios->flags & APM_FL_16BIT_PM) printf("[16-bit pm] "); if (apm_bios->flags & APM_FL_32BIT_PM) printf("[32-bit pm] "); if (apm_bios->flags & APM_FL_CPU_IDLE_SLOWS) printf("[cpu-idle-slow] "); if (apm_bios->flags & APM_FL_PM_DISABLED) printf("[disabled] "); if (apm_bios->flags & APM_FL_PM_DISENGAGED) printf("[disengaged] "); printf("\n"); if (req_ver >= 0x100) apm_bios->version_want = req_ver; if (req_ver != REQ_VER_NONE) { if (!apm_bios_connect(req_mode)) { fprintf(stderr,"Failed to connect to APM BIOS (last=0x%02X)\n",apm_bios->last_error); return 1; } printf("Connected to APM BIOS v%u.%u interface\n",apm_bios->major_neg,apm_bios->minor_neg); printf(" batteries: %u\n",apm_bios->batteries); printf(" capabilities:\n"); if (apm_bios->capabilities & 1) printf(" Can enter global standby state\n"); if (apm_bios->capabilities & 2) printf(" Can enter global suspend state\n"); if (apm_bios->capabilities & 4) printf(" Resume timer will wake from standby\n"); if (apm_bios->capabilities & 8) printf(" Resume timer will wake from suspend\n"); if (apm_bios->capabilities & 16) printf(" Resume on ring will wake from standby\n"); if (apm_bios->capabilities & 32) printf(" Resume on ring will wake from suspend\n"); if (apm_bios->capabilities & 64) printf(" PCMCIA ring indicator will wake up from standby\n"); if (apm_bios->capabilities & 128) printf(" PCMCIA ring indicator will wake up from suspend\n"); printf("\n"); } if (action == NULL) { } else if (!strcmp(action,"cpu-idle")) { printf("Issuing CPU idle command\n"); if (!apm_bios_cpu_idle()) fprintf(stderr,"CPU Idle failed\n"); } else if (!strcmp(action,"cpu-busy")) { printf("Issuing CPU busy command\n"); if (!apm_bios_cpu_busy()) fprintf(stderr,"CPU Busy failed\n"); } else if (!strcmp(action,"events")) { while (1) { signed long ev = apm_bios_pm_evnet(); if (ev >= 0LL) { printf("Event 0x%04X\n",(unsigned int)ev); } if (kbhit()) { if (getch() == 27) break; } } } else if (!strcmp(action,"status")) { apm_bios_update_status(); printf("AC=0x%X Batt=0x%X BattFlag=0x%X BattPercent=%u BattLife=%u%s\n", apm_bios->status_ac, apm_bios->status_battery, apm_bios->status_battery_flag, apm_bios->status_battery_life, apm_bios->status_battery_time&0x7FFF, (apm_bios->status_battery_time&0x8000)?"m":"s"); } else if (!strcmp(action,"standby")) { if (!apm_bios_power_state(APM_POWER_STANDBY)) fprintf(stderr,"Unable to set power state\n"); } else if (!strcmp(action,"suspend")) { if (!apm_bios_power_state(APM_POWER_SUSPEND)) fprintf(stderr,"Unable to set power state\n"); } else if (!strcmp(action,"off")) { if (!apm_bios_power_state(APM_POWER_OFF)) fprintf(stderr,"Unable to set power state\n"); } if (req_ver != REQ_VER_NONE && !dont_disconnect) { if (!apm_bios_connect(APM_CONNECT_NONE)) { fprintf(stderr,"Failed to disconnect\n"); } printf("Disconnected APM BIOS\n"); } return 0; }
int main(int argc,char **argv) { struct acpi_rsdt_header sdth; acpi_memaddr_t addr; unsigned long i,max; uint32_t tmp32,tmplen; char tmp[32]; for (i=1;i < (unsigned long)argc;) { const char *a = argv[(unsigned int)(i++)]; if (*a == '-' || *a == '/') { do { a++; } while (*a == '-' || *a == '/'); if (!strcmp(a,"?") || !strcmp(a,"h") || !strcmp(a,"help")) { help(); return 1; } else if (!strcmp(a,"32")) { acpi_use_rsdt_32 = 1; } else { fprintf(stderr,"Unknown switch '%s'\n",a); help(); return 1; } } else { fprintf(stderr,"Unknown arg '%s'\n",a); help(); return 1; } } if (!probe_8254()) { printf("Cannot init 8254 timer\n"); return 1; } if (!probe_8259()) { printf("Cannot init 8259 PIC\n"); return 1; } cpu_probe(); probe_dos(); detect_windows(); #if TARGET_MSDOS == 32 probe_dpmi(); dos_ltp_probe(); #endif #if TARGET_MSDOS == 16 if (!flatrealmode_setup(FLATREALMODE_4GB)) { printf("Unable to set up flat real mode (needed for 16-bit builds)\n"); printf("Most ACPI functions require access to the full 4GB range.\n"); return 1; } #endif if (!acpi_probe()) { printf("ACPI BIOS not found\n"); return 1; } assert(acpi_rsdp != NULL); printf("ACPI %u.0 structure at 0x%05lX\n",acpi_rsdp->revision+1,(unsigned long)acpi_rsdp_location); memcpy(tmp,(char*)(&(acpi_rsdp->OEM_id)),6); tmp[6]=0; printf("ACPI OEM ID '%s', RSDT address (32-bit) 0x%08lX Length %lu\n",tmp, (unsigned long)(acpi_rsdp->rsdt_address), (unsigned long)(acpi_rsdp->length)); if (acpi_rsdp->revision != 0) printf(" XSDT address (64-bit) 0x%016llX\n", (unsigned long long)(acpi_rsdp->xsdt_address)); printf("Chosen RSDT/XSDT at 0x%08llX\n",(unsigned long long)acpi_rsdt_location); if (acpi_rsdt != NULL) { memcpy(tmp,(void*)(acpi_rsdt->signature),4); tmp[4] = 0; printf(" '%s': len=%lu rev=%u\n",tmp,(unsigned long)acpi_rsdt->length, acpi_rsdt->revision); memcpy(tmp,(void*)(acpi_rsdt->OEM_id),6); tmp[6] = 0; printf(" OEM id: '%s'\n",tmp); memcpy(tmp,(void*)(acpi_rsdt->OEM_table_id),8); tmp[8] = 0; printf(" OEM table id: '%s' rev %lu\n",tmp, (unsigned long)acpi_rsdt->OEM_revision); memcpy(tmp,(void*)(&(acpi_rsdt->creator_id)),4); tmp[4] = 0; printf(" Creator: '%s' rev %lu\n",tmp, (unsigned long)acpi_rsdt->creator_revision); } max = acpi_rsdt_entries(); if (acpi_rsdt_is_xsdt()) { printf("Showing XSDT, %lu entries\n",max); } else { printf("Showing RSDT, %lu entries\n",max); } for (i=0;i < max;i++) { addr = acpi_rsdt_entry(i); printf(" [%lu] 0x%08llX ",i,(unsigned long long)addr); if (addr != 0ULL) { tmp32 = acpi_mem_readd(addr); tmplen = 0; memcpy(tmp,&tmp32,4); tmp[4] = 0; if (acpi_probe_rsdt_check(addr,tmp32,&tmplen)) { acpi_memcpy_from_phys(&sdth,addr,sizeof(struct acpi_rsdt_header)); printf("'%s' len=0x%lX rev=%u ",tmp,(unsigned long)tmplen,sdth.revision); memcpy(tmp,&sdth.OEM_id,6); tmp[6] = 0; printf("OEM id: '%s'\n",tmp); memcpy(tmp,&sdth.OEM_table_id,8); tmp[8] = 0; printf("OEM table id: '%s' rev %u ",tmp,sdth.OEM_revision); memcpy(tmp,&sdth.creator_id,4); tmp[4] = 0; printf("Creator id: '%s' rev %u",tmp,sdth.creator_revision); if (!memcmp(sdth.signature,"MCFG",4)) { struct acpi_mcfg_entry entry; uint64_t o = addr + 44; unsigned int count; printf("\nPCI Express map:"); assert(sizeof(struct acpi_mcfg_entry) == 16); count = (unsigned int)(tmplen / sizeof(struct acpi_mcfg_entry)); while (count != 0) { acpi_memcpy_from_phys(&entry,o,sizeof(struct acpi_mcfg_entry)); o += sizeof(struct acpi_mcfg_entry); /* Some bioses I test against seem to return enough for 3 but fill in only 1? */ if (entry.base_address != 0ULL || entry.start_pci_bus_number != 0 || entry.end_pci_bus_number != 0) { uint64_t sz; if (entry.start_pci_bus_number > entry.end_pci_bus_number) entry.start_pci_bus_number = entry.end_pci_bus_number; sz = (((unsigned long long)(entry.end_pci_bus_number - entry.start_pci_bus_number)) + 1ULL) << 20ULL; printf("\n @0x%08llX-0x%08llX seg=%u bus=%u-%u", (unsigned long long)entry.base_address, (unsigned long long)(entry.base_address + sz - 1ULL), (unsigned int)entry.pci_segment_group_number, (unsigned int)entry.start_pci_bus_number, (unsigned int)entry.end_pci_bus_number); } count--; } } } else { printf("'%s' check failed",tmp); } } printf("\n"); } acpi_free(); return 0; }
int main() { struct t8254_readback_t readback; t8254_time_t tick[3]; unsigned int i; printf("8254 library test program\n"); if (!probe_8254()) { printf("Chip not present. Your computer might be 2010-era hardware that dropped support for it.\n"); return 1; } if (!probe_8259()) { printf("8259 interrupt controller not present. Your computer might be 2010-era hardware that dropped support for it.\n"); return 1; } printf("8254 base clock: %luHz\n",T8254_REF_CLOCK_HZ); speaker_rate = T8254_REF_CLOCK_HZ / 400UL; /* 400Hz */ prev_irq0 = _dos_getvect(T8254_IRQ+0x08); _dos_setvect(T8254_IRQ+0x8,irq0); _cli(); write_8254_pc_speaker(speaker_rate); write_8254_system_timer(max); _sti(); #ifdef TARGET_PC98 /* PC-98 does not have IRQ0 running by default */ p8259_unmask(T8254_IRQ); #endif while (1) { if (kbhit()) { int c = getch(); if (c == 27) break; else if (c == '-') { max -= 80; if (max > (0xFFFF-80)) max = 0xFFFF; _cli(); write_8254_system_timer(max); _sti(); } else if (c == '=') { max += 110; if (max < 110 || max > (0xFFFF-110)) max = 0xFFFF; _cli(); write_8254_system_timer(max); _sti(); } /* play with timer 2 and the PC speaker gate */ else if (c == 'p') { unsigned char on = (t8254_pc_speaker_read_gate() != 0) ? 1 : 0; if (on) t8254_pc_speaker_set_gate(0); else t8254_pc_speaker_set_gate(3); } else if (c == '1') { #ifndef TARGET_PC98 unsigned char v = t8254_pc_speaker_read_gate(); t8254_pc_speaker_set_gate(v ^ PC_SPEAKER_OUTPUT_TTL_AND_GATE); #endif } else if (c == '2') { #ifndef TARGET_PC98 unsigned char v = t8254_pc_speaker_read_gate(); t8254_pc_speaker_set_gate(v ^ PC_SPEAKER_COUNTER_2_GATE); #endif } else if (c == '[') { speaker_rate += 110; if (speaker_rate > (0xFFFF-110) || speaker_rate < 110) speaker_rate = 0xFFFF; write_8254_pc_speaker(speaker_rate); } else if (c == ']') { speaker_rate -= 110; if (speaker_rate > (0xFFFF-110)) speaker_rate = 0; write_8254_pc_speaker(speaker_rate); } else if (c == 'w') { printf("\n"); pulse_width_test(); _cli(); write_8254_system_timer(max); _sti(); printf("\n"); } else if (c == 'z') { /* sleep-wait loop test */ unsigned long delay_ticks; unsigned long z; unsigned int c,cmax; printf("\nDelay interval in us? "); z = 1000000; scanf("%lu",&z); delay_ticks = t8254_us2ticks(z); printf(" %lu = %lu ticks\n",z,delay_ticks); if (delay_ticks == 0UL) cmax = (unsigned int)(T8254_REF_CLOCK_HZ / 20UL); else cmax = (unsigned int)(T8254_REF_CLOCK_HZ / 20UL / (unsigned long)delay_ticks); if (cmax == 0) cmax = 1; write_8254_pc_speaker(T8254_REF_CLOCK_HZ / 400UL); /* tick as fast as possible */ while (1) { if (kbhit()) { if (getch() == 27) break; } for (c=0;c < cmax;c++) { t8254_pc_speaker_set_gate(3); t8254_wait(delay_ticks); t8254_pc_speaker_set_gate(0); t8254_wait(delay_ticks); } } } else if (c == 'd') { printf("\n \nDetail mode, hit 'd' again to exit: [WARNING: 8254 only]\n"); while (1) { if (kbhit()) { int c = getch(); if (c == 'd') { break; } } _cli(); readback_8254(T8254_READBACK_ALL,&readback); _sti(); printf("\x0D"); for (i=0;i <= 2;i++) { printf("[%u] stat=%02x count=%04x ",i, readback.timer[i].status, readback.timer[i].count); } fflush(stdout); } printf("\n"); } } for (i=0;i <= 2;i++) tick[i] = read_8254(i); /* BUG: DOSBox/DOSBox-X appear to have a bug where the PC speaker readback toggles * regardless of the GATE input to Counter 2. Bring GATE low (setting bit 1 * of port 61h to 0) is supposed to cause Counter 2 to stop. The AND gate * after the output (bit 0 of port 61h) is not supposed to affect the readback. */ printf("\x0D %04x %04x %04x max=%04x count=%04x SPKR=%u",tick[0],tick[1],tick[2], max,counter,read_8254_pc_speaker_output()!=0?1:0); fflush(stdout); } printf("\n"); #ifdef TARGET_PC98 /* PC-98 does not have IRQ0 running by default */ p8259_mask(T8254_IRQ); #endif _cli(); write_8254_pc_speaker(0); t8254_pc_speaker_set_gate(0); _dos_setvect(T8254_IRQ+0x8,prev_irq0); _sti(); write_8254_system_timer(0xFFFF); /* restore normal function to prevent BIOS from going crazy */ return 0; }