Fix loader error (?!) + add configure script for user program

This commit is contained in:
Yann MAGNIN 2020-04-19 14:16:29 +02:00
parent 61582ad9f9
commit 71fd4969bb
35 changed files with 377 additions and 114 deletions

4
.gitignore vendored
View File

@ -55,7 +55,9 @@ dkms.conf
# Other
*.txt
build/
.tests
.old
*.g1a
debug_bin
output
gcc.cfg
.tests

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <sys/types.h>
#include <kernel/drivers/screen.h>
#include <display.h>

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <sys/types.h>
#define KEYCODE_GEN(row, column) \
(((row & 0x0f) << 4) | ((column & 0x0f) << 0))

View File

@ -0,0 +1,25 @@
#ifndef __KERNEL_DRIVERS_VBR_H__
# define __KERNEL_DRIVERS_VBR_H__
//---
// General exception code
//---
#define EXP_CODE_USER_BREAK 0x1e0 // <- DBR (or VBR + 0x100)
#define EXP_CODE_ACCESS_READ 0x0e0
#define EXP_CODE_TLB_READ 0x040 // <- VBR + 0x400
#define EXP_CODE_TLB_WRITE 0x060
#define EXP_CODE_TLB_INITWRITE 0x080
#define EXP_CODE_TLB_PROTECT_R 0x0a0
#define EXP_CODE_TLB_PROTECT_W 0x0c0
#define EXP_CODE_ACCESS_WRITE 0x100
#define EXP_CODE_TRAPA 0x160
#define EXP_CODE_BAD_INSTR 0x180
#define EXP_CODE_BAD_SLOTINSTR 0x1a0
//---
// Interruption code
//---
//TODO
#endif /*__KERNEL_DRIVERS_VBR_H__*/

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include <asm/types.h>
#include <sys/types.h>
#include <kernel/fs/filesystem.h>
#ifndef FILE_OPEN_NUMBER

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <sys/types.h>
// FS flags
#define FS_RDWR (0x01)

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include <asm/types.h>
#include <sys/types.h>
# define GLADFS_INODE_NAME_LENGHT (16)

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include <asm/types.h>
#include <sys/types.h>
#include <kernel/fs/file.h>
#define CASIO_SMEM_NAME_LENGHT 12

View File

@ -1,9 +1,6 @@
#ifndef __KERNEL_FS_STAT_H__
# define __KERNEL_FS_STAT_H__
#include <stddef.h>
#include <stdint.h>
/* File types. */
#define __S_IFMT 0170000 /* These bits determine file type. */
#define __S_IFDIR 0040000 /* Directory. */

View File

@ -3,9 +3,9 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <kernel/fs/filesystem.h>
#include <sys/types.h>
#include <kernel/fs/file.h>
#include <kernel/fs/filesystem.h>
#include <kernel/devices/device.h>
// Internal VFS macros

View File

@ -0,0 +1,14 @@
#ifndef __KERNEL_HARDWARE_MPU_H__
# define __KERNEL_HARDWARE_MPU_H__
// Define MPU arch.
typedef enum mpu_e
{
MPU_SH7305,
MPU_SH7724,
MPU_SH7337,
MPU_SH7355,
MPU_UNKNOWN,
} mpu_t;
#endif /*__KERNEL_HARDWARE_MPU_H__*/

View File

@ -52,7 +52,7 @@ struct pm_heap_page
size_t size; /* Page size (without header) */
struct pm_heap_page *next; /* Next heap page */
struct pm_heap_block heap; /* Start of block informations */
} __attribute__((packed, aligned(4)));
};
// Real physical memory informations
struct pm_page

View File

@ -6,7 +6,7 @@
#include <kernel/fs/file.h>
#include <kernel/fs/filesystem.h>
#include <kernel/context.h>
#include <asm/types.h>
#include <sys/types.h>
#define PROCESS_NB_OPEN_FILE (4)
#define PROCESS_USER_STACK_SIZE (2 * 1024)

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include <asm/types.h>
#include <sys/types.h>
// Process
extern pid_t sys_getpid(void);

View File

@ -16,16 +16,7 @@ typedef int32_t ssize_t;
# define __ssize_t_defined
#endif
// Define MPU arch.
typedef enum mpu_e
{
MPU_SH7305,
MPU_SH7724,
MPU_SH7337,
MPU_SH7355,
MPU_UNKNOWN,
} mpu_t;
// Define alias
typedef int32_t pid_t;
typedef int16_t mode_t;
typedef uint16_t dev_t;

22
include/lib/sys/wait.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __LIB_SYS_WAIT_H__
# define __LIB_SYS_WAIT_H__
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
// Wait options
#define WNOHANG 0
#define WUNTRACED 1
#define WCONTINUED 2
// Signals
#define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WEXITSTATUS(status) __WEXITSTATUS(status)
// Wait process
extern pid_t waitpid(pid_t pid, int *wstatus, int options);
extern pid_t wait(int *wstatus);
#endif /*__LIB_SYS_WAIT_H__*/

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <sys/types.h>
// TODO: move me
#define STDIN_FILENO 0
@ -15,22 +15,11 @@
#define _SC_PAGESIZE _SC_PAGE_SIZE
//TODO: move me
#define WNOHANG 0
#define WUNTRACED 1
#define WCONTINUED 2
//TODO: move me
#define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WEXITSTATUS(status) __WEXITSTATUS(status)
// Process part
extern pid_t getpid(void);
extern pid_t getpgid(void);
extern pid_t getppid(void);
extern int setpgid(pid_t pid, pid_t pgid);
extern pid_t waitpid(pid_t pid, int *wstatus, int options);
extern pid_t fexecve(const char *pathname, char **argv, char **envp);
// File part

View File

@ -4,6 +4,7 @@
#include <stddef.h>
#include <stdint.h>
extern int manual_proc_call(char **argv);
extern int check_builtin(int argc, char **argv);
extern int strtotab(int *argc, char ***argv, char const *str);
extern void strtotab_quit(int *argc, char ***argv);

View File

@ -1,4 +1,5 @@
#include <asm/types.h>
#include <stdint.h>
#include <kernel/hardware/mpu.h>
/* check_sh3 - Detecting sh3-based MPU */
static mpu_t check_sh3(uint16_t tplcr)

View File

@ -1,7 +1,9 @@
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
// Hardware
#include <kernel/hardware/mpu.h>
// Internal helpers
#include <asm/types.h>
#include <kernel/util/atomic.h>
#include <kernel/util/casio.h>
// Modules

View File

@ -1,24 +1,78 @@
#include <kernel/devices/earlyterm.h>
#include <kernel/drivers/vbr.h>
#include <kernel/process.h>
void exception_handler(void)
{
extern struct process *process_current;
uint32_t stack;
uint32_t spc;
uint32_t ssr;
uint32_t sr;
uint32_t evt;
uint32_t tea;
// Get some registers's data.
__asm__ volatile (
"stc spc, %0;"
"stc ssr, %1;"
"stc sr, %2"
: "=r"(spc), "=r"(ssr), "=r"(sr)
:
:
);
__asm__ volatile ("stc spc, %0" : "=r"(spc));
__asm__ volatile ("stc ssr, %0" : "=r"(ssr));
__asm__ volatile ("mov r15, %0" : "=r"(stack));
// Write exception informations.
// Get event code and tea regsiter
evt = *((uint32_t *)0xff000024);
tea = *((uint32_t *)0xff00000c);
// Display error screen
earlyterm_clear();
switch (evt)
{
case EXP_CODE_ACCESS_READ:
case EXP_CODE_ACCESS_WRITE:
earlyterm_write("CPU Access Violation (R/W)\n");
earlyterm_write("> Address : %p\n", tea);
break;
case EXP_CODE_BAD_INSTR:
case EXP_CODE_BAD_SLOTINSTR:
if(evt == EXP_CODE_BAD_SLOTINSTR)
earlyterm_write("Illegal slot instruction\n");
else
earlyterm_write("Illegal instruction\n");
earlyterm_write("> TEA value = %p\n", tea);
earlyterm_write("> TEA correct = %p\n", tea >> 2 << 2);
break;
case EXP_CODE_USER_BREAK:
earlyterm_write("Unexpected User Break exception.\n");
while(1);
case EXP_CODE_TLB_INITWRITE:
earlyterm_write("Initial MMU page write (bloking).\n");
while (1);
case EXP_CODE_TLB_PROTECT_R:
case EXP_CODE_TLB_PROTECT_W:
earlyterm_write("TLB protection violation (blocking)");
while (1);
case EXP_CODE_TLB_READ:
case EXP_CODE_TLB_WRITE:
earlyterm_write("TLB miss (blocking)");
while (1);
default:
earlyterm_write("Ho crap ! Unkonow exception !\n");
earlyterm_write("> EXPEVT : %#x\n", evt);
earlyterm_write("> TEA value = %p\n", tea);
}
// Common display
earlyterm_write("> SPC Value = %p\n", spc);
earlyterm_write("> Process : %p\n", process_current);
earlyterm_write("> Process entry : %p\n", process_current->memory.program.start);
earlyterm_write("> Proc rela. PC = %p\n", spc - (uint32_t)process_current->memory.program.start);
while (1);
/* // Write exception informations.
earlyterm_write(
"Ho crap ! Exception !\n"
"tra: %#x\n"
@ -27,10 +81,10 @@ void exception_handler(void)
"ssr: %#x\n"
"sr: %#x",
*((uint32_t *)0xff000020),
*((uint32_t *)0xff000024),
,
spc,
ssr,
sr
);
while (1);
while (1);*/
}

