Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cache and code cache manager #59

Merged
merged 7 commits into from
Nov 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion shell/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ shell-$(ARCH): shell.c shell.link
endif

clean:
rm -f shell-*
rm -f shell-riscv64 shell-x86_64 shell-powerpc64le



Expand Down
55 changes: 28 additions & 27 deletions shell/shell.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#define NZONE_SIZE 512
#define NZONE_SIZE 1024
#define HEAP_SIZE 4096

#if defined(__x86_64)
# define ASM_RETURN "mov %rdi, %rax\nret"
Expand All @@ -19,36 +18,38 @@

__asm__(
" \n"
".section .nzone,\"awx\", @progbits\n"
".section .entry,\"aw\" \n"
"entry: \n"
".8byte nzone \n"
" \n"
".section .heap1,\"aw\" \n"
"heap1: \n"
".space " TOSTRING(HEAP_SIZE) " \n"
" \n"
".section .heap2,\"aw\" \n"
"heap2: \n"
".space " TOSTRING(HEAP_SIZE) " \n"
" \n"
".section .nzone1,\"awx\", @progbits\n"
"nzone: \n"
"nzone1: \n"
ASM_RETURN " \n"
".space " TOSTRING(NZONE_SIZE) " \n"
" \n"
" \n"
".section .nzone2,\"awx\", @progbits\n"
"nzone2: \n"
ASM_RETURN " \n"
".space " TOSTRING(NZONE_SIZE) " \n"
".section .text \n"
);

extern unsigned char nzone[NZONE_SIZE];

typedef int (*entry_func)(int a);
static entry_func entry = (entry_func)(&nzone);

static int __attribute__ ((noinline)) trampoline(int a) {
return entry(a);
}
extern int (*entry)(intptr_t a, intptr_t b);
extern unsigned char nzone1[NZONE_SIZE];
extern unsigned char nzone2[NZONE_SIZE];
extern unsigned char heap1[NZONE_SIZE];
extern unsigned char heap2[NZONE_SIZE];

int main(int argc, char** argv) {
int x = 0;
switch (argc) {
case 1:
x = 42;
break;
case 2:
x = strtol(argv[1], NULL, 10);
if (errno) return 127;
break;
default:
return 127;
break;
}
return trampoline(x);
return entry((intptr_t)argc, (intptr_t)argv);
}
13 changes: 11 additions & 2 deletions shell/shell.link
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
SECTIONS
{
.nzone 0x00080000 : { }
.entry 0x00090000 : { }

.nzone1 0x000A0000 : { }
.heap1 0x000B0000 : { }
}
INSERT AFTER .bss;
SECTIONS
{
.nzone2 0x7000C0000 : { }
.heap2 0x7000D0000 : { }
}
INSERT AFTER .text;
INSERT AFTER .bss;

8 changes: 4 additions & 4 deletions src/Tinyrossa-POWER/TRPPC64Linux.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Class {
#name : #TRPPC64Linux,
#superclass : #TRCompilationTarget,
#category : #'Tinyrossa-POWER-Compile'
#superclass : #TRTarget,
#category : #'Tinyrossa-POWER-Target'
}

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRPPC64Linux >> codeGeneratorClass [
^ TRPPC64CodeGenerator
]
Expand All @@ -14,7 +14,7 @@ TRPPC64Linux >> name [
^ 'powerpc64le-linux'
]

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRPPC64Linux >> systemLinkageClass [
^ TRPPC64PSABILinkage
]
6 changes: 6 additions & 0 deletions src/Tinyrossa-POWER/TRRuntimeConfig.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #TRRuntimeConfig }

