Physical memory refactor + update lib part + add arguments managements

This commit is contained in:
Yann MAGNIN 2020-03-30 00:40:59 +02:00
parent 0a49df9a83
commit 61582ad9f9
111 changed files with 983 additions and 353 deletions

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <lib/display.h>
#include <display.h>
// Wait for debug (dirty)
// TODO: use earlyterm_read() to wait key event ?

View File

@ -3,9 +3,9 @@
#include <stddef.h>
#include <stdint.h>
#include <asm/types.h>
#include <kernel/drivers/screen.h>
#include <kernel/util/types.h>
#include <lib/display.h>
#include <display.h>
// Define default buffer size.
// TODO: remove me ?

View File

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

View File

@ -3,24 +3,14 @@
#include <stdint.h>
#include <stddef.h>
#include <kernel/util/types.h>
#include <asm/types.h>
#include <kernel/fs/filesystem.h>
#ifndef FILE_OPEN_NUMBER
# define FILE_OPEN_NUMBER 4
#endif
// TODO: fix me
#ifndef __LIB_UNISTD_H__
# define O_RDONLY 0x00
# define O_WRONLY 0x01
# define O_RDWR 0x02
# define SEEK_SET 0
# define SEEK_CUR 1
# define SEEK_END 2
#endif
// FILE type
struct file_s
{
void *private;

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <kernel/util/types.h>
#include <asm/types.h>
#include <kernel/fs/filesystem.h>
#include <kernel/fs/file.h>
#include <kernel/devices/device.h>

View File

@ -105,14 +105,20 @@ struct memory_info
};
// Function
extern void *pm_alloc(size_t size);
extern void pm_free(void *ptr);
extern void pm_debug(void);
// "user" function
extern void *pm_heap_alloc(struct pm_heap_page **page, size_t size);
extern void *pm_heap_realloc(struct pm_heap_page **page, void *ptr, size_t size);
extern void pm_heap_debug(struct pm_heap_page *page);
extern void pm_heap_free(struct pm_heap_page *page, void *ptr);
// Page allocator
extern void *pm_pages_alloc(int nb_pages);
extern void pm_pages_free(void *addr);
// Internal helpers
extern void *pm_block_split(struct pm_heap_block *block, size_t size);
extern void pm_block_frontmerge(struct pm_heap_block *block, void *brk);
extern void pm_block_backmerge(struct pm_heap_block **block, struct pm_heap_block *parent);
#endif /*__KERNEL_MEMORY_H__*/

View File

@ -6,7 +6,7 @@
#include <kernel/fs/file.h>
#include <kernel/fs/filesystem.h>
#include <kernel/context.h>
#include <kernel/util/types.h>
#include <asm/types.h>
#define PROCESS_NB_OPEN_FILE (4)
#define PROCESS_USER_STACK_SIZE (2 * 1024)
@ -78,7 +78,7 @@ struct process
void *start;
size_t size;
} exit;
struct heap *heap;
struct pm_heap_page *heap;
} memory;
@ -120,7 +120,7 @@ extern struct process *process_create(void);
extern int process_switch(pid_t pid);
// Internals
// Internals (kernel only)
extern struct process *process_alloc(void);
extern struct process *process_get(pid_t pid);
extern int process_free(struct process *process);

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include <kernel/util/types.h>
#include <asm/types.h>
// Process
extern pid_t sys_getpid(void);
@ -12,7 +12,7 @@ extern pid_t sys_getpgid(void);
extern pid_t sys_wait(int *wstatus);
extern int sys_setpgid(pid_t pid, pid_t pgid);
extern pid_t sys_waitpid(pid_t pid, int *wstatus, int options);
extern pid_t sys_fexecve(const char *pathname);
extern pid_t sys_fexecve(const char *pathname, char **argv, char **envp);
extern void sys_exit(int status);
// File
@ -28,5 +28,8 @@ extern int sys_close(int fd);
extern void *sys_mmap(void *addr, size_t length,
int prot, int flags, int fd, off_t offset);
extern int sys_munmap(void *addr, size_t length);
extern void *sys_proc_heap_alloc(size_t size);
extern void *sys_proc_heap_realloc(void *ptr, size_t size);
extern void sys_proc_heap_free(void *ptr);
#endif /*__SYSCALL_H__*/

View File

@ -0,0 +1,13 @@
#ifndef __KERNEL_UTIL_KMEM_H__
# define __KERNEL_UTIL_KMEM_H__
#include <stddef.h>
#include <stdint.h>
// Kernel memomries allocation function wrapper
extern void *kmem_alloc(size_t size);
extern void *kmem_realloc(void *ptr, size_t size);
extern void kmem_free(void *ptr);
extern void kmem_debug(void);
#endif /*__KERNEL_UTIL_KMEM_H__*/

View File

@ -1,8 +1,8 @@
#ifndef __KERNEL_UNISTD_32_H__
# define __KERNEL_UNISTD_32_H__
#ifndef __ASM_UNISTD_32_H__
# define __ASM_UNISTD_32_H__
// Define the number of syscall
#define __NR_MAX 18
#define __NR_MAX 21
// Kernel Test
#define __NR_test_syscall 0
@ -29,5 +29,8 @@
// Memory
#define __NR_mmap 16
#define __NR_munmap 17
#define __NR_proc_heap_alloc 18
#define __NR_proc_heap_free 19
#define __NR_proc_heap_realloc 20
#endif /*__KERNEL_UNISTD_32_H__*/
#endif /*__ASM_UNISTD_32_H__*/

156
include/lib/errno.h Normal file
View File

