Browse Source

Add Bfile wrapper driver for Graph35+II and Graph90+E + Graph35+EII support

master
Yann MAGNIN 2 years ago
parent
commit
cf27fb558b
  1. 10
      include/kernel/driver.h
  2. 36
      include/kernel/fs/smemfs.h
  3. 47
      include/kernel/util/casio.h
  4. 20
      src/kernel/bootstrap/driver.c
  5. 7
      src/kernel/bootstrap/start.c
  6. 2
      src/kernel/drivers/intc/driver.c
  7. 30
      src/kernel/fs/smemfs/initialize.c
  8. 4
      src/kernel/fs/smemfs/power_graphic_2/file/read.c
  9. 4
      src/kernel/fs/smemfs/power_graphic_2/filesystem/mount.c
  10. 6
      src/kernel/fs/smemfs/power_graphic_2/inode/find_first_child.c
  11. 4
      src/kernel/fs/smemfs/power_graphic_2/inode/find_next_sibling.c
  12. 6
      src/kernel/fs/smemfs/power_graphic_2/inode/find_parent.c
  13. 4
      src/kernel/fs/smemfs/power_graphic_2/inode/get_mode.c
  14. 4
      src/kernel/fs/smemfs/power_graphic_2/inode/get_name.c
  15. 74
      src/kernel/fs/smemfs/power_graphic_3/file/read.c
  16. 150
      src/kernel/fs/smemfs/power_graphic_3/filesystem/mount.c
  17. 31
      src/kernel/fs/smemfs/power_graphic_3/inode/find_first_child.c
  18. 33
      src/kernel/fs/smemfs/power_graphic_3/inode/find_next_sibling.c
  19. 26
      src/kernel/fs/smemfs/power_graphic_3/inode/find_parent.c
  20. 39
      src/kernel/fs/smemfs/power_graphic_3/inode/get_mode.c
  21. 34
      src/kernel/fs/smemfs/power_graphic_3/inode/get_name.c
  22. 14
      src/kernel/fs/smemfs/power_graphic_3/superblock/alloc_inode.c
  23. 19
      src/kernel/loader/entry.c
  24. 9
      src/kernel/util/casio/menu.c
  25. 90
      src/kernel/util/casio/syscall.s

10
include/kernel/driver.h

@ -0,0 +1,10 @@
#ifndef __KERNEL_DRIVER_H__
# define __KERNEL_DRIVER_H__
#include <stddef.h>
#include <stdint.h>
extern void drivers_install(int verbose);
extern void drivers_uninstall(int verbose);
#endif /*__KERNEL_DRIVER_H__*/

36
include/kernel/fs/smemfs.h

