Skip to content

Commit 9b22866

Browse files
committed
Move custom syscalls to a custom extension
1 parent 35e699d commit 9b22866

File tree

22 files changed

+448
-337
lines changed

22 files changed

+448
-337
lines changed

README.md

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,66 @@ Memory consists of three sections. Two are directly accessible by code: ROM (rx)
1212

1313
Code begins executing at address `0x4`. Address `0x0` must contain the size of the `.text` section (ie. `__etext`) to tell the processor how much data to decode from ROM; alternatively, it can be `0` to decode the entire ROM.
1414

15-
## System calls
16-
17-
| Index (a7) | Description | a0 | a1 | a2 | a3 | a4 | a5 | a6 | Return (a0) |
18-
| ---------- | ---------------- | ------- | ----- | --------- | ------ | -------- | -------- | --- | ----------------------- |
19-
| 0 | Halt | | | | | | | | |
20-
| 1 | `printchar` | value | | | | | | | |
21-
| 2 | `printflush` | | | | | | | | |
22-
| 3 | `draw clear` | red | green | blue | | | | | |
23-
| 4 | `draw color` | red | green | blue | alpha | | | | |
24-
| 5 | `draw col` | color | | | | | | | |
25-
| 6 | `draw stroke` | width | | | | | | | |
26-
| 7 | `draw line` | x1 | y1 | x2 | y2 | | | | |
27-
| 8 | `draw rect` | x | y | width | height | | | | |
28-
| 9 | `draw lineRect` | x | y | width | height | | | | |
29-
| 10 | `draw poly` | x | y | sides | radius | rotation | | | |
30-
| 11 | `draw linePoly` | x | y | sides | radius | rotation | | | |
31-
| 12 | `draw triangle` | x1 | y1 | x2 | y2 | x3 | y3 | | |
32-
| 13 | `draw image` | x | y | type | id | size | rotation | | lookup success (1 or 0) |
33-
| 14 | `draw print` | x | y | alignment | | | | | |
34-
| 15 | `draw translate` | x | y | | | | | | |
35-
| 16 | `draw scale` | x | y | | | | | | |
36-
| 17 | `draw rotate` | degrees | | | | | | | |
37-
| 18 | `draw reset` | | | | | | | | |
38-
| 19 | `drawflush` | | | | | | | | |
39-
40-
### `draw col`
15+
## Extensions
16+
17+
`rv32ima_Zicsr_Zicntr_Zihintpause`
18+
19+
| Extension | Version |
20+
| ----------- | ------- |
21+
| I | 2.1 |
22+
| M | 2.0 |
23+
| A | 2.1 |
24+
| Zicsr | 2.0 |
25+
| Zicntr | 2.0 |
26+
| Zihintpause | 2.0 |
27+
| Xmlogsys | N/A |
28+
29+
### Xmlogsys
30+
31+
This non-standard extension adds instructions to control the mlogv32 processor's hardware and access certain Mlog features.
32+
33+
| funct12 (31:20) | rs1 (19:15) | funct3 (14:12) | rd (11:7) | opcode (6:0) | name |
34+
| --------------- | ----------- | -------------- | --------- | ------------ | -------- |
35+
| funct12 | rs1 | `000` | `00000` | `0001011` | MLOGSYS |
36+
| funct12 | `00000` | `001` | rd | `0001011` | MLOGDRAW |
37+
38+
The MLOG instructions are encoded with an I-type instruction format using the _custom-0_ opcode. The zero-extended immediate is used as a minor opcode (funct12) for implementation reasons.
39+
40+
The MLOGSYS instruction is used for simple system controls, including halt, `printchar`, `printflush`, and `drawflush`.
41+
42+
| funct12 | rs1 | name |
43+
| ------- | ------- | ------------ |
44+
| 0 | `00000` | Halt |
45+
| 1 | char | `printchar` |
46+
| 2 | `00000` | `printflush` |
47+
| 3 | `00000` | `drawflush` |
48+
49+
The MLOGDRAW instruction is used for drawing graphics using the Mlog `draw` instruction. Arguments are passed to this instruction using registers a0 to a5 as necessary, and any return value is placed in _rd_. If _rd_ is specified as `00000` in the below table, no value will be written to `rd` in any case.
50+
51+
| funct12 | rd | a0 | a1 | a2 | a3 | a4 | a5 | name |
52+
| ------- | ----------------------- | ------- | ----- | --------- | ------ | -------- | -------- | ---------------- |
53+
| 0 | `00000` | red | green | blue | | | | `draw clear` |
54+
| 1 | `00000` | red | green | blue | alpha | | | `draw color` |
55+
| 2 | `00000` | color | | | | | | `draw col` |
56+
| 3 | `00000` | width | | | | | | `draw stroke` |
57+
| 4 | `00000` | x1 | y1 | x2 | y2 | | | `draw line` |
58+
| 5 | `00000` | x | y | width | height | | | `draw rect` |
59+
| 6 | `00000` | x | y | width | height | | | `draw lineRect` |
60+
| 7 | `00000` | x | y | sides | radius | rotation | | `draw poly` |
61+
| 8 | `00000` | x | y | sides | radius | rotation | | `draw linePoly` |
62+
| 9 | `00000` | x1 | y1 | x2 | y2 | x3 | y3 | `draw triangle` |
63+
| 10 | lookup success (1 or 0) | x | y | type | id | size | rotation | `draw image` |
64+
| 11 | `00000` | x | y | alignment | | | | `draw print` |
65+
| 12 | `00000` | x | y | | | | | `draw translate` |
66+
| 13 | `00000` | x | y | | | | | `draw scale` |
67+
| 14 | `00000` | degrees | | | | | | `draw rotate` |
68+
| 15 | `00000` | | | | | | | `draw reset` |
69+
70+
#### `draw col`
4171

