Compare commits
4 changed files with 38 additions and 133 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#define GATE_INTR_DPL3 0xEE
|
#define GATE_INTR_DPL3 0xEE
|
||||||
|
|
||||||
|
|
||||||
#include <kernel/common.h>
|
#include <kernel/common.h>
|
||||||
|
|
||||||
struct cpu_local;
|
struct cpu_local;
|
||||||
|
|
@ -89,7 +90,6 @@ extern struct irq_desc __idt[64];
|
||||||
|
|
||||||
void gdt_init();
|
void gdt_init();
|
||||||
void idt_init();
|
void idt_init();
|
||||||
void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment, void *func);
|
|
||||||
void tss_init(int cpu_id, struct cpu_local *local);
|
void tss_init(int cpu_id, struct cpu_local *local);
|
||||||
|
|
||||||
#endif /* _DESCRIPTOR_H_ */
|
#endif /* _DESCRIPTOR_H_ */
|
||||||
|
|
|
||||||
|
|
@ -81,27 +81,6 @@ static void timer_handler()
|
||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipi_handle_kill()
|
|
||||||
{
|
|
||||||
schedule();
|
|
||||||
lapic_eoi();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ipi_handle_tlb_flush()
|
|
||||||
{
|
|
||||||
tlb_flush();
|
|
||||||
lapic_eoi();
|
|
||||||
}
|
|
||||||
|
|
||||||
void lapic_send_ipi(u32 lapic_id, u8 vector)
|
|
||||||
{
|
|
||||||
/* check for current IPI */
|
|
||||||
while (lapic_read(lapic_addr, LAPIC_ICR) & (1 << 12))
|
|
||||||
;
|
|
||||||
lapic_write(lapic_addr, LAPIC_ICR + 0x10, lapic_id << 24);
|
|
||||||
lapic_write(lapic_addr, LAPIC_ICR, vector | (1 << 14));
|
|
||||||
}
|
|
||||||
|
|
||||||
void apic_init()
|
void apic_init()
|
||||||
{
|
{
|
||||||
ioapic_addr += hhdm_start;
|
ioapic_addr += hhdm_start;
|
||||||
|
|
@ -133,9 +112,6 @@ void apic_init()
|
||||||
lapic_write(lapic_addr, LAPIC_TIMER_INIT_COUNT, 0xFFFF0);
|
lapic_write(lapic_addr, LAPIC_TIMER_INIT_COUNT, 0xFFFF0);
|
||||||
lapic_write(lapic_addr, LAPIC_TIMER, 0x20 | 0x20000);
|
lapic_write(lapic_addr, LAPIC_TIMER, 0x20 | 0x20000);
|
||||||
|
|
||||||
idt_insert(IPI_KILL, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, ipi_handle_kill);
|
|
||||||
idt_insert(IPI_TLB_FLUSH, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, ipi_handle_tlb_flush);
|
|
||||||
|
|
||||||
krdy("APIC initialized\n");
|
krdy("APIC initialized\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@
|
||||||
#include <kernel/common.h>
|
#include <kernel/common.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
|
||||||
#define IPI_KILL 0x30
|
|
||||||
#define IPI_TLB_FLUSH 0x31
|
|
||||||
|
|
||||||
struct thread;
|
struct thread;
|
||||||
struct cpu_local {
|
struct cpu_local {
|
||||||
struct thread *cur_thread;
|
struct thread *cur_thread;
|
||||||
|
|
@ -17,7 +14,6 @@ struct cpu_local {
|
||||||
u32 cpu_id;
|
u32 cpu_id;
|
||||||
vaddr_t irq_rsp;
|
vaddr_t irq_rsp;
|
||||||
struct tss tss;
|
struct tss tss;
|
||||||
u32 apic_id;
|
|
||||||
} PACKED;
|
} PACKED;
|
||||||
|
|
||||||
struct pt_regs {
|
struct pt_regs {
|
||||||
|
|
|
||||||
123
lib/printf.c
123
lib/printf.c
|
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
#include <drivers/serial.h>
|
#include <drivers/serial.h>
|
||||||
#include <kernel/tty.h>
|
#include <kernel/tty.h>
|
||||||
#include <kernel/spinlock.h>
|
|
||||||
|
|
||||||
// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the
|
// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the
|
||||||
// printf_config.h header file
|
// printf_config.h header file
|
||||||
|
|
@ -198,14 +197,7 @@ static unsigned int _atoi(const char **str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// output the specified string in reverse, taking care of any zero-padding
|
// output the specified string in reverse, taking care of any zero-padding
|
||||||
static size_t _out_rev(
|
static size_t _out_rev(out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width,
|
||||||
out_fct_type out,
|
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
const char *buf,
|
|
||||||
size_t len,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const size_t start_idx = idx;
|
const size_t start_idx = idx;
|
||||||
|
|
@ -233,18 +225,8 @@ static size_t _out_rev(
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal itoa format
|
// internal itoa format
|
||||||
static size_t _ntoa_format(
|
static size_t _ntoa_format(out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative,
|
||||||
out_fct_type out,
|
unsigned int base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
char *buf,
|
|
||||||
size_t len,
|
|
||||||
bool negative,
|
|
||||||
unsigned int base,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
// pad leading zeros
|
// pad leading zeros
|
||||||
if (!(flags & FLAGS_LEFT)) {
|
if (!(flags & FLAGS_LEFT)) {
|
||||||
|
|
@ -293,17 +275,8 @@ static size_t _ntoa_format(
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal itoa for 'long' type
|
// internal itoa for 'long' type
|
||||||
static size_t _ntoa_long(
|
static size_t _ntoa_long(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative,
|
||||||
out_fct_type out,
|
unsigned long base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
unsigned long value,
|
|
||||||
bool negative,
|
|
||||||
unsigned long base,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
|
|
@ -327,17 +300,8 @@ static size_t _ntoa_long(
|
||||||
|
|
||||||
// internal itoa for 'long long' type
|
// internal itoa for 'long long' type
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
static size_t _ntoa_long_long(
|
static size_t _ntoa_long_long(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative,
|
||||||
out_fct_type out,
|
unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
unsigned long long value,
|
|
||||||
bool negative,
|
|
||||||
unsigned long long base,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
|
|
@ -364,26 +328,12 @@ static size_t _ntoa_long_long(
|
||||||
|
|
||||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||||
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
|
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
|
||||||
static size_t
|
static size_t _etoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width,
|
||||||
_etoa(out_fct_type out,
|
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
double value,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// internal ftoa for fixed decimal floating point
|
// internal ftoa for fixed decimal floating point
|
||||||
static size_t
|
static size_t _ftoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width,
|
||||||
_ftoa(out_fct_type out,
|
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
double value,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
||||||
|
|
@ -399,9 +349,8 @@ _ftoa(out_fct_type out,
|
||||||
if (value < -DBL_MAX)
|
if (value < -DBL_MAX)
|
||||||
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
|
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
|
||||||
if (value > DBL_MAX)
|
if (value > DBL_MAX)
|
||||||
return _out_rev(
|
return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U,
|
||||||
out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width,
|
width, flags);
|
||||||
flags);
|
|
||||||
|
|
||||||
// test for very large values
|
// test for very large values
|
||||||
// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
|
// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
|
||||||
|
|
@ -508,14 +457,7 @@ _ftoa(out_fct_type out,
|
||||||
|
|
||||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||||
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
||||||
static size_t
|
static size_t _etoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width,
|
||||||
_etoa(out_fct_type out,
|
|
||||||
char *buffer,
|
|
||||||
size_t idx,
|
|
||||||
size_t maxlen,
|
|
||||||
double value,
|
|
||||||
unsigned int prec,
|
|
||||||
unsigned int width,
|
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
// check for NaN and special values
|
// check for NaN and special values
|
||||||
|
|
@ -611,8 +553,7 @@ _etoa(out_fct_type out,
|
||||||
// output the exponential symbol
|
// output the exponential symbol
|
||||||
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
||||||
// output the exponent value
|
// output the exponent value
|
||||||
idx = _ntoa_long(
|
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1,
|
||||||
out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1,
|
|
||||||
FLAGS_ZEROPAD | FLAGS_PLUS);
|
FLAGS_ZEROPAD | FLAGS_PLUS);
|
||||||
// might need to right-pad spaces
|
// might need to right-pad spaces
|
||||||
if (flags & FLAGS_LEFT) {
|
if (flags & FLAGS_LEFT) {
|
||||||
|
|
@ -790,35 +731,31 @@ static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const
|
||||||
if (flags & FLAGS_LONG_LONG) {
|
if (flags & FLAGS_LONG_LONG) {
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
const long long value = va_arg(va, long long);
|
const long long value = va_arg(va, long long);
|
||||||
idx = _ntoa_long_long(
|
idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||||
out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value),
|
(unsigned long long)(value > 0 ? value : 0 - value), value < 0, base,
|
||||||
value < 0, base, precision, width, flags);
|
precision, width, flags);
|
||||||
#endif
|
#endif
|
||||||
} else if (flags & FLAGS_LONG) {
|
} else if (flags & FLAGS_LONG) {
|
||||||
const long value = va_arg(va, long);
|
const long value = va_arg(va, long);
|
||||||
idx = _ntoa_long(
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value),
|
||||||
out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0,
|
value < 0, base, precision, width, flags);
|
||||||
base, precision, width, flags);
|
|
||||||
} else {
|
} else {
|
||||||
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) :
|
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) :
|
||||||
(flags & FLAGS_SHORT) ? (short int)va_arg(va, int) :
|
(flags & FLAGS_SHORT) ? (short int)va_arg(va, int) :
|
||||||
va_arg(va, int);
|
va_arg(va, int);
|
||||||
idx = _ntoa_long(
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value),
|
||||||
out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0,
|
value < 0, base, precision, width, flags);
|
||||||
base, precision, width, flags);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// unsigned
|
// unsigned
|
||||||
if (flags & FLAGS_LONG_LONG) {
|
if (flags & FLAGS_LONG_LONG) {
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
idx = _ntoa_long_long(
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base,
|
||||||
out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision,
|
precision, width, flags);
|
||||||
width, flags);
|
|
||||||
#endif
|
#endif
|
||||||
} else if (flags & FLAGS_LONG) {
|
} else if (flags & FLAGS_LONG) {
|
||||||
idx = _ntoa_long(
|
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base,
|
||||||
out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width,
|
precision, width, flags);
|
||||||
flags);
|
|
||||||
} else {
|
} else {
|
||||||
const unsigned int value =
|
const unsigned int value =
|
||||||
(flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) :
|
(flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) :
|
||||||
|
|
@ -904,13 +841,12 @@ static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
const bool is_ll = sizeof(vaddr_t) == sizeof(long long);
|
const bool is_ll = sizeof(vaddr_t) == sizeof(long long);
|
||||||
if (is_ll) {
|
if (is_ll) {
|
||||||
idx = _ntoa_long_long(
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, (vaddr_t)va_arg(va, void *), false, 16U,
|
||||||
out, buffer, idx, maxlen, (vaddr_t)va_arg(va, void *), false, 16U, precision, width, flags);
|
precision, width, flags);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
idx = _ntoa_long(
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((vaddr_t)va_arg(va, void *)), false,
|
||||||
out, buffer, idx, maxlen, (unsigned long)((vaddr_t)va_arg(va, void *)), false, 16U,
|
16U, precision, width, flags);
|
||||||
precision, width, flags);
|
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -941,14 +877,11 @@ static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const
|
||||||
|
|
||||||
int printf_(const char *format, ...)
|
int printf_(const char *format, ...)
|
||||||
{
|
{
|
||||||
static spinlock_t lock = 0;
|
|
||||||
spinlock_acquire(&lock);
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
char buffer[1];
|
char buffer[1];
|
||||||
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
spinlock_release(&lock);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue