[build] Use clang (and fix va_list in kprintf)
This commit is contained in:
parent
52a5b9e6cf
commit
f414baa81e
5
Makefile
5
Makefile
@ -1,6 +1,7 @@
|
||||
CC = gcc
|
||||
LD = ld -m elf_i386
|
||||
#CC = gcc
|
||||
CC = clang
|
||||
CFLAGS = -Wall -Wextra -pedantic -m32 -O0 -std=c99 -finline-functions -fno-stack-protector -nostdinc -ffreestanding -Wno-unused-function -Wno-unused-parameter
|
||||
LD = ld -m elf_i386
|
||||
NASM = nasm -f elf
|
||||
ECHO = `which echo` -e
|
||||
MODULES = $(patsubst %.c,%.o,$(wildcard core/*.c))
|
||||
|
@ -1,12 +1,10 @@
|
||||
#include <system.h>
|
||||
|
||||
#define args_list char *
|
||||
#define _arg_stack_size(type) (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int))
|
||||
#define args_start(ap, fmt) do { \
|
||||
ap = (char *)((unsigned int)&fmt + _arg_stack_size(&fmt));\
|
||||
} while (0)
|
||||
#define args_end(ap)
|
||||
#define args_next(ap, type) (((type *)(ap+=_arg_stack_size(type)))[-1])
|
||||
typedef __builtin_va_list va_list;
|
||||
#define va_start(ap,last) __builtin_va_start(ap, last)
|
||||
#define va_end(ap) __builtin_va_end(ap)
|
||||
#define va_arg(ap,type) __builtin_va_arg(ap,type)
|
||||
#define va_copy(dest, src) __builtin_va_copy(dest,src)
|
||||
|
||||
static char buf[1024] = {-1};
|
||||
static int ptr = -1;
|
||||
@ -56,8 +54,8 @@ kprintf(
|
||||
) {
|
||||
int i = 0;
|
||||
char *s;
|
||||
args_list args;
|
||||
args_start(args, fmt);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ptr = 0;
|
||||
for ( ; fmt[i]; ++i) {
|
||||
if ((fmt[i] != '%') && (fmt[i] != '\\')) {
|
||||
@ -77,19 +75,19 @@ kprintf(
|
||||
/* fmt[i] == '%' */
|
||||
switch (fmt[++i]) {
|
||||
case 's':
|
||||
s = (char *)args_next(args, char *);
|
||||
s = (char *)va_arg(args, char *);
|
||||
while (*s) {
|
||||
buf[ptr++] = *s++;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
buf[ptr++] = (char)args_next(args, int);
|
||||
buf[ptr++] = (char)va_arg(args, int);
|
||||
break;
|
||||
case 'x':
|
||||
parse_hex((unsigned long)args_next(args, unsigned long));
|
||||
parse_hex((unsigned long)va_arg(args, unsigned long));
|
||||
break;
|
||||
case 'd':
|
||||
parse_num((unsigned long)args_next(args, unsigned long), 10);
|
||||
parse_num((unsigned long)va_arg(args, unsigned long), 10);
|
||||
break;
|
||||
case '%':
|
||||
buf[ptr++] = '%';
|
||||
@ -100,7 +98,7 @@ kprintf(
|
||||
}
|
||||
}
|
||||
buf[ptr] = '\0';
|
||||
args_end(args);
|
||||
va_end(args);
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user