public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Help porting newlib to a new CPU architecture (sorta)
@ 2021-07-06 21:08 ElijaxApps
  2021-07-06 22:00 ` Joel Sherrill
  0 siblings, 1 reply; 21+ messages in thread
From: ElijaxApps @ 2021-07-06 21:08 UTC (permalink / raw)
  To: newlib

Hi, thank you a lot four your great responses, them really got me on some
direction.

>even DOS (iiuc) requires at least a 16-bit CPU.  not sure FreeDOS supports
>16-bit though, or if it too requires 32-bit.
>-mike

Well, Libre 8 has:
4 GP 8 Bit registers for math operations. 16 Bit integers are not a big
problem,  if:
  - I could use 2 cycles for batching the operation,
  - I could use registers 2 on 2 (and update ALU width).
Or even I could rewrite the microcode of my CPU to make it work
independently, as in
  - Sum lower 8 bits, push to stack,
  - Sum higher 8 bits, push to stack,
  - On return (int) pop twice.

In memory terms it has 24 bit address RAM, all of them addressable and
directionable in 3 cycle jumps. No segmentation, no paragraphs, just plain
16MB of RAM in a single component. That's why I am confident about using a
DOS-like OS.

>Consider the AVR toolchain, used in Arduino.  Isn't that an 8-bit
machine?  It certainly is small.
>paul

Thanks for the tip! I have checked, I think this is the source code:

https://github.com/esp8266/Arduino/tree/master/cores/esp8266

Could you point out what files I need to rewrite? Thanks in advance.
Correct me if that is not the code, and in case I finally decide this
approach I'll move to its mailing list.

>The full toolchain includes libc, libbfd, binutils, gcc, which would
>have to be bootstrapped by cross-compiling from a host system.

>There is an AVR target which may support 8b and avr-libc which should
>support the toolchain.

>There is also an Arduino toolchain based off the AVR toolchain which
>supports developing and loading sketches which run on pretty bare 8b MCUs.

>You may be better off targeting the latter approach for simplicity.
>A lot may depend on how close a match you can find between your target
>architecture and some existing architecture.

Yeah, I've been checking GCC repository and there is already an AVR target,
that I could use as a base to make Libre 8 target. Another candidate is z80
you mentioned, with the only caveat of having to implement 16b integer
operations on my CPU firmware (not hard at all).

I know I will have to cross-compile at least once libc for using it, then
crosscompiling gcc itself, and it should be done then the compilation of
the full toolchain in the Libre 8 CPU itself. But the latter part is for
the moment out of scope, as I have very limited resources on the CPU and no
disk nor filesystem, just plain RAM (I was thinking on defining programs
and files as memory offsets, and made them reside in memory, in a future,
or . . . designing a component in logisim suitable as a hard disk with its
filesystem and such...)

Or, compiling every monolithic program I want to run as STATIC, so it will
include dependant libraries binary code on the executable.

For this, I need the libc library to be embedded, and that is why I reached
newlib.

@Orlando: You're pointing the very right direction there, I'll be quiet on
the quotes.

- I got already an assembler, written in Java. Is more like a parser, it
just transcribes a bunch of implemented opcodes into its binary format for
Libre 8. But I want to use any preexisting toolchain, as gcc ones. In other
case I would end rewriting the full toolchain. However, your indication
about porting GAS is actually a thing I really considered before.

So as far as I understand now, it is not only porting newlib, *I have to
port also to port GAS (GNU Assembler) and GCC (GNU compiler)? Take in mind
I just want to CROSS-COMPILE binaries.*

- How its an ABI formally defined on code? How is defined AVR - ABI? Could
you point some sources? I googled without finding much about ABI
definitions - "as is".

- Architecture is Von-Neumann (Instructions and Data ar mixed in a single
memory compartiment). Decoder will find instructions and data in the same
input.

- I found this project (
https://docs.platformio.org/en/latest/platforms/creating_platform.html )
which allows you to define toolchain components and right, I would need
only to change gas to libre 8 compiler. BUT, I would need some kind of
workaround to make C compiler to output mine pseudo assy, which I no doubt
it is possible but would be crappy. - OR, I just have to port GAS to Libre
8, and use "Standard ASSY".

- Thanks a lot for suggesting other 8 bit DOS OS's.



*So, what would be the first step? - Defining ABI (bring examples of
existing 8 bit ABI's) for entire toolchain. LINK NEEDED - Porting GAS, and
use a custom GAS-libre8 in platformio project. Could anyone point out out
which files need to be edited exactly?*

Thank you all.
Elijax Apps.

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Help porting newlib to a new CPU architecture (sorta)
@ 2021-07-06  0:49 ElijaxApps
  2021-07-06  4:35 ` Mike Frysinger
  0 siblings, 1 reply; 21+ messages in thread
From: ElijaxApps @ 2021-07-06  0:49 UTC (permalink / raw)
  To: newlib

Hi all,

I designed a Logisim schematic of a full system, able to run programs in
the simulation, as shown in this video:

https://www.youtube.com/watch?v=UP6tO8x5I5A

Is based on a SAP-1 (Simplest as Possible) basis, containing 4 GP registers
(8 bit), stack for function operations (up to 256 depth levels of
recursivity), 24bit plain RAM component, and a simple ALU able to echo
strings and perform not floating point math.

AFAIK, newlib is suitable for embedded devices, and I want to create the
full toolchain for C/C++ language at least.

At first I tried porting it by my own using this guide:

https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#sec_crt0

And I am stuck here:

   1.

   Implement the Board Support Package(s) for the target (Chapter 5
   <https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#chap_libgloss>
   ).
   -

      Implement the C Runtime start up, crt0.o for each BSP (Section 5.2
      <https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#sec_crt0>
      ).
      -

      Implement the environment global variable and 18 system call
      functions for each BSP following the convention namespace and
      reentrancy conventions specified in newlib/configure.host (Section 5.3
      <https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#sec_syscalls>
       and Section 5.4
      <https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#sec_reentrant_syscalls>
      ).
      -

      Create libgloss/*target*/Makefile.in and libgloss/*target*/
      configure.ac, based on the versions in the libgloss/libnosys directory
      and run aclocal and autoconf in libgloss/*target* (Section 5.5
      <https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#sec_bsp_config_make>
      ).

I have some questions regarding those points:

1) ATM my system is programmable, using a kind of own pseudo-assembler code
I created for that purpose, alongside with a Java compiler which translates
it to text hex file, then I copy its contents to the simulation's RAM. But
it's not "normal", "standard" ASSY, just an approximation made by not an
assy guy... (never coded any in actual ASSY).

So:
 - How do I write CRT code? In standard ASSY? In my own assy, and somewhere
I tell which binary format represents each mnemonic? In case of the first,
how will  the toolchain know the opcodes and binary format of the
instructions and data? In case of the second, could you please clarify the
paths of those files in the docs? :)

The full source to Libre 8 CPU is here. Some recent changes are not yet
pushed but the commited and de documentation provided in github should be
enough to make you an idea of what I tell by pseudo-assy.

https://github.com/ElijaxApps/Libre-8

I want to push it further, and perhaps port some existing software to it as
FreeDOS ... , as far as I can get. All ideas are welcome.

If you have to make questions about the architecture don't hesitate and do
it. If I have to modify os made changes to fit any requirement it won't be
a problem, even now I've reached this far.

I hope this is possible. Thank you,
Elijax Apps.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-07-07 20:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 21:08 Help porting newlib to a new CPU architecture (sorta) ElijaxApps
2021-07-06 22:00 ` Joel Sherrill
2021-07-06 23:50   ` Paul Koning
2021-07-07  0:29     ` ElijaxApps
2021-07-07 15:09   ` Grant Edwards
  -- strict thread matches above, loose matches on Subject: below --
2021-07-06  0:49 ElijaxApps
2021-07-06  4:35 ` Mike Frysinger
2021-07-06 13:05   ` Paul Koning
2021-07-07 20:32     ` ElijaxApps
2021-07-07 20:56       ` Orlando Arias
2021-07-06 14:02   ` Brian Inglis
2021-07-06 14:35     ` Orlando Arias
2021-07-06 18:08       ` Brian Inglis
2021-07-06 19:04         ` Orlando Arias
2021-07-06 20:01           ` Hans-Bernhard Bröker
2021-07-06 20:46             ` Orlando Arias
2021-07-07  5:45               ` Brian Inglis
2021-07-07 13:58                 ` Orlando Arias
2021-07-07 15:18                   ` Dave Nadler
2021-07-07 18:43               ` Hans-Bernhard Bröker
2021-07-07 20:23                 ` Orlando Arias

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).