forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to declare en function import

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Fri Jul 17, 2009 7:01 am    Post subject: How to declare en function import Reply with quote

I try to program a hello world in mips assembler. But i'm in trouble how to declare a import function in my program. When psp-fixup-imports is executed i've received a
Error, invalid stub address.

The Makefile

Code:

PSPSDK = $(shell psp-config --pspsdk-path)
PSPLIBSDIR = $(PSPSDK)/..
TARGET = hellomips
OBJS = hellomips.o
CFLAGS = -O2 -G0 -Wall -mno-crt0 -nostartfiles -nostdlib -nodefaultlibs
ASFLAGS = $(CFLAGS)
BUILD_PRX=1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World

include $(PSPSDK)/lib/build.mak


the macs.s file
Code:

   .macro IMPORT_START module, flags_ver
   .set push
   .section .rodata.sceResident, "a"
   .word   0
__stub_modulestr_\module:
   .asciz  "\module"
   .align  2

   .section .lib.stub, "a", @progbits
   .global __stub_module_\module
__stub_module_\module:
   .word   __stub_modulestr_\module
   .word   \flags_ver
   .word   0x5
   .word   __executable_start
   .word   __executable_start

   .set pop
        .endm

        .macro IMPORT_FUNC module, funcid, funcname

   .set push
   .set noreorder

   .extern __stub_module_\module
   .section .sceStub.text, "ax", @progbits
   .globl  \funcname
   .type   \funcname, @function
   .ent    \funcname, 0
\funcname:
   .word   __stub_module_\module
   .word   \funcid
   .end    \funcname
   .size   \funcname, .-\funcname

   .section .rodata.sceNid, "a"
   .word   \funcid

   .set pop
        .endm

        .macro IMPORT_FUNC_WITH_ALIAS module, funcid, funcname, alias

   .set push
   .set noreorder

   .extern __stub_module_\module
   .section .sceStub.text, "ax", @progbits
   .globl  \alias
   .type   \alias, @function
\alias:
   .globl  \funcname
   .type   \funcname, @function
   .ent    \funcname, 0
\funcname:
   .word   __stub_module_\module
   .word   \funcid
   .end    \funcname
   .size   \funcname, .-\funcname

   .section .rodata.sceNid, "a"
   .word   \funcid

   .set pop
        .endm


the moduleinfo.s
Code:

   .globl   module_info
   .section .rodata.sceModuleInfo,"a",@progbits
   .align   4
module_info:
   .half   0
   .byte   1
   .byte   1
   .ascii   "Hello world\000"
   .space   15
   .byte   0
   .word   _gp
   .set push
        .section .lib.ent.top, "a", @progbits
        .align 2
        .word 0
__lib_ent_top:
        .section .lib.ent.btm, "a", @progbits
        .align 2
__lib_ent_bottom:
        .word 0
        .section .lib.stub.top, "a", @progbits
        .align 2
        .word 0
__lib_stub_top:
        .section .lib.stub.btm, "a", @progbits
        .align 2
__lib_stub_bottom:
        .word 0
IMPORT_START "LoadExecForKernel",0x00010000
IMPORT_FUNC  "LoadExecForKernel",0x05572A5F,sceKernelExitGame 
        .set pop
        .text


and finaly the main program hellomips.s

Code:

   .include "mac.s"
   .include "moduleinfo.s"
   .global _start
   .global module_start
   .text
_start:
module_start:
   .set   noreorder
   j   $31
   nop
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group