How to set up Exception handler for Syscall
How to set up Exception handler for Syscall
How to set up an exception handler for Syscall instruction. I want to use the syscall instruction to access functions etc from Main program. Currently im just using Callx8 to jmp' to the functions fixed Address from external program(App) but even thought it works its not ideal because the Address of function can change as you move code around.
-
- Posts: 1694
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to set up Exception handler for Syscall
Can't you let the linker do its thing and manage functions' addresses?
Re: How to set up Exception handler for Syscall
its an external app which gets loaded later on and is compiled on its own( Not from arduino ide but directly from assembler). I believe the syscall instruction was made for that purpose. Basically its an app calling functions from main "kernel".
Think of it like how any operating system loads an executable and the executable uses the kernel functions via system calls. Already wrote code for loading apps via sd and running it. Rn the app uses Fixed Address pointers to call functions from "kernel" which as i said is not ideal because everytime you change code in arduino sketch the function's address changes. You have to recompile the user app with function pointer changes which is a hassle.
Anyway im just designing a portable console and to load different games it is necessary. Im not gonna depend on reflashing internal flash chip like how others have done it.
Also if you're wondering why im using xtensa assembler for user app is because it generates position independent code with no dependencies. I might try moving to using xtensa c or c++ compiler later for user app to see if it will work also.
Think of it like how any operating system loads an executable and the executable uses the kernel functions via system calls. Already wrote code for loading apps via sd and running it. Rn the app uses Fixed Address pointers to call functions from "kernel" which as i said is not ideal because everytime you change code in arduino sketch the function's address changes. You have to recompile the user app with function pointer changes which is a hassle.
Anyway im just designing a portable console and to load different games it is necessary. Im not gonna depend on reflashing internal flash chip like how others have done it.
Also if you're wondering why im using xtensa assembler for user app is because it generates position independent code with no dependencies. I might try moving to using xtensa c or c++ compiler later for user app to see if it will work also.
-
- Posts: 1694
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to set up Exception handler for Syscall
Ok, I think I get you.
In my understanding, the syscall is indeed intended for calls into an OS. On systems with memory protection /"world controller" its main purpose would be to switch between security contexts.
A common way to achieve the dynamic linking you want is to define a structure that holds a bunch of function pointers. This structure defines the interface between the separate parts of the application, or an 'application' and the runtime environment. When the application is loaded and started, it is passed a pointer to an instance of this structure and from then on uses the provided function pointers to call into the runtime environment.
Of course, this function table can grow quickly because you may have to provide almost everything the dynamic code may need, starting from standard functions like memcpy, math functions, and other stuff from the ROM or cstd, to more complex functions e.g. from the IDF.
I believe gcc already generates position-independent code (PIC) on Xtensas. But you could also look into defining a fixed address to which every 'application' is loaded; this in turn would much resemble the concept of OVERLAYS which may also be possible to leverage with the gcc toolchain.
In my understanding, the syscall is indeed intended for calls into an OS. On systems with memory protection /"world controller" its main purpose would be to switch between security contexts.
A common way to achieve the dynamic linking you want is to define a structure that holds a bunch of function pointers. This structure defines the interface between the separate parts of the application, or an 'application' and the runtime environment. When the application is loaded and started, it is passed a pointer to an instance of this structure and from then on uses the provided function pointers to call into the runtime environment.
Of course, this function table can grow quickly because you may have to provide almost everything the dynamic code may need, starting from standard functions like memcpy, math functions, and other stuff from the ROM or cstd, to more complex functions e.g. from the IDF.
I believe gcc already generates position-independent code (PIC) on Xtensas. But you could also look into defining a fixed address to which every 'application' is loaded; this in turn would much resemble the concept of OVERLAYS which may also be possible to leverage with the gcc toolchain.
-
- Posts: 1694
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to set up Exception handler for Syscall
Btw: To be able to dynamically load and run code, as an alternative you may want to look into interpreted or bytecode languages.
I find Microvium (JavaScript) intriguing. WASM could have pretty decent performance, and there seem to be a couple of engines which can/could run on an ESP32 (e.g. Espressif's esp-wasmachine, WAMR,...)
I find Microvium (JavaScript) intriguing. WASM could have pretty decent performance, and there seem to be a couple of engines which can/could run on an ESP32 (e.g. Espressif's esp-wasmachine, WAMR,...)
Re: How to set up Exception handler for Syscall
I dont need a interpreter. My code runs natively on esp32 ,no translation layer. My question wasnt about Running code its about setting up an exception handler for syscall.
Syscall generates an exception interrupt by design like esp32s illegal instruction or loadstoreerr cpu exceptions. I just want use my own interrupt handler to handle that event. Which is how it was intended to be used to access kernel functions/request from a user app. In arm arduino library for stm32 its a simple thing but i do not know how to set it up for esp32.that is what im asking.
Syscall generates an exception interrupt by design like esp32s illegal instruction or loadstoreerr cpu exceptions. I just want use my own interrupt handler to handle that event. Which is how it was intended to be used to access kernel functions/request from a user app. In arm arduino library for stm32 its a simple thing but i do not know how to set it up for esp32.that is what im asking.
-
- Posts: 1694
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to set up Exception handler for Syscall
No, it wasn't. Your question was about how to integrate/dynamically link code with your 'host' application at runtime. Naturally, all interpreted/byte code language engines already have solutions for this problem. As well as memory management for the hosted code, sharing/exchanging data/variables with the runtime, support for code bigger than whatever the host has left of unused IRAM, isolation/protection of the host environment from misbehaving 'guests', &c.My question wasnt about Running code...
Syscall is not the solution you're looking for. There is xt_set_exception_handler(), but:
As I said: You can pass a pointer from the runtime environment to the dynamically loaded code.Note that some exceptions are handled
by the porting layer itself, and cannot be taken over by application
code in this manner. These are the alloca, syscall, and coprocessor
exceptions.
Or store a pointer at a defined address just like an interrupt vector table would.
Re: How to set up Exception handler for Syscall
If its in use then oh well but is it possible to use software interrupt. On x86 you can define a software interrupt then just use int [irq number] to trigger it. Idk if thats possible on esp32.
Theres an instruction ILL which always generates exception, i used that but it reboots esp32 after processing the exception. It really should not reboot but idk
Theres an instruction ILL which always generates exception, i used that but it reboots esp32 after processing the exception. It really should not reboot but idk
-
- Posts: 1694
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to set up Exception handler for Syscall
Yeah, apparently software interrupts aren't really a thing on the Xtensa architecture.
On the ESPs, there should be ways to trigger a CPU (internal) interrupt by setting a bit in some interrupt status register, but details are scarce.
On the ESPs, there should be ways to trigger a CPU (internal) interrupt by setting a bit in some interrupt status register, but details are scarce.
Re: How to set up Exception handler for Syscall
Yeh its really hard to find stuff for xtensa architecture. btw I solved the issue of restarting on illegal exception by changing the pc register. So syscalls via the ILL instruction works now. Right now it checks the value of certain registers to determine if its done by the ILL instruction intentionally or unintentionally
Thanks for the help
Thanks for the help
Who is online
Users browsing this forum: No registered users and 48 guests