This commit was generated by cvs2svn to compensate for changes in r2,

which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2000-05-28 13:40:48 +00:00
parent 579491e8a4
commit 53dd513176
847 changed files with 91345 additions and 0 deletions

1
libsrc/dbg/.cvsignore Normal file
View File

@@ -0,0 +1 @@
dbg.s

26
libsrc/dbg/Makefile Normal file
View File

@@ -0,0 +1,26 @@
#
# makefile for CC65 runtime library
#
.SUFFIXES: .o .s .c
%.o: %.c
@echo $<
@$(CC) $(CFLAGS) $<
@$(AS) -g -o $@ $(AFLAGS) $(*).s
%.o: %.s
@echo $<
@$(AS) -g -o $@ $(AFLAGS) $<
C_OBJS = dbg.o
S_OBJS = asmtab.o dbgdasm.o dbgdump.o dbgisram.o dbgsupp.o
all: $(C_OBJS) $(S_OBJS)
clean:
@rm -f *~
@rm -f $(C_OBJS:.o=.s)
@rm -f $(C_OBJS)
@rm -f $(S_OBJS)

61
libsrc/dbg/asmtab.s Normal file
View File

@@ -0,0 +1,61 @@
;
; Ullrich von Bassewitz, 07.08.1998
;
; Tables needed for the line assembler/disassembler.
;
.export OffsetTab
.export AdrFlagTab
.export SymbolTab1, SymbolTab2
.export MnemoTab1, MnemoTab2
; -------------------------------------------------------------------------
; Assembler tables
.rodata
OffsetTab:
.byte $40,$02,$45,$03,$D0,$08,$40,$09
.byte $30,$22,$45,$33,$D0,$08,$40,$09
.byte $40,$02,$45,$33,$D0,$08,$40,$09
.byte $40,$02,$45,$B3,$D0,$08,$40,$09
.byte $00,$22,$44,$33,$D0,$8C,$44,$00
.byte $11,$22,$44,$33,$D0,$8C,$44,$9A
.byte $10,$22,$44,$33,$D0,$08,$40,$09
.byte $10,$22,$44,$33,$D0,$08,$40,$09
.byte $62,$13,$78,$A9
AdrFlagTab:
.byte $00,$21,$81,$82,$00,$00,$59,$4D
.byte $91,$92,$86,$4A,$85,$9D
SymbolTab1:
.byte $2C,$29,$2C,$23,$28,$24
SymbolTab2:
.byte $59,$00,$58,$24,$24,$00
MnemoTab1:
.byte $1C,$8A,$1C,$23,$5D,$8B,$1B,$A1
.byte $9D,$8A,$1D,$23,$9D,$8B,$1D,$A1
.byte $00,$29,$19,$AE,$69,$A8,$19,$23
.byte $24,$53,$1B,$23,$24,$53,$19,$A1
.byte $00,$1A,$5B,$5B,$A5,$69,$24,$24
.byte $AE,$AE,$A8,$AD,$29,$00,$7C,$00
.byte $15,$9C,$6D,$9C,$A5,$69,$29,$53
.byte $84,$13,$34,$11,$A5,$69,$23,$A0
MnemoTab2:
.byte $D8,$62,$5A,$48,$26,$62,$94,$88
.byte $54,$44,$C8,$54,$68,$44,$E8,$94
.byte $00,$B4,$08,$84,$74,$B4,$28,$6E
.byte $74,$F4,$CC,$4A,$72,$F2,$A4,$8A
.byte $00,$AA,$A2,$A2,$74,$74,$74,$72
.byte $44,$68,$B2,$32,$B2,$00,$22,$00
.byte $1A,$1A,$26,$26,$72,$72,$88,$C8
.byte $C4,$CA,$26,$48,$44,$44,$A2,$C8

1511
libsrc/dbg/dbg.c Normal file

File diff suppressed because it is too large Load Diff

295
libsrc/dbg/dbgdasm.s Normal file
View File

@@ -0,0 +1,295 @@
;
; Ullrich von Bassewitz, 07.08.1998
;
; unsigned DbgDisAsm (char* buf, unsigned addr);
; unsigned DbgDisAsm (unsigned addr);
;
;
; Part of this code is taken from the Plus/4 machine language monitor
; (TEDMon).
;
.import utsta0, popax
.import __hextab, OffsetTab, AdrFlagTab
.import SymbolTab1, SymbolTab2, MnemoTab1, MnemoTab2
; -------------------------------------------------------------------------
; Equates for better readability
.importzp sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3
BufIndex = tmp1 ; Index into output buffer
OperandLen = tmp2 ; Length of operand
BufLen = tmp3 ; Length of output buffer
AdrFlagBuf = tmp4 ; Flag for addressing mode
YSave = sreg ; Temp storage
XSave = sreg+1 ; Dito
BufPtr = ptr1 ; Pointer to output buffer
MemPtr = ptr2 ; Pointer to memory to disassemble
MnemoBuf = ptr3 ; Buffer for decoding mnemonic
; -------------------------------------------------------------------------
; Main entries
.export _DbgDisAsm, _DbgDisAsmLen
.proc _DbgDisAsm
sta BufLen ; Save the buffer length
jsr popax ; Get the buffer pointer
sta BufPtr
stx BufPtr+1
jsr popax ; Get the address
sta MemPtr
stx MemPtr+1
lda #0
sta BufIndex ; Initialize index into buffer
jsr DisAssLine ; Disassemble one line into the buffer
lda BufLen ; Get requested length
sec
sbc BufIndex
beq L2
tax ; Count into X
ldy BufIndex
lda #$20 ; Get a space
L1: sta (BufPtr),y
iny
dex
bne L1
L2: lda #0 ; Add C string terminator
sta (BufPtr),y
beq disassret
.endproc
_DbgDisAsmLen:
sta MemPtr ; Save address
stx MemPtr+1
ldy #$00
lda (MemPtr),y ; Get the opcode from memory...
jsr AnalyzeOPCode ; ...and analyze it
disassret:
ldx OperandLen ; Get length of operand
inx ; Adjust for opcode byte
txa
jmp utsta0 ; Set condition codes
; -------------------------------------------------------------------------
; Helper functions
Put3Spaces:
jsr PutSpace
Put2Spaces:
jsr PutSpace
PutSpace:
lda #$20
PutChar:
sty YSave ; Save Y
ldy BufIndex ; Get current line pointer
cpy BufLen ; Be sure not to overflow the buffer
bcs PC9
sta (BufPtr),y ; store character
iny ; bump index
sty BufIndex
PC9: ldy YSave ; get old value
rts
; Print the 16 bit hex value in X/Y
PutHex16:
txa
jsr PutHex8
tya
; Print 8 bit value in A, save X and Y
PutHex8:
stx XSave
sty YSave
ldy BufIndex
pha
lsr a
lsr a
lsr a
lsr a
tax
lda __hextab,x
sta (BufPtr),y
iny
pla
and #$0F
tax
lda __hextab,x
sta (BufPtr),y
iny
sty BufIndex
ldy YSave
ldx XSave
rts
; -------------------------------------------------------------------------
; Eine Zeile disassemblieren
DisAssLine:
ldy MemPtr
ldx MemPtr+1
jsr PutHex16 ; Print the address
jsr Put2Spaces ; Add some space
ldy #$00
lda (MemPtr),y ; Get the opcode from memory...
jsr AnalyzeOPCode ; ...and analyze it
pha ; Save mnemonic
ldx OperandLen ; Number of bytes
; Print the bytes that make up the instruction
inx
L2083: dex
bpl L208C ; Print the instruction bytes
jsr Put3Spaces ; If none left, print spaces instead
jmp L2094
L208C: lda (MemPtr),y ; Get a byte from memory
jsr PutHex8 ; ...and print it
jsr PutSpace ; Add some space
L2094: iny ; Next one...
cpy #$03 ; Maximum is three
bcc L2083 ;
jsr Put2Spaces ; Add some space after bytes
; Print the assembler mnemonic
pla ; Get mnemonic code
ldx #$03
jsr PutMnemo ; Print the mnemonic
ldx #$06
; Print the operand
L20A4: cpx #$03
bne L20BA
ldy OperandLen
beq L20BA
L20AC: lda AdrFlagBuf
cmp #$E8 ; Branch?
lda (MemPtr),y ; Get branch offset
bcs GetBranchAdr ; If branch: Calculate address
jsr PutHex8 ; Otherwise print 8bit value
dey
bne L20AC
L20BA: asl AdrFlagBuf
bcc L20CC
lda SymbolTab1-1,x
jsr PutChar
lda SymbolTab2-1,x
beq L20CC
jsr PutChar
L20CC: dex
bne L20A4
rts
; If the instruction is a branch, calculate the absolute address of the
; branch target and print it.
GetBranchAdr:
jsr L20DD
clc
adc #$01
bne L20D9
inx ; Bump high byte
L20D9: tay
jmp PutHex16 ; Output address
L20DD: ldx MemPtr+1
tay
bpl L20E3
dex
L20E3: adc MemPtr
bcc L20E8
inx ; Bump high byte
L20E8: rts
; -------------------------------------------------------------------------
; Subroutine to analyze an opcode byte in A. Will return a byte that
; encodes the mnemonic, and will set the number of bytes needed for this
; instruction in OperandLen
AnalyzeOPCode:
tay
lsr a
bcc L20F8
lsr a
bcs L2107
cmp #$22
beq L2107
and #$07
ora #$80
L20F8: lsr a
tax
lda OffsetTab,x
bcs L2103
lsr a
lsr a
lsr a
lsr a
L2103: and #$0F
bne L210B
L2107: ldy #$80
lda #$00
L210B: tax
lda AdrFlagTab,x
sta AdrFlagBuf
and #$03
sta OperandLen
tya
and #$8F
tax
tya
ldy #$03
cpx #$8A
beq L212B
L2120: lsr a
bcc L212B
lsr a
L2124: lsr a
ora #$20
dey
bne L2124
iny
L212B: dey
bne L2120
rts
; -------------------------------------------------------------------------
; Print the mnemonic with code in A (that code was returned by
; AnalyzeOpcode).
PutMnemo:
tay
lda MnemoTab1,y
sta MnemoBuf
lda MnemoTab2,y
sta MnemoBuf+1
L213A: lda #$00
ldy #$05 ; 3*5 bits in two bytes
L213E: asl MnemoBuf+1
rol MnemoBuf
rol a
dey
bne L213E
adc #$3F
jsr PutChar
dex
bne L213A
jmp PutSpace

