TSM_EmbReal – HiFive 1

HiFive1 | Crowd Supply
Wikipedia SiFive

HiFive1 | SiFive
Documentation | SiFive
RISC-V Tools | SiFive

SEGGER Adds Support for SiFive’s Coreplex IP to Its Industry Leading J-Link Debug Probe
Open Source RISC – Eclipse with RISC-V on the SiFive HiFive1 Board
PlatformIO RISC-V
RISC-V Foundation | Instruction Set Architecture (ISA)

Tutorials

FE310G: an open source RISC-V microcontroller – Introduction
FE310G: an open source RISC-V microcontroller – Interrupt System
FE310G: an open source RISC-V microcontroller – IDE

Core vs. Hart

Definition of “hart”
Add a definition for hart
RiscV spec references the word ‘hart’ – what does ‘hart’ mean?

Platform

GreenWaves Technologies GAP8: The IoT Application Processor
PULP Platform – Open hardware, the way it should be!

Abbrefiations and Dictionary

ISR Interrupt Service Routine
IST Interrupt Service Table
CSR Control status register
IER Interrupt enable register
ISA Instruction Set Architecture
PLIC Platform-Level Interrupt Controller
CLINT Core Local Interruptor
AON Always-On
WDT Watchdog Timer
RTC Real-Time Clock
PMU Power-Management Unit
OTP One-Time Programmable Memory
GPIO General Purpose Input/Output Controller

git

GitLab: Hans Buchmann
gitlab.fhnw.ch/edu/tsm-embreal

Wikipedia

Befehlssatz, Instruction Set
Befehlssatzarchitektur, Instruction Set Architecture (ISA)

Hardware I/O Functions / Alternate Functions (UART, SPI, PWM)

HiFive-1 Bare Bones
PIO_IOF_SEL in LED Fade Demo
github.com/sifive/freedom-e-sdk/blob/master/bsp/include/sifive/devices/gpio.h
https://github.com/sifive/freedom-e-sdk/blob/master/software/led_fade/led_fade.c
https://github.com/sifive/freedom-e-sdk/blob/master/bsp/env/freedom-e300-arty/platform.h

github.com/RIOT-OS/RIOT/blob/master/cpu/fe310/include/vendor/platform.h

[PATCH 12/15] HiFive1: add UART support
RTEMS BSP for HiFive1
[PreGSoC 2017] Make a port of RTEMS for HiFive1
Utilizing full power of RISC-V architecture via usage of RTEMS on top of SiFive FE310 processors

GPIO_IOF_EN
GPIO_IOF_SEL

vs.

GPIO_OUTPUT_EN
GPIO_OUTPUT_VAL

C++

C++ Standard

Which C++ standard is the default when compiling with g++?
Standard Predefined Macros

$ g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
#define __cplusplus 201402L ==> 2014 C++ standard

C++ Syntax

Private members

class PrivateClass {

    int a;
    int b;

    PrivateClass();
};

PrivateClass::PrivateClass() :
a(0),
b(1)
{
    //
}
#include "PrivateClass.h"

int main()
{
    PrivateClass k;
}
src/main.cpp: In function ‘int main()’:
src/main.cpp: error: ‘PrivateClass::PrivateClass()’
                     is private within this context
     PrivateClass k;

Private Static Instantiation

#include "stdio.h"

class StaticClass {

    static StaticClass k;

    int a;
    int b;

    StaticClass();
};

StaticClass StaticClass::k;

StaticClass::StaticClass() :
a(0),
b(1)
{
    printf("Hurra\n");
}
int main()
{
    //
}
$ ./main
Hurra

final

What is the purpose of the “final” keyword in C++11 for functions?
final specifier (since C++11)
override specifier (since C++11)

class Person final {
   [...]
}

class Andreas : Person {
   [...]
};

// error: cannot derive from ‘final’ base ‘Person’ in derived type ‘Andreas’
class Person {
   virtual void print() final;
}

class Andreas : Person {
   virtual void print() final;
};

// error: virtual function ‘virtual void Andreas::print()’
// overriding final function ‘virtual void Person::print()’

static vs. const

How to initialize private static members in C++?

class ConstClass {

    static int a       = 1;
    static const int b = 2;

    ConstClass();
};

ConstClass::ConstClass()
{
    //
}
int main()
{
    //
}
In file included from src/ConstClass.cpp:2:0:
include/ConstClass.h:6:16: error: ISO C++ forbids in-class
                                  initialization of non-const
                                  static member ‘ConstClass::a’
     static int a       = 1;
class ConstClass {

    static int a;
    static const int b = 2;

    ConstClass();
};

int ConstClass::a = 1;

ConstClass::ConstClass()
{
    //
}

const

