access-softek / msp430-clang

0 stars 2 forks source link

Invalid instruction mnemonic "pushm.w" #60

Open dmikushin opened 6 years ago

dmikushin commented 6 years ago

ChibiOS compilation dies here due to "invalid instruction mnemonic pushm.w" on line asm volatile ("pushm.w #7, R10");

/**
 * @brief   Performs a context switch between two threads.
 * @details This is the most critical code in any port, this function
 *          is responsible for the context switch between 2 threads.
 * @note    The implementation of this code affects <b>directly</b> the context
 *          switch performance so optimize here as much as you can.
 *
 * @param[in] ntp       the thread to be switched in
 * @param[in] otp       the thread to be switched out
 */
#if !(__GNUC__ < 6 && __GNUC_MINOR__ < 4) || defined(__OPTIMIZE__)
__attribute__((naked))
#endif
void _port_switch(thread_t *ntp, thread_t *otp) {
#if (__GNUC__ < 6 && __GNUC_MINOR__ < 4) && !defined(__OPTIMIZE__)
  asm volatile ("add #4, r1");
#endif
  (void)(ntp);
  (void)(otp);
#if defined(__MSP430X_LARGE__)
  asm volatile ("pushm.a #7, R10");
  asm volatile ("mova r1, @R13");
  asm volatile ("mova @R12, r1");
  asm volatile ("popm.a #7, R10");
  asm volatile ("reta");
#else
  asm volatile ("pushm.w #7, R10");
  asm volatile ("mov r1, @R13");
  asm volatile ("mov @R12, r1");
  asm volatile ("popm.w #7, R10");
  asm volatile ("ret");
#endif
}
chbessonova commented 6 years ago

Looks like pushm and popm instructions are from 430X isa extension. pushm #n, Rm is like 'push every register starting from Rm till R(m-n+1) to stack'. So, pushm #7, r10 should be equivalent to the following sequence:

push r10
push r9
push r8
push r7
push r6
push r5
push r4
asl commented 6 years ago

So, yes, we need a case for !MSP430X. Also we need to start planning to support MSP430X... The latter might be a bit tricky...

dmikushin commented 6 years ago

@asl ~22 insts to implement for MSP430X (manual, pp. 45-46: http://www.ti.com/lit/ug/slau391f/slau391f.pdf)

@chbessonova Thanks for the pointers! I was able to cook stubs for pushm/popm to get them pass through.

FWIW WIP sketch is here: https://github.com/dmikushin/msp430-clang/commit/bf759f7523d3723eba91d0e74cc8a692334cd3c9

asl commented 6 years ago

@dmikushin We do not support "X" isa. So you could not simply "add" pushm instruction, because it does not exist on msp430 :)

dmikushin commented 6 years ago

Sure: this will work on MSP430X only. ATM I needed a stub for compilation, that could later split into an "X" hw feature. Otherwise, we should drop ChibiOS in favor of something strictly 430-conformant.

asl commented 6 years ago

But what prevented you from modifying the source code if you needed the stub?

dmikushin commented 6 years ago

So, yes, we need a case for !MSP430X. Also we need to start planning to support MSP430X... The latter might be a bit tricky...

It was driven by your comment.

asl commented 6 years ago

Sorry, I was not not clear. I wrote that we need a special case in the source code to support non-X case. And "planning" does not mean "start coding right now" :)