display.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* display command: print resolution, color depth, and other graphics info. */
  2. #include "io.h"
  3. #include "vga.h"
  4. #include "gpu.h"
  5. #include "ati.h"
  6. #include "fbtext.h"
  7. static void put_uint(unsigned int n)
  8. {
  9. char buf[12];
  10. char *p = buf + sizeof(buf) - 1;
  11. *p = '\0';
  12. if (n == 0) {
  13. io_putchar('0');
  14. return;
  15. }
  16. while (n) {
  17. *--p = (char)('0' + (n % 10));
  18. n /= 10;
  19. }
  20. while (*p)
  21. io_putchar(*p++);
  22. }
  23. static void put_hex(unsigned int n)
  24. {
  25. static const char hex[] = "0123456789ABCDEF";
  26. io_putstr("0x");
  27. if (n == 0) {
  28. io_putchar('0');
  29. return;
  30. }
  31. {
  32. char buf[9];
  33. char *q = buf + 8;
  34. *q = '\0';
  35. while (n) {
  36. *--q = hex[n & 0xF];
  37. n >>= 4;
  38. }
  39. while (*q)
  40. io_putchar(*q++);
  41. }
  42. }
  43. void program_display_main(void)
  44. {
  45. io_putstr("resolution ");
  46. put_uint(vga_fb_width());
  47. io_putstr(" x ");
  48. put_uint(vga_fb_height());
  49. io_putchar('\n');
  50. io_putstr("color depth ");
  51. put_uint(vga_fb_bpp());
  52. io_putstr(" bpp\n");
  53. io_putstr("pitch ");
  54. put_uint(vga_fb_pitch());
  55. io_putstr(" bytes/line\n");
  56. io_putstr("VRAM ");
  57. put_uint(vga_fb_vram_kb());
  58. io_putstr(" KB\n");
  59. io_putstr("LFB ");
  60. put_hex((unsigned int)(unsigned long)vga_fb_ptr());
  61. io_putchar('\n');
  62. {
  63. unsigned int pci_id = vga_fb_pci_id();
  64. if (pci_id) {
  65. io_putstr("GPU ");
  66. io_putstr(gpu_vendor_name());
  67. io_putstr(" PCI ");
  68. put_hex(pci_id & 0xFFFF);
  69. io_putchar(':');
  70. put_hex(pci_id >> 16);
  71. io_putchar('\n');
  72. }
  73. }
  74. if (gpu_vendor() == GPU_VENDOR_ATI) {
  75. unsigned int method = ati_mmio_method();
  76. if (method) {
  77. io_putstr("ATI CRTC ");
  78. put_hex(ati_off_pitch_before());
  79. io_putstr(" -> ");
  80. put_hex(ati_off_pitch_after());
  81. io_putstr(" via ");
  82. if (method == 1)
  83. io_putstr("BAR2");
  84. else if (method == 2)
  85. io_putstr("LFB+8M");
  86. else if (method == 3)
  87. io_putstr("LFB+4M");
  88. else if (method == 4)
  89. io_putstr("IO");
  90. io_putchar('\n');
  91. }
  92. }
  93. io_putstr("text ");
  94. put_uint(fbtext_get_cols());
  95. io_putstr(" x ");
  96. put_uint(fbtext_get_rows());
  97. io_putstr(" chars\n");
  98. }