Move test in a specific folder

This commit is contained in:
Fabio Scotto di Santolo
2025-11-29 18:47:37 +01:00
parent c59b4004e5
commit 7eaf73e6fe
6 changed files with 0 additions and 0 deletions

21
example/asm.c Normal file
View File

@@ -0,0 +1,21 @@
#include <stdio.h>
int add(int a, int b)
{
int result;
asm volatile (
"addl %2, %1;" // Add b
"movl %1, %0;"
: "=r" (result)
: "r" (a), "r" (b)
: "cc"
);
return result;
}
int main(void)
{
int x = 10, y = 20;
printf("%d + %d = %d\n", x, y, add(x, y));
return 0;
}

13
example/linker.ld Normal file
View File

@@ -0,0 +1,13 @@
SECTIONS
{
. = 0x80200000;
.text : {
*(.text.entry) /* entry point */
*(.text*) /* all text sections */
}
.rodata : { *(.rodata*) }
.data : { *(.data*) }
.bss : { *(.bss*) }
}

25
example/naked.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdio.h>
// No function prologue/epilogue - raw assembly only
__attribute__((naked))
void my_naked_function()
{
__asm__ volatile (
"movl $42, %eax\n\t"
"ret"
);
}
int main()
{
int result;
__asm__ volatile (
"call my_naked_function\n\t"
"movl %%eax, %0\n\t"
: "=r"(result)
:
: "%eax"
);
printf("Result from naked function: %d\n", result);
return 0;
}

34
example/print.S Normal file
View File

@@ -0,0 +1,34 @@
.section .text
.globl _start
_start:
li a0, 72 # ASCII 'H'
li a7, 1 # SBI call ID for sbi_console_putchar
ecall # Make the SBI call
li a0, 101
li a7, 1
ecall
li a0, 108
li a7, 1
ecall
li a0, 108
li a7, 1
ecall
li a0, 111
li a7, 1
ecall
li a0, 10
li a7, 1
ecall
li a7, 93 # SBI call: shutdown
li a0, 0 # exit code 0
ecall
loop:
j loop # Infinite loop after printing

16
example/section.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h>
int var __attribute__((section("custom_data"))) = 1337;
__attribute__((section("custom_text")))
void custom()
{
printf("Hello from custom() in custom section!\n");
}
int main()
{
printf("var = %d\n", var);
custom();
return 0;
}