Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emard
    @emard
    I was thinking, author of the riscv-lcc compiler would be great to come here to chat a bit, if he replies about saxonsoc efforts just invite him to join :)
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab I have execve working as well.
    Lawrie Griffiths
    @lawrie
    @emard He has replied, and I have invited him - michg/riscv32_lcc#1
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab Another Unix system call I don't know how to support is nice.
    Lawrie Griffiths
    @lawrie
    I am also not sure how to do signal. Linux has signalfd4.
    Also not sure how to do stime.
    Lawrie Griffiths
    @lawrie
    The Unix calls in your list that I haven't got an equivalent of are: alarm, mpxchan, chroot, creat, gtime,gtty. nice, nosys, nullsys. pause, profil, ptrace, rext, ssig, stime, stty, ftime, sysacct, syslock, sysphys.
    Do you think we need any of those?
    Paul Ruiz
    @pnru_gitlab
    The nice() system call adjusts the process priority. On Linux it is a wrapper, using setpriority() and getpriority():
    https://linux.die.net/man/2/nice
    https://linux.die.net/man/2/getpriority
    For the wrapper, read the notes on both man pages. Because valid return codes are -20..+20 and half of that range conflicts with the Linux error code range (-4095..-1) some trickery is involved. Use PRIO_PROCESS for which.
    Paul Ruiz
    @pnru_gitlab
    On the syscall list:
    • alarm & pause: not needed, nanosleep will do (with wrappers for sleep and usleep)
    • mpxchan: a (failed) networking experiment, not relevant.
    • chroot: still exists, but perhaps not in the 80% of usage list
    • creat & mknod: not needed, these have been rolled into open() flags.
    • gtty & stty: not needed, these have been replaced by ioctl(), which you have
    • nosys & nullsys: not needed - nosys is a placeholder for calls that have not been included and results in a ENOSYS error (like you saw yesterday) and nullsys is for a call that was silently ignored.
    • profil was used for profiling code. Not sure how this works on Linux and can be ignored for now, I think.
    • ptrace was the original debugger interface and can be ignored. How this works on Risc-V linux will come back as a topic if we ever do a debugger for lcc code.
    • rexit: internal name of exit(); you already have that one
    • ssig: sets the signal mask. Signals (at least historically) need a fairly complex support routine in user space to work - I suggest we leave it too later.
    • gtime, stime, ftime: gtime is the internal name of time(). stime sets the time, needs root privilege and will be needed for Emard's RTC code, ftime gets time at millisecond resolution and is maybe outside the "80% set".
    • sysacct, syslock, sysphys: historical accounting and file locking. Can safely be skipped.
    I've been too quick on mknod. I think you will need to include mkdir and rmdir in the core lcc set. Come to think of it, maybe nice is also not in the 80% of usage set.
    Lawrie Griffiths
    @lawrie
    @emard There is a new version of riscv32_lcc.tar.gz in Smp/images with my latest system calls.
    I also added an examples directory with my C test code.
    emard
    @emard
    eheheeee I will download
    not yet updated at Smp
    Lawrie Griffiths
    @lawrie
    It is there now
    emard
    @emard
    dowloading extra fresh!
    Lawrie Griffiths
    @lawrie
    I will add setpriority, getprioriity, mkdir and rmdir.
    I don't know what the Linux system calls are for time and stime - perhaps settimeofday, gettimeofday.
    Lawrie Griffiths
    @lawrie
    I don't know what the parameters are for signalfd4, but as you say, we can leave signals for the moment.
    @pnru_gitlab Not sure how do do rmdir. I have unlinkat - perhaps that does it.
    Paul Ruiz
    @pnru_gitlab
    Yes: https://linux.die.net/man/2/unlinkat
    AT_REMOVEDIR is defined as 0x200
    Paul Ruiz
    @pnru_gitlab
    time and stime are clock_gettime and clock_settime on Linux:
    https://man7.org/linux/man-pages/man2/clock_settime.2.html
    Use CLOCK_REALTIME as the clock id (= 0).
    Paul Ruiz
    @pnru_gitlab
    For signals, the right base call is probably sigaction. I've been too focussed on ancient Unix it seems.
    https://man7.org/linux/man-pages/man7/signal.7.html
    Lawrie Griffiths
    @lawrie
    OK, I have added mkdirat, sigaction, clock_gettime, clock_settime, gettimeofday, settimeofday, getpriority and setpriority.
    That should be enough system calls for now. I need to look into wrappers next.
    Lawrie Griffiths
    @lawrie
    I have updated both riscv32_lcc.tar.gz and https://github.com/lawrie/riscv32_lcc/blob/master/lcc/bin/libs/stdlib/syscall.s with the latest system calls.
    emard
    @emard
    getting
    Lawrie Griffiths
    @lawrie
    It won't be much different to the previous one as the new system calls are untested.
    Paul Ruiz
    @pnru_gitlab
    @emard maybe enough works already to compile lcc's assembler.
    emard
    @emard
    I just downloaded and void main(void) printf exits correctly without return 0;. So much functions are added, I need to probably test only time-setting functions
    Lawrie Griffiths
    @lawrie
    One problem with clock_gettime and clock_settime is that tv_nsec (nanoseconds) needs a 64-bit long. A more minor problem, is that the C library does not have the relevant structs sand typedefs defined.
    Lawrie Griffiths
    @lawrie
    #include <stdio.h>
    #include <time.h>
    
    #define CLOCK_REALTIME 0
    
    typedef int clockid_t;
    
    struct timespec {
      time_t tv_sec;
      long tv_nsec;
    };
    
    int main(int argc, char **argv)
    { 
      int result;
      struct timespec tp;
      clockid_t clk_id;
    
      clk_id = CLOCK_REALTIME;
    
      result = clock_gettime(clk_id, &tp);
      printf("result: %i\n", result);
      printf("tp.tv_sec: %lld\n", tp.tv_sec);
      printf("tp.tv_nsec: %ld\n", tp.tv_nsec);
    
      return 0;
    }
    Nanoseconds overflow after about 2 seconds on 32-bit systems.
    emard
    @emard
    hwclock is not likely to execute more than 2 seconds :). It's not related, but if possible I'd also like to try 12F 2-core version if you compile next time upload some 12F smp too
    full wraparound is 4.3s but for signed intverval comparison useable delay is 2.15s
    emard
    @emard
    clock_settime works
    Lawrie Griffiths
    @lawrie
    I am not sure if a 2-cpu system will fit on a 12f. I am trying it.
    emard
    @emard
    Ahaaa, it's not necessary dont worry, if it compiles great, if not, don't optimiize
    emard
    @emard
    I got segfault with atoi(argv[1]) wanted to convert string to integer, any other way? Still I can do it low-level though
    Lawrie Griffiths
    @lawrie
    This works (provided you give in an integer arg):
    #include <stdlib.h>
    
    int main(int argc, char *argv[]) {
      return atoi(argv[1]);
    }
    emard
    @emard
    I got segfault with this
      printf("argc %d\n", argc);
      if(argc > 0)
      {
        val=atoi(argv[1]);   
        printf("argv[1] %d\n", val);
      }
    oh but now I cant reproduce it! :)
    anyway consider it just a glitch...
    Lawrie Griffiths
    @lawrie
    It works for me. But there are obviously still some bug around.
    emard
    @emard
    If something more stubborn bug appears, I'll report, so far so good :)
    Paul Ruiz
    @pnru_gitlab
    I'm surprised get/set_time work in the above. If I understood correctly Risc-V32 Linux uses a 64-bit time type, but LCC does not have 64 bit types and its library defines time_t as 32-bit. Hence the above code passes a buffer with space for two 32-bit words, and the kernel then writes/reads three 32 bit words to/from that space. Maybe time_t is 32 bit on Risc-V32 Linux after all.