RISC OS Open
Safeguarding the past, present and future of RISC OS for everyone
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account
Forums → Porting RISC OS →

C Kernel

Subscribe to C Kernel 97 posts, 23 voices

Posts per page:

Pages: 1 2 3 4

 
Jan 26, 2021 4:14pm
Avatar Krzysztof Jeszke (6296) 30 posts

Greetings, will we ever get to see RISC OS’ kernel rewritten in C? It could definetly improve the efficency of porting. Or, if it is planned. For what version estimated would it be released?

 
Jan 27, 2021 9:49am
Avatar Julie Stamp (8365) 404 posts

There are plenty of routines that could be written right now, for example a VDU driver.

 
Jan 27, 2021 10:56am
Avatar Rick Murray (539) 11560 posts

My understanding is that the things that one can do in C in the kernel is fairly limited.

Perhaps the first job should be to teach the kernel about the C runtime, so that code written in C can make use of library facilities (stderr → DebugTX for instance), as well as stack checking and the like.

 
Jan 27, 2021 2:39pm
Avatar Krzysztof Jeszke (6296) 30 posts

I mean, you’d definetly would be able to rewrite the stuff that is not necessarily only possible in ASM. The rest would be left to ASM, like drivers or very optimized stuff..?

 
Jan 27, 2021 11:11pm
Avatar Timothy Baldwin (184) 238 posts

I started rewriting it in C++ for x86 Linux many years ago, it managed to run FileSwitch, MessageTrans, ResourcesFS and BASIC.

I have partly reimplemented dynamic areas and OS_AMBControl in C with Linux system calls.

And someone else has partly reimplemented RISC OS in Python, with an online demo.

First we should:

  1. Remove the SysCommsModule pseudo-module.
  2. Build the kernel using relocatable AOF and support multiple source files.
  3. Rearrange the directory structure.
 
Jan 28, 2021 9:45am
Avatar Krzysztof Jeszke (6296) 30 posts

In my honest opinion i think that a linux port would make RISC OS not so unique and fast, like it’d get lost in between other linux distros. RISC OS should stay as it is but be more of cross-platform than just ARM

 
Jan 28, 2021 10:06am
Avatar Julie Stamp (8365) 404 posts

Those changes all look good Timothy :-) Once somebody goes over the hurdle of putting the first bit of C in, it will give a template for other people to follow.

Can I please emphasise again to any prospective volunteers: you do not have to wait for the above changes before writing code. There are plenty of things to get stuck in with, which you can write as a standalone feature (as a module or even in an application test bed) and which we can join up with the system at a later date, whether that be putting into the kernel, or as a separate module.

 
Jan 31, 2021 11:24am
Avatar Michael Grunditz (8594) 115 posts

I started rewriting it in C++ for x86 Linux many years ago, it managed to run FileSwitch, MessageTrans, ResourcesFS and BASIC.

Now that is a great effort! Very interesting with BASIC on x86.

 
Jun 6, 2021 10:26am
Avatar Simon Willcocks (1499) 184 posts

For what it’s worth, pretty much the only thing you really need to run C code is a stack, and that’s just an area of memory. No standard C library or functions are required.

GCC has inline assembler for the very few times you absolutely need it.

A linker script can locate the appropriate code at the start of the object file (along with locations of important places, like the location of the page after the OS) and objcopy can create a binary image.

Here, for example, is some startup code for a Pi3 (in aarch64), your C code in c_el3_nommu gets a section of memory (with a stack at the top of it) for each core:

/* Copyright © 2020 Simon Willcocks */

// Establish a stack for each core, at the top of an anonymous struct Core, and call a C routine.
//
// The size of the Core structure must be defined at compilation as CORE_SIZE (I recommend a multiple of 4k)

typedef struct Core Core;

void attribute(( noreturn, noinline )) c_el3_nommu( Core *core, int number );

asm ( “.section .init”
“\n.global _start”
“\n.type _start, %function”
“\n_start:”
“\n\tmrs x0, mpidr_el1”
“\n\tmov x3, #”CORE_SIZE
“\n\ttst x0, #0×40000000”
“\n\tand x1, x0, #0xff”
“\n\tcsel x1, x1, xzr, eq” // core number
“\n\tadr x0, initial_first_free_page”
“\n\tmadd x0, x1, x3, x0”
“\n\tadd sp, x0, x3”
“\n\tb c_el3_nommu”
“\n.previous” );

 
Jun 6, 2021 12:09pm
Avatar Jeffrey Lee (213) 5982 posts

Interesting – I didn’t know that you could place asm blocks outside of functions.

In terms of getting C code into the RISC OS kernel, I’ve taken Timothy’s relocatable AOF changes and built on top of them to allow ordinary C code to be used in the kernel. The data section has its address fixed at link time, so there’s no need to worry about relocation offsets, which makes things nice and simple when assembler needs to call into C or access variables in the RW/ZI data sections. Annoyingly I did have to write a custom tool to help with the linking; Norcroft’s binary output was appending the zero-init section on to the end of the binary, so instead I’m having it link to AIF and then my custom tool strips off the header leaving just the code/read-only section & the data used to populate the read-write section.

Expect to see those changes sometime in the next few weeks when the code to add OS_AbortTrap gets submitted.

Currently the code is being built with “-APCS 3/32bit/nofp/noswst”, the same as HAL C code, however that doesn’t match any of the build configurations that we’re using for libraries. So we might either have to switch to different settings, or update the shared makefiles so that suitable libraries can easily be built.

 
Jun 6, 2021 2:33pm
Avatar Simon Willcocks (1499) 184 posts

The .previous directive at the end is important, if you don’t want variables to end up in read-only memory.

My ld script is as follows, which allows memory management code to allocate memory appropriately.

/* Copyright © 2014-2017 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT(“elf64-littleaarch64”)
OUTPUT_ARCH(aarch64)
ENTRY
SECTIONS
{
. = 0×0;
at_ro_start = .;
.init : { *(.init) }
.text : { *(.text) }
.rodata : { *(.rodata) }
. = ALIGN (4096);
at_rw_start = .;
.data : { *(.data) }
.bss : { *(.bss) }
. = ALIGN (4096);
at_rw_end = .;

.data_driver : { *(.data_driver) } . = ALIGN (4096); initial_first_free_page = .; pad_to_here = .; /* Needed for build.sh */

}

 
Jun 6, 2021 7:04pm
Avatar Steve Pampling (1551) 7104 posts

Copyright © 2014-2017 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification…

Sailing close, turn away.

 
Jun 6, 2021 10:27pm
Avatar Simon Willcocks (1499) 184 posts

I think there are three whole lines of the original, and it doesn’t make up any part of the final product. Claiming copyright on that basis would be the same as claiming copyright because I edited the code using vim.

 
Jun 7, 2021 12:19am
Avatar Steffen Huber (91) 1764 posts

Sailing close, turn away.

??? Simon did exactly what that header expressly says to be allowed.

 
Jun 7, 2021 6:37am
Avatar Steve Pampling (1551) 7104 posts

??? Simon did exactly what that header expressly says to be allowed.

Indeed he did.

Which takes us as close to GPL as we could deal with.

 
Jun 7, 2021 6:42am
Avatar Chris Mahoney (1684) 1880 posts

Your post is the first to mention GPL in this thread. Assuming that the code sample above contains the full copyright notice (as required by said notice) then the GPL isn’t involved. It appears to be an all-permissive licence.

 
Jun 7, 2021 7:43am
Avatar Rick Murray (539) 11560 posts

It’s probably a lack of trust in anything to do with the FSF.

 
Jun 7, 2021 9:29am
Avatar Andrew McCarthy (3688) 360 posts

It’s probably a lack of trust in anything to do with the FSF.

Steve P randomly tossing off-topic © hand grenades into conversations; why? → Aldershot. Sighs.

 
Jun 7, 2021 9:39am
Avatar David Pitt (3386) 1226 posts

Steve P randomly tossing off-topic © hand grenades into conversations; why?

Why indeed – massively entitled …

