~joshrig/mipsfoo

35c4987dbcc5fc36e588282da5f2f887a31eb08d — Joshua Lynch 11 months ago e71eff5
renamed the files.
we've basic C functionality now.
3 files changed, 152 insertions(+), 59 deletions(-)

A locore.S
D main.S
R config.c => main.c
A locore.S => locore.S +121 -0
@@ 0,0 1,121 @@
#include <xc.h>
        
        .set nomips16
        .set nomicromips
        .set noreorder

        .align 2

        ## .equ LATB,     0xBF860130
        ## .equ TRISBCLR, 0xBF860114
        ## .equ ANSELCLR, 0xBF860104
        ## .equ LATBSET,  0xBF860138
        ## .equ LATBCLR,  0xBF860134

        .section .reset,code,keep

        .ent _reset
_reset:
        di                              # disable interrupts
        ehb                             # hazard barrier

        ## sw      zero, (LATB)            # enable gpio port
        ## li      t3, 0x7                 # gpio mask
        ## sll     t3, t3, 8
        ## sw      t3, (TRISBCLR)          # set output pin direction
        ## sw      t3, (ANSELCLR)          # enable digital mode

        la      sp, _stack              # _stack is defined in the linker script
        la      gp, _gp                 # _gp is defined in the linker script

_start_bss_init:
        la      t0, _bss_begin
        la      t1, _bss_end

        b       _bss_check
        nop

_bss_init:
        sw      zero, 0x0(t0)
        addu    t0, 4

_bss_check:
        bltu    t0, t1, _bss_init
        nop

        # XXX copy data from flash to ram (right?)
        # i mean, what exactly is in the .data section?

        mtc0    zero, _CP0_COUNT        # init count

        li      t2, -1                  # init compare
        mtc0    t2, _CP0_COMPARE

        li      t0, (1 << 22)           # set BEV
        mfc0    t2, _CP0_STATUS
        or      t2, t0, t2
        mtc0    t2, _CP0_STATUS

        la      t1, _ebase_address      # set ebase
        ehb
        mtc0    t1, _CP0_EBASE


        and     a0, a0, 0               # call main via a "thunk"
        and     a1, a1, 0
        la      t0, _main_entry
        jr      t0
        nop
        
        .end _reset
        .globl _reset
        .size _reset, .-_reset


        .ent _main_entry
_main_entry:

        and     a0, a0, 0
        and     a1, a1, 0
        la      t0, main
        jalr    t0
        nop

1:
        j       1b
        nop
        
        .end _main_entry
        
        
##         sw      zero, (LATB)            # enable gpio port

##         li      t3, 0x7                 # gpio mask
##         sll     t3, t3, 8

##         sw      t3, (TRISBCLR)          # set output pin direction
##         sw      t3, (ANSELCLR)          # enable digital mode

##         li      t0, 0                   # load the initial counter value

## 1:
##         sw      t3, (LATBCLR)           # logic low on the gpios

##         addiu   t0, t0, 1               # increment t0
##         and     t1, t0, 0x7             # mask off the relevant gpios
##         sll     t1, t1, 8               # left shift the values
##         sw      t1, (LATBSET)           # set the gpios high

##         li      t6, 4000000             # load delay
## loop:
##         subu    t6, t6, 1               # subtract 1
##         bnez    t6, loop                # if t6 != 0, loop
##         nop

##         j       1b
##         nop

##         .end _reset
##         .globl _reset
##         .size _reset, .-_reset
        

D main.S => main.S +0 -52
@@ 1,52 0,0 @@
#include <xc.h>
        
        .set nomips16
        .set nomicromips
        .set noreorder

        .align 2

        .equ LATB,     0xBF860130
        .equ TRISBCLR, 0xBF860114
        .equ ANSELCLR, 0xBF860104
        .equ LATBSET,  0xBF860138
        .equ LATBCLR,  0xBF860134

        .section .reset,code,keep

        .ent _reset
_reset:
        di                      // disable interrupts
        ehb                     // hazard barrier

        sw  zero, (LATB)        // enable gpio port

        li  t3, 0x7
        sll t3, t3, 8           // gpio mask

        sw  t3, (TRISBCLR)      // set output pin direction
        sw  t3, (ANSELCLR)      // enable digital mode

        li  t0, 0               // load the initial counter value

1:
        sw    t3, (LATBCLR)     // logic low on the gpios

        addiu t0, t0, 1         // increment t0, save to t1
        and   t1, t0, 0x7       // mask off the relevant gpios
        sll   t1, t1, 8         // left shift the values
        sw    t1, (LATBSET)     // set the gpios high

        li   t6, 4000000        // load delay
loop:
        subu t6, t6, 1          // subtract 1
        bnez t6, loop           // if t6 != 0, loop
        nop

        j 1b
        nop

        .end _reset
        .globl _reset
        .size _reset, .-_reset
        

R config.c => main.c +31 -7
@@ 1,13 1,7 @@
#include <xc.h>
#include <sys/attribs.h>

#define DEVICE_NAME		 "PIC32MZ2048EFH064"
#define DEVICE_ARCH		 "MIPS"
#define DEVICE_FAMILY		 "PIC32MZEF"
#define DEVICE_SERIES		 "PIC32MZ"

/* CPU clock frequency */
#define CPU_CLOCK_FREQUENCY 200000000
#include <inttypes.h>

/*** DEVCFG0 ***/
#pragma config DEBUG =      OFF


@@ 64,3 58,33 @@
#pragma config TSEQ =       0xffff
#pragma config CSEQ =       0x0

int main(int, int) __attribute__((section(".reset")));


int main(int a, int b)
{
    volatile uint32_t *LATB      = (volatile uint32_t *)0xBF860130;
    volatile uint32_t *TRISBCLR  = (volatile uint32_t *)0xBF860114;
    volatile uint32_t *ANSELBCLR = (volatile uint32_t *)0xBF860104;
    volatile uint32_t *LATBSET   = (volatile uint32_t *)0xBF860138;
    volatile uint32_t *LATBCLR   = (volatile uint32_t *)0xBF860134;
    uint16_t mask = 0x7 << 8;
    uint16_t count;

    
    *LATB = 0;
    *TRISBCLR = mask;
    *ANSELBCLR = mask;


    count = 0;
    while (1)
    {
        *LATBCLR = mask;
        *LATBSET = (count++ & 0x7) << 8;
        for (uint32_t i = 1000000; i > 0; i--)
            ;
    }

    return 0;
}