8#define INT_ENABLE_OFFSET 1
9#define SERIAL_BUFFER2_SIZE (4096 * 3)
10#define SERIAL_BUFFER2_MASK (SERIAL_BUFFER2_SIZE - 1)
13#define SLOT_WRITING 0xFE
15#define SLOT_DROPPED 0xFF
17#define SLOT_EMPTY 0x00
20#define SPIN_LIMIT 10000u
62 __asm__
volatile(
"pause");
68 for (
int i = 0;
str[i] !=
'\0'; i++)
76 const char* digits =
"0123456789ABCDEF";
79 bool negative =
false;
82 if (
base == 10 && num < 0) {
101 for (
int j = i - 1; j >= 0; j--)
126 head = __atomic_load_n(&
__buffer.head, __ATOMIC_RELAXED);
127 tail = __atomic_load_n(&
__buffer.tail, __ATOMIC_ACQUIRE);
133 true, __ATOMIC_ACQ_REL,
138 __asm__
volatile(
"pause");
169 while (__atomic_load_n(&entry->
len, __ATOMIC_ACQUIRE) !=
SLOT_EMPTY) {
180 __asm__
volatile(
"pause");
194 __atomic_store_n(&entry->
len,
len, __ATOMIC_RELEASE);
202 const char* digits =
"0123456789ABCDEF";
205 bool negative =
false;
207 if (
base == 10 && num < 0) {
217 while (n > 0 && i < 64) {
223 if (negative && i < 64)
228 __builtin_memset(buf2, 0,
sizeof(buf2));
229 for (
int j = i - 1; j >= 0; j--)
230 buf2[i - j - 1] = buf[j];
236 const char* digits =
"0123456789ABCDEF";
250 while (n > 0 && i < 64) {
256 int count = (limit > 0 && limit < i) ? limit : i;
257 int start = i -
count;
261 for (
int j = end; j >= start; j--)
262 buf2[end - j] = buf[j];
272 char temp_buffer[128];
275 for (
const char* p = fmt; *p !=
'\0'; p++) {
277 temp_buffer[temp_index++] = *p;
278 if (temp_index == 128) {
285 if (temp_index > 0) {
292 int i = __builtin_va_arg(args,
int);
294 }
else if (*p ==
'l') {
299 }
else if (*p ==
'd') {
303 }
else if (*p ==
'p') {
306 }
else if (*p ==
'x') {
309 }
else if (*p ==
's') {
310 char* s = __builtin_va_arg(args,
char*);
316 (slen > 128) ? 128 : (
uint8_t) slen;
319 }
else if (*p ==
'b') {
322 }
else if (*p ==
'B') {
323 int i = __builtin_va_arg(args,
int);
328 }
else if (*p ==
'.') {
331 while (*p >=
'0' && *p <=
'9') {
332 precision = precision * 10 + (*p -
'0');
361 if (__atomic_test_and_set(&
__flush_lock, __ATOMIC_ACQUIRE))
366 __atomic_load_n(&
__buffer.tail, __ATOMIC_RELAXED);
368 __atomic_load_n(&
__buffer.head, __ATOMIC_ACQUIRE);
380 len = __atomic_load_n(&entry->
len, __ATOMIC_ACQUIRE);
387 __asm__
volatile(
"pause");
401 __atomic_store_n(&
__buffer.tail,
tail + 1, __ATOMIC_RELEASE);
412 const char* digits =
"0123456789ABCDEF";
426 for (
int p = i; p <
width; p++)
429 for (
int j = i - 1; j >= 0; j--)
434 for (
const char* p = fmt; *p !=
'\0'; p++) {
448 while (*p >=
'0' && *p <=
'9') {
457 while (*p >=
'0' && *p <=
'9') {
458 precision = precision * 10 + (*p -
'0');
464 bool is_long =
false;
473 is_long ? __builtin_va_arg(args,
int64_t)
474 : (
int64_t) __builtin_va_arg(args,
int);
507 char* s = __builtin_va_arg(args,
char*);
514 int i = __builtin_va_arg(args,
int);
519 char c = (char) __builtin_va_arg(args,
int);
546 __builtin_va_list args;
547 __builtin_va_start(args, fmt);
552 __builtin_va_end(args);
562 __builtin_va_list args;
563 __builtin_va_start(args, fmt);
565 __builtin_va_end(args);
boolean_t multicore_start
elf_section_map uintptr_t base
static uint8_t inb(uint16_t port)
static void outb(uint16_t port, uint8_t value)
void serial_printf(const char *fmt,...)
void serial2_printf(const char *fmt,...)
static void irq_restore(uintptr_t flags)
static uintptr_t irq_save(void)
static void serial2_send_unsigned_number(uint64_t num, int base, int limit)
int serial_is_transmit_empty(void)
static void parse_before_multicore(__builtin_va_list args, const char *fmt)
#define SERIAL_BUFFER2_SIZE
static spinlock_t __serial2_producer_lock
static serial_ring_buffer_t __buffer
void parse_multicore(__builtin_va_list args, const char *fmt)
#define INT_ENABLE_OFFSET
static volatile unsigned char __flush_lock
static bool reserve_slot(uint32_t *out_idx)
static void serial_send_padded(uint64_t val, int base, int width, char pad)
void serial_send_string(char *str)
static void put_into_buffer(const char *str, uint8_t len)
void serial_send_number(int64_t num, int base)
#define SERIAL_BUFFER2_MASK
static void serial2_send_number(int64_t num, int base)
void spin_acquire(spinlock_t *lock)
void spin_release(spinlock_t *lock)
size_t strlen(const char *s)
kstring str(const char *str)
serial_entry_t buffer[(4096 *3)]