Code Monkey home page Code Monkey logo

Comments (6)

IanSeyler avatar IanSeyler commented on May 20, 2024

Is something in crt0.c required for this? Should syscalls.c exit() have a fflush(stdout)?

from baremetal-os-legacy.

vilhelmgray avatar vilhelmgray commented on May 20, 2024

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.

ohnx avatar ohnx commented on May 20, 2024

One possible (but probably horrible) solution would be to call the command line in exit()...

from baremetal-os-legacy.

vilhelmgray avatar vilhelmgray commented on May 20, 2024

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.

vilhelmgray avatar vilhelmgray commented on May 20, 2024

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.

benaryorg avatar benaryorg commented on May 20, 2024

Please have a look at #83 for some possible solutions.

from baremetal-os-legacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.