mirror of
				https://github.com/brain-hackers/lab
				synced 2025-11-04 14:38:34 +09:00 
			
		
		
		
	Merge pull request #5 from brain-hackers/x1-libbrain
x1 experimental libbrain
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -255,4 +255,6 @@ dmypy.json
 | 
			
		||||
 | 
			
		||||
*.bin
 | 
			
		||||
*.elf
 | 
			
		||||
*.a
 | 
			
		||||
*.o
 | 
			
		||||
/*/tmp
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,10 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
 | 
			
		||||
TARGET := AppMain
 | 
			
		||||
OBJS := crt0.o main.o
 | 
			
		||||
 | 
			
		||||
LIBS := libbrain/libbrain.a
 | 
			
		||||
 | 
			
		||||
ASFLAGS := -W
 | 
			
		||||
CFLAGS := -Wall -ffreestanding -fomit-frame-pointer -Os
 | 
			
		||||
CFLAGS := -Wall -ffreestanding -fomit-frame-pointer -Os -Ilibbrain
 | 
			
		||||
LDFLAGS := -T x1.ld
 | 
			
		||||
 | 
			
		||||
.PHONY:
 | 
			
		||||
@@ -25,7 +27,7 @@ clean:
 | 
			
		||||
	$(CC) -c $(CFLAGS) $<
 | 
			
		||||
 | 
			
		||||
$(TARGET).elf: $(OBJS)
 | 
			
		||||
	$(LD) $(LDFLAGS) $^ -o $@
 | 
			
		||||
	$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
 | 
			
		||||
 | 
			
		||||
$(TARGET).bin: $(TARGET).elf
 | 
			
		||||
	$(OBJCOPY) -O binary $< $@
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								x1/linkerscript/libbrain/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								x1/linkerscript/libbrain/Makefile
									
									
									
									
									
										Normal 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) $@ $^
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										54
									
								
								x1/linkerscript/libbrain/libbrain.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								x1/linkerscript/libbrain/libbrain.h
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_closedir.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_closedir.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_closedir
 | 
			
		||||
.type sys_closedir, %function
 | 
			
		||||
sys_closedir:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x6000644c
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fclose.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fclose.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fclose
 | 
			
		||||
.type sys_fclose, %function
 | 
			
		||||
sys_fclose:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006404
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_feof.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_feof.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_feof
 | 
			
		||||
.type sys_feof, %function
 | 
			
		||||
sys_feof:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006418
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_ferror.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_ferror.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_ferror
 | 
			
		||||
.type sys_ferror, %function
 | 
			
		||||
sys_ferror:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006430
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fflush.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fflush.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fflush
 | 
			
		||||
.type sys_fflush, %function
 | 
			
		||||
sys_fflush:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x6000641c
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fgetc.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fgetc.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fgetc
 | 
			
		||||
.type sys_fgetc, %function
 | 
			
		||||
sys_fgetc:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006420
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fgets.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fgets.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fgets
 | 
			
		||||
.type sys_fgets, %function
 | 
			
		||||
sys_fgets:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006424
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fopen.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fopen.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fopen
 | 
			
		||||
.type sys_fopen, %function
 | 
			
		||||
sys_fopen:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006400
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fputc.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fputc.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fputc
 | 
			
		||||
.type sys_fputc, %function
 | 
			
		||||
sys_fputc:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006428
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fputs.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fputs.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fputs
 | 
			
		||||
.type sys_fputs, %function
 | 
			
		||||
sys_fputs:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x6000642c
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fread.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fread.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fread
 | 
			
		||||
.type sys_fread, %function
 | 
			
		||||
sys_fread:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x6000640c
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_free.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_free.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_free
 | 
			
		||||
.type sys_free, %function
 | 
			
		||||
sys_free:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x600063c8
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_ftell.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_ftell.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_ftell
 | 
			
		||||
.type sys_ftell, %function
 | 
			
		||||
sys_ftell:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006408
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_fwrite.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_fwrite.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_fwrite
 | 
			
		||||
.type sys_fwrite, %function
 | 
			
		||||
sys_fwrite:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006410
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_malloc.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_malloc.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_malloc
 | 
			
		||||
.type sys_malloc, %function
 | 
			
		||||
sys_malloc:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x600063c4
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_mkdir.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_mkdir.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_mkdir
 | 
			
		||||
.type sys_mkdir, %function
 | 
			
		||||
sys_mkdir:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x6000643c
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_opendir.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_opendir.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_opendir
 | 
			
		||||
.type sys_opendir, %function
 | 
			
		||||
sys_opendir:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006454
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_printf.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_printf.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_printf
 | 
			
		||||
.type sys_printf, %function
 | 
			
		||||
sys_printf:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60092004
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_readdir.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_readdir.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_readdir
 | 
			
		||||
.type sys_readdir, %function
 | 
			
		||||
sys_readdir:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006450
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_remove.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_remove.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_remove
 | 
			
		||||
.type sys_remove, %function
 | 
			
		||||
sys_remove:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006434
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_rename.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_rename.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_rename
 | 
			
		||||
.type sys_rename, %function
 | 
			
		||||
sys_rename:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006438
 | 
			
		||||
							
								
								
									
										8
									
								
								x1/linkerscript/libbrain/sys_stat.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								x1/linkerscript/libbrain/sys_stat.s
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text
 | 
			
		||||
.align 4
 | 
			
		||||
 | 
			
		||||
.global sys_stat
 | 
			
		||||
.type sys_stat, %function
 | 
			
		||||
sys_stat:
 | 
			
		||||
    ldr     pc, [pc, #-4]
 | 
			
		||||
    .word 0x60006444
 | 
			
		||||
@@ -1,4 +1,7 @@
 | 
			
		||||
#include <libbrain.h>
 | 
			
		||||
 | 
			
		||||
int main(void *arg)
 | 
			
		||||
{
 | 
			
		||||
    sys_printf("Hello!\n");
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user