@ -24,16 +24,28 @@ extern void smemfd_uninitialize(void);
/** USB Power Graphic II SMEM driver part **/
/** **/
/*******************************************/
// Internal Casio's structure to dump file's informations
struct smem_USB3_file_info
// Internal superblock use by the USB3 abstractions
struct smemfs_USB3_superblock
{
uint16_t id; // File index
uint16_t type; // File type
struct {
uint32_t file; // File size (data + header)
uint32_t data; // Data size (without header)
} size;
uint32_t address; // Data address ?
struct smemfs_USB3_inode *root_inode;
struct smemfs_USB3_inode *fake_root_inode;
};
// Internal struct used to store SMEM dump
struct smemfs_USB3_inode
{
// File name
char name[32];
// Internal file's informations
int type;
size_t fsize;
size_t dsize;
// Internal abstraction informations
struct smemfs_USB3_inode *child;
struct smemfs_USB3_inode *sibling;
struct smemfs_USB3_inode *parent;
};
// Superblock primitives
@ -50,13 +62,15 @@ extern void * smemfs_USB3_find_next_sibling(void *inode);
extern int smemfs_USB3_get_name(void *inode, char *name, size_t count);
extern mode_t smemfs_USB3_get_mode(void *inode);
// Superblock
extern struct smemfs_USB3_inode *smemfs_USB3_alloc_inode(void);
/*******************************************/
/** **/
/** USB Power Graphic II SMEM driver part **/
/** **/
/*******************************************/
//TODO: update this part !!
// Define internal SMEM informations /flags
#define CASIO_SMEM_NAME_LENGHT 12
#define CASIO_SMEM_ROOT_ID 0xffff
@ -131,7 +145,7 @@ typedef struct casio_smem_header_s smemfs_header_t;
// Define internal superblock
struct smemfs_superblock_s
struct smemfs_USB2_superblock
{
smemfs_inode_t *inode_table;
smemfs_sector_t *sector_table;

47
include/kernel/util/casio.h

@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
//---
// Casio's wrapper
@ -78,6 +79,52 @@ extern int casio_TimerUninstall(int id);
extern int casio_TimerStart(int id);
extern int casio_TimerStop(int id);
//---
// Bfile syscalls
//---
//@note: Graph35+II define
// DT_ADDIN_APP -> 65
// DT_DIRECTORY -> 0
// DT_DOT -> 8
// DT_DOT_DOT -> 9
#define DT_DIRECTORY 0x0000 // Directory
#define DT_FILE 0x0001 // File
#define DT_ADDIN_APP 0x0002 // Add-In application
#define DT_EACT 0x0003 // eActivity
#define DT_LANGUAGE 0x0004 // Language
#define DT_BITMAP 0x0005 // Bitmap
#define DT_MAINMEM 0x0006 // Main Memory data
#define DT_TEMP 0x0007 // Temporary data
#define DT_DOT 0x0008 // . (Current directory)
#define DT_DOTDOT 0x0009 // .. (Parent directory)
#define DT_VOLUME 0x000A // Volume label
// @note: unsed with Graph35+
#define _OPENMODE_READ 0x01
#define _OPENMODE_READ_SHARE 0x80
#define _OPENMODE_WRITE 0x02
#define _OPENMODE_READWRITE 0x03
#define _OPENMODE_READWRITE_SHARE 0x83
// Internal Casio's structure to dump file's informations
struct casio_file_info
{
uint16_t id; // File index
uint16_t type; // File type
struct {
uint32_t file; // File size (data + header)
uint32_t data; // Data size (without header)
} size;
uint32_t address; // Data address ?
};
extern int casio_Bfile_OpenFile(uint16_t *pathname, int mode);
extern int casio_Bfile_ReadFile(int handle, void *buffer, size_t count, off_t pos);
extern int casio_Bfile_FindFirst(uint16_t *search_path, int *handle,
uint16_t *pathname, struct casio_file_info *file_info);
extern int casio_Bfile_FindNext(int handle, uint16_t *pathname, struct casio_file_info *file_info);
extern int casio_Bfile_FindClose(int handle);
extern int casio_Bfile_CloseFile(int handle);
#endif /*__KERNEL_UTIL_CASIO_H__*/

20
src/kernel/bootstrap/driver.c

@ -9,7 +9,7 @@
extern mpu_t mpu_get(void);
//TODO: secure if no driver is found !!
void bootstrap_drivers_install(void)
void drivers_install(int verbose)
{
extern uint32_t bdrivers_section;
extern uint32_t edrivers_section;
@ -17,8 +17,11 @@ void bootstrap_drivers_install(void)
mpu_t mpu;
int i;
// Verbose
if (verbose == 1)
earlyterm_write("Load drivers...\n");
// Start atomic operations
earlyterm_write("Load drivers...\n");
atomic_start();
i = -1;
@ -38,7 +41,8 @@ void bootstrap_drivers_install(void)
// Try to install the driver
// TODO: check driver error ?
earlyterm_write("* install driver [%s]\n", driver[i].name);
if (verbose == 1)
earlyterm_write("* install driver [%s]\n", driver[i].name);
(*driver[i].install)();
}
@ -46,7 +50,7 @@ void bootstrap_drivers_install(void)
atomic_stop();
}
void bootstrap_drivers_uninstall(void)
void drivers_uninstall(int verbose)
{
extern uint32_t bdrivers_section;
extern uint32_t edrivers_section;
@ -54,8 +58,11 @@ void bootstrap_drivers_uninstall(void)
mpu_t mpu;
int i;
// Verbose
if (verbose == 1)
earlyterm_write("Unload drivers...\n");
// Start atomic operations
earlyterm_write("Unload drivers...\n");
atomic_start();
// Uninstall driver (fifo style)
@ -76,7 +83,8 @@ void bootstrap_drivers_uninstall(void)
// Try to uninstall the driver
// TODO: check driver error ?
earlyterm_write("* uninstall driver [%s]\n", driver[i].name);
if (verbose == 1)
earlyterm_write("* uninstall driver [%s]\n", driver[i].name);
(*driver[i].uninstall)();
}

7
src/kernel/bootstrap/start.c

@ -12,6 +12,7 @@
#include <kernel/syscall.h>
#include <kernel/scheduler.h>
#include <kernel/loader.h>
#include <kernel/driver.h>
// Devices
#include <kernel/devices/earlyterm.h>
// Libs
@ -33,7 +34,6 @@ extern uint32_t edtors;
// Internal bootstrap funtions
extern mpu_t mpu_get(void);
extern void bootstrap_drivers_install(void);
extern void bootstrap_filesystem_init(void);
//
@ -90,7 +90,7 @@ int start(void)
earlyterm_write("Kernel initialisation...\n");
// Load all drivers on-the-fly
bootstrap_drivers_install();
drivers_install(1);
// Execute constructor.
// FIXME: remove me ?
@ -137,6 +137,9 @@ int start(void)
sched_start();
// normally the kernel SHOULD / CAN not arrive here.
uint32_t sr;
__asm__ volatile ("stc sr, %0" : "=r"(sr) );
earlyterm_write("Kernel job fini !\n");
earlyterm_write("SR -> %p\n", sr);
while (1) { __asm__ volatile ("sleep"); }
}

