-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forward application exit status
- Loading branch information
Showing
7 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extra/halt | ||
halt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright Cartesi and individual authors (see AUTHORS) | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
UNAME:=$(shell uname) | ||
|
||
TOOLCHAIN_IMAGE ?= cartesi/toolchain | ||
TOOLCHAIN_TAG ?= 0.15.0 | ||
RISCV_ARCH ?= rv64gc | ||
RISCV_ABI ?= lp64d | ||
|
||
CROSS_COMPILE = riscv64-cartesi-linux-gnu- | ||
RVCC = $(CROSS_COMPILE)gcc | ||
RVCXX = $(CROSS_COMPILE)g++ | ||
RVCOPY = $(CROSS_COMPILE)objcopy | ||
RVDUMP = $(CROSS_COMPILE)objdump | ||
STRIP = $(CROSS_COMPILE)strip | ||
RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) | ||
|
||
CONTAINER_MAKE := /usr/bin/make | ||
CONTAINER_BASE := /opt/cartesi/tools | ||
KERNEL_HEADERS_PATH := /opt/riscv/usr/include | ||
|
||
all: xhalt | ||
|
||
xhalt: xhalt.c | ||
$(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" | ||
|
||
extra.ext2: xhalt | ||
$(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" | ||
|
||
xhalt.toolchain: | ||
$(RVCC) -O2 -o xhalt xhalt.c | ||
$(STRIP) xhalt | ||
|
||
extra.ext2.toolchain: | ||
mkdir -m 0755 ./extra | ||
cp ./xhalt ./extra/xhalt | ||
genext2fs -i 512 -b 8192 -d extra $(basename $@) | ||
rm -rf ./extra | ||
|
||
toolchain-exec: | ||
@docker run --hostname $@ --rm \ | ||
-e USER=$$(id -u -n) \ | ||
-e GROUP=$$(id -g -n) \ | ||
-e UID=$$(id -u) \ | ||
-e GID=$$(id -g) \ | ||
-v `pwd`:$(CONTAINER_BASE) \ | ||
-w $(CONTAINER_BASE) \ | ||
$(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) $(CONTAINER_COMMAND) | ||
|
||
toolchain-env: | ||
@docker run --hostname toolchain-env -it --rm \ | ||
-e USER=$$(id -u -n) \ | ||
-e GROUP=$$(id -g -n) \ | ||
-e UID=$$(id -u) \ | ||
-e GID=$$(id -g) \ | ||
-v `pwd`:$(CONTAINER_BASE) \ | ||
-w $(CONTAINER_BASE) \ | ||
$(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) | ||
|
||
clean: | ||
\rm -rf xhalt extra.ext2 extra | ||
|
||
.PHONY: toolchain-exec toolchain-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## HTIF xhalt tool | ||
|
||
### Requirements | ||
|
||
- Docker >= 18.x | ||
- GNU Make >= 3.81 | ||
|
||
### Building | ||
|
||
```bash | ||
$ cd linux/htif | ||
$ make | ||
``` | ||
|
||
#### Makefile targets | ||
|
||
The following options are available as `make` targets: | ||
|
||
- **all**: builds the RISC-V xhalt executable | ||
- **extra.ext2**: builds the extra.ext2 filesystem image with the xhalt tool inside | ||
- **toolchain-env**: runs the toolchain image with current user UID and GID | ||
- **clean**: clean generated artifacts | ||
|
||
#### Makefile container options | ||
|
||
You can pass the following variables to the make target if you wish to use different docker image tags. | ||
|
||
- TOOLCHAIN\_IMAGE: toolchain image name | ||
- TOOLCHAIN\_TAG: toolchain image tag | ||
|
||
``` | ||
$ make TOOLCHAIN_TAG=mytag | ||
``` | ||
|
||
It's useful when you want to use prebuilt images like `cartesi/toolchain:latest` | ||
|
||
#### Usage | ||
|
||
The purpose of the xhalt tool please see the emulator documentation. | ||
|
||
The purpose of the `extra.ext2` image is to help the development creating a filesystem that contains the xhalt tool so it can be used with the emulator. For instructions on how to do that, please see the emulator documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <syscall.h> | ||
#include <linux/reboot.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
const char *halt = argc > 1? argv[1] : "0"; | ||
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, halt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters