Initial support for stm8 ##arch

* Missing parts: pseudodisasm, esil and instruction descriptions
This commit is contained in:
pancake 2024-05-01 04:08:24 +02:00 committed by GitHub
parent 34d870c638
commit 7b20346d77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 2466 additions and 3 deletions

View File

@ -27,6 +27,7 @@ arch.ebc
arch.evm
arch.fslsp
arch.gb
arch.stm8
arch.h8300
arch.hppa_gnu
arch.i4004

View File

@ -1,4 +1,4 @@
FILES=nes bf
FILES=nes bf stm8
OPDIR=${DESTDIR}/$(DATADIR)/radare2/${VERSION}/platform
include ../../../config-user.mk

View File

@ -1,3 +1,5 @@
arch_pro_files = [
'bf',
'nes',
'stm8',
]

1
libr/arch/d/stm8-fini.r2 Normal file
View File

@ -0,0 +1 @@
f-ioreg*

389
libr/arch/d/stm8-init.r2 Normal file
View File

@ -0,0 +1,389 @@
# Port A
f ioreg.PA_ODR=0x5000
f ioreg.PA_IDR=0x5001
f ioreg.PA_DDR=0x5002
f ioreg.PA_CR1=0x5003
f ioreg.PA_CR2=0x5004
# Port B
f ioreg.PB_ODR=0x5005
f ioreg.PB_IDR=0x5006
f ioreg.PB_DDR=0x5007
f ioreg.PB_CR1=0x5008
f ioreg.PB_CR2=0x5009
# Port C
f ioreg.PC_ODR=0x500A
f ioreg.PC_IDR=0x500B
f ioreg.PC_DDR=0x500C
f ioreg.PC_CR1=0x500D
f ioreg.PC_CR2=0x500E
# Port D
f ioreg.PD_ODR=0x500F
f ioreg.PD_IDR=0x5010
f ioreg.PD_DDR=0x5011
f ioreg.PD_CR1=0x5012
f ioreg.PD_CR2=0x5013
# Port E
f ioreg.PE_ODR=0x5014
f ioreg.PE_IDR=0x5015
f ioreg.PE_DDR=0x5016
f ioreg.PE_CR1=0x5017
f ioreg.PE_CR2=0x5018
# Port F
f ioreg.PF_ODR=0x5019
f ioreg.PF_IDR=0x501A
f ioreg.PF_DDR=0x501B
f ioreg.PF_CR1=0x501C
f ioreg.PF_CR2=0x501D
# Flash
f ioreg.FLASH_CR1=0x5050
f ioreg.FLASH_CR2=0x5051
f ioreg.FLASH_PUKR=0x5052
f ioreg.FLASH_DUKR=0x5053
f ioreg.FLASH_IAPSR=0x5054
# DMA1
f ioreg.DMA1_GCSR=0x5070
f ioreg.DMA1_GIR1=0x5071
f ioreg.DMA1_C0CR=0x5075
f ioreg.DMA1_C0SPR=0x5076
f ioreg.DMA1_C0NDTR=0x5077
f ioreg.DMA1_C0PARH=0x5078
f ioreg.DMA1_C0PARL=0x5079
f ioreg.DMA1_C0M0ARH=0x507B
f ioreg.DMA1_C0M0ARL=0x507C
f ioreg.DMA1_C1CR=0x507F
f ioreg.DMA1_C1SPR=0x5080
f ioreg.DMA1_C1NDTR=0x5081
f ioreg.DMA1_C1PARH=0x5082
f ioreg.DMA1_C1PARL=0x5083
f ioreg.DMA1_C1M0ARH=0x5085
f ioreg.DMA1_C1M0ARL=0x5086
f ioreg.DMA1_C2CR=0x5089
f ioreg.DMA1_C2SPR=0x508A
f ioreg.DMA1_C2NDTR=0x508B
f ioreg.DMA1_C2PARH=0x508C
f ioreg.DMA1_C2PARL=0x508D
f ioreg.DMA1_C2M0ARH=0x508F
f ioreg.DMA1_C2M0ARL=0x5090
f ioreg.DMA1_C3CR=0x5093
f ioreg.DMA1_C3SPR=0x5094
f ioreg.DMA1_C3NDTR=0x5095
f ioreg.DMA1_C3PARH_C3M1ARH=0x5096
f ioreg.DMA1_C3PARL_C3M1ARL=0x5097
f ioreg.DMA_C3M0EAR=0x5098
f ioreg.DMA1_C3M0ARH=0x5099
f ioreg.DMA1_C3M0ARL=0x509A
# SYS_CFG
f ioreg.SYSCFG_RMPCR3=0x509D
f ioreg.SYSCFG_RMPCR1=0x509E
f ioreg.SYSCFG_RMPCR2=0x509F
# ITC_EXTI
f ioreg.EXTI_CR1=0x50A0
f ioreg.EXTI_CR2=0x50A1
f ioreg.EXTI_CR3=0x50A2
f ioreg.EXTI_SR1=0x50A3
f ioreg.EXTI_SR2=0x50A4
f ioreg.EXTI_CONF1=0x50A5
#WFE
f ioreg.WFE_CR1=0x50A6
f ioreg.WFE_CR2=0x50A7
f ioreg.WFE_CR3=0x50A8
f ioreg.WFE_CR4=0x50A9
# ITC_EXTI
f ioreg.EXTI_CR4=0x50AA
f ioreg.EXTI_CONF2=0x50AB
# RST
f ioreg.RST_CR=0x50B0
f ioreg.RST_SR=0x50B1
# PWR
f ioreg.PWR_CSR1=0x50B2
f ioreg.PWR_CSR2=0x50B3
# CLK
f ioreg.CLK_CKDIVR=0x50C0
f ioreg.CLK_CRTCR=0x50C1
f ioreg.CLK_ICKCR=0x50C2
f ioreg.CLK_PCKENR1=0x50C3
f ioreg.CLK_PCKENR2=0x50C4
f ioreg.CLK_CCOR=0x50C5
f ioreg.CLK_ECKCR=0x50C6
f ioreg.CLK_SCSR=0x50C7
f ioreg.CLK_SWR=0x50C8
f ioreg.CLK_SWCR=0x50C9
f ioreg.CLK_CSSR=0x50CA
f ioreg.CLK_CBEEPR=0x50CB
f ioreg.CLK_HSICALR=0x50CC
f ioreg.CLK_HSITRIMR=0x50CD
f ioreg.CLK_HSIUNLCKR=0x50CE
f ioreg.CLK_REGCSR=0x50CF
f ioreg.CLK_PCKENR3=0x50D0
# WWDG
f ioreg.WWDG_CR=0x50D3
f ioreg.WWDG_WR=0x50D4
# IWDG
f ioreg.IWDG_KR=0x50E0
f ioreg.IWDG_PR=0x50E1
f ioreg.IWDG_RLR=0x50E2
# BEEP
f ioreg.BEEP_CSR1=0x50F0
f ioreg.BEEP_CSR2=0x50F3
# RTC
f ioreg.RTC_TR1=0x5140
f ioreg.RTC_TR2=0x5141
f ioreg.RTC_TR3=0x5142
f ioreg.RTC_DR1=0x5144
f ioreg.RTC_DR2=0x5145
f ioreg.RTC_DR3=0x5146
f ioreg.RTC_CR1=0x5148
f ioreg.RTC_CR2=0x5149
f ioreg.RTC_CR3=0x514A
f ioreg.RTC_ISR1=0x514C
f ioreg.RTC_ISR2=0x514D
f ioreg.RTC_SPRERH=0x5150
f ioreg.RTC_SPRERL=0x5151
f ioreg.RTC_APRER=0x5152
f ioreg.RTC_WUTRH=0x5154
f ioreg.RTC_WUTRL=0x5155
f ioreg.RTC_SSRH=0x5157
f ioreg.RTC_SSRL=0x5158
f ioreg.RTC_WPR=0x5159
f ioreg.RTC_SHIFTRH=0x515A
f ioreg.RTC_SHIFTRL=0x515B
f ioreg.RTC_ALRMAR1=0x515C
f ioreg.RTC_ALRMAR2=0x515D
f ioreg.RTC_ALRMAR3=0x515E
f ioreg.RTC_ALRMAR4=0x515F
f ioreg.RTC_ALRMASSRH=0x5164
f ioreg.RTC_ALRMASSRL=0x5165
f ioreg.RTC_ALRMASSMSKR=0x5166
f ioreg.RTC_CALRH=0x516A
f ioreg.RTC_CALRL=0x516B
f ioreg.RTC_TCR1=0x516C
f ioreg.RTC_TCR2=0x516D
# CSS
f ioreg.CSSLSE_CSR=0x5190
# SPI1
f ioreg.SPI1_CR1=0x5200
f ioreg.SPI1_CR2=0x5201
f ioreg.SPI1_ICR=0x5202
f ioreg.SPI1_SR=0x5203
f ioreg.SPI1_DR=0x5204
f ioreg.SPI1_CRCPR=0x5205
f ioreg.SPI1_RXCRCR=0x5206
f ioreg.SPI1_TXCRCR=0x5207
# I2C
f ioreg.I2C1_CR1=0x5210
f ioreg.I2C1_CR2=0x5211
f ioreg.I2C1_FREQR=0x5212
f ioreg.I2C1_OARL=0x5213
f ioreg.I2C1_OARH=0x5214
f ioreg.I2C1_OAR2=0X5215
f ioreg.I2C1_DR=0x5216
f ioreg.I2C1_SR1=0x5217
f ioreg.I2C1_SR2=0x5218
f ioreg.I2C1_SR3=0x5219
f ioreg.I2C1_ITR=0x521A
f ioreg.I2C1_CCRL=0x521B
f ioreg.I2C1_CCRH=0x521C
f ioreg.I2C1_TRISER=0x521D
f ioreg.I2C1_PECR=0x521E
# USART
f ioreg.USART1_SR=0x5230
f ioreg.USART1_DR=0x5231
f ioreg.USART1_BRR1=0x5232
f ioreg.USART1_BRR2=0x5233
f ioreg.USART1_CR1=0x5234
f ioreg.USART1_CR2=0x5235
f ioreg.USART1_CR3=0x5236
f ioreg.USART1_CR4=0x5237
f ioreg.USART1_CR5=0x5238
f ioreg.USART1_GTR=0x5239
f ioreg.USART1_PSCR=0x523A
# TIM2
f ioreg.TIM2_CR1=0x5250
f ioreg.TIM2_CR2=0x5251
f ioreg.TIM2_SMCR=0x5252
f ioreg.TIM2_ETR=0x5253
f ioreg.TIM2_DER=0x5254
f ioreg.TIM2_IER=0x5255
f ioreg.TIM2_SR1=0x5256
f ioreg.TIM2_SR2=0x5257
f ioreg.TIM2_EGR=0x5258
f ioreg.TIM2_CCMR1=0x5259
f ioreg.TIM2_CCMR2=0x525A
f ioreg.TIM2_CCER1=0x525B
f ioreg.TIM2_CNTRH=0x525C
f ioreg.TIM2_CNTRL=0x525D
f ioreg.TIM2_PSCR=0x525E
f ioreg.TIM2_ARRH=0x525F
f ioreg.TIM2_ARRL=0x5260
f ioreg.TIM2_CCR1H=0x5261
f ioreg.TIM2_CCR1L=0x5262
f ioreg.TIM2_CCR2H=0x5263
f ioreg.TIM2_CCR2L=0x5264
f ioreg.TIM2_BKR=0x5265
f ioreg.TIM2_OISR=0x5266
# TIM3
f ioreg.TIM3_CR1=0x5280
f ioreg.TIM3_CR2=0x5281
f ioreg.TIM3_SMCR=0x5282
f ioreg.TIM3_ETR=0x5283
f ioreg.TIM3_DER=0x5284
f ioreg.TIM3_IER=0x5285
f ioreg.TIM3_SR1=0x5286
f ioreg.TIM3_SR2=0x5287
f ioreg.TIM3_EGR=0x5288
f ioreg.TIM3_CCMR1=0x5289
f ioreg.TIM3_CCMR2=0x528A
f ioreg.TIM3_CCER1=0x528B
f ioreg.TIM3_CNTRH=0x528C
f ioreg.TIM3_CNTRL=0x528D
f ioreg.TIM3_PSCR=0x528E
f ioreg.TIM3_ARRH=0x528F
f ioreg.TIM3_ARRL=0x5290
f ioreg.TIM3_CCR1H=0x5291
f ioreg.TIM3_CCR1L=0x5292
f ioreg.TIM3_CCR2H=0x5293
f ioreg.TIM3_CCR2L=0x5294
f ioreg.TIM3_BKR=0x5295
f ioreg.TIM3_OISR=0x5296
# TIM4
f ioreg.TIM4_CR1=0x52E0
f ioreg.TIM4_CR2=0x52E1
f ioreg.TIM4_SMCR=0x52E2
f ioreg.TIM4_DER=0x52E3
f ioreg.TIM4_IER=0x52E4
f ioreg.TIM4_SR=0x52E5
f ioreg.TIM4_EGR=0x52E6
f ioreg.TIM4_CNTR=0x52E7
f ioreg.TIM4_PSCR=0x52E8
f ioreg.TIM4_ARR=0x52E9
# IRTIM
f ioreg.IR_CR=0x52FF
# COMP
f ioreg.COMP_CR=0x5300
f ioreg.COMP_CSR=0x5301
f ioreg.COMP_CCS=0x5302
# ADC1
f ioreg.ADC1_CR1=0x5340
f ioreg.ADC1_CR2=0x5341
f ioreg.ADC1_CR3=0x5342
f ioreg.ADC1_SR=0x5343
f ioreg.ADC1_DRH=0x5344
f ioreg.ADC1_DRL=0x5345
f ioreg.ADC1_HTRH=0x5346
f ioreg.ADC1_HTRL=0x5347
f ioreg.ADC1_LTRH=0x5348
f ioreg.ADC1_LTRL=0x5349
f ioreg.ADC1_SQR1=0x534A
f ioreg.ADC1_SQR2=0x534B
f ioreg.ADC1_SQR3=0x534C
f ioreg.ADC1_SQR4=0x534D
f ioreg.ADC1_TRIGR1=0x534E
f ioreg.ADC1_TRIGR2=0x534F
f ioreg.ADC1_TRIGR3=0x5350
f ioreg.ADC1_TRIGR4=0x5351
#RI
f ioreg.RI_ICR1=0x5431
f ioreg.RI_ICR2=0x5432
f ioreg.RI_IOIR1=0x5433
f ioreg.RI_IOIR2=0x5434
f ioreg.RI_IOIR3=0x5435
f ioreg.RI_IOCMR1=0x5436
f ioreg.RI_IOCMR2=0x5437
f ioreg.RI_IOCMR3=0x5438
f ioreg.RI_IOSR1=0x5439
f ioreg.RI_IOSR2=0x543A
f ioreg.RI_IOSR3=0x543B
f ioreg.RI_IOGCR=0x543C
f ioreg.RI_ASCR1=0x543D
f ioreg.RI_ASCR2=0x543E
f ioreg.RI_RCR=0x543F
#COMP1/2
f ioreg.COMP_CSR1=0x5440
f ioreg.COMP_CSR2=0x5441
f ioreg.COMP_CSR3=0x5442
f ioreg.COMP_CSR4=0x5443
f ioreg.COMP_CSR5=0x5444
#RI - continuare!
f ioreg.RI_CR=0x5450
f ioreg.RI_MASKR1=0x5451
f ioreg.RI_MASKR2=0x5452
f ioreg.RI_MASKR3=0x5453
f ioreg.RI_MASKR4=0x5454
f ioreg.RI_IOIR4=0x5455
f ioreg.RI_IOCMR4=0x5456
f ioreg.RI_IOSR4=0x5457
#CPU
f ioreg.A=0x7F00
f ioreg.PCE=0x7F01
f ioreg.PCH=0x7F02
f ioreg.PCL=0x7F03
f ioreg.XH=0x7F04
f ioreg.XL=0x7F05
f ioreg.YH=0x7F06
f ioreg.YL=0x7F07
f ioreg.SPH=0x7F08
f ioreg.SPL=0x7F09
f ioreg.CCR=0x7F0A
#CFG
f ioreg.CFG_GCR=0x7F60
#ITC-SPR
f ioreg.ITC_SPR1=0x7F70
f ioreg.ITC_SPR2=0x7F71
f ioreg.ITC_SPR3=0x7F72
f ioreg.ITC_SPR4=0x7F73
f ioreg.ITC_SPR5=0x7F74
f ioreg.ITC_SPR6=0x7F75
f ioreg.ITC_SPR7=0x7F76
f ioreg.ITC_SPR8=0x7F77
# SWIM
f ioreg.SWIM_CSR=0x7F80
# DM
f ioreg.DM_BK1RE=0x7F90
f ioreg.DM_BK1RH=0x7F91
f ioreg.DM_BK1RL=0x7F92
f ioreg.DM_BK2RE=0x7F93
f ioreg.DM_BK2RH=0x7F94
f ioreg.DM_BK2RL=0x7F95
f ioreg.DM_CR1=0x7F96
f ioreg.DM_CR2=0x7F97
f ioreg.DM_CSR1=0x7F98
f ioreg.DM_CSR2=0x7F99
f ioreg.DM_ENFCTR=0x7F9A