@ -0,0 +1,156 @@
#ifndef __KERNEL_ERRNO_H__
# define __KERNEL_ERRNO_H__ 1
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
/*
* This error code is special: arch syscall entry code will return
* -ENOSYS if users try to call a syscall that doesn't exist. To keep
* failures of syscalls that really do exist distinguishable from
* failures due to attempts to use a nonexistent syscall, syscall
* implementations should refrain from returning -ENOSYS.
*/
#define ENOSYS 38 /* Invalid system call number */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define ENOTSUP EOPNOTSUPP /* Not supported (may be the same value as [EOPNOTSUPP]) */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED 125 /* Operation Canceled */
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define ERFKILL 132 /* Operation not possible due to RF-kill */
#define EHWPOISON 133 /* Memory page has hardware error */
#endif /* __KERNEL_ERRNO_H__ */

20
include/lib/fcntl.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __LIB_FCNTL_H__
# define __LIB_FCNTL_H__
#include <stddef.h>
#include <stdint.h>
//TODO: update me !!
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
//TODO: define also in <stdio.h>
#define SEEK_SET 0 /* Seek from beginning of file. */
#define SEEK_CUR 1 /* Seek from current position. */
#define SEEK_END 2 /* Seek from end of file. */
// Functions
extern int open(const char *pathname, int flags, ...);
#endif /*__LIB_FCNTL_H__*/

30
include/lib/stdlib.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef __LIB_STDLIB_H__
# define __LIB_STDLIB_H__
#include <stddef.h>
#include <stdint.h>
#define HEAP_BLOCK_MIN (16)
struct heap_block
{
uint16_t status; /* status of the block (1=used,0=free) */
uint16_t size; /* size of the block (without block header) */
} __attribute__((packed, aligned(2)));
struct heap_page
{
void *brk; /* break (address of the limit area) */
size_t size; /* Page size (without header) */
struct heap_page *next; /* Next heap page */
struct heap_block heap; /* Start of block informations */
} __attribute__((packed, aligned(4)));
// Functions
extern void *malloc(size_t size);
extern void *calloc(size_t nmemb, size_t size);
extern void *realloc(void *ptr, size_t size);
extern void *reallocarray(void *ptr, size_t nmemb, size_t size);
extern void free(void *ptr);
#endif /*__LIB_STDLIB_H__*/

View File

@ -26,4 +26,7 @@ extern size_t strlen(char const *str);
/* strrchr() - find the last occurent of a byte */
extern char *strrchr(const char *s, int c);
/* strdup() - dump string */
extern char *strdup(const char *s);
#endif /*__STRING_H__*/

44
include/lib/sys/mman.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef __LIB_SYS_MMAN_H__
# define __LIB_SYS_MMAN_H__
#include <stddef.h>
#include <stdint.h>
#ifndef __KERNEL_MEMORY_H__
// mapping flags
// Protection (unused)
#define PROT_READ 0x1 /* Page can be read. */
#define PROT_WRITE 0x2 /* Page can be written. */
#define PROT_EXEC 0x4 /* Page can be executed. */
#define PROT_NONE 0x0 /* Page can not be accessed. */
// Mapping flags
#define MAP_SHARED 0x01 /* Share changes. */
#define MAP_PRIVATE 0x02 /* Changes are private. */
#define MAP_ANONYMOUS 0x20 /* Don't use a file. */
#define MAP_ANON MAP_ANONYMOUS /* Don't use a file. */
#define MAP_FILE 0 /* Ignored. */
#define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
#define MAP_DENYWRITE 0x00800 /* ETXTBSY. */
#define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
#define MAP_LOCKED 0x02000 /* Lock the mapping. */
#define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
#define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
#define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
#define MAP_STACK 0x20000 /* Allocation is for a stack. */
#define MAP_HUGETLB 0x40000 /* Create huge page mapping. */
#define MAP_SYNC 0x80000 /* Perform synchronous page
faults for the mapping. */
#define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED but do not unmap
underlying mapping. */
#define MAP_UNINITIALIZED 0x200000 /* Don't clear anonymous page */
// Value returned when mmap value
#define MAP_FAILED ((void*) -1)
#endif
// Prototype
extern void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
extern int munmap(void *addr, size_t length);
#endif /*__LIB_SYS_MMAN_H__*/

View File

@ -3,16 +3,18 @@
#include <stddef.h>
#include <stdint.h>
#include <kernel/util/types.h>
// Define syscall LIST
#include <kernel/util/unistd_32.h>
#include <asm/types.h>
// TODO: move me
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
//TODO: move me
#define _SC_PAGE_SIZE 0
#define _SC_PAGESIZE _SC_PAGE_SIZE
//TODO: move me
#define WNOHANG 0
#define WUNTRACED 1
@ -23,31 +25,21 @@
#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);
extern pid_t fexecve(const char *pathname, char **argv, char **envp);
// File syscall
// TODO: move me
// FIXME: find real value
#ifndef __FILE_H__
# define O_DIRECT 0
# define O_DIRECTORY 1
# define O_RDONLY 2
# define O_WRONLY 4
# define O_RDWR 8
# define SEEK_SET 0
# define SEEK_CUR 1
# define SEEK_END 2
#endif
extern int open(const char *pathname, int flags, ...);
// File part
extern ssize_t write(int fd, const void *buf, size_t count);
extern ssize_t read(int fd, void *buf, size_t count);
extern off_t lseek(int fd, off_t offset, int whence);
extern int close(int fd);
// System part
extern long sysconf(int name);
#endif /*__LIB_UNISTD_H__*/

View File

@ -8,7 +8,7 @@
// Generate a "command block" stored in ".cmd.cahce" section.
// We need to "hide" the block, so we generate anonyme name using
// __COUNTER__ macros.
#define gen_name(n) _##n
/*#define gen_name(n) _##n
#define anonym_name(n) gen_name(n)
#define VHEX_BUILTIN(builtin) \
static int builtin(int argc, char **argv); \
@ -18,6 +18,7 @@
.entry = builtin \
}; \
static int builtin(int argc, char **argv)
*/
// Define builtin struct.
struct builtin_s
@ -29,6 +30,7 @@ struct builtin_s
// Builtin list
extern int builtin_proc(void);
extern int builtin_ram(void);
extern int builtin_fxdb(int argc, char **argv);
#endif /*__USER_BUILTIN_H__*/

11
include/user/shell/util.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef __USER_UTIL_H__
# define __USER_UTIL_H__
#include <stddef.h>
#include <stdint.h>
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);
#endif /*__USER_UTIL_H__*/

View File

@ -1,9 +0,0 @@
#ifndef __USER_UTIL_H__
# define __USER_UTIL_H__
#include <stddef.h>
#include <stdint.h>
extern int check_builtin(char *cmd);
#endif /*__USER_UTIL_H__*/

View File

@ -11,7 +11,7 @@ include ../../global.mk
##---
## Static variables
##--
HEADER := -I../../include
HEADER := -I../../include -I../../include/lib
BUILD := ../../build/kernel
OUTPUT := ../../output
DEBUG := ../../debug_bin

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#include <kernel/devices/tty.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
int tty_close(void *inode)
{
@ -13,10 +13,10 @@ int tty_close(void *inode)
// output buffer
line = tty->cursor.max.y;
while (line >= 0)
pm_free(tty->buffers.output[line]);
pm_free(tty->buffers.output);
kmem_free(tty->buffers.output[line]);
kmem_free(tty->buffers.output);
// Free'd tty object
pm_free(tty);
kmem_free(tty);
return (0);
}

View File

@ -1,7 +1,7 @@
#include <kernel/devices/tty.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/drivers/screen.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <lib/display.h>
#include <lib/string.h>
@ -15,14 +15,14 @@ void *tty_open(dev_t major, dev_t minor)
(void)minor;
// Try to allocate tty object
tty = (struct tty_s*)pm_alloc(sizeof(struct tty_s));
tty = (struct tty_s*)kmem_alloc(sizeof(struct tty_s));
if (tty == NULL)
return (NULL);
// Get the font used by the tty.
if (dopen(&tty->disp, "default") != 0)
{
pm_free(tty);
kmem_free(tty);
return (NULL);
}
@ -38,10 +38,10 @@ void *tty_open(dev_t major, dev_t minor)
tty->cursor.max.y = tty->cursor.max.y * 4;
// Try to alloc new tty output buffer
tty->buffers.output = (char **)pm_alloc(sizeof(char *) * tty->cursor.max.y);
tty->buffers.output = (char **)kmem_alloc(sizeof(char *) * tty->cursor.max.y);
if (tty->buffers.output == NULL)
{
pm_free(tty);
kmem_free(tty);
return (NULL);
}
@ -50,16 +50,16 @@ void *tty_open(dev_t major, dev_t minor)
while (--line >= 0)
{
// Try to alloc the line
tty->buffers.output[line] = (char*)pm_alloc(tty->cursor.max.x);
tty->buffers.output[line] = (char*)kmem_alloc(tty->cursor.max.x);
if (tty->buffers.output[line] != NULL) {
memset(tty->buffers.output[line], '\0', tty->cursor.max.x);
continue;
}
// Release all allocated space and return NULL
while (++line < tty->cursor.max.y)
pm_free(tty->buffers.output[line]);
pm_free(tty->buffers.output);
pm_free(tty);
kmem_free(tty->buffers.output[line]);
kmem_free(tty->buffers.output);
kmem_free(tty);
return (NULL);
}

View File

@ -119,7 +119,13 @@ static int check_special(struct keyboard_obj_s *keyboard, key_t key)
return (1);
}
// Check DEL key.
// Check space key
if (key == KEY_DOT && (keyboard->mode & 1) == 0) {
buffer_insert(keyboard, ' ');
return (1);
}
// Check DEL key.
if (key == KEY_DEL)
{
// Check potential error.

View File

@ -1,5 +1,5 @@
#include <kernel/fs/gladfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
/* gladfs_alloc_fragdata() - Superblock primitive to alloc "empty" fragment data block (sync) */
@ -15,7 +15,7 @@ int gladfs_alloc_fragdata(struct gladfs_fragment_data_s **parent, int nb_block)
atomic_start();
// Try to alloc block
*parent = pm_alloc(gladfs_superblock.block_size * nb_block);
*parent = kmem_alloc(gladfs_superblock.block_size * nb_block);
if (*parent == NULL)
{
atomic_stop();

View File

@ -1,5 +1,5 @@
#include <kernel/fs/gladfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
#include <lib/string.h>
@ -12,7 +12,7 @@ struct gladfs_inode_s *gladfs_alloc_inode(const char *name, mode_t mode)
atomic_start();
// alloc memory
inode = pm_alloc(sizeof(struct gladfs_inode_s));
inode = kmem_alloc(sizeof(struct gladfs_inode_s));
if (inode == NULL)
{
atomic_stop();

View File

@ -1,5 +1,5 @@
#include <kernel/fs/gladfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
/* gladfs_destroy_fragdata() - Free'd allocated fragmented data (sync) */
@ -14,7 +14,7 @@ int gladfs_destroy_fragdata(struct gladfs_fragment_data_s *fragment)
atomic_start();
// Free'd allocated space
pm_free(fragment);
kmem_free(fragment);
// Stop atomic operation
atomic_stop();

View File

@ -1,5 +1,5 @@
#include <kernel/fs/gladfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
/* gladfs_destroy_inode() - Free'd allocated inode (sync) */
@ -29,7 +29,7 @@ int gladfs_destroy_inode(struct gladfs_inode_s *inode)
}
// Free inode
pm_free(inode);
kmem_free(inode);
// Stop atomic operations
atomic_stop();

View File

@ -1,5 +1,6 @@
#include <kernel/fs/vfs.h>
#include <kernel/process.h>
#include <fcntl.h>
ssize_t sys_pread(int fd, void *buf, size_t count, off_t offset)
{

View File

@ -1,5 +1,6 @@
#include <kernel/fs/vfs.h>
#include <kernel/process.h>
#include <fcntl.h>
ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t offset)
{

View File

@ -1,5 +1,6 @@
#include <kernel/fs/vfs.h>
#include <kernel/process.h>
#include <fcntl.h>
ssize_t sys_read(int fd, void *buf, size_t count)
{

View File

@ -1,5 +1,6 @@
#include <kernel/fs/vfs.h>
#include <kernel/process.h>
#include <fcntl.h>
ssize_t sys_write(int fd, const void *buf, size_t count)
{

View File

@ -1,5 +1,5 @@
#include <kernel/fs/vfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
#include <lib/string.h>
/* vfs_dentry_alloc() - Allocate new "empty" dentry */
@ -8,7 +8,7 @@ struct dentry *vfs_dentry_alloc(const char *name, mode_t mode)
struct dentry *node;
// Try to create new dentry
node = pm_alloc(sizeof(struct dentry));
node = kmem_alloc(sizeof(struct dentry));
if (node == NULL)
return (NULL);

View File

@ -1,5 +1,5 @@
#include <kernel/fs/vfs.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
/* vfs_dentry_free() - Free'd allocated dentry */
/* @note: *WARNING* no verification will be done, so do not use this primitive */
@ -10,5 +10,5 @@ void vfs_dentry_free(struct dentry *dentry)
return;
// Free'd allocated space
pm_free(dentry);
kmem_free(dentry);
}

View File

@ -1,5 +1,6 @@
#include <kernel/fs/vfs.h>
#include <kernel/fs/file.h>
#include <fcntl.h>
/* vfs_lseek() - File cursor management */
off_t vfs_lseek(FILE *file, off_t offset, int whence)

View File

@ -3,6 +3,7 @@
#include <kernel/fs/file.h>
#include <kernel/util/elf.h>
#include <kernel/devices/earlyterm.h>
#include <fcntl.h>
//
// TODO: write doc

View File

@ -1,5 +1,6 @@
#include <kernel/loader.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/util/kmem.h>
#include <kernel/memory.h>
#include <kernel/fs/vfs.h>
@ -19,7 +20,7 @@ static char *get_shstrtab(FILE *file, Elf32_Ehdr *header)
// Allocate dump area
earlyterm_write("Try to alloc strtab (%do)\n", shdr.sh_size);
shstrtab = (char*)pm_alloc(shdr.sh_size);
shstrtab = (char*)kmem_alloc(shdr.sh_size);
if (shstrtab == NULL)
{
earlyterm_write("relo_sym:mem (%d)\n", shdr.sh_size);
@ -30,7 +31,7 @@ static char *get_shstrtab(FILE *file, Elf32_Ehdr *header)
if (vfs_pread(file, shstrtab, shdr.sh_size, shdr.sh_offset) != (ssize_t)shdr.sh_size)
{
earlyterm_write("relo_sym: shstrtab size error\n");
pm_free(shstrtab);
kmem_free(shstrtab);
return (NULL);
}
return (shstrtab);
@ -102,6 +103,6 @@ int loader_reloc_sym(struct process *process, FILE *file, Elf32_Ehdr *header)
if (reloc_section(process, file, &shdr) != 0)
return (-3);
}
pm_free(shstrtab);
kmem_free(shstrtab);
return (0);
}

View File

@ -2,35 +2,6 @@
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
static void *pm_block_split(struct pm_heap_block *block, size_t size)
{
size_t rest_size;
void *ret;
// Check size
if (block->size < size)
return (NULL);
// Change current block status
block->status = 1;
// Check if we can not split
rest_size = block->size - (size + sizeof(struct pm_heap_block));
if (rest_size < PM_HEAP_BLOCK_MIN)
return (&block[1]);
// Update current block size and get the
// returned value
block->size = size;
ret = &block[1];
// Initialize seconde block
block = (void *)&block[1] + block->size;
block->status = 0;
block->size = rest_size;
return (ret);
}
static void *new_pages(struct pm_heap_page **page, size_t size)
{
int nb_page;
@ -57,7 +28,7 @@ static void *new_pages(struct pm_heap_page **page, size_t size)
return (pm_block_split(&(*page)->heap, size));
}
static void *pm_heap_alloc(struct pm_heap_page *page, size_t size)
static void *pm_heap_page_check(struct pm_heap_page *page, size_t size)
{
struct pm_heap_block *block;
size_t rest_size;
@ -85,10 +56,8 @@ static void *pm_heap_alloc(struct pm_heap_page *page, size_t size)
}
// Kernel malloc wrapper
void *pm_alloc(size_t size)
void *pm_heap_alloc(struct pm_heap_page **page, size_t size)
{
extern struct memory_info pmemory;
struct pm_heap_page **page;
void *ret;
// Force 4-align
@ -98,7 +67,6 @@ void *pm_alloc(size_t size)
atomic_start();
// Walk into each pages x_x
page = &pmemory.kheap;
while (*page != NULL)
{
// Check "page" size
@ -108,7 +76,7 @@ void *pm_alloc(size_t size)
}
// Try to find free space in the page
ret = pm_heap_alloc(*page, size);
ret = pm_heap_page_check(*page, size);
if (ret != NULL) {
atomic_stop();
return (ret);

View File

@ -0,0 +1,56 @@
#include <kernel/memory.h>
void *pm_block_split(struct pm_heap_block *block, size_t size)
{
int rest_size;
void *ret;
// Check size
if (block->size < size)
return (NULL);
// Change current block status
block->status = 1;
// Check if we can not split
rest_size = block->size - (size + sizeof(struct pm_heap_block));
if (rest_size < PM_HEAP_BLOCK_MIN)
return (&block[1]);
// Update current block size and get the
// returned value
block->size = size;
ret = &block[1];
// Initialize seconde block
block = (void *)&block[1] + block->size;
block->status = 0;
block->size = rest_size;
return (ret);
}
void pm_block_backmerge(struct pm_heap_block **block, struct pm_heap_block *parent)
{
// Check back-merge possibility
if (parent == NULL || parent->status != 0)
return;
// Absorb current block
parent->size += (*block)->size + sizeof(struct pm_heap_block);
// Switch current block
*block = parent;
}
void pm_block_frontmerge(struct pm_heap_block *block, void *brk)
{
struct pm_heap_block *block_front;
// Check front-merge possibility
block_front = (void*)&block[1] + block->size;
if ((void*)block_front >= brk || block_front->status != 0)
return;
// Absorb front block
block->size += block_front->size + sizeof(struct pm_heap_block);
}

View File

@ -1,11 +1,10 @@
#include <kernel/memory.h>
#include <kernel/devices/earlyterm.h>
void pm_debug(void)
void pm_heap_debug(struct pm_heap_page *page)
{
extern struct memory_info pmemory;
struct pm_heap_block *block;
struct pm_heap_page *page;
page = pmemory.kheap;
while (page != NULL)

View File

@ -2,33 +2,6 @@
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
static void pm_block_backmerge(struct pm_heap_block **block,
struct pm_heap_block *parent)
{
// Check back-merge possibility
if (parent == NULL || parent->status != 0)
return;
// Absorb current block
parent->size += (*block)->size + sizeof(struct pm_heap_block);
// Switch current block
*block = parent;
}
static void pm_block_frontmerge(struct pm_heap_block *block, void *brk)
{
struct pm_heap_block *block_front;
// Check front-merge possibility
block_front = (void*)&block[1] + block->size;
if ((void*)block_front >= brk || block_front->status != 0)
return;
// Absorb front block
block->size += block_front->size + sizeof(struct pm_heap_block);
}
static int pm_block_free(struct pm_heap_page *page, void *ptr)
{
struct pm_heap_block *block_parent;
@ -57,16 +30,12 @@ static int pm_block_free(struct pm_heap_page *page, void *ptr)
return (-1);
}
void pm_free(void *ptr)
void pm_heap_free(struct pm_heap_page *page, void *ptr)
{
extern struct memory_info pmemory;
struct pm_heap_page *page;
// Start atomic operations
atomic_start();
// Try to find the page
page = pmemory.kheap;
while (page != NULL)
{
// If is the page is found

View File

@ -0,0 +1,108 @@
#include <kernel/memory.h>
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
#include <string.h>
// Internal function
extern void *pm_block_split(struct pm_heap_block *block, size_t size);
extern void pm_block_backmerge(struct pm_heap_block **block, struct pm_heap_block *parent);
extern void pm_block_frontmerge(struct pm_heap_block *block, void *brk);
static int pm_block_update(struct pm_heap_block *block, size_t size, void *brk)
{
struct pm_heap_block *block_front;
// Check front block validity
block_front = (void*)&block[1] + block->size;
if ((void*)block_front >= brk || block_front->status != 0)
return (-1);
// Check size
if (block_front->size + sizeof(struct pm_heap_block) + block->size < size)
return (-1);
// merge front block and try to split the block
block->size += block_front->size + sizeof(struct pm_heap_block);
pm_block_split(block, size);
return (0);
}
static void *pm_block_realloc(struct pm_heap_page **page, void *ptr, size_t size)
{
struct pm_heap_block *block_parent;
struct pm_heap_block *block;
struct pm_heap_block *new;
block_parent = NULL;
block = &(*page)->heap;
while ((void*)block < (*page)->brk)
{
// check block validity
if ((void*)&block[1] != ptr)
{
block_parent = block;
block = (void*)&block[1] + block->size;
continue;
}
// Check useless action
if (block->size >= size || pm_block_update(block, size, (*page)->brk) == 0)
return (&block[1]);
// Manually alloc new node
new = pm_heap_alloc(page, size);
if (new == NULL)
return (&block[1]);
// Copie old place
memcpy(new, &block[1], block->size);
// Try back-merge / front merge current block
pm_block_backmerge(&block, block_parent);
pm_block_frontmerge(block, (*page)->brk);
// Update block status
block->status = 0;
return (new);
}
return (NULL);
}
void *pm_heap_realloc(struct pm_heap_page **page, void *ptr, size_t size)
{
void *ret;
// Force 4-align
size = (size + 3) >> 2 << 2;
// Start atomic operations
atomic_start();
// Try to find the page
while (page != NULL)
{
// If is the page is found
if (ptr > (void*)page && ptr < (*page)->brk)
{
// Check if the block is not found
ret = pm_block_realloc(page, ptr, size);
// Stop atomic operations and return area
atomic_stop();
return (ret);
}
// Get the next page
page = &(*page)->next;
}
// No block found, display error.
earlyterm_write(
"pm_free: Warning, you try to realloc"
"unused or allocated memory (%p)", ptr
);
DBG_WAIT;
// Stop atomic operations
atomic_stop();
return (NULL);
}

View File

@ -1,5 +1,6 @@
#include <kernel/memory.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/util/kmem.h>
// Internal data.
struct memory_info pmemory;
@ -49,19 +50,34 @@ void memory_init(void)
}
// TEST part
/* void *test0 = pm_alloc(16);
void *test1 = pm_alloc(128);
void *test2 = pm_alloc(80);
/* void *test0 = kmem_alloc(16);
void *test1 = kmem_alloc(128);
void *test2 = kmem_alloc(80);
earlyterm_write("test0 = %p\n", test0);
earlyterm_write("test1 = %p\n", test1);
earlyterm_write("test2 = %p\n", test2);
pm_free(test2);
pm_free(test0);
pm_heap_debug();
kmem_free(test1);
//kmem_debug();
//DBG_WAIT;
test1 = kmem_realloc(NULL, 16);
//earlyterm_write("test1 = %p\n", test1);
//kmem_debug();
//DBG_WAIT;
test1 = kmem_realloc(test1, 32);
earlyterm_write("test1 = %p\n", test1);
kmem_debug();
DBG_WAIT;
pm_free(test1);
pm_debug();
pm_free((void*)0xa0000000);
//test1 = kmem_realloc(test1, 10);
//earlyterm_write("test1 = %p\n", test1);
//kmem_debug();
//DBG_WAIT;
test1 = kmem_realloc(test1, 128);
earlyterm_write("test1 = %p\n", test1);
kmem_debug();
DBG_WAIT;
test1 = kmem_realloc(test1, 200);
earlyterm_write("test1 = %p\n", test1);
kmem_debug();
DBG_WAIT;
while (1);*/
}

View File

@ -0,0 +1,20 @@
#include <kernel/memory.h>
#include <kernel/syscall.h>
#include <kernel/process.h>
#include <kernel/util/atomic.h>
void *sys_proc_heap_alloc(size_t size)
{
extern struct process *process_current;
void *ret;
// start atomic operations
atomic_start();
// Try to alloc new uninitialized area
ret = pm_heap_alloc(&process_current->memory.heap, size);
// Stop atomic operation
atomic_stop();
return (ret);
}

View File

@ -0,0 +1,18 @@
#include <kernel/memory.h>
#include <kernel/syscall.h>
#include <kernel/process.h>
#include <kernel/util/atomic.h>
void sys_proc_heap_free(void *ptr)
{
extern struct process *process_current;
// start atomic operations
atomic_start();
// Freed allocated area
pm_heap_free(process_current->memory.heap, ptr);
// Stop atomic operation
atomic_stop();
}

View File

@ -0,0 +1,20 @@
#include <kernel/memory.h>
#include <kernel/syscall.h>
#include <kernel/process.h>
#include <kernel/util/atomic.h>
void *sys_proc_heap_realloc(void *ptr, size_t size)
{
extern struct process *process_current;
void *ret;
// start atomic operations
atomic_start();
// Try to alloc new uninitialized area
ret = pm_heap_realloc(&process_current->memory.heap, ptr, size);
// Stop atomic operation
atomic_stop();
return (ret);
}

View File

@ -1,7 +1,7 @@
#include <kernel/process.h>
#include <kernel/devices/earlyterm.h>
#include <kernel/util/atomic.h>
#include <kernel/memory.h>
#include <kernel/util/kmem.h>
// TODO: return EAGAIN !!
// TODO: return ENOMEM !!
@ -42,7 +42,7 @@ struct process *process_alloc(void)
}
// Alloc new process manually
*proc = (struct process *)pm_alloc(sizeof(struct process));
*proc = (struct process *)kmem_alloc(sizeof(struct process));
if (*proc == NULL) {
earlyterm_write("proc_alloc: ENOMEM !\n");
atomic_stop();

View File

@ -1,5 +1,5 @@
#include <kernel/process.h>
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
#include <kernel/memory.h>
#include <kernel/devices/earlyterm.h>
#include <lib/string.h>
@ -38,7 +38,7 @@ struct process *process_create(void)
{
earlyterm_write("proc_error: kernel stack error !");
DBG_WAIT;
pm_free((void *)process->memory.stack.user);
pm_pages_free((void *)process->memory.stack.user);
process_free(process);
return (NULL);
}
@ -56,8 +56,8 @@ struct process *process_create(void)
process->memory.exit.start = pm_pages_alloc(PM_SIZE_TO_PAGES(process->memory.exit.size));
if (process->memory.exit.start == NULL)
{
pm_free(process->memory.stack.user);
pm_free(process->memory.stack.kernel);
pm_pages_free(process->memory.stack.user);
pm_pages_free(process->memory.stack.kernel);
process_free(process);
return (NULL);
}
@ -88,6 +88,9 @@ struct process *process_create(void)
process->working_dir = vfs_root_node;
process->tty.private = NULL;
// Initialize heap
process->memory.heap = NULL;
// DEBUG !
//earlyterm_write("proc_create: success !\n");
//earlyterm_write("* user stack: %p\n", process->context.reg[15]);

View File

@ -3,7 +3,8 @@
#include <kernel/loader.h>
#include <kernel/util/atomic.h>
#include <kernel/devices/earlyterm.h>
#include <lib/string.h>
#include <kernel/memory.h>
#include <string.h>
//TODO
//TODO COPY-ON-WRITE !!
@ -21,15 +22,43 @@ static void proc_dump_shared(struct process *child, struct process *parent)
memcpy(&child->tty, &parent->tty, sizeof(FILE));
}
static int generate_arguments(struct process *proc, char **argv, char **envp)
{
// Generate argc
proc->context.reg[4] = -1;
while (argv[++proc->context.reg[4]] != NULL);
// Generate process argv area
proc->context.reg[5] = (uint32_t)pm_heap_alloc(&proc->memory.heap, sizeof(char*) * proc->context.reg[4]);
if (proc->context.reg[5] == 0x00000000)
return (-1);
// Dump argv
for (uint32_t i = 0 ; i < proc->context.reg[4] ; ++i)
{
((char**)proc->context.reg[5])[i] = pm_heap_alloc(&proc->memory.heap, strlen(argv[i]));
strcpy(((char**)proc->context.reg[5])[i], argv[i]);
}
//TODO: envp
(void)envp;
return (0);
}
//TODO
//TODO Return EAGAIN if no proc can be created !!
//TODO Return ENOMEM if no memories can be allocated !!
//TODO
pid_t sys_fexecve(const char *pathname)
pid_t sys_fexecve(const char *pathname, char **argv, char **envp)
{
extern struct process *process_current;
struct process *proc;
// CHeck error
// TODO: set errno to EFAULT
if (argv == NULL)
return (-1);
// Start atomic operation
atomic_start();
@ -57,6 +86,16 @@ pid_t sys_fexecve(const char *pathname)
return (-1);
}
// Generate arguments
if (generate_arguments(proc, argv, envp) != 0)
{
earlyterm_write("sys_fexecve: arguements error\n");
DBG_WAIT;
process_free(proc);
atomic_stop();
return (-1);
}
// Release child process
proc->sibling = process_current->child;
process_current->child = proc;

View File

@ -1,6 +1,6 @@
#include <kernel/syscall.h>
#include <kernel/util/unistd_32.h>
#include <kernel/devices/earlyterm.h>
#include <asm/unistd_32.h>
static void sys_test(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
{
@ -38,7 +38,10 @@ static const void *sys_handler[__NR_MAX] = {
// Memory
sys_mmap, // mmap
NULL//sys_munmap // munmap
NULL, // munmap
sys_proc_heap_alloc, // (custom) process heap alloc
sys_proc_heap_free, // (custom) process heap free
sys_proc_heap_realloc // (custom) process heap realloc
};
void *sys_get_handler(int sysno)

View File

@ -0,0 +1,14 @@
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
#include <kernel/memory.h>
void *kmem_alloc(size_t size)
{
extern struct memory_info pmemory;
void *ret;
atomic_start();
ret = pm_heap_alloc(&pmemory.kheap, size);
atomic_stop();
return (ret);
}

View File

@ -0,0 +1,12 @@
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
#include <kernel/memory.h>
void kmem_debug(void)
{
extern struct memory_info pmemory;
atomic_start();
pm_heap_debug(pmemory.kheap);
atomic_stop();
}

View File

@ -0,0 +1,12 @@
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
#include <kernel/memory.h>
void kmem_free(void *ptr)
{
extern struct memory_info pmemory;
atomic_start();
pm_heap_free(pmemory.kheap, ptr);
atomic_stop();
}

View File

@ -0,0 +1,25 @@
#include <kernel/util/kmem.h>
#include <kernel/util/atomic.h>
#include <kernel/memory.h>
void *kmem_realloc(void *ptr, size_t size)
{
extern struct memory_info pmemory;
void *ret;
// Check malloc
if (ptr == NULL)
return (kmem_alloc(size));
// Check free
if (size == 0) {
kmem_free(ptr);
return (0);
}
// Call common realloc part.
atomic_start();
ret = pm_heap_realloc(&pmemory.kheap, ptr, size);
atomic_stop();
return (ret);
}

View File

@ -11,7 +11,7 @@ include ../../global.mk
#------- --------#
# Generic variables #
#------- --------#
HEADER := -I../../include
HEADER := -I../../include/lib
BUILD-STATIC := ../../build/lib/static
BUILD-DYNAMIC := ../../build/lib/dynamic
TARGET-MODULES := libc display

View File

@ -1,5 +1,4 @@
#include <lib/display.h>
#include <kernel/drivers/screen.h>
#include <display.h>
static void font_draw_core(uint32_t *vram, struct font_s *font, struct font_block_s *fblock)
{

View File

@ -1,4 +1,4 @@
#include <lib/display.h>
#include <display.h>
/* dclear() - Wipe the Video RAM */
void dclear(display_t *disp)

View File

@ -1,4 +1,4 @@
#include <lib/display.h>
#include <display.h>
int dopen(display_t *disp, const char *fontname)
{

View File

@ -1,4 +1,4 @@
#include <lib/display.h>
#include <display.h>
/* dreverse() - Reverse Video RAM area */
void dreverse(display_t *disp, int x, int y, int width, int height)

View File

@ -1,4 +1,4 @@
#include <lib/display.h>
#include <display.h>
/* dscroll() - Scroll up the Video RAM */
//FIXME: This part is hardware specific (128x64px)!!

View File

@ -1,4 +1,4 @@
#include <lib/display.h>
#include <display.h>
// Define the (hardcoded) font bitmap informations.
#define DEFAULT_FONT_BITMAP_WIDTH (127) // Bitmap width

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
int dprintf(int fd, const char *restrict format, ...)
{

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
// Define all actions
static void action_str(struct printf_opt *op, char n);

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
//TODO: precision handling
int printf_common(struct printf_opt *opt, const char *restrict format)

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
static int get_flags(struct printf_opt *opt, const char *restrict format)
{

View File

@ -1,5 +1,5 @@
#include <lib/stdio.h>
#include <lib/unistd.h>
#include <stdio.h>
#include <unistd.h>
int printf(const char *restrict format, ...)
{

View File

@ -1,5 +1,5 @@
#include <lib/stdio.h>
#include <lib/unistd.h>
#include <stdio.h>
#include <unistd.h>
int putc(int c)
{

View File

@ -1,6 +1,6 @@
#include <lib/stdio.h>
#include <lib/string.h>
#include <lib/unistd.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int puts(const char *s)
{

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
int snprintf(char *restrict str, size_t size, const char *restrict format, ...)
{

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
int sprintf(char *restrict str, const char *restrict format, ...)
{

View File

@ -1,5 +1,5 @@
#include <lib/stdio.h>
#include <lib/unistd.h>
#include <stdio.h>
#include <unistd.h>
// FIXME:
// if the writte syscall do not return the same

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
static void disp_char(struct printf_opt *opt, char n)
{

View File

@ -1,4 +1,4 @@
#include <lib/stdio.h>
#include <stdio.h>
int vsprintf(char *restrict str, const char *restrict format, va_list ap)
{

View File

@ -0,0 +1,16 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void *calloc(size_t nmemb, size_t size)
{
if (size == 0 || nmemb == 0)
return (NULL);
void *ret = malloc(nmemb * size);
if (ret == NULL)
return (NULL);
memset(ret, 0x00, size);
return (ret);
}

View File

@ -0,0 +1,17 @@
#include <asm/unistd_32.h>
.text
.global _free
.type _free, @function
.align 2
/*
** @note: the MMU is used by Casio so we
** can not implement brk or skr because
** of non continuous heap.
*/
_free:
trapa #__NR_proc_heap_free
rts
nop
.end

View File

@ -0,0 +1,16 @@
#include <asm/unistd_32.h>
.text
.global _malloc
.type _malloc, @function
.align 2
/*
** @note: We can not implement brk or skr
** because the MMU is used by Casio.
*/
_malloc:
trapa #__NR_proc_heap_alloc
rts
nop
.end

View File

@ -0,0 +1,46 @@
#include <asm/unistd_32.h>
.text
.global _realloc
.type _realloc, @function
.extern _malloc
.extern _free
.align 2
/*
** void *realloc(void ptr, size_t size)
**
** @note: the MMU is used by Casio so we
** can not implement brk or skr because
** of non continuous heap.
*/
_realloc:
! Check malloc part
tst r4, r4 ! if ptr == NULL...
bf.s check_free ! ...if not, jump at <check_free>
mov.l .malloc, r0 ! get malloc() address
jmp @r0 ! call malloc(size)
mov r5, r4 ! (db) send size
! Check free
check_free:
tst r5, r5 ! if size == 0...
bf.s call_realloc ! ...if not, jump at <call_realloc>
mov.l .free, r0 ! get free() address
sts.l pr, @-r15 ! save pr register
jmp @r0 ! call free(ptr)
nop ! (db) nop
rts ! return...
xor r0, r0 ! (db) ...NULL
! Call realloc
call_realloc:
trapa #__NR_proc_heap_realloc
rts
nop
.align 4
.malloc: .long _malloc
.free: .long _free
.end

View File

@ -0,0 +1,8 @@
#include <stdlib.h>
//FIXME: check safe !!!!
//FIXME: Check underflow !!
void *reallocarray(void *ptr, size_t nmemb, size_t size)
{
return (realloc(ptr, nmemb * size));
}

View File

@ -1,5 +1,4 @@
#include <lib/string.h>
#include <lib/display.h>
#include <string.h>
void *memcpy(void *dest, const void *src, size_t count)
{

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
//TODO: update me :(
void *memset(void *s, int c, size_t n)

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
char *strcat(char *dest, char const *src)
{

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
//TODO: asm ?
char *strchr(const char *s1, int c)

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
int strcmp(const char *s1, const char *s2)
{

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
char *strcpy(char *dest, char const *src)
{

View File

@ -0,0 +1,22 @@
#include <string.h>
#include <stdlib.h>
char *strdup(const char *s)
{
size_t len;
void *dump;
// Check error
if (s == NULL)
return (NULL);
// Check len
len = strlen(s);
if (len == 0)
return (NULL);
// Dump string and return
dump = malloc(len);
memcpy(dump, s, len);
return (dump);
}

View File

@ -1,4 +1,4 @@
#include <lib/string.h>
#include <string.h>
size_t strlen(char const *str)
{

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _close
.type _close, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _fexecve
.type _fexecve, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _getpgid
.type _getpgid, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _getpid
.type _getpid, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _getppid
.type _getppid, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _lseek
.type _lseek, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _open
.type _open, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _read
.type _read, @function

View File

@ -1,4 +1,4 @@
#include <kernel/util/unistd_32.h>
#include <asm/unistd_32.h>
.text
.global _setpgid
.type _setpgid, @function

Some files were not shown because too many files have changed in this diff Show More