Merge branch 'main' of github.com:bLueriVerLHR/neulacpu

This commit is contained in:
2023-06-26 15:13:31 +08:00
10 changed files with 125 additions and 31 deletions

View File

@@ -28,15 +28,16 @@ LD_CSRIPT := kernel.ld
EXTRA_MACRO := # NDEBUG EXTRA_MACRO := # NDEBUG
EXTRA_FLAGS = -Wall -Werror -O0 -fno-omit-frame-pointer -ggdb -gdwarf-2 EXTRA_FLAGS = -Wall -Werror -O0 -fno-omit-frame-pointer -ggdb -gdwarf-2
EXTRA_FLAGS += -mfpu=none -march=loongarch32r -mabi=ilp32s
EXTRA_FLAGS += -MD EXTRA_FLAGS += -MD
EXTRA_FLAGS += -ffreestanding -fno-common -nostdlib EXTRA_FLAGS += -ffreestanding -fno-common -nostdlib
EXTRA_FLAGS += -I. EXTRA_FLAGS += -I.
EXTRA_FLAGS += -fno-pie -no-pie EXTRA_FLAGS += -fno-pie -no-pie
EXTRA_FLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) EXTRA_FLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
COMMONFLAGS := $(EXTRA_FLAGS) -march=loongarch32r COMMONFLAGS := $(EXTRA_FLAGS)
CPPFLAGS += $(addprefix -D,$(EXTRA_MACRO)) -I$(CURDIR)/include CPPFLAGS += $(addprefix -D,$(EXTRA_MACRO)) -I$(CURDIR)/include
CFLAGS += $(COMMONFLAGS) -O CFLAGS += $(COMMONFLAGS)
LDFLAGS += $(COMMONFLAGS) -z max-page-size=4096 -T$(LD_CSRIPT) LDFLAGS += $(COMMONFLAGS) -z max-page-size=4096 -T$(LD_CSRIPT)
.PHONY: all build clean .PHONY: all build clean
@@ -70,3 +71,6 @@ usr:
@TOP_BUILD_DIR=$(ABS_BUILD) \ @TOP_BUILD_DIR=$(ABS_BUILD) \
CPPFLAGS="$(CPPFLAGS)" \ CPPFLAGS="$(CPPFLAGS)" \
$(MAKE) native -C $(TOP_SRC_DIR)/user -j$(NPROC) $(MAKE) native -C $(TOP_SRC_DIR)/user -j$(NPROC)
tcpl:
$(CC) --target-help

6
laos/include/dev.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef DEV_H__
#define DEV_H__
extern char ioports[];
#endif

9
laos/include/filepath.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef FILEPATH_H__
#define FILEPATH_H__
char *basename(char *bnm, const char *path);
char *rmext(char *noext, const char *fname);
char *bearname(char *bnm, const char *fname);
#endif

View File

@@ -1,8 +1,16 @@
#include "asm.h" #include "asm.h"
#include "defs.h" #include "defs.h"
#include "latype.h" #include "latype.h"
#include "macro.h" #include "macro.h"
#ifndef __loongarch32r
#define __loongarch32r
#endif
#include "larchintrin.h"
#ifndef LA32R_H__ #ifndef LA32R_H__
#define LA32R_H__ #define LA32R_H__
@@ -56,18 +64,10 @@ static inline uint r_ra() {
// mem misc // mem misc
// //
static inline void dbar() {
asm volatile("dbar 0");
}
static inline void ibar() {
asm volatile("ibar 0");
}
// need to be tested // need to be tested
static inline void synchronize() { static inline void synchronize() {
dbar(); __dbar(0);
ibar(); __ibar(0);
} }
@@ -101,4 +101,6 @@ static inline uint scw(uint wdata, intptr_t addr) {
return recv; return recv;
} }
#endif #endif

View File

@@ -4,6 +4,6 @@
#define DEV_BASE_ADDR 0xa0000000 #define DEV_BASE_ADDR 0xa0000000
#define SERIAL_ADDR (DEV_BASE_ADDR + 0x00000000) #define SERIAL_OFFSET 0x00000000
#endif #endif

View File

@@ -38,4 +38,5 @@ SECTIONS
} }
PROVIDE(end = .); PROVIDE(end = .);
PROVIDE(ioports = 0xa0000000);
} }

3
laos/src/dev/dev.c Normal file
View File

@@ -0,0 +1,3 @@
#include "dev.h"
char ioports[];

View File

@@ -2,16 +2,18 @@
#include "memio.h" #include "memio.h"
#include "memlayout.h" #include "memlayout.h"
#include "spinlock.h" #include "spinlock.h"
#include "dev.h"
void consputc(int c) { void consputc(int c) {
if (c == '\b') { volatile char *out = &ioports[SERIAL_OFFSET];
memb(SERIAL_ADDR) = '\b'; if (c == '\b') {
memb(SERIAL_ADDR) = ' '; *out = '\b';
memb(SERIAL_ADDR) = '\b'; *out = ' ';
return; *out = '\b';
} return;
}
memb(SERIAL_ADDR) = c; *out = c;
} }
struct { struct {
@@ -20,9 +22,7 @@ struct {
// input // input
#define INPUT_BUF_SIZE 128 #define INPUT_BUF_SIZE 128
char buf[INPUT_BUF_SIZE]; char buf[INPUT_BUF_SIZE];
uint r; // Read index uint r; // Read index
uint w; // Write index uint w; // Write index
uint e; // Edit index uint e; // Edit index
} cons; } cons;

View File

@@ -29,11 +29,9 @@ int main(int argc, char *argv[]) {
char *tok = strtok(input, " "); char *tok = strtok(input, " ");
while (tok) { while (tok) {
if (*tok != '\n') { args = realloc(args, (argc + 1) * sizeof(char *));
args = realloc(args, (argc + 1) * sizeof(char *)); args[argc] = tok;
args[argc] = tok; argc += 1;
argc += 1;
}
tok = strtok(NULL, " "); tok = strtok(NULL, " ");
} }

71
laos/src/util/filepath.c Normal file
View File

@@ -0,0 +1,71 @@
#include "defs.h"
//
// bnm should be large enough to hold basename
//
char *basename(char *bnm, const char *path) {
const char *p = path;
const char *last_slash = NULL;
while (*p) {
if (*p == '/' || *p == '\\') {
last_slash = p;
}
p++;
}
char *q = bnm;
p = last_slash + 1;
while (*p) {
*q++ = *p++;
}
return bnm;
}
//
// noext should be large enough to hold no-ext name
//
char *rmext(char *noext, const char *fname) {
const char *p = fname;
const char *last_dot = NULL;
while (*p) {
if (*p == '.') {
last_dot = p;
}
p++;
}
char *q = noext;
p = fname;
while (p != last_dot) {
*q++ = *p++;
}
return noext;
}
//
// bnm should be large enough to hold bearname name
//
char *bearname(char *bnm, const char *fname) {
const char *p = fname;
const char *last_slash = NULL;
const char *last_dot = NULL;
while (*p) {
if (*p == '/' || *p == '\\') {
last_slash = p;
} else if (*p == '.') {
last_dot = p;
}
p++;
}
char *q = bnm;
p = last_slash + 1;
while (p != last_dot) {
*q++ = *p++;
}
return bnm;
}