Reputation: 197
I have successfully opened a file and have the file descriptor (7) stored in FILE, and I also have the size of the file (153kb) stored in SIZE. That being said, this mmap system call returns a -14. I'm not sure what I'm doing wrong
push %esi #Save non-general-purpose registers
push %edi #Save non-general-purpose registers
push %ebp #Save non-general-purpose registers
movl FILE, %edi #Move file descriptor into edi
movl $0, %ebp #Offset to 0
movl $0x2, %esi #MAP_PRIVATE
movl $0x3, %edx #PROT_READ
movl FSIZE, %ecx #File length
movl $0, %ebx # *addr = NULL
movl $90, %eax #mmap Sys Call
int $0x80 #Call kernel
test %eax, %eax #Error check
js _error
Upvotes: 0
Views: 2844
Reputation: 539
MMAP 90 = $5A
Example of MMAP the framebuffer device fb0 using NASM with Intel-Syntax
%define XRes 400h
%define YRes 300h
%define Mapsize (XRes*YRes*4) ; 1024x768x32
section .text
call MAP_FB ; mmap
;----------- Subroutine----
MAP_FB: mov eax, 5 ; syscall nr: open
xor edx, edx
mov ebx, DEVICE ; pointer/offset auf File/Device-Name
mov ecx, 2 ; /usr/include/bits/fcntl.h = O_RDWR
int 80h
mov [FD], eax ; File discriptor
mov ebx, MMAP
mov eax, 5Ah ; mmap(90)
int 80h
mov esi, eax ; pointer mmap-FRAMEBUFFER
ret
section .data
DEVICE DB "/dev/fb0", 0, 0, 0, 0
MMAP: DD 0 ; start - suggest memory address to allocate
DD Mapsize ; length
DD 3 ; prot (PROT_READ + PROT_WRITE)
DD 1 ; flags (MAP_SHARED = 1)
FD: DD 0 ; file discriptor(handle)
DD 0 ; offset into file to start reading
Upvotes: 1