Meaning of ‘const’ last in a function declaration of a class?
C++-Programmierung/ Eigene Datentypen definieren/ Methoden

class Person {
    void foo() const;   /* this pointer is const =>
                           cannot change any member data */
}

class A {
    public:
        int a, b, c, d;
};

class B {
    public:
        /* Das übergebene A-Objekt ist innerhalb 
           der Methode konstant */
        void methode(A const& parameter_name);
};

Operator Overload

class Person {
    operator unsigned() const;   /* cast-operator */
}

template

What does template mean?
Template (C++)

Type Parameters

  • Types
  • Templates

Non-type Parameters

  • Pointers
  • References
  • Integral constant expressions

In fact, we can create algorithms which evaluate at compile time (from Wikipedia):

template <int N>
struct Factorial 
{
     enum { value = N * Factorial<N - 1>::value };
};

template <>
struct Factorial<0> 
{
    enum { value = 1 };
};

// Factorial<4>::value == 24
// Factorial<0>::value == 1
void foo()
{
    int x = Factorial<4>::value; // == 24
    int y = Factorial<0>::value; // == 1
}

constexpr

  • A constexpr variable…
  • A constexpr function…
  • A constexpr constructor…

constexpr specifier (since C++11)
Difference between `constexpr` and `const`
When should you use constexpr capability in C++11?

class Person {
    operator unsigned() const;   /* cast-operator */
}

decltype

decltype specifier
decltype
Modern C++ Features – decltype and std::declval
Improved Type Inference in C++11: auto, decltype, and the new function declaration syntax
C equivalent to C++ decltype

namespace sys::pa {
    /* Statt dem statischen Datentyp einfach der Datentyp,
       der in CSR::mstatus benutzt wird.

       decltype “returns” a type. */
    /* 
    decltype(CSR::mstatus) CSR::mstatus;
}

struct A { double x; };
const A* a;

/* type of y is double (declared type) */
decltype(a->x) y;

/* type of z is const double& (lvalue expression) */
decltype((a->x)) z = y;
 
/* return type depends on template parameters.
   return type can be deduced since C++14 */
template<typename T, typename U>
auto add(T t, U u) -> decltype(t + u)
{
    return t+u;
}

RISC-V Assembly

C++ to ASM linkage in GCC

$ cat hardware-register-extern-asm.S | \
  c++filt > hardware-register-extern-asm2.S
int getObjId(void);         => _ZN8getObjIdEv
int getObjId(int);          => _ZN8getObjIdEi
int getObjId(unsigned int); => _ZN8getObjIdEj

'this is a mangled symbol' (_Z).
'It has 8 characters of user-defined symbol relevance' (8),
(v=void, i=int, j=unsigned int...). 
_GLOBAL__sub_I__ZN3App3appE:
	call	_Z41__static_initialization_and_destruction_0ii
	call	__static_initialization_and_destruction_0(int, int)  [demangled]

_Z41__static_initialization_and_destruction_0ii:
__static_initialization_and_destruction_0(int, int):  [demangled]
	call	_ZN3AppC1Ev
	call	App::App()  [demangled]

_ZN3App3appE:
App::app: [demangled]

_ZN3AppC2Ev: (_ZN3AppC1Ev)
App::App():  [demangled]

20400480 <_Z41__static_initialization_and_destruction_0ii>:
2040049e:	374d                	jal	20400440 <_ZN3sys5Msg_1C1Ev>
[...]
204004c0 <_GLOBAL__sub_I__ZN3sys5Msg_13msgE>:
204004cc:	3f55                	jal	20400480 <_Z41__static_initialization_and_destruction_0ii>


20404160 <_Z41__static_initialization_and_destruction_0ii>:
2040417e:	370d                	jal	204040a0 <_ZN3AppC1Ev>
[...]
20404000 <_GLOBAL__sub_I__ZNK3sys3Mod5Entry4showEPFvvE>:
2040400c:	3f55                	jal	20403fc0 <_Z41__static_initialization_and_destruction_0ii>


20403fc0 <_Z41__static_initialization_and_destruction_0ii>:
20403fde:	2089                	jal	20404020 <_ZN3sys7BuildIDC1Ev>
[...]
204041a0 <_GLOBAL__sub_I__ZN3App3appE>:
204041ac:	3f55                	jal	20404160 <_Z41__static_initialization_and_destruction_0ii>

Extern vs. Pointer

204040a0:       1101                    addi    sp,sp,-32
204040a2:       ce06                    sw      ra,28(sp)
204040a4:       c62a                    sw      a0,12(sp)
204040a6:       100127b7                lui     a5,0x10012
204040aa:       00078793                mv      a5,a5
204040ae:       4798                    lw      a4,8(a5)
204040b0:       004007b7                lui     a5,0x400
204040b4:       8f5d                    or      a4,a4,a5
204040b6:       100127b7                lui     a5,0x10012
204040ba:       00078793                mv      a5,a5
204040be:       c798                    sw      a4,8(a5)
204040c0:       100127b7                lui     a5,0x10012
204040c4:       00078793                mv      a5,a5
204040c8:       47d8                    lw      a4,12(a5)
204040ca:       004007b7                lui     a5,0x400
204040ce:       8f5d                    or      a4,a4,a5
204040d0:       100127b7                lui     a5,0x10012
204040d4:       00078793                mv      a5,a5
204040d8:       c7d8                    sw      a4,12(a5)
204040da:       204047b7                lui     a5,0x20404

App::App():
.LFB108:
        addi    sp,sp,-32
        sw      ra,28(sp)
        sw      a0,12(sp)
.LBB2:
        
