Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions booter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,37 @@ BOOTVM_IMAGE_HEAP_SIZE := 0x1000000

all: hello should_crash should_pagefault bigio $(BOOTVM_PROG)

CFLAGS = $(OPTIMIZE) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Werror -Wno-builtin-requires-header -g -I. -I$(INSTALLPATH)/include -I$(KERNELPATH)/include
LDFLAGS = -L$(INSTALLPATH)/lib -moslib=h2 -Qunused-arguments
ifeq ($(PICOLIBC),1)
OSLIB_FLAG = --target=hexagon-h2-picolibc
# Derive template path from the resolved compiler location: bin/../templates/staticExecutable/
PICOLIBC_LCS := $(abspath $(dir $(shell which $(CC)))/../templates/staticExecutable/static-executable-h2-picolibc.lcs.template)
GUEST_LDSCRIPT = -Wl,--script=$(PICOLIBC_LCS)
else
OSLIB_FLAG = -moslib=h2
GUEST_LDSCRIPT =
endif

CFLAGS = $(OSLIB_FLAG) $(OPTIMIZE) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Werror -Wno-builtin-requires-header -g -I. -I$(INSTALLPATH)/include -I$(KERNELPATH)/include
LDFLAGS = -L$(INSTALLPATH)/lib $(OSLIB_FLAG) -Qunused-arguments

include $(H2DIR)/scripts/Makefile.inc.config
include $(H2DIR)/scripts/Makefile.inc.opensource
include $(H2DIR)/scripts/Makefile.inc.bootvm


hello: hello.o
${CC} $(LDFLAGS) $(CFLAGS) -Wl,--section-start=.start=$(H2K_GUEST_START) -o hello hello.o
${CC} $(LDFLAGS) $(CFLAGS) $(GUEST_LDSCRIPT) -Wl,--section-start=.start=$(H2K_GUEST_START) -o hello hello.o

should_pagefault: OPTIMIZE = -O0
should_pagefault: should_pagefault.o
${CC} $(LDFLAGS) $(CFLAGS) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o should_pagefault should_pagefault.o
${CC} $(LDFLAGS) $(CFLAGS) $(GUEST_LDSCRIPT) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o should_pagefault should_pagefault.o

should_crash: OPTIMIZE = -O0
should_crash: should_crash.o
${CC} $(LDFLAGS) $(CFLAGS) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o should_crash should_crash.o
${CC} $(LDFLAGS) $(CFLAGS) $(GUEST_LDSCRIPT) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o should_crash should_crash.o

bigio: bigio.o
${CC} $(LDFLAGS) $(CFLAGS) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o bigio bigio.o
${CC} $(LDFLAGS) $(CFLAGS) $(GUEST_LDSCRIPT) -O0 -Wl,--section-start=.start=$(H2K_GUEST_START) -o bigio bigio.o

# %.o: %.c
# ${CC} ${CFLAGS} -c -o $@ $<
Expand Down
6 changes: 4 additions & 2 deletions booter/booter.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void add_linear_trans(unsigned int idx, unsigned long va, unsigned long long pa,
vm_params[idx].pmap_added = 1;
}