81
libsrc/dbg/dbgdump.s Normal file
View File

@@ -0,0 +1,81 @@
;
; Ullrich von Bassewitz, 11.08.1998
;
; char* DbgMemDump (unsigend Addr, char* Buf, unsigned char Length);
;
.export _DbgMemDump
.import addysp1
.import __hextab
.importzp sp, tmp2, tmp3, tmp4, ptr3, ptr4
_DbgMemDump:
ldy #0
lda (sp),y ; Get length
sta tmp4
iny
lda (sp),y ; Get the string buffer
sta ptr3
iny
lda (sp),y
sta ptr3+1
iny
lda (sp),y ; Get the address
sta ptr4
iny
lda (sp),y
sta ptr4+1
jsr addysp1 ; Drop the parameters
lda #0
sta tmp2 ; String index
sta tmp3 ; Byte index
; Print the address
lda ptr4+1 ; Hi address byte
jsr dump ; Print address
lda ptr4 ; Lo address byte
jsr dump
jsr putspace ; Add a space
dump1: dec tmp4 ; Bytes left?
bmi dump9 ; Jump if no
jsr putspace ; Add a space
ldy tmp3
inc tmp3
lda (ptr4),y
jsr dump
jmp dump1
dump9: lda #0
ldy tmp2
sta (ptr3),y ; Add string terminator
lda ptr3
ldx ptr3+1 ; We assume this is not zero
rts
; Dump one hex byte
dump: pha
lsr a
lsr a
lsr a
lsr a
tax
lda __hextab,x
jsr putc
pla
and #$0F
tax
lda __hextab,x
putc: ldy tmp2
inc tmp2
sta (ptr3),y
rts
putspace:
lda #$20
bne putc

55
libsrc/dbg/dbgisram.s Normal file
View File

@@ -0,0 +1,55 @@
;
; Ullrich von Bassewitz, 10.08.1998
;
; int DbgIsRAM (unsigned Addr);
;
.export _DbgIsRAM
.import popax, return0, return1
.importzp ptr1
_DbgIsRAM:
sta ptr1 ; Store the address
stx ptr1+1
ldy #0
php ; Save I flag
sei ; Disable interrupts
lda (ptr1),y ; Get old value
pha ; ...and save it
ldx #3
L1: lda TestVal,x
jsr CheckCell
bne L2
dex
bpl L1
; This seems to be RAM
pla
sta (ptr1),y ; Restore old value
plp ; Restore old I flag
jmp return1
; No RAM at this address
L2: pla
sta (ptr1),y ; Restore old value
plp ; Restore old I flag
jmp return0
; Check one memory cell
CheckCell:
sta (ptr1),y
cmp (ptr1),y ; Could we write it?
rts
.rodata
TestVal:
.byte $55, $AA, $33, $CC

201
libsrc/dbg/dbgsupp.s Normal file
View File