{ #category : #'*Tinyrossa-POWER' }
TRRuntimeConfig class >> forPPC64Linux [
^ self forTarget: TRPPC64Linux default
]
8 changes: 4 additions & 4 deletions src/Tinyrossa-RISCV/TRRV64GLinux.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Class {
#name : #TRRV64GLinux,
#superclass : #TRCompilationTarget,
#category : #'Tinyrossa-RISCV-Compile'
#superclass : #TRTarget,
#category : #'Tinyrossa-RISCV-Target'
}

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRRV64GLinux >> codeGeneratorClass [
^ TRRV64GCodeGenerator
]
Expand All @@ -14,7 +14,7 @@ TRRV64GLinux >> name [
^ 'riscv64-linux'
]

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRRV64GLinux >> systemLinkageClass [
^ TRRV64GPSABILinkage
]
6 changes: 6 additions & 0 deletions src/Tinyrossa-RISCV/TRRuntimeConfig.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #TRRuntimeConfig }

{ #category : #'*Tinyrossa-RISCV' }
TRRuntimeConfig class >> forRV64GLinux [
^ self forTarget: TRRV64GLinux default
]
102 changes: 97 additions & 5 deletions src/Tinyrossa-Tests/TRCompilationTestShell.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ Class {
#instVars : [
'target',
'binary',
'debugger'
'debugger',
'codeCacheManager',
'nzone1Base',
'nzone1Size',
'nzone1',
'heap1Base',
'heap1Size',
'heap1',
'nzone2Base',
'nzone2Size',
'nzone2',
'heap2Base',
'heap2Size',
'heap2',
'entryBase',
'entrySize'
],
#classVars : [
'DefaultImpl'
Expand Down Expand Up @@ -65,17 +80,78 @@ TRCompilationTestShell >> debugger [
^ debugger
]

{ #category : #accessing }
TRCompilationTestShell >> entry [
"Return the value if (default) entry point in nzone"

| memory entry |

memory := debugger selectedInferior memory.

"BOGUS BOGUS"
entry := memory unsignedLongLongAt: entryBase bigEndian: false.
^ entry
]

{ #category : #accessing }
TRCompilationTestShell >> entry: entry [
"Set the address of entry point in nzone"

| memory |

memory := debugger selectedInferior memory.
"BOGUS BOGUS"
memory unsignedLongLongAt: entryBase put: entry bigEndian: false.
^ entry
]

{ #category : #accessing }
TRCompilationTestShell >> heap1 [
heap1 isNil ifTrue: [
heap1 := TRCodeCache runtime: (codeCacheManager runtime) base: heap1Base size: heap1Size memory: debugger selectedInferior memory.
codeCacheManager addSegment: heap1.
].
^ heap1
]

{ #category : #accessing }
TRCompilationTestShell >> heap2 [
heap2 isNil ifTrue: [
heap2 := TRCodeCache runtime: (codeCacheManager runtime) base: heap2Base size: heap2Size memory: debugger selectedInferior memory.
codeCacheManager addSegment: heap2.
].
^ heap2
]

{ #category : #initialization }
TRCompilationTestShell >> initializeWithTarget: aTRCompilationTarget [
target := aTRCompilationTarget.

"!!! Following must be kept in sync with values in
`shell.c` and `shell.link`"
nzone1Base := 16r000A0000.
nzone1Size := 1024.
heap1Base := 16r000B0000.
heap1Size := 4096.

nzone2Base := 16r7000C0000.
nzone2Size := 1024.
heap2Base := 16r7000D0000.
heap2Size := 4096.

entryBase := 16r00090000.
entrySize := 8.

codeCacheManager := TRCodeCacheManager runtime: (TRRuntime forTarget: target).

self setUp.
]

{ #category : #utilities }
TRCompilationTestShell >> inject: compilation [
"Utility: inject compiled code into the shell"

debugger memoryAt: self nzone put: compilation codeBuffer bytes
self nzone add: compilation codeBuffer
]

{ #category : #utilities }
Expand Down Expand Up @@ -115,7 +191,7 @@ TRCompilationTestShell >> invoke: symbol with: arguments types: argumentTypes [
self error: 'Parameter type not supported yet: ' , typ name
].
].
self debugger setRegister: 'pc' to: self nzone.
self debugger setRegister: 'pc' to: (nzone1 exports at: symbol).

"Call injected function"
"
Expand All @@ -136,9 +212,25 @@ TRCompilationTestShell >> invoke: symbol with: arguments types: argumentTypes [

{ #category : #accessing }
TRCompilationTestShell >> nzone [
"Return the address of nzone. See shell.link linker script."
^ self nzone1
]

^ 16r00080000
{ #category : #accessing }
TRCompilationTestShell >> nzone1 [
nzone1 isNil ifTrue: [
nzone1 := TRCodeCache runtime: (codeCacheManager runtime) base: nzone1Base size: nzone1Size memory: debugger selectedInferior memory.
codeCacheManager addSegment: nzone1.
].
^ nzone1
]

{ #category : #accessing }
TRCompilationTestShell >> nzone2 [
nzone2 isNil ifTrue: [
nzone2 := TRCodeCache runtime: (codeCacheManager runtime) base: nzone2Base size: nzone2Size memory: debugger selectedInferior memory.
codeCacheManager addSegment: nzone2.
].
^ nzone2
]

{ #category : #running }
Expand Down
6 changes: 3 additions & 3 deletions src/Tinyrossa-Tests/TRILTestTarget.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Class {
#name : #TRILTestTarget,
#superclass : #TRCompilationTarget,
#superclass : #TRTarget,
#category : #'Tinyrossa-Tests-Compile'
}

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRILTestTarget >> codeGeneratorClass [
^ TRILTestCodeGenerator
]
Expand All @@ -14,7 +14,7 @@ TRILTestTarget >> name [
^ '<triltests>'
]

{ #category : #accessing }
{ #category : #'accessing - config - compilation' }
TRILTestTarget >> systemLinkageClass [
^ TRILTestLinkage
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Extension { #name : #TRCompilationTarget }
Extension { #name : #TRTarget }

{ #category : #'*Tinyrossa-Tests' }
TRCompilationTarget >> gem5 [
TRTarget >> gem5 [
"Return name of Gem5 architecture suitable for running programs for this target.

For example, for RISC-V return `RISCV`,
Expand All @@ -15,7 +15,7 @@ TRCompilationTarget >> gem5 [
]

{ #category : #'*Tinyrossa-Tests' }
TRCompilationTarget >> qemu [
TRTarget >> qemu [
"Return name of QEMU suitable for running programs for this target."

^ self subclassResponsibility
Expand Down
Loading