if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
if (0 == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
error("realloc pmap->base", NULL);
}
base = (H2K_linear_fmt_t *)(pmap->base.raw);
Expand Down Expand Up @@ -764,7 +764,7 @@ void clade_setup(unsigned int idx, long offset) {
/* Copy high-prio exception data to TCM */
ex_hi_size = ex_hi_end - ex_hi_start;
if (ex_hi_size && tcm_size) {
if (NULL == (vm_params[idx].clade_ex_hi = (unsigned int)h2_galloc(&tcm_alloc, ex_hi_size, 4096, 0))) {
if (0 == (vm_params[idx].clade_ex_hi = (unsigned int)h2_galloc(&tcm_alloc, ex_hi_size, 4096, 0))) {
FAIL("\tgalloc ex_hi", "");
}
// BOOTER_PRINTF("memcpy(0x%08x, 0x%08lx, 0x%08lx\n", vm_params[idx].clade_ex_hi, ex_hi_start + offset, ex_hi_size);
Expand Down Expand Up @@ -2310,6 +2310,7 @@ unsigned int process_line(int argc, char **argv, unsigned int idx) {
return idx;
}

#ifndef __PICOLIBC__
size_t getline(char **lineptr, size_t *n, FILE *stream) {

char *buf = NULL;
Expand Down Expand Up @@ -2362,6 +2363,7 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {

return p - buf - 1;
}
#endif /* !__PICOLIBC__ */

int main(int argc, char **argv)
{
Expand Down
6 changes: 5 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ H2DIR ?= ..

include ../scripts/Makefile.inc.tools

# Ensure toolchain path override is honored even when kernel is built directly.
ifneq ($(TOOLCHAIN_BIN),)
export PATH := $(TOOLCHAIN_BIN):$(PATH)
endif

ifeq ($(USE_PKW),1)
export PKW_VERSIONS := hexagon-tools=$(TOOLS_FLAVOR_KERNEL) arch=$(ARCH_FLAVOR)
endif
Expand Down Expand Up @@ -223,4 +228,3 @@ opt_install: info opt
cp include/asm_offsets.h $(INSTALLPATH)/include # for state trap

check: build/ref/libh2check.a

24 changes: 22 additions & 2 deletions kernel/build/offsets/make.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Yo. -*- Makefile -*-

# offsets is a target-side generator program (run under simulator) and uses
# libc headers like <stdio.h>. When building with PICOLIBC, select the picolibc
# sysroot via the target triple.
ifeq ($(PICOLIBC),1)
OFFSETS_TARGET_FLAG := --target=hexagon-none-picolibc
else
OFFSETS_TARGET_FLAG :=
endif

ifeq ($(PICOLIBC),1)
# Provide heap symbols and default memory layout expected by picolibc's libc.
# Use the linker script from the selected toolchain sysroot.
ifneq ($(TOOLCHAIN_BIN),)
OFFSETS_LDSCRIPT := -Wl,-T,$(abspath $(TOOLCHAIN_BIN)/../target/hexagon-unknown-none-picolibc/lib/v$(ARCHV)/G0/picolibc.ld)
else
OFFSETS_LDSCRIPT := -Wl,-T,$(shell $(CC) $(OFFSETS_TARGET_FLAG) -print-file-name=picolibc.ld)
endif
else
OFFSETS_LDSCRIPT :=
endif

include/asm_offsets.h: $(BUILD_DIR)/offsets
ifeq ($(RUN), $(RUN_TOOLSIM))
$(RUN) $< -- $@
Expand All @@ -8,9 +29,8 @@ else
endif

$(BUILD_DIR)/offsets: $(DIR)offsets.ref.c includes
$(CC) $(CFLAGS) -o $@ $<
$(CC) $(OFFSETS_TARGET_FLAG) $(OFFSETS_LDSCRIPT) $(CFLAGS) -o $@ $<

DEST_HFILES += include/asm_offsets.h

CLEAN_EXTRAS += $(BUILD_DIR)/offsets

1 change: 1 addition & 0 deletions kernel/build/offsets/offsets.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int main(int argc, char **argv)
fprintf(outfile, "#define STATUS_INTBLOCKED %d\n",H2K_STATUS_INTBLOCKED);
fprintf(outfile, "#define STATUS_VMWAIT %d\n",H2K_STATUS_VMWAIT);

fclose(outfile);
return 0;
}

13 changes: 11 additions & 2 deletions libs/blast/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@




# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
else
TARGET_FLAG =
endif

CC = hexagon-clang
AR = hexagon-ar
CFLAGS = -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../h2/include -I../../kernel/include -g $(OPTIMIZE) $(OPT_ADD) -G0
ASFLAGS = -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../h2/include -I../../kernel/include
CFLAGS = $(TARGET_FLAG) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../h2/include -I../../kernel/include -g $(OPTIMIZE) $(OPT_ADD) -G0
ASFLAGS = $(TARGET_FLAG) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../h2/include -I../../kernel/include
OPTIMIZE := -O2

export BLAST_LIB_INCLUDE=$(shell pwd)/include
Expand Down
9 changes: 8 additions & 1 deletion libs/h2/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

ALL: dummy

# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
else
TARGET_FLAG =
endif

OPTIMIZE := -Os

CFLAGS := -Iinclude -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g
CFLAGS := $(TARGET_FLAG) -Iinclude -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g

ifdef DEBUG
CFLAGS += -DDEBUG
Expand Down
9 changes: 8 additions & 1 deletion libs/h2_compat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ ALL: dummy

OPTIMIZE := -Os

CFLAGS := -Iinclude -I$(INSTALLPATH)/include -I../h2/include -I../posix/include -I../../libs/syscall/angel/include -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g
# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
else
TARGET_FLAG =
endif

CFLAGS := $(TARGET_FLAG) -Iinclude -I$(INSTALLPATH)/include -I../h2/include -I../posix/include -I../../libs/syscall/angel/include -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g

ifdef DEBUG
CFLAGS += -DDEBUG
Expand Down
1 change: 1 addition & 0 deletions libs/h2_compat/alloc/h2_alloc.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <h2_alloc.h>
#include <h2_plainmutex.h>
#include <stdlib.h>
#include <malloc.h>

/*
* h2_alloc.c
Expand Down
6 changes: 3 additions & 3 deletions libs/h2_compat/coproc/h2_coproc.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <h2_coproc.h>
#include <h2_alloc.h>

static unsigned int *configs[CFG_TYPE_MAX][CFG_SUBTYPE_MAX] = {NULL};
static unsigned int nunits[CFG_TYPE_MAX][CFG_SUBTYPE_MAX] = {0};
static unsigned int *counts[CFG_TYPE_MAX][CFG_SUBTYPE_MAX][CFG_MAX] = {NULL};
static unsigned int *configs[CFG_TYPE_MAX][CFG_SUBTYPE_MAX] = {{NULL}};
static unsigned int nunits[CFG_TYPE_MAX][CFG_SUBTYPE_MAX] = {{0}};
static unsigned int *counts[CFG_TYPE_MAX][CFG_SUBTYPE_MAX][CFG_MAX] = {{{NULL}}};
static unsigned int oldstyle = 0;
static unsigned int init_done = 0;

Expand Down
2 changes: 1 addition & 1 deletion libs/h2_compat/prof/h2_prof.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ unsigned int h2_prof_sample(unsigned long long int **res) {
unsigned int hthreads_mask;

if (NULL == (*res = (unsigned long long int *)h2_malloc(sizeof(unsigned long long int) * 6))) {
return NULL;
return 0;
}

asm volatile
Expand Down
9 changes: 8 additions & 1 deletion libs/posix/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

ALL: dummy

# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
else
TARGET_FLAG =
endif

OPTIMIZE := -Os

CFLAGS := -Iinclude -I../h2/include -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g
CFLAGS := $(TARGET_FLAG) -Iinclude -I../h2/include -G0 $(OPTIMIZE) $(OPT_ADD) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Wno-builtin-requires-header -Werror -g

ifdef DEBUG
CFLAGS += -DDEBUG
Expand Down
12 changes: 12 additions & 0 deletions libs/posix/pthread/misc/posix_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
#define H2_POSIX_TIME_H 1

#define _PROVIDE_POSIX_TIME_DECLS 1
#ifdef __PICOLIBC__
/* Enable POSIX clock IDs in Picolibc's time.h */
#ifndef _POSIX_MONOTONIC_CLOCK
#define _POSIX_MONOTONIC_CLOCK 1
#endif
#ifndef _POSIX_CPUTIME
#define _POSIX_CPUTIME 1
#endif
#ifndef _POSIX_THREAD_CPUTIME
#define _POSIX_THREAD_CPUTIME 1
#endif
#endif
#include <time.h> // dinkumware time.h, if we change c libraries we probably need to nuke this

/* In case time.h was included early without defining
Expand Down
10 changes: 8 additions & 2 deletions libs/qurt/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@


CC = hexagon-clang -mv$(TOOLARCH) -Iinclude -Wall -Wno-builtin-requires-header -I../h2/include -I../posix/include -I../h2_compat/include
# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
else
TARGET_FLAG =
endif

CC = hexagon-clang $(TARGET_FLAG) -mv$(TOOLARCH) -Iinclude -Wall -Wno-builtin-requires-header -I../h2/include -I../posix/include -I../h2_compat/include
AR = hexagon-ar

OPTIMIZE := -O2

CFLAGS = -g $(OPTIMIZE) $(OPT_ADD) -G0
Expand Down
1 change: 1 addition & 0 deletions libs/qurt/src/qurt_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <qurt_lifo.h>
#include <qurt_fd.h>
#include <stdint.h>

/* EJP: the best thing about this file is that most of the things are commented out. */

Expand Down
13 changes: 11 additions & 2 deletions libs/syscall/angel/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

CFLAGS = -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -Wno-builtin-requires-header -Werror -I../../h2/include -I../../h2_compat/include -I../../posix/include -g $(OPTIMIZE) $(OPT_ADD) -G0
ASFLAGS = -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../../h2/include -I../../posix/include
# Picolibc support: if PICOLIBC=1, use --target=hexagon-h2-picolibc
ifeq ($(PICOLIBC),1)
TARGET_FLAG = --target=hexagon-h2-picolibc
# _STD_END/_STD_BEGIN are Dinkumware-specific macros; define them as no-ops
TARGET_FLAG += -D_STD_END= -D_STD_BEGIN=
else
TARGET_FLAG =
endif

CFLAGS = $(TARGET_FLAG) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -Wno-builtin-requires-header -Werror -I../../h2/include -I../../h2_compat/include -I../../posix/include -g $(OPTIMIZE) $(OPT_ADD) -G0
ASFLAGS = $(TARGET_FLAG) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Iinclude -Wall -I../../h2/include -I../../posix/include

CFLAGS += $(LIB_CFLAGS) $(H2_EXTRA_CFLAGS)

Expand Down
2 changes: 1 addition & 1 deletion libs/syscall/angel/include/angel.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ struct heap_info { /* heap information */
int stack_base;
int stack_limit;
};

struct __sys_stat
{
unsigned long long int dev;
Expand All @@ -113,6 +112,7 @@ struct __sys_stat
unsigned long __pad2;
}__attribute__ ((aligned (8)));


/* SYSTEM CALL FUNCTIONS */
errno_t sys_clock(void);
errno_t sys_close(fd_t);
Expand Down
7 changes: 5 additions & 2 deletions libs/syscall/angel/src/sys_fstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "allsyscalls.h"

errno_t sys_fstat(fd_t fd, void *buffer)
sys_call_ret_t sys_fstat_internal(fd_t fd, void *buffer)
{
struct {
fd_t fd;
Expand All @@ -15,6 +15,9 @@ errno_t sys_fstat(fd_t fd, void *buffer)
x.buf = ANGEL_OFFSET_PTR(buffer);
clean(buffer, sizeof(struct __sys_stat) / 4);
clean(&x, 2);
return ANGEL(SYS_FSTAT,&x,0);
return angel_with_err(SYS_FSTAT, &x, 0);
}

errno_t sys_fstat(fd_t fd, void *buffer) {
return sys_fstat_internal(fd, buffer).ret_value;
}
Loading
Loading