Comments (6)
Is something in crt0.c required for this? Should syscalls.c exit() have a fflush(stdout)?
from baremetal-os-legacy.
The standard C exit
function provided by newlib calls the _exit
function defined in the syscalls.c
file. Currently, the BareMetal syscalls.c
_exit
function is defined as follows:
// exit -- Exit a program without cleaning up files
int _exit(int val)
{
exit(val);
return (-1);
}
The call to the standard C exit
function creates an infinite recursion which I believe leads to the crash.
This _exit
function should be reimplemented to use an appropriate BareMetal system call in order to "exit the program without cleaning up files." Furthermore, the _exit
function prototype's return type is void
so the function should not return a value.
from baremetal-os-legacy.
One possible (but probably horrible) solution would be to call the command line in exit()...
from baremetal-os-legacy.
Actually, since the description of the _exit
function explicitly states that the program should not clean up files, simply calling the command line in the _exit
function would provide the behavior we expect in a monotasking operating system like BareMetal: the running program exits immediately to the command line, thus allowing the next program to run.
Note that this would be a minimal implementation that should be improved in the future: most users expect operating systems to clean up files for them on a standard C _Exit
call; however, the minimal implementation will at least solve the crash and make the function usable.
Refer to section 7.20.4.4 of the C99 standard for more information on the standard C requirements of the _Exit
function (of which the newlib _exit
function is essentially an alias).
from baremetal-os-legacy.
I'm not sure if this will compile, but it should be close to the general solution for a minimal implementation (note the void
return type):
// exit -- Exit a program without cleaning up files
void _exit(int val)
{
asm volatile ("call os_command_line");
}
The os_command_line
routine is in the cli.asm file, but since it wasn't aligned in the kernel_start
routine in the kernel64.asm file like the other system calls, I'm not sure if that inline assembly I added will work -- I'm not familiar enough with the code.
from baremetal-os-legacy.
Please have a look at #83 for some possible solutions.
from baremetal-os-legacy.
Related Issues (20)
- porting baremetal-os on risc-v HOT 3
- It's actually 2015 now... HOT 3
- Memory mapped files (or file mapped virtual address space for one program/process/thread) HOT 9
- [INFO] 64-bit ARM HOT 7
- Stuck at iddrive_poll with VirtualBox HOT 7
- asm2c
- SATA drive support HOT 3
- Use switch tables instead of long strings of cmp/je combos HOT 2
- README.md says autoconf -fi HOT 4
- Boot from usb HOT 1
- tried to add elf format support but failed to run any app HOT 2
- Safe to run on a physical host yet? HOT 1
- Hi, I can't to run the BareMetal-OS HOT 5
- BareMetal Rust HOT 2
- e1000 driver does not setup bus mastering HOT 5
- CRLF or LF or CR or ? HOT 4
- os_output_char in Kernel API HOT 5
- LICENCE.TXT / CREDITS.TXT HOT 3
- BareMetal Rust PoC HOT 4
- Loader HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baremetal-os-legacy.