RetroBSD

2.11BSD operating system for microcontrollers
It is currently Tue Jan 18, 2022 6:52 am

All times are UTC




Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Tue Dec 22, 2015 10:34 am 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
Code:
# cc --version
pcc 1.1.0 20141014 for mipsel-unknown-litebsd0.1

The diff to make this happen is here:
https://github.com/ibara/LiteBSD/tree/pcc

Yes I will make a pull request. And yes, I was able to generate an asm file from LiteBSD itself. The compiler works.
I wrote:
Code:
#include <stdio.h>

int main(void)
{
        printf("Hi\n");
        return 0;
}

in a file named hello.c then ran
Code:
# cc -O2 -S -c hello.c

and I got back a valid hello.s asm file.

Now if only we could get a hold on an assembler, and we might be able to self-host!

pcc is a C99 compiler, so it should be able to take LiteBSD quite far.
Yes, I will upstream everything.

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 3:14 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Brian,

Am I missing something? Will the Retro assembler do the job.

Isn't MIPS for MX basically the same as MIPS for the MZ?

I guess I should read the data sheet :).

Wiz


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 6:46 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
wiz wrote:
Am I missing something? Will the Retro assembler do the job.

The RetroBSD assembler writes a.out files. We need something that will write ELF files.

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 8:23 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Brian,

Thanks :). More stuff too learn :).

I guess it must not be a simple loader problem?

I really like your package manager idea. Get the kernel development effort set apart from application development.

I think we should make the kernel as small and as well defined as we can. Both as to the 'application interface' and as to its use, location and meaning of its RAM variables. In what I write, I try to make it clear what each bit does, why it is there and where its fixed location is. This always seems to be a sore point with 'C' programmers??!! Are they just too lazy? I guess that may come across as critical? But I REALLY wonder.... For such an important piece of system software [the kernel], is there really any choice?

I really hope we can figure out how to add kernel loadable modules to simplify adding and working on new device drivers and other kernel stuff.

Happy holidays to all,

Wiz


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 8:45 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
ibara wrote:
The RetroBSD assembler writes a.out files. We need something that will write ELF files.

I'm being working on assembler port, in a separate branch. It will have basically the same input language (and instruction set), but it should generate ELF output.

Traditionally, all the Unixes used so called a.out format for object files and binaries. We use it in LiteBSD. A.out files have a pretty simple structure, easy to produce and process.

In late 90-s most operating systems had switched to a more advanced format called ELF (Executable and Linkable Format). The most essential feature of ELF is that it has all the needed support for shared libraries. So for LiteBSD I decided there is a little sense to mess with a.out and it's better to start with ELF from the very beginning.


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 9:06 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
Great! I kinda wish the elftoolchain people got on it and worked on the as program. It's sat there since 2012.

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Tue Dec 22, 2015 9:25 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge and Brian,

Thanks :).

Shared libraries -- Makes sense to me.

I started to try to figure out elf and gave up. Now I see why. Lots of stuff to make a better system possible.

Happy holidays to all.

Wiz


Top
 Profile  
 
