Linux To Win32

Тема в разделе "WASM.ASSEMBLER", создана пользователем elgrru, 27 май 2007.

  1. elgrru

    elgrru New Member

    Публикаций:
    0
    Регистрация:
    27 май 2007
    Сообщения:
    4
    Здраствуй многоуважаемый ALL!

    Делаю драйверную имплементацию работы с PCIBIOS под виндос. Найден кусок памяти с сервисными функциями:
    PCIBIOS_PCI_BIOS_PRESENT, PCIBIOS_FIND_PCI_DEVICE, PCIBIOS_READ_CONFIG_BYTE, PCIBIOS_READ_CONFIG_WORD и т.п., которые необходимо вызвать

    Подскажите пожалуйста, Как повторить нижний пример на асемблере под Win32?
    Спасибо, Игорь.

    Пример из Линукса, который это делает:
    Код (Text):
    1. static struct {
    2.     unsigned long address;
    3.     unsigned short segment;
    4. } pci_indirect = { 0, KERNEL_CS };
    5.  
    6. static int pci_bios_find_device(unsigned short vendor, unsigned short device_id, unsigned short index, unsigned char *bus, unsigned char *device_fn)
    7. {
    8.     unsigned short bx;
    9.     unsigned short ret;
    10.     unsigned long flags;
    11.  
    12.     save_flags(flags); cli();
    13.     __asm__("lcall (%%edi)\n\t"
    14.         "jc 1f\n\t"
    15.         "xor %%ah, %%ah\n"
    16.         "1:"
    17.         : "=b" (bx),
    18.           "=a" (ret)
    19.         : "1" (PCIBIOS_FIND_PCI_DEVICE),
    20.           "c" (device_id),
    21.           "d" (vendor),
    22.           "S" ((int) index),
    23.           "D" (&pci_indirect));
    24.     restore_flags(flags);
    25.     *bus = (bx >> 8) & 0xff;
    26.     *device_fn = bx & 0xff;
    27.     return (int) (ret & 0xff00) >> 8;
    28. }
    Кроме того, есть след описание для данного вызова:

    The BIOS32 Service Directory is accessed by doing a CALL FAR to the entry point provided in the Service data structure. This function returns the location of PCI devices that have a specific Class Code. Given a Class Code and a Index (N), the function returns the Bus Number, Device Number, and Function Number of the Nth Device/Function whose Class Code matches the input parameters.
    ENTRY:
    [AH] PCI_FUNCTION_ID
    [AL] FIND_PCI_CLASS_CODE
    [ECX] Class Code (in lower three bytes)
    [SI] Index (0...N)
    EXIT:
    [BH] Bus Number (0...255)
    [BL] Device Number in upper 5 bits, Function Number in bottom 3 bits
    [AH] Return Code: SUCCESSFUL, DEVICE_NOT_FOUND
    [CF] Completion Status, set = error, cleared = success.

    Calling software can find all devices having the same Class Code by making successive
    calls to this function starting with Index set to zero, and incrementing it until the return
    code is ’DEVICE_NOT_FOUND’.


    PS. Найденный сервисный адрес - "физический" я его предварительно отмапил на виртуальное пространство с помощью MmMapIoSpace
     
  2. Bob

    Bob New Member

    Публикаций:
    0
    Регистрация:
    2 авг 2004
    Сообщения:
    112
    Адрес:
    Ukraine
    А почему не хочешь прямой ввод\вывод делать? Ведь BIOS32 может и не быть.
     
  3. elgrru

    elgrru New Member

    Публикаций:
    0
    Регистрация:
    27 май 2007
    Сообщения:
    4
    HAL используется но не всегда помогает :). PCI-to-PCI brige не могут быть перепрограммированы HAL функциями:

    A call to HalSetBusData or HalSetBusDataByOffset fails if the target device is a PCI bridge device and the data to be written is within the PCI common configuration space header. This behavior is by-design, because these functions are used only for programming nonbridge devices.

    То что не работает уже проверено, PCI bios спасенье
     
  4. Bob

    Bob New Member

    Публикаций:
    0
    Регистрация:
    2 авг 2004
    Сообщения:
    112
    Адрес:
    Ukraine
    не, я не про HAL. Про Configuration Mechanism #1, прямая запись в порты
     
  5. rei3er

    rei3er maxim

    Публикаций:
    0
    Регистрация:
    15 янв 2007
    Сообщения:
    917
    Адрес:
    minsk
    Код (Text):
    1. static struct {
    2.     unsigned long address;
    3.     unsigned short segment;
    4. } pci_indirect = { 0, KERNEL_CS };
    5.  
    6. static int pci_bios_find_device(unsigned short vendor, unsigned short device_id, unsigned short index, unsigned char *bus, unsigned char *device_fn)
    7. {
    8.     unsigned short __bx;
    9.     unsigned short ret;
    10.     unsigned long flags;
    11.  
    12.         void *__pci_indirect = &pci_indirect;
    13.         asm {
    14.             pushfd
    15.             cli
    16.             mov eax, PCIBIOS_FIND_PCI_DEVICE
    17.             mov ecx, device_id
    18.             mov edx, vendor
    19.             mov esi, index
    20.             mov edi, __pci_indirect
    21.             call far dword ptr [edi]
    22.             jc short $ + 2
    23.             xor ah, ah
    24.             mov ret, eax
    25.             mov __bx, ebx
    26.             popfd
    27.         }
    28.     *bus = (__bx >> 8) & 0xff;
    29.     *device_fn = __bx & 0xff;
    30.     return (int) (ret & 0xff00) >> 8;
    31. }
     
  6. elgrru

    elgrru New Member

    Публикаций:
    0
    Регистрация:
    27 май 2007
    Сообщения:
    4
    Огромное СПАСИБО!!!