4272
`color` should be in integer format, eg. `0xff0000ff`.
4373

44-
### `draw image`
74+
#### `draw image`
4575

4676
`type`: `lookup` type
4777

@@ -56,7 +86,7 @@ Code begins executing at address `0x4`. Address `0x0` must contain the size of t
5686

5787
Returns 1 if the id was successfully looked up, or 0 if the lookup returned null.
5888

59-
### `draw print`
89+
#### `draw print`
6090

6191
| Alignment | Value |
6292
| ----------- | ----- |

asm/branch.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ loop2:
1313
addi x3, x3, -1
1414
bge x3, x4, loop2
1515

16-
j 0
16+
loop:
17+
j loop

asm/large_bin.s

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ _start:
1515
sb zero, 3(x7)
1616
lw x9, 0(x7)
1717

18-
j 0
18+
loop:
19+
j loop
1920

20-
.section .data
21+
.section .rodata
2122

2223
.org 512
2324
.balign 4

asm/load.s

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ _start:
1515

1616
lh x12, 3(x0) # misaligned load exception
1717

18-
j 0
18+
loop:
19+
j loop
1920

20-
.section .data
21+
.section .rodata
2122
.balign 4
2223
word:
2324
.word 0x01020304 # LE: 0x04030201

asm/math.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ _start:
3232
li x23, 1
3333
sra x24, x22, x23
3434

35-
j 0
35+
loop:
36+
j loop

asm/print.s

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ _start:
55
la s2, msg_len
66

77
loop:
8-
lbu a0, 0(s0)
9-
li a7, 1 # printchar
10-
ecall
8+
lbu t0, 0(s0)
9+
.insn i CUSTOM_0, 0, zero, t0, 1 # printchar
1110

1211
addi s0, s0, 1
1312
addi s1, s1, 1
1413
blt s1, s2, loop
1514

16-
li a7, 2 # printflush
17-
ecall
15+
.insn i CUSTOM_0, 0, zero, zero, 2 # printflush
1816

19-
j 0
17+
.insn i CUSTOM_0, 0, zero, zero, 0 # halt
2018

21-
.section .data
19+
.section .rodata
2220
msg:
2321
.ascii "hello world!"
2422
.set msg_len, . - msg

asm/store.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ _start:
2828

2929
sw x2, 1(x1) # misaligned store exception
3030

31+
loop:
32+
j loop
33+
3134
.section .data
3235
.balign 4
3336
word:

asm/system.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ _start:
44
.word 0b00000001000000000000000000001111
55

66
ebreak
7-
8-
li a0, 0
9-
li a7, 0 # halt
7+
108
ecall
119

10+
loop:
11+
j loop

coremark/mlogv32/core_portme.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Original Author: Shay Gal-on
1717
*/
1818
#include "coremark.h"
1919
#include "core_portme.h"
20-
#include "ecall.h"
20+
#include "xmlogsys.h"
2121

2222
#if VALIDATION_RUN
2323
volatile ee_s32 seed1_volatile = 0x3415;
@@ -157,5 +157,5 @@ portable_fini(core_portable *p)
157157
{
158158
p->portable_id = 0;
159159

160-
ecall(0, 0, 0, 0, 0, 0, 0, Halt);
160+
MLOGSYS_halt();
161161
}

coremark/mlogv32/core_portme.mak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ LFLAGS_END = -nostartfiles -nolibc
5151
# Flag : PORT_SRCS
5252
# Port specific source files can be added here
5353
# You may also need cvt.c if the fcvt functions are not provided as intrinsics by your compiler!
54-
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/ecall.c $(PORT_DIR)/entry.s $(PORT_DIR)/cvt.c
54+
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/xmlogsys.c $(PORT_DIR)/entry.s $(PORT_DIR)/cvt.c
5555
vpath %.c $(PORT_DIR)
5656
vpath %.s $(PORT_DIR)
5757

58-
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/ecall.o $(PORT_DIR)/entry.o $(PORT_DIR)/cvt.o
58+
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/xmlogsys.o $(PORT_DIR)/entry.o $(PORT_DIR)/cvt.o
5959

6060
# Flag : LOAD
6161
# For a simple port, we assume self hosted compile and run, no load needed.

0 commit comments

Comments
 (0)