Graphics driver programming =========================== Parameters at config.mnt: graphics_driver = Drivers filename graphics_driver_init = 0/1 = No/Yes graphics_boot_set = 0/1 = Vesa/Driver graphics_boot_x = X resolution for driver graphics_boot_y = Y resolution for driver graphics_boot_hz = Frequency for driver General driver steps: 1) Kernel loads driver (config.mnt/graphics_driver) 2) If graphics_driver_init = 1, kernel scans PCI for matching device ID's from drivers header. 3) If PCI match is found, kernel executes driver_entry functions 1 and 2. If graphics_boot_set = 1 and graphics_driver_init = 1, kernel also executes driver_entry function 4 with x, y and hz parameters. 4) During OS execution, kernel calls functions 1-5 when needed. Memory references within the driver: ; Relative mov [testaddr], rax ; Absolute mov rdi , testaddr add rdi , rbp ; rbp = driver base address, set by os. mov [rdi], rax testaddr: dq 0x0 Driver is executed at ring-0 privelidge level. Functions 0-31 are reserved, others available for other use. If needed, set page uncacheable with system call 400. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; PCI graphics card driver for MenuetOS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; use64 db 'MENUET64' ; Header dq 0x103 ; PCI Graphics driver dq driver_entry ; Driver entry dq image_end ; Size of image dq image_end ; Required memory (max 4mb) dd 0x11111111 ; Supported PCI card 1 dd 0x22222222 ; Supported PCI card 2, .. dd 0x00000000 ; End db "Newcard interface",0 ; Device db "Newco",0 ; Manufacturer inbytes: dq 0x0 ; Received bytes outbytes: dq 0x0 ; Sent bytes status: dq 0x0 ; 0x00 = driver not initialized ; 0x01 = device is working properly ; 0xff = undefined error driver_entry: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Driver entry from OS. ; ; In : rax 1 - Init ; 2 - Reset ; 3 - Get all modes ; 4 - Set mode ; 5 - Get current mode ; ; rbp - Driver location in linear memory ; r13 - PCI position [pci_bus] shl 16 + [pci_dev] shl 8 ; r14 - Entry point for drivers internal system calls ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cmp rax , 1 je card_init cmp rax , 2 je card_reset cmp rax , 3 je card_get_all cmp rax , 4 je card_set_mode cmp rax , 5 je card_get_mode mov rax , 0xff ; function not supported ret card_init: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Init driver ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Out: mov rax , 1 ; 1=fail mov rbx , 0 ret mov rax , 0 ; 0=success mov rbx , 11111b ; bitfield - supported functions ret card_reset: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Init driver ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Out: mov rax , 1 ; 1=fail mov rbx , 0 ret mov rax , 0 ; 0=success mov rbx , 0 ret card_get_all: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Return all supported graphics modes ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; In: rcx - entry num (0+) ; Out: mov rax , 0 ; 0/1 - present/not found mov rbx , 0 ; parameter format mov rcx , x_resolution mov rdx , y_resolution mov r8 , frequency (in 0.01 hz's) mov r9 , lfb_start mov r10 , scanline_in_bytes mov r11 , bytes_per_pixel (3/4) ret card_set_mode: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Set graphics mode ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; In: mov rbx , 0 ; parameter format mov rcx , x_resolution mov rdx , y_resolution mov r8 , frequency (in 0.01 hz's) mov r9 , lfb_start mov r10 , scanline_in_bytes mov r11 , bytes_per_pixel (3/4) ; Out: mov rax , 0 ; 0/1 - success/fail mov rbx , 0 ; parameter format mov rcx , x_resolution mov rdx , y_resolution mov r8 , frequency (in 0.01 hz's) mov r9 , lfb_start mov r10 , scanline in bytes mov r11 , bytes_per_pixel (3/4) ret card_get_mode: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Get current graphics mode ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Out: mov rax , 0 ; 0/1 - success/fail mov rbx , 0 ; parameter format ; Set following values to zero if card has not initialized ; a graphics mode. Value zero equals to undefined. mov rcx , x_resolution mov rdx , y_resolution mov r8 , frequency (in 0.01 hz's) mov r9 , lfb_start mov r10 , scanline_in_bytes mov r11 , bytes_per_pixel (3/4) ret image_end: