Move test in a specific folder
This commit is contained in:
21
example/asm.c
Normal file
21
example/asm.c
Normal 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
13
example/linker.ld
Normal 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
25
example/naked.c
Normal 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
34
example/print.S
Normal 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
16
example/section.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user