commit c5c72011513218b8d2b4ab83599cf70127e1f9e7
parent 0810c1f5fadd3a696a70d96a7f1d962378d0baab
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 5 Apr 2024 08:35:18 +0900
try to use tcc. need va_arg...
Diffstat:
6 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/sys/include/libc.h b/sys/include/libc.h
@@ -3,6 +3,7 @@
typedef unsigned char uint8;
typedef unsigned int uint32;
typedef unsigned long long int uint64;
+typedef long long int int64;
typedef unsigned long long int uintptr;
typedef struct {
@@ -28,4 +29,18 @@ typedef struct Memmap {
extern Memmap memmap;
-void *malloc(uintptr);
-\ No newline at end of file
+void *malloc(uintptr);
+void *memset(void *s, int c, uintptr n);
+
+/*
+typedef char *va_list;
+#define va_start(list, start) list = (char *)((int64 *)&(start)+1)
+// list += 8 on a 64-bit machine.
+#define va_arg(list, mode) \
+ ((sizeof(mode) == 1) ? ((list += 8), (mode *) list)[-8]:\
+ (sizeof(mode) == 2) ? ((list += 8), (mode *) list)[-4]:\
+ (sizeof(mode) == 4) ? ((list += 8), (mode *) list)[-2]:\
+ ((list += 8), (mode *) list)[-1])
+#define va_end(list)
+
+*/
+\ No newline at end of file
diff --git a/sys/src/Makefile b/sys/src/Makefile
@@ -6,11 +6,11 @@ BOOTCFLAGS = -I ../include \
-fno-builtin -g -mabi=sysv \
-mno-stack-arg-probe -Wall -e EfiMain
-CC = gcc
+CC = tcc
LD = ld
CFLAGS = -I ../include -nostdlib -fpic -mno-red-zone -Wall -g \
-ffreestanding -fno-builtin
-LDFLAGS = -Llibc -static
+LDFLAGS = -L../lib -static
disk.img: boot/boot.efi kernel/main.elf
qemu-img create -f raw disk.img 200M
@@ -27,7 +27,7 @@ boot/boot.efi: boot/boot.dll
boot/boot.dll: boot/boot.c boot/utils.c
$(BOOTCC) $(BOOTCFLAGS) -o $@ boot/boot.c boot/utils.c
-kernel/main.elf: kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o kernel/memmap.ld libc/libc.a
+kernel/main.elf: kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o kernel/memmap.ld ../lib/libc.a
$(LD) $(LDFLAGS) -e kernel_main -T kernel/memmap.ld -o $@ \
kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o \
-lc
@@ -40,10 +40,15 @@ kernel/alloc.o: kernel/alloc.c ../include/libc.h
kernel/console.o: kernel/console.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h
$(CC) $(CFLAGS) -c -o $@ kernel/console.c
-libc/libc.a: libc/strcpy.o
- ar rcs $@ libc/strcpy.o
+../lib/libc.a: libc/strcpy.o libc/memset.o ../lib
+ ar rcs $@ libc/strcpy.o libc/memset.o
libc/strcpy.o: libc/strcpy.c ../include/libc.h
$(CC) $(CFLAGS) -c -o $@ libc/strcpy.c
+libc/memset.o: libc/memset.c ../include/libc.h
+ $(CC) $(CFLAGS) -c -o $@ libc/memset.c
+
+../lib:
+ mkdir -p ../lib
run: disk.img OVMF.fd
qemu-system-x86_64 \
@@ -64,4 +69,4 @@ clean:
rm -rf disk.img image
rm -f boot/boot.efi boot/boot.dll
rm -f kernel/*.o kernel/main.elf
- rm -f libc/*.o libc/*.a
+ rm -rf libc/*.o ../lib
diff --git a/sys/src/kernel/console.c b/sys/src/kernel/console.c
@@ -1,9 +1,8 @@
-#include <stdarg.h> // TODO: implement stdarg by myself.
-
#include <libc.h>
#include <uefi.h>
#include <draw.h>
#include <console.h>
+#include <stdarg.h> // TODO: implement own stdarg.h
void
cons_putchar(Console *con, char c)
diff --git a/sys/src/kernel/draw.c b/sys/src/kernel/draw.c
@@ -22,7 +22,7 @@ init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIX
}
root_window.fb = fb_base;
root_window.fg = 0x0;
- root_window.bg = 0xffffea;
+ root_window.bg = 0xffffea00;
root_window.hres = hres;
root_window.vres = vres;
root_window.ppsl = ppsl;
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -18,6 +18,7 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
// can't print to console.
goto halt;
}
+ cons_printf(&console, "Does this work: %d, %s, %x\n", 10, "string", 0xdeadbeef);
line(&root_window, (Point){1000, 100}, (Point){1050, 140}, 0x000000);
line(&root_window, (Point){1000, 300}, (Point){100000, 100000}, 0x000000);
line(&root_window, (Point){1000, 400}, (Point){1100, 400}, 0xff000000);
diff --git a/sys/src/libc/memset.c b/sys/src/libc/memset.c
@@ -0,0 +1,11 @@
+#include <libc.h>
+
+void *
+memset(void *s, int c, uintptr n)
+{
+ void *s0 = s;
+ for (; n > 0; n--) {
+ *(int *)s++ = c;
+ }
+ return s0;
+}
+\ No newline at end of file