mirror of https://github.com/flysand7/ciabatta.git
Hide dbg_printfs behind a define
This commit is contained in:
parent
a812a18033
commit
845d08ee3a
2
build.py
2
build.py
|
@ -273,7 +273,7 @@ if target == 'linux':
|
||||||
print_step(f'Compiling {dl_lib}\n')
|
print_step(f'Compiling {dl_lib}\n')
|
||||||
assemble('src/loader/loader-entry.asm', 'bin/loader-entry.o')
|
assemble('src/loader/loader-entry.asm', 'bin/loader-entry.o')
|
||||||
compile(['bin/loader-entry.o', 'src/loader/loader-self-reloc.c', 'src/loader/loader.c'], dl_lib,
|
compile(['bin/loader-entry.o', 'src/loader/loader-self-reloc.c', 'src/loader/loader.c'], dl_lib,
|
||||||
'-shared -nostdlib -Wl,-e,_dlstart -Wl,--sort-section,alignment -Wl,--sort-common -Wl,--gc-sections -Wl,--hash-style=both -Wl,--no-undefined -Wl,--exclude-libs=ALL -fno-stack-protector')
|
'-ffreestanding -shared -nostdlib -Wl,-e,_dlstart -Wl,--sort-section,alignment -Wl,--sort-common -Wl,--gc-sections -Wl,--hash-style=both -Wl,--no-undefined -Wl,--exclude-libs=ALL -fno-stack-protector')
|
||||||
|
|
||||||
print_step(f'Compiling {crt_file}\n')
|
print_step(f'Compiling {crt_file}\n')
|
||||||
if target == 'linux':
|
if target == 'linux':
|
||||||
|
|
|
@ -16,30 +16,27 @@
|
||||||
#include <cia-def.h>
|
#include <cia-def.h>
|
||||||
#include <bin/elf.h>
|
#include <bin/elf.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define AUX_CNT 32
|
#define AUX_CNT 32
|
||||||
#define DYN_CNT 37
|
#define DYN_CNT 37
|
||||||
|
|
||||||
#include <stdarg.h>
|
static void print_string_n(char *str, u64 len) {
|
||||||
static void _dbg_print_char(char c) {
|
sys_write(STDOUT_FILENO, str, len);
|
||||||
sys_write(STDOUT_FILENO, &c, 1);
|
|
||||||
}
|
}
|
||||||
|
static void print_char(char c) {
|
||||||
static void _dbg_print_string(char *str) {
|
print_string_n(&c, 1);
|
||||||
|
}
|
||||||
|
static void print_string(char *str) {
|
||||||
int str_len = 0;
|
int str_len = 0;
|
||||||
while(str[str_len] != 0) {
|
while(str[str_len] != 0) {
|
||||||
str_len += 1;
|
str_len += 1;
|
||||||
}
|
}
|
||||||
sys_write(STDOUT_FILENO, str, str_len);
|
print_string_n(str, str_len);
|
||||||
}
|
}
|
||||||
|
static void print_int(i64 number) {
|
||||||
static void _dbg_print_string_n(char *str, u64 len) {
|
|
||||||
sys_write(STDOUT_FILENO, str, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _dbg_print_int(i64 number) {
|
|
||||||
if(number < 0) {
|
if(number < 0) {
|
||||||
_dbg_print_char('-');
|
print_char('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
@ -49,10 +46,9 @@ static void _dbg_print_int(i64 number) {
|
||||||
*--p = (number%10) + '0';
|
*--p = (number%10) + '0';
|
||||||
number /= 10;
|
number /= 10;
|
||||||
} while(number > 0);
|
} while(number > 0);
|
||||||
_dbg_print_string(p);
|
print_string(p);
|
||||||
}
|
}
|
||||||
|
static void print_uint(u64 number) {
|
||||||
static void _dbg_print_uint(u64 number) {
|
|
||||||
char buf[20];
|
char buf[20];
|
||||||
buf[19] = 0;
|
buf[19] = 0;
|
||||||
char *p = buf + sizeof buf - 1;
|
char *p = buf + sizeof buf - 1;
|
||||||
|
@ -60,11 +56,10 @@ static void _dbg_print_uint(u64 number) {
|
||||||
*--p = (number%10) + '0';
|
*--p = (number%10) + '0';
|
||||||
number /= 10;
|
number /= 10;
|
||||||
} while(number > 0);
|
} while(number > 0);
|
||||||
_dbg_print_string(p);
|
print_string(p);
|
||||||
}
|
}
|
||||||
|
static void print_hex(u64 number) {
|
||||||
static void _dbg_print_hex(u64 number) {
|
// print_string("0x");
|
||||||
// _dbg_print_string("0x");
|
|
||||||
char digits[] = "0123456789abcdef";
|
char digits[] = "0123456789abcdef";
|
||||||
char buf[20];
|
char buf[20];
|
||||||
buf[19] = 0;
|
buf[19] = 0;
|
||||||
|
@ -77,10 +72,9 @@ static void _dbg_print_hex(u64 number) {
|
||||||
char digit = digits[bits];
|
char digit = digits[bits];
|
||||||
*--p = digit;
|
*--p = digit;
|
||||||
}
|
}
|
||||||
_dbg_print_string(p);
|
print_string(p);
|
||||||
}
|
}
|
||||||
|
static void printf(char *fmt, ...) {
|
||||||
static void _dbg_printf(char *fmt, ...) {
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
char str_buf[256];
|
char str_buf[256];
|
||||||
|
@ -92,29 +86,29 @@ static void _dbg_printf(char *fmt, ...) {
|
||||||
fmt++;
|
fmt++;
|
||||||
}
|
}
|
||||||
str_buf[buf_i] = 0;
|
str_buf[buf_i] = 0;
|
||||||
_dbg_print_string_n(str_buf, buf_i);
|
print_string_n(str_buf, buf_i);
|
||||||
buf_i = 0;
|
buf_i = 0;
|
||||||
if(*fmt == '%') {
|
if(*fmt == '%') {
|
||||||
++fmt;
|
++fmt;
|
||||||
if(*fmt == 'd') {
|
if(*fmt == 'd') {
|
||||||
i64 number = va_arg(args, i64);
|
i64 number = va_arg(args, i64);
|
||||||
_dbg_print_int(number);
|
print_int(number);
|
||||||
}
|
}
|
||||||
else if(*fmt == 'u') {
|
else if(*fmt == 'u') {
|
||||||
u64 number = va_arg(args, u64);
|
u64 number = va_arg(args, u64);
|
||||||
_dbg_print_uint(number);
|
print_uint(number);
|
||||||
}
|
}
|
||||||
else if(*fmt == 'x') {
|
else if(*fmt == 'x') {
|
||||||
u64 number = va_arg(args, u64);
|
u64 number = va_arg(args, u64);
|
||||||
_dbg_print_hex(number);
|
print_hex(number);
|
||||||
}
|
}
|
||||||
else if(*fmt == 's') {
|
else if(*fmt == 's') {
|
||||||
char *str = va_arg(args, char *);
|
char *str = va_arg(args, char *);
|
||||||
_dbg_print_string(str);
|
print_string(str);
|
||||||
}
|
}
|
||||||
else if(*fmt == 'c') {
|
else if(*fmt == 'c') {
|
||||||
int c = va_arg(args, int);
|
int c = va_arg(args, int);
|
||||||
_dbg_print_char(c);
|
print_char(c);
|
||||||
}
|
}
|
||||||
++fmt;
|
++fmt;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +116,24 @@ static void _dbg_printf(char *fmt, ...) {
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
#define _dbg_print_char(c) print_char(c)
|
||||||
|
#define _dbg_print_string(s) print_string(s)
|
||||||
|
#define _dbg_print_string_n(s,n) print_string_n(s,n)
|
||||||
|
#define _dbg_print_int(d) print_int(d)
|
||||||
|
#define _dbg_print_uint(u) print_uint(u)
|
||||||
|
#define _dbg_print_hex(x) print_hex(x)
|
||||||
|
#define _dbg_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define _dbg_print_char(c) do {} while(0)
|
||||||
|
#define _dbg_print_string(s) do {} while(0)
|
||||||
|
#define _dbg_print_string_n(s,n) do {} while(0)
|
||||||
|
#define _dbg_print_int(d) do {} while(0)
|
||||||
|
#define _dbg_print_uint(u) do {} while(0)
|
||||||
|
#define _dbg_print_hex(x) do {} while(0)
|
||||||
|
#define _dbg_printf(fmt, ...) do {} while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void loader_entry(u64 *sp, u64 *dyn, u64 *aux);
|
extern void loader_entry(u64 *sp, u64 *dyn, u64 *aux);
|
||||||
|
|
||||||
void _dlstart_reloc_c(u64 *sp, Elf64_Dyn *dynv) {
|
void _dlstart_reloc_c(u64 *sp, Elf64_Dyn *dynv) {
|
||||||
|
|
Loading…
Reference in New Issue