create simple kernel in C with a linker script
This commit is contained in:
29
kernel.c
Normal file
29
kernel.c
Normal file
@@ -0,0 +1,29 @@
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef uint32_t size_t;
|
||||
|
||||
extern char __bss[], __bss_end[], __stack_top[];
|
||||
|
||||
void *memset(void *buf, char c, size_t n) {
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
while (n--)
|
||||
*p++ = c;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void kernel_main(void) {
|
||||
memset(__bss, 0, (size_t) __bss_end - (size_t) __bss);
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
__attribute__((section(".text.boot")))
|
||||
__attribute__((naked))
|
||||
void boot(void) {
|
||||
__asm__ __volatile__(
|
||||
"mv sp, %[stack_top]\n" // Set stacker point
|
||||
"j kernel_main\n" // Jump to the kernel function
|
||||
:
|
||||
: [stack_top] "r" (__stack_top) // Pass the stack top address as %[stack_top]
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user