Graphics driver programming - static address ============================================ With this example, you can write a static memory address driver, which greatly simplifies driver programming. You just need to check that driver address at rbp matches the assembled base address. Enable driver_development in config.mnt to load non-certified drivers. Graphics driver 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. Driver is executed at ring-0 privelidge level. Functions 0-31 are reserved, others available for other use. If needed, set page non-cacheable with system call 400. Driver memory consists of two 2MB pages. First page for code and internal driver data, the second page for data communication between driver and device. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; PCI graphics card driver for MenuetOS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; driver_base equ (0x100000*64) use64 org driver_base db 'MENUET64' ; Header dq 0x103 ; PCI Graphics driver dq driver_entry-driver_base; 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 5,105,400 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cmp rbp , driver_base je addressfine mov [status],dword 0xff mov rax , 0xff ret addressfine: 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 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; If needed, set next 2M page non-cacheable with system call 400 ; for data transfer to the device ; mov rax , 400 ; mov rbx , 1 ; mov rcx , driver_base+0x100000*2 ; call r14 ; syscall entry ; Success mov [status],dword 1 mov rbx , 11111b ; bitfield - supported functions mov rax , 0 ret ; Fail mov [status],dword 0xff mov rbx , 0 mov rax , 1 ret card_reset: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Init driver ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov rax , 0 ; 0=success mov rbx , 0 ret mov rax , 1 ; 1=fail 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 ; ; Driver data ; parameter1: dq 0x0 parameter2: dq 0x0 ; ; Non-cacheable data between driver and device ; org (driver_base+0x100000*2) structure1: ; .. structure2: ; .. image_end: