mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 12:34:26 +01:00
baremetal: implement C assert
This commit is contained in:
1
baremetal/assert_fail.c
Symbolic link
1
baremetal/assert_fail.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../lkmc/assert_fail.c
|
||||
@@ -13,13 +13,55 @@ enum {
|
||||
|
||||
int _close(int file) { return -1; }
|
||||
|
||||
void _exit(int status) {
|
||||
#if defined(GEM5)
|
||||
LKMC_M5OPS_EXIT;
|
||||
#else
|
||||
#if defined(__arm__)
|
||||
__asm__ __volatile__ (
|
||||
"mov r0, #0x18\n"
|
||||
"ldr r1, =#0x20026\n"
|
||||
"svc 0x00123456\n"
|
||||
:
|
||||
:
|
||||
: "r0", "r1"
|
||||
);
|
||||
#elif defined(__aarch64__)
|
||||
/* TODO actually use the exit value here, just for fun. */
|
||||
__asm__ __volatile__ (
|
||||
"mov x1, #0x26\n" \
|
||||
"movk x1, #2, lsl #16\n" \
|
||||
"str x1, [sp,#0]\n" \
|
||||
"mov x0, #0\n" \
|
||||
"str x0, [sp,#8]\n" \
|
||||
"mov x1, sp\n" \
|
||||
"mov w0, #0x18\n" \
|
||||
"hlt 0xf000\n"
|
||||
:
|
||||
:
|
||||
: "x0", "x1"
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fstat(int file, struct stat *st) {
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Required by assert. */
|
||||
int _getpid(void) { return 0; }
|
||||
|
||||
/* Required by assert. */
|
||||
int _kill(pid_t pid, int sig) {
|
||||
exit(128 + sig);
|
||||
}
|
||||
|
||||
int _isatty(int file) { return 1; }
|
||||
|
||||
int _lseek(int file, int ptr, int dir) { return 0; }
|
||||
|
||||
int _open(const char *name, int flags, int mode) { return -1; }
|
||||
|
||||
int _read(int file, char *ptr, int len) {
|
||||
@@ -61,35 +103,3 @@ int _write(int file, char *ptr, int len) {
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void _exit(int status) {
|
||||
#if defined(GEM5)
|
||||
LKMC_M5OPS_EXIT;
|
||||
#else
|
||||
#if defined(__arm__)
|
||||
__asm__ __volatile__ (
|
||||
"mov r0, #0x18\n"
|
||||
"ldr r1, =#0x20026\n"
|
||||
"svc 0x00123456\n"
|
||||
:
|
||||
:
|
||||
: "r0", "r1"
|
||||
);
|
||||
#elif defined(__aarch64__)
|
||||
/* TODO actually use the exit value here, just for fun. */
|
||||
__asm__ __volatile__ (
|
||||
"mov x1, #0x26\n" \
|
||||
"movk x1, #2, lsl #16\n" \
|
||||
"str x1, [sp,#0]\n" \
|
||||
"mov x0, #0\n" \
|
||||
"str x0, [sp,#8]\n" \
|
||||
"mov x1, sp\n" \
|
||||
"mov w0, #0x18\n" \
|
||||
"hlt 0xf000\n"
|
||||
:
|
||||
:
|
||||
: "x0", "x1"
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
../lkmc/assert_fail.c
|
||||
../lkmc/lkmc_assert_fail.c
|
||||
Reference in New Issue
Block a user