System Calls Reference Doc


marmakoide

Still Fresh
Joined
Sep 17, 2006
Messages
15
Age
43
Location
Paris, France
Website
www.lri.fr
Hi everybody

I made for my personal use a little C library, in the spirit of the Rlyeh lib : no C standard lib, simple memory management withou mallocs. But I still need to speak a little bit with Linux. Currently, I ripped an assembler source code from Dzzz tutorials. Here it is the beast, syscall.s
Code:
#
# GP2X Linux system calls
#
	.align 4
	.globl open
	.globl close
	.globl munmap
	.globl chdir
	.globl exec
	.globl mmap

open:
	swi #0x900005
	mov pc, lr

close:
	swi #0x900006
	mov pc, lr

munmap:
	swi #0x90005B
	mov pc, lr

chdir:
	swi #0x90000C
	mov pc, lr

exec:
	swi #0x90000B
	mov pc, lr

mmap:
	stmdb sp!, {r0, r1, r2, r3}
	mov r0, sp
	swi #0x90005A
	add sp, sp, #16
	mov pc, lr

Now, I want to add some calls, as the read call to load something like PNG pictures or scripts. Where I can find the information to fill my file syscall with more calls ?
 
:D Got it ! I'am not that ignorant in computer science, but a real noob for the low level stuffs. Here it is my self answer, so that other newbies like me will find their way in less time than me.

What I was searching is : the interrupts code used to call a given function of the Linux kernel. To call a Linux kernel function, just trigger an interrupt, that's the meaning of the swi ARM assembler instruction. So this numbers could be found in the Linux kernel source, ARM version. After digging in the kernel 2.6 source code, I found the treasure, /linux-2.6.4/arch/arm/kernel/calls.S in the code source archive. The numbers found in this file are just the same as the one I get form a Dzzz tutorial. Here it a snippet of this file :
Code:
/*
 *  linux/arch/arm/kernel/calls.S
 *
 *  Copyright (C) 1995-2003 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  This file is included twice in entry-common.S
 */
#ifndef NR_syscalls
#define NR_syscalls 288
#else

__syscall_start:
/* 0 */		.long	sys_restart_syscall
		.long	sys_exit
		.long	sys_fork_wrapper
		.long	sys_read
		.long	sys_write
/* 5 */		.long	sys_open
		.long	sys_close
		.long	sys_ni_syscall		/* was sys_waitpid */
		.long	sys_creat
		.long	sys_link
/* 10 */	.long	sys_unlink
		.long	sys_execve_wrapper
		.long	sys_chdir
... And so on. Big Google will find this for you !
 
that's the way

but remember that on x86 things are not like that

on x86 you'll have to call int 80h passing the function number on register eax, and I don't know if function numbers are identical from x86's eax to arm's swi interface

so if you wan't to compile something for gp2x and still being capable of running/debugging on PC, you should write a macro to switch from swi to int 80h and vice-versa whenever needed
 
Back
Top