Writting Directly To Fb


spookyln

Member
Joined
Dec 21, 2006
Messages
107
Location
Czech Republic
Website
www.tbs-software.com
hi, coz i able to write on stdout with no problem in asm.
today i make next step. writing to FB.
but with no luck, Segmentation Fault is my second name :)

please check my code and help me with this.

CODE

format ELF executable
use32
entry start
segment readable executable

start:
; open /dev/fb0
mov r0, sMem-$-8
mov r1, 2; = O_RDWR
swi 0x900005; open
mov r6, r0

; mmap
mov r0, 0
mov r1, 0x10000
mov r2, 3
mov r3, 1
mov r4, r6
mov r5, 0xC0000000
stmdb sp!, {r0, r1, r2, r3, r4, r5}
swi 0x90005A;mmap
;add sp, sp, 24
mov r7, r0

mov r1, 0xFFFFFFFF
mov r2, 0
loop:
str r1, [r0, 4]
add r2, r2, 1
cmp r2, 0x12C00 ; 320x240
ble loop

; unmmap
mov r0, r7
mov r1, 0x10000
swi 0x90005B

; close /dev/fb0
mov r0, r6
swi 0x900006; close

;cd /usr/gp2x
add r0,pc,MenuDir-$-8
swi 0x90000c;chdir

;execute gp2xmenu
add r0,pc,MenuCmd-$-8
mov r1,0;arg2 = NULL
mov r2,0;arg3 = NULL
swi 0x90000b;execve

;exit
mov r0,1
swi 0x900001;exit


sMem: db "/dev/fb0"
MenuDir: db '/usr/gp2x'
MenuCmd: db '/usr/gp2x/gp2xmenu'



i have downloaded .pdf manuals but im not good in english.
examples helps me a lot.
thanks
 
Your mmap seems fishy.

Why are you writing in assembler anyway? Might find it easier to write in C without the standard libs. Code will be as short and compact, but without the mystery.
 
You can try adding "segment readable writeable executable" to the top of your code
Here a bit of code that may help
CODE

;****************************************;
; ARM GP2X DEMO. ;
;----------------------------------------;
; By Dex. ;
; ;
; Demos Basic template, gp2x under linux;
; Coded with FasmARM. ;
; C:\fasmarm test.asm test.gpe ;
; 05/28/07;
;****************************************;
format ELF executable
entry start ; tell linker entry point

segment readable writeable executable

macro adr reg,location { ; simple micro
add reg,pc,location-$-8
}

code32 ; we want to use 32 bits
align 4
start:
; open /dev/mem
adr r0,MemFileName
mov r1,2 ; O_RDWR
swi 0x900005 ; sys_open

adr r1,MmapParamsFd
str r0, [r1]

adr r0,MmapParams
swi 0x90005a

mov r7,r0
add r9,r7,0x1180
mainloop:
ldr r8, [r9, 4]
mov r8, r8
tst r8, 0x4000
bne mainloop

mov r0,0xC0000000
mov r1,0x10000
swi 0x90005B

ldr r0,[pc,MmapParamsFd-$-8]
swi 0x900006

adr r0,Dirtest ; directory
swi 0x90000C ; chdir

adr r0,Menutest ; program to execute
mov r1,0 ; arg 2 = NULL
mov r2,0 ; arg 3 = NULL
swi 0x90000B ; execve


align 4
MmapParams:
dw 0x00000000 ; addr (ignored)
dw 0x10000 ; size
dw 3 ; 2; PROT_WRITE
dw 1 ; flags = MAP_SHARED
MmapParamsFd: dw 0 ; FD
MmapParamsOffset: dw 0xc0000000 ; offset
align 4
MemFileName: db "/dev/mem",0
align 4
Dirtest: db "/usr/gp2x",0
align 4
Menutest: db "/usr/gp2x/gp2xmenu",0
align 4
segment writeable
 
notaz said:
Because mmap uses more then 4 parameters, they shouldn't be passed through registers. See Dex's example.
I assumed thats why he was using 'stmdb sp!, {r0, r1, r2, r3, r4, r5}', to push them on the user stack.
 
Last edited by a moderator:
Squidge said:
I assumed thats why he was using 'stmdb sp!, {r0, r1, r2, r3, r4, r5}', to push them on the user stack.
whoops, don't know why I ignored that.
 
Last edited by a moderator:
ok, now i see that will be better use asm routines inline with C.
many examples, many developers etc :) i read thread about "making 64k demo " its great.

but i have one question.
i read wiki about setting develop environment on linux but there many toolchains. what toolchain you preffer ?

there is open2x apps for gcc4 and gcc3.4. prerelease libpack and of course oddbots libs soft float for open2x.

now i playing with laptop running Fedora where is arm-gp2x-linux in repository. Installed Code::Block, write simple app. crosscompiled and seems to be no prob. but some include and libs missing :( libSDL_ttf etc.
and now what ?

Exist "only one" toolchain which is all "standard" precompiled libs installed ? i mean whole SDL stuff etc.
thanks.
 
Why is the goal you are trying to achieve? Minimal file size? Maximum speed? Balance of both?

Just as going from raw assembler to C/SDL is a kinda major move...
 
I would go, for the language you know best and feel most comfortable with, fasmarm is very easy to use, but there are no tut or examples, i am go to do a fasmarm lib for gp2x dev, to help newbee (it a case of time ), but i am still learning coding on top of linux, as most of my stuff i have coded for the gp2x, is bare-metal, which is much simpler.
 
Back
Top