Prvi poblem sa kojim se susrećem jeste koji sistemski call da pozovem a koji je definisan u /usr/mips-linux-gnu/include/asm/unistd.h.
Code:
#ifndef _ASM_UNISTD_H
#define _ASM_UNISTD_H
#include <asm/sgidefs.h>
#if _MIPS_SIM == _MIPS_SIM_ABI32
/*
* Linux o32 style syscalls are in the range from 4000 to 4999.
*/
#define __NR_Linux 4000
#define __NR_syscall (__NR_Linux + 0)
#define __NR_exit (__NR_Linux + 1)
#define __NR_fork (__NR_Linux + 2)
#define __NR_read (__NR_Linux + 3)
#define __NR_write (__NR_Linux + 4)
#define __NR_open (__NR_Linux + 5)
#define __NR_close (__NR_Linux + 6)
#ifndef _ASM_UNISTD_H
#define _ASM_UNISTD_H
#include <asm/sgidefs.h>
#if _MIPS_SIM == _MIPS_SIM_ABI32
/*
* Linux o32 style syscalls are in the range from 4000 to 4999.
*/
#define __NR_Linux 4000
#define __NR_syscall (__NR_Linux + 0)
#define __NR_exit (__NR_Linux + 1)
#define __NR_fork (__NR_Linux + 2)
#define __NR_read (__NR_Linux + 3)
#define __NR_write (__NR_Linux + 4)
#define __NR_open (__NR_Linux + 5)
#define __NR_close (__NR_Linux + 6)
Mislim da je to __NR_read I stvarno nakon
Code:
#Raad the integer and save it in s0
li v0,__NR_read
syscall
move s0, v0
#Raad the integer and save it in s0
li v0,__NR_read
syscall
move s0, v0
program čeka da se unese input, dobro ja unesem recimo proj 9 ali u registru v0 i s0 nalazi se 0x2 ?
EDIT:
Ovako našao sam ovo
Code:
asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);
asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);
to su dake argumenti koje zahtjeva __NR_read, dobro ovu bi bila moja pitanja
1. prvi argument je fd znači za stdin je 0 ?
2. drugi argument je char __user *buf to znači da je pointer prema bufferu, pointer prema nekoj memorijskoj lokaciji ? Probao sam da stavim ovako
Code:
#Read the integer and save it in s0
nop
nop
li a0,0 # firs argument, for stdin is 0 ISTR, see "man 2 read"
la a1,(var1) # second argument load adress of var1 in to a1
li a2,10 # third argument is count of byts
li v0,__NR_read
syscall
.data
var1: .space 12
#Read the integer and save it in s0
nop
nop
li a0,0 # firs argument, for stdin is 0 ISTR, see "man 2 read"
la a1,(var1) # second argument load adress of var1 in to a1
li a2,10 # third argument is count of byts
li v0,__NR_read
syscall
.data
var1: .space 12
ali dobijam SIGSEGV, Segmentation fault.
3. treći argument je size_t count znači neki broj ? ali čega ?
[Ovu poruku je menjao vidonk dana 29.03.2017. u 15:16 GMT+1]
vidovic-slobodan.blogspot.com