-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from dinosaure/better-boot-S
Better boot.S and link script
- Loading branch information
Showing
9 changed files
with
147 additions
and
222 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,19 @@ | ||
#include <string.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
#define WT size_t | ||
#define WS (sizeof(WT)) | ||
|
||
void *memmove(void *dest, const void *src, size_t n) | ||
void *memmove(void *v_dst, const void *v_src, size_t len) | ||
{ | ||
char *d = dest; | ||
const char *s = src; | ||
char *dst = v_dst; | ||
const char *src = v_src; | ||
|
||
if (d==s) return d; | ||
if (s+n <= d || d+n <= s) return memcpy(d, s, n); | ||
if (dst == src) return dst; | ||
if (src + len <= dst || dst + len <= src) return memcpy(dst, src, len) ; | ||
|
||
if (d<s) { | ||
if ((uintptr_t)s % WS == (uintptr_t)d % WS) { | ||
while ((uintptr_t)d % WS) { | ||
if (!n--) return dest; | ||
*d++ = *s++; | ||
} | ||
for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; | ||
} | ||
for (; n; n--) *d++ = *s++; | ||
} else { | ||
if ((uintptr_t)s % WS == (uintptr_t)d % WS) { | ||
while ((uintptr_t)(d+n) % WS) { | ||
if (!n--) return dest; | ||
d[n] = s[n]; | ||
} | ||
while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); | ||
} | ||
while (n) n--, d[n] = s[n]; | ||
} | ||
if (dst < src) | ||
for (; len; len--) *dst++ = *src++; | ||
else | ||
while (len) len--, dst[len] = src[len]; | ||
|
||
return dest; | ||
return dst; | ||
} |
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,27 +1,36 @@ | ||
// AArch64 mode | ||
.macro ADR_REL register, symbol | ||
adrp \register, \symbol | ||
add \register, \register, #:lo12:\symbol | ||
.endm | ||
|
||
// To keep this in the first portion of the binary. | ||
.section ".text.boot" | ||
.globl _start | ||
.equ _core_id_mask, 0b11 | ||
|
||
.section .text._start | ||
|
||
// Entry point for the kernel. Registers: | ||
// x0 -> 32 bit pointer to DTB in memory (primary core only) / 0 (secondary cores) | ||
// x1 -> 0 | ||
// x2 -> 0 | ||
// x3 -> 0 | ||
// x4 -> 32 bit kernel entry point, _start location | ||
_start: | ||
mov sp, #0x30000000 | ||
mrs x1, MPIDR_EL1 | ||
and x1, x1, _core_id_mask | ||
mov x2, #0 | ||
cmp x1, x2 | ||
b.ne .L_parking_loop | ||
.L_bss_init_loop: | ||
ADR_REL x0, __bss_start | ||
ADR_REL x1, __bss_end_exclusive | ||
.L_bss_loop: | ||
cmp x0, x1 | ||
b.eq .L_prepare_c | ||
stp xzr, xzr, [x0], #16 | ||
b .L_bss_loop | ||
.L_prepare_c: | ||
ADR_REL x0, __boot_core_stack_end_exclusive | ||
mov sp, x0 | ||
.L_jump: | ||
bl _start_c | ||
b .L_parking_loop | ||
.L_parking_loop: | ||
wfe | ||
b .L_parking_loop | ||
|
||
// clear bss | ||
ldr x5, =__bss_start | ||
ldr w6, =__bss_size | ||
3: cbz w6, 4f | ||
str xzr, [x5], #8 | ||
sub w6, w6, #1 | ||
cbnz w6, 3b | ||
|
||
// jump to C code, should not return | ||
4: bl kernel_main | ||
1: wfe | ||
b 1b | ||
.size _start, . - _start | ||
.type _start, function | ||
.global _start |
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,11 +1,3 @@ | ||
#include <stddef.h> | ||
|
||
void *memset(void *dest, int c, size_t n); | ||
void *memcpy(void *restrict dest, const void *restrict src, size_t n); | ||
void *memmove(void *dest, const void *src, size_t n); | ||
int memcmp(const void *vl, const void *vr, size_t n); | ||
int strcmp(const char *l, const char *r); | ||
int strncmp(const char *l, const char *r, size_t n); | ||
char *strcpy(char *restrict dest, const char *restrict src); | ||
size_t strlen(const char *s); | ||
int isspace(int c); |
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
Oops, something went wrong.