Skip to content

Commit

Permalink
build: make without warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
roemvaar committed Oct 18, 2024
1 parent 7f0eaa6 commit 19c97e9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 27 deletions.
14 changes: 7 additions & 7 deletions include/peripherals/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#define CLOCKHZ 1000000 // Free-running system timer, constant 1MHz rate

#define TIMER_CS (PERIPHERALS_BASE + 0x00003000)
#define TIMER_CLO (PERIPHERALS_BASE + 0x00003004)
#define TIMER_CHI (PERIPHERALS_BASE + 0x00003008)
#define TIMER_C0 (PERIPHERALS_BASE + 0x0000300C)
#define TIMER_C1 (PERIPHERALS_BASE + 0x00003010)
#define TIMER_C2 (PERIPHERALS_BASE + 0x00003014)
#define TIMER_C3 (PERIPHERALS_BASE + 0x00003018)
#define TIMER_CS (unsigned long)(PERIPHERALS_BASE + 0x00003000)
#define TIMER_CLO (unsigned long)(PERIPHERALS_BASE + 0x00003004)
#define TIMER_CHI (unsigned long)(PERIPHERALS_BASE + 0x00003008)
#define TIMER_C0 (unsigned long)(PERIPHERALS_BASE + 0x0000300C)
#define TIMER_C1 (unsigned long)(PERIPHERALS_BASE + 0x00003010)
#define TIMER_C2 (unsigned long)(PERIPHERALS_BASE + 0x00003014)
#define TIMER_C3 (unsigned long)(PERIPHERALS_BASE + 0x00003018)

#define TIMER_CS_M0 (1 << 0)
#define TIMER_CS_M1 (1 << 1)
Expand Down
2 changes: 0 additions & 2 deletions include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern struct task_struct *current;
extern int num_tasks;

typedef struct mem_block MemBlock_t;
typedef void (*EntryPoint_t)(void);

/* TaskState_t
*
Expand Down Expand Up @@ -90,7 +89,6 @@ struct task_struct
struct task_struct *parent; /* A pointer to the TaskDescriptor of the task that created it, its parent */
struct task_struct *next_task_ready_queue; /* Pointer to TaskDescriptor of the next ready task (schedule) */
struct task_struct *next_task_send_queue; /* Pointer to TaskDescriptor of the next ready task (send queue) */
// EntryPoint_t code; /* Pointer to the instruction memory for this task */
// MemBlock_t *mem;
};

Expand Down
2 changes: 1 addition & 1 deletion include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "sched.h"

int task_create(int priority, EntryPoint_t code);
int task_create(int priority, void (*task_code)(void));
int task_parent_tid(void);
void task_yield(void);
void task_exit(void);
Expand Down
30 changes: 19 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@

void task1()
{
int tid = sys_mytid();
uart_printf(CONSOLE, "current: %d\r\n", tid);
for (int i = 0; i < 5; i++) {
uart_printf(CONSOLE, "Task 1...\r\n");
while(1) {
int tid = sys_mytid();
uart_printf(CONSOLE, "current: %d\r\n", tid);
for (int i = 0; i < 5; i++) {
uart_printf(CONSOLE, "Task 1...\r\n");
}
}
}

void task2(unsigned char *array)
// void task2(unsigned char *array)
void task2(void)
{
int tid = sys_mytid();
uart_printf(CONSOLE, "current: %d\r\n", tid);
for (int i = 0; i < 5; i++) {
uart_putc(CONSOLE, array[i]);
while(1) {
int tid = sys_mytid();
uart_printf(CONSOLE, "current: %d\r\n", tid);
for (int i = 0; i < 5; i++) {
// uart_putc(CONSOLE, array[i]);
uart_putc(CONSOLE, i);
}
uart_putc(CONSOLE, '\r');
uart_putc(CONSOLE, '\n');
}
uart_putc(CONSOLE, '\r');
uart_putc(CONSOLE, '\n');
}

void task3()
Expand Down Expand Up @@ -112,6 +118,8 @@ int kmain(void)
uart_printf(CONSOLE, "[error] Couldn't create a new task: %d\r\n", ret);
}

schedule();

#ifdef DEBUG
// print_priority_queue();
int tid = sys_mytid();
Expand Down
2 changes: 1 addition & 1 deletion src/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// static MemBlock_t stacks[BLOCK_COUNT];

static unsigned short mem_map[BLOCK_COUNT];
// static unsigned short mem_map[BLOCK_COUNT];

// void mem_init(void)
// {
Expand Down
11 changes: 11 additions & 0 deletions src/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ void switch_to(struct task_struct *next)
cpu_switch_to(prev, next);
}

// void cpu_switch_to_in_c(struct task_struct *prev, struct task_struct *next)
// {
// /* Save registers from `prev` task */
// save_sp(prev->cpu_context.sp);
// save_pc(prev->cpu_context.pc);

// /* Load registers from `next` task */
// load_sp(next->cpu_context.sp);
// load_pc(next->cpu_context.pc);
// }

// void switch_to_new_task(void)
// {
// // task_descriptor queues[PRIORITY_LEVELS][16];
Expand Down
18 changes: 16 additions & 2 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "mm.h"
#include "sched.h"
#include "sys.h"

/* task_create
*
Expand All @@ -17,7 +18,7 @@
* -1 - invalid priority
* -2 - kernel is out of task descriptors
*/
int task_create(int priority, EntryPoint_t code)
int task_create(int priority, void (*task_code)(void))
{
/* Check that the priority is valid */
if (priority < 0 || priority >= PRIORITY_LEVELS) {
Expand All @@ -30,13 +31,26 @@ int task_create(int priority, EntryPoint_t code)
return -2; // No available task descriptors
}

/* Set the initial values for the CPU context of the task */
new_task->cpu_context.x19 = 0;
new_task->cpu_context.x20 = 0;
new_task->cpu_context.x21 = 0;
new_task->cpu_context.x22 = 0;
new_task->cpu_context.x23 = 0;
new_task->cpu_context.x24 = 0;
new_task->cpu_context.x25 = 0;
new_task->cpu_context.x26 = 0;
new_task->cpu_context.x27 = 0;
new_task->cpu_context.x28 = 0;
// new_task->cpu_context.sp = GET_STACK_FOR_THIS_INSTRUCTION; // TODO
new_task->cpu_context.x19 = (unsigned long)task_code;

new_task->tid = get_new_tid();
new_task->priority = priority;
new_task->parent = get_current_task();
new_task->state = READY;
new_task->next_task_ready_queue = NULL;
new_task->next_task_send_queue = NULL;
// new_task->code = code;
// new_task->mem = get_mem_by_tid(new_task->tid);

/* Add new task into ready_queue */
Expand Down
6 changes: 3 additions & 3 deletions src/utils.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ cpu_switch_to:
stp x23, x24, [x8], #16
stp x25, x26, [x8], #16
stp x27, x28, [x8], #16
stp x29, x9, [x8], #16
str x30, [x8]
stp x29, x9, [x8], #16 // TODO(roemvaar): make sure that x29 is fp, sp, and pc
str x30, [x8] // TODO(roemvaar): check why indirect sp move
add x8, x1, x10
ldp x19, x20, [x8], #16 // restore callee-saved registers
ldp x21, x22, [x8], #16
ldp x21, x22, [x8], #16 // TODO(roemvaar): make sure the syntax is okay (address)
ldp x23, x24, [x8], #16
ldp x25, x26, [x8], #16
ldp x27, x28, [x8], #16
Expand Down

0 comments on commit 19c97e9

Please sign in to comment.