        lui     a5,%hi(GPIO)
        addi    a5,a5,%lo(GPIO)
        lw      a4,8(a5)
        
        li      a5,4194304
        or      a4,a4,a5
        
        lui     a5,%hi(GPIO)
        addi    a5,a5,%lo(GPIO)
        sw      a4,8(a5)
        
        lui     a5,%hi(GPIO)
        addi    a5,a5,%lo(GPIO)
        lw      a4,12(a5)
        
        li      a5,4194304
        or      a4,a4,a5
        
        lui     a5,%hi(GPIO)
        addi    a5,a5,%lo(GPIO)
        sw      a4,12(a5)
204040a0:       7179                    addi    sp,sp,-48
204040a2:       d606                    sw      ra,44(sp)
204040a4:       d422                    sw      s0,40(sp)
204040a6:       c62a                    sw      a0,12(sp)
204040a8:       100127b7                lui     a5,0x10012
204040ac:       cc3e                    sw      a5,24(sp)
204040ae:       47e2                    lw      a5,24(sp)
204040b0:       4798                    lw      a4,8(a5)
204040b2:       004007b7                lui     a5,0x400
204040b6:       8f5d                    or      a4,a4,a5
204040b8:       47e2                    lw      a5,24(sp)
204040ba:       c798                    sw      a4,8(a5)
204040bc:       47e2                    lw      a5,24(sp)
204040be:       43d8                    lw      a4,4(a5)
204040c0:       001007b7                lui     a5,0x100
204040c4:       8f5d                    or      a4,a4,a5
204040c6:       47e2                    lw      a5,24(sp)
204040c8:       c3d8                    sw      a4,4(a5)
204040ca:       47e2                    lw      a5,24(sp)
204040cc:       47d8                    lw      a4,12(a5)
204040ce:       004007b7                lui     a5,0x400
204040d2:       8f5d                    or      a4,a4,a5
204040d4:       47e2                    lw      a5,24(sp)
204040d6:       c7d8                    sw      a4,12(a5)
204040d8:       204057b7                lui     a5,0x20405

App::App():
.LFB108:
        addi    sp,sp,-48
        sw      ra,44(sp)
        sw      s0,40(sp)
        sw      a0,12(sp)
.LBB4:
.LBB5:
        
        li      a5,268509184
        sw      a5,24(sp)
        
        lw      a5,24(sp)
        lw      a4,8(a5)
        
        li      a5,4194304
        or      a4,a4,a5
        
        lw      a5,24(sp)
        sw      a4,8(a5)
        
        lw      a5,24(sp)
        lw      a4,4(a5)
        
        li      a5,1048576
        or      a4,a4,a5
        
        lw      a5,24(sp)
        sw      a4,4(a5)
        
        lw      a5,24(sp)
        lw      a4,12(a5)
        
        li      a5,4194304
        or      a4,a4,a5
        
        lw      a5,24(sp)
        sw      a4,12(a5)

C++ Optimizing

Optimizing software in C++ – An optimization guide for Windows, Linux and Mac platforms (2018)

x86-64

x86-Prozessor
x64
x86 calling conventions
x86 assembly language
Assembler-Programmierung für x86-Prozessoren
Limitations of Intel Assembly Syntax Compared to AT&T, GNU tools and how to use AT&T / Intel Syntax
X86 Assembly/GAS Syntax
x86 Assembly Guide
x86-64 Assembly Programming
What is the difference between MOV and LEA?
Baby steps in x86 assembly

Calling Convention

Introduction to X86-64 Assembly for Compiler Writers, 2015
System V ABI (PDF)
System V ABI
Wikipedia: x86 calling conventions
Assembly registers in 64-bit architecture
Passing argument through registers instead of the stack

Books

Guide to Assembly Language Programming in Linux, Teil 1, Sivarama P. Dandamudi

0xax.github.io

Just a memo – My posts about Linux kernel and low-level stuff
Say hello to x86_64 Assembly [part 1]
Say hello to x86_64 Assembly [part 2]
Say hello to x86_64 Assembly [part 3]
Say hello to x86_64 Assembly [part 4]
Say hello to x86_64 Assembly [part 5]
Say hello to x86_64 Assembly [part 6]
Say hello to x86_64 Assembly [part 7]
Say hello to x86_64 Assembly [part 8]

gcc / g++

-o file     Place output in file file. This applies to whatever sort of output
            is being produced, whether it be an executable file, an object file,
            an assembler file or preprocessed C code. 
-c          Compile or assemble the source files, but do not link. The linking
            stage simply is not done. The ultimate output is in the form of an
            object file for each source file. 
-S          Stop after the stage of compilation proper; do not assemble. The
            output is in the form of an assembler code file for each non-assembler
            input file specified.
-E          Stop after the preprocessing stage; do not run the compiler proper.
            The output is in the form of preprocessed source code, which is sent
            to the standard output. 
-O0         Reduce compilation time and make debugging produce the expected results.
            This is the default.
-O1         Optimize. Optimizing compilation takes somewhat more time, and a lot
            more memory for a large function. 
-O2         Optimize even more. GCC performs nearly all supported optimizations
            that do not involve a space-speed tradeoff. 

gdb

GDB QUICK REFERENCE (PDF)
Using gdb layout when debugging Assembly Language Programs

set disassembly-flavor command
TUI-specific Commands

$ gdb swap
(gdb) b main
(gdb) r

(gdb) set print asm-demangle on

### Disassembly Format
(gdb) set disassembly-flavor att
(gdb) set disassembly-flavor intel
(gdb) show disassembly-flavor

### TUI Commands
(gdb) tui enable
(gdb) tui disable
(gdb) layout asm
(gdb) layout src
(gdb) layout split
(gdb) layout regs
(gdb) focus asm
(gdb) focus src
(gdb) focus regs
(gdb) refresh
(gdb) update

### Assembly
(gdb) ni   (next ASM)
(gdb) si   (step into ASM)

### Sow Registers
(gdb) info reg rdi
rdi            0x7fffffffddb0   140737488346544
(gdb) info reg rdi
rsi            0x7fffffffddb4   140737488346548

### Examine
(gdb) x 0x7fffffffddb0
0x7fffffffddb0: 0x00000001
(gdb) x 0x7fffffffddb4
0x7fffffffddb4: 0x00000002
(gdb) x $rdi
0x7fffffffddb0: 0x00000001
(gdb) x/i $pc  <== Program Counter
=> 0x5555555546ab <swap+1>:     mov    %rsp,%rbp
(gdb) x/i $rip <== Instruction Pointer
=> 0x5555555546ab <swap+1>:     mov    %rsp,%rbp

x command, Displays the memory contents at a given address
print command, Prints the value of a given expression
10.6 Examining Memory
Difference between x and p in gdb?
Program Variables
Examining the Symbol Table
Wikipedia: Symbol Table
Wikipedia: .bss
Wikipedia: Datensegment

x <address>       shows the contents of a memory address

p <symbol>        shows the value stored in a named variable
print <symbol>

info registers    shows registers and what they're doing
info frame

### For example:
int x;
int& f(int& variable) { return variable; }
int  g(int wert)      { return wert; }

(gdb) p x
$3 = 3

(gdb) x x
0x3:    Cannot access memory at address 0x3

(gdb) x &x
0x555555756134 <x>:     0x0000000000000003

(gdb) p r
No symbol "r" in current context.

(gdb) info address x
Symbol "x" is static storage at address 0x555555756134.

(gdb) info symbol 0x555555756134 
x in section .bss of /home/andreas/src/cpp-test/obj/lvalue/lvalue
              --> Symbol Table

(gdb) whatis x
type = int

 Address               Data
 _____________________ ______________________
|          x          |                      |
|    0x555555756134   |               0x3    |
|_____________________|______________________|
|                     |                      |
|        0x3          | Cannot access memory |
|_____________________|______________________|

(gdb) whatis f
type = int &(int &)

(gdb) whatis g
type = int (int)

Stack

how can one see content of stack with gdb

p $sp           shows the stack-pointer address
x $sp           shows the stack-pointer content
0x7fffffffdcd0: 0x0000007900000000

info frame      show the stack frame info
x/4xg $sp       

(gdb) p $sp
$6 = (void *) 0x7fffffffdcd0

(gdb) x $sp
0x7fffffffdcd0: 0x0000007900000000

