Compare commits
6 Commits
dc8df7fade
...
20b4545cae
Author | SHA1 | Date | |
---|---|---|---|
20b4545cae | |||
fc47ff581e | |||
08793178f1 | |||
3c1c63e970 | |||
57ba9ff126 | |||
c0178a1405 |
@ -32,7 +32,7 @@ void baseimg_init(void) {
|
|||||||
hal_hang();
|
hal_hang();
|
||||||
} else {
|
} else {
|
||||||
LOG("baseimg", "base.img found\n");
|
LOG("baseimg", "base.img found\n");
|
||||||
LOG("baseimg", "addr = %p, size = %lld\n", baseimg->address, baseimg->size);
|
LOG("baseimg", "addr = %p, size = %lu\n", baseimg->address, baseimg->size);
|
||||||
for (size_t i = 0; i < 30; i++) {
|
for (size_t i = 0; i < 30; i++) {
|
||||||
kprintf("%02X ", ((uint8_t *)(baseimg->address))[i]);
|
kprintf("%02X ", ((uint8_t *)(baseimg->address))[i]);
|
||||||
if (i > 0 && (i + 1) % 10 == 0) {
|
if (i > 0 && (i + 1) % 10 == 0) {
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
typedef int32_t (*DevFn)(uint8_t *buffer, size_t len, void *extra);
|
typedef int32_t (*DevFn)(uint8_t *buffer, size_t len, void *extra);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Dev {
|
||||||
|
struct Dev *next;
|
||||||
DevFn fns[DEV_FNS_MAX];
|
DevFn fns[DEV_FNS_MAX];
|
||||||
} Dev;
|
} Dev;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "dev.h"
|
#include "dev.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "dlmalloc/malloc.h"
|
#include "dlmalloc/malloc.h"
|
||||||
|
#include "util/util.h"
|
||||||
|
#include "syscall/devctl.h"
|
||||||
|
|
||||||
Dev PS2KBDEV;
|
Dev PS2KBDEV;
|
||||||
Ps2KbFastBuf PS2KB_BUF;
|
Ps2KbFastBuf PS2KB_BUF;
|
||||||
@ -32,4 +34,5 @@ void ps2kbdev_init(void) {
|
|||||||
uint8_t *buf = dlmalloc(bufsz);
|
uint8_t *buf = dlmalloc(bufsz);
|
||||||
rbuf_init(&PS2KB_BUF.rbuf, buf, bufsz);
|
rbuf_init(&PS2KB_BUF.rbuf, buf, bufsz);
|
||||||
PS2KB_BUF.init = true;
|
PS2KB_BUF.init = true;
|
||||||
|
LL_APPEND(DEVS, &PS2KBDEV);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include "termdev.h"
|
#include "termdev.h"
|
||||||
#include "dev.h"
|
#include "dev.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
#include "util/util.h"
|
||||||
|
#include "syscall/devctl.h"
|
||||||
|
|
||||||
Dev TERMDEV;
|
Dev TERMDEV;
|
||||||
|
|
||||||
@ -16,4 +18,5 @@ int32_t termdev_putch(uint8_t *buffer, size_t len, void *extra) {
|
|||||||
void termdev_init(void) {
|
void termdev_init(void) {
|
||||||
hal_memset(&TERMDEV, 0, sizeof(TERMDEV));
|
hal_memset(&TERMDEV, 0, sizeof(TERMDEV));
|
||||||
TERMDEV.fns[0] = &termdev_putch;
|
TERMDEV.fns[0] = &termdev_putch;
|
||||||
|
LL_APPEND(DEVS, &TERMDEV);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "hal/hal.h"
|
#include "hal/hal.h"
|
||||||
|
|
||||||
int32_t littlefs_cleanup(struct VfsMountPoint *vmp) {
|
int32_t littlefs_cleanup(struct VfsMountPoint *vmp) {
|
||||||
dlfree(vmp->fs.littlefs.instance.cfg);
|
dlfree((void *)vmp->fs.littlefs.instance.cfg);
|
||||||
int32_t err = vmp->backingsd->cleanup(vmp->backingsd);
|
int32_t err = vmp->backingsd->cleanup(vmp->backingsd);
|
||||||
if (err != E_OK) {
|
if (err != E_OK) {
|
||||||
return err;
|
return err;
|
||||||
@ -204,6 +204,7 @@ int32_t littlefs_fetchdirent(struct VfsMountPoint *vmp, const char *path, IoctlD
|
|||||||
lfs_dir_close(&vmp->fs.littlefs.instance, &dir);
|
lfs_dir_close(&vmp->fs.littlefs.instance, &dir);
|
||||||
|
|
||||||
spinlock_release(&vmp->spinlock);
|
spinlock_release(&vmp->spinlock);
|
||||||
|
return E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int portlfs_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
|
int portlfs_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
|
||||||
|
@ -25,7 +25,7 @@ typedef struct BackTraceFrame {
|
|||||||
void backtrace(BackTraceFrame *bt) {
|
void backtrace(BackTraceFrame *bt) {
|
||||||
kprintf("Backtrace:\n");
|
kprintf("Backtrace:\n");
|
||||||
for (size_t frame = 0; bt; frame++) {
|
for (size_t frame = 0; bt; frame++) {
|
||||||
kprintf(" 0x%llx\n", bt->rip);
|
kprintf(" %zu: 0x%lx\n", frame, bt->rip);
|
||||||
bt = bt->rbp;
|
bt = bt->rbp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ void hal_vmm_map_kern(uint64_t targetcr3) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t hal_vmm_userproc_pml4_phys(Proc *proc) {
|
uint64_t hal_vmm_userproc_pml4_phys(void) {
|
||||||
uint8_t *cr3phys = pmm_alloc(1);
|
uint8_t *cr3phys = pmm_alloc(1);
|
||||||
uint64_t phys = (uint64_t)cr3phys;
|
uint64_t phys = (uint64_t)cr3phys;
|
||||||
hal_memset(VIRT(phys), 0, HAL_PAGE_SIZE);
|
hal_memset(VIRT(phys), 0, HAL_PAGE_SIZE);
|
||||||
|
@ -17,8 +17,6 @@ typedef struct VasRange {
|
|||||||
uint8_t pgflags;
|
uint8_t pgflags;
|
||||||
} PACKED VasRange;
|
} PACKED VasRange;
|
||||||
|
|
||||||
struct Proc;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
HAL_PG_PRESENT = 1<<0,
|
HAL_PG_PRESENT = 1<<0,
|
||||||
HAL_PG_RW = 1<<1,
|
HAL_PG_RW = 1<<1,
|
||||||
@ -60,6 +58,6 @@ void hal_vmm_map_page(uint64_t cr3phys, uint64_t virtaddr, uint64_t physaddr, ui
|
|||||||
uint64_t hal_vmm_current_cr3(void);
|
uint64_t hal_vmm_current_cr3(void);
|
||||||
void hal_vmm_map_range(uint64_t cr3phys, void *virtstart, void *physstart, size_t size, uint32_t flags);
|
void hal_vmm_map_range(uint64_t cr3phys, void *virtstart, void *physstart, size_t size, uint32_t flags);
|
||||||
void hal_vmm_unmap_range(uint64_t cr3phys, void *virtstart, void *physstart, size_t size);
|
void hal_vmm_unmap_range(uint64_t cr3phys, void *virtstart, void *physstart, size_t size);
|
||||||
uint64_t hal_vmm_userproc_pml4_phys(struct Proc *proc);
|
uint64_t hal_vmm_userproc_pml4_phys();
|
||||||
|
|
||||||
#endif // HAL_VMM_H_
|
#endif // HAL_VMM_H_
|
||||||
|
@ -108,7 +108,7 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
|||||||
ksprintf(proc->name, "%s:%s", mountpoint, path);
|
ksprintf(proc->name, "%s:%s", mountpoint, path);
|
||||||
|
|
||||||
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
||||||
proc->platformdata.cr3 = hal_vmm_userproc_pml4_phys(proc);
|
proc->platformdata.cr3 = hal_vmm_userproc_pml4_phys();
|
||||||
|
|
||||||
uint8_t *kstackp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
uint8_t *kstackp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
||||||
proc->platformdata.kstack = kstackp;
|
proc->platformdata.kstack = kstackp;
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "spinlock/spinlock.h"
|
#include "spinlock/spinlock.h"
|
||||||
#include "ramsd.h"
|
#include "ramsd.h"
|
||||||
|
#include "compiler/attr.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STOREDEV_RAMSD,
|
STOREDEV_RAMSD,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *storedev_strings[] = {
|
UNUSED static const char *storedev_strings[] = {
|
||||||
"RAMSD",
|
"RAMSD",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,10 +10,7 @@
|
|||||||
#include "dev/ps2kbdev.h"
|
#include "dev/ps2kbdev.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
|
||||||
Dev *DEVS[] = {
|
Dev *DEVS = NULL;
|
||||||
[0x10] = &TERMDEV,
|
|
||||||
[0x11] = &PS2KBDEV,
|
|
||||||
};
|
|
||||||
|
|
||||||
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
||||||
uint64_t *devh = (uint64_t *)devh1;
|
uint64_t *devh = (uint64_t *)devh1;
|
||||||
@ -26,9 +23,18 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
|||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case DEVCTL_GET_HANDLE: {
|
case DEVCTL_GET_HANDLE: {
|
||||||
uint64_t devid = buffer1;
|
Dev *founddev = NULL;
|
||||||
if (devid >= LEN(DEVS)) {
|
size_t i = 0;
|
||||||
ret = E_INVALIDARGUMENT;
|
Dev *dev, *devtmp;
|
||||||
|
LL_FOREACH_SAFE_IDX(DEVS, dev, devtmp, i) {
|
||||||
|
if (i == buffer1) {
|
||||||
|
founddev = dev;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (founddev == NULL) {
|
||||||
|
ret = E_NOENTRY;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,14 +42,14 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
|||||||
for (size_t i = 0; i < PROC_DEVHANDLES_MAX; i++) {
|
for (size_t i = 0; i < PROC_DEVHANDLES_MAX; i++) {
|
||||||
if (proc->devs[i] == NULL) {
|
if (proc->devs[i] == NULL) {
|
||||||
found = true;
|
found = true;
|
||||||
proc->devs[i] = DEVS[devid];
|
proc->devs[i] = founddev;
|
||||||
*devh = i;
|
*devh = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
ret = E_NOENTRY;
|
ret = E_NOMEMORY;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -59,6 +65,10 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dev *dev = proc->devs[*devh];
|
Dev *dev = proc->devs[*devh];
|
||||||
|
if (dev == NULL) {
|
||||||
|
ret = E_NOENTRY;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
ret = dev->fns[cmd]((uint8_t *)buffer1, (size_t)len1, (void *)extra1);
|
ret = dev->fns[cmd]((uint8_t *)buffer1, (size_t)len1, (void *)extra1);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
#include "dev/dev.h"
|
||||||
|
|
||||||
|
extern Dev *DEVS;
|
||||||
|
|
||||||
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1);
|
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define SYSCALLS_MAX 0xff
|
#define SYSCALLS_MAX 0xff
|
||||||
|
|
||||||
#define SYSCALL0(name) \
|
#define SYSCALL0(name) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
UNUSED uint64_t _1, \
|
UNUSED uint64_t _1, \
|
||||||
UNUSED uint64_t _2, \
|
UNUSED uint64_t _2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -18,7 +18,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL1(name, arg1) \
|
#define SYSCALL1(name, arg1) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
UNUSED uint64_t _2, \
|
UNUSED uint64_t _2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -28,7 +28,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL2(name, arg1, arg2) \
|
#define SYSCALL2(name, arg1, arg2) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -38,7 +38,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL3(name, arg1, arg2, arg3) \
|
#define SYSCALL3(name, arg1, arg2, arg3) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -48,7 +48,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
|
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -58,7 +58,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
|
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -68,7 +68,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
|
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||||
name(IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "fs/portlfs/portlfs.h"
|
#include "fs/portlfs/portlfs.h"
|
||||||
#include "storedev/storedev.h"
|
#include "storedev/storedev.h"
|
||||||
#include "sysdefs/ioctl.h"
|
#include "sysdefs/ioctl.h"
|
||||||
|
#include "compiler/attr.h"
|
||||||
|
|
||||||
#define VFS_MOUNTPOINT_LABEL_MAX 128
|
#define VFS_MOUNTPOINT_LABEL_MAX 128
|
||||||
#define VFS_MOUNTPOINTS_MAX 30
|
#define VFS_MOUNTPOINTS_MAX 30
|
||||||
@ -16,7 +17,7 @@ enum {
|
|||||||
VFS_LITTLEFS,
|
VFS_LITTLEFS,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *vfs_strings[] = {
|
UNUSED static const char *vfs_strings[] = {
|
||||||
"Little FS",
|
"Little FS",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
#ifndef ERRORS_H_
|
#ifndef ERRORS_H_
|
||||||
#define ERRORS_H_
|
#define ERRORS_H_
|
||||||
|
|
||||||
enum {
|
#define E_OK 0
|
||||||
E_OK = 0,
|
#define E_NOMEMORY -1
|
||||||
E_NOMEMORY = -1,
|
#define E_UNKNOWN_FSTYPE -2
|
||||||
E_UNKNOWN_FSTYPE = -2,
|
#define E_NOENTRY -3
|
||||||
E_NOENTRY = -3,
|
#define E_OUTOFBOUNDS -4
|
||||||
E_OUTOFBOUNDS = -4,
|
#define E_UNKNOWN_SDTYPE -5
|
||||||
E_UNKNOWN_SDTYPE = -5,
|
#define E_TODO -6
|
||||||
E_TODO = -6,
|
#define E_BADIO -7
|
||||||
E_BADIO = -7,
|
#define E_BADSYSCALL -8
|
||||||
E_BADSYSCALL = -8,
|
#define E_DOSCHEDULING -9
|
||||||
E_DOSCHEDULING = -9,
|
#define E_INVALIDARGUMENT -10
|
||||||
E_INVALIDARGUMENT = -10,
|
#define E_INVALIDOPER -11
|
||||||
E_INVALIDOPER = -11,
|
#define E_RESOURCEAVAIL -12
|
||||||
E_RESOURCEAVAIL = -12,
|
#define E_SPAWNERROR -13
|
||||||
E_SPAWNERROR = -13,
|
#define E_NOTYET -14
|
||||||
E_NOTYET = -14,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
#if !defined(__ASSEMBLER__)
|
||||||
|
|
||||||
|
__attribute__((unused))
|
||||||
static const char *_ERROR_STRINGS[] = {
|
static const char *_ERROR_STRINGS[] = {
|
||||||
"OK",
|
"OK",
|
||||||
"Out of memory",
|
"Out of memory",
|
||||||
@ -39,4 +40,6 @@ static const char *_ERROR_STRINGS[] = {
|
|||||||
#define ERRSTRING_INDEX(ioh) ((size_t)((ioh) < 0 ? (ioh) * (-1) : (ioh)))
|
#define ERRSTRING_INDEX(ioh) ((size_t)((ioh) < 0 ? (ioh) * (-1) : (ioh)))
|
||||||
#define ERRSTRING(ioh) (_ERROR_STRINGS[ERRSTRING_INDEX(ioh)])
|
#define ERRSTRING(ioh) (_ERROR_STRINGS[ERRSTRING_INDEX(ioh)])
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // ERRORS_H_
|
#endif // ERRORS_H_
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#ifndef SHARE_SYSDEFS_DEVCTL_H_
|
#ifndef SHARE_SYSDEFS_DEVCTL_H_
|
||||||
#define SHARE_SYSDEFS_DEVCTL_H_
|
#define SHARE_SYSDEFS_DEVCTL_H_
|
||||||
|
|
||||||
enum {
|
#define DEVCTL_GET_HANDLE 100
|
||||||
DEVCTL_GET_HANDLE = 100,
|
|
||||||
};
|
#if !defined(__ASSEMBLER__)
|
||||||
|
|
||||||
typedef uint64_t Dev_t;
|
typedef uint64_t Dev_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_DEVCTL_H_
|
#endif // SHARE_SYSDEFS_DEVCTL_H_
|
||||||
|
@ -1,30 +1,26 @@
|
|||||||
#ifndef SHARE_SYSDEFS_IOCTL_H_
|
#ifndef SHARE_SYSDEFS_IOCTL_H_
|
||||||
#define SHARE_SYSDEFS_IOCTL_H_
|
#define SHARE_SYSDEFS_IOCTL_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#define IOCTL_NOHANDLE (-1)
|
#define IOCTL_NOHANDLE (-1)
|
||||||
|
|
||||||
enum {
|
#define IOCTL_OPENF 0
|
||||||
IOCTL_OPENF = 0,
|
#define IOCTL_CLOSEF 1
|
||||||
IOCTL_CLOSEF = 1,
|
#define IOCTL_READ 2
|
||||||
IOCTL_READ = 2,
|
#define IOCTL_STAT 3
|
||||||
IOCTL_STAT = 3,
|
#define IOCTL_WRITE 4
|
||||||
IOCTL_WRITE = 4,
|
#define IOCTL_FETCHDIRENT 5
|
||||||
IOCTL_FETCHDIRENT = 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
#define IOCTL_F_READ (1<<0)
|
||||||
IOCTL_F_READ = 1<<0,
|
#define IOCTL_F_WRITE (1<<1)
|
||||||
IOCTL_F_WRITE = 1<<1,
|
#define IOCTL_F_MAKE (1<<2)
|
||||||
IOCTL_F_MAKE = 1<<2,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
#define IOCTLSTAT_DIR 0
|
||||||
IOCTLSTAT_DIR = 0,
|
#define IOCTLSTAT_FILE 1
|
||||||
IOCTLSTAT_FILE = 1,
|
|
||||||
};
|
#if !defined(__ASSEMBLER__)
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct IoctlStat {
|
typedef struct IoctlStat {
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -38,4 +34,6 @@ typedef struct IoctlDirent {
|
|||||||
|
|
||||||
typedef int32_t IOH;
|
typedef int32_t IOH;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_IOCTL_H_
|
#endif // SHARE_SYSDEFS_IOCTL_H_
|
||||||
|
@ -9,13 +9,11 @@
|
|||||||
#define IPCPIPE_OUT (0)
|
#define IPCPIPE_OUT (0)
|
||||||
#define IPCPIPE_IN (1)
|
#define IPCPIPE_IN (1)
|
||||||
|
|
||||||
enum {
|
#define IPCPIPE_MAKE 0
|
||||||
IPCPIPE_MAKE = 0,
|
#define IPCPIPE_READ 1
|
||||||
IPCPIPE_READ = 1,
|
#define IPCPIPE_WRITE 2
|
||||||
IPCPIPE_WRITE = 2,
|
#define IPCPIPE_ADD_BCAST 3
|
||||||
IPCPIPE_ADD_BCAST = 3,
|
#define IPCPIPE_REPLACE 4
|
||||||
IPCPIPE_REPLACE = 4,
|
#define IPCPIPE_DELETE 5
|
||||||
IPCPIPE_DELETE = 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_IPCPIPE_H_
|
#endif // SHARE_SYSDEFS_IPCPIPE_H_
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
#ifndef SHARE_SYSDEFS_MMAN_H_
|
#ifndef SHARE_SYSDEFS_MMAN_H_
|
||||||
#define SHARE_SYSDEFS_MMAN_H_
|
#define SHARE_SYSDEFS_MMAN_H_
|
||||||
|
|
||||||
enum {
|
#define MMAN_MAP_PF_RW (1<<0)
|
||||||
MMAN_MAP_PF_RW = (1<<0),
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
#define MMAN_MAP_F_FIXED (1<<0)
|
||||||
MMAN_MAP_F_FIXED = (1<<0),
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_MMAN_H_
|
#endif // SHARE_SYSDEFS_MMAN_H_
|
||||||
|
@ -3,17 +3,17 @@
|
|||||||
|
|
||||||
#define PROC_ARG_MAX 128
|
#define PROC_ARG_MAX 128
|
||||||
|
|
||||||
enum {
|
#define PCTL_KILL 0
|
||||||
PCTL_KILL = 0,
|
#define PCTL_SPAWN 1
|
||||||
PCTL_SPAWN = 1,
|
#define PCTL_POLLSTATE 2
|
||||||
PCTL_POLLSTATE = 2,
|
#define PCTL_RUN 3
|
||||||
PCTL_RUN = 3,
|
#define PCTL_GETPID 4
|
||||||
PCTL_GETPID = 4,
|
#define PCTL_ARGLEN 5
|
||||||
PCTL_ARGLEN = 5,
|
#define PCTL_ARGV 6
|
||||||
PCTL_ARGV = 6,
|
#define PCTL_PLS_SZ 7
|
||||||
PCTL_PLS_SZ = 7,
|
#define PCTL_PLS_STAT 8
|
||||||
PCTL_PLS_STAT = 8,
|
|
||||||
};
|
#if !defined(__ASSEMBLER__)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t pid;
|
uint64_t pid;
|
||||||
@ -24,4 +24,6 @@ typedef struct {
|
|||||||
|
|
||||||
typedef uint64_t PID_t;
|
typedef uint64_t PID_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SHARE_HDRS_PROCESSCTL_H_
|
#endif // SHARE_HDRS_PROCESSCTL_H_
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
#ifndef SHARE_HDRS_SYSCALL_H_
|
#ifndef SHARE_HDRS_SYSCALL_H_
|
||||||
#define SHARE_HDRS_SYSCALL_H_
|
#define SHARE_HDRS_SYSCALL_H_
|
||||||
|
|
||||||
enum {
|
#define SYS_DEBUGPRINT 1
|
||||||
SYS_DEBUGPRINT = 1,
|
#define SYS_PROCESSCTL 2
|
||||||
SYS_PROCESSCTL = 2,
|
#define SYS_IOCTL 3
|
||||||
SYS_IOCTL = 3,
|
#define SYS_IPCPIPE 4
|
||||||
SYS_IPCPIPE = 4,
|
#define SYS_MMAN_MAP 5
|
||||||
SYS_MMAN_MAP = 5,
|
#define SYS_MMAN_UNMAP 6
|
||||||
SYS_MMAN_UNMAP = 6,
|
#define SYS_SCHEDRELEASE 7
|
||||||
SYS_SCHEDRELEASE = 7,
|
#define SYS_DEVCTL 8
|
||||||
SYS_DEVCTL = 8,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SHARE_HDRS_SYSCALL_H_
|
#endif // SHARE_HDRS_SYSCALL_H_
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <system/system.h>
|
#include <system/system.h>
|
||||||
#include <sysdefs/processctl.h>
|
#include <sysdefs/processctl.h>
|
||||||
#include <sysdefs/devctl.h>
|
|
||||||
#include <errors.h>
|
#include <errors.h>
|
||||||
#include <uprintf.h>
|
#include <uprintf.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
#include <umalloc/umalloc.h>
|
#include <umalloc/umalloc.h>
|
||||||
#include <devids.h>
|
|
||||||
|
|
||||||
extern void main(void);
|
extern void main(void);
|
||||||
extern uint8_t _bss_start[];
|
extern uint8_t _bss_start[];
|
||||||
|
11
ulib/dev.h
Normal file
11
ulib/dev.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef ULIB_DEV_H_
|
||||||
|
#define ULIB_DEV_H_
|
||||||
|
|
||||||
|
#define DEV_TERMDEV 0
|
||||||
|
#define DEV_PS2KBDEV 1
|
||||||
|
|
||||||
|
#define DEV_TERMDEV_PUTCH 0
|
||||||
|
|
||||||
|
#define DEV_PS2KBDEV_READCH 0
|
||||||
|
|
||||||
|
#endif // ULIB_DEV_H_
|
@ -1,9 +0,0 @@
|
|||||||
#ifndef ULIB_DEVIDS_H_
|
|
||||||
#define ULIB_DEVIDS_H_
|
|
||||||
|
|
||||||
enum {
|
|
||||||
DEV_TERMDEV = 0x10,
|
|
||||||
DEV_PS2KBDEV = 0x11,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ULIB_DEVIDS_H_
|
|
@ -16,7 +16,7 @@
|
|||||||
#include <log.h>
|
#include <log.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <umalloc/umalloc.h>
|
#include <umalloc/umalloc.h>
|
||||||
#include <devids.h>
|
#include <dev.h>
|
||||||
|
|
||||||
#include <errors.h>
|
#include <errors.h>
|
||||||
#include <sysdefs/ioctl.h>
|
#include <sysdefs/ioctl.h>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <ulib.h>
|
#include <ulib.h>
|
||||||
|
|
||||||
extern void fs_fetch(void);
|
extern void fs_fetch(void);
|
||||||
|
extern void fs_mkf(void);
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (argslen() == 0) {
|
if (argslen() == 0) {
|
||||||
@ -13,6 +14,8 @@ void main(void) {
|
|||||||
|
|
||||||
if (string_strcmp(cmd, "fetch") == 0) {
|
if (string_strcmp(cmd, "fetch") == 0) {
|
||||||
fs_fetch();
|
fs_fetch();
|
||||||
|
} else if (string_strcmp(cmd, "mkf") == 0) {
|
||||||
|
fs_mkf();
|
||||||
} else {
|
} else {
|
||||||
uprintf("fs: unknown command %s\n", cmd);
|
uprintf("fs: unknown command %s\n", cmd);
|
||||||
}
|
}
|
||||||
|
36
user/fs/mkf.c
Normal file
36
user/fs/mkf.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
struct {
|
||||||
|
char *write;
|
||||||
|
} FS_MKF_CONFIG = {
|
||||||
|
.write = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static Arg ARGS[] = {
|
||||||
|
ARG("-write", ARG_STRING, &FS_MKF_CONFIG.write),
|
||||||
|
ARG_END(),
|
||||||
|
};
|
||||||
|
|
||||||
|
void fs_mkf(void) {
|
||||||
|
if (argslen() < 2) {
|
||||||
|
uprintf("fs: Not enough arguments\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *path = *(args()+1);
|
||||||
|
|
||||||
|
int32_t ret;
|
||||||
|
if ((ret = parse_args(args()+2, argslen()-1, ARGS)) < 0) {
|
||||||
|
uprintf("fs mkf: Could not parse args: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
IOH ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)path, IOCTL_F_MAKE | IOCTL_F_WRITE, 0);
|
||||||
|
if (FS_MKF_CONFIG.write != NULL) {
|
||||||
|
if (ioctl(ioh, IOCTL_WRITE, (uint64_t)FS_MKF_CONFIG.write, string_len(FS_MKF_CONFIG.write), 0) < 0) {
|
||||||
|
uprintf("fs mkf: could not write to %s\n", path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||||
|
}
|
@ -20,10 +20,10 @@ void tb_runinitscript(void) {
|
|||||||
string_memset(buf, 0, sizeof(buf));
|
string_memset(buf, 0, sizeof(buf));
|
||||||
r = ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_READ, (uint8_t *)buf, sizeof(buf)-1);
|
r = ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_READ, (uint8_t *)buf, sizeof(buf)-1);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
devctl(&termdev, 0x00, (uint8_t *)buf, string_len(buf), 0);
|
devctl(&termdev, DEV_TERMDEV_PUTCH, (uint8_t *)buf, string_len(buf), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = devctl(&ps2kbdev, 0x00, NULL, 0, 0);
|
r = devctl(&ps2kbdev, DEV_PS2KBDEV_READCH, NULL, 0, 0);
|
||||||
if (r != E_NOTYET) {
|
if (r != E_NOTYET) {
|
||||||
uint8_t b = r;
|
uint8_t b = r;
|
||||||
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &b, 1);
|
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &b, 1);
|
||||||
|
Reference in New Issue
Block a user