-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrap an init task which holds at least the initial stack that is to be used when setting up the registers (such as `sp` and `tp`). In order to guarantee that the stack and the rest of the registers are set up correctly, this commit also provides a raw implementation of a `printk` function. Moreover, this commit also adds an argument that must be passed to `start_kernel`, which is the pointer to the embedded `fdt` blob. This argument will be used by later work so to fetch, at least, the base address for the initial ram disk. This was also used to test that the stack was working as expected. Signed-off-by: Miquel Sabaté Solà <[email protected]>
- Loading branch information
Showing
8 changed files
with
135 additions
and
24 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
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,9 +1,30 @@ | ||
#ifndef __FBOS_COMPILER_H | ||
#define __FBOS_COMPILER_H | ||
|
||
/* | ||
* Nicer looking versions of compiler attributes. | ||
*/ | ||
|
||
#define __noreturn __attribute__((__noreturn__)) | ||
|
||
/* | ||
* Compiler attributes specific to linker sections. | ||
*/ | ||
|
||
#define __section(s) __attribute__((__section__(s))) | ||
#define __kernel __section(".text.kernel") | ||
#define __kernel __section(".kernel.text") | ||
|
||
/* | ||
* Multiple aliases for 64-bit integers which have their definition on the | ||
* standard library. | ||
*/ | ||
|
||
typedef long ssize_t; | ||
typedef unsigned long size_t; | ||
typedef unsigned long uint64_t; | ||
typedef unsigned long uintptr_t; | ||
|
||
// Helpful macro when prototyping. | ||
#define __unused(x) (void)x | ||
|
||
#endif /* __FBOS_COMPILER_H */ |
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,8 +1,11 @@ | ||
#ifndef FBOS_INIT_H | ||
#define FBOS_INIT_H | ||
#ifndef __FBOS_INIT_H | ||
#define __FBOS_INIT_H | ||
|
||
#include <fbos/compiler.h> | ||
|
||
extern __noreturn __kernel void start_kernel(void); | ||
extern struct task_struct init_task; | ||
|
||
#endif /* FBOS_INIT_H */ | ||
// The entry point for the kernel. | ||
__noreturn __kernel void start_kernel(uintptr_t *dtb); | ||
|
||
#endif /* __FBOS_INIT_H */ |
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,16 +1,23 @@ | ||
#ifndef FBOS_MM_H | ||
#define FBOS_MM_H | ||
#ifndef __FBOS_MM_H | ||
#define __FBOS_MM_H | ||
|
||
/* | ||
* Page = 4KB. | ||
*/ | ||
#define PAGE_SIZE 0x1000 | ||
|
||
/* | ||
* Initial size of the thread, which coincides with the size of the stack for a | ||
* given thread. | ||
*/ | ||
#define THREAD_SIZE_ORDER 2 | ||
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) | ||
|
||
/* | ||
* The code will be linked to start at the first page, which will have a given | ||
* offset. | ||
*/ | ||
#define PAGE_OFFSET 0x80200000 | ||
#define LINK_ADDR PAGE_OFFSET | ||
|
||
#endif /* FBOS_MM_H */ | ||
#endif /* __FBOS_MM_H */ |
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,6 +1,55 @@ | ||
#include <fbos/mm.h> | ||
|
||
.global _start | ||
.section .text.head | ||
.section .head.text | ||
|
||
_start: | ||
// TODO | ||
call start_kernel | ||
// Mask all interrupts | ||
csrw sie, zero | ||
csrw sip, zero | ||
|
||
// Flush the instruction cache | ||
fence.i | ||
|
||
// Reset all registers except ra, a0, a1. | ||
li sp, 0 | ||
li gp, 0 | ||
li tp, 0 | ||
li t0, 0 | ||
li t1, 0 | ||
li t2, 0 | ||
li s0, 0 | ||
li s1, 0 | ||
li a2, 0 | ||
li a3, 0 | ||
li a4, 0 | ||
li a5, 0 | ||
li a6, 0 | ||
li a7, 0 | ||
li s2, 0 | ||
li s3, 0 | ||
li s4, 0 | ||
li s5, 0 | ||
li s6, 0 | ||
li s7, 0 | ||
li s8, 0 | ||
li s9, 0 | ||
li s10, 0 | ||
li s11, 0 | ||
li t3, 0 | ||
li t4, 0 | ||
li t5, 0 | ||
li t6, 0 | ||
csrw sscratch, 0 | ||
|
||
// Point tp and sp to the init task. | ||
la tp, init_task | ||
la sp, init_task + THREAD_SIZE | ||
|
||
// The `start_kernel` function requires an argument to be passed, which is | ||
// the pointer to the `fdt` blob. The bootloader puts this on the `a1` | ||
// register, so let's move it now to `a0`. | ||
mv a0, a1 | ||
|
||
// Start the kernel. | ||
tail start_kernel |
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,12 +1,28 @@ | ||
#include <fbos/init.h> | ||
#include <fbos/printk.h> | ||
#include <fbos/mm.h> | ||
#include <fbos/sched.h> | ||
#include <fbos/dt.h> | ||
|
||
unsigned long init_stack[THREAD_SIZE / sizeof(unsigned long)]; | ||
|
||
struct task_struct init_task = { .stack = init_stack }; | ||
|
||
/* | ||
* This is the main entry point of the kernel after head.S is done. This | ||
* function can (and will) assume that everything has been reset and that we can | ||
* start the whole thing. | ||
*/ | ||
__noreturn __kernel void start_kernel(void) | ||
__noreturn __kernel void start_kernel(uintptr_t *dtb) | ||
{ | ||
// TODO: disable irqs, etc. | ||
|
||
printk("Welcome to FizzBuzz OS!\n"); | ||
|
||
parse_dtb(dtb); | ||
|
||
// TODO: reenable stuff | ||
|
||
for (;;) | ||
; | ||
} |