 Address / Register    Data
 _____________________ _____________________
|                     |                     |
|  Stack Pointer (SP) |    0x7fffffffdcd0   |
|_____________________|_____________________|
|                     |                     |
|        ...          |        ...          |
|_____________________|_____________________|
|                     |                     |
|    0x7fffffffdcd0   |    0x007900000000   |
|_____________________|_____________________|

Attach Source
How to point GDB to your sources
info source command, Dislays information about the current source file

Reading symbols from hardware-register-extern...(no debugging symbols found)...done.
==> no debugging symbols!

(gdb) info sources
No symbol table is loaded.  Use the "file" command.
Before:
CFLAGS=  -O2 -std=c++14 \
After:
CFLAGS=  -O0 -ggdb -std=c++14 \
(gdb) show dir
Source directories searched: $cdir:$cwd

(gdb) dir ../namespace
Source directories searched: /home/andreas/src/tsm-embreal/HiFive1/work/../namespace:$cdir:$cwd

(gdb) info source
Current source file is <unknown>
Compilation directory is /home/andreas/src/tsm-embreal/HiFive1/work
Source language is c++.
Producer is GNU C++14 8.2.0 -march=rv32imac -mabi=ilp32 -ggdb -O0 -std=c++14 -fomit-frame-pointer -fpermissive -fcheck-new -fsized-deallocation -fno-exceptions -fno-use-cxa-atexit -fno-builtin -falign-functions=32 -fno-rtti -fno-unwind-tables.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.

(gdb) list
1	<unknown>: No such file or directory.

(gdb) file ../namespace/hardware-register-extern.cc
"/home/andreas/src/tsm-embreal/HiFive1/work/../namespace/hardware-register-extern.cc": not in executable format: File format not recognized

(gdb) source ../namespace/hardware-register-extern.cc 
../namespace/hardware-register-extern.cc:1: Error in sourced command file:
Undefined command: "".  Try "help".

(gdb) help source
Read commands from a file named FILE.

Eclipse

Eclipse TM Terminal: ESP32 serial terminal
Terminal view not processing \n, \r correctly for serial connection

OpenOCD

OpenOCD – udev rules
GNU MCU Eclipse: How to install the OpenOCD binaries?

Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: no device found
Error: unable to open ftdi device with vid 0403, pid 6010, description 'Dual RS232-HS', serial '*' at bus location '*'

$ groups $USER
andreas : andreas adm cdrom sudo dip lpadmin sambashare

$ sudo usermod -aG plugdev $USER
$ sudo usermod -aG dialout $USER

$ groups $USER
andreas : andreas adm dialout cdrom sudo dip plugdev lpadmin sambashare
                      *******                *******
$ sudo xed /etc/udev/rules.d/98-openocd.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="664", GROUP="plugdev"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="664", GROUP="plugdev"

$ sudo udevadm control --reload-rules

$ udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB1)

  looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1/ttyUSB1/tty/ttyUSB1':
    KERNEL=="ttyUSB1"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1/ttyUSB1':
    KERNELS=="ttyUSB1"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="ftdi_sio"
    [...]

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1':
    KERNELS=="1-2:1.1"
    SUBSYSTEMS=="usb"
    DRIVERS=="ftdi_sio"
    [...]
    ATTRS{interface}=="Dual RS232-HS"
    [...]

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2':
    KERNELS=="1-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    [...]
    ATTRS{idProduct}=="6010"
    ATTRS{idVendor}=="0403"
    [...]

RIOT

RIOT – The friendly Operating System for the Internet of Things
SiFive HiFive1 RISC-V board
RIOT Wiki: Board%3A-HiFive1 (deprecated)
Creating your first RIOT project
RIOT Wiki: OpenOCD
“Copy this file to your udev configuration directory make sure your vid and pid are covered and adjust the GROUP to some group you are part of.”
RIOT Tutorials for RIOT
RIOT RTOS Port for HiFive1

[  771.168432] usb 1-2: new high-speed USB device number 8 using xhci_hcd
[  771.316930] usb 1-2: New USB device found, idVendor=0403, idProduct=6010
[  771.316935] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  771.316940] usb 1-2: Product: Dual RS232-HS
[  771.316944] usb 1-2: Manufacturer: FTDI
[  771.339667] usbcore: registered new interface driver usbserial_generic
[  771.339683] usbserial: USB Serial support registered for generic
[  771.342827] usbcore: registered new interface driver ftdi_sio
[  771.342844] usbserial: USB Serial support registered for FTDI USB Serial Device
[  771.342934] ftdi_sio 1-2:1.0: FTDI USB Serial Device converter detected
[  771.342974] usb 1-2: Detected FT2232H
[  771.343481] usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB0
[  771.343628] ftdi_sio 1-2:1.1: FTDI USB Serial Device converter detected
[  771.343660] usb 1-2: Detected FT2232H
[  771.343801] usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB1
$ sudo apt-get install libmpfr6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libmpfr6 is already the newest version (4.0.1-1).
The following packages were automatically installed and are no longer required:
  linux-headers-4.15.0-32 linux-headers-4.15.0-32-generic linux-image-4.15.0-32-generic linux-modules-4.15.0-32-generic linux-modules-extra-4.15.0-32-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