View File

@ -20,7 +20,7 @@ static void *casio_smem_get_data_base_address(smemfs_fragdata_t *fragment)
// If the block ID is missing, return error
if (block->info.id != fragment->data_block_id)
return (NULL);
return ((void *)(block->offset + fragment->data_offset));
return ((void *)(uintptr_t)(block->offset + fragment->data_offset));
}
/* casio_smem_read() - Read the file data (based on internal cursor) */
@ -33,6 +33,9 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos)
size_t current_size;
size_t real_size;
earlyterm_write("pos = %#x\n", pos);
DBG_WAIT;
// Get Check obvious error.
if (inode == NULL || buf == NULL)
return (-1);
@ -76,8 +79,8 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos)
}
// Read file data
current_size = 0;
fragment_data_offset = pos - current_size;
current_size = 0;
while (current_size < count &&
fragment->magic == CASIO_SMEM_FRAGMENT_MAGIC &&
fragment->info == CASIO_SMEM_FRAGMENT_INFO_EXIST)

View File

@ -16,6 +16,9 @@ ssize_t vfs_pread(FILE *file, void *buf, size_t count, off_t offset)
file->file_op->read == NULL)
return (-1);
// Debug
earlyterm_write("pos = %#x\n", offset);
// Check error
// Read with FS specifique primitive and return the numbe of reading bytes.
return (file->file_op->read(((struct dentry*)file->private)->inode, buf, count, offset));

View File