View File

@ -24,6 +24,7 @@ r_arch_sources = [
'p/ppc/gnu/ppc-dis.c',
'p/ppc/gnu/ppc-opc.c',
'p/ppc/libvle/vle.c',
'p/stm8/plugin.c',
'p/ppc/libps/libps.c',
'p/ppc_cs/plugin.c',
'p/null/plugin.c',

9
libr/arch/p/stm8.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_STM8=p/stm8/plugin.o
STATIC_OBJ+=$(OBJ_STM8)
TARGET_STM8=arch_stm8.$(EXT_SO)
ALL_TARGETS+=$(TARGET_STM8)
$(TARGET_STM8): $(OBJ_STM8)
$(CC) $(call libname,arch_stm8) $(LDFLAGS) $(CFLAGS) -o arch_stm8.$(EXT_SO) $(OBJ_STM8)

View File

@ -0,0 +1 @@
GPL code from https://github.com/volbus/gmtdisas

View File

@ -0,0 +1,362 @@
// Evolved from https://github.com/volbus/gmtdisas
#include <r_util.h>
#include "ins.inc.c"
typedef struct {
uint32_t start_add;
uint32_t ext_offset;
uint32_t size;
uint32_t line_index;
unsigned char *data;
} datablock;
char *stm8_disasm(ut64 pc, const ut8 *data, int size, unsigned int *type, ut64 *jump, int *len) {
datablock _block = {
.start_add = pc,
.ext_offset = 0,
.size = size,
.line_index = 0,
.data = data
};
datablock *block = &_block;
RStrBuf *sb = r_strbuf_new ("");
int cnt, n, add, err;
instruction ins;
int oc[6];
cnt = 0;
add = block->start_add;
while (cnt < block->size) {
oc[0] = *(block->data + cnt);
oc[1] = -1;
oc[2] = -1;
oc[3] = -1;
oc[4] = -1;
oc[5] = -1;
err = 0;
n = 1;
switch (oc[0]) {
case 0x72:
oc[1] = *(block->data + cnt + 1);
ins = ins_table_72[oc[1]];
n = 2;
break;
case 0x90:
oc[1] = *(block->data + cnt + 1);
ins = ins_table_90[oc[1]];
n = 2;
break;
case 0x91:
oc[1] = *(block->data + cnt + 1);
if ((oc[1] >= 0x60) && (oc[1] <= 0xDF)) {
ins = ins_table_91_0x60[oc[1] - 0x60];
} else {
err = 1;
}
n = 2;
break;
case 0x92:
oc[1] = *(block->data + cnt + 1);
if ((oc[1] >= 0x30) && (oc[1] <= 0xDF)) {
ins = ins_table_92_0x30[oc[1] - 0x30];
} else {
err = 1;
}
n = 2;
break;
default:
oc[1] = oc[0];
oc[0] = -1;
ins = ins_table[oc[1]];
}
if (err || !ins.size) {
*len = 0;
return NULL;
r_strbuf_appendf (sb, ".byte 0x%02x", oc[1]);
ins.size = 1;
} else {
if (ins.type) {
*type = ins.type;
}
r_strbuf_appendf (sb, "%s", ins.text);
if (n == 1) {
for (; n < ins.size; n++)
oc[n+1] = *(block->data + cnt + n);
} else {
for (; n < ins.size; n++)
oc[n] = *(block->data + cnt + n);
}
switch (ins.des) {
case STM8_NONE:
break;
case STM8_REG_A:
r_strbuf_append (sb, " a");
break;
case STM8_REG_XL:
r_strbuf_append (sb, " xl");
break;
case STM8_REG_YL:
r_strbuf_append (sb, " yl");
break;
case STM8_REG_XH:
r_strbuf_append (sb, " xh");
break;
case STM8_REG_YH:
r_strbuf_append (sb, " yh");
break;
case STM8_REG_CC:
r_strbuf_append (sb, " cc");
break;
case STM8_REG_X:
r_strbuf_append (sb, " x");
break;
case STM8_REG_Y:
r_strbuf_append (sb, " y");
break;
case STM8_REG_SP:
r_strbuf_append (sb, " sp");
break;
case STM8_IMM_BYTE_2:
r_strbuf_appendf (sb, " 0x%02x", oc[2]);
break;
case STM8_IMM_WORD_23:
r_strbuf_appendf (sb, " 0x%02x%02x", oc[2], oc[3]);
break;
case STM8_PTR_X:
r_strbuf_append (sb, " (x)");
break;
case STM8_PTR_Y:
r_strbuf_append (sb, " (y)");
break;
case SHORTMEM_2:
r_strbuf_appendf (sb, " 0x%02x", oc[2]);
break;
case SHORTMEM_3:
r_strbuf_appendf (sb, " 0x%02x", oc[3]);
break;
case LONGMEM_23:
// ioreg
r_strbuf_appendf (sb, " 0x%02x%02x", oc[2], oc[3]);
*jump = (oc[2] <<8) | oc[3];
break;
case LONGMEM_34:
// ioreg
r_strbuf_appendf (sb, " 0x%02x%02x", oc[3], oc[4]);
break;
case LONGMEM_45:
// ioreg
r_strbuf_appendf (sb, " 0x%02x%02x", oc[4], oc[5]);
break;
case EXTMEM_234:
r_strbuf_appendf (sb, " 0x%02x%02x%02x", oc[2], oc[3], oc[4]);
break;
case SHORTOFF_2:
(oc[2] & 0x80) ? (n = oc[2] - 0x100) : (n = oc[2]);
#if 0
r_strbuf_appendf (sb, " .%+-4i ;(0x%06X)",
(prog_mode & PROG_MODE_REL0) ? (n+ins.size) : n,
add + ins.size + n);
#else
r_strbuf_appendf (sb, " 0x%08x", add + ins.size + n);
#endif
*jump = add + ins.size + n;
break;
case SHORTOFF_4:
(oc[4] & 0x80) ? (n = oc[4] - 0x100) : (n = oc[4]);
#if 0
r_strbuf_appendf (sb, " .%+-4i ;(0x%06X)",
(prog_mode & PROG_MODE_REL0) ? (n+ins.size) : n,
add + ins.size + n);
#else
r_strbuf_appendf (sb, " 0x%08x", add + ins.size + n);
#endif
*jump = add + ins.size + n;
break;
case SHORTOFF_X_2:
r_strbuf_appendf (sb, " (0x%02x, x)", oc[2]);
break;
case SHORTOFF_Y_2:
r_strbuf_appendf (sb, " (0x%02x, y)", oc[2]);
break;
case SHORTOFF_SP_2:
r_strbuf_appendf (sb, " (0x%02x, sp)", oc[2]);
break;
case LONGOFF_X_23:
r_strbuf_appendf (sb, " (0x%02x%02x, x)", oc[2], oc[3]);
break;
case LONGOFF_Y_23:
r_strbuf_appendf (sb, " (0x%02x%02x, y)", oc[2], oc[3]);
break;
case EXTOFF_X_234:
r_strbuf_appendf (sb, " (0x%02x%02x%02x, x)", oc[2], oc[3], oc[4]);
break;
case EXTOFF_Y_234:
r_strbuf_appendf (sb, " (0x%02x%02x%02x, y)", oc[2], oc[3], oc[4]);
break;
case SHORTPTR_2:
r_strbuf_appendf (sb, " [0x%02x]", oc[2]);
break;
case LONGPTR_23:
r_strbuf_appendf (sb, " [0x%02x%02x]", oc[2], oc[3]);
break;
case SHORTPTR_OFF_X_2:
r_strbuf_appendf (sb, " ([0x%02x], x)", oc[2]);
break;
case SHORTPTR_OFF_Y_2:
r_strbuf_appendf (sb, " ([0x%02x], y)", oc[2]);
break;
case LONGPTR_OFF_X_23:
r_strbuf_appendf (sb, " ([0x%02x%02x], x)", oc[2], oc[3]);
break;
case LONGPTR_OFF_Y_23:
r_strbuf_appendf (sb, " ([0x%02x%02x], y)", oc[2], oc[3]);
break;
case LONGMEM_BIT_123:
// ioreg
r_strbuf_appendf (sb, " 0x%02x%02x", oc[2], oc[3]);
r_strbuf_appendf (sb, ", %d", (oc[1] & 0x0F)>>1);
break;
}
switch (ins.src) {
case STM8_NONE:
break;
case STM8_REG_A:
r_strbuf_append (sb, ", a");
break;
case STM8_REG_XL:
r_strbuf_append (sb, ", xl");
break;
case STM8_REG_YL:
r_strbuf_append (sb, ", yl");
break;
case STM8_REG_XH:
r_strbuf_append (sb, ", xh");
break;
case STM8_REG_YH:
r_strbuf_append (sb, ", yh");
break;
case STM8_REG_CC:
r_strbuf_append (sb, ", cc");
break;
case STM8_REG_X:
r_strbuf_append (sb, ", x");
break;
case STM8_REG_Y:
r_strbuf_append (sb, ", y");
break;
case STM8_REG_SP:
r_strbuf_append (sb, ", sp");
break;
case STM8_IMM_BYTE_2:
r_strbuf_appendf (sb, ", 0x%02x", oc[2]);
break;
case STM8_IMM_WORD_23:
r_strbuf_appendf (sb, ", 0x%02x%02x", oc[2], oc[3]);
break;
case STM8_PTR_X:
r_strbuf_append (sb, ", (x)");
break;
case STM8_PTR_Y:
r_strbuf_append (sb, ", (y)");
break;
case SHORTMEM_2:
r_strbuf_appendf (sb, ", 0x%02x", oc[2]);
break;
case SHORTMEM_3:
r_strbuf_appendf (sb, ", 0x%02x", oc[3]);
break;
case LONGMEM_23:
r_strbuf_appendf (sb, ", 0x%02x%02x", oc[2], oc[3]);
break;
case LONGMEM_34:
// ioreg
r_strbuf_appendf (sb, ", 0x%02x%02x", oc[3], oc[4]);
break;
case LONGMEM_45:
// ioreg
r_strbuf_appendf (sb, ", 0x%02x%02x", oc[4], oc[5]);
break;
case EXTMEM_234:
r_strbuf_appendf (sb, ", 0x%02x%02x%02x", oc[2], oc[3], oc[4]);
break;
case SHORTOFF_2:
(oc[2] & 0x80) ? (n = oc[2] - 0x100) : (n = oc[2]);
#if 0
r_strbuf_appendf (sb, ", .%+-4i ;(0x%06X)",
(prog_mode & PROG_MODE_REL0) ? (n+ins.size) : n,
add + ins.size + n);
#else
r_strbuf_appendf (sb, ", 0x%08x", add + ins.size + n);
#endif
*jump = add + ins.size + n;
break;
case SHORTOFF_4:
(oc[4] & 0x80) ? (n = oc[4] - 0x100) : (n = oc[4]);
#if 0
r_strbuf_appendf (sb, ", .%+-4i ;(0x%06X)",
(prog_mode & PROG_MODE_REL0) ? (n+ins.size) : n,
add + ins.size + n);
#else
r_strbuf_appendf (sb, ", 0x%08x", add + ins.size + n);
#endif
*jump = add + ins.size + n;
break;
case SHORTOFF_X_2:
r_strbuf_appendf (sb, ", (0x%02x, x)", oc[2]);
break;
case SHORTOFF_Y_2:
r_strbuf_appendf (sb, ", (0x%02x, y)", oc[2]);
break;
case SHORTOFF_SP_2:
r_strbuf_appendf (sb, ", (0x%02x, sp)", oc[2]);
break;
case LONGOFF_X_23:
r_strbuf_appendf (sb, ", (0x%02x%02x, x)", oc[2], oc[3]);
break;
case LONGOFF_Y_23:
r_strbuf_appendf (sb, ", (0x%02x%02x, y)", oc[2], oc[3]);
break;
case EXTOFF_X_234:
r_strbuf_appendf (sb, ", (0x%02x%02x%02x, x)", oc[2], oc[3], oc[4]);
break;
case EXTOFF_Y_234:
r_strbuf_appendf (sb, ", (0x%02x%02x%02x, y)", oc[2], oc[3], oc[4]);
break;
case SHORTPTR_2:
r_strbuf_appendf (sb, ", [0x%02x]", oc[2]);
break;
case LONGPTR_23:
r_strbuf_appendf (sb, ", [0x%02x%02x]", oc[2], oc[3]);
break;
case SHORTPTR_OFF_X_2:
r_strbuf_appendf (sb, ", ([0x%02x], x)", oc[2]);
break;
case SHORTPTR_OFF_Y_2:
r_strbuf_appendf (sb, ", ([0x%02x], y)", oc[2]);
break;
case LONGPTR_OFF_X_23:
r_strbuf_appendf (sb, ", ([0x%02x%02x], x)", oc[2], oc[3]);
break;
case LONGPTR_OFF_Y_23:
r_strbuf_appendf (sb, ", ([0x%02x%02x], y)", oc[2], oc[3]);
break;
case LONGMEM_BIT_123:
// ioreg
r_strbuf_appendf (sb, ", 0x%02x%02x", oc[2], oc[3]);
r_strbuf_appendf (sb, ", %d", (oc[1] & 0x0F)>>1);
break;
}
}
cnt += ins.size;
add += ins.size;
break;
}
*len = cnt;
return r_strbuf_drain (sb);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,479 @@
# -------------------------------------------------------------------
# GPIOR bit definitions
# -------------------------------------------------------------------
# FLASH_CR1 bits
f ioreg.FLASH_CR1_IE_bp=1
f ioreg.FLASH_CR1_FIX_bp=0
# FLASH_CR2 bits
f ioreg.FLASH_CR2_OPT_bp=7
f ioreg.FLASH_CR2_WPRG_bp=6
f ioreg.FLASH_CR2_ERASE_bp=5
f ioreg.FLASH_CR2_FPRG_bp=4
f ioreg.FLASH_CR2_PRG_bp=0
# FLASH_IAPSR bits
f ioreg.FLASH_IAPSR_DUL_bp=3
f ioreg.FLASH_IAPSR_EOP_bp=2
f ioreg.FLASH_IAPSR_PUL_bp=1
f ioreg.FLASH_IAPSR_WR_PG_DIS_bp=0
# CLK_CKDIVR bits
f ioreg.CLK_CKDIVR_CKM0_bp=0
f ioreg.CLK_CKDIVR_CKM1_bp=1
f ioreg.CLK_CKDIVR_CKM2_bp=2
f ioreg.CLK_CKDIVR_CKM_DIV1_gc=0x00
f ioreg.CLK_CKDIVR_CKM_DIV2_gc=0x01
f ioreg.CLK_CKDIVR_CKM_DIV4_gc=0x02
f ioreg.CLK_CKDIVR_CKM_DIV8_gc=0x03
f ioreg.CLK_CKDIVR_CKM_DIV16_gc=0x04
f ioreg.CLK_CKDIVR_CKM_DIV32_gc=0x05
f ioreg.CLK_CKDIVR_CKM_DIV64_gc=0x06
f ioreg.CLK_CKDIVR_CKM_DIV128_gc=0x07
# CLK_PCKENR1 bits
f ioreg.CLK_PCKENR1_TIM2_bp=0
f ioreg.CLK_PCKENR1_TIM3_bp=1
f ioreg.CLK_PCKENR1_TIM4_bp=2
f ioreg.CLK_PCKENR1_I2C1_bp=3
f ioreg.CLK_PCKENR1_SPI1_bp=4
f ioreg.CLK_PCKENR1_USART1_bp=5
f ioreg.CLK_PCKENR1_BEEP_bp=6
f ioreg.CLK_PCKENR1_DAC_bp=7
#CLK_PCKENR2 bits
f ioreg.CLK_PCKENR2_ADC1_bp=0
f ioreg.CLK_PCKENR2_TIM1_bp=1
f ioreg.CLK_PCKENR2_RTC_bp=2
f ioreg.CLK_PCKENR2_LCD_bp=3
f ioreg.CLK_PCKENR2_DMA1_bp=4
f ioreg.CLK_PCKENR2_COMP_bp=5
f ioreg.CLK_PCKENR2_BOOTROM_bp=7
# CLK_PCKENR3 bits
f ioreg.CLK_PCKENR3_AES_bp=0
f ioreg.CLK_PCKENR3_TIM5_bp=1
f ioreg.CLK_PCKENR3_SPI2_bp=2
f ioreg.CLK_PCKENR3_USART2_bp=3
f ioreg.CLK_PCKENR3_USART3_bp=4
f ioreg.CLK_PCKENR3_CSS_LSE_bp=5
# SPI_CR1 bits
f ioreg.SPI_CR1_LSBFIRST_bp=7
f ioreg.SPI_CR1_SPE_bp=6
f ioreg.SPI_CR1_BR2_bp=5
f ioreg.SPI_CR1_BR1_bp=4
f ioreg.SPI_CR1_BR0_bp=3
f ioreg.SPI_CR1_MSTR_bp=2
f ioreg.SPI_CR1_CPOL_bp=1
f ioreg.SPI_CR1_CPHA_bp=0
# SPI_CR2 bits
f ioreg.SPI_CR2_BDM_bp=7
f ioreg.SPI_CR2_BDOE_bp=6
f ioreg.SPI_CR2_RXONLY_bp=2
f ioreg.SPI_CR2_SSM_bp=1
f ioreg.SPI_CR2_SSI_bp=0
# SPI_ICR bits
f ioreg.SPI_ICR_TXIE_bp=7
f ioreg.SPI_ICR_RXIE_bp=6
f ioreg.SPI_ICR_ERRIE_bp=5
f ioreg.SPI_ICR_WKIE_bp=4
# SPI_SR bits
f ioreg.SPI_SR_BSY_bp=7
f ioreg.SPI_SR_OVR_bp=6
f ioreg.SPI_SR_MODF_bp=5
f ioreg.SPI_SR_WKUP_bp=3
f ioreg.SPI_SR_TXE_bp=1
f ioreg.SPI_SR_RXNE_bp=0
# USART_CR1 bits
f ioreg.USART_CR1_R8_bp=7
f ioreg.USART_CR1_T8_bp=6
f ioreg.USART_CR1_UARTD_bp=5
f ioreg.USART_CR1_M_bp=4
f ioreg.USART_CR1_WAKE_bp=3
f ioreg.USART_CR1_PCEN_bp=2
f ioreg.USART_CR1_PS_bp=1
f ioreg.USART_CR1_PIEN_bp=0
# USART_CR2 bits
f ioreg.USART_CR2_TIEN_bp=7
f ioreg.USART_CR2_TCIEN_bp=6
f ioreg.USART_CR2_RIEN_bp=5
f ioreg.USART_CR2_ILIEN_bp=4
f ioreg.USART_CR2_TEN_bp=3
f ioreg.USART_CR2_REN_bp=2
f ioreg.USART_CR2_RWU_bp=1
f ioreg.USART_CR2_SBK_bp=0
# USART_CR3 bits
f ioreg.USART_CR3_LINEN_bp=6
f ioreg.USART_CR3_STOP2_bp=5
f ioreg.USART_CR3_STOP1_bp=4
f ioreg.USART_CR3_CLKEN_bp=3
f ioreg.USART_CR3_CPOL_bp=2
f ioreg.USART_CR3_CPHA_bp=1
f ioreg.USART_CR3_LBCL_bp=0
# USART_SR bits
f ioreg.USART_SR_TXE_bp=7
f ioreg.USART_SR_TC_bp=6
f ioreg.USART_SR_RXNE_bp=5
f ioreg.USART_SR_IDLE_bp=4
f ioreg.USART_SR_OR_bp=3
f ioreg.USART_SR_NF_bp=2
f ioreg.USART_SR_FE_bp=1
f ioreg.USART_SR_PE_bp=0
# TIM_IER bits
f ioreg.TIM_IER_BIE_bp=7
f ioreg.TIM_IER_TIE_bp=6
f ioreg.TIM_IER_COMIE_bp=5
f ioreg.TIM_IER_CC4IE_bp=4
f ioreg.TIM_IER_CC3IE_bp=3
f ioreg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ioreg.I2C_SR2_OVR_bp=3
f ioreg.I2C_SR2_PECERR_bp=4
f ioreg.I2C_SR2_WURF_bp=5
f ioreg.I2C_SR2_TIMEOUT_bp=6
f ioreg.I2C_SR2_SMBALERT_bp=7
# I2C_SR3
f ioreg.I2C_SR3_MSL_bp=0
f ioreg.I2C_SR3_BUSY_bp=1
f ioreg.I2C_SR3_TRA_bp=2
f ioreg.I2C_SR3_GENCALL_bp=4
f ioreg.I2C_SR3_SMBDEFAULT_bp=5
f ioreg.I2C_SR3_SMBHOST_bp=6
f ioreg.I2C_SR3_DUALF_bp=7
# DMA_GCSR
f ioreg.DMA_GCSR_GEN_bp=0
f ioreg.DMA_GCSR_GP_bp=1
f ioreg.DMA_GCSR_TO_bp=2
# DMA_GIR1
f ioreg.DMA_GIR1_IFC0_bp=0
f ioreg.DMA_GIR1_IFC1_bp=1
f ioreg.DMA_GIR1_IFC2_bp=2
f ioreg.DMA_GIR1_IFC3_bp=3
# DMA_CCR
f ioreg.DMA_CCR_EN_bp=0
f ioreg.DMA_CCR_TCIE_bp=1
f ioreg.DMA_CCR_HTIE_bp=2
f ioreg.DMA_CCR_DIR_bp=3
f ioreg.DMA_CCR_CIRC_bp=4
f ioreg.DMA_CCR_MINCDEC_bp=5
f ioreg.DMA_CCR_MEM_bp=6
# DMA_CxSPR
f ioreg.DMA_CSPR_TCIF_bp=1
f ioreg.DMA_CSPR_HTIF_bp=2
f ioreg.DMA_CSPR_TSIZE_bp=3
f ioreg.DMA_CSPR_PL0_bp=4
f ioreg.DMA_CSPR_PL1_bp=5
f ioreg.DMA_CSPR_PEND_bp=6
f ioreg.DMA_CSPR_BUSY_bp=7
# ADC_CR1
f ioreg.ADC_CR1_ADON_bp=0
f ioreg.ADC_CR1_START_bp=1
f ioreg.ADC_CR1_CONT_bp=2
f ioreg.ADC_CR1_EOCIE_bp=3
f ioreg.ADC_CR1_AWDIE_bp=4
f ioreg.ADC_CR1_RES0_bp=5
f ioreg.ADC_CR1_RES1_bp=6
f ioreg.ADC_CR1_OVERIE_bp=7
f ioreg.ADC_CR1_ADON_START_CONT_gc=0x07
# ADC_CR2
f ioreg.ADC_CR2_SMTP0_bp=0
f ioreg.ADC_CR2_SMTP1_bp=1
f ioreg.ADC_CR2_SMTP2_bp=2
f ioreg.ADC_CR2_EXTSEL0_bp=3
f ioreg.ADC_CR2_EXTSEL1_bp=4
f ioreg.ADC_CR2_TRIG_EDGE0_bp=5
f ioreg.ADC_CR2_TRIG_EDGE1_bp=6
f ioreg.ADC_CR2_PRESC_bp=7
# ADC_SQR1
f ioreg.ADC_SQR1_CHSEL_SVREFINT_bp=4
f ioreg.ADC_SQR1_CHSEL_STS_bp=5
f ioreg.ADC_SQR1_DMAOFF_bp=7
# ADC_TRIG1
f ioreg.ADC_TRIG1_VREFINTON_bp=4
# TIM_CCMR1/2
# output
f ioreg.TIM_CCMR_CCS0_bp=0
f ioreg.TIM_CCMR_CCS1_bp=1
f ioreg.TIM_CCMR_OCFE_bp=2
f ioreg.TIM_CCMR_OCPE_bp=3
f ioreg.TIM_CCMR_OCM0_bp=4
f ioreg.TIM_CCMR_OCM1_bp=5
f ioreg.TIM_CCMR_OCM2_bp=6
f ioreg.TIM_CCMR_OCM_SET_gc=0x10
f ioreg.TIM_CCMR_OCM_RES_gc=0x20
f ioreg.TIM_CCMR_OCM_TGL_gc=0x30
f ioreg.TIM_CCMR_OCM_LOW_gc=0x40
f ioreg.TIM_CCMR_OCM_HIGH_gc=0x50
f ioreg.TIM_CCMR_OCM_PWM1_gc=0x60
f ioreg.TIM_CCMR_OCM_PWM2_gc=0x70
# input
f ioreg.TIM_CCMR_ICPSC_bp=2
f ioreg.TIM_CCMR_ICPSC_bp=3
f ioreg.TIM_CCMR_ICF0_bp=4
f ioreg.TIM_CCMR_ICF1_bp=5
f ioreg.TIM_CCMR_ICF2_bp=6
f ioreg.TIM_CCMR_ICF3_bp=7
# TIM_CCER1
f ioreg.TIM_CCER1_CC1E_bp=0
f ioreg.TIM_CCER1_CC1P_bp=1
f ioreg.TIM_CCER1_CC2E_bp=4
f ioreg.TIM_CCER1_CC2P_bp=5
# TIM_BKR
f ioreg.TIM_BKR_LOCK0_bp=0
f ioreg.TIM_BKR_LOCK1_bp=1
f ioreg.TIM_BKR_OSSI_bp=2
f ioreg.TIM_BKR_BKE_bp=4
f ioreg.TIM_BKR_BKP_bp=5
f ioreg.TIM_BKR_AOE_bp=6
f ioreg.TIM_BKR_MOE_bp=7
# ADC_SR
f ioreg.ADC_SR_EOC_bp=0
f ioreg.ADC_SR_AWD_bp=1
f ioreg.ADC_SR_OVER_bp=2
# CLK_SWCR
f ioreg.CLK_SWCR_SWBSY_bp=0
f ioreg.CLK_SWCR_SWEN_bp=1
f ioreg.CLK_SWCR_SWIEN_bp=2
f ioreg.CLK_SWCR_SWIF_bp=3
# CLK_SWR
f ioreg.CLK_SWR_HSI_gc=0x01
f ioreg.CLK_SWR_LSI_gc=0x02
f ioreg.CLK_SWR_HSE_gc=0x04
f ioreg.CLK_SWR_LSE_gc=0x08
# CLK_ICKCR
f ioreg.CLK_ICKCR_HSION_bp=0
f ioreg.CLK_ICKCR_HSIRDY_bp=1
f ioreg.CLK_ICKCR_LSION_bp=2
f ioreg.CLK_ICKCR_LSIRDY_bp=3
f ioreg.CLK_ICKCR_SAHALT_bp=4
f ioreg.CLK_ICKCR_FHWU_bp=5
f ioreg.CLK_ICKCR_BEEPAHALT_bp=6
# CLK_CRTCR
f ioreg.CLK_CRTCR_DIV_1_gc=0x00
f ioreg.CLK_CRTCR_DIV_2_gc=0x20
f ioreg.CLK_CRTCR_DIV_4_gc=0x40
f ioreg.CLK_CRTCR_DIV_8_gc=0x60
f ioreg.CLK_CRTCR_DIV_16_gc=0x80
f ioreg.CLK_CRTCR_DIV_32_gc=0xA0
f ioreg.CLK_CRTCR_DIV_64_gc=0xC0
f ioreg.CLK_CRTCR_DIV_128_gc=0xE0
f ioreg.CLK_CRTCR_SEL_NONE_gc=0x00
f ioreg.CLK_CRTCR_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ST_SR_IWDGF_bp=1
f ioreg.RST_SR_ILLOPF_bp=2
f ioreg.RST_SR_SWIMF_bp=3
f ioreg.RST_SR_WWDGF_bp=4
f ioreg.RST_SR_BORF_bp=5
# PWR_CSR1
f ioreg.PWR_CSR1_PVDE_bp=0
f ioreg.PWR_CSR1_PLS_0=1
f ioreg.PWR_CSR1_PLS_0=2
f ioreg.PWR_CSR1_PLS_0=3
f ioreg.PWR_CSR1_PVDIEN_bp=4
f ioreg.PWR_CSR1_PVDIF_bp=5
f ioreg.PWR_CSR1_PVDOF_bp=6
f ioreg.PWR_CSR1_PLS_1V85_gc=0x00
f ioreg.PWR_CSR1_PLS_2V05_gc=0x02
f ioreg.PWR_CSR1_PLS_2V26_gc=0x04
f ioreg.PWR_CSR1_PLS_2V45_gc=0x06
f ioreg.PWR_CSR1_PLS_2V65_gc=0x08
f ioreg.PWR_CSR1_PLS_2V85_gc=0x0A
f ioreg.PWR_CSR1_PLS_3V05_gc=0x0C
f ioreg.PWR_CSR1_PLS_IN_gc=0x0E
f ioreg.PWR_CSR1_PLS_gm=0x0E
# TIM_DER
f ioreg.TIM_DER_UDE_bp=0
f ioreg.TIM_DER_CC1DE_bp=1
f ioreg.TIM_DER_CC2DE_bp=2
f ioreg.TIM_DER_CC3DE_bp=3
f ioreg.TIM_DER_CC4DE_bp=4
f ioreg.TIM_DER_COMDE_bp=5
# -------------------------------------------------------------------------------
# Fin

76
libr/arch/p/stm8/plugin.c Normal file
View File

@ -0,0 +1,76 @@
/* radare - LGPL - Copyright 2024 - pancake */
#define R_LOG_ORIGIN "arch.stm8"
#include <r_arch.h>
#include "gmtdisas/asm.c"
static bool stm8_op(RArchSession *as, RAnalOp *op, RAnalOpMask mask) {
int len = 0;
ut64 jump = UT64_MAX;
op->type = R_ANAL_OP_TYPE_ILL;
// op->type = R_ANAL_OP_TYPE_NOP;
op->mnemonic = stm8_disasm (op->addr, op->bytes, op->size, &op->type, &jump, &len);
if (jump != UT64_MAX) {
op->jump = jump;
op->fail = op->addr + len; // not for non-conditional
}
op->size = len;
return op->size;
}
static char *regs(RArchSession *as) {
const char *const p =
"=PC pc\n"
"=SP sp\n"
"=SN x\n"
"=BP r31\n"
"=A0 x\n"
"=A1 y\n"
"=A2 a\n"
"gpr pc .64 0 0\n" // 24bit
"gpr sp .64 8 0\n" // 16bit
"gpr x .16 16 0\n" // 16
"gpr y .16 18 0\n" // 16
"gpr a .8 20 0\n" // 8
"gpr xh .8 16 0\n"
"gpr xl .8 17 0\n"
"gpr yh .8 18 0\n"
"gpr yl .8 19 0\n"
"gpr cc .16 20 0\n"
;
return strdup (p);
}
static int archinfo(RArchSession *as, ut32 q) {
switch (q) {
case R_ARCH_INFO_MAX_OP_SIZE:
return 5;
case R_ARCH_INFO_MIN_OP_SIZE:
return 1;
}
return 1; /* :D */
}
const RArchPlugin r_arch_plugin_stm8 = {
.meta = {
.name = "stm8",
.desc = "STM8 microprocessor",
.author = "pancake",
.license = "GPL3",
},
.arch = "stm8",
.info = archinfo,
.bits = R_SYS_BITS_PACK (32),
.endian = R_SYS_ENDIAN_LITTLE,
.decode = &stm8_op,
.regs = &regs,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ARCH,
.data = &r_arch_plugin_stm8,
.version = R2_VERSION
};
#endif

View File

@ -1,6 +1,6 @@
FILES=6502 8051 m68k x86 arc arm avr bpf LH5801 ppc z80 mips sparc sh xtensa
FILES+=i8080 java i4004 dalvik msp430 lm32 s390 tms320 propeller v810 v850
FILES+=pic18c chip8 tricore bf pickle riscv evm sm5xx gb
FILES+=pic18c chip8 tricore bf pickle riscv evm sm5xx gb stm8
F_SDB=$(addsuffix .sdb,${FILES})
SDB=../../../shlr/sdb/sdb

View File

@ -1,7 +1,8 @@
sdb_files = [
'6502',
'8051',
'LH5801',
'LH5801', ## todo lowercase
'stm8',
'arc',
'arm',
'avr',

8
libr/asm/d/stm8.sdb.txt Normal file
View File

@ -0,0 +1,8 @@
srlw=Shift Right Logical Word
srl=Shift Right Logical
sraw=Shift Right Arithmetic Word
sra=Shift Right Arithmetic
sll=Shift Left Logical
sllw=Shift Left Logical Word
exg=Exchange Register Contents
lf=Load Far

View File

@ -7,6 +7,7 @@ r_esil_sources = [
'esil_trace.c',
'esil_toc.c',
'p/esil_null.c',
'p/esil_forth.c',
'p/esil_dummy.c',
]
esil_extra_inc = include_directories('..', '../include')

View File

@ -345,6 +345,7 @@ extern const RArchPlugin r_arch_plugin_x86_cs;
extern const RArchPlugin r_arch_plugin_x86_nasm;
extern const RArchPlugin r_arch_plugin_x86_nz;
extern const RArchPlugin r_arch_plugin_xap;
extern const RArchPlugin r_arch_plugin_stm8;
extern const RArchPlugin r_arch_plugin_xcore_cs;
extern const RArchPlugin r_arch_plugin_xtensa;
extern const RArchPlugin r_arch_plugin_z80;

View File

@ -181,6 +181,7 @@ if get_option('plugins') == ''
arch_plugins += [
'arm_gnu',
'lanai',
'stm8',
'loongarch_gnu',
'm68k_gnu',
'mips_gnu',