$ dpkg-query -L libmpfr6
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmpfr.so.6.0.1
/usr/share
/usr/share/doc
/usr/share/doc/libmpfr6
/usr/share/doc/libmpfr6/AUTHORS
/usr/share/doc/libmpfr6/BUGS
/usr/share/doc/libmpfr6/NEWS.gz
/usr/share/doc/libmpfr6/README
/usr/share/doc/libmpfr6/TODO.gz
/usr/share/doc/libmpfr6/changelog.Debian.gz
/usr/share/doc/libmpfr6/copyright
/usr/lib/x86_64-linux-gnu/libmpfr.so.6

$ locate libmpfr
/usr/lib/x86_64-linux-gnu/libmpfr.so.6
/usr/lib/x86_64-linux-gnu/libmpfr.so.6.0.1
/usr/share/doc/libmpfr6
/usr/share/doc/libmpfr6/AUTHORS
/usr/share/doc/libmpfr6/BUGS
/usr/share/doc/libmpfr6/NEWS.gz
/usr/share/doc/libmpfr6/README
/usr/share/doc/libmpfr6/TODO.gz
/usr/share/doc/libmpfr6/changelog.Debian.gz
/usr/share/doc/libmpfr6/copyright
/var/lib/dpkg/info/libmpfr6:amd64.list
/var/lib/dpkg/info/libmpfr6:amd64.md5sums
/var/lib/dpkg/info/libmpfr6:amd64.shlibs
/var/lib/dpkg/info/libmpfr6:amd64.symbols
/var/lib/dpkg/info/libmpfr6:amd64.triggers
$ ../tools/flash.sh startup-1
make: 'startup-1' is up to date.
Open On-Chip Debugger 0.10.0+dev-00062-g5d9f4864-dirty (2018-08-15-11:40)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: no device found
Error: unable to open ftdi device with vid 0403, pid 6010, description 'Dual RS232-HS', serial '*' at bus location '*'

Warn : Flash driver of onboard_spi_flash does not support free_driver_priv()

$ cat /etc/udev/rules.d/98-openocd.rules 
ACTION!="add|change", GOTO="openocd_rules_end"
SUBSYSTEM!="usb|tty|hidraw", GOTO="openocd_rules_end"

#Please keep this list sorted by VID:PID

#CMSIS-DAP compatible adapters
ATTRS{product}=="*CMSIS-DAP*", MODE="666", GROUP="root"

LABEL="openocd_rules_end"