PostPosted: Fri Dec 25, 2015 5:29 am 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
So after a few days of playing around with this...
It seems like (virtual) memory exhaustion errors prevent a usable native toolchain from happening right now :(
The latest GNU as and ld that will natively run on LiteBSD is binutils-2.11, which is about a year before mips32r2 support was added to binutils so you can't successfully link things together (since the libraries are mips32r2). You can create valid .o files with pcc + GNU as (but they're mips1, seems like that's all pcc supports right now).
The ld from elftoolchain doesn't work. Looks like it hits (virtual) memory exhaustion errors trying to link even the simplest programs.

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Fri Dec 25, 2015 5:56 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
The ld from elftoolchain can be made smaller. Just need to remove elf64 support from it.


Top
 Profile  
 
PostPosted: Tue Dec 29, 2015 9:34 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
I've done some more work on pcc for LiteBSD and worked with the pcc maintainer: LiteBSD is now a supported pcc target and I now have a -current pcc running on LiteBSD. This compiler can successfully assemble the arch(1) program in LiteBSD ports. It even optimizes!

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 12:04 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
I've tried with pcc and my "reference rc4 source" (viewtopic.php?f=13&t=37431#p42629):

Code:
# time cc -o rc4 rc4.c
rc4.c, line 108: compiler error: Cannot generate code, node 0x48a0f0 op SCONV
error: /usr/libexec/ccom terminated with status 1
       68.34 real        53.18 user         0.00 sys
#
# time cc -O2 -o rc4 rc4.c
rc4.c, line 39: compiler error: Cannot generate code, node 0x47af38 op SCONV
error: /usr/libexec/ccom terminated with status 1
       60.53 real        46.86 user         0.00 sys
# ls -l
total 4
-rw-r--r--  1 root  wheel  3007 Dec 30 04:50 rc4.c
# cc -O2 -S -c rc4.c
rc4.c, line 39: compiler error: Cannot generate code, node 0x47af38 op SCONV
error: /usr/libexec/ccom terminated with status 1
# ls
rc4.c   rc4.s
# ls -l
total 8
-rw-r--r--  1 root  wheel  3007 Dec 30 04:50 rc4.c
-rw-r--r--  1 root  wheel   665 Dec 30 03:47 rc4.s
# cat rc4.s
        .section .mdebug.abi32
        .previous
        .abicalls
        .text
        .p2align 2
        .align 2
        .globl swap
        .ent swap
swap:
        .frame $fp,16,$ra
        .set noreorder
        .cpload $25     # pseudo-op to load GOT ptr into $25
        .set reorder
        subu $sp,$sp,16
        .cprestore 8    # pseudo-op to store GOT ptr at 8(sp)
        sw $ra,4($sp)
        sw $fp,($sp)
        move $fp,$sp
        subu $sp,$sp,8
$L649:
$L653:
        lb $3,($4)              # (u)char load
        nop
        sb $3,-1($fp)           # store (u)char
        nop
        lb $3,($5)              # (u)char load
        nop
        sb $3,($4)              # store (u)char
        nop
        lbu $2,-1($fp)  # load uchar to reg
        nop
        sb $2,($5)              # store (u)char
        nop
        addiu $sp,$fp,16
        lw $ra,-12($sp)
        lw $fp,-16($sp)
        jr $ra
        nop
        .end swap
        .size swap,.-swap
        .p2align 2
#

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 1:49 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Interestingly, this excercise shots down the sdcard's filesystem (tried few times):
Code:
# ls -l
total 4
-rw-r--r--  1 root  wheel  3007 Dec 30 04:50 rc4.c
# pcc -v -E rc4.c > rc4.i
PCC preprocessor version Portable C Compiler 1.2.0.DEVEL 20151220 for mipsel-unk
nown-litebsd0.1
# /usr/libexec/ccom rc4.i > rc4.out
sd0: card_read: READ_MULTIPLE timed out, reply = 255
sd0: card_write: data rejected, reply = ff
PID 47 (ccom) protection violation at 402b00: BadVAddr = 0089d218
sd0: card_cmd timeout, cmd=12, addr=0006424a, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 0006424a
sd0: card_cmd timeout, cmd=12, addr=0001a122, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 0001a122
sd0: card_cmd timeout, cmd=12, addr=0001a222, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 0001a222
PID 37 (sh) protection violation at 412e28: BadVAddr = 00000001
sd0: card_cmd timeout, cmd=12, addr=0001810a, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 0001810a
sd0: card_cmd timeout, cmd=12, addr=0006422a, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 0006422a
sd0: card_cmd timeout, cmd=12, addr=00064232, reply=ff
sd0: card_read: bad READ_MULTIPLE reply = 255, offset = 00064232

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 2:14 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
On the 4th attempt:
Code:
# date 1512301508.00
Wed Dec 30 15:08:00 PST 2015
# pcc -v -E rc4.c > rc4.i
PCC preprocessor version Portable C Compiler 1.2.0.DEVEL 20151220 for mipsel-unk
nown-litebsd0.1
# /usr/libexec/ccom rc4.i > rc4.txt
rc4.c, line 108: compiler error: Cannot generate code, node 0x48a0f0 op SCONV
# ls -l
total 36
-rw-r--r--  1 root  wheel   3007 Dec 30 04:50 rc4.c
-rw-r--r--  1 root  wheel  21288 Dec 30 15:08 rc4.i
-rw-r--r--  1 root  wheel   7133 Dec 30 15:09 rc4.txt
#

rc4.c, rc4.i, rc4.txt attached.


Attachments:
RC4.zip [6.85 KiB]
Downloaded 1023 times

_________________
Pukao Hats Cleaning Services Ltd.
Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 4:04 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
Hi Pito --

This is a bug in the compiler and is known. But more examples are always helpful to report upstream!

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 8:03 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Will the bug be fixed? Or stays known? :)
Does the pcc know double on liteBSD?
I have got a lot of examples to mess with during long winter evenings.. :)

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 10:39 pm 
Contributor

Joined: Mon Apr 29, 2013 1:56 am
Posts: 196
Pito wrote:
Code:
        lb $3,($4)              # (u)char load
        nop
        sb $3,-1($fp)           # store (u)char
        nop
        lb $3,($5)              # (u)char load
        nop
        sb $3,($4)              # store (u)char
        nop
        lbu $2,-1($fp)  # load uchar to reg
        nop
        sb $2,($5)              # store (u)char
        nop


These nops following loads and stores are required for some ancient MIPS revisions. There should be an option to not generate them (unless there already is).


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 10:39 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
Pito wrote:
Will the bug be fixed? Or stays known? :)

Hopefully! That's why we're submitting patches and bug fixes to them :)

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 10:40 pm 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
alexfru wrote:
These nops following loads and stores are required for some ancient MIPS revisions. There should be an option to not generate them (unless there already is).

AFAIK, pcc only targets -mips1. (one of things I'm looking for help on is making it a real -mips32r2 compiler)

_________________
@__briancallahan on Twitter


Top
 Profile  
 
PostPosted: Wed Dec 30, 2015 11:03 pm 
Contributor

Joined: Mon Apr 29, 2013 1:56 am
Posts: 196
ibara wrote:
AFAIK, pcc only targets -mips1. (one of things I'm looking for help on is making it a real -mips32r2 compiler)


In that case, there's a bunch of useful instructions that are available on R2:
mul(t?) (storing the product in a GPR instead of LO/HI), seb/seh, ins/ext (can save one instruction on 64-bit shifts by a constant amount), ldc1/sdc1, mthc1/mfhc1 (btw, there should also be an option to choose between 32-bit FPU (32 float/16 double regs) vs 64-bit FPU (64 float/double regs), movn/movz, clz/clo, rotr(v), wsbh.

AFAIR, there are other places, where nops aren't required on R2 anymore. E.g. nops around multiplication/division and floating-point. Essentially, only unfilled branch delay slots need nops on R2.


Top
 Profile  
 
PostPosted: Thu Dec 31, 2015 2:28 am 
Contributor
User avatar

Joined: Sun Oct 20, 2013 3:15 am
Posts: 322
If you want to take a look, all the MD code for MIPS lives in usr.bin/pcc/pcc/arch/mips.
The stuff you're looking at lives in table.c in that directory.

_________________
@__briancallahan on Twitter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3  Next

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission