some lib docs
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
#include <arch.h>
|
#include <arch.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
|
|
||||||
// In arch code, make sure arch_api.panic and arch_api.console.putchar is set up befire calling
|
// Make sure `arch_api.panic` and `arch_api.console.putchar` is intialized if calling from architecure-specific code.
|
||||||
|
// Will be compiled out if `DEBUG` is not defined.
|
||||||
static inline void assert(bool condition, const char* msg)
|
static inline void assert(bool condition, const char* msg)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
@@ -3,6 +3,23 @@
|
|||||||
#include <def.h>
|
#include <def.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// Make sure `arch_api.console.putchar` is intialized if calling from architecure-specific code.
|
||||||
|
//
|
||||||
|
// Supported formats:
|
||||||
|
// - `d`: i64 (decimal)
|
||||||
|
// - `u`: u64 (decimal)
|
||||||
|
// - `x`: u64 (hex)
|
||||||
|
// - `c`: char (ascii)
|
||||||
|
// - `s`: char* (ascii string)
|
||||||
|
//
|
||||||
|
// ```c
|
||||||
|
// printf(
|
||||||
|
// "The answer is %d is located at offset %x in file %s",
|
||||||
|
// 42,
|
||||||
|
// 0x2000
|
||||||
|
// "hitchhiker.txt"
|
||||||
|
// );
|
||||||
|
// ```
|
||||||
void printf(const char* fmt, ...)
|
void printf(const char* fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ void reverse(char* str, size_t length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ```c
|
||||||
|
// char buffer[21];
|
||||||
|
// itoa64(-1234, buffer);
|
||||||
|
// ```
|
||||||
void itoa64(i64 value, char* buffer)
|
void itoa64(i64 value, char* buffer)
|
||||||
{
|
{
|
||||||
char temp[21];
|
char temp[21];
|
||||||
@@ -75,6 +79,10 @@ void itoa64(i64 value, char* buffer)
|
|||||||
buffer[j] = '\0';
|
buffer[j] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ```c
|
||||||
|
// char buffer[21];
|
||||||
|
// uitoa64(1234, buffer);
|
||||||
|
// ```
|
||||||
void uitoa64(u64 value, char* buffer)
|
void uitoa64(u64 value, char* buffer)
|
||||||
{
|
{
|
||||||
char temp[21];
|
char temp[21];
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
int strcmp(const char* a, const char* b);
|
int strcmp(const char* a, const char* b);
|
||||||
void reverse(char* str, size_t length);
|
void reverse(char* str, size_t length);
|
||||||
|
|
||||||
void uitoa64(u64 value, char* buffer);
|
|
||||||
void itoa64(i64 value, char* buffer);
|
void itoa64(i64 value, char* buffer);
|
||||||
|
void uitoa64(u64 value, char* buffer);
|
||||||
void uitoa64_hex(u64 value, char* buffer);
|
void uitoa64_hex(u64 value, char* buffer);
|
||||||
Reference in New Issue
Block a user