mips u-boot如何在汇编中添加调式打印

0,硬件原理图

1,确认串口使用uart0

复制代码
/*
 * UART
 */
#define UART0_IOBASE		0xb8147000	/* Uart0 register base address mapping  */
#define UART0_FREQ		(100000000) /* Serial Clock */ // 100MHz
//#define UART0_FREQ		(CONFIG_OCP_CLOCK_FREQ/8)	/* Serial Clock */ // V6, switch
//#define UART0_FREQ		(CONFIG_OCP_CLOCK_FREQ*12/10)	/* Serial Clock */ // V6, usb otg
//#define UART0_FREQ		6250000 //(CONFIG_OCP_CLOCK_FREQ/4)	/* Serial Clock */ // V7
//#define UART0_FREQ		(CONFIG_OCP_CLOCK_FREQ/4)	/* Serial Clock */ // V7

/* Register offset from UARTx_IOBASE */
#ifdef CONFIG_RTL_8197F_VG
#define UART_RBR                0x00
#define UART_THR                0x00
#else
//#define UART_RBR		0x00
#define UART_RBR		0x24
//#define UART_THR		0x00
#define UART_THR		0x24
#endif
#define UART_IER		0x04
#define UART_IIR		0x08
#define UART_FCR		0x08
#define UART_LCR		0x0C
#define UART_LSR		0x14
#define UART_DLL		0x00
#define UART_DLH		0x04

/* uart LCR register bits */
#define UART_LCR_PEN		0x00000008	/* parity enable bit */
#define UART_LCR_EPS		0X00000010
#define UART_LCR_PARITY		(UART_LCR_PEN | UART_LCR_EPS)
#define UART_LCR_STOP		0x00000004	/* stop bit          */
#define UART_LCR_DLS		0x00000003	/* 8 bits mode       */
#define UART_LCR_DLAB		0x00000080	/* DLAB bit          */


/* Uart baudrate */
#define UART_BAUD_RATEL		(UART_BAUD_DEFAULT & 0x00ff)
#define UART_BAUD_RATEH		((UART_BAUD_DEFAULT & 0xff00) >> 8)
#define UART_IOBASE		UART0_IOBASE

/******************************************************************************
*
* dwc_serial_init - initialize a channel
*
* This routine initializes the number of data bits, parity
* and set the selected baud rate. Interrupts are disabled.
* Set the modem control signals if the option is selected.
*
* RETURNS: N/A
*/

static int dwc_serial_init (void)
{
	REG32(UART_IOBASE+UART_IER) = 0;

	REG32(UART_IOBASE+UART_LCR) = UART_LCR_DLAB;
	REG32(UART_IOBASE+UART_DLL) = UART_BAUD_RATEL;
	REG32(UART_IOBASE+UART_DLH) = UART_BAUD_RATEH;
//REG32(UART_IOBASE+0x1C) = 0xA0030; // 57600, 115200
//REG32(UART_IOBASE+0x20) = 0xC0; // 57600, 115200
	REG32(UART_IOBASE+UART_LCR) = UART_LCR_DLS;
	return 0;
}

2,手动测试串口使用情况

手动写A/B/C进行测试

8197F# mw 0xb8147000 0x41

A8197F# mw 0xb8147000 0x42

B8197F# mw 0xb8147000 0x47

G8197F#

测试代码

复制代码
#include "asm/stack_asm.h"

/*
 * 调试开关:定义 DEBUG_UART 可启用调试打印
 */
#define DEBUG_UART

#ifdef DEBUG_UART
/* UART 硬件地址(根据实测,THR 在偏移 0x00) */
#define UART_BASE       0xb8147000
#define UART_LSR_OFF    0x14
#define UART_THR_OFF    0x00

/* 发送一个立即数字符 */
.macro  uart_send_char_imm ch
    li      t0, UART_BASE
    li      t1, \ch
1:
    lw      t2, UART_LSR_OFF(t0)
    andi    t2, t2, 0x20        /* THRE 位 */
    beqz    t2, 1b
    nop
    sw      t1, UART_THR_OFF(t0)
.endm

/* 发送字符串(字符串标签) */
.macro  uart_send_str str
    la      t1, \str
1:
    lb      t2, 0(t1)
    beqz    t2, 2f
    nop
    uart_send_char_imm t2       /* 注意:这里直接使用立即数宏,但 t2 是寄存器,不能这样用! */
    addiu   t1, t1, 1
    b       1b
    nop
2:
.endm

.section .rodata
debug_str1:
    .asciz "test@OsStartToRun\r\n"
#endif /* DEBUG_UART */

    .section ".text", "ax"
    .set noreorder
    .global OsStartToRun
    .global OsTaskSchedule

/*
 * VOID OsStartToRun(LosTaskCB * topTask)
 */
OsStartToRun:
#ifdef DEBUG_UART
    /* 直接打印固定字符串 */
    la      t1, debug_str1
1:
    lb      t2, 0(t1)
    beqz    t2, 2f
    nop
    /* 发送字符 */
    li      t0, UART_BASE
3:
    lw      t3, UART_LSR_OFF(t0)
    andi    t3, t3, 0x20
    beqz    t3, 3b
    nop
    sw      t2, UART_THR_OFF(t0)
    addiu   t1, t1, 1
    b       1b
    nop
2:
#endif

    /* 原有代码 */
    lw      sp, 0(a0)
    RESTORE_ALL
    eret
    nop

可以看到有串口打印test@OsStartToRun

相关推荐
Hi202402174 天前
同一个 NMS 算子,两种语言实现:CUDA C 与 Rust 生成 LLVM IR 和 Vortex 汇编的差异
c语言·汇编·rust·gpgpu·vortex·cudac
lhbweilai4 天前
深挖FreeRTOS内核实现(二)
c语言·汇编·stm32·单片机
水饺编程4 天前
第1章:开发环境搭建,在 Windows 中安装 VS 2019
linux·c语言·汇编·visual studio
水饺编程5 天前
第1章:下载 Linux 0.12 内核
linux·c语言·汇编·ubuntu
水饺编程5 天前
第1章:开发环境搭建,在 Windows 中安装 Git
linux·c语言·汇编·git·ubuntu
水饺编程6 天前
第1章:在 Windows 中安装 GCC 套件
c语言·汇编
水饺编程6 天前
第1章,了解乌班图环境,使用浏览器和邮箱
c语言·汇编·ubuntu
水饺编程6 天前
第1章:开发环境搭建,在 Windows 中安装 QEMU
c语言·汇编
AC赳赳老秦6 天前
OpenClaw 数据引用规范自动生成:为公开数据构建可信来源标注与标准引用体系
大数据·开发语言·汇编·数据库·人工智能·deepseek·openclaw
AC赳赳老秦8 天前
数据采集全链路审计留痕:用 OpenClaw 实现合规审计与追溯
开发语言·汇编·python·php·swift·deepseek·openclaw