/* File: SumoMon.asm Copyright ©1998, 1999 Larry Barello Author: Larry Barello lbarello@accessone.com You are allowed to use this file for personal use only. You may use, embed, modify or distribute the contents of this file in any way you see fit as long as you include this copyright notice in the resulting file. Any commercial or industrial use including publishing or distributing in any form requires the written authorization of the copyright holder(s). No guarantees are made about fitness, functionality, correctness or performance of this file. The file is supplied on a "AS IS" basis, with no responsibility assumed by the author(s) for bug fixes, support, or damages of any sort arising from the use of this file. Contact the author with problem reports or fixes, feature requests or additions and questions. They are welcomed and will be incorporated as time and energy permits. */ #include "Registers.inc" #include "AvrX.inc" MODULE SUMOMONITOR EXTERN _QueuePid SmallContext SmallContextSize EXTERN AvrXReadEEProm AvrXWriteEEProm EXTERN AvrXSuspend AvrXResume EXTERN AvrXCancelTimer EXTERN AvrXSetSemaphore EXTERN GetHexByte GetHexWord PutHexByte PutHexWord EXTERN _GetChar PutChar PutCR PutSpace IsWhite _PrintString PUBLIC MonitorTcb MonitorEntry Monitor MonitorStack MonitorPid RSEG DATA:DATA(0) Address: DS 2 EEAddress: DS 2 ObjectId: DS 1 ; Default for Object ID ; ; Stack Usage: Context (10) + Local (8) + non-avrx interrupt (2) bytes ; needed for stack ; RSEG SSEG:DATA(0) DS 21 MonitorStack: DS 1 RSEG AVRXDATA:DATA(0) MonitorPid: DS PidSz RSEG CODE WORDFLAG: = 0 EEFLAG: = 1 #ifndef SioFlags #define SioFlags R26 #endif ;+ ;------------------------------------------------- ; ; NOTE: Highest Priority because user interface ; should work even when a process gets into ; an infinite loop. ; MonitorTcb: DW MonitorStack DW MonitorEntry>>1 DB MonitorPid, SmallContextSize DW SmallContext>>1 DB 0x01 ; Priority ;- ;+ ;------------------------------------------------- ; Sumo Monitor: program for examining and modifying ; registers, data, i/o and eeprom. ; ; Stack Usage: ; 6 words max ; ; Register Usage: ; R24-31 (mid size context save) ; ; NB {opt, opt} Must select one of the options ; [opt, opt] Optional input - can be ignored ; ; Command summary: ; Hello: DB '\r' DB 'SumoMon V1\r' ; DB '\r' ; DB 'Modify = m{s,e}[w][aaaa]\r' ; DB 'Halt = h[oo]\r' ; DB 'Step = s[oo]\r' ; DB 'Resume = r[oo]\r' ; DB 'Signal = i[oo]\r' ; DB 'Cancel = c[oo]\r' DB 0 ;- RSEG CODE(1) MonitorEntry: ldi Zl, low(Hello) ldi Zh, high(Hello) rcall _PrintString ldi Zl, low(RAMSTART) sts Address+1, Zl ldi Zh, high(RAMSTART) sts Address, Zh Monitor: rcall PutCR ldi TxByte, '>' rcall PutChar rcall m_Parse rjmp Monitor m_Parse: rcall _GetChar cpi RxByte, 'm' ; Modify Memory breq m_ModifyMemory cpi RxByte, 'h' ; Halt (suspend) Process breq m_HaltProcess cpi RxByte, 's' ; Step process breq m_StepProcess cpi RxByte, 'r' ; Resume Process breq m_ResumeProcess cpi RxByte, 'i' ; Signal Semaphore breq m_SetSemaphore cpi RxByte, 'c' ; breq m_CancelTimer m_err: ldi TxByte, '?' rjmp PutChar m_ModifyMemory: rjmp GetFlagsAndAddress m_HaltProcess: rcall GetObjectID brtc m_err rjmp AvrXSuspend m_ResumeProcess: rcall GetObjectID brtc m_err rjmp AvrXResume m_CancelTimer: rcall GetObjectID brtc m_err rjmp AvrXCancelTimer m_SetSemaphore: rcall GetObjectID brtc m_err rjmp AvrXSetSemaphore m_StepProcess: rcall GetObjectID brtc m_err clr Yh ldd Xl, Y+PidState sbrs Xl, SuspendedBit rjmp m_err cbr Xl, _SUSP | _SUSPENDED ; Clear suspension std Y+PidState, Xl mov Xl, Yl BeginCritical rcall _QueuePid ; Add to run queue ldd Xl, Y+PidState sbr Xl, _SUSP ; Re-suspend std Y+PidState, Xl EndCriticalReturn ;+ ; GetObjectID ; ; Little helper routine to get and return a byte value with ; carry set if all Ok. e.g. entered 2 hex digits, or terminated ; with whitespace. ; ; Puts the ID in the Xl register because that is what all the ; AvrX routines expect. ;- GetObjectID: rcall GetHexByte brts goi00 rcall IsWhite brtc goi02 goi00: tst R25 brne goi01 ; lds Yl, ObjectId ; Restore default goi01: sts ObjectId, Yl mov Zl, Yl ; Some like Xl mov Xl, Yl ; and some like Zl goi02: ret ;+ ;----------------------------------------------------- ; ; GetFlagsAndAddress ; ; Parse input stream for byte/word flag and address. All are optional ; as long as the input stream is terminated with whitespace. ;- GetFlagsAndAddress: clt rcall _GetChar cpi RxByte, 's' brne gbTRYEERAM cbr SioFlags, 1<