Sighs +=1

 
Jun 7, 2021 12:56pm
Avatar Paolo Fabio Zaino (28) 1106 posts

@ Jeffrey

or update the shared makefiles so that suitable libraries can easily be built.

If there is a chance to update the Shared Makefiles, can someone please have a look at the way CUtil is behaving? It systematically tries to link the util code against ansilib, not sure why, sounds more something left unseen from the dependencies on CApp or something…

I haven’t posted in bugs yet because I am not sure if this is a wanted behaviour or not, doesn’t make sense to me, but that doesn’t mean it’s a bug. The fix I use now it’s simple, just set `UTIL_LIBS =` after including CUtil, so not a big issue.

Thanks

 
Jun 7, 2021 1:34pm
Avatar David Pitt (3386) 1226 posts

can someone please have a look at the way CUtil is behaving? It systematically tries to link the util code against ansilib, not sure why, sounds more something left unseen from the dependencies on CApp or something…

Had a look in DDE30b using Steve Fryatt’s Locate.

AcornC/C++.Makefiles.CUtil contains :-

# You can't currently use the shared C library from a transient
UTIL_LIBS := $(filter-out ${CLIB},${APP_LIBS}) ${ANSILIB}

ANSILIB is defined in AppLibs and ModuleLibs :-

ANSILIB   = CLIB:o.ansilib

HTH.

 
Jun 7, 2021 1:52pm
Avatar Paolo Fabio Zaino (28) 1106 posts

yup David, thx.

As I said the fix in a MakeFile is super easy, just set UTIL_LIBS=(empty), so no need to alter my copy of SharedMakefiles. What I am asking mostly is: Is that ansilib linking a desired behaviour for reasons I do not know? hence the question here on the fly and not posting in bugs first.

For every future reading, I do not recommend to alter your DDE files, your changes may be overwritten during an update, so eventually set’s the variables as I shown in your own MakeFile instead.

 
Jun 7, 2021 2:16pm
Avatar Jeffrey Lee (213) 5982 posts

What I am asking mostly is: Is that ansilib linking a desired behaviour for reasons I do not know?

I suspect it’s intentional. CApp & CModule both link to the shared C library by default, so for consistency it makes sense that CUtil would also link to a C runtime/library. And because the SCL doesn’t support utilities, they went with the next-best thing, which is ANSILib (a static build of the SCL).

However, when Julie Stamp ran into problems when trying to use CUtil with ANSILib, I could only find two examples of code in the source tree that use CUtil, neither of which use it “normally”, so it’s possible that it’s a bit broken/incomplete.

 
Jun 7, 2021 9:14pm
Avatar Paolo Fabio Zaino (28) 1106 posts

@ Jeffrey

I suspect it’s intentional.

I could only find two examples of code in the source tree that use CUtil, neither of which use it “normally”, so it’s possible that it’s a bit broken/incomplete.

Thanks a lot for the quick answer! Sorry for replying so late, but I am having a crazy day at work…

Ok will post something in bugs later then, cheers!

 
Jun 8, 2021 8:47am
Avatar Colin Ferris (399) 1365 posts

Perhaps one could contact Adrian L and see if they could use his CLib replacement library .If they want to write ‘C’ stand alone programs

Next page

Pages: 1 2 3 4

Reply

To post replies, please first log in.

Forums → Porting RISC OS →

Search forums

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Description

Technical discussions for people porting RISC OS to new hardware.

Voices

  • Krzysztof Jeszke (6296)
  • Julie Stamp (8365)
  • Rick Murray (539)
  • Timothy Baldwin (184)
  • Michael Grunditz (8594)
  • Simon Willcocks (1499)
  • Jeffrey Lee (213)
  • Steve Pampling (1551)
  • Steffen Huber (91)
  • Chris Mahoney (1684)
  • Andrew McCarthy (3688)
  • David Pitt (3386)
  • Paolo Fabio Zaino (28)
  • Colin Ferris (399)

Options

  • Forums
  • Login
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Beast theme is based on Beast's default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Beast © 2006 Josh Goebel and Rick Olson
This site runs on Rails

Hosted by Arachsys