2
src/kernel/drivers/intc/driver.c

@ -134,5 +134,5 @@ VHEX_DRIVER(2, driver_intc_sh7305) = {
.arch = MPU_SH7305,
.install = &sh7305_intc_driver_install,
.uninstall = &sh7305_intc_driver_uninstall,
.name = "cpg"
.name = "intc"
};

30
src/kernel/fs/smemfs/initialize.c

@ -44,24 +44,24 @@ struct file_system_type smemfs_filesystem =
};
// Internal superblock informations
struct smemfs_superblock_s smemfs_superblock;
struct smemfs_USB2_superblock smemfs_USB2_superblock;
struct smemfs_USB3_superblock smemfs_USB3_superblock;
// switch USB Power Graphic II driver to
// USB Power Graphic III (Casio syscall wrapper)
static void use_dump_smem_driver(void)
{
/* smemfs_filesystem.filesystem_operations.mount = &smemfs_USB3_mount;
smemfs_filesystem.filesystem_operations.umount = &smemfs_USB3_umount;
smemfs_USB3_superblock.root_inode = NULL;
smemfs_filesystem.filesystem_operations.mount = &smemfs_USB3_mount;
smemfs_filesystem.filesystem_operations.umount = NULL;
smemfs_filesystem.file_operations.read = &smemfs_USB3_read;
smemfs_filesystem.inode_operations.find_next_sibling = &smemfs_USB3_find_next_sibling;
smemfs_filesystem.inode_operations.find_first_child = &smemfs_USB3_find_first_child;
smemfs_filesystem.inode_operations.find_parent = &smemfs_USB3_find_parent;
smemfs_filesystem.inode_operations.get_name = &smemfs_USB3_get_name;
smemfs_filesystem.inode_operations.get_mode = &smemfs_USB3_get_mode;
smemfs_superblock.sector_table = NULL;
smemfs_superblock.inode_table = NULL;*/
while (1);
atomic_stop();
}
void smemfs_initialize(void)
@ -74,25 +74,25 @@ void smemfs_initialize(void)
// Casio SMEM sector table start
// always (?) at 0xa0270000 (tested with OS 1.00.0000).
// TODO: return error !!
smemfs_superblock.sector_table = (void *)0xa0270000;
if (smemfs_superblock.sector_table->magic_start != CASIO_SMEM_BLOCK_ENTRY_MAGIC)
smemfs_USB2_superblock.sector_table = (void *)0xa0270000;
if (smemfs_USB2_superblock.sector_table->magic_start != CASIO_SMEM_BLOCK_ENTRY_MAGIC)
{
earlyterm_write("SMEMFS: Casio sector table error !");
earlyterm_write("SMEMFS: sector table error !\n");
return (use_dump_smem_driver());
}
// Try to find Casio SMEM inode table start always at the end of
// the sector table. Normaly start at 0xa0270320 but not always (?)
int i = -1;
while (smemfs_superblock.sector_table[++i].magic_start == CASIO_SMEM_BLOCK_ENTRY_MAGIC);
while (smemfs_USB2_superblock.sector_table[++i].magic_start == CASIO_SMEM_BLOCK_ENTRY_MAGIC);
// Get the inode table
// TODO: return error !!
smemfs_superblock.inode_table = (void *)&smemfs_superblock.sector_table[i];
if ((smemfs_superblock.inode_table->info != 0x51 &&
smemfs_superblock.inode_table->info != 0x01) ||
smemfs_superblock.inode_table->parent.id != 0xffff ||
smemfs_superblock.inode_table->parent.type != 0xffff)
smemfs_USB2_superblock.inode_table = (void *)&smemfs_USB2_superblock.sector_table[i];
if ((smemfs_USB2_superblock.inode_table->info != 0x51 &&
smemfs_USB2_superblock.inode_table->info != 0x01) ||
smemfs_USB2_superblock.inode_table->parent.id != 0xffff ||
smemfs_USB2_superblock.inode_table->parent.type != 0xffff)
{
earlyterm_write("SMEMFS: Casio inode table error !");
return (use_dump_smem_driver());

4
src/kernel/fs/smemfs/power_graphic_2/file/read.c

@ -7,11 +7,11 @@
/* casio_smem_data_base_address() - Generate the fragmented data address (0xa0000000 + offset) */
static void *casio_smem_get_data_base_address(smemfs_fragdata_t *fragment)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
struct casio_smem_block_s *block;
// Find the appropriate block
block = smemfs_superblock.sector_table;
block = smemfs_USB2_superblock.sector_table;
while (block->magic_start == CASIO_SMEM_BLOCK_ENTRY_MAGIC &&
block->info.id != fragment->data_block_id)
{

4
src/kernel/fs/smemfs/power_graphic_2/filesystem/mount.c

@ -4,14 +4,14 @@
/* casio_smem_mount() - Mount the file system (sync) */
void *smemfs_USB2_mount(void)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
void *root_inode;
// Start atomic operation
atomic_start();
// Get root inode
root_inode = smemfs_superblock.sector_table;
root_inode = smemfs_USB2_superblock.sector_table;
// Stop atomic operation
atomic_stop();

6
src/kernel/fs/smemfs/power_graphic_2/inode/find_first_child.c

@ -4,7 +4,7 @@
/* smemfs_find_first_child() - Find the fist file in the (folder) inode (sync) */
void *smemfs_USB2_find_first_child(void *inode)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
uint16_t folder_id;
void *child_inode;
@ -16,7 +16,7 @@ void *smemfs_USB2_find_first_child(void *inode)
atomic_start();
// Check root inode
if (inode == smemfs_superblock.sector_table)
if (inode == smemfs_USB2_superblock.sector_table)
{
folder_id = CASIO_SMEM_ROOT_ID;
} else {
@ -33,7 +33,7 @@ void *smemfs_USB2_find_first_child(void *inode)
}
// Return the first child of the file.
child_inode = smemfs_USB2_walk(inode, smemfs_superblock.inode_table,
child_inode = smemfs_USB2_walk(inode, smemfs_USB2_superblock.inode_table,
folder_id, WALK_FLAG_ID_CHECK_PARENT);
// Stop atomic operation

4
src/kernel/fs/smemfs/power_graphic_2/inode/find_next_sibling.c

@ -4,7 +4,7 @@
/* smemfs_find_next_sibling() - Find the next file from the same parent (sync) */
void *smemfs_USB2_find_next_sibling(void *inode)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
void *sibling_inode;
uint16_t folder_id;
@ -16,7 +16,7 @@ void *smemfs_USB2_find_next_sibling(void *inode)
atomic_start();
// Check inode validity (and root)
if (inode == smemfs_superblock.sector_table ||
if (inode == smemfs_USB2_superblock.sector_table ||
((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST)
{
atomic_stop();

6
src/kernel/fs/smemfs/power_graphic_2/inode/find_parent.c

@ -4,7 +4,7 @@
/* smemfs_find_parent() - Return the parent inode */
void *smemfs_USB2_find_parent(void *inode)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
void *parent_inode;
uint16_t folder_id;
@ -16,7 +16,7 @@ void *smemfs_USB2_find_parent(void *inode)
atomic_start();
// Check inode validity (and root)
if (inode == smemfs_superblock.sector_table ||
if (inode == smemfs_USB2_superblock.sector_table ||
((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST)
{
atomic_stop();
@ -27,7 +27,7 @@ void *smemfs_USB2_find_parent(void *inode)
folder_id = ((struct casio_smem_header_s *)inode)->parent.id;
// Return first inode find
parent_inode = smemfs_USB2_walk(inode, smemfs_superblock.inode_table, folder_id,
parent_inode = smemfs_USB2_walk(inode, smemfs_USB2_superblock.inode_table, folder_id,
WALK_FLAG_ID_CHECK_DIRECTORY);
// Stop atomic operation

4
src/kernel/fs/smemfs/power_graphic_2/inode/get_mode.c

@ -5,7 +5,7 @@
/* smemfs_get_mode() - Return the permission dans the type of a file (sync) */
mode_t smemfs_USB2_get_mode(void *inode)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
struct casio_smem_header_s *header;
mode_t inode_type;
@ -17,7 +17,7 @@ mode_t smemfs_USB2_get_mode(void *inode)
atomic_start();
// Check root inode
if (inode == smemfs_superblock.sector_table)
if (inode == smemfs_USB2_superblock.sector_table)
{
atomic_stop();
return (__S_IFDIR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

4
src/kernel/fs/smemfs/power_graphic_2/inode/get_name.c

@ -4,7 +4,7 @@
/* smemfs_get_name() - Dump the name of a file (sync) */
int smemfs_USB2_get_name(void *inode, char *buf, size_t count)
{
extern struct smemfs_superblock_s smemfs_superblock;
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
struct casio_smem_header_s *header;
// Check error
@ -15,7 +15,7 @@ int smemfs_USB2_get_name(void *inode, char *buf, size_t count)
atomic_start();
// Check root inode
if (inode == smemfs_superblock.sector_table)
if (inode == smemfs_USB2_superblock.sector_table)
{
buf[0] = '/';
buf[1] = '\0';

74
src/kernel/fs/smemfs/power_graphic_3/file/read.c

@ -0,0 +1,74 @@
#include <kernel/fs/smemfs.h>
#include <kernel/driver.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/util/casio.h>
#include <string.h>
static void generate_absolute_path(uint16_t *pathname, struct smemfs_USB3_inode *inode, int *pos)
{
// Root inode
if (inode == NULL) {
memcpy(pathname, u"\\\\fls0", 12);
*pos = 6;
return;
}
// Check parent inode
generate_absolute_path(pathname, inode->parent, pos);
// Insert file name
pathname[(*pos)++] = '\\';
for (int i = 0 ; inode->name[i] != '\0' ; )
{
pathname[*pos] = inode->name[i];
*pos = *pos + 1;
i = i + 1;
}
pathname[*pos] = '\0';
}
static void display_test(uint16_t *buffer)
{
for (int i = 0 ; buffer[i] != 0x0000 ; ++i)
earlyterm_write("%c", buffer[i] & 0x00ff);
earlyterm_write("\n");
DBG_WAIT;
}
ssize_t smemfs_USB3_read(void *inode, void *buf, size_t count, off_t pos)
{
struct smemfs_USB3_inode *smemfs_USB3_inode;
uint16_t pathname[64];
ssize_t read;
int handle;
// Check obvious error
if (inode == NULL)
return (-1);
// Get inode
smemfs_USB3_inode = inode;
generate_absolute_path(pathname, inode, &handle);
// We should use internal Casio's `Bfile_*` syscall
// to dump SMEM content
drivers_uninstall(0);
//DEBUG
display_test(pathname);
// Open the file
read = -1;
handle = casio_Bfile_OpenFile(pathname, _OPENMODE_READ);
if (handle >= 0)
{
read = casio_Bfile_ReadFile(handle, buf, count, pos);
casio_Bfile_CloseFile(handle);
}
// Restore all drivers
drivers_install(0);
// Return the number of readed bytes
return (read);
}

150
src/kernel/fs/smemfs/power_graphic_3/filesystem/mount.c

@ -1,5 +1,115 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/atomic.h>
#include <kernel/util/casio.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/driver.h>
#include <string.h>
static size_t wide_char_convert(char *pathname, uint16_t *pathname_wc)
{
size_t i;
i = -1;
while (pathname_wc[++i] != 0x0000 && pathname_wc[i] != 0xffff)
pathname[i] = pathname_wc[i] & 0x00ff;
pathname[i] = '\0';
return (i);
}
/*static void display_test(uint16_t *buffer)
{
for (int i = 0 ; buffer[i] != 0x0000 ; ++i)
earlyterm_write("%c", buffer[i] & 0x00ff);
earlyterm_write("\n");
}*/
// @note: send buffer to avoid recursif buffer definition
static void dump_smem_level(struct smemfs_USB3_inode *parent,
struct smemfs_USB3_inode **sibling, uint16_t *buffer)
{
struct casio_file_info file_info;
struct smemfs_USB3_inode *inode;
int handle;
int i;
// Generate search path
i = 7;
memcpy(buffer, u"\\\\fls0\\", 14);
if (parent != NULL) {
for (int j = 0 ; parent->name[j] != '\0' ; ) {
buffer[i] = (uint16_t)(parent->name[j]);
i = i + 1;
j = j + 1;
}
buffer[i++] = '\\';
}
buffer[i + 0] = '*';
buffer[i + 1] = 0x0000;
//DEBUG
//display_test(buffer);
// Find the first file
// @note: the search buffer and the buffer which will content
// the file name is the same. But it's not used at the same time
// so we can use this tricky way to save some stack
if (casio_Bfile_FindFirst(buffer, &handle, buffer, &file_info) != 0)
return;
// Get all inode stored in this level
i = 0;
do {
// Try to alloc new inode
// TODO: return error code !
*sibling = smemfs_USB3_alloc_inode();
if (*sibling == NULL)
break;
// Get first inide
if (i == 0)
inode = *sibling;
i = 1;
// Convert wide char into char
wide_char_convert((*sibling)->name, buffer);
// Dump file informations
(*sibling)->type = file_info.type;
(*sibling)->fsize = file_info.size.file;
(*sibling)->dsize = file_info.size.data;
// Link node and get next sibling
(*sibling)->parent = parent;
sibling = &(*sibling)->sibling;
} while (casio_Bfile_FindNext(handle, buffer, &file_info) == 0);
// Close casio BfileFind* handle
casio_Bfile_FindClose(handle);
// Now let's check all file to find directories
while (inode != NULL)
{
// Check directory type
if (inode->type == DT_DIRECTORY)
dump_smem_level(inode, &inode->child, buffer);
// Get next inode
inode = inode->sibling;
}
}
static void proto_ls(struct smemfs_USB3_inode *inode, int level)
{
if (inode == NULL)
return;
for (int i = 0 ; i < level ; ++i)
earlyterm_write(" ");
earlyterm_write("%s\n", inode->name);
if (inode->child != NULL)
proto_ls(inode->child, level + 1);
proto_ls(inode->sibling, level);
}
/*
** smemfs_USB3_mount() - Mount the file system (sync)
@ -10,19 +120,41 @@
*/
void *smemfs_USB3_mount(void)
{
extern struct smemfs_superblock_s smemfs_superblock;
void *root_inode = NULL;
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
uint16_t buffer[64];
void *root_inode;
// Start atomic operation
// Get current root inode
atomic_start();
root_inode = smemfs_USB3_superblock.root_inode;
atomic_stop();
//TODO
//TODO Use Bfile_FindFirst and Bfile_Find_Next to dump
//TODO All internal FS informations
//TODO
// Check useless mount
if (root_inode != NULL)
return (root_inode);
// Stop atomic operation
atomic_stop();
// We should use internal Casio's `Bfile_*` syscall
// to dump SMEM content
drivers_uninstall(0);
// Generate fake root inode
smemfs_USB3_superblock.fake_root_inode = (void*)0xdeadbeff;
// Dump SMEM files organisation
smemfs_USB3_superblock.root_inode = NULL;
dump_smem_level(smemfs_USB3_superblock.root_inode,
&smemfs_USB3_superblock.root_inode, buffer);
// Get the "fake" root inode
root_inode = smemfs_USB3_superblock.fake_root_inode;
//DEBUG
//proto_ls(smemfs_USB3_superblock.root_inode, 0);
//earlyterm_write("TAMER !\n");
//while (1);
// Restore all drivers
drivers_install(0);
// Return the sector table to simulate the root inode.
return (root_inode);

31
src/kernel/fs/smemfs/power_graphic_3/inode/find_first_child.c

@ -0,0 +1,31 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
void *smemfs_USB3_find_first_child(void *inode)
{
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
struct smemfs_USB3_inode *smemfs_USB3_inode;
struct smemfs_USB3_inode *child_inode;
// Check error
if (inode == NULL)
return (NULL);
// Get smemfs inode
smemfs_USB3_inode = inode;
// Check fake root and get child if possible
atomic_start();
child_inode = smemfs_USB3_superblock.root_inode;
if (inode != smemfs_USB3_superblock.fake_root_inode)
child_inode = smemfs_USB3_inode->child;
atomic_stop();
// Debug
//earlyterm_write("First child %s$\n", child_inode->name);
//DBG_WAIT;
// Return child inode
return (child_inode);
}

33
src/kernel/fs/smemfs/power_graphic_3/inode/find_next_sibling.c

@ -0,0 +1,33 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
void *smemfs_USB3_find_next_sibling(void *inode)
{
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
struct smemfs_USB3_inode *smemfs_USB3_inode;
struct smemfs_USB3_inode *sibling_inode;
// Check error
if (inode == NULL)
return (NULL);
// Get smemfs inode
smemfs_USB3_inode = inode;
// Get fake root and get next sibling if possible
atomic_start();
sibling_inode = NULL;
if (inode != smemfs_USB3_superblock.fake_root_inode)
sibling_inode = smemfs_USB3_inode->sibling;
atomic_stop();
// Debug
//if (sibling_inode != NULL) {
// earlyterm_write("Sibling: %s$\n", sibling_inode->name);
// DBG_WAIT;
//}
// Return next sibling inode
return (sibling_inode);
}

26
src/kernel/fs/smemfs/power_graphic_3/inode/find_parent.c

@ -0,0 +1,26 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/atomic.h>
void *smemfs_USB3_find_parent(void *inode)
{
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
struct smemfs_USB3_inode *smemfs_USB3_inode;
void *parent_inode;
// Check error
if (inode == NULL)
return (NULL);
// Get smemfs inode
smemfs_USB3_inode = inode;
// Get fake root and get parent inode if possible
atomic_start();
parent_inode = NULL;
if (inode != smemfs_USB3_superblock.fake_root_inode)
parent_inode = smemfs_USB3_inode->parent;
atomic_stop();
// Return parent inode
return (parent_inode);
}

39
src/kernel/fs/smemfs/power_graphic_3/inode/get_mode.c

@ -0,0 +1,39 @@
#include <kernel/fs/smemfs.h>
#include <kernel/fs/stat.h>
#include <kernel/util/atomic.h>
#include <kernel/util/casio.h>
mode_t smemfs_USB3_get_mode(void *inode)
{
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
struct smemfs_USB3_inode *smemfs_USB3_inode;
mode_t inode_type;
// Check error
if (inode == NULL)
return (-1);
// Get smemfs inode
smemfs_USB3_inode = inode;
// Get file name
atomic_start();
// Check fake root
if (inode == smemfs_USB3_superblock.fake_root_inode) {
atomic_stop();
return (__S_IFDIR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
}
// We can only check if the file is a
// directory or not (Bfile limitation)
// TODO ?
inode_type = __S_IFREG;
if (smemfs_USB3_inode->type == DT_DIRECTORY)
inode_type = __S_IFDIR;
atomic_stop();
// Return default permission and type
return (inode_type | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
}

34
src/kernel/fs/smemfs/power_graphic_3/inode/get_name.c

@ -0,0 +1,34 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/atomic.h>
#include <string.h>
int smemfs_USB3_get_name(void *inode, char *name, size_t count)
{
extern struct smemfs_USB3_superblock smemfs_USB3_superblock;
struct smemfs_USB3_inode *smemfs_USB3_inode;
// Check error
if (inode == NULL)
return (-1);
// Get smemfs inode
smemfs_USB3_inode = inode;
// Get file name
atomic_start();
// Check fake root inode
if (inode == smemfs_USB3_superblock.fake_root_inode) {
name[0] = '/';
name[1] = '\0';
atomic_stop();
return (0);
}
strncpy(name, smemfs_USB3_inode->name, count);
atomic_stop();
// Return count
// TODO: real count
return (count);
}

14
src/kernel/fs/smemfs/power_graphic_3/superblock/alloc_inode.c

@ -0,0 +1,14 @@
#include <kernel/fs/smemfs.h>
#include <kernel/util/kmem.h>
#include <string.h>
struct smemfs_USB3_inode *smemfs_USB3_alloc_inode(void)
{
struct smemfs_USB3_inode *inode;
// Try to alloc new inode
inode = kmem_alloc(sizeof(struct smemfs_USB3_inode));
if (inode != NULL)
memset(inode, 0x00, sizeof(struct smemfs_USB3_inode));
return (inode);
}

19
src/kernel/loader/entry.c

@ -18,7 +18,7 @@ int loader(struct process *process, const char *path)
if (process == NULL || vfs_open(&file, path, O_RDONLY) != 0)
{
earlyterm_write("loader: Fault error !\n");
earlyterm_write("* path: %s$\n", path);
earlyterm_write("* path: %s$\n", path);
earlyterm_write("* process: %p\n", process);
DBG_WAIT;
return (-1);
@ -32,10 +32,6 @@ int loader(struct process *process, const char *path)
{
earlyterm_write("loader: ELF file header error ! (%d)\n", err);
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
return (-2);
}
@ -45,11 +41,6 @@ int loader(struct process *process, const char *path)
{
earlyterm_write("loader: ELF file image error ! (%d)\n", err);
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
return (-3);
}
@ -59,14 +50,10 @@ int loader(struct process *process, const char *path)
{
earlyterm_write("loader: ELF relo error ! (%d)\n", err);
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
DBG_WAIT;
return (-4);
}
// Close file
vfs_close(&file);
return (0);
}

9
src/kernel/util/casio/menu.c

@ -2,10 +2,7 @@
#include <kernel/util/atomic.h>
#include <kernel/bits/context.h>
#include <kernel/devices/earlyterm.h>
// Internal bootstrap primitives
extern void bootstrap_drivers_install(void);
extern void bootstrap_drivers_uninstall(void);
#include <kernel/driver.h>
// Internal informations
int casio_timer_id;
@ -30,7 +27,7 @@ void casio_return_menu(int mode)
int col;
// unistall / restore all drivers
bootstrap_drivers_uninstall();
drivers_uninstall(0);
// If we should involve main menu manually
// we need to setup one timer which will inject
@ -47,5 +44,5 @@ void casio_return_menu(int mode)
} while (mode == 1);
// Re-install Vhex drivers
bootstrap_drivers_install();
drivers_install(0);
}

90
src/kernel/util/casio/syscall.s

@ -17,11 +17,14 @@
.global _casio_Bkey_PutKeymatrix
.global _casio_CreateFile
.global _casio_OpenFile
.global _casio_ReadFile
.global _casio_WriteFile
.global _casio_CloseFile
.global _casio_Bfile_CreateFile
.global _casio_Bfile_OpenFile
.global _casio_Bfile_ReadFile
.global _casio_Bfile_WriteFile
.global _casio_Bfile_CloseFile
.global _casio_Bfile_FindFirst
.global _casio_Bfile_FindNext
.global _casio_Bfile_FindClose
.global _casio_TimerInstall
.global _casio_TimerUninstall
@ -48,11 +51,14 @@
.type _casio_Bkey_PutKeymatrix, @function
.type _casio_CreateFile, @function
.type _casio_OpenFile, @function
.type _casio_ReadFile, @function
.type _casio_WriteFile, @function
.type _casio_CloseFile, @function
.type _casio_Bfile_CreateFile, @function
.type _casio_Bfile_OpenFile, @function
.type _casio_Bfile_ReadFile, @function
.type _casio_Bfile_WriteFile, @function
.type _casio_Bfile_CloseFile, @function
.type _casio_Bfile_FindFirst, @function
.type _casio_Bfile_FindNext, @function
.type _casio_Bfile_FindClose, @function
.type _casio_SetTimer, @function
@ -68,7 +74,6 @@ _casio_Bdisp_GetVRAM:
jmp @r1
nop
_casio_Bdisp_PrintMini:
mov.l .syscall_entry, r1
mov.l .sys_printMini, r0
@ -118,6 +123,8 @@ _casio_Bdisp_SaveDisp:
nop
_casio_Malloc:
mov.l .syscall_entry, r1
mov.l .sys_malloc, r0
@ -131,6 +138,8 @@ _casio_Free:
nop
_casio_GetKey:
mov.l .syscall_entry, r1
mov.l .sys_getkey, r0
@ -143,43 +152,65 @@ _casio_GetKeyWait:
jmp @r1
nop
_casio_Bkey_PutKeymatrix:
mov.l .syscall_entry, r1
mov.l .sys_putKeycode, r0
jmp @r1
nop
_casio_CreateFile:
_casio_Bfile_CreateFile:
mov.l .syscall_entry, r1
mov.l .sys_createFile, r0
mov.l .sys_Bfile_CreateFile, r0
jmp @r1
nop
_casio_OpenFile:
_casio_Bfile_OpenFile:
mov.l .syscall_entry, r1
mov.l .sys_openFile, r0
mov.l .sys_Bfile_OpenFile, r0
jmp @r1
nop
_casio_WriteFile:
_casio_Bfile_WriteFile:
mov.l .syscall_entry, r1
mov.l .sys_writeFile, r0
mov.l .sys_Bfile_WriteFile, r0
jmp @r1
nop
_casio_ReadFile:
_casio_Bfile_ReadFile:
mov.l .syscall_entry, r1
mov.l .sys_readFile, r0
mov.l .sys_Bfile_ReadFile, r0
jmp @r1
nop
_casio_CloseFile:
_casio_Bfile_CloseFile:
mov.l .syscall_entry, r1
mov.l .sys_closeFile, r0
mov.l .sys_Bfile_CloseFile, r0
jmp @r1
nop
_casio_Bfile_FindFirst:
mov.l .syscall_entry, r1
mov.l .sys_Bfile_FindFirst, r0
jmp @r1
nop
_casio_Bfile_FindNext:
mov.l .syscall_entry, r1
mov.l .sys_Bfile_FindNext, r0
jmp @r1
nop
_casio_Bfile_FindClose:
mov.l .syscall_entry, r1
mov.l .sys_Bfile_FindClose, r0
jmp @r1
nop
_casio_TimerInstall:
mov.l .syscall_entry, r1
@ -219,13 +250,18 @@ _casio_TimerStop:
.sys_save_disp: .long 0x00000813
.sys_malloc: .long 0x00000acd
.sys_free: .long 0x00000acc
.sys_createFile: .long 0x00000434
.sys_openFile: .long 0x0000042c
.sys_writeFile: .long 0x00000435
.sys_readFile: .long 0x00000432
.sys_closeFile: .long 0x0000042d
.sys_getkeywait: .long 0x00000247
.sys_putKeycode: .long 0x0000024f
.sys_Bfile_CreateFile: .long 0x00000434
.sys_Bfile_OpenFile: .long 0x0000042c
.sys_Bfile_WriteFile: .long 0x00000435
.sys_Bfile_ReadFile: .long 0x00000432
.sys_Bfile_CloseFile: .long 0x0000042d
.sys_Bfile_FindFirst: .long 0x0000043b
.sys_Bfile_FindNext: .long 0x0000043c
.sys_Bfile_FindClose: .long 0x0000043d
.sys_TimerInstall: .long 0x00000118
.sys_TimerUninstall: .long 0x00000119
.sys_TimerStart: .long 0x0000011a

Loading…
Cancel
Save