x1 experimental libbrain

This commit is contained in:
Suguru Saito 2021-12-15 01:27:08 +09:00
parent cd917143b7
commit 373c554708
26 changed files with 260 additions and 2 deletions

View File

@ -7,8 +7,10 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
TARGET := AppMain TARGET := AppMain
OBJS := crt0.o main.o OBJS := crt0.o main.o
LIBS := libbrain/libbrain.a
ASFLAGS := -W ASFLAGS := -W
CFLAGS := -Wall -ffreestanding -fomit-frame-pointer -Os CFLAGS := -Wall -ffreestanding -fomit-frame-pointer -Os -Ilibbrain
LDFLAGS := -T x1.ld LDFLAGS := -T x1.ld
.PHONY: .PHONY:
@ -25,7 +27,7 @@ clean:
$(CC) -c $(CFLAGS) $< $(CC) -c $(CFLAGS) $<
$(TARGET).elf: $(OBJS) $(TARGET).elf: $(OBJS)
$(LD) $(LDFLAGS) $^ -o $@ $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
$(TARGET).bin: $(TARGET).elf $(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@

View File

@ -0,0 +1,23 @@
CROSS_COMPILE := arm-linux-gnueabihf-
AS := $(CROSS_COMPILE)as
AR := $(CROSS_COMPILE)ar
TARGET := libbrain.a
OBJS := sys_closedir.o sys_feof.o sys_fflush.o sys_fgets.o sys_fputc.o sys_fread.o sys_ftell.o sys_malloc.o sys_opendir.o sys_readdir.o sys_rename.o sys_fclose.o sys_ferror.o sys_fgetc.o sys_fopen.o sys_fputs.o sys_free.o sys_fwrite.o sys_mkdir.o sys_printf.o sys_remove.o sys_stat.o
ASFLAGS := -W
ARFLAGS := -crs
.PHONY:
all: $(TARGET)
.PHONY:
clean:
-rm -f $(TARGET) *.o
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
$(TARGET): $(OBJS)
$(AR) $(ARFLAGS) $@ $^

View File

@ -0,0 +1,54 @@
#ifndef H_LIB_BRAIN_H
#define H_LIB_BRAIN_H
typedef unsigned long size_t;
typedef void FILE;
typedef void* DIR;
struct stat {
unsigned int flags;
unsigned int st_atim;
unsigned int st_mtim;
unsigned int st_ctim;
size_t st_size;
};
struct dirent {
unsigned int type;
size_t size;
size_t filename_length;
char filename[260];
};
enum {
SEEK_SET = 0,
SEEK_CUR,
SEEK_END,
};
void *sys_malloc(size_t size);
int sys_free(void *ptr);
FILE *sys_fopen(const char *filename, const char *mode);
int sys_fclose(FILE *stream);
int sys_ftell(FILE *stream);
size_t sys_fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t sys_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
int sys_fseek(FILE *stream, int offset, int whence);
int sys_feof(FILE *stream);
int sys_fflush(FILE *stream);
int sys_fgetc(FILE *stream);
char *sys_fgets(char *s, int n, FILE *stream);
int sys_fputc(int ch, FILE *stream);
int sys_fputs(const char *str, FILE *stream);
int sys_ferror(FILE *stream);
int sys_remove(const char *filepath);
int sys_rename(const char *oldpath, const char *newpath);
int sys_mkdir(const char *pathname);
int sys_stat(const char *filepath, struct stat *buf);
int sys_closedir(DIR *dirp);
struct dirent *sys_readdir(DIR *dirp);
DIR *sys_opendir(const char *pathname);
int sys_printf(const char *fmt);
#endif

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_closedir
.type sys_closedir, %function
sys_closedir:
ldr pc, [pc, #-4]
.word 0x6000644c

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fclose
.type sys_fclose, %function
sys_fclose:
ldr pc, [pc, #-4]
.word 0x60006404

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_feof
.type sys_feof, %function
sys_feof:
ldr pc, [pc, #-4]
.word 0x60006418

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_ferror
.type sys_ferror, %function
sys_ferror:
ldr pc, [pc, #-4]
.word 0x60006430

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fflush
.type sys_fflush, %function
sys_fflush:
ldr pc, [pc, #-4]
.word 0x6000641c

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fgetc
.type sys_fgetc, %function
sys_fgetc:
ldr pc, [pc, #-4]
.word 0x60006420

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fgets
.type sys_fgets, %function
sys_fgets:
ldr pc, [pc, #-4]
.word 0x60006424

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fopen
.type sys_fopen, %function
sys_fopen:
ldr pc, [pc, #-4]
.word 0x60006400

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fputc
.type sys_fputc, %function
sys_fputc:
ldr pc, [pc, #-4]
.word 0x60006428

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fputs
.type sys_fputs, %function
sys_fputs:
ldr pc, [pc, #-4]
.word 0x6000642c

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fread
.type sys_fread, %function
sys_fread:
ldr pc, [pc, #-4]
.word 0x6000640c

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_free
.type sys_free, %function
sys_free:
ldr pc, [pc, #-4]
.word 0x600063c8

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_ftell
.type sys_ftell, %function
sys_ftell:
ldr pc, [pc, #-4]
.word 0x60006408

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_fwrite
.type sys_fwrite, %function
sys_fwrite:
ldr pc, [pc, #-4]
.word 0x60006410

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_malloc
.type sys_malloc, %function
sys_malloc:
ldr pc, [pc, #-4]
.word 0x600063c4

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_mkdir
.type sys_mkdir, %function
sys_mkdir:
ldr pc, [pc, #-4]
.word 0x6000643c

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_opendir
.type sys_opendir, %function
sys_opendir:
ldr pc, [pc, #-4]
.word 0x60006454

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_printf
.type sys_printf, %function
sys_printf:
ldr pc, [pc, #-4]
.word 0x60092004

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_readdir
.type sys_readdir, %function
sys_readdir:
ldr pc, [pc, #-4]
.word 0x60006450

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_remove
.type sys_remove, %function
sys_remove:
ldr pc, [pc, #-4]
.word 0x60006434

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_rename
.type sys_rename, %function
sys_rename:
ldr pc, [pc, #-4]
.word 0x60006438

View File

@ -0,0 +1,8 @@
.text
.align 4
.global sys_stat
.type sys_stat, %function
sys_stat:
ldr pc, [pc, #-4]
.word 0x60006444

View File

@ -1,4 +1,7 @@
#include <libbrain.h>
int main(void *arg) int main(void *arg)
{ {
sys_printf("Hello!\n");
return 0; return 0;
} }