mirror of
https://github.com/ivoszbg/uniLoader.git
synced 2024-11-21 11:30:06 +00:00
Compare commits
4 Commits
784bfd609a
...
2de1d3c549
Author | SHA1 | Date | |
---|---|---|---|
|
2de1d3c549 | ||
|
a244bad67f | ||
|
3b517ba95a | ||
|
be0ad76a97 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "lib/neatlibc"]
|
||||
path = lib/neatlibc
|
||||
url = https://github.com/aligrudi/neatlibc.git
|
4
Kconfig
4
Kconfig
@ -13,6 +13,10 @@ menu "Building options"
|
||||
need to set this unless you want the configured kernel build
|
||||
directory to select the cross-compiler automatically.
|
||||
|
||||
config LOGLEVEL
|
||||
int "Verbosity of logs"
|
||||
default 7
|
||||
|
||||
config EMBED_LINUX
|
||||
bool "Embed linux kernel and device tree"
|
||||
default y
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
*/
|
||||
@ -6,7 +6,16 @@
|
||||
#ifndef DEBUG_H_ /* Include guard */
|
||||
#define DEBUG_H_
|
||||
|
||||
extern void draw_text(volatile char *fb, char *text, int textX, int textY, int width, int stride);
|
||||
long int debug_linecount = 0;
|
||||
// Sorted by importance
|
||||
#define KERN_EMERG 0
|
||||
#define KERN_ALERT 1
|
||||
#define KERN_CRIT 2
|
||||
#define KERN_ERR 3
|
||||
#define KERN_WARNING 4
|
||||
#define KERN_NOTICE 5
|
||||
#define KERN_INFO 6
|
||||
#define KERN_DEBUG 7
|
||||
|
||||
#endif
|
||||
extern void printk(int loglevel, char *text);
|
||||
|
||||
#endif // DEBUG_H_
|
||||
|
1830
include/lib/font.h
1830
include/lib/font.h
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
* Copyright (c) 2022, Markuss Broks <markuss.broks@gmail.com>
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern void __simplefb_raw_print(volatile char *fb, char *text, int text_x,
|
||||
int text_y, int width, int stride);
|
||||
extern void simplefb_probe(void *data);
|
||||
extern struct video *video_info;
|
||||
|
||||
@ -34,4 +36,4 @@ typedef struct _font_params {
|
||||
|
||||
font_params get_font_params(void);
|
||||
|
||||
#endif
|
||||
#endif // SIMPLEFB_H_
|
||||
|
4503
include/lib/video/font.h
Normal file
4503
include/lib/video/font.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
*/
|
||||
@ -12,9 +12,6 @@ extern unsigned long kernel_size;
|
||||
extern void load_kernel(void* dtb, void* x1, void* x2, void* x3, void* kernel);
|
||||
extern void soc_init(void);
|
||||
|
||||
extern void clean_fb(volatile char *fb, int width, int height, int stride);
|
||||
extern void printk(char *text);
|
||||
|
||||
extern void writel(unsigned int value, void* address);
|
||||
|
||||
#endif // MAIN_H_
|
||||
|
@ -1,7 +1,7 @@
|
||||
# SIMPLEFB
|
||||
# simplefb
|
||||
lib-$(CONFIG_SIMPLE_FB) += simplefb/simplefb.o
|
||||
|
||||
# DEBUG
|
||||
# debug
|
||||
lib-y += debug/debug.o
|
||||
|
||||
# unic (neatlibc still temporarily resides)
|
||||
|
@ -1,20 +1,63 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <lib/debug.h>
|
||||
#include <lib/simplefb.h>
|
||||
#include <stddef.h>
|
||||
#include <lib/video/font.h>
|
||||
|
||||
long int debug_linecount = 0;
|
||||
|
||||
// Global log level that controls the verbosity
|
||||
static int global_loglevel = CONFIG_LOGLEVEL;
|
||||
|
||||
void printk(int log_level, char *text)
|
||||
{
|
||||
if (log_level > global_loglevel)
|
||||
return;
|
||||
|
||||
char *prefix;
|
||||
switch (log_level) {
|
||||
case KERN_EMERG:
|
||||
prefix = "[EMERG] ";
|
||||
break;
|
||||
case KERN_ALERT:
|
||||
prefix = "[ALERT] ";
|
||||
break;
|
||||
case KERN_CRIT:
|
||||
prefix = "[CRIT] ";
|
||||
break;
|
||||
case KERN_ERR:
|
||||
prefix = "[ERROR] ";
|
||||
break;
|
||||
case KERN_WARNING:
|
||||
prefix = "[WARN] ";
|
||||
break;
|
||||
case KERN_NOTICE:
|
||||
prefix = "[NOTICE] ";
|
||||
break;
|
||||
case KERN_INFO:
|
||||
prefix = "[INFO] ";
|
||||
break;
|
||||
case KERN_DEBUG:
|
||||
prefix = "[DEBUG] ";
|
||||
break;
|
||||
default:
|
||||
prefix = "[LOG] ";
|
||||
break;
|
||||
}
|
||||
|
||||
void printk(char *text) {
|
||||
#ifdef CONFIG_SIMPLE_FB
|
||||
/* IMPORTANT: Limit the linecount */
|
||||
if(debug_linecount > 100 || debug_linecount < 0)
|
||||
debug_linecount = 0;
|
||||
// Actually the first line's Y pos. Scales in __simplefb_raw_print
|
||||
int y_pos = 5;
|
||||
int prefix_width = strlen(prefix) * SCALED_FONTW;
|
||||
|
||||
draw_text((char*)CONFIG_FRAMEBUFFER_BASE, "[uniLoader] ", 0, (20 + (debug_linecount * 30)), CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE);
|
||||
draw_text((char*)CONFIG_FRAMEBUFFER_BASE, text, 0 + (12 * 8), (20 + (debug_linecount * 30)), CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE);
|
||||
|
||||
debug_linecount++;
|
||||
__simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, prefix, 0, y_pos,
|
||||
CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE);
|
||||
__simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, text, prefix_width, y_pos,
|
||||
CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE);
|
||||
#endif
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit d111f5115422bd527cb0034a0a697fd487e98e2d
|
@ -1,20 +0,0 @@
|
||||
.global htonl
|
||||
.global ntohl
|
||||
ntohl:
|
||||
htonl:
|
||||
eor x1, x0, x0, ror #16
|
||||
bic x1, x1, #0x00ff0000
|
||||
mov x0, x0, ror #8
|
||||
eor x0, x0, x1, lsr #8
|
||||
ret
|
||||
|
||||
.global htons
|
||||
.global ntohs
|
||||
ntohs:
|
||||
htons:
|
||||
mov x1, x0, lsr #8
|
||||
and x0, x0, #255
|
||||
and x1, x1, #255
|
||||
mov x0, x0, lsl #8
|
||||
orr x0, x0, x1
|
||||
ret
|
@ -1,26 +0,0 @@
|
||||
|
||||
.global __memcpylong
|
||||
__memcpylong:
|
||||
mov x12, x0 // Save the base address in x12
|
||||
memcpylong_loop:
|
||||
subs x2, x2, #4 // Decrement the counter (in bytes)
|
||||
bmi memcpylong_ret // If the counter is negative, exit
|
||||
ldr w3, [x1], #4 // Load 4 bytes from address in x1 into w3 and increment x1
|
||||
str w3, [x0], #4 // Store 4 bytes from w3 to address in x0 and increment x0
|
||||
b memcpylong_loop // Repeat the loop
|
||||
memcpylong_ret:
|
||||
mov x0, x12 // Restore the original base address
|
||||
ret // Return from function
|
||||
|
||||
.global __memsetlong
|
||||
__memsetlong:
|
||||
mov x12, x0 // Save the base address in x12
|
||||
memsetlong_loop:
|
||||
subs x2, x2, #4 // Decrement the counter (in bytes)
|
||||
bmi memsetlong_ret // If the counter is negative, exit
|
||||
str w1, [x0], #4 // Store 4 bytes of the value in w1 to address in x0 and increment x0
|
||||
b memsetlong_loop // Repeat the loop
|
||||
memsetlong_ret:
|
||||
mov x0, x12 // Restore the original base address
|
||||
ret // Return from function
|
||||
|
@ -1,167 +0,0 @@
|
||||
.global memcpy
|
||||
memcpy:
|
||||
mov x12, x0
|
||||
memcpy_loop:
|
||||
subs x2, x2, #1
|
||||
bmi memcpy_ret
|
||||
ldrb w3, [x1], #1
|
||||
strb w3, [x0], #1
|
||||
b memcpy_loop
|
||||
memcpy_ret:
|
||||
mov x0, x12
|
||||
ret
|
||||
|
||||
.global memset
|
||||
memset:
|
||||
mov x12, x0
|
||||
memset_loop:
|
||||
subs x2, x2, #1
|
||||
bmi memset_ret
|
||||
strb w1, [x0], #1
|
||||
b memset_loop
|
||||
memset_ret:
|
||||
mov x0, x12
|
||||
ret
|
||||
|
||||
.global memmove
|
||||
memmove:
|
||||
mov x12, x0
|
||||
cmp x0, x1
|
||||
ble memmove_fw
|
||||
add x3, x1, x2
|
||||
cmp x0, x3
|
||||
bgt memmove_fw
|
||||
|
||||
// copying the memory in reverse order
|
||||
add x0, x0, x2
|
||||
add x1, x1, x2
|
||||
memmove_bw:
|
||||
subs x2, x2, #1
|
||||
bmi memmove_ret
|
||||
ldrb w3, [x1, #-1]!
|
||||
strb w3, [x0, #-1]!
|
||||
b memmove_bw
|
||||
memmove_fw:
|
||||
subs x2, x2, #1
|
||||
bmi memmove_ret
|
||||
ldrb w3, [x1], #1
|
||||
strb w3, [x0], #1
|
||||
b memmove_fw
|
||||
memmove_ret:
|
||||
mov x0, x12
|
||||
ret
|
||||
|
||||
.global memchr
|
||||
memchr:
|
||||
subs x2, x2, #1
|
||||
bmi memchr_failed
|
||||
ldrb w3, [x0], #1
|
||||
cmp w3, w1
|
||||
bne memchr
|
||||
sub x0, x0, #1
|
||||
b memchr_ret
|
||||
memchr_failed:
|
||||
mov x0, #0
|
||||
memchr_ret:
|
||||
ret
|
||||
|
||||
.global memrchr
|
||||
memrchr:
|
||||
mov x12, #0
|
||||
memrchr_loop:
|
||||
subs x2, x2, #1
|
||||
bmi memrchr_ret
|
||||
ldrb w3, [x0], #1
|
||||
cmp w3, w1
|
||||
cset x12, eq
|
||||
b memrchr_loop
|
||||
memrchr_ret:
|
||||
mov x0, x12
|
||||
ret
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
subs x2, x2, #1
|
||||
bmi memcmp_match
|
||||
ldrb w3, [x0], #1
|
||||
ldrb w12, [x1], #1
|
||||
subs w3, w3, w12
|
||||
cset x0, ne
|
||||
bne memcmp_ret
|
||||
b memcmp
|
||||
memcmp_match:
|
||||
mov x0, #0
|
||||
memcmp_ret:
|
||||
ret
|
||||
|
||||
.global strlen
|
||||
strlen:
|
||||
mov x2, x0
|
||||
strlen_loop:
|
||||
ldrb w1, [x0], #1
|
||||
tst w1, w1
|
||||
bne strlen_loop
|
||||
sub x0, x0, x2
|
||||
sub x0, x0, #1
|
||||
ret
|
||||
|
||||
.global strchr
|
||||
strchr:
|
||||
ldrb w2, [x0], #1
|
||||
cmp w1, w2
|
||||
sub x0, x0, #1
|
||||
beq strchr_ret
|
||||
tst w2, w2
|
||||
bne strchr
|
||||
mov x0, #0
|
||||
strchr_ret:
|
||||
ret
|
||||
|
||||
.global strrchr
|
||||
strrchr:
|
||||
mov x3, #0
|
||||
strrchr_loop:
|
||||
ldrb w2, [x0], #1
|
||||
cmp w1, w2
|
||||
cset x3, eq
|
||||
tst w2, w2
|
||||
bne strrchr_loop
|
||||
strrchr_ret:
|
||||
mov x0, x3
|
||||
ret
|
||||
|
||||
.global strcmp
|
||||
strcmp:
|
||||
ldrb w2, [x0], #1
|
||||
ldrb w3, [x1], #1
|
||||
cmp w2, w3
|
||||
beq strcmp
|
||||
sub x0, x2, x3
|
||||
ret
|
||||
|
||||
.global strcpy
|
||||
strcpy:
|
||||
mov x3, x0
|
||||
strcpy_loop:
|
||||
ldrb w2, [x1], #1
|
||||
strb w2, [x0], #1
|
||||
tst w2, w2
|
||||
bne strcpy_loop
|
||||
mov x0, x3
|
||||
ret
|
||||
|
||||
.global strncmp
|
||||
strncmp:
|
||||
mov x12, x2
|
||||
strncmp_loop:
|
||||
subs x12, x12, #1
|
||||
cset x0, mi
|
||||
bmi strncmp_ret
|
||||
ldrb w2, [x0], #1
|
||||
ldrb w3, [x1], #1
|
||||
cmp w2, w3
|
||||
beq strncmp_loop
|
||||
sub x0, x2, x3
|
||||
strncmp_ret:
|
||||
ret
|
||||
|
@ -1,294 +0,0 @@
|
||||
__syscall:
|
||||
stp x4, x5, [sp, #-16]!
|
||||
stp x7, lr, [sp, #-16]!
|
||||
ldr x4, [sp, #32]
|
||||
ldr x5, [sp, #40]
|
||||
mov x7, x12
|
||||
svc #0
|
||||
|
||||
cmn x0, #4096
|
||||
csneg x2, x0, x0, cs
|
||||
ldr x3, =errno
|
||||
cset x0, cs
|
||||
str x2, [x3], cs
|
||||
ldp x4, x5, [sp], #16
|
||||
ldp x7, lr, [sp], #16
|
||||
ret
|
||||
|
||||
.extern errno
|
||||
|
||||
.global _exit
|
||||
_exit:
|
||||
mov x12, #1
|
||||
b __syscall
|
||||
|
||||
.global fork
|
||||
fork:
|
||||
mov x12, #2
|
||||
b __syscall
|
||||
|
||||
.global read
|
||||
read:
|
||||
mov x12, #3
|
||||
b __syscall
|
||||
|
||||
.global write
|
||||
write:
|
||||
mov x12, #4
|
||||
b __syscall
|
||||
|
||||
.global open
|
||||
open:
|
||||
mov x12, #5
|
||||
b __syscall
|
||||
|
||||
.global close
|
||||
close:
|
||||
mov x12, #6
|
||||
b __syscall
|
||||
|
||||
.global waitpid
|
||||
waitpid:
|
||||
mov x12, #7
|
||||
b __syscall
|
||||
|
||||
.global creat
|
||||
creat:
|
||||
mov x12, #8
|
||||
b __syscall
|
||||
|
||||
.global link
|
||||
link:
|
||||
mov x12, #9
|
||||
b __syscall
|
||||
|
||||
.global unlink
|
||||
unlink:
|
||||
mov x12, #10
|
||||
b __syscall
|
||||
|
||||
.global execve
|
||||
execve:
|
||||
mov x12, #11
|
||||
b __syscall
|
||||
|
||||
.global chdir
|
||||
chdir:
|
||||
mov x12, #12
|
||||
b __syscall
|
||||
|
||||
.global time
|
||||
time:
|
||||
mov x12, #13
|
||||
b __syscall
|
||||
|
||||
.global mknod
|
||||
mknod:
|
||||
mov x12, #14
|
||||
b __syscall
|
||||
|
||||
.global chmod
|
||||
chmod:
|
||||
mov x12, #15
|
||||
b __syscall
|
||||
|
||||
.global lseek
|
||||
lseek:
|
||||
mov x12, #19
|
||||
b __syscall
|
||||
|
||||
.global getpid
|
||||
getpid:
|
||||
mov x12, #20
|
||||
b __syscall
|
||||
|
||||
.global mount
|
||||
mount:
|
||||
mov x12, #21
|
||||
b __syscall
|
||||
|
||||
.global umount
|
||||
umount:
|
||||
mov x12, #22
|
||||
b __syscall
|
||||
|
||||
.global setuid
|
||||
setuid:
|
||||
mov x12, #23
|
||||
b __syscall
|
||||
|
||||
.global getuid
|
||||
getuid:
|
||||
mov x12, #24
|
||||
b __syscall
|
||||
|
||||
.global access
|
||||
access:
|
||||
mov x12, #33
|
||||
b __syscall
|
||||
|
||||
.global sync
|
||||
sync:
|
||||
mov x12, #36
|
||||
b __syscall
|
||||
|
||||
.global kill
|
||||
kill:
|
||||
mov x12, #37
|
||||
b __syscall
|
||||
|
||||
.global mkdir
|
||||
mkdir:
|
||||
mov x12, #39
|
||||
b __syscall
|
||||
|
||||
.global rmdir
|
||||
rmdir:
|
||||
mov x12, #40
|
||||
b __syscall
|
||||
|
||||
.global dup
|
||||
dup:
|
||||
mov x12, #41
|
||||
b __syscall
|
||||
|
||||
.global pipe
|
||||
pipe:
|
||||
mov x12, #42
|
||||
b __syscall
|
||||
|
||||
.global brk
|
||||
brk:
|
||||
mov x12, #45
|
||||
b __syscall
|
||||
|
||||
.global setgid
|
||||
setgid:
|
||||
mov x12, #46
|
||||
b __syscall
|
||||
|
||||
.global getgid
|
||||
getgid:
|
||||
mov x12, #47
|
||||
b __syscall
|
||||
|
||||
.global geteuid
|
||||
geteuid:
|
||||
mov x12, #49
|
||||
b __syscall
|
||||
|
||||
.global getegid
|
||||
getegid:
|
||||
mov x12, #50
|
||||
b __syscall
|
||||
|
||||
.global ioctl
|
||||
ioctl:
|
||||
mov x12, #54
|
||||
b __syscall
|
||||
|
||||
.global fcntl
|
||||
fcntl:
|
||||
mov x12, #55
|
||||
b __syscall
|
||||
|
||||
.global dup2
|
||||
dup2:
|
||||
mov x12, #63
|
||||
b __syscall
|
||||
|
||||
.global getppid
|
||||
getppid:
|
||||
mov x12, #64
|
||||
b __syscall
|
||||
|
||||
.global setsid
|
||||
setsid:
|
||||
mov x12, #66
|
||||
b __syscall
|
||||
|
||||
.global sigaction
|
||||
sigaction:
|
||||
mov x12, #67
|
||||
b __syscall
|
||||
|
||||
.global gettimeofday
|
||||
gettimeofday:
|
||||
mov x12, #78
|
||||
b __syscall
|
||||
|
||||
.global settimeofday
|
||||
settimeofday:
|
||||
mov x12, #79
|
||||
b __syscall
|
||||
|
||||
.global mmap
|
||||
mmap:
|
||||
mov x12, #192
|
||||
b __syscall
|
||||
|
||||
.global munmap
|
||||
munmap:
|
||||
mov x12, #91
|
||||
b __syscall
|
||||
|
||||
.global stat
|
||||
stat:
|
||||
mov x12, #106
|
||||
b __syscall
|
||||
|
||||
.global lstat
|
||||
lstat:
|
||||
mov x12, #107
|
||||
b __syscall
|
||||
|
||||
.global fstat
|
||||
fstat:
|
||||
mov x12, #108
|
||||
b __syscall
|
||||
|
||||
.global sigreturn
|
||||
sigreturn:
|
||||
mov x12, #119
|
||||
b __syscall
|
||||
|
||||
.global clone
|
||||
clone:
|
||||
mov x12, #120
|
||||
b __syscall
|
||||
|
||||
.global uname
|
||||
uname:
|
||||
mov x12, #122
|
||||
b __syscall
|
||||
|
||||
.global fchdir
|
||||
fchdir:
|
||||
mov x12, #133
|
||||
b __syscall
|
||||
|
||||
.global getdents
|
||||
getdents:
|
||||
mov x12, #141
|
||||
b __syscall
|
||||
|
||||
.global nanosleep
|
||||
nanosleep:
|
||||
mov x12, #162
|
||||
b __syscall
|
||||
|
||||
.global poll
|
||||
poll:
|
||||
mov x12, #168
|
||||
b __syscall
|
||||
|
||||
.global chown
|
||||
chown:
|
||||
mov x12, #182
|
||||
b __syscall
|
||||
|
||||
.global getcwd
|
||||
getcwd:
|
||||
mov x12, #183
|
||||
b __syscall
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
.global htonl
|
||||
.global ntohl
|
||||
ntohl:
|
||||
htonl:
|
||||
eor r1, r0, r0, ror #16
|
||||
bic r1, r1, #0x00ff0000
|
||||
mov r0, r0, ror #8
|
||||
eor r0, r0, r1, lsr #8
|
||||
mov pc, lr
|
||||
|
||||
.global htons
|
||||
.global ntohs
|
||||
ntohs:
|
||||
htons:
|
||||
mov r1, r0, lsr #8
|
||||
and r0, r0, #255
|
||||
and r1, r1, #255
|
||||
mov r0, r0, lsl #8
|
||||
orr r0, r0, r1
|
||||
mov pc, lr
|
@ -1,25 +0,0 @@
|
||||
|
||||
.global __memcpylong
|
||||
__memcpylong:
|
||||
mov r12, r0 @ Save the base address in r12
|
||||
memcpylong_loop:
|
||||
subs r2, r2, #4 @ Decrement the counter (in bytes)
|
||||
bmi memcpylong_ret @ If the counter is negative, exit
|
||||
ldr r3, [r1], #4 @ Load 4 bytes from address in r1 into r3 and increment r1
|
||||
str r3, [r0], #4 @ Store 4 bytes from r3 to address in r0 and increment r0
|
||||
b memcpylong_loop @ Repeat the loop
|
||||
memcpylong_ret:
|
||||
mov r0, r12 @ Restore the original base address
|
||||
mov pc, lr @ Return from function
|
||||
|
||||
.global __memsetlong
|
||||
__memsetlong:
|
||||
mov r12, r0 @ Save the base address in r12
|
||||
memsetlong_loop:
|
||||
subs r2, r2, #4 @ Decrement the counter (in bytes)
|
||||
bmi memsetlong_ret @ If the counter is negative, exit
|
||||
str r1, [r0], #4 @ Store 4 bytes of the value in r1 to address in r0 and increment r0
|
||||
b memsetlong_loop @ Repeat the loop
|
||||
memsetlong_ret:
|
||||
mov r0, r12 @ Restore the original base address
|
||||
mov pc, lr @ Return from function
|
@ -1,166 +0,0 @@
|
||||
.global memcpy
|
||||
memcpy:
|
||||
mov r12, r0
|
||||
memcpy_loop:
|
||||
subs r2, r2, #1
|
||||
bmi memcpy_ret
|
||||
ldrb r3, [r1], #1
|
||||
strb r3, [r0], #1
|
||||
b memcpy_loop
|
||||
memcpy_ret:
|
||||
mov r0, r12
|
||||
mov pc, lr
|
||||
|
||||
.global memset
|
||||
memset:
|
||||
mov r12, r0
|
||||
memset_loop:
|
||||
subs r2, r2, #1
|
||||
bmi memset_ret
|
||||
strb r1, [r0], #1
|
||||
b memset_loop
|
||||
memset_ret:
|
||||
mov r0, r12
|
||||
mov pc, lr
|
||||
|
||||
.global memmove
|
||||
memmove:
|
||||
mov r12, r0
|
||||
cmp r0, r1
|
||||
ble memmove_fw
|
||||
add r3, r1, r2
|
||||
cmp r0, r3
|
||||
bgt memmove_fw
|
||||
|
||||
@ copying the memory in reverse order
|
||||
add r0, r0, r2
|
||||
add r1, r1, r2
|
||||
memmove_bw:
|
||||
subs r2, r2, #1
|
||||
bmi memmove_ret
|
||||
ldrb r3, [r1, #-1]!
|
||||
strb r3, [r0, #-1]!
|
||||
b memmove_bw
|
||||
memmove_fw:
|
||||
subs r2, r2, #1
|
||||
bmi memmove_ret
|
||||
ldrb r3, [r1], #1
|
||||
strb r3, [r0], #1
|
||||
b memmove_fw
|
||||
memmove_ret:
|
||||
mov r0, r12
|
||||
mov pc, lr
|
||||
|
||||
.global memchr
|
||||
memchr:
|
||||
subs r2, r2, #1
|
||||
bmi memchr_failed
|
||||
ldrb r3, [r0], #1
|
||||
cmp r3, r1
|
||||
bne memchr
|
||||
sub r0, r0, #1
|
||||
b memchr_ret
|
||||
memchr_failed:
|
||||
mov r0, #0
|
||||
memchr_ret:
|
||||
mov pc, lr
|
||||
|
||||
.global memrchr
|
||||
memrchr:
|
||||
mov r12, #0
|
||||
memrchr_loop:
|
||||
subs r2, r2, #1
|
||||
bmi memrchr_ret
|
||||
ldrb r3, [r0], #1
|
||||
cmp r3, r1
|
||||
subeq r12, r0, #1
|
||||
b memrchr_loop
|
||||
memrchr_ret:
|
||||
mov r0, r12
|
||||
mov pc, lr
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
subs r2, r2, #1
|
||||
bmi memcmp_match
|
||||
ldrb r3, [r0], #1
|
||||
ldrb r12, [r1], #1
|
||||
subs r3, r3, r12
|
||||
movne r0, r3
|
||||
bne memcmp_ret
|
||||
b memcmp
|
||||
memcmp_match:
|
||||
mov r0, #0
|
||||
memcmp_ret:
|
||||
mov pc, lr
|
||||
|
||||
.global strlen
|
||||
strlen:
|
||||
mov r2, r0
|
||||
strlen_loop:
|
||||
ldrb r1, [r0], #1
|
||||
tst r1, r1
|
||||
bne strlen_loop
|
||||
sub r0, r0, r2
|
||||
sub r0, r0, #1
|
||||
mov pc, lr
|
||||
|
||||
.global strchr
|
||||
strchr:
|
||||
ldrb r2, [r0], #1
|
||||
cmp r1, r2
|
||||
subeq r0, r0, #1
|
||||
beq strchr_ret
|
||||
tst r2, r2
|
||||
bne strchr
|
||||
mov r0, #0
|
||||
strchr_ret:
|
||||
mov pc, lr
|
||||
|
||||
.global strrchr
|
||||
strrchr:
|
||||
mov r3, #0
|
||||
strrchr_loop:
|
||||
ldrb r2, [r0], #1
|
||||
cmp r1, r2
|
||||
subeq r3, r0, #1
|
||||
tst r2, r2
|
||||
bne strrchr_loop
|
||||
strrchr_ret:
|
||||
mov r0, r3
|
||||
mov pc, lr
|
||||
|
||||
.global strcmp
|
||||
strcmp:
|
||||
ldrb r2, [r0], #1
|
||||
ldrb r3, [r1], #1
|
||||
cmp r2, r3
|
||||
beq strcmp
|
||||
sub r0, r2, r3
|
||||
mov pc, lr
|
||||
|
||||
.global strcpy
|
||||
strcpy:
|
||||
mov r3, r0
|
||||
strcpy_loop:
|
||||
ldrb r2, [r1], #1
|
||||
strb r2, [r0], #1
|
||||
tst r2, r2
|
||||
bne strcpy_loop
|
||||
mov r0, r3
|
||||
mov pc, lr
|
||||
|
||||
.global strncmp
|
||||
strncmp:
|
||||
mov r12, r2
|
||||
strncmp_loop:
|
||||
subs r12, r12, #1
|
||||
movmi r0, #0
|
||||
bmi strncmp_ret
|
||||
ldrb r2, [r0], #1
|
||||
ldrb r3, [r1], #1
|
||||
cmp r2, r3
|
||||
beq strncmp_loop
|
||||
sub r0, r2, r3
|
||||
strncmp_ret:
|
||||
mov pc, lr
|
@ -1,291 +0,0 @@
|
||||
|
||||
__syscall:
|
||||
stmfd sp!, {r4, r5, r7, lr}
|
||||
ldr r4, [sp, #16]
|
||||
ldr r5, [sp, #20]
|
||||
mov r7, r12
|
||||
swi #0
|
||||
|
||||
cmn r0, #4096
|
||||
rsbcs r2, r0, #0
|
||||
ldrcs r3, =errno
|
||||
mvncs r0, #0
|
||||
strcs r2, [r3]
|
||||
ldmfd sp!, {r4, r5, r7, pc}
|
||||
|
||||
.extern errno
|
||||
|
||||
.global _exit
|
||||
_exit:
|
||||
mov r12, #1
|
||||
b __syscall
|
||||
|
||||
.global fork
|
||||
fork:
|
||||
mov r12, #2
|
||||
b __syscall
|
||||
|
||||
.global read
|
||||
read:
|
||||
mov r12, #3
|
||||
b __syscall
|
||||
|
||||
.global write
|
||||
write:
|
||||
mov r12, #4
|
||||
b __syscall
|
||||
|
||||
.global open
|
||||
open:
|
||||
mov r12, #5
|
||||
b __syscall
|
||||
|
||||
.global close
|
||||
close:
|
||||
mov r12, #6
|
||||
b __syscall
|
||||
|
||||
.global waitpid
|
||||
waitpid:
|
||||
mov r12, #7
|
||||
b __syscall
|
||||
|
||||
.global creat
|
||||
creat:
|
||||
mov r12, #8
|
||||
b __syscall
|
||||
|
||||
.global link
|
||||
link:
|
||||
mov r12, #9
|
||||
b __syscall
|
||||
|
||||
.global unlink
|
||||
unlink:
|
||||
mov r12, #10
|
||||
b __syscall
|
||||
|
||||
.global execve
|
||||
execve:
|
||||
mov r12, #11
|
||||
b __syscall
|
||||
|
||||
.global chdir
|
||||
chdir:
|
||||
mov r12, #12
|
||||
b __syscall
|
||||
|
||||
.global time
|
||||
time:
|
||||
mov r12, #13
|
||||
b __syscall
|
||||
|
||||
.global mknod
|
||||
mknod:
|
||||
mov r12, #14
|
||||
b __syscall
|
||||
|
||||
.global chmod
|
||||
chmod:
|
||||
mov r12, #15
|
||||
b __syscall
|
||||
|
||||
.global lseek
|
||||
lseek:
|
||||
mov r12, #19
|
||||
b __syscall
|
||||
|
||||
.global getpid
|
||||
getpid:
|
||||
mov r12, #20
|
||||
b __syscall
|
||||
|
||||
.global mount
|
||||
mount:
|
||||
mov r12, #21
|
||||
b __syscall
|
||||
|
||||
.global umount
|
||||
umount:
|
||||
mov r12, #22
|
||||
b __syscall
|
||||
|
||||
.global setuid
|
||||
setuid:
|
||||
mov r12, #23
|
||||
b __syscall
|
||||
|
||||
.global getuid
|
||||
getuid:
|
||||
mov r12, #24
|
||||
b __syscall
|
||||
|
||||
.global access
|
||||
access:
|
||||
mov r12, #33
|
||||
b __syscall
|
||||
|
||||
.global sync
|
||||
sync:
|
||||
mov r12, #36
|
||||
b __syscall
|
||||
|
||||
.global kill
|
||||
kill:
|
||||
mov r12, #37
|
||||
b __syscall
|
||||
|
||||
.global mkdir
|
||||
mkdir:
|
||||
mov r12, #39
|
||||
b __syscall
|
||||
|
||||
.global rmdir
|
||||
rmdir:
|
||||
mov r12, #40
|
||||
b __syscall
|
||||
|
||||
.global dup
|
||||
dup:
|
||||
mov r12, #41
|
||||
b __syscall
|
||||
|
||||
.global pipe
|
||||
pipe:
|
||||
mov r12, #42
|
||||
b __syscall
|
||||
|
||||
.global brk
|
||||
brk:
|
||||
mov r12, #45
|
||||
b __syscall
|
||||
|
||||
.global setgid
|
||||
setgid:
|
||||
mov r12, #46
|
||||
b __syscall
|
||||
|
||||
.global getgid
|
||||
getgid:
|
||||
mov r12, #47
|
||||
b __syscall
|
||||
|
||||
.global geteuid
|
||||
geteuid:
|
||||
mov r12, #49
|
||||
b __syscall
|
||||
|
||||
.global getegid
|
||||
getegid:
|
||||
mov r12, #50
|
||||
b __syscall
|
||||
|
||||
.global ioctl
|
||||
ioctl:
|
||||
mov r12, #54
|
||||
b __syscall
|
||||
|
||||
.global fcntl
|
||||
fcntl:
|
||||
mov r12, #55
|
||||
b __syscall
|
||||
|
||||
.global dup2
|
||||
dup2:
|
||||
mov r12, #63
|
||||
b __syscall
|
||||
|
||||
.global getppid
|
||||
getppid:
|
||||
mov r12, #64
|
||||
b __syscall
|
||||
|
||||
.global setsid
|
||||
setsid:
|
||||
mov r12, #66
|
||||
b __syscall
|
||||
|
||||
.global sigaction
|
||||
sigaction:
|
||||
mov r12, #67
|
||||
b __syscall
|
||||
|
||||
.global gettimeofday
|
||||
gettimeofday:
|
||||
mov r12, #78
|
||||
b __syscall
|
||||
|
||||
.global settimeofday
|
||||
settimeofday:
|
||||
mov r12, #79
|
||||
b __syscall
|
||||
|
||||
.global mmap
|
||||
mmap:
|
||||
mov r12, #192
|
||||
b __syscall
|
||||
|
||||
.global munmap
|
||||
munmap:
|
||||
mov r12, #91
|
||||
b __syscall
|
||||
|
||||
.global stat
|
||||
stat:
|
||||
mov r12, #106
|
||||
b __syscall
|
||||
|
||||
.global lstat
|
||||
lstat:
|
||||
mov r12, #107
|
||||
b __syscall
|
||||
|
||||
.global fstat
|
||||
fstat:
|
||||
mov r12, #108
|
||||
b __syscall
|
||||
|
||||
.global sigreturn
|
||||
sigreturn:
|
||||
mov r12, #119
|
||||
b __syscall
|
||||
|
||||
.global clone
|
||||
clone:
|
||||
mov r12, #120
|
||||
b __syscall
|
||||
|
||||
.global uname
|
||||
uname:
|
||||
mov r12, #122
|
||||
b __syscall
|
||||
|
||||
.global fchdir
|
||||
fchdir:
|
||||
mov r12, #133
|
||||
b __syscall
|
||||
|
||||
.global getdents
|
||||
getdents:
|
||||
mov r12, #141
|
||||
b __syscall
|
||||
|
||||
.global nanosleep
|
||||
nanosleep:
|
||||
mov r12, #162
|
||||
b __syscall
|
||||
|
||||
.global poll
|
||||
poll:
|
||||
mov r12, #168
|
||||
b __syscall
|
||||
|
||||
.global chown
|
||||
chown:
|
||||
mov r12, #182
|
||||
b __syscall
|
||||
|
||||
.global getcwd
|
||||
getcwd:
|
||||
mov r12, #183
|
||||
b __syscall
|
@ -1,16 +1,17 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
* Copyright (c) 2022, Markuss Broks <markuss.broks@gmail.com>
|
||||
* Copyright (c) 2022, Michael Srba <Michael.Srba@seznam.cz>
|
||||
*/
|
||||
#include <drivers/framework.h>
|
||||
#include <lib/font.h>
|
||||
#include <lib/simplefb.h>
|
||||
#include <string.h>
|
||||
|
||||
/* volatile char */
|
||||
static void clean_fb(void *fb, int width, int height, int stride) {
|
||||
#include <string.h>
|
||||
#include <drivers/framework.h>
|
||||
#include <lib/video/font.h>
|
||||
#include <lib/simplefb.h>
|
||||
|
||||
static void clean_fbmem(void *fb, int width, int height, int stride)
|
||||
{
|
||||
memset(fb, 0x0, (width * height * stride));
|
||||
}
|
||||
|
||||
@ -19,7 +20,8 @@ static void clean_fb(void *fb, int width, int height, int stride) {
|
||||
* Unlike ARGB8888, we explicitly use 3 bytes to represent each pixel, making sure
|
||||
* no extra padding byte is added.
|
||||
*/
|
||||
static void draw_pixel(volatile char *fb, int x, int y, int width, int stride, color c)
|
||||
static void draw_pixel(volatile char *fb, int x, int y, int width, int stride,
|
||||
color c)
|
||||
{
|
||||
long int location = (x * stride) + (y * width * stride);
|
||||
#ifdef CONFIG_FRAMEBUFFER_BGRA
|
||||
@ -35,48 +37,54 @@ static void draw_pixel(volatile char *fb, int x, int y, int width, int stride, c
|
||||
#endif
|
||||
}
|
||||
|
||||
static void draw_horizontal_line(volatile char *fb, int x1, int x2, int y, color c,
|
||||
int width, int stride)
|
||||
static int current_y = 0;
|
||||
void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y,
|
||||
int width, int stride)
|
||||
{
|
||||
for (int i = x1; i < x2; i++)
|
||||
draw_pixel(fb, i, y, width, stride, c);
|
||||
}
|
||||
|
||||
static void draw_vertical_line(volatile char *fb, int x, int y1, int y2, color c,
|
||||
int width, int stride)
|
||||
{
|
||||
for (int i = y1; i < y2; i++)
|
||||
draw_pixel(fb, x, i, width, stride, c);
|
||||
}
|
||||
|
||||
static void draw_filled_rectangle(volatile char *fb, int x1, int y1, int w, int h,
|
||||
color c, int width, int stride)
|
||||
{
|
||||
for (int i = y1; i < (y1 + h); i++)
|
||||
draw_horizontal_line(fb, x1, (x1 + w), i, c, width, stride);
|
||||
}
|
||||
|
||||
void draw_text(volatile char *fb, char *text, int textX, int textY, int width, int stride)
|
||||
{
|
||||
// loop through all characters in the text string
|
||||
int l = strlen(text);
|
||||
int current_x = text_x;
|
||||
current_y = current_y == 0 ? text_y : current_y;
|
||||
|
||||
int max_x = width - SCALED_FONTW;
|
||||
|
||||
for (int i = 0; i < l; i++) {
|
||||
// Special characters handling
|
||||
switch (text[i]) {
|
||||
case '\n':
|
||||
current_x = text_x;
|
||||
current_y += SCALED_FONTH;
|
||||
break;
|
||||
}
|
||||
|
||||
// Non-printable chars
|
||||
if (text[i] < 32)
|
||||
continue;
|
||||
|
||||
if (current_x > max_x) {
|
||||
current_x = text_x;
|
||||
current_y += SCALED_FONTH;
|
||||
}
|
||||
|
||||
int ix = font_index(text[i]);
|
||||
unsigned char *img = letters[ix];
|
||||
|
||||
// Draw the character as a scaled bitmap
|
||||
for (int y = 0; y < FONTH; y++) {
|
||||
unsigned char b = img[y];
|
||||
|
||||
for (int x = 0; x < FONTW; x++) {
|
||||
if (((b << x) & 0b10000000) > 0)
|
||||
draw_pixel(fb, textX + i * FONTW + x, textY + y, width,
|
||||
stride, (color){255, 255, 255});
|
||||
if (((b << x) & 0b10000000) > 0) {
|
||||
for (int dy = 0; dy < SCALE_FACTOR; dy++) {
|
||||
for (int dx = 0; dx < SCALE_FACTOR; dx++) {
|
||||
draw_pixel(fb, current_x + x * SCALE_FACTOR + dx,
|
||||
current_y + y * SCALE_FACTOR + dy,
|
||||
width, stride, (color){255, 255, 255});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current_x += SCALED_FONTW;
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +92,7 @@ void simplefb_probe(void *data)
|
||||
{
|
||||
struct video *fb_info = data;
|
||||
|
||||
clean_fb((char*)fb_info->address, fb_info->width, fb_info->height,
|
||||
clean_fbmem((char*)fb_info->address, fb_info->width, fb_info->height,
|
||||
fb_info->stride);
|
||||
|
||||
/* TODO: Introduce a full drivers framework that allows proper exiting */
|
||||
|
@ -99,24 +99,21 @@ char *strcpy(char *s1, const char *s2)
|
||||
return rc;
|
||||
}
|
||||
|
||||
char *strncpy(char *s1, const char *s2, size_t n)
|
||||
|
||||
char *strncpy(char *d, char *s, long n)
|
||||
{
|
||||
char *rc = s1;
|
||||
int len = strlen(s);
|
||||
if (len > n)
|
||||
len = n;
|
||||
memcpy(d, s, len);
|
||||
memset(d + len, 0, n - len);
|
||||
return d;
|
||||
}
|
||||
|
||||
while (n && (*s1++ = *s2++)) {
|
||||
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
|
||||
to check it again for >0 in the next loop below, so we must not risk
|
||||
underflow.
|
||||
*/
|
||||
--n;
|
||||
}
|
||||
|
||||
/* Checking against 1 as we missed the last --n in the loop above. */
|
||||
while (n-- > 1) {
|
||||
*s1++ = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
char *strcat(char *d, char *s)
|
||||
{
|
||||
strcpy(d + strlen(d), s);
|
||||
return d;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
|
@ -16,7 +16,8 @@
|
||||
int memcmp (const void *s1, const void *s2, size_t n);
|
||||
void *memchr (const void *s, int c, size_t n);
|
||||
char *strcpy (char *s1, const char *s2);
|
||||
char *strncpy (char *s1, const char *s2, size_t n);
|
||||
char *strncpy (char *d, char *s, long n);
|
||||
char *strcat (char *d, char *s);
|
||||
int strcmp (const char *s1, const char *s2);
|
||||
int strncmp (const char *s1, const char *s2, size_t n);
|
||||
size_t strlen (const char *s);
|
||||
|
17
main/main.c
17
main/main.c
@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
|
||||
*/
|
||||
@ -6,6 +6,7 @@
|
||||
#include <board.h>
|
||||
#include <main.h>
|
||||
#include <string.h>
|
||||
#include <lib/debug.h>
|
||||
|
||||
/*
|
||||
* Provide an empty board config that has
|
||||
@ -31,15 +32,23 @@ void main(void* dt, void* kernel)
|
||||
EXECUTE_BOARD_OP(board.ops[BOARD_OP_DRIVER_SETUP]);
|
||||
EXECUTE_BOARD_OP(board.ops[BOARD_OP_LATE_INIT]);
|
||||
|
||||
printk("Passed board initialization!");
|
||||
printk("Welcome to uniLoader!");
|
||||
printk(-1, " .__.____ .___\n");
|
||||
printk(-1, " __ __ ____ |__| | _________ __| _/___________\n");
|
||||
printk(-1, "| | \\/ \\| | | / _ \\__ \\ / __ |/ __ \\_ __\\\n");
|
||||
printk(-1, "| | / | \\ | |__( <_> ) __ \\_/ /_/ \\ ___/| |\\/\n");
|
||||
printk(-1, "|____/|___| /__|_______ \\____(____ /\\____ |\\___ >__|\n");
|
||||
printk(-1, " \\/ \\/ \\/ \\/ \\/\n");
|
||||
|
||||
printk(-1, "Passed board initialization!\n");
|
||||
printk(-1, "Welcome to uniLoader!\n");
|
||||
|
||||
/* Copy kernel to memory and boot */
|
||||
printk("Booting linux...");
|
||||
printk(-1, "Booting linux...\n");
|
||||
|
||||
memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size);
|
||||
load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY);
|
||||
|
||||
/* We shouldn't get there */
|
||||
printk(KERN_WARNING, "Something wrong happened, we shouldn't be here. Hanging....\n");
|
||||
while(1) {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user