-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaed2ed
commit 6b4989d
Showing
8 changed files
with
116 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BasedOnStyle: Google | ||
IndentWidth: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
# define UARTADR 0x10000000 | ||
#include "task.h" | ||
#include "switch.h" | ||
|
||
task_info task_list[2]; | ||
|
||
#define UARTADR 0x10000000 | ||
|
||
void print_int(int i) { | ||
i %= 10; | ||
volatile unsigned int * const UART0DR = (unsigned int *)UARTADR; | ||
volatile unsigned int *const UART0DR = (unsigned int *)UARTADR; | ||
*UART0DR = (unsigned int)(i + '0'); | ||
} | ||
|
||
void print_uart0(const char *s) { | ||
volatile unsigned int * const UART0DR = (unsigned int *)UARTADR; | ||
volatile unsigned int *const UART0DR = (unsigned int *)UARTADR; | ||
while (*s != '\0') { | ||
*UART0DR = (unsigned int)(*s); | ||
s++; | ||
} | ||
} | ||
|
||
int main(){ | ||
void clear_bss() { | ||
extern unsigned int* __bss_start, __bss_end; | ||
unsigned int start = (unsigned int)__bss_start; | ||
unsigned int end = (unsigned int)__bss_end; | ||
while (start < end) { | ||
*(unsigned int*)start = 0; | ||
start ++; | ||
} | ||
} | ||
|
||
void task_1() { | ||
while (1) { | ||
print_uart0("task_1\n"); | ||
} | ||
} | ||
|
||
int main() { | ||
clear_bss(); | ||
print_uart0("Hello world!\n"); | ||
print_int(1); | ||
task_create(&task_list[0], task_1, 0); | ||
task_load_rv32(&task_list[0].sp); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
void task_switch_rv32(unsigned int* old_sp, unsigned int new_sp); | ||
void task_load_rv32(unsigned int* sp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "switch.h" | ||
#include "task.h" | ||
|
||
void task_switch(task_info* current, task_info* next) { | ||
task_switch_rv32(¤t->sp, (unsigned int)&next->sp); | ||
} | ||
|
||
void task_create(task_info* task, void (*entry)(void), int pid) { | ||
task->pid = pid; | ||
//タスクのスタックポインタを設定 | ||
task->sp = (unsigned int)&(task->stack[4096]); | ||
// stack pointerをずらしながら、レジスタの初期値を設定していく | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s11 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s10 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s9 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s8 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s7 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s6 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s5 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s4 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s3 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s2 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s1 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = 0; // s0 | ||
task->sp -= sizeof(unsigned int); | ||
*((unsigned int*)(task->sp)) = (unsigned int)entry; // ra | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
typedef struct task_info { | ||
int pid; | ||
unsigned int stack[4096]; | ||
unsigned int sp; | ||
} task_info; | ||
|
||
void task_switch(task_info* current, task_info* next); | ||
|
||
void task_create(task_info* task, void (*entry)(void), int pid); |