@ -11,8 +11,9 @@ static char *get_shstrtab(FILE *file, Elf32_Ehdr *header)
off_t offset;
// Get sections string header tables
offset = header->e_shoff + (header->e_shstrndx * sizeof(Elf32_Shdr));
if (vfs_pread(file, &shdr, sizeof(Elf32_Shdr), offset) != sizeof(Elf32_Shdr))
offset = header->e_shoff + (header->e_shstrndx * header->e_shentsize);
earlyterm_write("pos = %#x\n", offset);
if (vfs_pread(file, &shdr, header->e_shentsize, offset) != header->e_shentsize)
{
earlyterm_write("relo_sym: shdr size\n");
return (NULL);
@ -28,6 +29,7 @@ static char *get_shstrtab(FILE *file, Elf32_Ehdr *header)
}
// Get string tables
earlyterm_write("pos = %#x\n", shdr.sh_offset);
if (vfs_pread(file, shstrtab, shdr.sh_size, shdr.sh_offset) != (ssize_t)shdr.sh_size)
{
earlyterm_write("relo_sym: shstrtab size error\n");
@ -48,8 +50,9 @@ static int reloc_section(struct process *process, FILE *file, Elf32_Shdr *shdr)
for (uint32_t i = 0 ; i < shdr->sh_size / shdr->sh_entsize ; ++i)
{
// Get relocatable entry
offset = shdr->sh_offset + (i * sizeof(Elf32_Rela));
if (vfs_pread(file, &rela, sizeof(Elf32_Rela), offset) != sizeof(Elf32_Rela))
offset = shdr->sh_offset + (i * shdr->sh_entsize);
earlyterm_write("rela\npos = %#x\n", offset);
if (vfs_pread(file, &rela, shdr->sh_entsize, offset) != (ssize_t)shdr->sh_entsize)
{
earlyterm_write("relo_sym: reloc section size error\n");
return (-1);
@ -84,8 +87,8 @@ int loader_reloc_sym(struct process *process, FILE *file, Elf32_Ehdr *header)
for (int i = 1 ; i < header->e_shnum ; ++i)
{
// Get next section header
offset = header->e_shoff + (i * sizeof(Elf32_Shdr));
if (vfs_pread(file, &shdr, sizeof(Elf32_Shdr), offset) != sizeof(Elf32_Shdr))
offset = header->e_shoff + (i * header->e_shentsize);
if (vfs_pread(file, &shdr, header->e_shentsize, offset) != header->e_shentsize)
{
earlyterm_write("loader_reloc_sym: section header\n");
earlyterm_write("loader_reloc_sym: shoff = %#x\n", header->e_shoff);

View File

@ -20,7 +20,7 @@ static void *new_pages(struct pm_heap_page **page, size_t size)
// Initialize new page
(*page)->next = NULL;
(*page)->size = (nb_page * PM_PAGE_SIZE) - sizeof(struct pm_heap_page);
(*page)->brk = (void*)(*page) + (nb_page * PM_PAGE_SIZE);
(*page)->brk = ((void*)(*page)) + (nb_page * PM_PAGE_SIZE);
// Initialize first block
(*page)->heap.status = 0;
@ -37,7 +37,7 @@ static void *pm_heap_page_check(struct pm_heap_page *page, size_t size)
// Walk into the page and check each block x_x
block = &page->heap;
rest_size = page->size;
while ((void*)block < page->brk && rest_size > size)
while ((void*)&block[1] < page->brk && rest_size > size)
{
// Check if the block is used or not
if (block->status == 0)

View File

@ -9,7 +9,7 @@ static int pm_block_free(struct pm_heap_page *page, void *ptr)
block_parent = NULL;
block = &page->heap;
while ((void*)block < page->brk)
while ((void*)&block[1] < page->brk)
{
// check block validity
if ((void*)&block[1] != ptr)
@ -56,7 +56,7 @@ void pm_heap_free(struct pm_heap_page *page, void *ptr)
// No block found, display error.
earlyterm_write(
"pm_free: Warning, you try to free unused"
" or allocated memory (%p)", ptr
" or allocated memory (%p)\n", ptr
);
DBG_WAIT;

View File

@ -35,7 +35,7 @@ static void *pm_block_realloc(struct pm_heap_page **page, void *ptr, size_t size
block_parent = NULL;
block = &(*page)->heap;
while ((void*)block < (*page)->brk)
while ((void*)&block[1] < (*page)->brk)
{
// check block validity
if ((void*)&block[1] != ptr)
@ -72,6 +72,10 @@ void *pm_heap_realloc(struct pm_heap_page **page, void *ptr, size_t size)
{
void *ret;
// Check error
if (ptr == NULL)
return (NULL);
// Force 4-align
size = (size + 3) >> 2 << 2;
@ -79,10 +83,10 @@ void *pm_heap_realloc(struct pm_heap_page **page, void *ptr, size_t size)
atomic_start();
// Try to find the page
while (page != NULL)
while (*page != NULL)
{
// If is the page is found
if (ptr > (void*)page && ptr < (*page)->brk)
if (ptr > (void*)*page && ptr < (*page)->brk)
{
// Check if the block is not found
ret = pm_block_realloc(page, ptr, size);
@ -97,8 +101,8 @@ void *pm_heap_realloc(struct pm_heap_page **page, void *ptr, size_t size)
// No block found, display error.
earlyterm_write(
"pm_free: Warning, you try to realloc"
"unused or allocated memory (%p)", ptr
"pm_free: Warning, you try to realloc an "
"unused or allocated memory (%p)\n", ptr
);
DBG_WAIT;

View File

@ -3,7 +3,7 @@
#include <kernel/devices/earlyterm.h>
#include <kernel/memory.h>
// TODO: remove / move me ?
#include <lib/unistd.h>
#include <sys/wait.h>
void sys_exit(int status)
{

View File

@ -0,0 +1,12 @@
#include <asm/unistd_32.h>
.text
.global _wait
.type _wait, @function
.align 2
_wait:
trapa #__NR_wait
rts
nop
.end

View File

@ -3,23 +3,52 @@
## Project: Vhex - On-calc debugger
## Author: yann.magnin@epitech.eu
## ---
include ../../../global.mk
##---
## Build configuration
##---
CONFIG := gcc.cfg
ifeq "$(wildcard $(CONFIG))" ""
$(error "config file $(CONFIG) does not exist")
endif
include $(CONFIG)
##---
## Static variables
##--
HEADER := -I../../../include/lib -I../../../include/user/shell
BUILD := ../../../build/user/shell
DEBUG := ../../../debug_bin
OUTPUT := ../../../output
header := -I../../../include/lib -I../../../include/user/shell
build := ../../../build/user/shell/$(CONFIG.ARCH)
debug := ../../../debug_bin/$(CONFIG.ARCH)
output := ../../../output
NAME := shell
EXEC := $(OUTPUT)/$(NAME).elf
LDFLAG := -T $(NAME).ld
MEMORY_MAP := $(DEBUG)/$(NAME).map
LIBS := -L../../lib -llibc -lgcc
name := shell
EXEC := $(output)/$(name)
cflags := -Werror -Wall -W -Wextra -std=c11
# Add arch specific flags
ifeq "$(CONFIG.ARCH)" "casio"
EXEC := $(output)/$(name).elf
dflags := -Wl,-M -T $(name).ld
lflags := -L../../lib -llibc -lgcc
cflags += $(CONFIG.CEXTRA) -pie
memmap := > $(debug)/$(name).map
endif
# Tools
cc := $(CONFIG.TOOLCHAIN)gcc
ld := $(CONFIG.TOOLCHAIN)ld
objcopy := $(CONFIG.TOOLCHAIN)objcpy
objdump := $(CONFIG.TOOLCHAIN)objdump
# Colors
red := \033[1;31m
green := \033[1;32m
blue := \033[1;34m
white := \033[1;37m
nocolor := \033[1;0m
##---
@ -34,48 +63,69 @@ $(foreach path,$(DIRECTORY),$(eval \
$(wildcard $(path)/*.s) \
))
# Geneate all object files
OBJ := $(patsubst ._%,$(BUILD)/%.o,$(subst /,_,$(subst src/,,$(basename $(SRC)))))
OBJ := $(patsubst ._%,$(build)/%.o,$(subst /,_,$(subst src/,,$(basename $(SRC)))))
##---
## General rules
## Building rules
##---
all: $(EXEC)
$(EXEC): $(OBJ) | $(DEBUG)
$(CC) -pie -Wl,-M $(LDFLAG) $(CFLAGS) -o $@ $(OBJ) $(HEADER) $(LIBS) > $(MEMORY_MAP)
$(EXEC): $(OBJ) | $(debug)
$(cc) $(dflags) $(cflags) -o $@ $(OBJ) $(header) $(lflags) $(memmap)
$(BUILD) $(DEBUG):
$(build) $(debug):
@ printf "Create $(blue)$@$(nocolor) directory\n"
@ mkdir -p $@
##---
## Install / tests rules
##---
# Install is only available for CASIO arch
ifeq "$(CONFIG.ARCH)" "casio"
install: $(EXEC)
sudo p7 send --force -d VHEX $^
else
install: $(EXEC)
valgrind $(EXEC)
endif
##---
## Debug rules
##---
check:
@ echo 'src: $(SRC)'
@ echo 'obj: $(OBJ)'
@ echo 'directory: $(DIRECTORY)'
@ echo 'clfags: $(cflags)'
@ echo 'cc: $(cc)'
asm:
@ $(OBJDUMP) -D $(EXEC) | less
@ $(objdump) -D $(EXEC) | less
map:
@ cat $(MEMORY_MAP) | less
@ cat $(memmap) | less
sec:
@ $(OBJDUMP) -h $(EXEC)
@ $(objdump) -h $(EXEC)
##---
## Automated rules
##---
define rule-src
$(patsubst ._%,$(BUILD)/%.o,$(subst /,_,$(subst src/,,$(basename $1)))): $1 | $(BUILD)
$(patsubst ._%,$(build)/%.o,$(subst /,_,$(subst src/,,$(basename $1)))): $1 | $(build)
@ printf "compiling $(white)$$<$(nocolor)..."
@ $(CC) -pie $(CFLAGS) -o $$@ -c $$< $(HEADER) -lgcc
@ $(cc) $(cflags) -o $$@ -c $$< $(header) -lgcc
@ printf "$(green)[ok]$(nocolor)\n"
endef
@ -90,8 +140,8 @@ $(foreach source,$(SRC),$(eval \
## Cleaning rules
##---
clean:
rm -rf $(BUILD)
rm -rf $(DEBUG)
rm -rf $(build)
rm -rf $(debug)
fclean: clean
rm -f $(EXEC)

View File

@ -1,5 +1,6 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include "builtin.h"
int builtin_proc(void)

79
src/user/shell/configure vendored Executable file
View File

@ -0,0 +1,79 @@
#!/bin/bash
# Define global variables
confile='gcc.cfg'
debug='false'
arch='casio'
##---
## Help screen
##---
function fhelp()
{
cat << EOF
Usage: ./configure [-h] [--help] [--arch=<TARGET>] [--debug]
-h, --help Display this help
--arch=<TARGET> Specify POSIX architecture to compile with:
- casio (Casio calculators)
- native (use clasic gcc compiler)
--debug Enable "-g3" compialtion flags to have more
informations about program
EOF
exit 0
}
##---
## Parse entry
##---
for opt in "$@"
do
# Check flags
case "$1" in
-h | --help) fhelp;;
--arch=*) arch=${1#*=};;
--debug) debug='true';;
*)
echo "'$1' invalide arg"
exit 84;;
esac
# Shift current arguments list
# to the left.
shift;
done
##---
## Check arguments
##---
if [ $arch != 'casio' ] && [ $arch != 'native' ]; then
echo "'$arch': Invalide architecture, abord"
exit 84
fi
##---
## Generate configuration file
##---
function generate_output()
{
echo "CONFIG.ARCH := $arch"
if [ $arch == 'casio' ]; then
echo 'CONFIG.TOOLCHAIN := sh-elf-'
echo 'CONFIG.CEXTRA := -m3 -mb -mrenesas -ffreestanding -nostdlib'
else
[[ $debug == 'true' ]] && echo 'CONFIG.CEXTRA := -g3'
fi
}
generate_output > $confile
echo "Configuration saved in $confile !"

View File

@ -3,27 +3,6 @@
#include <stdio.h>
#include "util.h"
static int manual_proc_call(char **argv)
{
char pathname[32];
int wstatus;
pid_t child;
// Generate pathname
// TODO: handle PATH
strcpy(pathname, "/mnt/casio/VHEX/");
strcat(pathname, argv[0]);
// Try to call binary from eeprom
printf("try to call '%s'\n", pathname);
child = fexecve(pathname, argv, NULL);
if (child != 0)
return (-1);
waitpid(child, &wstatus, 0);
return (WEXITSTATUS(wstatus));
}
//TODO: documentation.
int main(void)
{

View File

@ -0,0 +1,31 @@
#include "util.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int manual_proc_call(char **argv)
{
char pathname[32];
int wstatus;
pid_t child;
printf("try to call '%s'\n", argv[0]);
for(int i = 0 ; i < 30000000 ; ++i);
// Generate pathname
// TODO: handle PATH
strcpy(pathname, "/mnt/casio/VHEX/");
strcat(pathname, argv[0]);
// Try to call binary from eeprom
printf("try to call '%s'\n", pathname);
for(int i = 0 ; i < 30000000 ; ++i);
child = fexecve(pathname, argv, NULL);
if (child != 0)
return (-1);
waitpid(child, &wstatus, 0);
return (0);
}

View File

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <asm/types.h>
#include <sys/types.h>
#include <errno.h>
//