repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
willmexe/opuntiaOS | kernel/kernel/platform/x86/tasking/tss.c | <reponame>willmexe/opuntiaOS
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <mem/kmalloc.h>
#include <mem/vmm.h>
#include <platform/x86/gdt.h>
#include <platform/x86/tasking/tss.h>
tss_t tss;
void set_ltr(uint16_t seg)
{
asm volatile("ltr %0"
:
: "r"(seg));
}
|
willmexe/opuntiaOS | userland/applications/activity_monitor/GraphView.h | #pragma once
#include <libg/Font.h>
#include <libui/View.h>
#include <string>
class GraphView : public UI::View {
UI_OBJECT();
public:
GraphView(UI::View* superview, const LG::Rect&, int data_size);
void display(const LG::Rect& rect) override;
void add_new_value(int val)
{
for (int i = 0; i < m_data.size() - 1; i++) {
m_data[i] = m_data[i + 1];
}
m_data[m_data.size() - 1] = val;
set_needs_display();
}
private:
std::vector<int> m_data;
}; |
willmexe/opuntiaOS | libs/libc/include/ctype.h | <reponame>willmexe/opuntiaOS
#ifndef _LIBC_CTYPE_H
#define _LIBC_CTYPE_H
#include <stddef.h>
#include <sys/_structs.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
extern const char __ctypes[256];
static inline int isalnum(int c) { return __ctypes[(unsigned char)(c)] & (_U | _L | _N); }
static inline int isalpha(int c) { return __ctypes[(unsigned char)(c)] & (_U | _L); }
static inline int iscntrl(int c) { return __ctypes[(unsigned char)(c)] & (_C); }
static inline int isdigit(int c) { return __ctypes[(unsigned char)(c)] & (_N); }
static inline int isxdigit(int c) { return __ctypes[(unsigned char)(c)] & (_N | _X); }
static inline int isspace(int c) { return __ctypes[(unsigned char)(c)] & (_S); }
static inline int ispunct(int c) { return __ctypes[(unsigned char)(c)] & (_P); }
static inline int isprint(int c) { return __ctypes[(unsigned char)(c)] & (_P | _U | _L | _N | _B); }
static inline int isgraph(int c) { return __ctypes[(unsigned char)(c)] & (_P | _U | _L | _N); }
static inline int islower(int c) { return (__ctypes[(unsigned char)(c)] & (_U | _L)) == _L; }
static inline int isupper(int c) { return (__ctypes[(unsigned char)(c)] & (_U | _L)) == _U; }
static inline int tolower(int c) { return isupper(c) ? (c) - 'a' + 'A' : c; }
static inline int toupper(int c) { return islower(c) ? (c) - 'A' + 'a' : c; }
__END_DECLS
#endif /* _LIBC_CTYPE_H */ |
willmexe/opuntiaOS | libs/libc/posix/time.c | #include <sys/time.h>
#include <sysdep.h>
int gettimeofday(timeval_t* tv, timezone_t* tz)
{
int res = DO_SYSCALL_2(SYS_GETTIMEOFDAY, tv, tz);
RETURN_WITH_ERRNO(res, res, -1);
}
int settimeofday(const timeval_t* tv, const timezone_t* tz)
{
return -1;
} |
willmexe/opuntiaOS | libs/libui/include/libui/EdgeInsets.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
namespace UI {
class EdgeInsets {
public:
EdgeInsets() = default;
EdgeInsets(int top, int left, int bottom, int right)
: m_top(top)
, m_left(left)
, m_bottom(bottom)
, m_right(right)
{
}
inline int top() const { return m_top; }
inline int left() const { return m_left; }
inline int bottom() const { return m_bottom; }
inline int right() const { return m_right; }
private:
int m_top { 0 };
int m_bottom { 0 };
int m_left { 0 };
int m_right { 0 };
};
} // namespace UI |
willmexe/opuntiaOS | libs/libc/include/stdlib.h | #ifndef _LIBC_STDLIB_H
#define _LIBC_STDLIB_H
#include <stddef.h>
#include <sys/cdefs.h>
#include <sys/environ.h>
#include <sys/types.h>
__BEGIN_DECLS
#ifndef NOMINMAX
#ifndef max
#define max(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#endif /* max */
#ifndef min
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#endif /* min */
#endif /* NOMINMAX */
static inline int abs(int i)
{
return i < 0 ? -i : i;
}
/* malloc */
extern void* malloc(size_t);
extern void free(void*);
extern void* calloc(size_t, size_t);
extern void* realloc(void*, size_t);
/* tools */
int atoi(const char* s);
/* exit */
void abort() __attribute__((noreturn));
void exit(int status) __attribute__((noreturn));
/* pts */
int posix_openpt(int flags);
int ptsname_r(int fd, char* buf, size_t buflen);
char* ptsname(int fd);
/* env */
int putenv(char* string);
char* getenv(const char* name);
int setenv(const char* name, const char* value, int overwrite);
int unsetenv(const char* name);
__END_DECLS
#endif // _LIBC_STDLIB_H
|
willmexe/opuntiaOS | libs/libui/include/libui/Common/MenuItem.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
#include <functional>
#include <libipc/VectorEncoder.h>
#include <string>
#include <utility>
namespace UI {
class Menu;
class MenuBar;
class MenuItem {
friend class Menu;
friend class MenuBar;
public:
MenuItem(const std::string& title, std::function<void()> action)
: m_title(title)
, m_action(action)
{
}
MenuItem(std::string&& title, std::function<void()> action)
: m_title(std::move(title))
, m_action(action)
{
}
inline const std::string& title() const { return m_title; }
inline void invoke() { m_action(); }
private:
inline void set_id(uint32_t id) { m_id = id; }
std::string m_title;
std::function<void()> m_action;
uint32_t m_id;
};
class Menu {
friend class MenuBar;
public:
Menu() = default;
Menu(const std::string& title)
: m_title(title)
{
}
Menu(std::string&& title)
: m_title(std::move(title))
{
}
inline void add_item(const MenuItem& item)
{
int id = m_menu_items.size();
m_menu_items.push_back(item);
m_menu_items.back().set_id(id);
}
inline const std::string& title() const { return m_title; }
inline uint32_t menu_id() const { return m_menu_id; }
std::vector<MenuItem>& items() { return m_menu_items; }
const std::vector<MenuItem>& items() const { return m_menu_items; }
private:
inline void set_menu_id(uint32_t id) { m_menu_id = id; }
std::string m_title {};
uint32_t m_menu_id;
std::vector<MenuItem> m_menu_items;
};
} |
willmexe/opuntiaOS | userland/system/homescreen/FastLaunchEntity.h | #pragma once
#include <libg/PixelBitmap.h>
#include <string>
class FastLaunchEntity {
public:
FastLaunchEntity() = default;
void set_icon(LG::PixelBitmap&& icon) { m_icon = std::move(icon); }
const LG::PixelBitmap& icon() const { return m_icon; }
void set_path_to_exec(std::string&& path) { m_path_to_exec = std::move(path); }
const std::string& path_to_exec() const { return m_path_to_exec; }
private:
LG::PixelBitmap m_icon;
std::string m_path_to_exec {};
}; |
willmexe/opuntiaOS | kernel/include/mem/kswapd.h | <filename>kernel/include/mem/kswapd.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_MEM_KSWAPD_H
#define _KERNEL_MEM_KSWAPD_H
void kswapd();
#endif // _KERNEL_MEM_KSWAPD_H
|
willmexe/opuntiaOS | kernel/include/io/tty/pty_slave.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_IO_TTY_PTY_SLAVE_H
#define _KERNEL_IO_TTY_PTY_SLAVE_H
#include <algo/sync_ringbuffer.h>
#ifndef PTYS_COUNT
#define PTYS_COUNT 4
#endif
struct pty_master_entry;
struct pty_slave_entry {
int inode_indx;
struct pty_master_entry* ptm;
sync_ringbuffer_t buffer;
};
typedef struct pty_slave_entry pty_slave_entry_t;
extern pty_slave_entry_t pty_slaves[PTYS_COUNT];
int pty_slave_create(int id, struct pty_master_entry* ptm);
#endif |
willmexe/opuntiaOS | kernel/include/platform/generic/syscalls/params.h | #ifdef __i386__
#include <platform/x86/syscalls/params.h>
#elif __arm__
#include <platform/aarch32/syscalls/params.h>
#endif |
willmexe/opuntiaOS | kernel/include/algo/bitmap.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_ALGO_BITMAP_H
#define _KERNEL_ALGO_BITMAP_H
#include <libkern/types.h>
struct bitmap {
uint8_t* data;
size_t len;
};
typedef struct bitmap bitmap_t;
bitmap_t bitmap_wrap(uint8_t* data, size_t len);
bitmap_t bitmap_allocate(size_t len);
int bitmap_find_space(bitmap_t bitmap, int req);
int bitmap_find_space_aligned(bitmap_t bitmap, int req, int alignment);
int bitmap_set(bitmap_t bitmap, int where);
int bitmap_unset(bitmap_t bitmap, int where);
int bitmap_set_range(bitmap_t bitmap, int start, int len);
int bitmap_unset_range(bitmap_t bitmap, int start, int len);
#endif //_KERNEL_ALGO_BITMAP_H |
willmexe/opuntiaOS | kernel/include/tasking/proc.h | <filename>kernel/include/tasking/proc.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_TASKING_PROC_H
#define _KERNEL_TASKING_PROC_H
#include <algo/dynamic_array.h>
#include <fs/vfs.h>
#include <io/tty/tty.h>
#include <libkern/atomic.h>
#include <libkern/lock.h>
#include <libkern/types.h>
#include <mem/kmemzone.h>
#include <mem/memzone.h>
#include <mem/vmm.h>
#define MAX_PROCESS_COUNT 1024
#define MAX_OPENED_FILES 16
struct blocker;
enum PROC_STATUS {
PROC_INVALID = 0,
PROC_ALIVE,
PROC_DEAD,
PROC_DYING,
PROC_ZOMBIE,
};
struct thread;
struct proc {
pdirectory_t* pdir;
pid_t pid;
pid_t ppid;
pid_t pgid;
uint32_t prio;
uint32_t status;
struct thread* main_thread;
// Locking order is important, vm_lock could not be acquired while lock is busy.
lock_t vm_lock;
lock_t lock;
uid_t uid;
gid_t gid;
uid_t euid;
gid_t egid;
uid_t suid;
gid_t sgid;
dynamic_array_t zones;
dentry_t* proc_file;
dentry_t* cwd;
file_descriptor_t* fds;
tty_entry_t* tty;
int exit_code;
bool is_kthread;
/* Trace data */
bool is_tracee;
};
typedef struct proc proc_t;
/**
* PROC FUNCTIONS
*/
uint32_t proc_alloc_pid();
struct thread* thread_by_pid(pid_t pid);
int proc_init_storage();
int proc_setup(proc_t* p);
int proc_setup_with_uid(proc_t* p, uid_t uid, gid_t gid);
int proc_setup_tty(proc_t* p, tty_entry_t* tty);
int proc_fill_up_stack(proc_t* p, int argc, char** argv, char** env);
int proc_free(proc_t* p);
int proc_free_lockless(proc_t* p);
struct thread* proc_alloc_thread();
struct thread* proc_create_thread(proc_t* p);
void proc_kill_all_threads(proc_t* p);
void proc_kill_all_threads_except(proc_t* p, struct thread* gthread);
/**
* KTHREAD FUNCTIONS
*/
int kthread_setup(proc_t* p);
int kthread_setup_regs(proc_t* p, void* entry_point);
void kthread_setup_segment_regs(proc_t* p);
int kthread_fill_up_stack(struct thread* thread, void* data);
int kthread_free(proc_t* p);
int proc_load(proc_t* p, struct thread* main_thread, const char* path);
int proc_fork_from(proc_t* new_proc, struct thread* from_thread);
int proc_die(proc_t* p);
int proc_block_all_threads(proc_t* p, const struct blocker* blocker);
/**
* PROC FD FUNCTIONS
*/
int proc_chdir(proc_t* p, const char* path);
file_descriptor_t* proc_get_free_fd(proc_t* p);
file_descriptor_t* proc_get_fd(proc_t* p, uint32_t index);
int proc_get_fd_id(proc_t* proc, file_descriptor_t* fd);
int proc_copy_fd(file_descriptor_t* oldfd, file_descriptor_t* newfd);
/**
* PROC HELPER FUNCTIONS
*/
static ALWAYS_INLINE bool proc_is_su(proc_t* p) { return p->euid == 0; }
static ALWAYS_INLINE int proc_is_alive(proc_t* p) { return p->status == PROC_ALIVE; }
#endif // _KERNEL_TASKING_PROC_H |
willmexe/opuntiaOS | kernel/include/drivers/generic/timer.h | #ifdef __i386__
#include <drivers/x86/pit.h>
#elif __arm__
#include <drivers/aarch32/sp804.h>
#endif |
willmexe/opuntiaOS | libs/libc/include/sched.h | #ifndef _LIBC_SCHED_H
#define _LIBC_SCHED_H
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
void sched_yield();
__END_DECLS
#endif // _LIBC_SCHED_H |
willmexe/opuntiaOS | kernel/include/libkern/printf.h | <filename>kernel/include/libkern/printf.h
#ifndef _KERNEL_LIBKERN_PRINTF_H
#define _KERNEL_LIBKERN_PRINTF_H
#include <libkern/types.h>
typedef int (*printf_putch_callback)(char ch, char* buf_base, size_t* written, void* callback_params);
int vsnprintf(char* s, size_t n, const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);
int snprintf(char* s, size_t n, const char* format, ...);
int sprintf(char* s, const char* format, ...);
int printf_engine(char* buf, const char* format, printf_putch_callback callback, void* callback_params, va_list arg);
#endif // _KERNEL_LIBKERN_PRINTF_H |
willmexe/opuntiaOS | kernel/include/platform/x86/vmm/consts.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_PLATFORM_X86_VMM_CONSTS_H
#define _KERNEL_PLATFORM_X86_VMM_CONSTS_H
#define VMM_PTE_COUNT (1024)
#define VMM_PDE_COUNT (1024)
#define VMM_PAGE_SIZE (4096)
#define VMM_OFFSET_IN_DIRECTORY(a) (((a) >> 22) & 0x3ff)
#define VMM_OFFSET_IN_TABLE(a) (((a) >> 12) & 0x3ff)
#define VMM_OFFSET_IN_PAGE(a) ((a)&0xfff)
#define TABLE_START(vaddr) ((vaddr >> 22) << 22)
#define PAGE_START(vaddr) ((vaddr >> 12) << 12)
#define FRAME(addr) (addr / VMM_PAGE_SIZE)
#define VMM_USER_TABLES_START 0
#define VMM_KERNEL_TABLES_START 768
#endif //_KERNEL_PLATFORM_X86_VMM_CONSTS_H
|
willmexe/opuntiaOS | userland/tests/utester/main.c | <gh_stars>0
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
void exectest(void)
{
int i, pid;
char* paramscat[] = {
"/bin/cat",
"../readme",
"../readme",
(char*)0,
};
for (i = 0; i < 20; i++) {
pid = fork();
if (pid < 0) {
write(1, "fork failed\n", 12);
return;
}
if (pid) {
wait(pid);
} else {
execve("/bin/cat", paramscat, 0);
write(1, "exec failed\n", 12);
exit(0);
}
}
write(1, "exectest ok\n", 12);
}
void exitwait(void)
{
int i, pid;
for (i = 0; i < 20; i++) {
pid = fork();
if (pid < 0) {
write(1, "fork failed\n", 12);
return;
}
if (pid) {
wait(pid);
} else {
exit(0);
}
}
write(1, "exitwait ok\n", 12);
}
void mem(void)
{
void *m1, *m2;
int pid, ppid;
write(1, "mem test\n", 9);
ppid = getpid();
if ((pid = fork()) == 0) {
m1 = 0;
for (int i = 0; i < 1; i++) {
m2 = malloc(10001);
if (m2 == 0) {
write(1, "couldn't allocate mem1!!\n", 25);
kill(ppid, 9);
exit(1);
}
*(char**)m2 = m1;
m1 = m2;
}
while (m1) {
m2 = *(char**)m1;
free(m1);
m1 = m2;
}
m1 = malloc(1024 * 20);
if (m1 == 0) {
write(1, "couldn't allocate mem?!!\n", 25);
kill(ppid, 9);
exit(1);
}
free(m1);
write(1, "mem ok\n", 7);
exit(0);
} else {
wait(pid);
}
}
char buf[512];
// four processes write different files at the same
// time, to test block allocation.
void fourfiles(void)
{
int fd, pid, i, j, n, total, pi;
char* names[] = { "f0.e", "f1.e", "f2.e", "f3.e" };
char* fname;
int pids[4];
write(1, "fourfiles test\n", 15);
for (pi = 0; pi < 4; pi++) {
fname = names[pi];
unlink(fname);
pid = fork();
pids[pi] = pid;
if (pid < 0) {
write(1, "fork failed\n", 12);
exit(-1);
}
if (pid == 0) {
fd = open(fname, O_CREAT | O_RDWR);
if (fd < 0) {
write(1, "create failed\n", 14);
exit(-1);
}
memset(buf, '0' + pi, 512);
for (i = 0; i < 12; i++) {
if ((n = write(fd, buf, 500)) != 500) {
write(1, "write failed\n", 14);
exit(-1);
}
}
exit(-1);
}
}
for (pi = 0; pi < 4; pi++) {
wait(pids[pi]);
}
for (i = 0; i < 4; i++) {
fname = names[i];
fd = open(fname, 0);
total = 0;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
for (j = 0; j < n; j++) {
if (buf[j] != '0' + i) {
write(1, "wrong char\n", 11);
exit(-1);
}
}
total += n;
}
close(fd);
if (total != 12 * 500) {
write(1, "wrong length\n", 13);
exit(-1);
}
unlink(fname);
}
write(1, "fourfiles ok\n", 13);
}
void dirfile(void)
{
int fd;
write(1, "dir vs file\n", 12);
fd = open("dirfile", 0);
if (fd >= 0) {
write(1, "create dirfile succeeded!\n", 26);
exit(-1);
}
fd = open("dirfile", O_CREAT);
if (chdir("dirfile") == 0) {
write(1, "chdir dirfile succeeded!\n", 25);
exit(-1);
}
if (unlink("dirfile") != 0) {
write(1, "unlink dirfile failed!\n", 23);
exit(-1);
}
fd = open(".", O_RDWR);
if (fd >= 0) {
write(1, "open . for writing succeeded!\n", 30);
exit(-1);
}
fd = open(".", 0);
if (write(fd, "x", 1) > 0) {
write(1, "write . succeeded!\n", 19);
exit(-1);
}
close(fd);
write(1, "dir vs file OK\n", 15);
}
static volatile int rev = 0;
int inter(int no)
{
write(1, ")", 1);
rev++;
return 0;
}
void testsignals()
{
write(1, "signals test\n", 13);
int pid = fork();
if (pid) {
sched_yield();
for (int i = 0; i < 50; i++) {
write(1, "(", 1);
kill(pid, 3);
sched_yield();
}
wait(pid);
} else {
sigaction(3, inter);
while (rev != 50) {
}
for (int i = 0; i < 50; i++) {
write(1, "(", 1);
raise(3);
}
}
}
int main(int argc, char** argv)
{
testsignals();
mem();
exectest();
fourfiles();
dirfile();
return 0;
} |
willmexe/opuntiaOS | userland/utilities/edit/lifetime.h | <filename>userland/utilities/edit/lifetime.h<gh_stars>100-1000
#ifndef _USERLAND_EDIT_LIFETIME_H
#define _USERLAND_EDIT_LIFETIME_H
#include "viewer.h"
#include <termios.h>
extern struct termios orig_term;
void enable_raw_mode();
void restore_termios();
void exit_app();
void crash_app();
#endif |
willmexe/opuntiaOS | userland/utilities/edit/menu.h | <gh_stars>100-1000
#ifndef _USERLAND_EDIT_MENU_H
#define _USERLAND_EDIT_MENU_H
#include "mode.h"
#include "viewer.h"
void menu_enter_mode();
void menu_leave_mode();
void menu_accept_key(char key);
#endif |
willmexe/opuntiaOS | libs/libc/stdlib/env.c | <filename>libs/libc/stdlib/env.c
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
static void free_var(const char* string)
{
// TODO: Implement me!
}
char* getenv(const char* name)
{
size_t len = strlen(name);
for (int i = 0; environ[i]; i++) {
const char* envv = environ[i];
char* eqpos = strchr(envv, '=');
if (!eqpos) {
continue;
}
size_t curlen = (size_t)(eqpos - envv);
if (curlen == len && strncmp(name, envv, len) == 0) {
return (char*)&envv[len + 1];
}
}
return NULL;
}
int setenv(const char* name, const char* value, int overwrite)
{
if (!overwrite && getenv(name)) {
return 0;
}
int name_len = strlen(name);
int value_len = strlen(value);
int len = name_len + 1 + value_len;
char* string = (char*)malloc(len + 1);
strncpy(string, name, name_len);
string[name_len] = '=';
strncpy(&string[name_len + 1], value, value_len);
string[len] = '\0';
return putenv(string);
}
int putenv(char* string)
{
char* pos = strchr(string, '=');
if (!pos) {
return unsetenv(string);
}
size_t len = (size_t)(pos - string);
int env_i = 0;
for (; environ[env_i]; env_i++) {
const char* envv = environ[env_i];
char* eqpos = strchr(envv, '=');
if (!eqpos) {
continue;
}
size_t curlen = (size_t)(eqpos - envv);
if (len != curlen) {
continue;
}
if (strncmp(string, envv, len) == 0) {
free_var(envv);
environ[env_i] = string;
return 0;
}
}
char** new_environ = (char**)malloc(sizeof(char*) * (env_i + 2));
for (int i = 0; i < env_i; i++) {
new_environ[i] = environ[i];
}
new_environ[env_i] = string;
new_environ[env_i + 1] = NULL;
extern int __environ_malloced;
if (__environ_malloced) {
free(environ);
}
environ = new_environ;
__environ_malloced = 1;
return 0;
}
int unsetenv(const char* name)
{
size_t len = strlen(name);
int env_i = 0;
int remove_pos = 0;
const char* remove_env = NULL;
for (; environ[env_i]; env_i++) {
const char* envv = environ[env_i];
char* eqpos = strchr(envv, '=');
if (!eqpos) {
continue;
}
size_t curlen = (size_t)(eqpos - envv);
if (len != curlen) {
continue;
}
if (strncmp(name, envv, len) == 0) {
remove_pos = env_i;
remove_env = envv;
}
}
size_t move_len = ((env_i - 1) - remove_pos) * sizeof(char*);
memmove(&environ[remove_pos], &environ[remove_pos + 1], move_len);
free_var(remove_env);
return 0;
}
|
willmexe/opuntiaOS | libs/libc/include/sys/environ.h | #ifndef _LIBC_SYS_ENVIRON_H
#define _LIBC_SYS_ENVIRON_H
#include <sys/cdefs.h>
__BEGIN_DECLS
extern char** environ;
__END_DECLS
#endif // _LIBC_SYS_ENVIRON_H |
willmexe/opuntiaOS | libs/libui/include/libui/Screen.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
#include <cstring>
#include <fcntl.h>
#include <libg/Rect.h>
#include <string>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <utility>
namespace UI {
class Screen;
static Screen* __main_screen;
class Screen {
public:
Screen()
: m_screen_fd(open("/dev/bga", O_RDONLY))
, m_bounds(0, 0, ioctl(m_screen_fd, BGA_GET_WIDTH, 0), ioctl(m_screen_fd, BGA_GET_HEIGHT, 0))
{
}
explicit Screen(const std::string& path)
: m_screen_fd(open(path.c_str(), O_RDONLY))
, m_bounds(0, 0, ioctl(m_screen_fd, BGA_GET_WIDTH, 0), ioctl(m_screen_fd, BGA_GET_HEIGHT, 0))
{
}
~Screen() = default;
int scale() const { return 1; }
const LG::Rect& bounds() const { return m_bounds; }
static Screen& main()
{
if (!__main_screen) {
__main_screen = new UI::Screen();
}
return *__main_screen;
}
private:
int m_screen_fd;
LG::Rect m_bounds;
};
} // namespace UI |
willmexe/opuntiaOS | kernel/kernel/syscalls/handler.c | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/log.h>
#include <mem/kmalloc.h>
#include <platform/generic/syscalls/params.h>
#include <platform/generic/system.h>
#include <syscalls/handlers.h>
#include <tasking/cpu.h>
static const void* syscalls[] = {
[SYS_RESTART_SYSCALL] = sys_restart_syscall,
[SYS_EXIT] = sys_exit,
[SYS_FORK] = sys_fork,
[SYS_READ] = sys_read,
[SYS_WRITE] = sys_write,
[SYS_OPEN] = sys_open,
[SYS_CLOSE] = sys_close,
[SYS_WAITPID] = sys_waitpid,
[SYS_CREAT] = sys_creat,
[SYS_LINK] = sys_none, // sys_link
[SYS_UNLINK] = sys_unlink,
[SYS_EXECVE] = sys_exec,
[SYS_CHDIR] = sys_chdir,
[SYS_GETCWD] = sys_getcwd,
[SYS_SIGACTION] = sys_sigaction,
[SYS_SIGRETURN] = sys_sigreturn,
[SYS_GETTIMEOFDAY] = sys_gettimeofday,
[SYS_LSEEK] = sys_lseek,
[SYS_GETPID] = sys_getpid,
[SYS_GETUID] = sys_getuid,
[SYS_SETUID] = sys_setuid,
[SYS_SETGID] = sys_setgid,
[SYS_SETREUID] = sys_setreuid,
[SYS_SETREGID] = sys_setregid,
[SYS_KILL] = sys_kill,
[SYS_MKDIR] = sys_mkdir,
[SYS_RMDIR] = sys_rmdir,
[SYS_MMAP] = sys_mmap,
[SYS_MUNMAP] = sys_munmap,
[SYS_DUP] = sys_dup,
[SYS_DUP2] = sys_dup2,
[SYS_SOCKET] = sys_socket,
[SYS_BIND] = sys_bind,
[SYS_CONNECT] = sys_connect,
[SYS_GETDENTS] = sys_getdents,
[SYS_IOCTL] = sys_ioctl,
[SYS_SETPGID] = sys_setpgid,
[SYS_GETPGID] = sys_getpgid,
[SYS_PTHREAD_CREATE] = sys_create_thread,
[SYS_NANOSLEEP] = sys_sleep,
[SYS_PTRACE] = sys_ptrace,
[SYS_SELECT] = sys_select,
[SYS_FSTAT] = sys_fstat,
[SYS_FSYNC] = sys_fsync,
[SYS_SCHED_YIELD] = sys_sched_yield,
[SYS_UNAME] = sys_uname,
[SYS_CLOCK_GETTIME] = sys_clock_gettime,
[SYS_CLOCK_SETTIME] = sys_none,
[SYS_CLOCK_GETRES] = sys_none,
[SYS_NICE] = sys_nice,
[SYS_SHBUF_CREATE] = sys_shbuf_create,
[SYS_SHBUF_GET] = sys_shbuf_get,
[SYS_SHBUF_FREE] = sys_shbuf_free,
};
#ifdef __i386__
int ksyscall_impl(int id, int a, int b, int c, int d)
{
system_disable_interrupts();
trapframe_t* tf;
trapframe_t tf_on_stack;
tf = &tf_on_stack;
SYSCALL_ID(tf) = id;
SYSCALL_VAR1(tf) = a;
SYSCALL_VAR2(tf) = b;
SYSCALL_VAR3(tf) = c;
sys_handler(tf);
/* This hack has to be here, when a context switching happens
during a syscall (e.g. when block occurs). The hack will start
interrupts again after it has become a running thread. */
cpu_enter_kernel_space();
system_enable_interrupts();
return SYSCALL_VAR1(tf);
}
#elif __arm__
int ksyscall_impl(int id, int a, int b, int c, int d)
{
int ret;
asm volatile(
"mov r7, %1;\
mov r0, %2;\
mov r1, %3;\
mov r2, %4;\
mov r3, %5;\
mov r4, %6;\
swi 1;\
mov %0, r0;"
: "=r"(ret)
: "r"(id), "r"((int)(a)), "r"((int)(b)), "r"((int)(c)), "r"((int)(d)), "r"((int)(0))
: "memory", "r0", "r1", "r2", "r3", "r4", "r7");
return ret;
}
#endif
void sys_handler(trapframe_t* tf)
{
system_disable_interrupts();
cpu_enter_kernel_space();
void (*callee)(trapframe_t*) = (void*)syscalls[SYSCALL_ID(tf)];
callee(tf);
cpu_leave_kernel_space();
system_enable_interrupts_only_counter();
}
void sys_restart_syscall(trapframe_t* tf)
{
}
void sys_none(trapframe_t* tf) { }
|
willmexe/opuntiaOS | libs/libc/ptrace/ptrace.c | #include <sys/ptrace.h>
#include <sysdep.h>
int ptrace(ptrace_request_t request, pid_t pid, void* addr, void* data)
{
int res = DO_SYSCALL_4(SYS_PTRACE, request, pid, addr, data);
RETURN_WITH_ERRNO(res, 0, res);
} |
willmexe/opuntiaOS | userland/utilities/rmdir/main.c | <reponame>willmexe/opuntiaOS<filename>userland/utilities/rmdir/main.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (argc < 2) {
printf("Usage: rmdir files...\n");
return 0;
}
for (int i = 1; i < argc; i++) {
if (rmdir(argv[i]) < 0) {
printf("rmdir: failed to delete\n");
break;
}
}
return 0;
} |
willmexe/opuntiaOS | userland/system/homescreen/HomeScreenView.h | <filename>userland/system/homescreen/HomeScreenView.h
#pragma once
#include "AppListView.h"
#include "FastLaunchEntity.h"
#include "HomeScreenEntity.h"
#include <libg/Font.h>
#include <libui/StackView.h>
#include <libui/View.h>
#include <list>
#include <string>
#include <vector>
class HomeScreenView : public UI::View {
UI_OBJECT();
public:
HomeScreenView(UI::View* superview, const LG::Rect& frame);
HomeScreenView(UI::View* superview, UI::Window* window, const LG::Rect& frame);
static constexpr int dock_height() { return 70; }
static constexpr int applist_height() { return 22; }
static constexpr int dock_height_with_padding() { return dock_height() + applist_height() + 2 * grid_padding() + 4; }
static constexpr int grid_entities_size() { return 48; }
static constexpr int icon_size() { return 48; }
static constexpr int icon_view_size() { return 62; }
static constexpr int grid_padding() { return 16; }
static constexpr int grid_entities_per_row() { return 4; }
static constexpr int grid_entities_per_column() { return 5; }
void display(const LG::Rect& rect) override;
void on_window_create(const std::string& bundle_id, const std::string& icon_path, int window_id, int window_type);
void new_grid_entity(const std::string& title, const std::string& icon_path, std::string&& exec_path);
void new_fast_launch_entity(const std::string& title, const std::string& icon_path, std::string&& exec_path);
private:
std::vector<UI::StackView*> m_grid_stackviews;
UI::StackView* m_dock_stackview {};
AppListView* m_applist_view {};
std::list<FastLaunchEntity> m_grid_entites {};
std::list<FastLaunchEntity> m_fast_launch_entites {};
}; |
willmexe/opuntiaOS | libs/libc/include/bits/signal.h | <reponame>willmexe/opuntiaOS<gh_stars>100-1000
#ifndef _LIBC_BITS_SIGNAL_H
#define _LIBC_BITS_SIGNAL_H
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
#define SIGPWR 30
#define SIGSYS 31
#endif // _LIBC_BITS_SIGNAL_H |
willmexe/opuntiaOS | test/kernel/signal/main.c | <gh_stars>100-1000
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int ret = 1;
void save_on_terminate()
{
ret = 0;
}
int main(int argc, char** argv)
{
sigaction(SIGTERM, save_on_terminate);
raise(SIGTERM);
return ret;
} |
willmexe/opuntiaOS | kernel/kernel/libkern/log.c | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <drivers/generic/uart.h>
#include <libkern/libkern.h>
#include <libkern/lock.h>
#include <libkern/log.h>
#include <libkern/stdarg.h>
// Turn off lock debug output for log.
#ifdef DEBUG_LOCK
#undef lock_acquire
#undef lock_release
#endif
static lock_t _log_lock;
static int putch_callback_stream(char c, char* buf_base, size_t* written, void* callback_params)
{
return uart_write(COM1, c);
}
static int vlog_unfmt(const char* format, va_list arg)
{
return printf_engine(NULL, format, putch_callback_stream, NULL, arg);
}
static int vlog_fmt(const char* init_msg, const char* format, va_list arg)
{
vlog_unfmt(init_msg, arg);
vlog_unfmt(format, arg);
if (format[-1] != '\n') {
vlog_unfmt("\n", arg);
}
return 0;
}
int log(const char* format, ...)
{
lock_acquire(&_log_lock);
va_list arg;
va_start(arg, format);
int ret = vlog_fmt("\033[1;37m[LOG]\033[0m ", format, arg);
va_end(arg);
lock_release(&_log_lock);
return ret;
}
int log_warn(const char* format, ...)
{
lock_acquire(&_log_lock);
va_list arg;
va_start(arg, format);
int ret = vlog_fmt("\033[1;33m[WARN]\033[0m ", format, arg);
va_end(arg);
lock_release(&_log_lock);
return ret;
}
int log_error(const char* format, ...)
{
lock_acquire(&_log_lock);
va_list arg;
va_start(arg, format);
int ret = vlog_fmt("\033[1;31m[ERR]\033[0m ", format, arg);
va_end(arg);
lock_release(&_log_lock);
return ret;
}
int log_not_formatted(const char* format, ...)
{
lock_acquire(&_log_lock);
va_list arg;
va_start(arg, format);
int ret = vlog_unfmt(format, arg);
va_end(arg);
lock_release(&_log_lock);
return ret;
}
void logger_setup()
{
lock_init(&_log_lock);
uart_setup();
} |
willmexe/opuntiaOS | kernel/kernel/fs/procfs/procfs.c | <gh_stars>0
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <fs/procfs/procfs.h>
#include <fs/vfs.h>
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/log.h>
// #define PROCFS_DEBUG
/**
* ProcFS works with caches differently. It does NOT allow reading
* of random inode in it's current implementation. Instead of
* accessing inode randomly, every cache entry (dentry) will be
* filled up with inode by lookup functions, and the ONLY way when
* procfs_read_inode will be called is to get the root inode.
*/
extern const file_ops_t procfs_root_ops;
int procfs_read_inode(dentry_t* dentry)
{
if (dentry->inode_indx != 2) {
ASSERT("NOT ROOT ENTRY ID READ IN PROCFS");
}
procfs_inode_t* procfs_inode = (procfs_inode_t*)dentry->inode;
memset((void*)procfs_inode, 0, sizeof(procfs_inode_t));
procfs_inode->index = 2;
procfs_inode->mode = S_IFDIR | 0444;
procfs_inode->ops = &procfs_root_ops;
return 0;
}
int procfs_write_inode(dentry_t* dentry)
{
return 0;
}
int procfs_free_inode(dentry_t* dentry)
{
return 0;
}
fsdata_t procfs_data(dentry_t* dentry)
{
fsdata_t fsdata;
fsdata.sb = 0;
fsdata.gt = 0;
return fsdata;
}
int procfs_can_read(dentry_t* dentry, uint32_t start)
{
procfs_inode_t* procfs_inode = (procfs_inode_t*)dentry->inode;
if (!procfs_inode->ops->can_read) {
return -ENOEXEC;
}
return procfs_inode->ops->can_read(dentry, start);
}
int procfs_read(dentry_t* dentry, uint8_t* buf, size_t start, size_t len)
{
procfs_inode_t* procfs_inode = (procfs_inode_t*)dentry->inode;
if (!procfs_inode->ops->read) {
return -ENOEXEC;
}
return procfs_inode->ops->read(dentry, buf, start, len);
}
int procfs_getdents(dentry_t* dir, uint8_t* buf, off_t* offset, size_t len)
{
procfs_inode_t* procfs_inode = (procfs_inode_t*)dir->inode;
if (!procfs_inode->ops->getdents) {
return -ENOEXEC;
}
return procfs_inode->ops->getdents(dir, buf, offset, len);
}
int procfs_lookup(dentry_t* dir, const char* name, uint32_t len, dentry_t** result)
{
procfs_inode_t* procfs_inode = (procfs_inode_t*)dir->inode;
if (!procfs_inode->ops->lookup) {
return -ENOEXEC;
}
return procfs_inode->ops->lookup(dir, name, len, result);
}
driver_desc_t _procfs_driver_info()
{
driver_desc_t fs_desc = { 0 };
fs_desc.type = DRIVER_FILE_SYSTEM;
fs_desc.functions[DRIVER_FILE_SYSTEM_RECOGNIZE] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_PREPARE_FS] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_OPEN] = NULL; /* No custom open, vfs will use its code */
fs_desc.functions[DRIVER_FILE_SYSTEM_CAN_READ] = procfs_can_read;
fs_desc.functions[DRIVER_FILE_SYSTEM_READ] = procfs_read;
fs_desc.functions[DRIVER_FILE_SYSTEM_WRITE] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_TRUNCATE] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_MKDIR] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_EJECT_DEVICE] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_READ_INODE] = procfs_read_inode;
fs_desc.functions[DRIVER_FILE_SYSTEM_WRITE_INODE] = procfs_write_inode;
fs_desc.functions[DRIVER_FILE_SYSTEM_FREE_INODE] = procfs_free_inode;
fs_desc.functions[DRIVER_FILE_SYSTEM_GET_FSDATA] = procfs_data;
fs_desc.functions[DRIVER_FILE_SYSTEM_LOOKUP] = procfs_lookup;
fs_desc.functions[DRIVER_FILE_SYSTEM_GETDENTS] = procfs_getdents;
fs_desc.functions[DRIVER_FILE_SYSTEM_FSTAT] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_IOCTL] = NULL;
fs_desc.functions[DRIVER_FILE_SYSTEM_MMAP] = NULL;
return fs_desc;
}
void procfs_install()
{
devman_register_driver(_procfs_driver_info(), "procfs");
}
devman_register_driver_installation(procfs_install);
int procfs_mount()
{
dentry_t* mp;
if (vfs_resolve_path("/proc", &mp) < 0) {
return -ENOENT;
}
int driver_id = vfs_get_fs_id("procfs");
if (driver_id < 0) {
#ifdef PROCFS_DEBUG
log("Procfs: no driver is installed, exiting");
#endif
return -ENOENT;
}
#ifdef PROCFS_DEBUG
log("procfs: %x", driver_id);
#endif
int err = vfs_mount(mp, new_virtual_device(DEVICE_STORAGE), driver_id);
dentry_put(mp);
return err;
} |
willmexe/opuntiaOS | libs/libc/include/sys/select.h | #ifndef _LIBC_SYS_SELECT_H
#define _LIBC_SYS_SELECT_H
#include <bits/sys/select.h>
#include <bits/time.h>
#include <stddef.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
int select(int nfds, fd_set_t* readfds, fd_set_t* writefds, fd_set_t* exceptfds, timeval_t* timeout);
__END_DECLS
#endif // _LIBC_SYS_SELECT_H |
willmexe/opuntiaOS | kernel/include/libkern/lock.h | <filename>kernel/include/libkern/lock.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_LIBKERN_LOCK_H
#define _KERNEL_LIBKERN_LOCK_H
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/log.h>
#include <libkern/types.h>
// #define DEBUG_LOCK
struct lock {
int status;
#ifdef DEBUG_LOCK
#endif // DEBUG_LOCK
};
typedef struct lock lock_t;
static ALWAYS_INLINE void lock_init(lock_t* lock)
{
__atomic_store_n(&lock->status, 0, __ATOMIC_RELAXED);
}
static ALWAYS_INLINE void lock_acquire(lock_t* lock)
{
while (__atomic_exchange_n(&lock->status, 1, __ATOMIC_ACQUIRE) == 1) {
// TODO: May be some cpu sleep?
}
}
static ALWAYS_INLINE void lock_release(lock_t* lock)
{
ASSERT(lock->status == 1);
__atomic_store_n(&lock->status, 0, __ATOMIC_RELEASE);
}
#ifdef DEBUG_LOCK
#define lock_acquire(x) \
log("acquire lock %s %s:%d ", #x, __FILE__, __LINE__); \
lock_acquire(x);
#define lock_release(x) \
log("release lock %s %s:%d ", #x, __FILE__, __LINE__); \
lock_release(x);
#endif
#endif // _KERNEL_LIBKERN_LOCK_H |
willmexe/opuntiaOS | boot/x86/stage2/stage2.c | <gh_stars>0
/**
* Stage2 is used to load main kernel.
*/
#include "config.h"
#include "drivers/ata.h"
#include "drivers/uart.h"
#include "mem/vm.h"
#include <libboot/abi/drivers.h>
#include <libboot/abi/memory.h>
#include <libboot/elf/elf_lite.h>
#include <libboot/fs/ext2_lite.h>
#include <libboot/log/log.h>
#include <libboot/mem/mem.h>
#include <libboot/types.h>
// #define DEBUG_BOOT
static boot_desc_t boot_desc;
int prepare_boot_disk(drive_desc_t* drive_desc)
{
init_ata(0x1F0, 1);
if (indentify_ata_device(drive_desc) == 0) {
return 0;
}
return -1;
}
int prepare_fs(drive_desc_t* drive_desc, fs_desc_t* fs_desc)
{
if (ext2_lite_init(drive_desc, fs_desc) == 0) {
return 0;
}
return -1;
}
void* bootdesc_ptr;
void load_kernel(drive_desc_t* drive_desc, fs_desc_t* fs_desc, mem_desc_t* mem_desc)
{
size_t kernel_vaddr = 0;
size_t kernel_paddr = 0;
size_t kernel_size = 0;
int res = elf_load_kernel(drive_desc, fs_desc, KERNEL_PATH, &kernel_vaddr, &kernel_paddr, &kernel_size);
kernel_size = align_size(kernel_size, VMM_PAGE_SIZE);
boot_desc_t boot_desc;
boot_desc.vaddr = kernel_vaddr;
boot_desc.paddr = kernel_paddr;
boot_desc.kernel_size = (kernel_size + align_size(sizeof(boot_desc_t), VMM_PAGE_SIZE)) / 1024;
boot_desc.devtree = NULL;
boot_desc.memory_map = (void*)0xA00;
boot_desc.memory_map_size = mem_desc->memory_map_size;
bootdesc_ptr = paddr_to_vaddr(copy_after_kernel(kernel_paddr, &boot_desc, sizeof(boot_desc), &kernel_size, VMM_PAGE_SIZE), kernel_paddr, kernel_vaddr);
}
void stage2(mem_desc_t* mem_desc)
{
uart_init();
log_init(uart_write);
#ifdef DEBUG_BOOT
log("STAGE2");
#endif
drive_desc_t drive_desc;
fs_desc_t fs_desc;
if (prepare_boot_disk(&drive_desc) != 0) {
#ifdef DEBUG_BOOT
log("STAGE2");
#endif
while (1) { }
}
if (prepare_fs(&drive_desc, &fs_desc) != 0) {
#ifdef DEBUG_BOOT
log("STAGE2");
#endif
while (1) { }
}
load_kernel(&drive_desc, &fs_desc, mem_desc);
vm_setup();
// enabling paging
asm volatile("mov %cr0, %eax");
asm volatile("or $0x80000000, %eax");
asm volatile("mov %eax, %cr0");
asm volatile("push %0"
:
: "r"(bootdesc_ptr));
asm volatile("mov $0xc0000000, %eax");
asm volatile("call *%eax");
while (1) { }
}
|
willmexe/opuntiaOS | libs/libc/time/time.c | <filename>libs/libc/time/time.c
#include <sys/time.h>
#include <sysdep.h>
#include <time.h>
static const int __days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static inline char __is_leap_year(time_t year)
{
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}
static void time_to_tm(time_t timep, tm_t* res)
{
res->tm_sec = timep % 60;
time_t minutes = timep / 60;
res->tm_min = minutes % 60;
time_t hours = minutes / 60;
res->tm_hour = hours % 24;
time_t days = hours / 24;
res->tm_wday = (days + 4) % 7;
time_t year = 1970;
while (days >= 365 + __is_leap_year(year)) {
days -= 365 + __is_leap_year(year);
year++;
}
res->tm_year = year - 1900;
res->tm_yday = days;
res->tm_mday = 1;
if (__is_leap_year(year) && days >= 59) {
days--;
if (days == 59) {
res->tm_mday = 2;
}
}
time_t m;
for (m = 0; m < 11; m++) {
if (days <= __days_per_month[m]) {
break;
}
days -= __days_per_month[m];
}
res->tm_mday += days;
res->tm_mon = m;
}
time_t time(time_t* timep)
{
timeval_t tv;
timezone_t tz;
if (gettimeofday(&tv, &tz) != 0) {
return (time_t)-1;
}
if (timep) {
*timep = tv.tv_sec;
}
return tv.tv_sec;
}
char* asctime(const tm_t* tm)
{
return NULL;
}
char* asctime_r(const tm_t* tm, char* buf)
{
return NULL;
}
char* ctime(const time_t* timep)
{
return NULL;
}
char* ctime_r(const time_t* timep, char* buf)
{
return NULL;
}
tm_t* gmtime(const time_t* timep)
{
static tm_t tm_gmtime_buf;
return gmtime_r(timep, &tm_gmtime_buf);
}
tm_t* gmtime_r(const time_t* timep, tm_t* result)
{
if (!result || !timep) {
return NULL;
}
time_to_tm(*timep, result);
return result;
}
tm_t* localtime(const time_t* timep)
{
static tm_t tm_localtime_buf;
return localtime_r(timep, &tm_localtime_buf);
}
tm_t* localtime_r(const time_t* timep, tm_t* result)
{
// FIXME: Implement time zone
if (!result || !timep) {
return NULL;
}
time_to_tm(*timep, result);
return result;
}
time_t mktime(tm_t* tm)
{
return 0;
}
int clock_gettime(clockid_t clk_id, timespec_t* tp)
{
int res = DO_SYSCALL_2(SYS_CLOCK_GETTIME, clk_id, tp);
RETURN_WITH_ERRNO(res, res, -1);
}
// TODO: Implement
int clock_getres(clockid_t clk_id, timespec_t* res) { return -1; }
int clock_settime(clockid_t clk_id, const timespec_t* tp) { return -1; }
|
willmexe/opuntiaOS | kernel/include/platform/generic/vmm/pte.h | #ifdef __i386__
#include <platform/x86/vmm/pte.h>
#elif __arm__
#include <platform/aarch32/vmm/pte.h>
#endif |
willmexe/opuntiaOS | kernel/include/platform/x86/system.h | <reponame>willmexe/opuntiaOS<filename>kernel/include/platform/x86/system.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_PLATFORM_X86_SYSTEM_H
#define _KERNEL_PLATFORM_X86_SYSTEM_H
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#include <platform/generic/registers.h>
/**
* INTS
*/
void system_disable_interrupts();
void system_enable_interrupts();
void system_enable_interrupts_only_counter();
inline static void system_disable_interrupts_no_counter() { asm volatile("cli"); }
inline static void system_enable_interrupts_no_counter() { asm volatile("sti"); }
/**
* PAGING
*/
inline static void system_set_pdir(uintptr_t pdir)
{
asm volatile("mov %%eax, %%cr3"
:
: "a"(pdir));
}
inline static void system_flush_local_tlb_entry(uintptr_t vaddr)
{
asm volatile("invlpg (%0)" ::"r"(vaddr)
: "memory");
}
inline static void system_flush_all_cpus_tlb_entry(uintptr_t vaddr)
{
system_flush_local_tlb_entry(vaddr);
// TODO: Send inter-processor messages.
}
inline static void system_flush_whole_tlb()
{
system_set_pdir(read_cr3());
}
inline static void system_enable_write_protect()
{
asm volatile("mov %cr0, %eax");
asm volatile("or $0x10000, %eax");
asm volatile("mov %eax, %cr0");
}
inline static void system_disable_write_protect()
{
asm volatile("mov %cr0, %eax");
asm volatile("and $0xFFFEFFFF, %eax");
asm volatile("mov %eax, %cr0");
}
inline static void system_enable_paging()
{
asm volatile("mov %cr0, %eax");
asm volatile("or $0x80000000, %eax");
asm volatile("mov %eax, %cr0");
}
inline static void system_disable_paging()
{
asm volatile("mov %cr0, %eax");
asm volatile("and $0x7FFFFFFF, %eax");
asm volatile("mov %eax, %cr0");
}
inline static void system_stop_until_interrupt()
{
asm volatile("hlt");
}
NORETURN inline static void system_stop()
{
system_disable_interrupts();
system_stop_until_interrupt();
while (1) { }
}
/**
* CPU
*/
inline static int system_cpu_id()
{
return 0;
}
#endif /* _KERNEL_PLATFORM_X86_SYSTEM_H */ |
willmexe/opuntiaOS | boot/x86/stage2/mem/vm.c | #include "vm.h"
int vm_setup()
{
ptable_t* table_0mb = (ptable_t*)0x9A000;
ptable_t* table_0mbplus = (ptable_t*)0x98000;
ptable_t* table_3gb = (ptable_t*)0x9B000;
ptable_t* table_3gbplus = (ptable_t*)0x99000;
ptable_t* table_stack = (ptable_t*)0x9C000;
pdirectory_t* dir = (pdirectory_t*)0x9D000;
for (uint32_t phyz = 0, virt = 0, i = 0; i < 1024; phyz += VMM_PAGE_SIZE, virt += VMM_PAGE_SIZE, i++) {
pte_t new_page = 0;
// pte_set_attr(&new_page, PTE_PRESENT);
new_page |= 3;
new_page |= ((phyz / VMM_PAGE_SIZE) << 12);
table_0mb->entities[i] = new_page;
}
for (uint32_t phyz = 0x400000, virt = 0x400000, i = 0; i < 1024; phyz += VMM_PAGE_SIZE, virt += VMM_PAGE_SIZE, i++) {
pte_t new_page = 0;
// pte_set_attr(&new_page, PTE_PRESENT);
new_page |= 3;
new_page |= ((phyz / VMM_PAGE_SIZE) << 12);
table_0mbplus->entities[i] = new_page;
}
for (uint32_t phyz = 0x100000, virt = 0xc0000000, i = 0; i < 1024; phyz += VMM_PAGE_SIZE, virt += VMM_PAGE_SIZE, i++) {
pte_t new_page = 0;
new_page |= 3;
new_page |= ((phyz / VMM_PAGE_SIZE) << 12);
table_3gb->entities[i] = new_page;
}
for (uint32_t phyz = 0x500000, virt = 0xc0400000, i = 0; i < 1024; phyz += VMM_PAGE_SIZE, virt += VMM_PAGE_SIZE, i++) {
pte_t new_page = 0;
new_page |= 3;
new_page |= ((phyz / VMM_PAGE_SIZE) << 12);
table_3gbplus->entities[i] = new_page;
}
for (uint32_t phyz = 0x000000, virt = 0xffc00000, i = 0; i < 1024; phyz += VMM_PAGE_SIZE, virt += VMM_PAGE_SIZE, i++) {
pte_t new_page = 0;
new_page |= 3;
new_page |= ((phyz / VMM_PAGE_SIZE) << 12);
table_stack->entities[i] = new_page;
}
uint8_t* dir_for_memset = (uint8_t*)dir;
for (int i = 0; i < 1024; i++) {
dir->entities[i] = 0;
}
uint32_t table_0mb_int = (uint32_t)table_0mb;
dir->entities[0] |= 3;
dir->entities[0] |= ((table_0mb_int / VMM_PAGE_SIZE) << 12);
table_0mb_int = (uint32_t)table_0mbplus;
dir->entities[1] |= 3;
dir->entities[1] |= ((table_0mb_int / VMM_PAGE_SIZE) << 12);
uint32_t table_3gb_int = (uint32_t)table_3gb;
dir->entities[768] |= 3;
dir->entities[768] |= ((table_3gb_int / VMM_PAGE_SIZE) << 12);
table_3gb_int = (uint32_t)table_3gbplus;
dir->entities[769] |= 3;
dir->entities[769] |= ((table_3gb_int / VMM_PAGE_SIZE) << 12);
uint32_t table_stack_int = (uint32_t)table_stack;
dir->entities[1023] |= 3;
dir->entities[1023] |= ((table_stack_int / VMM_PAGE_SIZE) << 12);
asm volatile("mov %%eax, %%cr3"
:
: "a"(dir));
return 0;
} |
willmexe/opuntiaOS | boot/aarch32/target/cortex-a15/memmap.h | <filename>boot/aarch32/target/cortex-a15/memmap.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _BOOT_TARGET_CORTEX_A15_MEMMAP_H
#define _BOOT_TARGET_CORTEX_A15_MEMMAP_H
#include <libboot/abi/memory.h>
extern struct memory_map arm_memmap[2];
#endif // _BOOT_TARGET_CORTEX_A15_MEMMAP_H |
willmexe/opuntiaOS | libs/libc/include/pthread.h | #ifndef _LIBC_PTHREAD_H
#define _LIBC_PTHREAD_H
#include <bits/thread.h>
#include <sys/_structs.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
int pthread_create(void* func);
__END_DECLS
#endif /* _LIBC_PTHREAD_H */ |
willmexe/opuntiaOS | test/kernel/fs/cwd/main.c | <gh_stars>100-1000
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char buf[256];
#define ANSWER "/test_bin/kernel$fs$cwd"
int main(int argc, char** argv)
{
int fd = 0;
fd = open("/proc/self/exe", O_RDONLY);
int rd = read(fd, buf, 256);
if (rd != strlen(ANSWER)) {
TestErr("Wrong len");
}
if (strncmp(buf, ANSWER, rd)) {
TestErr("Wrong path");
}
return 0;
} |
willmexe/opuntiaOS | kernel/kernel/mem/memzone.c | <reponame>willmexe/opuntiaOS<gh_stars>100-1000
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <fs/vfs.h>
#include <libkern/bits/errno.h>
#include <libkern/log.h>
#include <mem/kmalloc.h>
#include <tasking/proc.h>
/**
* PROC ZONING
*/
static inline bool _pzones_intersect(size_t start1, size_t size1, size_t start2, size_t size2)
{
size_t end1 = start1 + size1 - 1;
size_t end2 = start2 + size2 - 1;
return (start1 <= start2 && start2 <= end1) || (start1 <= end2 && end2 <= end1) || (start2 <= start1 && start1 <= end2) || (start2 <= end1 && end1 <= end2);
}
static inline bool _proc_can_fixup_zone(proc_t* proc, size_t* start_ptr, int* len_ptr)
{
size_t zones_count = proc->zones.size;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(&proc->zones, i);
if (_pzones_intersect(*start_ptr, *len_ptr, zone->start, zone->len)) {
if (*start_ptr >= zone->start) {
int move = (zone->start + zone->len) - (*start_ptr);
*start_ptr += move;
*len_ptr -= move;
} else {
int move = (*start_ptr + *len_ptr) - zone->start;
*len_ptr -= move;
}
if (*len_ptr <= 0) {
return false;
}
}
}
return true;
}
static inline bool _proc_can_add_zone(proc_t* proc, size_t start, size_t len)
{
size_t zones_count = proc->zones.size;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(&proc->zones, i);
if (_pzones_intersect(start, len, zone->start, zone->len)) {
return false;
}
}
return true;
}
static inline void _proc_swap_zones(memzone_t* one, memzone_t* two)
{
memzone_t tmp = *one;
*one = *two;
*two = tmp;
}
/**
* Inserts zone, which won't overlap with existing ones.
*/
memzone_t* memzone_extend(proc_t* proc, size_t start, size_t len)
{
len += (start & (VMM_PAGE_SIZE - 1));
start &= ~(VMM_PAGE_SIZE - 1);
if (len % VMM_PAGE_SIZE) {
len += VMM_PAGE_SIZE - (len % VMM_PAGE_SIZE);
}
memzone_t new_zone = { 0 };
new_zone.type = 0;
new_zone.flags = ZONE_USER;
if (_proc_can_fixup_zone(proc, &start, (int*)&len)) {
new_zone.start = start;
new_zone.len = len;
if (!dynarr_push(&proc->zones, &new_zone)) {
return NULL;
}
return (memzone_t*)dynarr_get(&proc->zones, proc->zones.size - 1);
}
return NULL;
}
memzone_t* memzone_new(proc_t* proc, size_t start, size_t len)
{
len += (start & (VMM_PAGE_SIZE - 1));
start &= ~(VMM_PAGE_SIZE - 1);
if (len % VMM_PAGE_SIZE) {
len += VMM_PAGE_SIZE - (len % VMM_PAGE_SIZE);
}
memzone_t new_zone = { 0 };
new_zone.start = start;
new_zone.len = len;
new_zone.type = 0;
new_zone.flags = ZONE_USER;
new_zone.ops = NULL;
if (_proc_can_add_zone(proc, start, len)) {
if (!dynarr_push(&proc->zones, &new_zone)) {
return NULL;
}
return (memzone_t*)dynarr_get(&proc->zones, proc->zones.size - 1);
}
return NULL;
}
/* FIXME: Think of more efficient way */
memzone_t* memzone_new_random(proc_t* proc, size_t len)
{
if (len % VMM_PAGE_SIZE) {
len += VMM_PAGE_SIZE - (len % VMM_PAGE_SIZE);
}
size_t zones_count = proc->zones.size;
/* Check if we can put it at the beginning */
memzone_t* ret = memzone_new(proc, 0, len);
if (ret) {
return ret;
}
size_t min_start = 0xffffffff;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(&proc->zones, i);
if (_proc_can_add_zone(proc, zone->start + zone->len, len)) {
if (min_start > zone->start + zone->len) {
min_start = zone->start + zone->len;
}
}
}
if (min_start == 0xffffffff) {
return NULL;
}
return memzone_new(proc, min_start, len);
}
/* FIXME: Think of more efficient way */
memzone_t* memzone_new_random_backward(proc_t* proc, size_t len)
{
if (len % VMM_PAGE_SIZE) {
len += VMM_PAGE_SIZE - (len % VMM_PAGE_SIZE);
}
size_t zones_count = proc->zones.size;
/* Check if we can put it at the end */
memzone_t* ret = memzone_new(proc, KERNEL_BASE - len, len);
if (ret) {
return ret;
}
size_t max_end = 0;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(&proc->zones, i);
if (_proc_can_add_zone(proc, zone->start - len, len)) {
if (max_end < zone->start) {
max_end = zone->start;
}
}
}
if (max_end == 0) {
return NULL;
}
return memzone_new(proc, max_end - len, len);
}
memzone_t* memzone_find_no_proc(dynamic_array_t* zones, size_t addr)
{
size_t zones_count = zones->size;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(zones, i);
if (zone->start <= addr && addr < zone->start + zone->len) {
return zone;
}
}
return NULL;
}
memzone_t* memzone_find(proc_t* proc, size_t addr)
{
return memzone_find_no_proc(&proc->zones, addr);
}
int memzone_free_no_proc(dynamic_array_t* zones, memzone_t* givzone)
{
size_t zones_count = zones->size;
for (size_t i = 0; i < zones_count; i++) {
memzone_t* zone = (memzone_t*)dynarr_get(zones, i);
if (givzone == zone) {
_proc_swap_zones(zone, dynarr_get(zones, zones_count - 1));
dynarr_pop(zones);
return 0;
}
}
return -EALREADY;
}
int memzone_free(proc_t* proc, memzone_t* givzone)
{
return memzone_free_no_proc(&proc->zones, givzone);
} |
willmexe/opuntiaOS | kernel/include/platform/generic/init.h | <gh_stars>100-1000
#ifdef __i386__
#include <platform/x86/init.h>
#elif __arm__
#include <platform/aarch32/init.h>
#endif |
willmexe/opuntiaOS | boot/aarch32/vmm/vmm.h | <reponame>willmexe/opuntiaOS
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _BOOT_VMM_VMM_H
#define _BOOT_VMM_VMM_H
#include "consts.h"
#include <libboot/types.h>
struct PACKED page_desc {
union {
struct {
unsigned int xn : 1; // Execute never. Stops execution of page.
unsigned int one : 1; // Always one for tables
unsigned int b : 1; // cacheable
unsigned int c : 1; // Cacheable
unsigned int ap1 : 2;
unsigned int tex : 3;
unsigned int ap2 : 1;
unsigned int s : 1;
unsigned int ng : 1;
unsigned int baddr : 20;
};
uint32_t data;
};
};
typedef struct page_desc page_desc_t;
struct PACKED table_desc {
union {
struct {
int valid : 1; /* Valid mapping */
int zero1 : 1;
int zero2 : 1;
int ns : 1;
int zero3 : 1;
int domain : 4;
int imp : 1;
int baddr : 22;
};
uint32_t data;
};
};
typedef struct table_desc table_desc_t;
typedef struct {
page_desc_t entities[VMM_PTE_COUNT];
} ptable_t;
typedef struct pdirectory {
table_desc_t entities[VMM_PDE_COUNT];
} pdirectory_t;
void vm_setup(size_t kernel_vaddr, size_t kernel_paddr, size_t kernel_size);
void vm_setup_secondary_cpu();
#endif // _BOOT_VMM_VMM_H |
willmexe/opuntiaOS | kernel/kernel/drivers/x86/pci.c | <reponame>willmexe/opuntiaOS
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <drivers/x86/pci.h>
// #define DEBUG_PCI
static driver_desc_t _pci_driver_info()
{
driver_desc_t pci_desc = { 0 };
pci_desc.type = DRIVER_BUS_CONTROLLER;
pci_desc.flags = DRIVER_DESC_FLAG_START;
pci_desc.system_funcs.on_start = pci_find_devices;
pci_desc.functions[DRIVER_BUS_CONTROLLER_FIND_DEVICE] = pci_find_devices;
return pci_desc;
}
static uint32_t _pci_do_read_bar(uint8_t bus, uint8_t device, uint8_t function, uint8_t bar_id)
{
uint32_t header_type = pci_read(bus, device, function, 0x0e) & 0x7f;
uint8_t max_bars = 6 - (header_type * 4);
if (bar_id >= max_bars)
return 0;
uint32_t bar_val = pci_read(bus, device, function, 0x10 + 4 * bar_id);
return bar_val;
}
static bar_t _pci_get_bar(uint8_t bus, uint8_t device, uint8_t function, uint8_t bar_id)
{
bar_t result;
uint32_t bar_val = _pci_do_read_bar(bus, device, function, bar_id);
result.type = (bar_val & 0x1) ? INPUT_OUTPUT : MEMORY_MAPPED;
if (result.type == MEMORY_MAPPED) {
} else {
result.address = (uint32_t)((bar_val >> 2) << 2);
result.prefetchable = 0;
}
return result;
}
void pci_install()
{
devman_register_driver(_pci_driver_info(), "pci86");
}
devman_register_driver_installation(pci_install);
uint32_t pci_read(uint16_t bus, uint16_t device, uint16_t function, uint32_t offset)
{
uint32_t id = (0x1 << 31)
| ((bus & 0xFF) << 16)
| ((device & 0x1F) << 11)
| ((function & 0x07) << 8)
| (offset & 0xFC);
port_dword_out(0xCF8, id);
uint32_t tmp = (uint32_t)(port_dword_in(0xCFC) >> (8 * (offset % 4)));
return tmp;
}
void pci_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t data)
{
uint32_t bus32 = bus;
uint32_t device32 = device;
uint16_t function16 = function;
uint32_t address = (1 << 31)
| (bus32 << 16)
| (device32 << 11)
| (function16 << 8)
| (offset & 0xFC);
port_dword_out(0xCF8, address);
port_dword_out(0xCFC, data);
}
char pci_has_device_functions(uint8_t bus, uint8_t device)
{
return pci_read(bus, device, 0, 0x0e) & (1 << 7);
}
static int dev_type_by_class(device_desc_t* dd)
{
switch (dd->pci.class_id) {
case 0x1:
switch (dd->pci.subclass_id) {
case 0x1:
case 0x3:
case 0x4:
return DEVICE_BUS_CONTROLLER;
default:
return DEVICE_STORAGE;
}
case 0x2:
return DEVICE_NETWORK;
case 0x3:
return DEVICE_DISPLAY;
case 0x6:
return DEVICE_BRIDGE;
default:
#ifdef DEBUG_PCI
log("PCI: DEVICE_UNKNOWN: Class %d subclass %d", dd->pci.class_id, dd->pci.subclass_id);
#endif
return DEVICE_UNKNOWN;
}
}
int pci_find_devices()
{
#ifdef DEBUG_PCI
log("PCI: scanning\n");
#endif
uint8_t bus, device, function;
for (bus = 0; bus < 8; bus++) {
for (device = 0; device < 32; device++) {
uint8_t functions_count = pci_has_device_functions(bus, device) == 0 ? 8 : 1;
for (function = 0; function < functions_count; function++) {
device_desc_t dev = pci_get_device_desriptor(bus, device, function);
if (dev.pci.vendor_id == 0x0000 || dev.pci.vendor_id == 0xffff) {
continue;
}
for (uint8_t bar_id = 0; bar_id < 6; bar_id++) {
bar_t bar = _pci_get_bar(bus, device, function, bar_id);
if (bar.address && (bar.type == INPUT_OUTPUT)) {
dev.pci.port_base = (uint32_t)bar.address;
}
}
devman_register_device(dev, dev_type_by_class(&dev));
#ifdef DEBUG_PCI
log("PCI: Vendor %x, devID %x, cl %x scl %x\n", dev.pci.vendor_id, dev.pci.device_id, dev.pci.class_id, dev.pci.subclass_id);
#endif
}
}
}
return 0;
}
device_desc_t pci_get_device_desriptor(uint8_t bus, uint8_t device, uint8_t function)
{
device_desc_t new_device = { 0 };
new_device.type = DEVICE_DESC_PCI;
new_device.pci.bus = bus;
new_device.pci.device = device;
new_device.pci.function = function;
new_device.pci.vendor_id = pci_read(bus, device, function, 0x00);
new_device.pci.device_id = pci_read(bus, device, function, 0x02);
new_device.pci.class_id = pci_read(bus, device, function, 0x0b);
new_device.pci.subclass_id = pci_read(bus, device, function, 0x0a);
new_device.pci.interface_id = pci_read(bus, device, function, 0x09);
new_device.pci.revision_id = pci_read(bus, device, function, 0x08);
new_device.pci.interrupt = pci_read(bus, device, function, 0x3c);
return new_device;
}
uint32_t pci_read_bar(device_t* dev, int bar_id)
{
return _pci_do_read_bar(dev->device_desc.pci.bus, dev->device_desc.pci.device, dev->device_desc.pci.function, bar_id);
}
|
willmexe/opuntiaOS | userland/tests/mmaptest/main.c | #include <sys/mman.h>
#include <unistd.h>
#define BUF_SIZE 512
char buf[BUF_SIZE];
void cat(int fd)
{
int n = 0;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
exit(1);
}
}
}
int main(int argc, char** argv)
{
int fd, i;
if (argc <= 1) {
cat(0);
return 0;
}
fd = open(argv[1], 0);
if (fd < 0) {
return 1;
}
mmap_params_t mp;
mp.flags = MAP_PRIVATE;
mp.fd = fd;
mp.size = 4096;
mp.prot = PROT_READ;
char* file = (char*)mmap(&mp);
if (file) {
write(1, file, 30);
}
if (close(fd) == 0) {
write(1, "s", 1);
return 1;
}
return 0;
} |
willmexe/opuntiaOS | servers/window_server/shared/MessageContent/MenuBar.h | #pragma once
#include <cstdint>
#include <libg/Color.h>
struct StatusBarStyle {
public:
enum Mode : uint32_t {
LightText = (1 << 0),
HideText = (1 << 1),
};
StatusBarStyle()
: m_flags(0)
, m_color(LG::Color::LightSystemBackground)
{
}
StatusBarStyle(uint32_t attr)
: m_flags(attr)
{
}
StatusBarStyle(Mode attr)
: m_flags(uint32_t(attr))
{
}
StatusBarStyle(uint32_t attr, const LG::Color& clr)
: m_flags(attr)
, m_color(clr)
{
}
StatusBarStyle(Mode attr, const LG::Color& clr)
: m_flags(uint32_t(attr))
, m_color(clr)
{
}
explicit StatusBarStyle(const LG::Color& clr)
: m_flags(0)
, m_color(clr)
{
}
struct StandardLightType {
};
static const StandardLightType StandardLight;
StatusBarStyle(StandardLightType)
: m_flags(0)
, m_color(LG::Color::LightSystemBackground)
{
}
struct StandardOpaqueType {
};
static const StandardOpaqueType StandardOpaque;
StatusBarStyle(StandardOpaqueType)
: m_flags(0)
, m_color(LG::Color::Opaque)
{
}
~StatusBarStyle() = default;
inline bool hide_text() const { return has_attr(Mode::HideText); }
inline bool show_text() const { return !hide_text(); }
inline bool light_text() const { return has_attr(Mode::LightText); }
inline bool dark_text() const { return !light_text(); }
inline StatusBarStyle& set_light_text()
{
set_attr(Mode::LightText);
return *this;
}
inline StatusBarStyle& set_dark_text()
{
rem_attr(Mode::LightText);
return *this;
}
inline StatusBarStyle& set_hide_text()
{
set_attr(Mode::HideText);
return *this;
}
inline StatusBarStyle& set_show_text()
{
rem_attr(Mode::HideText);
return *this;
}
inline uint32_t flags() const { return m_flags; }
inline void set_flags(uint32_t attr) { m_flags = attr; }
inline StatusBarStyle& set_mode(Mode attr)
{
m_flags = (uint32_t)attr;
return *this;
}
inline const LG::Color& color() const { return m_color; }
inline void set_color(const LG::Color& clr) { m_color = clr; }
private:
inline bool has_attr(Mode mode) const { return ((m_flags & (uint32_t)mode) == (uint32_t)mode); }
inline void set_attr(Mode mode) { m_flags |= (uint32_t)mode; }
inline void rem_attr(Mode mode) { m_flags = m_flags & (~(uint32_t)mode); }
uint32_t m_flags { 0 };
LG::Color m_color { LG::Color::LightSystemBackground };
}; |
willmexe/opuntiaOS | libs/libfoundation/include/libfoundation/ByteOrder.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
#include <cstddef>
namespace LFoundation {
class ByteOrder {
public:
template <typename T>
[[gnu::always_inline]] static inline T from_network(T value)
{
if constexpr (sizeof(T) == 8) {
return __builtin_bswap64(value);
}
if constexpr (sizeof(T) == 4) {
return __builtin_bswap32(value);
}
if constexpr (sizeof(T) == 2) {
return __builtin_bswap16(value);
}
if constexpr (sizeof(T) == 1) {
return value;
}
}
};
} // namespace LFoundation |
willmexe/opuntiaOS | kernel/kernel/syscalls/identity.c | <reponame>willmexe/opuntiaOS<gh_stars>100-1000
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/log.h>
#include <platform/generic/syscalls/params.h>
#include <syscalls/handlers.h>
#include <tasking/sched.h>
#include <tasking/tasking.h>
void sys_getpid(trapframe_t* tf)
{
return_with_val(RUNNING_THREAD->tid);
}
void sys_getuid(trapframe_t* tf)
{
return_with_val(RUNNING_THREAD->process->uid);
}
void sys_setuid(trapframe_t* tf)
{
uid_t new_uid = SYSCALL_VAR1(tf);
proc_t* proc = RUNNING_THREAD->process;
lock_acquire(&proc->lock);
if (proc->uid != new_uid && proc->euid != new_uid && !proc_is_su(proc)) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
proc->uid = new_uid;
proc->euid = new_uid;
proc->suid = new_uid;
lock_release(&proc->lock);
return_with_val(0);
}
void sys_setgid(trapframe_t* tf)
{
gid_t new_gid = SYSCALL_VAR1(tf);
proc_t* proc = RUNNING_THREAD->process;
lock_acquire(&proc->lock);
if (proc->gid != new_gid && proc->egid != new_gid && !proc_is_su(proc)) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
proc->gid = new_gid;
proc->egid = new_gid;
proc->sgid = new_gid;
lock_release(&proc->lock);
return_with_val(0);
}
void sys_setreuid(trapframe_t* tf)
{
proc_t* proc = RUNNING_THREAD->process;
uid_t new_ruid = SYSCALL_VAR1(tf);
uid_t new_euid = SYSCALL_VAR2(tf);
lock_acquire(&proc->lock);
if (new_ruid == (uid_t)-1) {
new_ruid = proc->uid;
}
if (new_euid == (uid_t)-1) {
new_euid = proc->euid;
}
if (proc->uid != new_euid && proc->euid != new_euid && proc->suid != new_euid) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
if (proc->uid != new_ruid && proc->euid != new_ruid && proc->suid != new_ruid) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
proc->uid = new_ruid;
proc->euid = new_euid;
lock_release(&proc->lock);
return_with_val(0);
}
void sys_setregid(trapframe_t* tf)
{
proc_t* proc = RUNNING_THREAD->process;
gid_t new_rgid = SYSCALL_VAR1(tf);
gid_t new_egid = SYSCALL_VAR2(tf);
lock_acquire(&proc->lock);
if (new_rgid == (gid_t)-1) {
new_rgid = proc->gid;
}
if (new_egid == (gid_t)-1) {
new_egid = proc->egid;
}
if (proc->gid != new_egid && proc->egid != new_egid && proc->sgid != new_egid) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
if (proc->gid != new_rgid && proc->egid != new_rgid && proc->sgid != new_rgid) {
lock_release(&proc->lock);
return_with_val(-EPERM);
}
proc->gid = new_rgid;
proc->egid = new_egid;
lock_release(&proc->lock);
return_with_val(0);
} |
willmexe/opuntiaOS | kernel/kernel/drivers/x86/fpu.c | <reponame>willmexe/opuntiaOS<filename>kernel/kernel/drivers/x86/fpu.c
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <drivers/x86/fpu.h>
#include <libkern/log.h>
#include <libkern/mem.h>
#include <platform/x86/idt.h>
#include <tasking/tasking.h>
static fpu_state_t fpu_state;
#define DEBUG_FPU
void fpu_setup(void)
{
uint32_t tmp;
asm volatile("mov %%cr0, %0"
: "=r"(tmp));
tmp &= ~(1 << 2);
tmp |= (1 << 1);
asm volatile("mov %0, %%cr0" ::"r"(tmp));
asm volatile("mov %%cr4, %0"
: "=r"(tmp));
tmp |= 3 << 9;
asm volatile("mov %0, %%cr4" ::"r"(tmp));
}
void fpu_handler()
{
if (!RUNNING_THREAD) {
#ifdef DEBUG_FPU
log_warn("FPU: no running thread, but handler is called");
#endif
return;
}
if (fpu_is_avail()) {
#ifdef DEBUG_FPU
log_warn("FPU: is avail, but handler is called");
#endif
return;
}
fpu_make_avail();
if (RUNNING_THREAD->tid == THIS_CPU->fpu_for_pid) {
return;
}
if (THIS_CPU->fpu_for_thread && thread_is_alive(THIS_CPU->fpu_for_thread) && THIS_CPU->fpu_for_thread->tid == THIS_CPU->fpu_for_pid) {
fpu_save(THIS_CPU->fpu_for_thread->fpu_state);
}
fpu_restore(RUNNING_THREAD->fpu_state);
THIS_CPU->fpu_for_thread = RUNNING_THREAD;
THIS_CPU->fpu_for_pid = RUNNING_THREAD->tid;
}
void fpu_init()
{
fpu_setup();
asm volatile("fninit");
asm volatile("fxsave %0"
: "=m"(fpu_state));
}
void fpu_init_state(fpu_state_t* new_fpu_state)
{
memcpy(new_fpu_state, &fpu_state, sizeof(fpu_state_t));
} |
willmexe/opuntiaOS | kernel/include/platform/generic/vmm/pf_types.h | #ifdef __i386__
#include <platform/x86/vmm/pf_types.h>
#elif __arm__
#include <platform/aarch32/vmm/pf_types.h>
#endif |
willmexe/opuntiaOS | kernel/kernel/algo/bitmap.c | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <algo/bitmap.h>
#include <libkern/bits/errno.h>
#include <libkern/platform.h>
#include <mem/kmalloc.h>
#define BITMAP_BLOCKS_PER_BYTE (8)
#define bitmap_get(bitmap, where) ((bitmap.data[where / BITMAP_BLOCKS_PER_BYTE] >> (where % BITMAP_BLOCKS_PER_BYTE)) & 1)
bitmap_t bitmap_wrap(uint8_t* data, size_t len)
{
bitmap_t bitmap;
bitmap.data = data;
bitmap.len = len;
return bitmap;
}
/* FIXME: Let user know if alloction was unsucessful */
bitmap_t bitmap_allocate(size_t len)
{
size_t alloc_len = len / BITMAP_BLOCKS_PER_BYTE;
if (len % BITMAP_BLOCKS_PER_BYTE) {
alloc_len++;
}
uint8_t* data = kmalloc(alloc_len);
return bitmap_wrap(data, len);
}
int bitmap_next_range_of_unset_bits(bitmap_t bitmap, int from, size_t min_len, int* start_of_free_chunks)
{
uint32_t* bitmap32 = (uint32_t*)bitmap.data;
// Calculating the start offset.
int start_bucket_index = from / 32;
int start_bucket_bit = from % 32;
size_t free_chunks = 0;
for (size_t bucket_index = start_bucket_index; bucket_index < bitmap.len / 32; bucket_index++) {
if (bitmap32[bucket_index] == 0xffffffff) {
// Skip over completely full bucket of size 32.
if (free_chunks >= min_len) {
return free_chunks;
}
free_chunks = 0;
start_bucket_bit = 0;
continue;
}
if (bitmap32[bucket_index] == 0x0) {
// Skip over completely empty bucket of size 32.
if (free_chunks == 0) {
*start_of_free_chunks = bucket_index * 32;
}
free_chunks += 32;
if (free_chunks >= min_len) {
return free_chunks;
}
start_bucket_bit = 0;
continue;
}
uint32_t bucket = bitmap32[bucket_index];
int viewed_bits = start_bucket_bit;
uint32_t trailing_zeroes = 0;
bucket >>= viewed_bits;
start_bucket_bit = 0;
while (viewed_bits < 32) {
if (bucket == 0) {
if (free_chunks == 0) {
*start_of_free_chunks = bucket_index * 32 + viewed_bits;
}
free_chunks += 32 - viewed_bits;
viewed_bits = 32;
} else {
trailing_zeroes = ctz32(bucket);
bucket >>= trailing_zeroes;
if (free_chunks == 0) {
*start_of_free_chunks = bucket_index * 32 + viewed_bits;
}
free_chunks += trailing_zeroes;
viewed_bits += trailing_zeroes;
if (free_chunks >= min_len) {
return free_chunks;
}
// Deleting trailing ones.
uint32_t trailing_ones = ctz32(~bucket);
bucket >>= trailing_ones;
viewed_bits += trailing_ones;
free_chunks = 0;
}
}
}
if (free_chunks < min_len) {
size_t first_trailing_bit = (bitmap.len / 32) * 32;
size_t trailing_bits = bitmap.len % 32;
for (size_t i = 0; i < trailing_bits; i++) {
if (!bitmap_get(bitmap, first_trailing_bit + i)) {
if (!free_chunks) {
*start_of_free_chunks = first_trailing_bit + i;
}
if (++free_chunks >= min_len) {
return free_chunks;
}
} else {
free_chunks = 0;
}
}
return -1;
}
return free_chunks;
}
int bitmap_find_space(bitmap_t bitmap, int req)
{
int start = 0;
int len = bitmap_next_range_of_unset_bits(bitmap, 0, req, &start);
if (len < 0) {
return -ENODATA;
}
return start;
}
int bitmap_find_space_aligned(bitmap_t bitmap, int req, int alignment)
{
int taken = 0;
int start = 0;
for (int i = 0; i < bitmap.len / 8; i++) {
if (bitmap.data[i] == 0xff) {
taken = 0;
continue;
}
for (int j = 0; j < BITMAP_BLOCKS_PER_BYTE; j++) {
if ((bitmap.data[i] >> j) & 1) {
taken = 0;
} else {
if (taken == 0) {
start = i * BITMAP_BLOCKS_PER_BYTE + j;
}
if ((start % alignment) == 0) {
taken++;
}
if (taken == req) {
return start;
}
}
}
}
return -ENODATA;
}
int bitmap_set(bitmap_t bitmap, int where)
{
if (where >= bitmap.len) {
return -EFAULT;
}
int block = where / BITMAP_BLOCKS_PER_BYTE;
int offset = where % BITMAP_BLOCKS_PER_BYTE;
bitmap.data[block] |= (1 << offset);
return 0;
}
int bitmap_unset(bitmap_t bitmap, int where)
{
if (where >= bitmap.len) {
return -EFAULT;
}
int block = where / BITMAP_BLOCKS_PER_BYTE;
int offset = where % BITMAP_BLOCKS_PER_BYTE;
bitmap.data[block] &= ~((1 << offset));
return 0;
}
int bitmap_set_range(bitmap_t bitmap, int start, int len)
{
if (start + len - 1 >= bitmap.len) {
return -EFAULT;
}
int where = start;
while (len && (where % BITMAP_BLOCKS_PER_BYTE) != 0) {
bitmap_set(bitmap, where);
where++;
len--;
}
while (len >= BITMAP_BLOCKS_PER_BYTE) {
int block = where / BITMAP_BLOCKS_PER_BYTE;
bitmap.data[block] = 0xff;
where += BITMAP_BLOCKS_PER_BYTE;
len -= BITMAP_BLOCKS_PER_BYTE;
}
while (len) {
bitmap_set(bitmap, where);
where++;
len--;
}
return 0;
}
int bitmap_unset_range(bitmap_t bitmap, int start, int len)
{
if (start + len - 1 >= bitmap.len) {
return -EFAULT;
}
int where = start;
while (len && (where % BITMAP_BLOCKS_PER_BYTE) != 0) {
bitmap_unset(bitmap, where);
where++;
len--;
}
while (len >= BITMAP_BLOCKS_PER_BYTE) {
int block = where / BITMAP_BLOCKS_PER_BYTE;
bitmap.data[block] = 0x0;
where += BITMAP_BLOCKS_PER_BYTE;
len -= BITMAP_BLOCKS_PER_BYTE;
}
while (len) {
bitmap_unset(bitmap, where);
where++;
len--;
}
return 0;
} |
willmexe/opuntiaOS | kernel/kernel/mem/vm_pspace32.c | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/lock.h>
#include <libkern/log.h>
#include <mem/kmemzone.h>
#include <mem/vm_alloc.h>
#include <mem/vmm.h>
#include <platform/generic/cpu.h>
#include <platform/generic/system.h>
#include <platform/generic/vmm/mapping_table.h>
#include <platform/generic/vmm/pf_types.h>
/**
* VM system for 32bit machines designed to support 2-level address
* translation mechanism.
* Pspace for 32bit arches is located right after the kernel and has
* all ptables at the 2nd level mapped to this area. So, the size of
* pspace is 4mb.
*
* TODO: Add detailed notes about the VM system design.
*/
static kmemzone_t pspace_zone;
ptable_t* vm_pspace_get_nth_active_ptable(size_t n)
{
return (ptable_t*)(pspace_zone.start + n * PTABLE_SIZE);
}
ptable_t* vm_pspace_get_vaddr_of_active_ptable(uintptr_t vaddr)
{
return (ptable_t*)vm_pspace_get_nth_active_ptable(VMM_OFFSET_IN_DIRECTORY(vaddr));
}
page_desc_t* vm_pspace_get_page_desc(uintptr_t vaddr)
{
ptable_t* ptable = vm_pspace_get_vaddr_of_active_ptable(vaddr);
return _vmm_ptable_lookup(ptable, vaddr);
}
/**
* The function is used to init pspace.
* Used only in the first stage of VM init.
*/
void vm_pspace_init()
{
pspace_zone = kmemzone_new(4 * MB);
if (VMM_OFFSET_IN_TABLE(pspace_zone.start) != 0) {
kpanic("WRONG PSPACE START ADDR");
}
/* The code assumes that the length of tables which cover pspace
is 4KB and that the tables are fit in a single page and are continuous. */
extern uintptr_t kernel_ptables_start_paddr;
const size_t ptables_per_page = VMM_PAGE_SIZE / PTABLE_SIZE;
uintptr_t kernel_ptabels_vaddr = pspace_zone.start + VMM_KERNEL_TABLES_START * PTABLE_SIZE;
uintptr_t kernel_ptabels_paddr = kernel_ptables_start_paddr;
for (int i = VMM_KERNEL_TABLES_START; i < VMM_TOTAL_TABLES_PER_DIRECTORY; i += ptables_per_page) {
table_desc_t* ptable_desc = _vmm_pdirectory_lookup(THIS_CPU->pdir, kernel_ptabels_vaddr);
if (!table_desc_is_present(*ptable_desc)) {
kpanic("vm_pspace_init: pspace should present");
}
ptable_t* ptable_vaddr = (ptable_t*)(kernel_ptables_start_paddr + (VMM_OFFSET_IN_DIRECTORY(kernel_ptabels_vaddr) - VMM_KERNEL_TABLES_START) * PTABLE_SIZE);
page_desc_t* page = _vmm_ptable_lookup(ptable_vaddr, kernel_ptabels_vaddr);
page_desc_set_attrs(page, PAGE_DESC_PRESENT | PAGE_DESC_WRITABLE);
page_desc_set_frame(page, kernel_ptabels_paddr);
kernel_ptabels_vaddr += VMM_PAGE_SIZE;
kernel_ptabels_paddr += VMM_PAGE_SIZE;
}
}
/**
* The function is used to generate a new pspace.
* The function returns the table of itself.
* Pspace table is one page (4KB) long, since the whole length is 4MB.
*/
void vm_pspace_gen(pdirectory_t* pdir)
{
const uintptr_t ptables_per_page = VMM_PAGE_SIZE / PTABLE_SIZE;
ptable_t* cur_ptable = vm_pspace_get_nth_active_ptable(VMM_OFFSET_IN_DIRECTORY(pspace_zone.start));
uintptr_t ptable_paddr = vm_alloc_ptables_to_cover_page();
kmemzone_t tmp_zone = kmemzone_new(VMM_PAGE_SIZE);
ptable_t* new_ptable = (ptable_t*)tmp_zone.start;
vmm_map_page_lockless((uintptr_t)new_ptable, ptable_paddr, MMU_FLAG_PERM_READ | MMU_FLAG_PERM_WRITE);
/* The code assumes that the length of tables which cover pspace
is 4KB and that the tables are fit in a single page and are continuous. */
memcpy(new_ptable, cur_ptable, VMM_PAGE_SIZE);
page_desc_t pspace_page;
page_desc_init(&pspace_page);
page_desc_set_attrs(&pspace_page, PAGE_DESC_PRESENT | PAGE_DESC_WRITABLE);
page_desc_set_frame(&pspace_page, ptable_paddr);
/* According to prev comment, we can remain overflow here, since we write to the right memory cell */
new_ptable->entities[VMM_OFFSET_IN_DIRECTORY(pspace_zone.start) / ptables_per_page] = pspace_page;
size_t table_coverage = VMM_PAGE_SIZE * VMM_TOTAL_PAGES_PER_TABLE;
uintptr_t ptable_vaddr_for = pspace_zone.start;
uintptr_t ptable_paddr_for = ptable_paddr;
for (int i = 0; i < ptables_per_page; i++, ptable_vaddr_for += table_coverage, ptable_paddr_for += PTABLE_SIZE) {
table_desc_t pspace_table;
table_desc_init(&pspace_table);
table_desc_set_attrs(&pspace_table, TABLE_DESC_PRESENT | TABLE_DESC_WRITABLE);
table_desc_set_frame(&pspace_table, ptable_paddr_for);
pdir->entities[VMM_OFFSET_IN_DIRECTORY(ptable_vaddr_for)] = pspace_table;
}
vmm_unmap_page_lockless((uintptr_t)new_ptable);
kmemzone_free(tmp_zone);
}
void vm_pspace_free(pdirectory_t* pdir)
{
table_desc_t* ptable_desc = &pdir->entities[VMM_OFFSET_IN_DIRECTORY(pspace_zone.start)];
if (!table_desc_has_attrs(*ptable_desc, TABLE_DESC_PRESENT)) {
return;
}
vm_free_ptables_to_cover_page(table_desc_get_frame(*ptable_desc));
table_desc_del_frame(ptable_desc);
}
int vm_pspace_on_ptable_mapped(uintptr_t vaddr, uintptr_t ptable_paddr, ptable_lv_t level)
{
const uintptr_t ptable_vaddr_start = PAGE_START((uintptr_t)vm_pspace_get_vaddr_of_active_ptable(vaddr));
uint32_t ptable_settings = MMU_FLAG_PERM_READ | MMU_FLAG_PERM_WRITE | MMU_FLAG_PERM_EXEC;
if (IS_USER_VADDR(vaddr)) {
ptable_settings |= MMU_FLAG_NONPRIV;
}
return vmm_map_page_lockless(ptable_vaddr_start, ptable_paddr, ptable_settings);
} |
willmexe/opuntiaOS | kernel/include/libkern/stdarg.h | #ifndef _KERNEL_LIBKERN_STDARG_H
#define _KERNEL_LIBKERN_STDARG_H
#define va_start(v, l) __builtin_va_start(v, l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v, l) __builtin_va_arg(v, l)
#endif // _KERNEL_LIBKERN_STDARG_H |
willmexe/opuntiaOS | libs/libui/include/libui/ClientDecoder.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
#include "../../../servers/window_server/shared/Connections/WSConnection.h"
#include <libfoundation/EventLoop.h>
namespace UI {
class App;
class ClientDecoder : public BaseWindowClientDecoder {
public:
ClientDecoder();
~ClientDecoder() = default;
using BaseWindowClientDecoder::handle;
virtual std::unique_ptr<Message> handle(MouseMoveMessage& msg) override;
virtual std::unique_ptr<Message> handle(MouseActionMessage& msg) override;
virtual std::unique_ptr<Message> handle(MouseLeaveMessage& msg) override;
virtual std::unique_ptr<Message> handle(MouseWheelMessage& msg) override;
virtual std::unique_ptr<Message> handle(KeyboardMessage& msg) override;
virtual std::unique_ptr<Message> handle(DisplayMessage& msg) override;
virtual std::unique_ptr<Message> handle(WindowCloseRequestMessage& msg) override;
virtual std::unique_ptr<Message> handle(ResizeMessage& msg) override;
virtual std::unique_ptr<Message> handle(MenuBarActionMessage& msg) override;
virtual std::unique_ptr<Message> handle(PopupActionMessage& msg) override;
// Notifiers
virtual std::unique_ptr<Message> handle(NotifyWindowCreateMessage& msg) override;
virtual std::unique_ptr<Message> handle(NotifyWindowStatusChangedMessage& msg) override;
virtual std::unique_ptr<Message> handle(NotifyWindowIconChangedMessage& msg) override;
virtual std::unique_ptr<Message> handle(NotifyWindowTitleChangedMessage& msg) override;
private:
LFoundation::EventLoop& m_event_loop;
};
} // namespace UI |
willmexe/opuntiaOS | kernel/kernel/syscalls/time.c | <reponame>willmexe/opuntiaOS<gh_stars>100-1000
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/log.h>
#include <platform/generic/syscalls/params.h>
#include <platform/generic/tasking/trapframe.h>
#include <syscalls/handlers.h>
#include <time/time_manager.h>
void sys_clock_gettime(trapframe_t* tf)
{
clockid_t clk_id = SYSCALL_VAR1(tf);
timespec_t* u_ts = (timespec_t*)SYSCALL_VAR2(tf);
switch (clk_id) {
case CLOCK_MONOTONIC:
u_ts->tv_sec = timeman_seconds_since_boot();
u_ts->tv_nsec = timeman_get_ticks_from_last_second() * (1000000000 / timeman_ticks_per_second());
break;
case CLOCK_REALTIME:
u_ts->tv_sec = timeman_now();
u_ts->tv_nsec = timeman_get_ticks_from_last_second() * (1000000000 / timeman_ticks_per_second());
break;
default:
return_with_val(-EINVAL);
}
return_with_val(0);
}
void sys_gettimeofday(trapframe_t* tf)
{
timeval_t* tv = (timeval_t*)SYSCALL_VAR1(tf);
timezone_t* tz = (timezone_t*)SYSCALL_VAR2(tf);
if (!tv || !tz) {
return_with_val(-EINVAL);
}
tv->tv_sec = timeman_now();
tv->tv_usec = timeman_get_ticks_from_last_second() * (1000000 / timeman_ticks_per_second());
tz->tz_dsttime = DST_NONE;
tz->tz_minuteswest = 0;
return_with_val(0);
} |
willmexe/opuntiaOS | kernel/include/drivers/generic/rtc.h | <filename>kernel/include/drivers/generic/rtc.h
#ifdef __i386__
#include <drivers/x86/rtc.h>
#elif __arm__
#include <drivers/aarch32/pl031.h>
#endif |
willmexe/opuntiaOS | libs/libc/include/bits/sys/stat.h | #ifndef _LIBC_BITS_SYS_STAT_H
#define _LIBC_BITS_SYS_STAT_H
#include <sys/types.h>
/* MODES */
#define S_IFSOCK 0xC000 /* [XSI] socket */
#define S_IFLNK 0xA000 /* [XSI] symbolic link */
#define S_IFREG 0x8000 /* [XSI] regular */
#define S_IFBLK 0x6000 /* [XSI] block special */
#define S_IFDIR 0x4000 /* [XSI] directory */
#define S_IFCHR 0x2000 /* [XSI] character special */
#define S_IFIFO 0x1000 /* [XSI] named pipe (fifo) */
#define S_ISUID 0x0800
#define S_ISGID 0x0400
#define S_ISVTX 0x0200
/* Read, write, execute/search by owner */
#define S_IRWXU 0x01c0
#define S_IRUSR 0x0100
#define S_IWUSR 0x0080
#define S_IXUSR 0x0040
/* Read, write, execute/search by group */
#define S_IRWXG 0x0038
#define S_IRGRP 0x0020
#define S_IWGRP 0x0010
#define S_IXGRP 0x0008
/* Read, write, execute/search by others */
#define S_IRWXO 0x0007
#define S_IROTH 0x0004
#define S_IWOTH 0x0002
#define S_IXOTH 0x0001
struct fstat {
uint32_t dev; /* ID of device containing file */
uint32_t ino; /* inode number */
mode_t mode; /* protection */
uint32_t nlink; /* number of hard links */
uint32_t uid; /* user ID of owner */
uint32_t gid; /* group ID of owner */
uint32_t rdev; /* device ID (if special file) */
uint32_t size; /* total size, in bytes */
uint32_t atime; /* time of last access */
uint32_t mtime; /* time of last modification */
uint32_t ctime; /* time of last status change */
};
typedef struct fstat fstat_t;
#endif // _LIBC_BITS_SYS_STAT_H |
willmexe/opuntiaOS | boot/x86/stage2/config.h | #ifndef STAGE2_CONFIG
#define STAGE2_CONFIG
#define KERNEL_PATH "/boot/kernel.bin"
#define KERNEL_BASE 0x100000
#endif // STAGE2_CONFIG |
willmexe/opuntiaOS | boot/aarch32/main.c | <gh_stars>0
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "drivers/pl181.h"
#include "drivers/uart.h"
#include "target/memmap.h"
#include "vmm/vmm.h"
#include <libboot/devtree/devtree.h>
#include <libboot/elf/elf_lite.h>
#include <libboot/fs/ext2_lite.h>
#include <libboot/log/log.h>
#include <libboot/mem/malloc.h>
#include <libboot/mem/mem.h>
// #define DEBUG_BOOT
#define KERNEL_PATH "/boot/kernel.bin"
extern void jump_to_kernel(void*);
extern uint32_t _odt_phys[];
extern uint32_t _odt_phys_end[];
static void* bootdesc_ptr;
static size_t kernel_vaddr = 0;
static size_t kernel_paddr = 0;
static size_t kernel_size = 0;
static int sync = 0;
static int alloc_init()
{
devtree_entry_t* dev = devtree_find_device("ram");
if (!dev) {
log("Can't find RAM in devtree");
while (1) { };
}
extern int bootloader_start[];
size_t alloc_space = (size_t)bootloader_start - dev->paddr;
malloc_init((void*)dev->paddr, alloc_space);
return 0;
}
static int prepare_boot_disk(drive_desc_t* drive_desc)
{
pl181_init(drive_desc);
return -1;
}
static int prepare_fs(drive_desc_t* drive_desc, fs_desc_t* fs_desc)
{
if (ext2_lite_init(drive_desc, fs_desc) == 0) {
return 0;
}
return -1;
}
static void load_kernel(drive_desc_t* drive_desc, fs_desc_t* fs_desc)
{
int res = elf_load_kernel(drive_desc, fs_desc, KERNEL_PATH, &kernel_vaddr, &kernel_paddr, &kernel_size);
kernel_size = align_size(kernel_size, VMM_PAGE_SIZE);
#ifdef DEBUG_BOOT
log("kernel %x %x %x", kernel_vaddr, kernel_paddr, kernel_size);
#endif
void* odt_ptr = paddr_to_vaddr(copy_after_kernel(kernel_paddr, devtree_start(), devtree_size(), &kernel_size, VMM_PAGE_SIZE), kernel_paddr, kernel_vaddr);
#ifdef DEBUG_BOOT
log("copying ODT %x -> %x of %d", devtree_start(), odt_ptr, devtree_size());
#endif
void* rammap_ptr = paddr_to_vaddr(copy_after_kernel(kernel_paddr, arm_memmap, sizeof(arm_memmap), &kernel_size, VMM_PAGE_SIZE), kernel_paddr, kernel_vaddr);
#ifdef DEBUG_BOOT
log("copying RAMMAP %x -> %x of %d", arm_memmap, rammap_ptr, sizeof(arm_memmap));
#endif
boot_desc_t boot_desc;
boot_desc.vaddr = kernel_vaddr;
boot_desc.paddr = kernel_paddr;
boot_desc.kernel_size = (kernel_size + align_size(sizeof(boot_desc_t), VMM_PAGE_SIZE)) / 1024;
boot_desc.devtree = odt_ptr;
boot_desc.memory_map = (void*)rammap_ptr;
boot_desc.memory_map_size = sizeof(arm_memmap) / sizeof(arm_memmap[0]);
bootdesc_ptr = paddr_to_vaddr(copy_after_kernel(kernel_paddr, &boot_desc, sizeof(boot_desc), &kernel_size, VMM_PAGE_SIZE), kernel_paddr, kernel_vaddr);
#ifdef DEBUG_BOOT
log("copying BOOTDESC %x -> %x of %d", &boot_desc, bootdesc_ptr, sizeof(boot_desc));
#endif
}
void load_boot_cpu()
{
devtree_init((void*)_odt_phys, (uint32_t)_odt_phys_end - (uint32_t)_odt_phys);
uart_init();
log_init(uart_write);
alloc_init();
drive_desc_t drive_desc;
fs_desc_t fs_desc;
prepare_boot_disk(&drive_desc);
prepare_fs(&drive_desc, &fs_desc);
load_kernel(&drive_desc, &fs_desc);
vm_setup(kernel_vaddr, kernel_paddr, kernel_size);
__atomic_store_n(&sync, 1, __ATOMIC_RELEASE);
jump_to_kernel(bootdesc_ptr);
}
void load_secondary_cpu()
{
while (__atomic_load_n(&sync, __ATOMIC_ACQUIRE) == 0) {
continue;
}
vm_setup_secondary_cpu();
jump_to_kernel(bootdesc_ptr);
} |
willmexe/opuntiaOS | libs/libc/posix/system.c | #include <string.h>
#include <sys/utsname.h>
#include <sysdep.h>
#include <unistd.h>
int uname(utsname_t* buf)
{
int res = DO_SYSCALL_1(SYS_UNAME, buf);
RETURN_WITH_ERRNO(res, 0, -1);
}
#define PATH_CONSTANT "/bin:/usr/bin"
#define PATH_CONSTANT_LEN sizeof(PATH_CONSTANT)
size_t confstr(int name, char* buf, size_t len)
{
switch (name) {
case _CS_PATH:
if (!buf || !len) {
return PATH_CONSTANT_LEN;
} else {
// Return path only if enough space.
if (len < PATH_CONSTANT_LEN) {
return 0;
}
memcpy(buf, PATH_CONSTANT, PATH_CONSTANT_LEN);
return PATH_CONSTANT_LEN;
}
default:
break;
}
return 0;
} |
willmexe/opuntiaOS | libs/libc/pthread/pthread.c | #include <pthread.h>
#include <sys/mman.h>
#include <sysdep.h>
int pthread_create(void* func)
{
uint32_t start = (uint32_t)mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_STACK | MAP_PRIVATE, 0, 0);
thread_create_params_t params;
params.stack_start = start;
params.stack_size = 4096;
params.entry_point = (uint32_t)func;
int res = DO_SYSCALL_1(SYS_PTHREAD_CREATE, ¶ms);
RETURN_WITH_ERRNO(res, 0, res);
} |
willmexe/opuntiaOS | userland/system/homescreen/HomeScreenEntity.h | <filename>userland/system/homescreen/HomeScreenEntity.h
#pragma once
#include <libg/PixelBitmap.h>
class HomeScreenEntity {
public:
HomeScreenEntity() = default;
HomeScreenEntity(int window_id)
: m_window_id(window_id)
{
}
bool operator==(const HomeScreenEntity& other) const { return m_window_id == other.m_window_id; }
bool operator!=(const HomeScreenEntity& other) const { return m_window_id != other.m_window_id; }
int window_id() const { return m_window_id; }
void set_icon(LG::PixelBitmap&& icon) { m_icon = std::move(icon); }
const LG::PixelBitmap& icon() const { return m_icon; }
private:
int m_window_id { 0 };
LG::PixelBitmap m_icon;
int m_window_status { 0 };
}; |
willmexe/opuntiaOS | libs/libc/include/sys/ptrace.h | <filename>libs/libc/include/sys/ptrace.h
#ifndef _LIBC_SYS_PTRACE_H
#define _LIBC_SYS_PTRACE_H
#include <bits/sys/ptrace.h>
#include <stddef.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
int ptrace(ptrace_request_t request, pid_t pid, void* addr, void* data);
__END_DECLS
#endif // _LIBC_SYS_PTRACE_H |
willmexe/opuntiaOS | kernel/include/platform/x86/idt.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_PLATFORM_X86_IDT_H
#define _KERNEL_PLATFORM_X86_IDT_H
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#include <platform/x86/pic.h>
#include <platform/x86/port.h>
#include <platform/x86/tasking/trapframe.h>
#define INIT_CODE_SEG 0x08
#define INIT_DATA_SEG 0x10
#define IDT_ENTRIES 0x100
#define IRQ_MASTER_OFFSET 32
#define IRQ_SLAVE_OFFSET 40
struct PACKED idt_entry { // call gate
uint16_t offset_lower;
uint16_t segment;
uint8_t zero;
uint8_t type;
uint16_t offset_upper;
};
extern struct idt_entry idt[IDT_ENTRIES];
extern void** handlers[IDT_ENTRIES];
void idt_element_setup(uint8_t n, void* handler_addr, bool user);
void interrupts_setup();
void set_irq_handler(uint8_t interrupt_no, void (*handler)());
void init_irq_handlers();
/* ISRs reserved for CPU exceptions */
extern void isr0();
extern void isr1();
extern void isr2();
extern void isr3();
extern void isr4();
extern void isr5();
extern void isr6();
extern void isr7();
extern void isr8();
extern void isr9();
extern void isr10();
extern void isr11();
extern void isr12();
extern void isr13();
extern void isr14();
extern void isr15();
extern void isr16();
extern void isr17();
extern void isr18();
extern void isr19();
extern void isr20();
extern void isr21();
extern void isr22();
extern void isr23();
extern void isr24();
extern void isr25();
extern void isr26();
extern void isr27();
extern void isr28();
extern void isr29();
extern void isr30();
extern void isr31();
/* IRQ definitions */
extern void irq0();
extern void irq1();
extern void irq2();
extern void irq3();
extern void irq4();
extern void irq5();
extern void irq6();
extern void irq7();
extern void irq8();
extern void irq9();
extern void irq10();
extern void irq11();
extern void irq12();
extern void irq13();
extern void irq14();
extern void irq15();
extern void irq_null();
extern void irq_empty_handler();
extern void syscall();
#define IRQ0 32
#define IRQ1 33
#define IRQ2 34
#define IRQ3 35
#define IRQ4 36
#define IRQ5 37
#define IRQ6 38
#define IRQ7 39
#define IRQ8 40
#define IRQ9 41
#define IRQ10 42
#define IRQ11 43
#define IRQ12 44
#define IRQ13 45
#define IRQ14 46
#define IRQ15 47
#endif // _KERNEL_PLATFORM_X86_IDT_H
|
willmexe/opuntiaOS | kernel/include/mem/kmalloc.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_MEM_KMALLOC_H
#define _KERNEL_MEM_KMALLOC_H
#include <libkern/types.h>
#include <mem/vmm.h>
#define KMALLOC_SPACE_SIZE (4 * MB)
#define KMALLOC_BLOCK_SIZE 32
void kmalloc_init();
void* kmalloc(size_t size);
void* kmalloc_aligned(size_t size, size_t alignment);
void* kmalloc_page_aligned();
void kfree(void* ptr);
void kfree_aligned(void* ptr);
void* krealloc(void* ptr, size_t size);
#endif // _KERNEL_MEM_KMALLOC_H
|
willmexe/opuntiaOS | kernel/kernel/tasking/thread.c | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <fs/vfs.h>
#include <libkern/bits/errno.h>
#include <libkern/libkern.h>
#include <libkern/log.h>
#include <mem/kmalloc.h>
#include <tasking/proc.h>
#include <tasking/sched.h>
#include <tasking/tasking.h>
#include <tasking/thread.h>
extern void trap_return();
extern void _tasking_jumper();
int _thread_setup_kstack(thread_t* thread, uintptr_t esp)
{
char* sp = (char*)(esp);
/* setting trapframe in kernel stack */
sp -= sizeof(*thread->tf);
thread->tf = (trapframe_t*)sp;
/* setting return point in kernel stack, so it
will return to this address in _tasking_jumper */
sp -= sizeof(uintptr_t);
*(uintptr_t*)sp = (uintptr_t)trap_return;
/* setting context in kernel stack */
sp -= sizeof(*thread->context);
thread->context = (context_t*)sp;
/* setting init data */
memset((void*)thread->context, 0, sizeof(*thread->context));
context_set_instruction_pointer(thread->context, (uintptr_t)_tasking_jumper);
memset((void*)thread->tf, 0, sizeof(*thread->tf));
return 0;
}
int thread_setup_main(proc_t* p, thread_t* thread)
{
/* allocating kernel stack */
thread->kstack = kmemzone_new(VMM_PAGE_SIZE);
if (!thread->kstack.start) {
return -ENOMEM;
}
thread->process = p;
thread->tid = p->pid;
thread->last_cpu = LAST_CPU_NOT_SET;
/* setting signal handlers to 0 */
thread->signals_mask = 0xffffffff; /* for now all signals are legal */
thread->pending_signals_mask = 0;
memset((void*)thread->signal_handlers, 0, sizeof(thread->signal_handlers));
_thread_setup_kstack(thread, thread->kstack.start + VMM_PAGE_SIZE);
tf_setup_as_user_thread(thread->tf);
#ifdef FPU_ENABLED
/* setting fpu */
thread->fpu_state = kmalloc_aligned(sizeof(fpu_state_t), FPU_STATE_ALIGNMENT);
fpu_init_state(thread->fpu_state);
#endif
return 0;
}
int thread_setup(proc_t* p, thread_t* thread)
{
/* allocating kernel stack */
thread->kstack = kmemzone_new(VMM_PAGE_SIZE);
if (!thread->kstack.start) {
return -ENOMEM;
}
thread->process = p;
thread->tid = proc_alloc_pid();
thread->last_cpu = LAST_CPU_NOT_SET;
/* setting signal handlers to 0 */
thread->signals_mask = 0xffffffff; /* for now all signals are legal */
thread->pending_signals_mask = 0;
memset((void*)thread->signal_handlers, 0, sizeof(thread->signal_handlers));
_thread_setup_kstack(thread, thread->kstack.start + VMM_PAGE_SIZE);
tf_setup_as_user_thread(thread->tf);
#ifdef FPU_ENABLED
/* setting fpu */
thread->fpu_state = kmalloc_aligned(sizeof(fpu_state_t), FPU_STATE_ALIGNMENT);
fpu_init_state(thread->fpu_state);
#endif
return 0;
}
int thread_copy_of(thread_t* thread, thread_t* from_thread)
{
memcpy(thread->tf, from_thread->tf, sizeof(trapframe_t));
#ifdef FPU_ENABLED
memcpy(thread->fpu_state, from_thread->fpu_state, sizeof(fpu_state_t));
#endif
return 0;
}
/**
* STACK FUNCTIONS
*/
int thread_fill_up_stack(thread_t* thread, int argc, char** argv, int envp_count, char** envp)
{
const int alignment = sizeof(uintptr_t);
size_t argv_data_size = 0;
for (int i = 0; i < argc; i++) {
argv_data_size += strlen(argv[i]) + 1;
}
if (argv_data_size % alignment) {
argv_data_size += alignment - (argv_data_size % alignment);
}
size_t envp_data_size = 0;
for (int i = 0; i < envp_count; i++) {
envp_data_size += strlen(envp[i]) + 1;
}
if (envp_data_size % alignment) {
envp_data_size += alignment - (envp_data_size % alignment);
}
const size_t envp_array_size = (envp_count + 1) * sizeof(char*);
const size_t argv_array_size = (argc + 1) * sizeof(char*);
#ifdef __i386__
const size_t pointers_size = sizeof(argc) + sizeof(char*) + sizeof(char*); // argc + pointer to argv array + pointer to envp array.
#elif __arm__
const size_t pointers_size = 0;
#endif
const size_t arrays_size = argv_array_size + envp_array_size;
const size_t data_size = argv_data_size + envp_data_size;
const size_t total_size_on_stack = data_size + arrays_size + pointers_size;
int* tmp_buf = (int*)kmalloc(total_size_on_stack);
if (!tmp_buf) {
return -EAGAIN;
}
memset((void*)tmp_buf, 0, total_size_on_stack);
// Resolve pointers from the start of stack
char* tmp_buf_ptr = ((char*)tmp_buf) + total_size_on_stack;
char* tmp_buf_envp_data_ptr = tmp_buf_ptr - envp_data_size;
uintptr_t* tmp_buf_envp_array_ptr = (uintptr_t*)((char*)tmp_buf_envp_data_ptr - envp_array_size);
char* tmp_buf_argv_data_ptr = (char*)tmp_buf_envp_array_ptr - argv_data_size;
uintptr_t* tmp_buf_argv_array_ptr = (uintptr_t*)((char*)tmp_buf_argv_data_ptr - argv_array_size);
int* tmp_buf_envp_ptr = (int*)((char*)tmp_buf_argv_array_ptr - sizeof(char*));
int* tmp_buf_argv_ptr = (int*)((char*)tmp_buf_envp_ptr - sizeof(char*));
int* tmp_buf_argc_ptr = (int*)((char*)tmp_buf_argv_ptr - sizeof(int));
uintptr_t envp_data_sp = get_stack_pointer(thread->tf) - envp_data_size;
uintptr_t envp_array_sp = envp_data_sp - envp_array_size;
uintptr_t argv_data_sp = envp_array_sp - argv_data_size;
uintptr_t argv_array_sp = argv_data_sp - argv_array_size;
#ifdef __i386__
uintptr_t envp_sp = argv_array_sp - sizeof(char*);
uintptr_t argv_sp = envp_sp - sizeof(char*);
uintptr_t argc_sp = argv_sp - sizeof(int);
uintptr_t end_sp = argc_sp;
uintptr_t copy_to_sp = end_sp;
#elif __arm__
uintptr_t end_sp = argv_array_sp;
uintptr_t copy_to_sp = end_sp;
// The alignment of sp must be 2x of the pointer size.
end_sp = end_sp & ~(uintptr_t)(alignment * 2 - 1);
#endif
// Fill argv
char* top_of_argv_data = tmp_buf_argv_data_ptr + argv_data_size;
set_stack_pointer(thread->tf, argv_data_sp + argv_data_size);
for (int i = argc - 1; i >= 0; i--) {
size_t len = strlen(argv[i]);
top_of_argv_data -= len + 1;
tf_move_stack_pointer(thread->tf, -(len + 1));
memcpy(top_of_argv_data, argv[i], len);
top_of_argv_data[len] = 0;
tmp_buf_argv_array_ptr[i] = get_stack_pointer(thread->tf);
}
tmp_buf_argv_array_ptr[argc] = 0;
// Fill envp
char* top_of_envp_data = tmp_buf_envp_data_ptr + envp_data_size;
set_stack_pointer(thread->tf, envp_data_sp + envp_data_size);
for (int i = envp_count - 1; i >= 0; i--) {
size_t len = strlen(envp[i]);
top_of_envp_data -= len + 1;
tf_move_stack_pointer(thread->tf, -(len + 1));
memcpy(top_of_envp_data, envp[i], len);
top_of_envp_data[len] = 0;
tmp_buf_envp_array_ptr[i] = get_stack_pointer(thread->tf);
}
tmp_buf_envp_array_ptr[envp_count] = 0;
#ifdef __i386__
*tmp_buf_envp_ptr = envp_array_sp;
*tmp_buf_argv_ptr = argv_array_sp;
*tmp_buf_argc_ptr = argc;
#elif __arm__
thread->tf->r[0] = argc;
thread->tf->r[1] = argv_array_sp;
thread->tf->r[2] = envp_array_sp;
#endif
set_stack_pointer(thread->tf, end_sp);
vmm_copy_to_pdir(thread->process->pdir, (uint8_t*)tmp_buf, copy_to_sp, total_size_on_stack);
kfree(tmp_buf);
return 0;
}
int thread_kstack_free(thread_t* thread)
{
kmemzone_free(thread->kstack);
#ifdef FPU_ENABLED
kfree_aligned(thread->fpu_state);
#endif
return 0;
}
int thread_free(thread_t* thread)
{
if (thread->status != THREAD_STATUS_DYING) {
return -EINVAL;
}
thread_kstack_free(thread);
thread->status = THREAD_STATUS_INVALID;
return 0;
}
int thread_die(thread_t* thread)
{
if (thread_is_freed(thread)) {
return -EINVAL;
}
thread->status = THREAD_STATUS_DYING;
sched_dequeue(thread);
return 0;
}
int thread_stop(thread_t* thread)
{
thread->status = THREAD_STATUS_STOPPED;
sched_dequeue(thread);
return 0;
}
int thread_stop_and_resched(thread_t* thread)
{
thread->status = THREAD_STATUS_STOPPED;
sched_dequeue(thread);
resched();
return 0;
}
int thread_continue(thread_t* thread)
{
thread->status = THREAD_STATUS_RUNNING;
return 0;
}
int thread_init_blocker(thread_t* thread, const blocker_t* blocker)
{
thread->status = THREAD_STATUS_BLOCKED;
thread->blocker.reason = blocker->reason;
thread->blocker.should_unblock = blocker->should_unblock;
thread->blocker.should_unblock_for_signal = blocker->should_unblock_for_signal;
sched_dequeue(thread);
return 0;
}
/**
* DEBUG FUNCTIONS
*/
int thread_dump_frame(thread_t* thread)
{
#ifdef __i386__
for (uintptr_t i = thread->tf->esp; i < thread->tf->ebp; i++) {
uint8_t byte = *(uint8_t*)i;
uintptr_t b32 = (uintptr_t)byte;
log("%x - %x\n", i, b32);
}
#endif
return 0;
} |
willmexe/opuntiaOS | boot/aarch32/vmm/consts.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _BOOT_VMM_CONSTS_H
#define _BOOT_VMM_CONSTS_H
#define VMM_PTE_COUNT (256)
#define VMM_PDE_COUNT (4096)
#define VMM_PAGE_SIZE (4096)
#define VMM_OFFSET_IN_DIRECTORY(a) (((a) >> 20) & 0xfff)
#define VMM_OFFSET_IN_TABLE(a) (((a) >> 12) & 0xff)
#define VMM_OFFSET_IN_PAGE(a) ((a)&0xfff)
#define TABLE_START(vaddr) ((vaddr >> 20) << 20)
#define PAGE_START(vaddr) ((vaddr >> 12) << 12)
#define FRAME(addr) (addr / VMM_PAGE_SIZE)
#define VMM_USER_TABLES_START 0
#define VMM_KERNEL_TABLES_START 3072
#endif //_BOOT_VMM_CONSTS_H
|
willmexe/opuntiaOS | libs/libc/include/pwd.h | #ifndef _LIBC_PWD_H
#define _LIBC_PWD_H
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
struct passwd {
char* pw_name;
char* pw_passwd;
uid_t pw_uid;
gid_t pw_gid;
char* pw_gecos;
char* pw_dir;
char* pw_shell;
};
typedef struct passwd passwd_t;
void setpwent();
void endpwent();
passwd_t* getpwent();
passwd_t* getpwuid(uid_t uid);
passwd_t* getpwnam(const char* name);
__END_DECLS
#endif // _LIBC_PWD_H |
willmexe/opuntiaOS | kernel/include/algo/dynamic_array.h | <reponame>willmexe/opuntiaOS<filename>kernel/include/algo/dynamic_array.h
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_ALGO_DYNAMIC_ARRAY_H
#define _KERNEL_ALGO_DYNAMIC_ARRAY_H
#include <libkern/types.h>
// TODO: Speed up bucket search using binary jumps.
struct dynamic_array_bucket {
void* data;
struct dynamic_array_bucket* next;
size_t capacity;
size_t size;
};
typedef struct dynamic_array_bucket dynamic_array_bucket_t;
struct dynamic_array {
dynamic_array_bucket_t* head;
dynamic_array_bucket_t* tail;
size_t size; /* number of elements in vector */
size_t element_size; /* size of elements in bytes */
};
typedef struct dynamic_array dynamic_array_t;
#define dynarr_init(type, v) dynarr_init_of_size_impl(v, sizeof(type), 8)
#define dynarr_init_of_size(type, v, cap) dynarr_init_of_size_impl(v, sizeof(type), cap)
int dynarr_init_of_size_impl(dynamic_array_t* v, size_t element_size, size_t capacity);
int dynarr_free(dynamic_array_t* v);
void* dynarr_get(dynamic_array_t* v, int index);
void* dynarr_push(dynamic_array_t* v, void* element);
int dynarr_pop(dynamic_array_t* v);
int dynarr_clear(dynamic_array_t* v);
#endif // _KERNEL_ALGO_DYNAMIC_ARRAY_H |
willmexe/opuntiaOS | boot/x86/stage2/drivers/uart.c | <gh_stars>100-1000
/*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "uart.h"
#include "port.h"
static int _uart_setup_impl(int port)
{
port_byte_out(port + 1, 0x00);
port_byte_out(port + 3, 0x80);
port_byte_out(port + 0, 0x03);
port_byte_out(port + 1, 0x00);
port_byte_out(port + 3, 0x03);
port_byte_out(port + 2, 0xC7);
port_byte_out(port + 4, 0x0B);
return 0;
}
void uart_init()
{
_uart_setup_impl(COM1);
}
static inline bool _uart_is_free_in(int port)
{
return port_byte_in(port + 5) & 0x01;
}
static inline bool _uart_is_free_out(int port)
{
return port_byte_in(port + 5) & 0x20;
}
int uart_write(uint8_t data)
{
while (!_uart_is_free_out(COM1)) { }
port_byte_out(COM1, data);
return 0;
}
|
willmexe/opuntiaOS | kernel/include/libkern/rwlock.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef _KERNEL_LIBKERN_RWLOCK_H
#define _KERNEL_LIBKERN_RWLOCK_H
#include <libkern/atomic.h>
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/lock.h>
#include <libkern/log.h>
#include <libkern/types.h>
struct rwlock {
int readers;
lock_t lock;
#ifdef DEBUG_LOCK
#endif // DEBUG_LOCK
};
typedef struct rwlock rwlock_t;
static ALWAYS_INLINE void rwlock_init(rwlock_t* rwlock)
{
}
static ALWAYS_INLINE void rwlock_r_acquire(rwlock_t* rwlock)
{
lock_acquire(&rwlock->lock);
rwlock->readers++;
lock_release(&rwlock->lock);
}
static ALWAYS_INLINE void rwlock_r_release(rwlock_t* rwlock)
{
lock_acquire(&rwlock->lock);
ASSERT(rwlock->readers >= 0);
rwlock->readers--;
lock_release(&rwlock->lock);
}
static ALWAYS_INLINE void rwlock_w_acquire(rwlock_t* rwlock)
{
for (;;) {
lock_acquire(&rwlock->lock);
if (!rwlock->readers) {
return;
}
lock_release(&rwlock->lock);
}
}
static ALWAYS_INLINE void rwlock_w_release(rwlock_t* rwlock)
{
lock_release(&rwlock->lock);
}
// #define DEBUG_LOCK
#ifdef DEBUG_LOCK
#define rwlock_r_acquire(x) \
log("acquire r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_r_acquire(x);
#define rwlock_r_release(x) \
log("release r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_r_release(x);
#define rwlock_w_acquire(x) \
log("acquire w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_w_acquire(x);
#define rwlock_w_release(x) \
log("release w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_w_release(x);
#endif
#endif // _KERNEL_LIBKERN_RWLOCK_H |
willmexe/opuntiaOS | kernel/include/platform/generic/tasking/dump_impl.h | <reponame>willmexe/opuntiaOS
#ifdef __i386__
#include <platform/x86/tasking/dump_impl.h>
#elif __arm__
#include <platform/aarch32/tasking/dump_impl.h>
#endif |
willmexe/opuntiaOS | libs/libfoundation/include/libfoundation/ProcessInfo.h | /*
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
* + Contributed by <NAME> <<EMAIL>>
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once
#include <string>
#include <unistd.h>
#include <vector>
namespace LFoundation {
class ProcessInfo {
public:
inline static ProcessInfo& the()
{
extern ProcessInfo* s_LFoundation_ProcessInfo_the;
return *s_LFoundation_ProcessInfo_the;
}
ProcessInfo(int argc, char** argv);
~ProcessInfo() = default;
std::vector<std::string>& arguments() { return m_args; }
const std::vector<std::string>& arguments() const { return m_args; }
const std::string& process_name() const { return m_process_name; }
const std::string& bundle_id() const { return m_bundle_id; }
int processor_count();
bool mobile_app_on_desktop() { return false; }
private:
// TODO: Maybe move out info file parsing to a seperate file?
void parse_info_file();
std::vector<std::string> m_args;
std::string m_process_name;
std::string m_bundle_id;
int m_processor_count { -1 };
};
} // namespace LFoundation |
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/rtosal_error.c | <filename>WD-Firmware/rtos/rtosal/rtosal_error.c
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_error.c
* @author <NAME>
* @date 13.11.2019
* @brief The file supply service to handle error notification in RTOSAL
*
*/
/**
* include files
*/
#include "rtosal_error_api.h"
#include "rtosal_macros.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
RTOSAL_SECTION void rtosalParamErrorNotification(const void *pParam, u32_t uiErrorCode);
/**
* external prototypes
*/
/**
* global variables
*/
rtosalParamErrorNotification_t fptrParamErrorNotification = rtosalParamErrorNotification;
/**
* functions
*/
/**
* default 'param error' notification function
* The user should define and register a param-notification function of his own
*
* @param pParam pointer of the invalid parameter
* @param uiErrorCode error code
*
* @return none
*/
RTOSAL_SECTION void rtosalParamErrorNotification(const void *pParam, u32_t uiErrorCode)
{
(void)pParam;
(void)uiErrorCode;
}
/**
* Register notification function for a case of param error
*
* @param fptrRtosalParamErrorNotification - pointer to a notification function
*
* @return none
*/
RTOSAL_SECTION void rtosalParamErrorNotifyFuncRegister(rtosalParamErrorNotification_t fptrRtosalParamErrorNotification)
{
fptrParamErrorNotification = fptrRtosalParamErrorNotification;
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/demo/demo_comrv_baremetal.c | <reponame>edward-jones/riscv-fw-infrastructure
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* include files
*/
#include "common_types.h"
#include "psp_macros.h"
#include "comrv_api.h"
#include "demo_platform_al.h"
#include "psp_csrs.h"
#include "demo_utils.h"
/**
* definitions
*/
#define M_DEMO_COMRV_RTOS_FENCE() M_PSP_INST_FENCE(); \
M_PSP_INST_FENCEI();
#define M_DEMO_5_NOPS() \
asm volatile ("nop"); \
asm volatile ("nop"); \
asm volatile ("nop"); \
asm volatile ("nop"); \
asm volatile ("nop");
#define M_DEMO_10_NOPS() \
M_DEMO_5_NOPS(); \
M_DEMO_5_NOPS();
#define M_DEMO_50_NOPS() \
M_DEMO_10_NOPS(); \
M_DEMO_10_NOPS(); \
M_DEMO_10_NOPS(); \
M_DEMO_10_NOPS(); \
M_DEMO_10_NOPS();
#define M_DEMO_100_NOPS() \
M_DEMO_50_NOPS() \
M_DEMO_50_NOPS()
#define M_DEMO_512B_NOPS() \
M_DEMO_100_NOPS() \
M_DEMO_100_NOPS() \
M_DEMO_50_NOPS() \
M_DEMO_5_NOPS() \
asm volatile ("nop");
#define M_DEMO_1K_NOPS() \
M_DEMO_512B_NOPS() \
M_DEMO_512B_NOPS()
#define M_OVL_DUMMY_FUNCTION(x,y) \
void _OVERLAY_ OvlTestFunc_##x##_() \
{ \
M_DEMO_50_NOPS(); \
M_DEMO_10_NOPS(); \
OvlTestFunc_##y##_(); \
M_DEMO_10_NOPS(); \
};
#define M_OVL_DUMMY_FUNCTION_LEAF(x) \
void _OVERLAY_ OvlTestFunc_##x##_() \
{ \
M_DEMO_50_NOPS(); \
M_DEMO_10_NOPS(); \
};
#define M_OVL_FUNCTIONS_GENERATOR \
M_OVL_DUMMY_FUNCTION_LEAF(11) \
M_OVL_DUMMY_FUNCTION_LEAF(12) \
M_OVL_DUMMY_FUNCTION_LEAF(13) \
M_OVL_DUMMY_FUNCTION(14,11) \
M_OVL_DUMMY_FUNCTION(15,12) \
M_OVL_DUMMY_FUNCTION(16,13)
M_OVL_DUMMY_FUNCTION_LEAF(10)
M_OVL_FUNCTIONS_GENERATOR
#define M_OVL_FUNCTIONS_CALL \
OvlTestFunc_14_(); \
OvlTestFunc_15_(); \
OvlTestFunc_16_();
#ifdef D_COMRV_FW_INSTRUMENTATION
comrvInstrumentationArgs_t g_stInstArgs;
#endif /* D_COMRV_FW_INSTRUMENTATION */
#define OVL_OverlayFunc0 _OVERLAY_
#define OVL_OverlayFunc1 _OVERLAY_
#define OVL_OverlayFunc2 _OVERLAY_
#define OVL_OverlayFunc3 _OVERLAY_
#define OVL_OverlayFunc4 _OVERLAY_
#define D_DEMO_DISABLE_LOAD 0
D_PSP_NO_INLINE void NonOverlayFunc(void);
void OVL_OverlayFunc0 OverlayFunc0(void);
void OVL_OverlayFunc1 OverlayFunc1(void);
void OVL_OverlayFunc2 OverlayFunc2(void);
void OVL_OverlayFunc4 OverlayFunc4(void);
u32_t OVL_OverlayFunc3 OverlayFunc3(u32_t uiVal1, u32_t uiVal2, u32_t uiVal3, u32_t uiVal4,
u32_t uiVal5, u32_t uiVal6, u32_t uiVal7, u32_t uiVal8,
u32_t uiVal9);
/**
* macros
*/
/**
* types
*/
typedef void (*funcPtr)(void);
/**
* local prototypes
*/
/**
* external prototypes
*/
extern void demoComrvSetErrorHandler(void* fptrAddress);
/**
* global variables
*/
funcPtr myFunc;
volatile u32_t globalCount = 0;
volatile u32_t gOverlayFunc0 = 0;
volatile u32_t gOverlayFunc1 = 0;
volatile u32_t gOverlayFunc2 = 0;
/**
* functions
*/
u32_t demoNewErrorHook(const comrvErrorArgs_t* pErrorArgs)
{
/* make sure we got the load disabled error */
if (pErrorArgs->uiErrorNum == D_COMRV_LOAD_DISABLED_ERR)
{
M_DEMO_END_PRINT();
}
/* make sure we got the invoke disabled error */
else if (pErrorArgs->uiErrorNum == D_COMRV_INVOKED_WHILE_DISABLED)
{
/* we can continue executing the demo */
return 0;
}
else
{
M_DEMO_ERR_PRINT();
}
/* we can't continue from this point */
while(1);
}
void _OVERLAY_ OvlTestFunc4K(void)
{
M_DEMO_1K_NOPS();
M_DEMO_1K_NOPS();
M_DEMO_1K_NOPS();
M_DEMO_512B_NOPS();
asm volatile ("nop");
}
/* overlay function 4 */
void OVL_OverlayFunc4 OverlayFunc4(void)
{
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
}
/* non overlay function */
D_PSP_NO_INLINE void NonOverlayFunc(void)
{
globalCount+=1;
OverlayFunc2();
globalCount+=2;
}
/* overlay function 3 - 8 args through regs + 1 through the stack*/
u32_t OVL_OverlayFunc3 OverlayFunc3(u32_t uiVal1, u32_t uiVal2, u32_t uiVal3, u32_t uiVal4,
u32_t uiVal5, u32_t uiVal6, u32_t uiVal7, u32_t uiVal8,
u32_t uiVal9)
{
/* unlock the group holding OverlayFunc2 (we need 1K for
overlay group containing OvlTestFunc_16_) */
comrvLockUnlockOverlayGroupByFunction(OverlayFunc1, D_COMRV_GROUP_STATE_UNLOCK);
/* call other overlay function to make sure args remain valid */
OvlTestFunc_10_();
return uiVal1+uiVal2+uiVal3+uiVal4+uiVal5+uiVal6+uiVal7+uiVal8+uiVal9;
}
/* overlay function 2 */
void OVL_OverlayFunc2 OverlayFunc2(void)
{
gOverlayFunc2+=3;
/* lock the group holding OverlayFunc2 */
comrvLockUnlockOverlayGroupByFunction(OverlayFunc1, D_COMRV_GROUP_STATE_LOCK);
}
/* overlay function 1 */
void OVL_OverlayFunc1 OverlayFunc1(void)
{
gOverlayFunc1+=3;
NonOverlayFunc();
gOverlayFunc1+=4;
}
/* overlay function 0 */
void OVL_OverlayFunc0 OverlayFunc0(void)
{
OverlayFunc4();
gOverlayFunc0+=1;
myFunc();
gOverlayFunc0+=2;
NonOverlayFunc();
/* check 9 args (8 will pass via regs + one additional via stack) */
gOverlayFunc0+=OverlayFunc3(1,2,3,4,5,6,7,8,9);
}
void demoStart(void)
{
comrvInitArgs_t stComrvInitArgs;
M_DEMO_START_PRINT();
/* Register interrupt vector */
pspMachineInterruptsSetVecTableAddress(&M_PSP_VECT_TABLE);
/* mark that comrv init shall load comrv tables */
stComrvInitArgs.ucCanLoadComrvTables = 1;
/* init comrv */
comrvInit(&stComrvInitArgs);
#ifdef D_COMRV_CONTROL_SUPPORT
/* register a new error handler so we can catch the next expected error */
demoComrvSetErrorHandler(demoNewErrorHook);
/* check the disable API */
comrvDisable();
/* try to call an overlay function */
OverlayFunc0();
/* enable comrv */
comrvEnable();
/* clear registered error handler - use the default */
demoComrvSetErrorHandler(NULL);
#endif /* D_COMRV_CONTROL_SUPPORT */
/* demonstrate function pointer usage */
myFunc = OverlayFunc1;
globalCount+=1;
OverlayFunc0();
globalCount+=2;
OverlayFunc4();
/* verify function calls where completed successfully */
if (globalCount != 9 || gOverlayFunc0 != 48 ||
gOverlayFunc1 != 7 || gOverlayFunc2 != 6)
{
/* loop forever */
M_DEMO_ENDLESS_LOOP();
}
/* check that the overlay group > 512B works */
M_OVL_FUNCTIONS_CALL;
/* at this point the entire cache is taken with 1 loaded group,
lets add a call to a none loaded function which will break the loaded
group */
OverlayFunc4();
/* reset comrv, keep the 'offset' and 'multi-group' tables loaded */
comrvReset(E_RESET_TYPE_LOADED_GROUPS);
/* call 4K overlay - will fill the cache */
OvlTestFunc4K();
/* load small function, following cache being full */
OvlTestFunc_14_();
#ifdef D_COMRV_LOAD_CONFIG_SUPPORT
/* note: this section must always be executed last in the demo
as it marks demo completion in the comrv error hook */
/* disable 'load' operation */
comrvConfigureLoadOperation(D_DEMO_DISABLE_LOAD);
/* Call an already loaded function while load operation is disabled
we expect the call to be valid */
OvlTestFunc_14_();
/* register a new error handler so we can catch the next expected error */
demoComrvSetErrorHandler(demoNewErrorHook);
/* now call a function that isn't loaded - this should fail and
comrv engine shall call the error handler hook function */
OverlayFunc0();
#endif /* D_COMRV_LOAD_CONFIG_SUPPORT */
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/demo/main.c | <reponame>edward-jones/riscv-fw-infrastructure
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file main.c
* @author <NAME>
* @date 23.10.2019
* @brief main C file of the demonstration application
*/
/**
* include files
*/
#include "demo_platform_al.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
extern void demoStart(void);
/**
* global variables
*/
//////////////////////////////////////////////////////////////////////
/**
* Initialize the platform and then calls the appropriate demo function
*
* @param - void
*
* @return - this function never returns
*/
//////////////////////////////////////////////////////////////////////
int main(void)
{
/* Initialize the platform first */
demoPlatformInit();
/* Now is the time to activate the relevant demonstration function */
demoStart();
/* For OS based demo: if all is well, the scheduler will now be running, and the
following line will never be reached. If the following line does execute,
then there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the FreeRTOS
web site for more details. */
/* For OSless demos getting here means the demo has completed successfully */
//write(1,"\n-- We should not reach here. Check what went wrong. --\n", 55);
for( ;; );
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/demo/demo_trap.c | <gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* include files
*/
#include "psp_api.h"
#include "demo_platform_al.h"
#include "demo_utils.h"
/**
* definitions
*/
#define D_IN_EXCEPTION_HANDLER (0)
#define D_TRAPS_TEST_RESULT (M_PSP_BIT_MASK(D_IN_EXCEPTION_HANDLER))
#define D_ILLEGAL_CSR_ADDRESS (0x7)
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
u32_t g_uiTestWayPoints = 0;
/**
* functions
*/
/**
* demoIllegalInstructionExceptionHandler - Handle exception
*
*/
void demoIllegalInstructionExceptionHandler(void)
{
u32_t uiMepc = M_PSP_READ_CSR(D_PSP_MEPC_NUM);
/* Mark that exception handler visited */
g_uiTestWayPoints |= M_PSP_BIT_MASK(D_IN_EXCEPTION_HANDLER);
/* move return address from exception one forward in order to avoid infinitely repeating exception */
M_PSP_WRITE_CSR(D_PSP_MEPC_NUM, uiMepc + 4);
}
/**
* demoIllegalInstructionExceptionHandlingTest - verify exception handled properly
*
*/
void demoIllegalInstructionExceptionHandlingTest(void)
{
/* register trap handler */
/* TODO: Replace trap handler registration with dedicated PSP API */
M_PSP_WRITE_CSR(D_PSP_MTVEC_NUM, &M_PSP_VECT_TABLE);
pspMachineInterruptsRegisterExcpHandler(demoIllegalInstructionExceptionHandler, E_EXC_ILLEGAL_INSTRUCTION);
/* create illegal instruction exception by writing to non valid CSR address */
M_PSP_WRITE_CSR(D_ILLEGAL_CSR_ADDRESS, 0);
/* verify all test way points were visited */
if(g_uiTestWayPoints != D_TRAPS_TEST_RESULT)
{
/* Test failed */
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
}
/**
* demoStart - startup point of the demo application. called from main function.
*
*/
void demoStart(void)
{
M_DEMO_START_PRINT();
/* verify proper exception handling */
demoIllegalInstructionExceptionHandlingTest();
M_DEMO_END_PRINT();
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/psp_mutex_eh2.c | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_mutex_eh2.c
* @author <NAME>
* @date 24.06.2020
* @brief The file supplies the psp mutex relevant APIs
* Relevant for SweRV-EH2 (multi-harts and atomic commands supported)
*
*/
/**
* include files
*/
#include "psp_api.h"
#include "psp_internal_mutex_eh2.h"
/**
* types
*/
/**
* definitions
*/
#define D_PSP_SIZE_OF_MUTEX_CB sizeof(pspMutexCb_t)
/* Size of mutex CB is 64bits (== 8 bytes). In order to check that an address is aligned to 8 bytes, check that low 3 bits are 0 */
#define D_PSP_ADDRESS_ALIGN_TO_SIZEOF_MUTEX_CB 0x7
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
/* Address of the mutex-heap. Allocated by the application and supplied to PSP for initialization and handling */
u32_t g_uiAppMutexsHeapAddress;
/* Number of mutexs in the mutex-heap. This number is set by the application */
u32_t g_uiAppNumberOfMutexs;
/**
* APIs
*/
/**
* @brief - Initialize (zero) mutexs that PSP is using internally for multi-harts safe activities
*
*/
D_PSP_TEXT_SECTION void pspMutexInitPspMutexs(void)
{
/* Call Internal-Mutexs module to do its initializations */
pspInternalMutexInit();
}
/* @brief - Verify the input mutex address is valid
*
* @parameter - mutex address
*
* @return - TRUE / FALSE
*/
D_PSP_TEXT_SECTION u32_t pspIsMutexAddressValid(u32_t* uiMutexAddress)
{
u32_t uiValid = D_PSP_FALSE;
/* uiMutexAddress is valid if it is inside the mutex Heap and is aligned to mutex size (8bytes) */
if ((uiMutexAddress >= (u32_t*)g_uiAppMutexsHeapAddress) &&
(uiMutexAddress < (u32_t*)(g_uiAppMutexsHeapAddress + g_uiAppNumberOfMutexs*D_PSP_SIZE_OF_MUTEX_CB)) &&
(0 == (D_PSP_ADDRESS_ALIGN_TO_SIZEOF_MUTEX_CB & (u32_t)uiMutexAddress)))
{
uiValid = D_PSP_TRUE;
}
return (uiValid);
}
/**
* @brief - Initialize (zero) heap of mutexs.
*
* @parameter - Address of the mutexs heap
* @parameter - Number of mutexs in the heap
*
*/
D_PSP_TEXT_SECTION void pspMutexHeapInit(pspMutexCb_t* pMutexHeapAddress, u32_t uiNumOfmutexs)
{
/* Assert if address is NULL or number of mutexs is 0 */
M_PSP_ASSERT((NULL != pMutexHeapAddress) && (0 != uiNumOfmutexs)) ;
/* Protect the mutex-heap initialization. Make sure it cannot be done simultaneously by multiple harts */
pspInternalMutexLock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
/* Initialize (== zero) the mutexs heap */
pspMemsetBytes(pMutexHeapAddress, 0, uiNumOfmutexs * D_PSP_SIZE_OF_MUTEX_CB);
/* Save the information - address of mutexs heap and number of mutexs */
g_uiAppMutexsHeapAddress = (u32_t)pMutexHeapAddress;
g_uiAppNumberOfMutexs = uiNumOfmutexs;
/* Remove the protection */
pspInternalMutexUnlock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
}
/**
* @brief - Create a mutex in the mutexs-heap.
* - Search for an available mutex in the heap
* - Mark it as 'occupied'
* - Mark the hart that created it
*
* @return - Address of the created mutex. In case of failure return NULL.
*/
D_PSP_TEXT_SECTION pspMutexCb_t* pspMutexCreate(void)
{
u32_t uiMutexIndex; /* Index used for scanning */
pspMutexCb_t* pRetMutex = NULL; /* Returned pointer to the created mutex */
pspMutexCb_t* pMutex = (pspMutexCb_t*)g_uiAppMutexsHeapAddress; /* Pointer to a mutex control block */
u32_t uiHartId = M_PSP_MACHINE_GET_HART_ID();
/* Protect the creation of a mutex. Make sure the creation cannot be done simultaneously by multiple harts */
pspInternalMutexLock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
/* Search for an unoccupied mutex in the mutexs heap */
for(uiMutexIndex = 0; uiMutexIndex < g_uiAppNumberOfMutexs; uiMutexIndex++)
{
if(D_PSP_MUTEX_UNOCCUIPED == pMutex->uiMutexOccupied)
{
/* Set the address of the found mutex, to be returned */
pRetMutex = pMutex;
/* Mark the mutex as 'occupied' */
pMutex->uiMutexOccupied = D_PSP_MUTEX_OCCUIPED;
/* Mark the hart that created the mutex */
pMutex->uiMutexCreator = uiHartId;
/* Make sure to mark the mutex as 'unlocked' */
pMutex->uiMutexState = D_PSP_MUTEX_UNLOCKED;
/* mutex is found, break out of the loop*/
break;
}
}
/* Remove the protection */
pspInternalMutexUnlock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
/* Return the address of the mutex. NULL == there's no available mutex in the mutexs-heap */
return (pRetMutex);
}
/**
* @brief - Destroy (remove the 'occupied' mark) a mutex in the mutexs-heap
*
* @parameter - Address of the mutex to be destroyed
*
* @return - In case of success - return NULL. In case of failure - return the given mutex address.
*/
D_PSP_TEXT_SECTION pspMutexCb_t* pspMutexDestroy(pspMutexCb_t* pMutex)
{
pspMutexCb_t* pRetMutexAddr; /* Pointer to a mutex. Used for return value */
u32_t uiHartId = M_PSP_MACHINE_GET_HART_ID();
/* Verify mutex address validity*/
M_PSP_ASSERT(D_PSP_TRUE == pspIsMutexAddressValid(pMutex));
/* Protect the mutex destroy. Make sure the destroy cannot be done simultaneously by multiple harts */
pspInternalMutexLock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
/* Only the hart that created this mutex can also destroy it */
if (uiHartId == pMutex->uiMutexCreator)
{
pMutex->uiMutexOccupied = D_PSP_MUTEX_UNOCCUIPED; /* mark the mutex as 'unoccupied' */
pMutex->uiMutexCreator = 0; /* clean the 'creator' field */
pMutex->uiMutexState = D_PSP_MUTEX_UNLOCKED; /* set the mutex state to 'free' */
pRetMutexAddr = NULL; /* returned NULL indicates success to destroy the mutex */
}
else
{
/* Failure. The hart that request to destroy the mutex is not the one that created it. Return the given mutex address to specify that it is still alive */
pRetMutexAddr = pMutex;
}
/* Remove the protection */
pspInternalMutexUnlock(E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG);
return (pRetMutexAddr);
}
/**
* @brief - Lock a mutex using atomic commands.
*
* @parameter - pointer to the mutex to lock
*
*/
D_PSP_TEXT_SECTION void pspMutexAtomicLock(pspMutexCb_t* pMutex)
{
/* Verify mutex address validity*/
M_PSP_ASSERT(D_PSP_TRUE == pspIsMutexAddressValid(pMutex));
/* Lock the mutex */
M_PSP_ATOMIC_ENTER_CRITICAL_SECTION(&(pMutex->uiMutexState));
}
/**
* @brief - Free a mutex using atomic commands.
*
* @parameter - pointer to the mutex to free
*
*/
D_PSP_TEXT_SECTION void pspMutexAtomicUnlock(pspMutexCb_t* pMutex)
{
/* Verify mutex address validity*/
M_PSP_ASSERT(D_PSP_TRUE == pspIsMutexAddressValid(pMutex));
/* Unlock the mutex */
M_PSP_ATOMIC_EXIT_CRITICAL_SECTION(&(pMutex->uiMutexState));
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/api_inc/psp_pragmas.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_pragmas.h
* @author <NAME>
* @date 11/2019
* @brief The file defines the psp pragmas
*/
#ifndef __PSP_PRAGMAS_H__
#define __PSP_PRAGMAS_H__
#if defined (__GNUC__) || defined (__clang__)
#define DO_PRAGMA(_PRAGMA_NAME_) _Pragma(#_PRAGMA_NAME_)
#define TODO(_MY_MSG_) DO_PRAGMA(message ("TODO - " #_MY_MSG_))
#define PRE_COMPILED_MSG(_MY_MSG_) DO_PRAGMA(message (#_MY_MSG_))
#else
#error "Currently, GCC and LLVM are the only supported compilers."
#endif // defined __GNUC__ || defined __clang__
#endif /* __PSP_MACRO_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/board/nexys_a7_el2/bsp/bsp_external_interrupts.c | <filename>WD-Firmware/board/nexys_a7_el2/bsp/bsp_external_interrupts.c<gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file bsp_external_interrupts.c
* @author <NAME>
* @date 29.03.2020
* @brief External_interrupts creation in Nexys_A7 SweRVolf FPGA
*/
/**
* include files
*/
#include "psp_api.h"
#include "bsp_external_interrupts.h"
/**
* definitions
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* Initialize the register that used for triggering IRQs generation
*
* @param uiExtInterruptPolarity - indicates the polarity mode. Based on that, the triggering register should be initialized.
*
*/
void bspInitializeGenerationRegister(u32_t uiExtInterruptPolarity)
{
u08_t ucRegisterClear;
/* For Active-High the initial value of uiRegisterClear is 0 */
if (D_PSP_EXT_INT_ACTIVE_HIGH == uiExtInterruptPolarity)
{
ucRegisterClear = 0;
}
else /*(D_PSP_EXT_INT_ACTIVE_LOW == uiExtInterruptPolarity) */
{
ucRegisterClear = 0x22; /* 00100010 */
}
M_PSP_WRITE_REGISTER_8(D_BSP_EXT_INTS_GENERATION_REGISTER, ucRegisterClear);
/* Sync the output. Make sure not to progress until the write to external register is done */
M_PSP_INST_FENCEI();
}
/**
* For IRQ3 or IRQ4 on the SweRVolf FPGA board, set polarity, type(i.e.edge/level) and triggering the interrupt
*
* @param - uiExtInterruptNumber - D_BSP_IRQ_3 or D_BSP_IRQ_4
* @param - uiExtInterruptPolarity - Active High / Low
* @param - uiExtInterruptType - Edge (pulse of 1 clock cycle) / Level (change level)
*/
void bspGenerateExtInterrupt(u32_t uiExtInterruptNumber, u32_t uiExtInterruptPolarity, u32_t uiExtInterruptType)
{
u08_t ucExtInterruptBitMap = 0;
if (D_BSP_IRQ_3 == uiExtInterruptNumber)
{
if (D_PSP_EXT_INT_ACTIVE_LOW == uiExtInterruptPolarity)
{
ucExtInterruptBitMap |= (1 << D_BSP_IRQ3_POLARITY_BIT); /* bit#1: 1 = Active Low, 0 = Active High */
}
if (D_PSP_EXT_INT_EDGE_TRIG_TYPE == uiExtInterruptType)
{
ucExtInterruptBitMap |= (1 << D_BSP_IRQ3_TYPE_BIT); /* bit#2: 1 = Edge, 0 = Level */
}
ucExtInterruptBitMap |= (1 << D_BSP_IRQ3_ACTIVATE_BIT); /* Set the trigger bit */
}
else if (D_BSP_IRQ_4 == uiExtInterruptNumber)
{
if (D_PSP_EXT_INT_ACTIVE_LOW == uiExtInterruptPolarity)
{
ucExtInterruptBitMap |= (1 << D_BSP_IRQ4_POLARITY_BIT); /* bit#5: 1 = Active Low, 0 = Active High */
}
if (D_PSP_EXT_INT_EDGE_TRIG_TYPE == uiExtInterruptType)
{
ucExtInterruptBitMap |= (1 << D_BSP_IRQ4_TYPE_BIT); /* bit#6: 1 = Edge, 0 = Level */
}
ucExtInterruptBitMap |= (1 << D_BSP_IRQ4_ACTIVATE_BIT); /* Set the trigger bit */
}
M_PSP_WRITE_REGISTER_8(D_BSP_EXT_INTS_GENERATION_REGISTER, ucExtInterruptBitMap);
/* Sync the output. Make sure not to progress until the write to external register is done */
M_PSP_INST_FENCEI();
}
/**
* Clear the trigger that generate external interrupt
*
* @param - uiExtInterruptNumber - D_BSP_IRQ_3 or D_BSP_IRQ_4
*
*/
void bspClearExtInterrupt(u32_t uiExtInterruptNumber)
{
u08_t ucExtInterruptBitMap = M_PSP_READ_REGISTER_8(D_BSP_EXT_INTS_GENERATION_REGISTER);
if (D_BSP_IRQ_3 == uiExtInterruptNumber)
{
ucExtInterruptBitMap &= ~(1 << D_BSP_IRQ3_ACTIVATE_BIT);
}
else if (D_BSP_IRQ_4 == uiExtInterruptNumber)
{
ucExtInterruptBitMap &= ~(1 << D_BSP_IRQ4_ACTIVATE_BIT);
}
M_PSP_WRITE_REGISTER_8(D_BSP_EXT_INTS_GENERATION_REGISTER, ucExtInterruptBitMap );
/* Sync the output. Make sure not to progress until the write to external register is done */
M_PSP_INST_FENCEI();
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/rtosal_queue.c | <gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_queue.c
* @author <NAME>
* @date 21.01.2019
* @brief The file implements the RTOS AL queue API
*
*/
/**
* include files
*/
#include "psp_api.h"
#include "common_defines.h"
#include "rtosal_queue_api.h"
#include "rtosal_macros.h"
#include "rtosal_util.h"
#include "rtosal_interrupt_api.h"
#include "rtosal_task_api.h"
#ifdef D_USE_FREERTOS
#include "queue.h"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
u32_t msgQueueSend(rtosalMsgQueue_t* pRtosalMsgQueueCb,
const void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks,
u32_t uiSendToFront);
/**
* external prototypes
*/
/**
* global variables
*/
/**
* Create a message queue
*
* @param pRtosalMsgQueueCb - Pointer to queue control block to be created
* @param pRtosMsgQueueBuffer - Pointer to the queue buffer (its size must be
* uiRtosMsgQueueSize * uiRtosMsgQueueItemSize)
* @param uiRtosMsgQueueSize - Maximum number of items ( queue deep )
* @param uiRtosMsgQueueItemSize - Queue message-item size in bytes
* @param pRtosalMsgQueueName - String of the queue name (for debugging)
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_QUEUE_ERROR - The pRtosalMsgQueueCb is invalid or been used
* - D_RTOSAL_PTR_ERROR - Invalid pRtosMsgQueueBuffer
* - D_RTOSAL_SIZE_ERROR - Invalid uiRtosMsgQueueSize
* - D_RTOSAL_CALLER_ERROR - The caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalMsgQueueCreate(rtosalMsgQueue_t* pRtosalMsgQueueCb, void* pRtosMsgQueueBuffer,
u32_t uiRtosMsgQueueSize, u32_t uiRtosMsgQueueItemSize,
s08_t* pRtosalMsgQueueName)
{
u32_t uiRes;
void* pQueueCB;
// Todo: we can only allow message size of min 4bytes . we need to reutrn error otherwise
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueCb, pRtosalMsgQueueCb == NULL, D_RTOSAL_QUEUE_ERROR);
#ifdef D_USE_FREERTOS
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosMsgQueueBuffer, pRtosMsgQueueBuffer == NULL, D_RTOSAL_PTR_ERROR);
/* create the queue */
pQueueCB = xQueueCreateStatic(uiRtosMsgQueueSize, uiRtosMsgQueueItemSize,
(uint8_t*)pRtosMsgQueueBuffer,
(StaticQueue_t*)pRtosalMsgQueueCb->cMsgQueueCB);
/* queue created successfully */
if (pRtosalMsgQueueCb->cMsgQueueCB == pQueueCB)
{
/* assign a name to the created queue */
vQueueAddToRegistry((void*)pRtosalMsgQueueCb->cMsgQueueCB, (const char*)pRtosalMsgQueueName);
uiRes = D_RTOSAL_SUCCESS;
}
else
{
uiRes = D_RTOSAL_QUEUE_ERROR;
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
// for thread, on uiRtosMsgQueueItemSize we need to translate bytes to numerical values: 1-16 where each idx is 32bit word
// and on uiRtosMsgQueueSize we need to trans to bytes
//uiRes = add a call to ThreadX queue create API
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Destroy a queue
*
* @param pRtosalMsgQueueCb - pointer to queue control block to be destroyed
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_QUEUE_ERROR - the ptr, MsgQueueCB, in the pRtosalMsgQueueCb is invalid
* - D_RTOSAL_CALLER_ERROR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalMsgQueueDestroy(rtosalMsgQueue_t* pRtosalMsgQueueCb)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueCb, pRtosalMsgQueueCb == NULL, D_RTOSAL_QUEUE_ERROR);
#ifdef D_USE_FREERTOS
vQueueDelete((void*)pRtosalMsgQueueCb->cMsgQueueCB);
uiRes = D_RTOSAL_SUCCESS;
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Add an item to the queue front/back
*
* @param pRtosalMsgQueueCb - Pointer to queue control block to add the item to
* @param pRtosalMsgQueueItem - Pointer to a memory containing the item to add (to be copy)
* @param uiWaitTimeoutTicks - In case queue is full, how many ticks to wait until
* the queue can accommodate a new item:
* D_RTOSAL_NO_WAIT, D_RTOSAL_WAIT_FOREVER or timer ticks value
* @param uiSendToFront - D_RTOSAL_TRUE:
* D_RTOSAL_FALSE:
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_DELETED - The message queue was already deleted when this api was called
* - D_RTOSAL_QUEUE_FULL - Queue is full for the provided window time
* - D_RTOSAL_WAIT_ABORTED - aborted by different consumer (like other thread)
* - D_RTOSAL_QUEUE_ERROR - the ptr, MsgQueueCB, in the pRtosalMsgQueueCb is invalid
* - D_RTOSAL_PTR_ERROR - invalid pRtosalMsgQueueItem
* - D_RTOSAL_WAIT_ERROR - invalide uiWaitTimeoutTicks: if caller is not a thread it
* must use "NO WAIT"
*/
RTOSAL_SECTION u32_t rtosalMsgQueueSend(rtosalMsgQueue_t* pRtosalMsgQueueCb, const void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks, u32_t uiSendToFront)
{
return msgQueueSend(pRtosalMsgQueueCb, pRtosalMsgQueueItem,
uiWaitTimeoutTicks, uiSendToFront);
}
#ifdef D_USE_FREERTOS
u32_t msgQueueSend(rtosalMsgQueue_t* pRtosalMsgQueueCb, const void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks, u32_t uiSendToFront)
{
u32_t uiRes;
/* specify if a context switch is needed as a uiResult calling FreeRTOS ...ISR function */
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueCb, pRtosalMsgQueueCb == NULL, D_RTOSAL_QUEUE_ERROR);
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueItem, pRtosalMsgQueueItem == NULL, D_RTOSAL_PTR_ERROR);
/* check if message should be sent to the queue front */
if (uiSendToFront == D_RTOSAL_TRUE)
{
/* msgQueueSend invoked from an ISR context */
if (rtosalIsInterruptContext() == D_RTOSAL_INT_CONTEXT)
{
/* send the queue message */
uiRes = xQueueSendToFrontFromISR((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueItem, &xHigherPriorityTaskWoken);
}
else
{
uiRes = xQueueSendToFront((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueItem, uiWaitTimeoutTicks);
}
}
/* send message to the queue back */
else
{
/* msgQueueSend invoked from an ISR context */
if (rtosalIsInterruptContext() == D_RTOSAL_INT_CONTEXT)
{
uiRes = xQueueSendToBackFromISR((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueItem, &xHigherPriorityTaskWoken);
}
else
{
uiRes = xQueueSendToBack((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueItem, uiWaitTimeoutTicks);
}
} /* if (uiSendToFront == D_RTOSAL_TRUE) */
/* queue was full */
if (uiRes == errQUEUE_FULL)
{
/* The message could not be sent */
uiRes = D_RTOSAL_QUEUE_FULL;
}
else
{
uiRes = D_RTOSAL_SUCCESS;
}
/* due to the message send we got an indicating that a context
switch should be requested before the interrupt exits */
if (uiRes == D_RTOSAL_SUCCESS && xHigherPriorityTaskWoken == pdTRUE)
{
rtosalContextSwitchIndicationSet();
}
return uiRes;
}
#elif D_USE_THREADX
u32_t msgQueueSend(rtosalMsgQueue_t* pRtosalMsgQueueCb, void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks, u32_t uiSendToFront)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueCb, pRtosalMsgQueueCb == NULL, D_RTOSAL_QUEUE_ERROR);
/* check if message should be sent to the queue front */
if (uiSendToFront == D_RTOSAL_TRUE)
{
// TODO:
//uiRes = add a call to ThreadX queue add front
}
else
{
// TODO:
//uiRes = add a call to ThreadX queue add back
}
return uiRes;
}
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* Retrieve an item from the queue.
*
* @param pRtosalMsgQueueCb - Pointer to queue control block to get the item from
* @param pRtosalMsgQueueDstBuf - Pointer to a memory destination for which the item shall be copied to
* @param uiWaitTimeoutTicks - in case queue is empty, how many ticks to wait until
* the queue becomes non-empty.
* Provide: D_RTOSAL_NO_WAIT, D_RTOSAL_WAIT_FOREVER or timer ticks value
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_DELETED - The message queue was already deleted when this api was called
* - D_RTOSAL_QUEUE_EMPTY - The queue is empty for the giving window time
* - D_RTOSAL_WAIT_ABORTED - aborted by different consumer (like other thread)
* - D_RTOSAL_QUEUE_ERROR - The ptr, MsgQueueCB, in the pRtosalMsgQueueCb is invalid
* - D_RTOSAL_PTR_ERROR - invalid pRtosalMsgQueueItem
* - D_RTOSAL_WAIT_ERROR - invalide uiWaitTimeoutTicks: if caller is not thread he
* must used "NO WAIT"
*/
u32_t rtosalMsgQueueRecieve(rtosalMsgQueue_t* pRtosalMsgQueueCb, void* pRtosalMsgQueueDstBuf,
u32_t uiWaitTimeoutTicks)
{
u32_t uiRes;
#ifdef D_USE_FREERTOS
/* specify if a context switch is needed as a uiResult calling FreeRTOS ...ISR function */
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueCb, pRtosalMsgQueueCb == NULL, D_RTOSAL_QUEUE_ERROR);
#ifdef D_USE_FREERTOS
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMsgQueueDstBuf, pRtosalMsgQueueDstBuf == NULL, D_RTOSAL_PTR_ERROR);
/* rtosalMsgQueueRecieve invoked from an ISR context */
if (rtosalIsInterruptContext() == D_RTOSAL_INT_CONTEXT)
{
uiRes = xQueueReceiveFromISR((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueDstBuf, &xHigherPriorityTaskWoken);
}
else
{
uiRes = xQueueReceive((void*)pRtosalMsgQueueCb->cMsgQueueCB, pRtosalMsgQueueDstBuf, uiWaitTimeoutTicks);
}
/* message sent successfully */
if (uiRes == pdPASS)
{
uiRes = D_RTOSAL_SUCCESS;
}
else
{
/* queue is empty */
uiRes = D_RTOSAL_QUEUE_EMPTY;
}
/* due to the message send we got an indicating that a context
switch should be requested before the interrupt exits */
if (uiRes == D_RTOSAL_SUCCESS && xHigherPriorityTaskWoken == pdTRUE)
{
rtosalContextSwitchIndicationSet();
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/demo/demo_cti.c | <reponame>edward-jones/riscv-fw-infrastructure
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* include files
*/
#include "common_types.h"
#include "demo_platform_al.h"
#include "demo_utils.h"
#include "cti_api.h"
#include "comrv_api.h"
#include "psp_api.h"
/**
* definitions
*/
#define M_DEMO_COMRV_RTOS_FENCE() M_PSP_INST_FENCE(); \
M_PSP_INST_FENCEI();
/**
* macros
*/
/**
* types
*/
typedef u32_t (*DemoExternalErrorHook_t)(const comrvErrorArgs_t* pErrorArgs);
/**
* local prototypes
*/
/**
* external prototypes
*/
extern void* _OVERLAY_STORAGE_START_ADDRESS_;
extern u32_t xcrc32(const u08_t *pBuf, s32_t siLen, u32_t uiInit);
/**
* global variables
*/
DemoExternalErrorHook_t fptrDemoExternalErrorHook = NULL;
/**
* functions
*/
void demoStart(void)
{
comrvInitArgs_t stComrvInitArgs;
stComrvInitArgs.ucCanLoadComrvTables = 1;
M_DEMO_START_PRINT();
/* Register interrupt vector */
pspMachineInterruptsSetVecTableAddress(&M_PSP_VECT_TABLE);
/* Init ComRV engine */
comrvInit(&stComrvInitArgs);
/* run the tests */
ctiMain();
M_DEMO_END_PRINT();
}
/**
* memory copy hook
*
* @param none
*
* @return none
*/
void comrvMemcpyHook(void* pDest, void* pSrc, u32_t uiSizeInBytes)
{
u32_t loopCount = uiSizeInBytes/(sizeof(u32_t)), i;
/* copy dwords */
for (i = 0; i < loopCount ; i++)
{
*((u32_t*)pDest + i) = *((u32_t*)pSrc + i);
}
loopCount = uiSizeInBytes - (loopCount*(sizeof(u32_t)));
/* copy bytes */
for (i = (i-1)*(sizeof(u32_t)) ; i < loopCount ; i++)
{
*((u08_t*)pDest + i) = *((u08_t*)pSrc + i);
}
}
/**
* load overlay group hook
*
* @param pLoadArgs - refer to comrvLoadArgs_t for exact args
*
* @return loaded address or NULL if unable to load
*/
void* comrvLoadOvlayGroupHook(comrvLoadArgs_t* pLoadArgs)
{
g_stCtiOvlFuncsHitCounter.uiComrvLoad++;
comrvMemcpyHook(pLoadArgs->pDest, (u08_t*)&_OVERLAY_STORAGE_START_ADDRESS_ + pLoadArgs->uiGroupOffset, pLoadArgs->uiSizeInBytes);
/* it is upto the end user of comrv to synchronize the instruction and data stream after
overlay data has been written to destination memory */
M_DEMO_COMRV_RTOS_FENCE();
return pLoadArgs->pDest;
}
/**
* set a function pointer to be called by comrvErrorHook
*
* @param pErrorArgs - pointer to error arguments
*
* @return none
*/
void demoComrvSetErrorHandler(void* fptrAddress)
{
fptrDemoExternalErrorHook = fptrAddress;
}
/**
* error hook
*
* @param pErrorArgs - pointer to error arguments
*
* @return none
*/
void comrvErrorHook(const comrvErrorArgs_t* pErrorArgs)
{
comrvStatus_t stComrvStatus;
comrvGetStatus(&stComrvStatus);
/* if external error handler was set e.g. cti */
if (fptrDemoExternalErrorHook == NULL)
{
/* we can't continue so loop forever */
M_DEMO_ERR_PRINT();
M_DEMO_ENDLESS_LOOP();
}
else
{
fptrDemoExternalErrorHook(pErrorArgs);
}
}
/**
* Invalidate data cache hook
*
* @param pAddress - memory address to invalidate
* uiNumSizeInBytes - number of bytes to invalidate
*
* @return none
*/
void comrvInvalidateDataCacheHook(const void* pAddress, u32_t uiNumSizeInBytes)
{
(void)pAddress;
(void)uiNumSizeInBytes;
}
/**
* crc calculation hook
*
* @param pAddress - memory address to calculate
* memSizeInBytes - number of bytes to calculate
* uiExpectedResult - expected crc result
*
* @return calculated CRC
*/
#ifdef D_COMRV_ENABLE_CRC_SUPPORT
u32_t comrvCrcCalcHook(const void* pAddress, u16_t usMemSizeInBytes, u32_t uiExpectedResult)
{
volatile u32_t uiCrc;
uiCrc = xcrc32(pAddress, usMemSizeInBytes, 0xffffffff);
return !(uiExpectedResult == uiCrc);
}
#endif /* D_COMRV_ENABLE_CRC_SUPPORT */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/psp_cache_control_eh1.c | <reponame>edward-jones/riscv-fw-infrastructure
/*
* Copyright (c) 2010-2016 Western Digital, Inc.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_cache_control_eh1.c
* @author <NAME>
* @date 05.07.2020
* @brief Cache control services for SweRV EH1
*/
/**
* include files
*/
#include "psp_api.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/* @brief - Enable I-Cache for a given memory-id
*
* @parameter - memory Id
*/
D_PSP_TEXT_SECTION void pspMachineCacheControlEnableIcache(u32_t uiMemoryRegionId)
{
M_PSP_ASSERT(D_CACHE_CONTROL_MAX_NUMBER_OF_REGIONS > uiMemoryRegionId);
M_PSP_SET_CSR(D_PSP_MRAC_NUM, M_PSP_CACHE_CONTROL_ICACHE_VAL(uiMemoryRegionId));
}
/**
* @brief - Enable side-effect for a given memory-id
*
* @parameter - memory Id
*/
D_PSP_TEXT_SECTION void pspMachineCacheControlEnableSideEfect(u32_t uiMemoryRegionId)
{
M_PSP_ASSERT(D_CACHE_CONTROL_MAX_NUMBER_OF_REGIONS > uiMemoryRegionId);
M_PSP_SET_CSR(D_PSP_MRAC_NUM, M_PSP_CACHE_CONTROL_SIDEEFFECT_VAL(uiMemoryRegionId));
}
/* @brief - Disable I-Cache for a given memory-id
*
* @parameter - memory Id
*/
D_PSP_TEXT_SECTION void pspMachineCacheControlDisableIcache(u32_t uiMemoryRegionId)
{
M_PSP_ASSERT(D_CACHE_CONTROL_MAX_NUMBER_OF_REGIONS > uiMemoryRegionId);
M_PSP_CLEAR_CSR(D_PSP_MRAC_NUM, M_PSP_CACHE_CONTROL_ICACHE_VAL(uiMemoryRegionId));
}
/**
* @brief - Disable side-effect for a given memory-id
*
* @parameter - memory Id
*/
D_PSP_TEXT_SECTION void pspMachineCacheControlDisableSideEfect(u32_t uiMemoryRegionId)
{
M_PSP_ASSERT(D_CACHE_CONTROL_MAX_NUMBER_OF_REGIONS > uiMemoryRegionId);
M_PSP_CLEAR_CSR(D_PSP_MRAC_NUM, M_PSP_CACHE_CONTROL_SIDEEFFECT_VAL(uiMemoryRegionId));
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/api_inc/rtosal_error_api.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_error_api.h
* @author <NAME>
* @date 13.11.2019
* @brief The file supply service to handle error notification in RTOSAL
*/
#ifndef __RTOSAL_ERROR_API_H__
#define __RTOSAL_ERROR_API_H__
/**
* include files
*/
#include "common_types.h"
#include "rtosal_config.h"
#include "rtosal_defines.h"
#include "rtosal_types.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/* param error notification function */
typedef void (*rtosalParamErrorNotification_t)(const void *pParam, u32_t uiErrorCode);
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* Set param error notification function
*/
//void rtosalParamErrorNotifyFuncSet(rtosalParamErrorNotification_t fptrRtosalParamErrorNotification);
/**
* Register notification function for a case of param error
*
* @param fptrRtosalParamErrorNotification - pointer to a notification function
*
* @return none
*/
void rtosalParamErrorNotifyFuncRegister(rtosalParamErrorNotification_t fptrRtosalParamErrorNotification);
#endif /* __RTOSAL_ERROR_API_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/config/hifive1/FreeRTOSConfig.h | <gh_stars>10-100
/*
FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
***************************************************************************
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
***************************************************************************
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available on the following
link: http://www.freertos.org/a00114.html
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that is more than just the market leader, it *
* is the industry's de facto standard. *
* *
* Help yourself get started quickly while simultaneously helping *
* to support the FreeRTOS project by purchasing a FreeRTOS *
* tutorial book, reference manual, or both: *
* http://www.FreeRTOS.org/Documentation *
* *
***************************************************************************
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
the FAQ page "My application does not run, what could be wrong?". Have you
defined configASSERT()?
http://www.FreeRTOS.org/support - In return for receiving this top quality
embedded software for free we request you assist our global community by
participating in the support forum.
http://www.FreeRTOS.org/training - Investing in training allows your team to
be as productive as possible as early as possible. Now you can receive
FreeRTOS training directly from <NAME>, CEO of Real Time Engineers
Ltd, and the world's leading authority on the world's leading RTOS.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and commercial middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include "platform.h"
/*
* For some reason the standard demo timer demo/test tasks fail when executing
* in QEMU, although they pass on other RISC-V platforms. This requires
* further investigation, but for now, defining _WINDOWS_ has the effect of
* using the wider timer test thresholds that are normally only used when the
* tests are used with the FreeRTOS Windows port (which is not deterministic
* and therefore requires wider margins).
*/
#define _WINDOWS_
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configCLINT_BASE_ADDRESS CLINT_CTRL_ADDR
#define configUSE_PREEMPTION 1
#define configCPU_CLOCK_HZ 265000000
#ifdef D_CLOCK_RATE
#define configRTC_CLOCK_HZ D_CLOCK_RATE /* If the clock rate is already defined, take it here */
#else
#define configRTC_CLOCK_HZ 32768
#endif
#ifdef D_TICK_TIME_MS /* If D_TICK_TIME_MS is already defined, use it to calculate configTICK_RATE_HZ */
#define configTICK_RATE_HZ 1000/D_TICK_TIME_MS
#else
#define configTICK_RATE_HZ 250
#endif
#define configMAX_PRIORITIES 3
#define configMINIMAL_STACK_SIZE 450 /* [NR] To-do check why in new config it is set to 2*70 */
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 1
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
/* Memory allocation related definitions. */
#ifndef configSUPPORT_STATIC_ALLOCATION
#define configSUPPORT_STATIC_ALLOCATION 1
#endif
#ifndef configSUPPORT_DYNAMIC_ALLOCATION
#define configSUPPORT_DYNAMIC_ALLOCATION 0
#endif
#define configTOTAL_HEAP_SIZE 11*1024
#define configAPPLICATION_ALLOCATED_HEAP 0
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#define configUSE_UPDATE_STACK_PRIOR_CONTEXT_SWITCH 1
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xTaskResumeFromISR 1
#define INCLUDE_vTaskCleanUpResources 1
/* Define to trap errors during development. */
#define configASSERT( x ) if( ( x ) == 0 ) {taskDISABLE_INTERRUPTS(); for( ;; );}
#endif /* FREERTOS_CONFIG_H */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/api_inc/rtosal_queue_api.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_queue_api.h
* @author <NAME>
* @date 07.02.2019
* @brief The file defines the RTOS AL queue interfaces
*/
#ifndef __RTOSAL_QUEUE_API_H__
#define __RTOSAL_QUEUE_API_H__
/**
* include files
*/
#include "rtosal_config.h"
#include "rtosal_defines.h"
#include "rtosal_types.h"
/**
* definitions
*/
/**
* macros
*/
#ifdef D_USE_FREERTOS
#define M_MSG_QUEUE_CB_SIZE_IN_BYTES sizeof(StaticQueue_t)
#elif D_USE_THREADX
#define M_MSG_QUEUE_CB_SIZE_IN_BYTES sizeof(TBD) // size of the CB struct
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* types
*/
/* message queue */
typedef struct rtosalMsgQueue
{
s08_t cMsgQueueCB[M_MSG_QUEUE_CB_SIZE_IN_BYTES];
} rtosalMsgQueue_t;
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* Create a message queue
*/
u32_t rtosalMsgQueueCreate(rtosalMsgQueue_t* pRtosalMsgQueueCb, void* pRtosMsgQueueBuffer,
u32_t uiRtosMsgQueueSize, u32_t uiRtosMsgQueueItemSize,
s08_t* pRtosalMsgQueueName);
/**
* Destroy a queue
*/
u32_t rtosalMsgQueueDestroy(rtosalMsgQueue_t* pRtosalMsgQueueCb);
/**
* Add an item to the queue front/back
*/
u32_t rtosalMsgQueueSend(rtosalMsgQueue_t* pRtosalMsgQueueCb, const void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks, u32_t uiSendToFront);
/**
* Retrieve an item from the queue. The message to retrieve shall be copied to a
* user provided buffer and shall be deleted from the message queue
*/
u32_t rtosalMsgQueueRecieve(rtosalMsgQueue_t* pRtosalMsgQueueCb, void* pRtosalMsgQueueItem,
u32_t uiWaitTimeoutTicks);
#endif /* __RTOSAL_QUEUE_API_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/api_inc/rtosal_interrupt_api.h | <gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_interrupt_api.h
* @author <NAME>
* @date 07.02.2019
* @brief The file defines the RTOS AL interrupt interfaces
*/
#ifndef __RTOSAL_INTERRUPT_API_H__
#define __RTOSAL_INTERRUPT_API_H__
/**
* include files
*/
#include "rtosal_config.h"
#include "rtosal_defines.h"
#include "rtosal_types.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/* */
typedef enum rtosalInterruptCause
{
userSoftwareInterrupt = 0,
} rtosalInterruptCause_t;
/* interrupt handler definition */
typedef void (*rtosalInterruptHandler_t)(void);
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* The function installs an interrupt service routine per risc-v cuase
*
* @param fptrRtosalInterruptHandler β function pointer to the interrupt
* service routine
* @param uiInterruptId β interrupt ID number
* @param uiInterruptPriority β interrupt priority
* @param stCauseIndex β value of the mcuase register this
* interrupt is assigned to
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_CALLER_ERROR
*/
u32_t rtosalInstallIsr(rtosalInterruptHandler_t fptrRtosalInterruptHandler,
u32_t uiInterruptId , u32_t uiInterruptPriority,
rtosalInterruptCause_t stCauseIndex);
/**
* @brief check if in ISR context
*
* @param None
*
* @return u32_t - D_NON_INT_CONTEXT
* - non zero value - interrupt context
*/
u32_t rtosalIsInterruptContext(void);
#endif /* __RTOSAL_INTERRUPT_API_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/demo/demo_bit_manipulation.c |
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file demo_bit_manipulation.c
* @author <NAME>
* @date 23.07.2020
* @brief Demo application for Bit-Manipulation operations for EH2 and EL2
*/
/**
* include files
*/
#include "psp_api.h"
#include "demo_platform_al.h"
#include "demo_utils.h"
/**
* definitions
*/
#define D_DEMO_FFS_INPUT_NUM 0x02F4B203 /* 0000 0010 1111 0100 1011 0010 0000 0011*/
#define D_DEMO_FFS_EXPECTED_RESULT (31 - 6) /* 25 i.e. 31 - clz(D_DEMO_FFS_INPUT_NUM) */
/*----------------------------------*/
#define D_DEMO_FLS_INPUT_NUM 0x05681A00 /* 0000 0101 0110 1000 0001 1010 0000 0000 */
#define D_DEMO_FLS_EXPECTED_RESULT (31 - 9) /* 22 i.e. 31 - ctz(D_DEMO_FLS_INPUT_NUM) */
/*----------------------------------*/
#define D_DEMO_FFS_FLS_UNSUPPORTED_VALUE 0 /* FFS and FLS does not support input = 0 */
#define D_DEMO_FFS_FLS_RESULT_FOR_UNSUPPORTED_VALUE -1 /* In this case, the returned value is -1 */
/*----------------------------------*/
#define D_DEMO_CLZ_INPUT_NUM 0x0007B79F /* 0000 0000 0000 0111 1011 0111 1001 1111 */
#define D_DEMO_CLZ_EXPECTED_RESULT 13 /* number of zeros until 1'st '1' at the most significant side of the number */
/*----------------------------------*/
#define D_DEMO_CTZ_INPUT_NUM 0x6FA89020 /* 0110 1111 1010 1000 1001 0000 0010 0000 */
#define D_DEMO_CTZ_EXPECTED_RESULT 5 /* number of zeros until 1'st '1' at the least significant side of the number */
/*----------------------------------*/
#define D_DEMO_PCNT_INPUT_NUM 0x6FA89020 /* 0110 1111 1010 1000 1001 0000 0010 0000 */
#define D_DEMO_PCNT_EXPECTED_RESULT 12 /* number of zeros in the number */
/*----------------------------------*/
#define D_DEMO_ANDN_1ST_ARG 0xFF07B5AC /* 1111 1111 0000 0111 1011 0101 1010 1100 */
#define D_DEMO_ANDN_2ND_ARG 0x89B3E6CF /* 1000 1001 1011 0011 1110 0110 1100 1111 */
#define D_DEMO_ANDN_EXPECTED_RESULT 0x76041120 /* bitwise AND between 1'st number and 2'nd inverted number */
/*----------------------------------*/
#define D_DEMO_ORN_1ST_ARG 0xFF07B5AC /* 1111 1111 0000 0111 1011 0101 1010 1100 */
#define D_DEMO_ORN_2ND_ARG 0x89B3E6CF /* 1000 1001 1011 0011 1110 0110 1100 1111 */
#define D_DEMO_ORN_EXPECTED_RESULT 0xFF4FBDBC /* bitwise OR between 1'st number and 2'nd inverted number */
/*----------------------------------*/
#define D_DEMO_XNOR_1ST_ARG 0xFF07B5AC /* 1111 1111 0000 0111 1011 0101 1010 1100 */
#define D_DEMO_XNOR_2ND_ARG 0x89B3E6CF /* 1000 1001 1011 0011 1110 0110 1100 1111 */
#define D_DEMO_XNOR_EXPECTED_RESULT 0x894BAC9C /* bitwise XOR between 1'st number and 2'nd inverted number */
/*----------------------------------*/
#define D_DEMO_MIN_1ST_ARG 0x8000FFAB /* when treated as signed integer, this number = -65444 */
#define D_DEMO_MIN_2ND_ARG 0x0FFF0B65 /* when treated as signed integer, this number = 268372837 */
#define D_DEMO_MIN_EXPECTED_RESULT 0x8000FFAB /* when treated as signed integer, -65444 is the minimum */
/*----------------------------------*/
#define D_DEMO_MAX_1ST_ARG 0x8000FFAB /* when treated as signed integer, this number = -65444 */
#define D_DEMO_MAX_2ND_ARG 0x0FFF0B65 /* when treated as signed integer, this number = 268372837 */
#define D_DEMO_MAX_EXPECTED_RESULT 0x0FFF0B65 /* when treated as signed integer, 268372837 is the maximum */
/*----------------------------------*/
#define D_DEMO_MINU_1ST_ARG 0x8000FFAB /* when treated as unsigned integer, this number = 2147549099 */
#define D_DEMO_MINU_2ND_ARG 0x0FFF0B65 /* when treated as unsigned integer, this number = 268372837 */
#define D_DEMO_MINU_EXPECTED_RESULT 0x0FFF0B65 /* when treated as unsigned integer, 268372837 is the minimum */
/*----------------------------------*/
#define D_DEMO_MAXU_1ST_ARG 0x8000FFAB /* when treated as unsigned integer, this number = 2147549099 */
#define D_DEMO_MAXU_2ND_ARG 0x0FFF0B65 /* when treated as unsigned integer, this number = 268372837 */
#define D_DEMO_MAXU_EXPECTED_RESULT 0x8000FFAB /* when treated as unsigned integer, 2147549099 is the maximum */
/*----------------------------------*/
#if 0 /* Currently we do not have an example for inpuuut & output for sextb and sexth operations */
#define D_DEMO_SEXTB_INPUT_NUM 0
#define D_DEMO_SEXTB_EXPECTED_RESULT 0
/*----------------------------------*/
#define D_DEMO_SEXTH_INPUT_NUM 0
#define D_DEMO_SEXTH_EXPECTED_RESULT 0
#endif
/*----------------------------------*/
#define D_DEMO_PACK_1ST_ARG 0x12345678
#define D_DEMO_PACK_2ND_ARG 0x90ABCDEF
#define D_DEMO_PACK_EXPECTED_RESULT 0xCDEF5678 /* pack lower halves of 1'st and 2'nd arguments. 1'st argument half in the least significant part */
/*----------------------------------*/
#define D_DEMO_PACKU_1ST_ARG 0x12345678
#define D_DEMO_PACKU_2ND_ARG 0x90ABCDEF
#define D_DEMO_PACKU_EXPECTED_RESULT 0x90AB1234 /* pack upper halves of 1'st and 2'nd arguments. 1'st argument half in the least significant part */
/*----------------------------------*/
#define D_DEMO_PACKH_1ST_ARG 0x12345678
#define D_DEMO_PACKH_2ND_ARG 0x90ABCDEF
#define D_DEMO_PACKH_EXPECTED_RESULT 0x0000EF78 /* pack least significant bytes of 1'st and 2'nd arguments in least significant 16 bits of result argument. zero the rest */
/*----------------------------------*/
#define D_DEMO_ROTATEL_1ST_ARG 0x05670FB1
#define D_DEMO_NUM_OF_LEFT_ROTATIONS 8
#define D_DEMO_ROTATEL_EXPECTED_RESULT 0x670FB105 /* rotate-left the argument bits while shift in the bits from the opposite side, in order */
/*----------------------------------*/
#define D_DEMO_ROTATER_1ST_ARG 0x0000FFFB
#define D_DEMO_NUM_OF_RIGHT_ROTATIONS 4
#define D_DEMO_ROTATER_EXPECTED_RESULT 0xB0000FFF /* rotate-right the argument bits while shift in the bits from the opposite side, in order */
/*----------------------------------*/
#define D_DEMO_REVERSE_INPUT_NUM 0xB00A8561 /* 10110000000010101000010101100001 - reverse the bits in this 32bits argument (i.e. swap bits 0-31, 1-30, 2-29 etc.) */
#define D_DEMO_REVERSE_EXPECTED_RESULT 0x86A1500D /* 10000110101000010101000000001101 - result of the reverse */
/*----------------------------------*/
#define D_DEMO_REVERSE_8_INPUT_NUM 0xA6B23D25 /* swap the bytes in every word in this 32bit argument */
#define D_DEMO_REVERSE_8_EXPECTED_RESULT 0x253DB2A6 /* result of the swap */
/*----------------------------------*/
#define D_DEMO_ORCB_INPUT_NUM 0 /* */ /* [Nati to do] complete with inputs and expected results for orc.b and orc.16 operations */
#define D_DEMO_ORCB_EXPECTED_RESULT 0 /* result of the orcb */
/*----------------------------------*/
#define D_DEMO_ORC_16_INPUT_NUM 0 /* */
#define D_DEMO_ORC_16_EXPECTED_RESULT 0 /* result of the orc16 */
/*----------------------------------*/
#define D_DEMO_SBSET_1ST_ARG 0xF101010F /* 11110001000000010000000100001111 */
#define D_DEMO_SBSET_BIT_POSITION 10 /* Set bit #10 */
#define D_DEMO_SBSET_EXPECTED_RESULT 0xF101050F /* 11110001000000010000010100001111 */
/*----------------------------------*/
#define D_DEMO_SBCLR_1ST_ARG 0xDC3CFFFF /* 11011100001111001111111111111111 */
#define D_DEMO_SBCLR_BIT_POSITION 20 /* Clear bit #20 */
#define D_DEMO_SBCLR_EXPECTED_RESULT 0xDC2CFFFF /* 11011100001011001111111111111111 */
/*----------------------------------*/
#define D_DEMO_SBINVERT_1ST_ARG 0x44F03500 /* 01000100111100000011010100000000 */
#define D_DEMO_SBINVERT_BIT_POSITION 0 /* Invert bit #0 */
#define D_DEMO_SBINVERT_EXPECTED_RESULT 0x44F03501 /* 01000100111100000011010100000001 */
/*----------------------------------*/
#define D_DEMO_SBEXTRACT_1ST_ARG 0xF09F4CD2 /* 11110000100111110100110011010010 */
#define D_DEMO_SBEXTRACT_BIT_POSITION 25 /* Extract bit #25 */
#define D_DEMO_SBEXTRACT_EXPECTED_RESULT 0
/*----------------------------------*/
#define D_DEMO_CLMUL_RS1 0xf2ab12dc
#define D_DEMO_CLMUL_RS2 0xfb34ef12
#define D_DEMO_CLMUL_CLMUL_RESULT 0x10bf7c78
#define D_DEMO_CLMUL_CLMULH_RESULT 0x5210d09d
#define D_DEMO_CLMUL_CLMULR_RESULT 0xa421a13a
/*----------------------------------*/
#define D_DEMO_SH1ADD_RS1 0x00AB12DC
#define D_DEMO_SH1ADD_RS2 0x0034EF12
#define D_DEMO_SH1ADD_RESULT 0xe914f100
#define D_DEMO_SH2ADD_RS1 0x00AB12DC
#define D_DEMO_SH2ADD_RS2 0x0034EF12
#define D_DEMO_SH2ADD_RESULT 0xdf7ecf24
#define D_DEMO_SH3ADD_RS1 0x00AB12DC
#define D_DEMO_SH3ADD_RS2 0x0034EF12
#define D_DEMO_SH3ADD_RESULT 0xcc528b6c
/*----------------------------------*/
#define D_DEMO_ZEXTH_RS 0x12345678
#define D_DEMO_ZEXTH_RESULT 0x00005678
/*----------------------------------*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
void demoBitManipulation(void)
{
u32_t uiResult;
/* Find First Set */
M_PSP_BITMANIP_FFS(D_DEMO_FFS_INPUT_NUM, uiResult);
if (D_DEMO_FFS_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* Find First Set - with 0 as input: expect to get -1 */
M_PSP_BITMANIP_FFS(D_DEMO_FFS_FLS_UNSUPPORTED_VALUE, uiResult);
if (D_DEMO_FFS_FLS_RESULT_FOR_UNSUPPORTED_VALUE != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* Find Last Set */
M_PSP_BITMANIP_FLS(D_DEMO_FLS_INPUT_NUM, uiResult);
if (D_DEMO_FLS_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* Find Last Set - with 0 as input: expect to get -1 */
M_PSP_BITMANIP_FLS(D_DEMO_FFS_FLS_UNSUPPORTED_VALUE, uiResult);
if (D_DEMO_FFS_FLS_RESULT_FOR_UNSUPPORTED_VALUE != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* clz - count leading zeros */
M_PSP_BITMANIP_CLZ(D_DEMO_CLZ_INPUT_NUM, uiResult);
if (D_DEMO_CLZ_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* ctz - count trailing zeros */
M_PSP_BITMANIP_CTZ(D_DEMO_CTZ_INPUT_NUM, uiResult);
if (D_DEMO_CTZ_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* pcnt - count bit set */
M_PSP_BITMANIP_PCNT(D_DEMO_PCNT_INPUT_NUM, uiResult);
if (D_DEMO_PCNT_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* min - minimum of 2 signed numbers */
M_PSP_BITMANIP_MIN(D_DEMO_MIN_1ST_ARG, D_DEMO_MIN_2ND_ARG, uiResult);
if (D_DEMO_MIN_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* max - maximum of 2 signed numbers */
M_PSP_BITMANIP_MAX(D_DEMO_MAX_1ST_ARG, D_DEMO_MAX_2ND_ARG, uiResult);
if (D_DEMO_MAX_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* minu - min of 2 unsigned numbers */
M_PSP_BITMANIP_MINU(D_DEMO_MINU_1ST_ARG, D_DEMO_MINU_2ND_ARG, uiResult);
if (D_DEMO_MINU_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* maxu - maximum of 2 unsigned numbers */
M_PSP_BITMANIP_MAXU(D_DEMO_MAXU_1ST_ARG, D_DEMO_MAXU_2ND_ARG, uiResult);
if (D_DEMO_MAXU_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
#if 0 /* Currently we do not have an example for input & output for sextb and sexth operations */
/* sextb - sign-extend byte */
M_PSP_BITMANIP_SEXTB(D_DEMO_SEXTB_INPUT_NUM, uiResult);
if (D_DEMO_SEXTB_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sexth - sign-extend half-word */
M_PSP_BITMANIP_SEXTH(D_DEMO_SEXTH_INPUT_NUM, uiResult);
if (D_DEMO_SEXTH_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
#endif
/* reverse8 - swap chars in each word */
M_PSP_BITMANIP_REV8(D_DEMO_REVERSE_8_INPUT_NUM, uiResult);
if (D_DEMO_REVERSE_8_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* orc.b */
M_PSP_BITMANIP_ORCB(D_DEMO_ORCB_INPUT_NUM, uiResult);
if (D_DEMO_ORCB_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbset - single-bit set */
M_PSP_BITMANIP_SBSET(D_DEMO_SBSET_1ST_ARG, D_DEMO_SBSET_BIT_POSITION, uiResult);
if (D_DEMO_SBSET_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbseti - single-bit set (with immediate) */
M_PSP_BITMANIP_SBSETI(D_DEMO_SBSET_1ST_ARG, D_DEMO_SBSET_BIT_POSITION, uiResult);
if (D_DEMO_SBSET_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbclr - single bit clear */
M_PSP_BITMANIP_SBCLR(D_DEMO_SBCLR_1ST_ARG, D_DEMO_SBCLR_BIT_POSITION, uiResult);
if (D_DEMO_SBCLR_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbclri - single bit clear (witj immediate) */
M_PSP_BITMANIP_SBCLRI(D_DEMO_SBCLR_1ST_ARG, D_DEMO_SBCLR_BIT_POSITION, uiResult);
if (D_DEMO_SBCLR_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbinvert - single bit invert */
M_PSP_BITMANIP_SBINV(D_DEMO_SBINVERT_1ST_ARG, D_DEMO_SBINVERT_BIT_POSITION, uiResult);
if (D_DEMO_SBINVERT_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbinverti - single bit invert (with immediate) */
M_PSP_BITMANIP_SBINVI(D_DEMO_SBINVERT_1ST_ARG, D_DEMO_SBINVERT_BIT_POSITION, uiResult);
if (D_DEMO_SBINVERT_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbextract - single bit extract */
M_PSP_BITMANIP_SBEXT(D_DEMO_SBEXTRACT_1ST_ARG, D_DEMO_SBEXTRACT_BIT_POSITION, uiResult);
if (D_DEMO_SBEXTRACT_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sbextracti - single bit extract (with immediate) */
M_PSP_BITMANIP_SBEXTI(D_DEMO_SBEXTRACT_1ST_ARG, D_DEMO_SBEXTRACT_BIT_POSITION, uiResult);
if (D_DEMO_SBEXTRACT_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* clmul - carry-less multiplication (lower half) */
M_PSP_BITMANIP_CLMUL(D_DEMO_CLMUL_RS1, D_DEMO_CLMUL_RS2, uiResult);
if (D_DEMO_CLMUL_CLMUL_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* clmulh - carry-less multiplication (upper half) */
M_PSP_BITMANIP_CLMULH(D_DEMO_CLMUL_RS1, D_DEMO_CLMUL_RS2, uiResult);
if (D_DEMO_CLMUL_CLMULH_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* clmulr - Carry-less multiply (reversed) */
M_PSP_BITMANIP_CLMULR(D_DEMO_CLMUL_RS1, D_DEMO_CLMUL_RS2, uiResult);
if (D_DEMO_CLMUL_CLMULR_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* zexth - Zero-extend halfword*/
M_PSP_BITMANIP_ZEXTH(D_DEMO_ZEXTH_RS, uiResult);
if (D_DEMO_ZEXTH_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
#ifdef D_PSP_BITMANIP_ZBP
/* andN - 'and' with negate argument */
M_PSP_BITMANIP_ANDN(D_DEMO_ANDN_1ST_ARG, D_DEMO_ANDN_2ND_ARG, uiResult);
if (D_DEMO_ANDN_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* orN - 'or' with negate argument */
M_PSP_BITMANIP_ORN(D_DEMO_ORN_1ST_ARG, D_DEMO_ORN_2ND_ARG, uiResult);
if (D_DEMO_ORN_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* xNor - 'xor' with negate argument */
M_PSP_BITMANIP_XNOR(D_DEMO_XNOR_1ST_ARG, D_DEMO_XNOR_2ND_ARG, uiResult);
if (D_DEMO_XNOR_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* pack - pack 2 lower halves of 2 arguments */
M_PSP_BITMANIP_PACK(D_DEMO_PACK_1ST_ARG, D_DEMO_PACK_2ND_ARG, uiResult);
if (D_DEMO_PACK_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* packu - pack 2 upper halves of 2 arguments */
M_PSP_BITMANIP_PACKU(D_DEMO_PACKU_1ST_ARG, D_DEMO_PACKU_2ND_ARG, uiResult);
if (D_DEMO_PACKU_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* packh - pack 2 LSB bytes of 2 arguments */
M_PSP_BITMANIP_PACKH(D_DEMO_PACKH_1ST_ARG, D_DEMO_PACKH_2ND_ARG, uiResult);
if (D_DEMO_PACKH_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* rotate left */
M_PSP_BITMANIP_ROL(D_DEMO_ROTATEL_1ST_ARG, D_DEMO_NUM_OF_LEFT_ROTATIONS,uiResult);
if (D_DEMO_ROTATEL_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* rotate right */
M_PSP_BITMANIP_ROR(D_DEMO_ROTATER_1ST_ARG, D_DEMO_NUM_OF_RIGHT_ROTATIONS,uiResult);
if (D_DEMO_ROTATER_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* rotate right immediate */
M_PSP_BITMANIP_RORI(D_DEMO_ROTATER_1ST_ARG, D_DEMO_NUM_OF_RIGHT_ROTATIONS,uiResult);
if (D_DEMO_ROTATER_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* reverse - reverse all 32 bits */
M_PSP_BITMANIP_REV(D_DEMO_REVERSE_INPUT_NUM, uiResult);
if (D_DEMO_REVERSE_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* orc.16 */
M_PSP_BITMANIP_ORC16(D_DEMO_ORC_16_INPUT_NUM, uiResult);
if (D_DEMO_ORC_16_EXPECTED_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
#endif /* D_PSP_BITMANIP_ZBP */
/* The current version of the compiler does not support Zba-extension
* instructions */
#ifdef D_PSP_BITMANIP_ZBA
/* sh1add- Shift left by 1 and add */
M_PSP_BITMANIP_SH1ADD(D_DEMO_SH1ADD_RS1, D_DEMO_SH1ADD_RS2, uiResult);
if (D_DEMO_SH1ADD_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sh2add- Shift left by 2 and add */
M_PSP_BITMANIP_SH2ADD(D_DEMO_SH2ADD_RS1, D_DEMO_SH2ADD_RS2, uiResult);
if (D_DEMO_SH2ADD_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
/* sh3add- Shift left by 3 and add */
M_PSP_BITMANIP_SH3ADD(D_DEMO_SH3ADD_RS1, D_DEMO_SH3ADD_RS2, uiResult);
if (D_DEMO_SH3ADD_RESULT != uiResult)
{
M_DEMO_ERR_PRINT();
M_PSP_EBREAK();
}
#endif /* D_PSP_BITMANIP_ZBA */
}
/**
* @brief - demoStart - startup point of the demo application. called from main function.
*
*/
void demoStart(void)
{
M_DEMO_START_PRINT();
/* Register interrupt vector */
pspMachineInterruptsSetVecTableAddress(&M_PSP_VECT_TABLE);
/* Run this demo only if target is Whisper. Cannot run on SweRV */
if (D_PSP_FALSE == demoIsSwervBoard())
{
/* Bit-manipulation demo function */
demoBitManipulation();
}
else
{
/* SweRV */
printfNexys("This demo is currently not supported in SweRV FPGA Board");
}
M_DEMO_END_PRINT();
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/api_inc/rtosal_defines.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_defines.h
* @author <NAME>
* @date 21.01.2019
* @brief The defines rtos-al private interfaces
*
*/
#ifndef __RTOSAL_DEFINES_H__
#define __RTOSAL_DEFINES_H__
/**
* include files
*/
/**
* definitions
*/
/* function return codes */
#ifdef D_USE_FREERTOS
#define D_RTOSAL_SUCCESS 0x00
#define D_RTOSAL_DELETED 0x01
#define D_RTOSAL_NO_MEMORY 0x02
#define D_RTOSAL_POOL_ERROR 0x03
#define D_RTOSAL_PTR_ERROR 0x04
#define D_RTOSAL_WAIT_ERROR 0x05
#define D_RTOSAL_SIZE_ERROR 0x06
#define D_RTOSAL_GROUP_ERROR 0x07
#define D_RTOSAL_NO_EVENTS 0x08
#define D_RTOSAL_OPTION_ERROR 0x09
#define D_RTOSAL_QUEUE_ERROR 0x0A
#define D_RTOSAL_QUEUE_EMPTY 0x0B
#define D_RTOSAL_QUEUE_FULL 0x0C
#define D_RTOSAL_SEMAPHORE_ERROR 0x0D
#define D_RTOSAL_NO_INSTANCE 0x0E
#define D_RTOSAL_TASK_ERROR 0x0F
#define D_RTOSAL_PRIORITY_ERROR 0x10
#define D_RTOSAL_START_ERROR 0x11
#define D_RTOSAL_DELETE_ERROR 0x12
#define D_RTOSAL_RESUME_ERROR 0x13
#define D_RTOSAL_CALLER_ERROR 0x14
#define D_RTOSAL_SUSPEND_ERROR 0x15
#define D_RTOSAL_TIMER_ERROR 0x16
#define D_RTOSAL_TICK_ERROR 0x17
#define D_RTOSAL_ACTIVATE_ERROR 0x18
#define D_RTOSAL_THRESH_ERROR 0x19
#define D_RTOSAL_SUSPEND_REMOVED 0x1A
#define D_RTOSAL_WAIT_ABORTED 0x1B
#define D_RTOSAL_WAIT_ABORT_ERROR 0x1C
#define D_RTOSAL_MUTEX_ERROR 0x1D
#define D_RTOSAL_NOT_AVAILABLE 0x1E
#define D_RTOSAL_NOT_OWNED 0x1F
#define D_RTOSAL_INHERIT_ERROR 0x20
#define D_RTOSAL_NOT_DONE 0x21
#define D_RTOSAL_CEILING_EXCEEDED 0x22
#define D_RTOSAL_INVALID_CEILING 0x23
#define D_RTOSAL_FAIL 0xFE
#define D_RTOSAL_FEATURE_NOT_ENABLED 0xFF
#elif D_USE_THREADX
#define D_RTOSAL_SUCCESS TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_DELETED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_MEMORY TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_POOL_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_PTR_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_WAIT_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SIZE_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_GROUP_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_EVENTS TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_OPTION_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_QUEUE_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_QUEUE_EMPTY TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_QUEUE_FULL TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SEMAPHORE_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_INSTANCE TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_TASK_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_PRIORITY_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_START_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_DELETE_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_RESUME_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_CALLER_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SUSPEND_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_TIMER_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_TICK_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_ACTIVATE_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_THRESH_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SUSPEND_REMOVED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_WAIT_ABORTED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_WAIT_ABORT_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_MUTEX_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NOT_AVAILABLE TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NOT_OWNED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_INHERIT_ERROR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NOT_DONE TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_CEILING_EXCEEDED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_INVALID_CEILING TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_FAIL TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_FEATURE_NOT_ENABLED TBD_TAKE_VAL_FROM_TX
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/* function input definitions */
#ifdef D_USE_FREERTOS
#define D_RTOSAL_OR 0
#define D_RTOSAL_OR_CLEAR 1
#define D_RTOSAL_AND 2
#define D_RTOSAL_AND_CLEAR 3
#define D_RTOSAL_INHERIT 1
#define D_RTOSAL_NO_INHERIT 0
#define D_RTOSAL_NO_WAIT 0
#define D_RTOSAL_WAIT_FOREVER 0xFFFFFFFF
#define D_RTOSAL_TRUE 1
#define D_RTOSAL_FALSE 0
#define D_RTOSAL_DONT_START 0
#define D_RTOSAL_AUTO_START 1
#define D_RTOSAL_NO_TIME_SLICE 0
#elif D_USE_THREADX
#define D_RTOSAL_OR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_OR_CLEAR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_AND TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_AND_CLEAR TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_INHERIT TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_INHERIT TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_WAIT TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_WAIT_FOREVER TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_TRUE TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_FALSE TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_DONT_START TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_AUTO_START TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_NO_TIME_SLICE TBD_TAKE_VAL_FROM_TX
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
#ifdef D_USE_FREERTOS
#define D_RTOSAL_SCHEDULER_NOT_STARTED 0
#define D_RTOSAL_SCHEDULER_RUNNING 1
#define D_RTOSAL_SCHEDULER_SUSPENDED 2
#define D_RTOSAL_SCHEDULER_UNKNOWN_STATE 3
#elif D_USE_THREADX
#define D_RTOSAL_SCHEDULER_NOT_STARTED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SCHEDULER_RUNNING TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SCHEDULER_SUSPENDED TBD_TAKE_VAL_FROM_TX
#define D_RTOSAL_SCHEDULER_UNKNOWN_STATE TBD_TAKE_VAL_FROM_TX
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
#endif /* __RTOSAL_DEFINES_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/psp_internal_mutex_eh2.c | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_internal_mutex_eh2.c
* @author <NAME>
* @date 05.07.2020
* @brief The file defines mutexs for internal PSP usage. It is relevant for SweRV EH2 (multi HW-threads core)
*
*/
/**
* include files
*/
#include "psp_api.h"
#include "psp_internal_mutex_eh2.h"
/**
* definitions
*/
#define D_INTERNAL_MUTEX_SECTION __attribute__((section(".psp_internal_mutexes")))
#define D_PSP_NUM_OF_INTERNAL_MUTEXES 5
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
D_INTERNAL_MUTEX_SECTION u32_t g_uiInternalPspMutex[D_PSP_NUM_OF_INTERNAL_MUTEXES];
/**
* APIs
*/
/**
* @brief - Initialize (zero) the internal PSP mutexs. Used by PSP for multi-harts safe functionality
* Note that the size of PSP internal mutex is 32bit (while the mutex for users is 64bits)
*
*/
D_PSP_TEXT_SECTION void pspInternalMutexInit(void)
{
/* Set all mutexs used internally by PSP to "Unlocked" state */
pspMemsetBytes((void*)g_uiInternalPspMutex, D_PSP_MUTEX_UNLOCKED, sizeof(u32_t)*D_PSP_NUM_OF_INTERNAL_MUTEXES);
}
/**
* @brief - Lock an internal-PSP mutex
*
* @parameter - mutex number
*
*/
void pspInternalMutexLock(u32_t uiMutexNumber)
{
M_PSP_ASSERT(D_PSP_NUM_OF_INTERNAL_MUTEXES > uiMutexNumber);
pspAtomicsEnterCriticalSection((u32_t*)&g_uiInternalPspMutex[uiMutexNumber]);
}
/**
* @brief - Unlock an internal-PSP mutex
*
* @parameter - mutex number
*
*/
void pspInternalMutexUnlock(u32_t uiMutexNumber)
{
M_PSP_ASSERT(D_PSP_NUM_OF_INTERNAL_MUTEXES > uiMutexNumber);
pspAtomicsExitCriticalSection((u32_t*)&g_uiInternalPspMutex[uiMutexNumber]);
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/psp_performance_monitor_el2.c | /*
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_performance_monitor_el2.c
* @author <NAME>
* @date 20.08.2020
* @brief performance monitor service provider for SweRV EL2
* comply with The RISC-V Instruction Set Manual Volume II: Privileged Architecture 20190405-Priv-MSU-Ratification
*
*/
/**
* include files
*/
#include "psp_api.h"
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* @brief The function disables all the performance monitors
* ** Note ** Only Performance-Monitor counters 3..6 are disabled by this setting.
* The instruction-retired, cycles and time counters stay enabled.
*
*/
D_PSP_TEXT_SECTION void pspMachinePerfMonitorDisableAll(void)
{
/* In MCOUNTINHIBIT CSR, '1' means counter is disabled */
M_PSP_SET_CSR(D_PSP_MCOUNTINHIBIT_NUM, D_PSP_CYCLE_COUNTER|D_PSP_INSTRET_COUNTER|D_PSP_COUNTER0|D_PSP_COUNTER1|D_PSP_COUNTER2|D_PSP_COUNTER3);
}
/**
* @brief The function enables all the performance monitors
*
*/
D_PSP_TEXT_SECTION void pspMachinePerfMonitorEnableAll(void)
{
/* In MCOUNTINHIBIT CSR, '0' means counter is enabled */
M_PSP_CLEAR_CSR(D_PSP_MCOUNTINHIBIT_NUM, D_PSP_CYCLE_COUNTER|D_PSP_INSTRET_COUNTER|D_PSP_COUNTER0|D_PSP_COUNTER1|D_PSP_COUNTER2|D_PSP_COUNTER3);
}
/**
* @brief The function disable a specific performance monitor counter
*
* @param uiPerfMonCounter- Performance-Monitor counter to disable/enable
* supported counters to enable/disbale are:
* D_PSP_CYCLE_COUNTER
* D_PSP_INSTRET_COUNTER
* D_PSP_COUNTER0
* D_PSP_COUNTER1
* D_PSP_COUNTER2
* D_PSP_COUNTER3
*/
D_PSP_TEXT_SECTION void pspMachinePerfMonitorDisableCounter(u32_t uiPerfMonCounter)
{
/* In MCOUNTINHIBIT CSR, '1' means counter is disabled */
M_PSP_SET_CSR(D_PSP_MCOUNTINHIBIT_NUM, uiPerfMonCounter);
}
/**
* @brief The function enable a specific performance monitor counter
*
* @param uiPerfMonCounter- Performance-Monitor counter to disable/enable
* supported counters to enable/disbale are:
* D_PSP_CYCLE_COUNTER
* D_PSP_INSTRET_COUNTER
* D_PSP_COUNTER0
* D_PSP_COUNTER1
* D_PSP_COUNTER2
* D_PSP_COUNTER3
*/
D_PSP_TEXT_SECTION void pspMachinePerfMonitorEnableCounter(u32_t uiPerfMonCounter)
{
/* In MCOUNTINHIBIT CSR, '0' means counter is enabled */
M_PSP_CLEAR_CSR(D_PSP_MCOUNTINHIBIT_NUM, uiPerfMonCounter);
}
/**
* @brief The function pair a counter to an event
*
* @param uiCounter β counter to be set
* β supported counters are:
* D_PSP_COUNTER0
* D_PSP_COUNTER1
* D_PSP_COUNTER2
* D_PSP_COUNTER3
* @param uiEvent β event to be paired to the selected counter
*
* @return No return value
*/
D_PSP_TEXT_SECTION void pspMachinePerfCounterSet(u32_t uiCounter, u32_t uiEvent)
{
switch (uiCounter)
{
case D_PSP_COUNTER0:
M_PSP_WRITE_CSR(D_PSP_MHPMEVENT3_NUM, uiEvent);
break;
case D_PSP_COUNTER1:
M_PSP_WRITE_CSR(D_PSP_MHPMEVENT4_NUM, uiEvent);
break;
case D_PSP_COUNTER2:
M_PSP_WRITE_CSR(D_PSP_MHPMEVENT5_NUM, uiEvent);
break;
case D_PSP_COUNTER3:
M_PSP_WRITE_CSR(D_PSP_MHPMEVENT6_NUM, uiEvent);
break;
default:
M_PSP_ASSERT(1);
break;
}
}
/**
* @brief The function gets the counter value (64 bit)
*
* @param uiCounter β counter index
* β supported counters are:
* D_PSP_CYCLE_COUNTER
* D_PSP_TIME_COUNTER
* D_PSP_INSTRET_COUNTER
* D_PSP_COUNTER0
* D_PSP_COUNTER1
* D_PSP_COUNTER2
* D_PSP_COUNTER3
*
* @return u64_t β Counter value
*/
D_PSP_TEXT_SECTION u64_t pspMachinePerfCounterGet(u32_t uiCounter)
{
u64_t uiCounterVal = 0xDEAFBEEFDEAFBEEF;
switch (uiCounter)
{
case D_PSP_CYCLE_COUNTER:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MCYCLE_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MCYCLEH_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
case D_PSP_TIME_COUNTER:
uiCounterVal = pspMachineTimerCounterGet();
break;
case D_PSP_INSTRET_COUNTER:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MINSTRET_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MINSTRETH_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
case D_PSP_COUNTER0:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER3_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER3H_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
case D_PSP_COUNTER1:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER4_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER4H_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
case D_PSP_COUNTER2:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER5_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER5H_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
case D_PSP_COUNTER3:
uiCounterVal = (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER6_NUM); /* read low 32 bits */
uiCounterVal |= (u64_t)M_PSP_READ_CSR(D_PSP_MHPMCOUNTER6H_NUM) << D_PSP_SHIFT_32; /* read high 32 bits */
break;
default:
M_PSP_ASSERT(1);
break;
}
return uiCounterVal;
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/board/nexys_a7_el2/bsp/bsp_timer.h | <gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file bsp_timer.h
* @author <NAME>
* @date 20.04.2020
* @brief Timer in Nexys_A7 SweRVolf FPGA (used for tests purpose to generate NMI or External interrupt)
*/
#ifndef __BSP_TIMER_H__
#define __BSP_TIMER_H__
/**
* include files
*/
/**
* definitions
*/
/**
* types
*/
/* Options for timer routing - i.e. upon timer expiration, NMI-pin/IRQ3/IRQ4 will be asserted */
typedef enum timerRouting
{
E_TIMER_TO_NMI = 0,
E_TIMER_TO_IRQ3 = 1,
E_TIMER_TO_IRQ4 = 2,
}eTimerRouting_t;
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* Setup the routing of the timer of SweRVolf FPGA
*
* @param eTimerRouting - whether timer expiration will be routed to NMI-pin, IRQ3 or IRQ4
*/
void bspRoutTimer(eTimerRouting_t eTimerRouting);
/**
* Setting up the timer duration on SweRVolf FPGA
*
* @param uiTimerDuration - Timer duration in mili-seconds
*/
void bspSetTimerDurationMsec(u32_t uiTimerDurationMsec);
/**
* Start the timer on SweRVolf FPGA
*
*/
void bspStartTimer(void);
/**
* Stop the timer on SweRVolf FPGA
*
*/
void bspStopTimer(void);
#endif /* __BSP_TIMER_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/rtosal_mutex.c | <gh_stars>10-100
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_mutex.c
* @author <NAME>
* @date 21.01.2019
* @brief The file implements the RTOS AL mutex API
*
*/
/**
* include files
*/
#include "rtosal_mutex_api.h"
#include "rtosal_macros.h"
#include "rtosal_util.h"
#ifdef D_USE_FREERTOS
#include "semphr.h"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* Mutex creation function
*
* @param pRtosalMutexCb - pointer to the mutex control block to be created
* @param pRtosalMutexName - string of the mutex name (for debuging)
* @param uiPriorityInherit - this mutex can be inherit or not
* values: D_RTOSAL_INHERIT or D_RTOSAL_NO_INHERIT
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_MUTEX_ERROR - the group pRtosalMutexCb is invalid or been used
* - D_RTOSAL_CALLER_ERROR - the caller can not call this function
* - D_RTOSAL_INHERIT_ERROR - bad parm on uiPriorityInherit
*/
RTOSAL_SECTION u32_t rtosalMutexCreate(rtosalMutex_t* pRtosalMutexCb, s08_t* pRtosalMutexName, u32_t uiPriorityInherit)
{
u32_t uiRes;
void* pMutexCb;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMutexCb, pRtosalMutexCb == NULL, D_RTOSAL_MUTEX_ERROR);
#ifdef D_USE_FREERTOS
/* D_RTOSAL_NO_INHERIT isn't supported by FreeRTOS */
M_RTOSAL_VALIDATE_FUNC_PARAM(uiPriorityInherit, uiPriorityInherit == D_RTOSAL_NO_INHERIT, D_RTOSAL_INHERIT_ERROR);
/* create the mutex */
pMutexCb = xSemaphoreCreateMutexStatic((StaticSemaphore_t*)pRtosalMutexCb->cMutexCB);
if (pRtosalMutexCb->cMutexCB == pMutexCb)
{
uiRes = D_RTOSAL_SUCCESS;
/* assign a name to the created mutex */
vQueueAddToRegistry((void*)pRtosalMutexCb->cMutexCB, (const char*)pRtosalMutexName);
}
else
{
uiRes = D_RTOSAL_MUTEX_ERROR;
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Destroys a mutex
*
* @param pRtosalMutexCb - pointer to the mutex control block to be deleted
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_MUTEX_ERROR - the group pRtosalMutexCb is invalid or been used
* - D_RTOSAL_CALLER_ERROR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalMutexDestroy(rtosalMutex_t* pRtosalMutexCb)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMutexCb, pRtosalMutexCb == NULL, D_RTOSAL_MUTEX_ERROR);
#ifdef D_USE_FREERTOS
vSemaphoreDelete(pRtosalMutexCb->cMutexCB);
uiRes = D_RTOSAL_SUCCESS;
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Obtain ownership of a mutex
*
* @param pRtosalMutexCb - pointer to the mutex control block to be locked
* @param uiWaitTimeoutTicks - define how many ticks to wait in case the mutex
* is not available.
* Parms: D_RTOSAL_NO_WAIT, D_RTOSAL_WAIT_FOREVER, 32bit timer ticks value
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_DELETED - the mutex was deleted when this api was called
* - D_RTOSAL_NOT_AVAILABLE - time out while waiting for the mutex
* - D_RTOSAL_WAIT_ABORTED - aborted by different consumer (like other thread)
* - D_RTOSAL_MUTEX_ERROR - the ptr in the mutex CB is invalid
* - D_RTOSAL_WAIT_ERROR - illegal use of wait (wait can be used only from thread)
* - D_RTOSAL_CALLER_ERROR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalMutexWait(rtosalMutex_t* pRtosalMutexCb, u32_t uiWaitTimeoutTicks)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMutexCb, pRtosalMutexCb == NULL, D_RTOSAL_MUTEX_ERROR);
#ifdef D_USE_FREERTOS
uiRes = xSemaphoreTake((void*)pRtosalMutexCb->cMutexCB, uiWaitTimeoutTicks);
if (uiRes == pdPASS)
{
uiRes = D_RTOSAL_SUCCESS;
}
else
{
uiRes = D_RTOSAL_NOT_AVAILABLE;
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Release ownership of a mutex
*
* @param pRtosalMutexCb - pointer to the mutex control block to be unlocked
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_NOT_OWNED - mutex is already taken by different consumer
* - D_RTOSAL_MUTEX_ERROR - the ptr in the mutex CB is invalid
* - D_RTOSAL_CALLER_ERROR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalMutexRelease(rtosalMutex_t* pRtosalMutexCb)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalMutexCb, pRtosalMutexCb == NULL, D_RTOSAL_MUTEX_ERROR);
#ifdef D_USE_FREERTOS
uiRes = xSemaphoreGive(pRtosalMutexCb->cMutexCB);
if (uiRes == pdPASS)
{
uiRes = D_RTOSAL_SUCCESS;
}
else
{
uiRes = D_RTOSAL_NOT_OWNED;
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/loc_inc/psp_internal_mutex_eh2.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_internal_mutex_eh2.h
* @author <NAME>
* @date 05.07.2020
* @brief The file defines mutexs for internal PSP usage. It is relevant for SweRV EH2 (multi HW-threads core)
*
*/
#ifndef __PSP_INTERNAL_MUTEX_EH2_H__
#define __PSP_INTERNAL_MUTEX_EH2_H__
/**
* include files
*/
/**
* types
*/
/* Mutexs for PSP internal usage */
typedef enum pspInternalMutex
{
E_MUTEX_INTERNAL_FOR_MUTEX_HEAP_MNG = 0,
E_MUTEX_INTERNAL_FOR_EXT_INTERRUPTS = 1,
E_MUTEX_INTERNAL_FOR_CORR_ERR_COUNTERS = 2,
E_MUTEX_INTERNAL_FOR_NMI_DELEGATION = 3,
E_MUTEX_INTERNAL_FOR_MEMORY_CONTROL = 4,
E_MUTEX_INTERNAL_LAST
}ePspInternalMutex_t;
/**
* definitions
*/
#define D_PSP_SIZE_OF_INTERNAL_MUTEX 4 /* Size of internal PSP mutex is 4 bytes (32bits) */
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* @brief - Initialize (zero) the internal PSP mutexs. Used by PSP for multi-harts safe functionality
*
*/
void pspInternalMutexInit(void);
/**
* @brief - Lock an internal-PSP mutex
*
* @parameter - mutex number
*
*/
void pspInternalMutexLock(u32_t uiMutexNumber);
/**
* @brief - Unlock an internal-PSP mutex
*
* @parameter - mutex number
*
*/
void pspInternalMutexUnlock(u32_t uiMutexNumber);
#endif /* __PSP_INTERNAL_MUTEX_EH2_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/rtosal_event.c | <reponame>edward-jones/riscv-fw-infrastructure
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_event.c
* @author <NAME>
* @date 21.01.2019
* @brief The file implements the RTOS AL event API
*
*/
/**
* include files
*/
#include "rtosal_event_api.h"
#include "rtosal_macros.h"
#include "rtosal_task_api.h"
#include "rtosal_util.h"
#include "rtosal_interrupt_api.h"
#include "psp_api.h"
#ifdef D_USE_FREERTOS
#include "event_groups.h"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* definitions
*/
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* Create an event group
*
* @param pRtosalEventGroupCb - pointer to event group control block
* @param pRtosalEventGroupName - string of the group name (for debuging)
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_GROUP_ERROR - the group CB is invalid or been used
* - D_RTOSAL_CALLER_ERR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalEventGroupCreate(rtosalEventGroup_t* pRtosalEventGroupCb, s08_t* pRtosalEventGroupName)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventGroupCb, pRtosalEventGroupCb == NULL, D_RTOSAL_GROUP_ERROR);
#ifdef D_USE_FREERTOS
/* unused parameter with FreeRTOS */
(void)pRtosalEventGroupName;
/* create the event group */
pRtosalEventGroupCb->eventGroupHandle = xEventGroupCreateStatic((StaticEventGroup_t*)pRtosalEventGroupCb->cEventGroupCB);
if (pRtosalEventGroupCb->eventGroupHandle != NULL)
{
uiRes = D_RTOSAL_SUCCESS;
}
else
{
uiRes = D_RTOSAL_GROUP_ERROR;
}
#elif D_USE_THREADX
/* create the event group */
// TODO:
// uiRes = add call to threadx create flags API
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Destroy a specific event group
*
* @param pRtosalEventGroupCb - pointer to event group control block to be deleted
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_GROUP_ERROR - the group CB is invalid or been used
* - D_RTOSAL_CALLER_ERR - the caller can not call this function
*/
RTOSAL_SECTION u32_t rtosalEventGroupDestroy(rtosalEventGroup_t* pRtosalEventGroupCb)
{
u32_t uiRes;
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventGroupCb, pRtosalEventGroupCb == NULL, D_RTOSAL_GROUP_ERROR);
#ifdef D_USE_FREERTOS
vEventGroupDelete(pRtosalEventGroupCb->eventGroupHandle);
uiRes = D_RTOSAL_SUCCESS;
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif
return uiRes;
}
/**
* Set the event bits of a specific event group
*
* @param pRtosalEventGroupCb - pointer to event group control block to set the event bits
* @param stSetRtosalEventBits - value of the event bits vector to set
* @param uiSetOption - one of the values: D_RTOSAL_AND or D_RTOSAL_OR
* @param pRtosalEventBits - pointer to the value of the event bits vector
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_GROUP_ERROR - the group CB is invalid or been used
* - D_RTOSAL_OPTION_ERROR - bad param on uiSetOption
* - D_RTOSAL_FAIL - fail to set event
*/
RTOSAL_SECTION u32_t rtosalEventGroupSet(rtosalEventGroup_t* pRtosalEventGroupCb,
rtosalEventBits_t stSetRtosalEventBits,
u32_t uiSetOption, rtosalEventBits_t* pRtosalEventBits)
{
u32_t uiRes;
#ifdef D_USE_FREERTOS
/* specify if a context switch is needed as a uiResult calling FreeRTOS ...ISR function */
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventGroupCb, pRtosalEventGroupCb == NULL, D_RTOSAL_GROUP_ERROR);
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventBits, pRtosalEventBits == NULL, D_RTOSAL_GROUP_ERROR);
#ifdef D_USE_FREERTOS
/* rtosalEventGroupSet invoked from an ISR context */
if (rtosalIsInterruptContext() == D_RTOSAL_INT_CONTEXT)
{
uiRes = xEventGroupSetBitsFromISR(pRtosalEventGroupCb->eventGroupHandle,
stSetRtosalEventBits, &xHigherPriorityTaskWoken);
if (uiRes == pdPASS)
{
uiRes = D_RTOSAL_SUCCESS;
}
else
{
/* The message could not be sent */
uiRes = D_RTOSAL_FAIL;
}
/* due to the set bit/s we got an indicating that a context switch
should be requested before the interrupt exits */
if (uiRes == D_RTOSAL_SUCCESS && xHigherPriorityTaskWoken == pdTRUE)
{
rtosalContextSwitchIndicationSet();
}
}
else
{
*pRtosalEventBits = xEventGroupSetBits(pRtosalEventGroupCb->eventGroupHandle, stSetRtosalEventBits);
uiRes = D_RTOSAL_SUCCESS;
}
#elif D_USE_THREADX
// TODO:
// uiRes = add call to ThreadX set flags API
/* if we need to retrieve the set event bits */
if (uiRes == D_RTOSAL_SUCCESS)
{
// uiRes = add call to ThreadX set flags API
}
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
/**
* Retrieve the event bits of a specific event group
*
* @param pRtosalEventGroupCb - pointer to event group control block to retrieve
* the bits from
* @param pRtosalEventBits - pointer to the value of the RTOS event bits vector
* @param uiRetrieveEvents - event bits vector to retrieve
* @param uiRetrieveOption - one of the values: D_RTOSAL_AND, D_RTOSAL_AND_CLEAR,
* D_RTOSAL_OR or D_RTOSAL_OR_CLEAR; using the 'AND' will wait for all bits;
* using the 'OR' will wait for at least one bit to be set;
* using the 'CLEAR' will clear the bit when read.
* @param uiWaitTimeoutTicks - wait value if event vector bits are not set;
* can be one of the values: D_RTOSAL_NO_WAIT, D_RTOSAL_WAIT_FOREVER
* or timer ticks value
*
* @return u32_t - D_RTOSAL_SUCCESS
* - D_RTOSAL_DELETED - The event was already deleted when this api was called
* - D_RTOSAL_NO_EVENTS - time out while waiting for the event
* - D_RTOSAL_WAIT_ABORTED - aborted by different consumer (like other thread)
* - D_RTOSAL_GROUP_ERROR - the ptr in the group CB is invalid
* - D_RTOSAL_PTR_ERROR - bad pRtosalEventBits
* - D_RTOSAL_WAIT_ERROR - illegal use of wait (wait can be used only from thread)
* - D_RTOSAL_OPTION_ERROR - bad uiRetrieveOption
*/
RTOSAL_SECTION u32_t rtosalEventGroupGet(rtosalEventGroup_t* pRtosalEventGroupCb, u32_t uiRetrieveEvents,
rtosalEventBits_t* pRtosalEventBits, u32_t uiRetrieveOption,
u32_t uiWaitTimeoutTicks)
{
u32_t uiRes;
#ifdef D_USE_FREERTOS
BaseType_t xClearOnExit;
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventGroupCb, pRtosalEventGroupCb == NULL, D_RTOSAL_GROUP_ERROR);
#ifdef D_USE_FREERTOS
M_RTOSAL_VALIDATE_FUNC_PARAM(pRtosalEventBits, pRtosalEventBits == NULL, D_RTOSAL_GROUP_ERROR);
/* invoked from an ISR context */
if (rtosalIsInterruptContext() == D_RTOSAL_INT_CONTEXT)
{
*pRtosalEventBits = xEventGroupGetBitsFromISR(pRtosalEventGroupCb->eventGroupHandle);
}
else
{
/* determine if event bits will be cleared in the event group before
xEventGroupWaitBits() returns */
if (uiRetrieveOption == D_RTOSAL_AND_CLEAR || uiRetrieveOption == D_RTOSAL_OR_CLEAR)
{
xClearOnExit = pdTRUE;
}
else
{
xClearOnExit = pdFALSE;
}
/* determine if to wait for all the event bits */
if (uiRetrieveOption == D_RTOSAL_AND_CLEAR || uiRetrieveOption == D_RTOSAL_AND)
{
uiRetrieveOption = pdTRUE;
}
else
{
uiRetrieveOption = pdFALSE;
}
/* call FreeRTOS interface */
*pRtosalEventBits = xEventGroupWaitBits(pRtosalEventGroupCb->eventGroupHandle,
(EventBits_t)uiRetrieveEvents,
xClearOnExit, uiRetrieveOption,
(TickType_t)uiWaitTimeoutTicks);
}
uiRes = D_RTOSAL_SUCCESS;
#elif D_USE_THREADX
#error "Add appropriate THREADX definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
return uiRes;
}
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/api_inc/psp_macros_eh1.h | /*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_macro_eh1.h
* @author <NAME>
* @date 03/2020
* @brief The file defines the psp macros for SweRV EH1
*/
#ifndef __PSP_MACRO_EH1_H__
#define __PSP_MACRO_EH1_H__
/**
* include files
*/
/**
* macros
*/
/* enable all cache regions without "side effects"
* for more info please read the PRM for "Region Access Control Register" */
#define M_PSP_ICACHE_ENABLE() M_PSP_WRITE_CSR(D_PSP_MRAC,0x55555555)
#define M_PSP_ICACHE_DISABLE() M_PSP_WRITE_CSR(D_PSP_MRAC,0x0)
#endif /* __PSP_MACRO_EH1_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/rtosal_util.c | <reponame>edward-jones/riscv-fw-infrastructure<filename>WD-Firmware/rtos/rtosal/rtosal_util.c
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_util.c
* @author <NAME>
* @date 21.01.2019
* @brief The file implements the RTOS AL misc API
*
*/
/**
* include files
*/
#include "psp_api.h"
#include "rtosal_util.h"
#include "rtosal_macros.h"
#include "rtosal_task_api.h"
#ifdef D_USE_FREERTOS
#include "FreeRTOS.h"
#include "task.h"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
#include "demo_platform_al.h"
/**
* definitions
*/
#define D_IDLE_TASK_SIZE 450
#define D_TIMER_TASK_SIZE 450
/**
* macros
*/
/**
* types
*/
/**
* local prototypes
*/
/**
* external prototypes
*/
/* application specific timer-tick handler function. The function should be implemented and registered
* by the application */
extern rtosalTimerTickHandler_t fptrTimerTickHandler ;
/**
* global variables
*/
u32_t g_rtosalContextSwitch = 0;
u32_t g_rtosalIsInterruptContext = D_RTOSAL_NON_INT_CONTEXT;
u32_t g_uInterruptsPreserveMask = 0; /* Used for restoring interrupts status */
u32_t g_uInterruptsDisableCounter = 0;
#ifdef D_USE_FREERTOS
/* Idle-task and Timer-task are created by FreeRtos and not by this application */
rtosalTask_t stIdleTask;
rtosalStackType_t uIdleTaskStackBuffer[D_IDLE_TASK_SIZE];
rtosalTask_t stTimerTask;
rtosalStackType_t uTimerTaskStackBuffer[D_TIMER_TASK_SIZE];
#endif
/**
*
*
* @param none
*
* @return none
*/
RTOSAL_SECTION void rtosalContextSwitchIndicationSet(void)
{
g_rtosalContextSwitch = 1;
}
/**
*
*
* @param none
*
* @return none
*/
RTOSAL_SECTION void rtosalContextSwitchIndicationClear(void)
{
g_rtosalContextSwitch = 0;
}
/**
* @brief check if in ISR context
*
* @param None
*
* @return u32_t - D_NON_INT_CONTEXT
* - non zero value - interrupt context
*/
RTOSAL_SECTION u32_t rtosalIsInterruptContext(void)
{
return (g_rtosalIsInterruptContext > 0);
}
/**
* This function is invoked by the system timer interrupt
*
* @param none
*
* @return none
*/
RTOSAL_SECTION void rtosalTick(void)
{
#ifdef D_USE_FREERTOS
if (xTaskIncrementTick() == D_PSP_TRUE)
{
vTaskSwitchContext();
}
#elif D_USE_THREADX
#error "Add THREADX appropriate definitions"
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
}
#ifdef D_USE_FREERTOS
/**
* vApplicationGetIdleTaskMemory - Called from FreeRTOS upon Idle task creation, to get task's memory buffers
*
* rtosalStaticTask_t **ppxIdleTaskTCBBuffer - pointer to Task's Control-Block buffer (pointer to pointer as it is output parameter)
* rtosalStack_t **ppxIdleTaskStackBuffer - pointer to Task's stack buffer (pointer to pointer as it is output parameter)
* u32_t *pulIdleTaskStackSize - Task's stack size (pointer, as it is output parameter)
*
*/
void vApplicationGetIdleTaskMemory(rtosalStaticTask_t **ppxIdleTaskTCBBuffer, rtosalStack_t **ppxIdleTaskStackBuffer, u32_t *pulIdleTaskStackSize)
{
*ppxIdleTaskTCBBuffer = (rtosalStaticTask_t*)&stIdleTask;
*ppxIdleTaskStackBuffer = (rtosalStack_t*)&uIdleTaskStackBuffer[0];
*pulIdleTaskStackSize = D_IDLE_TASK_SIZE;
}
/**
* vApplicationGetTimerTaskMemory - Called from FreeRTOS upon Timer task creation, to get task's memory buffers
*
* rtosalStaticTask_t **ppxTimerTaskTCBBuffer - pointer to Task's Control-Block buffer (pointer to pointer as it is output parameter)
* rtosalStack_t **ppxTimerTaskStackBuffer - pointer to Task's stack buffer (pointer to pointer as it is output parameter)
* u32_t *pulTimerTaskStackSize - Task's stack size (pointer, as it is output parameter)
*
*/
void vApplicationGetTimerTaskMemory(rtosalStaticTask_t **ppxTimerTaskTCBBuffer, rtosalStack_t **ppxTimerTaskStackBuffer, u32_t *pulTimerTaskStackSize)
{
*ppxTimerTaskTCBBuffer = (rtosalStaticTask_t*)&stTimerTask;
*ppxTimerTaskStackBuffer = (rtosalStack_t*)&uTimerTaskStackBuffer[0];
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
/**
* vApplicationMallocFailedHook - Called from FreeRTOS upon malloc failure
*
* Not in use
*
*/
void vApplicationMallocFailedHook( void )
{
/* The malloc failed hook is enabled by setting
configUSE_MALLOC_FAILED_HOOK to 1 in FreeRTOSConfig.h.
Called if a call to pvPortMalloc() fails because there is insufficient
free memory available in the FreeRTOS heap. pvPortMalloc() is called
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
demoOutputMsg("malloc failed\n", 14);
for( ;; );
}
/**
* vApplicationStackOverflowHook - Called from FreeRTOS upon stack-overflow
*
* void* xTask - not in use
* signed char *pcTaskName - not in use
*
*/
void vApplicationStackOverflowHook(void* xTask, signed char *pcTaskName)
{
( void ) pcTaskName;
( void ) xTask;
/* Run time stack overflow checking is performed if
configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. pxCurrentTCB can be
inspected in the debugger if the task name passed into this function is
corrupt. */
demoOutputMsg("Stack Overflow\n", 15);
for( ;; );
}
/**
* vApplicationStackOverflowHook - Called from FreeRTOS
*
* Currently empty function
*
*/
void vApplicationIdleHook( void )
{
/*demoOutputMsg("Idle Task Hook\n", 15);*/
}
/**
* vApplicationTickHook - Called from FreeRTOS upon any timer's tick
*
*/
//extern void rtosalContextSwitchIndicationClear(void); /* Temporarily here! */
void vApplicationTickHook( void )
{
if (NULL != fptrTimerTickHandler)
{
fptrTimerTickHandler();
}
}
#endif /* D_USE_FREERTOS */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/psp/api_inc/psp_interrupts_eh1.h | <filename>WD-Firmware/psp/api_inc/psp_interrupts_eh1.h
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020-2021 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file psp_interrupts_eh1.h
* @author <NAME>
* @date 14.01.2020
* @brief The file supplies information and registration API for interrupt and exception service routines on EH1 core.
*/
#ifndef __PSP_INTERRUPTS_EH1_H__
#define __PSP_INTERRUPTS_EH1_H__
/**
* include files
*/
/**
* macros
*/
/**
* types
*/
/* EH1 specific interrupt causes */
typedef enum pspInterruptCauseEH1
{
E_LAST_COMMON_CAUSE = E_LAST_CAUSE,
E_FIRST_EH1_CAUSE = 27,
E_MACHINE_INTERNAL_TIMER1_CAUSE = 28,
E_MACHINE_INTERNAL_TIMER0_CAUSE = 29,
E_MACHINE_CORRECTABLE_ERROR_CAUSE = 30,
E_LAST_EH1_CAUSE
} ePspInterruptCauseEH1_t;
/* interrupt handler definition */
typedef void (*fptrPspInterruptHandler_t)(void);
/**
* definitions
*/
#define D_PSP_FIRST_EH1_INT_CAUSE = E_MACHINE_INTERNAL_TIMER1_CAUSE;
/* Enable/Disable bits of Timer0, Timer1 and Correctable-Error-Counter interrupts */
#define D_PSP_INTERRUPTS_MACHINE_TIMER0 E_MACHINE_INTERNAL_TIMER0_CAUSE
#define D_PSP_INTERRUPTS_MACHINE_TIMER1 E_MACHINE_INTERNAL_TIMER1_CAUSE
#define D_PSP_INTERRUPTS_MACHINE_CORR_ERR_COUNTER E_MACHINE_CORRECTABLE_ERROR_CAUSE
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* macros
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* @brief - Disable specified interrupt when called in MACHINE-LEVEL
* *************
* IMPORTANT NOTE: When you call this function, you can use either one of the following defined values:
*************** - D_PSP_INTERRUPTS_MACHINE_SW
- D_PSP_INTERRUPTS_MACHINE_TIMER
- D_PSP_INTERRUPTS_MACHINE_EXT
- D_PSP_INTERRUPTS_SUPERVISOR_SW
- D_PSP_INTERRUPTS_SUPERVISOR_TIMER
- D_PSP_INTERRUPTS_SUPERVISOR_EXT
- D_PSP_INTERRUPTS_USER_SW
- D_PSP_INTERRUPTS_USER_TIMER
- D_PSP_INTERRUPTS_USER_EXT
- D_PSP_INTERRUPTS_MACHINE_TIMER0
- D_PSP_INTERRUPTS_MACHINE_TIMER1
- D_PSP_INTERRUPTS_MACHINE_CORR_ERR_COUNTER
*
* @input parameter - Interrupt number to disable
*
* @return - none
*/
void pspMachineInterruptsDisableIntNumber(u32_t uiInterruptNumber);
/**
* @brief - Enable specified interrupt when called in MACHINE-LEVEL
* *************
* IMPORTANT NOTE: When you call this function, you can use either one of the following defined values:
*************** - D_PSP_INTERRUPTS_MACHINE_SW
- D_PSP_INTERRUPTS_MACHINE_TIMER
- D_PSP_INTERRUPTS_MACHINE_EXT
- D_PSP_INTERRUPTS_SUPERVISOR_SW
- D_PSP_INTERRUPTS_SUPERVISOR_TIMER
- D_PSP_INTERRUPTS_SUPERVISOR_EXT
- D_PSP_INTERRUPTS_USER_SW
- D_PSP_INTERRUPTS_USER_TIMER
- D_PSP_INTERRUPTS_USER_EXT
- D_PSP_INTERRUPTS_MACHINE_TIMER0
- D_PSP_INTERRUPTS_MACHINE_TIMER1
- D_PSP_INTERRUPTS_MACHINE_CORR_ERR_COUNTER
*
* @input parameter - Interrupt number to enable
*
* @return - none
*/
void pspMachineInterruptsEnableIntNumber(u32_t uiInterruptNumber);
/**
* @brief - The function returns the address the handler of a given exception
*
* @parameter - exceptionCause - exception cause
* @return - fptrInterruptHandler - function pointer to the exception handler
*/
fptrPspInterruptHandler_t pspInterruptsGetExceptionHandler(u32_t uiExceptionCause);
#endif /* __PSP_INTERRUPTS_EH1_H__ */
|
edward-jones/riscv-fw-infrastructure | WD-Firmware/rtos/rtosal/api_inc/rtosal_time_api.h | <filename>WD-Firmware/rtos/rtosal/api_inc/rtosal_time_api.h
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 Western Digital Corporation or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:*www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file rtosal_time_api.h
* @author <NAME>
* @date 21.01.2019
* @brief The file defines the RTOS AL time interface
*/
#ifndef __RTOSAL_TIME_API_H__
#define __RTOSAL_TIME_API_H__
/**
* include files
*/
#include "rtosal_config.h"
#include "rtosal_defines.h"
#include "rtosal_types.h"
/**
* definitions
*/
/**
* macros
*/
#ifdef D_USE_FREERTOS
#define M_TIMER_CB_SIZE_IN_BYTES sizeof(StaticTimer_t)
#elif D_USE_THREADX
#define M_TIMER_CB_SIZE_IN_BYTES sizeof(TBD) // size of the CB struct
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/**
* types
*/
#ifdef D_USE_FREERTOS
typedef void* timerHandlerParam_t;
#elif D_USE_THREADX
#error *** TODO: need to define the TBD ***
typedef TBD timerHandlerParam_t;
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
/* timer */
typedef struct rtosalTimer
{
#ifdef D_USE_FREERTOS
void* timerHandle;
#else
#error "Add appropriate RTOS definitions"
#endif /* #ifdef D_USE_FREERTOS */
s08_t cTimerCB[M_TIMER_CB_SIZE_IN_BYTES];
}rtosalTimer_t;
/* timer handler definition */
typedef void (*rtosalTimerHandler_t)(timerHandlerParam_t);
/**
* local prototypes
*/
/**
* external prototypes
*/
/**
* global variables
*/
/**
* APIs
*/
/**
* @brief Timer creation function
*/
u32_t rtosTimerCreate(rtosalTimer_t* pRtosalTimerCb, s08_t *pRtosTimerName,
rtosalTimerHandler_t fptrRtosTimerCallcabk,
u32_t uTimeCallbackParam, u32_t uiAutoActivate,
u32_t uiTicks, u32_t uiRescheduleTicks);
/**
* @brief Destroy a timer
*/
u32_t rtosTimerDestroy(rtosalTimer_t* pRtosalTimerCb);
/**
* @brief Start a timer
*/
u32_t rtosTimerStart(rtosalTimer_t* pRtosalTimerCb);
/**
* @brief Stop a timer
*/
u32_t rtosTimerStop(rtosalTimer_t* pRtosalTimerCb);
/**
* @brief Modify the timer expiration value
*/
u32_t rtosTimerModifyPeriod(rtosalTimer_t* pRtosalTimerCb, u32_t uiTicks, u32_t uiRescheduleTicks);
/**
* @brief - Store the input parameter in a global variable for usage along the program run
*/
void rtosalTimerSetPeriod(u32_t timerPeriod);
#endif /* __RTOSAL_TIME_API_H__ */
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.