@@ -0,0 +1,201 @@
;
; Ullrich von Bassewitz, 08.08.1998
;
; Support routines for the debugger
;
.export _DbgInit
.export _DbgSP, _DbgCS, _DbgHI
.import popax, return0, _DbgEntry, _set_brk, _end_brk
.import _DbgBreaks
.import _brk_pc
.importzp sp, sreg, ptr1, tmp1, zpspace
; C callable function, will install the debugger
_DbgInit:
lda #<DbgBreak
ldx #>DbgBreak
jmp _set_brk
; Entry for the break vector.
DbgBreak:
pla
sta retsav
pla
sta retsav+1
cli
tsx ; Stack pointer
stx _DbgSP
jsr DbgSwapZP ; Swap stuff
lda #<DbgStack ; Set new stack
sta sp
lda #>DbgStack
sta sp+1
jsr ResetDbgBreaks ; Reset temporary breakpoints
jsr _DbgEntry ; Call C code
jsr SetDbgBreaks ; Set temporary breakpoints
jsr DbgSwapZP ; Swap stuff back
lda retsav+1
pha
lda retsav
pha
rts
; Stack used when in debugger mode
.bss
.res 256
DbgStack:
; Swap space for the the C temporaries
CTemp:
_DbgCS: .res 2 ; sp
_DbgHI: .res 2 ; sreg
.res 22 ; Other stuff
_DbgSP: .res 1
retsav: .res 2 ; Save buffer for return address
.code
; Swap the C temporaries
DbgSwapZP:
ldy #zpspace-1
Swap1: ldx CTemp,y
lda sp,y ; ######
sta CTemp,y
txa
sta sp,y
dey
bpl Swap1
rts
; ----------------------------------------------------------------------------
; Utility functions
; Set/reset the breakpoints. We must do that here since the breakpoints
; may be in the runtime stuff, causing the C part to fail before it has
; reset the breakpoints. See declaration of struct breakpoint in the C
; source
MaxBreaks = 48 ; 4*12
ResetDbgBreaks:
ldy #0
ldx #0
L4: lda _DbgBreaks+3,x ; Get bk_use
beq L6 ; Jump if not set
bpl L5 ; Jump if user breakpoint
lda #0
sta _DbgBreaks+3,x ; Clear if temp breakpoint
L5: lda _DbgBreaks+1,x ; PC hi
sta ptr1+1
lda _DbgBreaks,x ; PC lo
sta ptr1
lda _DbgBreaks+2,x ; Old OPC
sta (ptr1),y ; Reset the breakpoint
L6: inx
inx
inx
inx
cpx #MaxBreaks ; Done?
bne L4
rts
SetDbgBreaks:
ldx #0
ldy #0
L7: lda _DbgBreaks+3,x ; Get bk_use
beq L8 ; Jump if not set
lda _DbgBreaks+1,x ; PC hi
sta ptr1+1
lda _DbgBreaks,x ; PC lo
sta ptr1
lda (ptr1),y ; Get the breakpoint OPC...
sta _DbgBreaks+2,x ; ...and save it
lda #$00 ; Load BRK opcode
sta (ptr1),y
L8: inx
inx
inx
inx
cpx #MaxBreaks ; Done?
bne L7
rts
; Get a free breakpoint slot or return 0
.export _DbgGetBreakSlot
_DbgGetBreakSlot:
ldx #0
L10: lda _DbgBreaks+3,x ; Get bk_use
beq L11 ; Jump if not set
inx
inx
inx
inx
cpx #MaxBreaks ; Done?
bne L10
jmp return0 ; No free slot
L11: stx tmp1
lda #<_DbgBreaks
ldx #>_DbgBreaks
clc
adc tmp1
bcc L12
inx
L12: ldy #1 ; Force != 0
rts
; Check if a given address has a user breakpoint set, if found, return the
; slot, otherwise return 0.
.export _DbgIsBreak
_DbgIsBreak:
jsr popax ; Get address
sta ptr1
stx ptr1+1
ldx #0
L20: lda _DbgBreaks+3,x ; Get bk_use
beq L21 ; Jump if not set
bmi L21 ; Jump if temp breakpoint
lda _DbgBreaks,x ; Low byte of address
cmp ptr1
bne L21
lda _DbgBreaks+1,x ; High byte of address
cmp ptr1+1
beq L22
L21: inx
inx
inx
inx
cpx #MaxBreaks ; Done?
bne L20
jmp return0 ; Not found
L22: stx tmp1
lda #<_DbgBreaks
ldx #>_DbgBreaks
clc
adc tmp1
bcc L23
inx
L23: ldy #1 ; Force != 0
rts