format binary use16 org 0x7c00 DMA_BUF = 0x7e00 cld xor ax, ax mov ds, ax mov es, ax ; clear DMA buffer mov di, DMA_BUF xor ax, ax mov cx, 256 repnz stosw ; two TRIM requests (both are the same: one sector, starting at sector index 1) mov di, DMA_BUF mov dword [di+ 0], 0x00000001 mov dword [di+ 4], 0x00010000 mov dword [di+ 8], 0x00000001 mov dword [di+12], 0x00010000 ; find IDE PCI device mov ax, 0xb102 mov dx, 0x8086 mov cx, 0x7010 xor si, si int 0x1a ; bx has PCI address push bx ; enable BM+MEM+IO mov di, 0x04 ; command/status mov ax, 0xb10a ; read config dword int 0x1a pop bx push bx or cl, 0x7 ; BM+MEM+IO mov di, 0x04 mov ax, 0xb10d ; write config dword int 0x1a pop bx push bx ; read BAR4 (DMA I/O space) mov di, 0x20 ; bar4 mov ax, 0xb10a int 0x1a and cx, 0xfffc ; DMA I/O base push cx mov dx, cx ; set up DMA xor al, al ; status: 0 out dx, al mov al, 0x04 ; clear pending interrupts add dx, 2 out dx, al mov eax, prdt add dx, 2 out dx, eax ; send TRIM command mov dx, 0x1f0 mov si, dsm_trim_cmd mov cx, 8 out_loop: lodsb out dx, al inc dx loop out_loop ; start DMA transfer pop dx mov al, 0x01 out dx, al ; immediately reset device, cancelling ongoing TRIM mov dx, 0x3f6 mov al, 0x04 out dx, al cli hlt dsm_trim_cmd: db 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x06 pciaddr: dw ? align(8) prdt: dd DMA_BUF dd 512 or 0x80000000 times 510-($-$$) db 0 dw 0xaa55 times 512 db 0