$ sudo ../tools/flash.sh startup-1
[sudo] password for andreas: 
../tools/flash.sh: 6: ../tools/flash.sh: [[: not found
make: 'startup-1' is up to date.
Open On-Chip Debugger 0.10.0+dev-00062-g5d9f4864-dirty (2018-08-15-11:40)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 10000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
Info : Examined RISCV core; XLEN=32, misa=0x40001105
Info : Listening on port 3333 for gdb connections
Info : [0] Found 2 triggers
halted at 0x204003b4 due to debug interrupt
Info : Found flash device 'issi is25lp128' (ID 0x0018609d)
cleared protection for sectors 64 through 255 on flash bank 0
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
halted at 0x204003b4 due to debug interrupt
** Programming Started **
auto erase enabled
Info : Retrying memory read starting from 0x80000000 with more delays
Info : Retrying memory read starting from 0x80000000 with more delays
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
wrote 65536 bytes from file startup-1.bin in 0.875611s (73.092 KiB/s)
** Programming Finished **
** Verify Started **
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
Info : Retrying memory read starting from 0x20400000 with more delays
verified 13256 bytes in 0.372329s (34.768 KiB/s)
** Verified OK **
halted at 0x20400004 due to step
Warn : Flash driver of onboard_spi_flash does not support free_driver_priv()

hello

---------------------------------------- ctor
0x20402d00	1	sys/sys.o
0x20400320	0	sys/msg-1.o
0x20402e40	2	startup-1.o

test::Startup::Startup()
GNU:c2b75a723e41aa655b4fbbceabe9df508d33e39d
press key 's' ...

good bye
---------------------------------------- dtor
0x20402e60	0	startup-1.o
test::Startup::~Startup()
$ make app-anatomy-1
../tc/bin/riscv32-fhnw-elf-g++ -O2 -std=c++14 -march=rv32imac -mabi=ilp32 -fomit-frame-pointer -fpermissive -fcheck-new -fsized-deallocation -fno-exceptions -fno-use-cxa-atexit -fno-builtin -falign-functions=32 -Wreturn-type -fno-rtti -Wall -fno-unwind-tables  -include "sys/sys.h" -I /home/andreas/src/tsm-embreal/HiFive1/namespace -I /home/andreas/src/tsm-embreal/src -DEARLY_INIT -DNO_FLOATS -DNO_LONG_DIV -DSYS_SYS_SHOW_STARTUP -D'INTERFACE(name,info)=' -D'IMPLEMENTATION(name,info)=' -D'VERSION="heads/master-0-g361662c "'    /home/andreas/src/tsm-embreal/HiFive1/namespace/app-anatomy-1.cc   -o app-anatomy-1
/home/andreas/src/tsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/../../../../riscv32-fhnw-elf/bin/ld: cannot find crt0.o: No such file or directory
/home/andreas/src/tsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/../../../../riscv32-fhnw-elf/bin/ld: cannot find -lstdc++
/home/andreas/src/tsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/../../../../riscv32-fhnw-elf/bin/ld: cannot find -lm
/home/andreas/src/tsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/../../../../riscv32-fhnw-elf/bin/ld: cannot find -lc
/home/andreas/src/tsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/../../../../riscv32-fhnw-elf/bin/ld: cannot find -lgloss
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'app-anatomy-1' failed
make: *** [app-anatomy-1] Error 1


$ make clean
rm -f sys/deb/deblow.o sys/boot/big-bang-continued.o sys/msg-1.o sys/board.o sys/abi/abi.o startup-1.o sys/boot/big-bang.o sys/reg/aon.o io/ascii/out.o sys/msg.o math/double.o sys/reg/uart.o sys/reg/gpio.o io/ascii/write.o sys/sys.o sys/deb/deblow0.o util/float-conv.o sys/deb/deb.o sys/hwreg.o startup-1 \
        startup-1.map \
        startup-1.bin \
        tor.o

$ make makefile
/home/andreas/src/tsm-embreal/tools/makefile.sh ../config/projects.xml > Makefile

$ make app-anatomy-1
[...]
k$ make cpu-demo
g++ -O2 -std=c++14 -c -ocpu-demo.o /home/andreas/src/tsm-embreal/posix/src/cpu-demo.S
g++   cpu-demo.o  -lm -lpthread -lasound -o cpu-demo
/usr/bin/x86_64-linux-gnu-ld: cannot find -lasound
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'cpu-demo' failed
make: *** [cpu-demo] Error 1

$ git pull
$ make makefile
../../tools/makefile.sh ../config/projects.xml > Makefile

$ make cpu-demo
g++   cpu-demo.o  -lm -lpthread  -o cpu-demo
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'cpu-demo' failed
make: *** [cpu-demo] Error 1

$ make cpu-demo-app
g++ -O2 -std=c++14 -I /home/andreas/src/tsm-embreal/posix/src -I /home/andreas/src/tsm-embreal/src  -c -o cpu-demo-app.o /home/andreas/src/tsm-embreal/posix/src/cpu-demo-app.cc
g++ -O2 -std=c++14 -c -ocpu-demo.o /home/andreas/src/tsm-embreal/posix/src/cpu-demo.S
g++  cpu-demo-app.o cpu-demo.o  -lm -lpthread  -ocpu-demo-app
$ make event-demo-1
../tc/bin/riscv32-fhnw-elf-g++
-O2
-std=c++14
-march=rv32imac
-mabi=ilp32
-fomit-frame-pointer
-fpermissive
-fcheck-new
-fsized-deallocation
-fno-exceptions
-fno-use-cxa-atexit
-fno-builtin
-falign-functions=32
-Wreturn-type
-fno-rtti
-Wall
-fno-unwind-tables
-include "sys/sys.h"
-I tsm-embreal/HiFive1/namespace
-I tsm-embreal/src
-DEARLY_INIT
-DNO_FLOATS
-DNO_LONG_DIV
-DSYS_SYS_SHOW_STARTUP
-D'INTERFACE(name,info)='
-D'IMPLEMENTATION(name,info)='
-D'VERSION="heads/master-0-g0f5b43b-dirty "'
-c
-o sys/deb/deblow.o
tsm-embreal/HiFive1/namespace/sys/deb/deblow.cc

tsm-embreal/HiFive1/namespace/sys/deb/deblow0.S
tsm-embreal/HiFive1/namespace/sys/boot/big-bang.S
tsm-embreal/HiFive1/namespace/sys/msg-1.cc
tsm-embreal/HiFive1/namespace/sys/msg.cc
tsm-embreal/HiFive1/namespace/io/ascii/out.cc
tsm-embreal/HiFive1/namespace/io/ascii/write.cc
tsm-embreal/HiFive1/namespace/util/float-conv.cc
tsm-embreal/HiFive1/namespace/math/double.cc
tsm-embreal/HiFive1/namespace/sys/deb/deb.cc
tsm-embreal/HiFive1/namespace/sys/abi/abi.cc
tsm-embreal/HiFive1/namespace/sys/board.cc
tsm-embreal/HiFive1/namespace/sys/reg/gpio.cc
tsm-embreal/HiFive1/namespace/sys/boot/big-bang-continued.cc
tsm-embreal/HiFive1/namespace/sys/reg/uart.cc
tsm-embreal/HiFive1/namespace/sys/reg/aon.cc
tsm-embreal/HiFive1/namespace/sys/hwreg.cc
tsm-embreal/HiFive1/namespace/sys/sys.cc
tsm-embreal/HiFive1/namespace/event-demo-1.cc
tsm-embreal/HiFive1/namespace/sys/event.cc

../tc/bin/riscv32-fhnw-elf-objdump
-wt 
sys/deb/deblow.o
sys/deb/deblow0.o
sys/boot/big-bang.o
sys/msg-1.o
sys/msg.o
io/ascii/out.o
io/ascii/write.o
util/float-conv.o
math/double.o
sys/deb/deb.o
sys/abi/abi.o
sys/board.o
sys/reg/gpio.o
sys/boot/big-bang-continued.o
sys/reg/uart.o
sys/reg/aon.o
sys/hwreg.o
sys/sys.o
event-demo-1.o
sys/event.o
|
tsm-embreal/tools/mod-dep.py -c tor -
|
../tc/bin/riscv32-fhnw-elf-g++
-include "sys/sys.h"
-I tsm-embreal/HiFive1/namespace
-I tsm-embreal/src
-DEARLY_INIT
-DNO_FLOATS
-DNO_LONG_DIV
-DSYS_SYS_SHOW_STARTUP
-D'INTERFACE(name,info)='
-D'IMPLEMENTATION(name,info)='
-D'VERSION="heads/master-0-g0f5b43b-dirty "' 
-O2
-std=c++14
-march=rv32imac
-mabi=ilp32
-fomit-frame-pointer
-fpermissive
-fcheck-new
-fsized-deallocation
-fno-exceptions
-fno-use-cxa-atexit
-fno-builtin
-falign-functions=32
-Wreturn-type
-fno-rtti
-Wall
-fno-unwind-tables 
-c
-x c++
-o tor.o -

&&
../tc/bin/riscv32-fhnw-elf-ld
--relax
-o event-demo-1
tor.o
sys/deb/deblow.o
sys/deb/deblow0.o
sys/boot/big-bang.o
sys/msg-1.o
sys/msg.o 
io/ascii/out.o
io/ascii/write.o
util/float-conv.o
math/double.o
sys/deb/deb.o
sys/abi/abi.o
sys/board.o
sys/reg/gpio.o
sys/boot/big-bang-continued.o
sys/reg/uart.o
sys/reg/aon.o
sys/hwreg.o
sys/sys.o
event-demo-1.o
sys/event.o
-Map=event-demo-1.map
--build-id
-Ltsm-embreal/resources/gcc-riscv-8.2.0/bin/../lib/gcc/riscv32-fhnw-elf/8.2.0/
-lgcc
--script=../config/layout.ld
&&
../tc/bin/riscv32-fhnw-elf-objcopy
--output-target=binary
event-demo-1 
event-demo-1.bin
$ ../tc/bin/riscv32-fhnw-elf-readelf -h event-demo-1
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x20400000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          30672 (bytes into file)
  Flags:                             0x1, RVC, soft-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         2
  Size of section headers:           40 (bytes)
  Number of section headers:         9
  Section header string table index: 8
  
$ ../tc/bin/riscv32-fhnw-elf-readelf -S event-demo-1
There are 9 section headers, starting at offset 0x77d0:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        20400000 001000 00363c 00  AX  0   0 32
  [ 2] .data             PROGBITS        80000000 005000 000000 00  WA  0   0  1
  [ 3] .sdata            PROGBITS        80000000 005000 000004 00  WA  0   0  4
  [ 4] .bss              NOBITS          80000004 005004 0000a8 00  WA  0   0  4
  [ 5] .comment          PROGBITS        00000000 005004 000011 01  MS  0   0  1
  [ 6] .symtab           SYMTAB          00000000 005018 000ff0 10      7  48  4
  [ 7] .strtab           STRTAB          00000000 006008 00178c 00      0   0  1
  [ 8] .shstrtab         STRTAB          00000000 007794 00003c 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

Leave a Reply

Your email address will not be published. Required fields are marked *