无法在汇编代码文件中包含新的头文件。 (Linux ARM64 内核)

huangapple go评论62阅读模式
英文:

Cannot include a new header file from an assembly code file.. (linux arm64 kernel)

问题

I made a small code for debug (see here. I've used similar code previously but this one seems more correct.)
And I wanted to make a macro related to this. It is for writing an arbitrary mark data in a buffer. (Of course I cannot write so many data because this macro doesn't do pointer round down at the boundary).

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm

When I add above code to the beginning of the assembly file, it works just fine.

.... (skip) ....

#include <asm/sysreg.h>
#include <asm/thread_info.h>
#include <asm/virt.h>

.global mydstart
.global myptr
.global mydebug2

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm

#include "efi-header.S"

#define __PHYS_OFFSET   KERNEL_START

I made arch/arm64/include/asm/ckim.h and replace above code to just "#include <asm/ckim.h>".
The ckim.h file is like this.

#ifndef __ASM_ASSEMBLER_H
#define __ASM_ASSEMBLER_H

.global mydstart
.global myptr
.global mydebug2

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm

#endif  /* __ASM_ASSEMBLER_H */

Then when I do 'make', I get this error.

ckim@ckim-ubuntu:~/prj1/LinuxDevDrv/linux-5.15.68$ make
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  CHK     include/generated/compile.h
  AS      arch/arm64/kernel/head.o
arch/arm64/kernel/head.S: Assembler messages:
arch/arm64/kernel/head.S:118: Error: unknown mnemonic 'write_mark' -- 'write_mark 0x4444'
make[2]: *** [scripts/Makefile.build:391: arch/arm64/kernel/head.o] Error 1
make[1]: *** [scripts/Makefile.build:552: arch/arm64/kernel] Error 2
make: *** [Makefile:1898: arch/arm64] Error 2

All other asm/*.h include files are under arch/arm64 so I put the asm/ckim.h under there.
What am I missing?

英文:

I made a small code for debug (see here. I've used similar code previously but this one seems more correct.)
And I wanted to make a macro related to this. It is for writing an arbitrary mark data in a buffer. (Of course I cannot write so many data because this macro doesn't do pointer round down at the boundary).

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm

When I add above code to the beginning of the assembly file, it works just fine.

.... (skip) ....

#include &lt;asm/sysreg.h&gt;
#include &lt;asm/thread_info.h&gt;
#include &lt;asm/virt.h&gt;

.global mydstart
.global myptr
.global mydebug2

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm



#include &quot;efi-header.S&quot;

#define __PHYS_OFFSET   KERNEL_START

I made arch/arm64/include/asm/ckim.h and replace above code to just "#include <asm/ckim.h>".
The ckim.h file is like this.

#ifndef __ASM_ASSEMBLER_H
#define __ASM_ASSEMBLER_H

.global mydstart
.global myptr
.global mydebug2

.macro write_mark, data
mov x27, \data
adr_l x26, myptr
ldr x28, [x26]
str x27, [x28], #8
adr_l x26, myptr
str x28, [x26] // store write pointer at myptr
.endm

#endif  /* __ASM_ASSEMBLER_H */

Then when I do 'make', I get this error.

ckim@ckim-ubuntu:~/prj1/LinuxDevDrv/linux-5.15.68$ make
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  CHK     include/generated/compile.h
  AS      arch/arm64/kernel/head.o
arch/arm64/kernel/head.S: Assembler messages:
arch/arm64/kernel/head.S:118: Error: unknown mnemonic `write_mark&#39; -- `write_mark 0x4444&#39;
make[2]: *** [scripts/Makefile.build:391: arch/arm64/kernel/head.o] Error 1
make[1]: *** [scripts/Makefile.build:552: arch/arm64/kernel] Error 2
make: *** [Makefile:1898: arch/arm64] Error 2

All other asm/*.h include files are under arch/arm64 so I put the asm/ckim.h under there.
What am I missing??

答案1

得分: 1

问题在于你在包含保护中使用了错误的标识符,请使用不同的标识符,例如:

#ifndef __ASM_CKIM_H
#define __ASM_CKIM_H
// ...
#endif

你之前使用的标识符在其他包含文件中已经定义(特别是asm/assembler.h),因此你的头文件将不会包括受保护的代码。

英文:

The problem is that you have a wrong identifier in the include guard, please use something different like:

#ifndef __ASM_CKIM_H
#define __ASM_CKIM_H
// ...
#endif

you were using a identifier that was defined in other include file (in particular asm/assembler.h) and therefore, your header file would not include the guarded code

huangapple
  • 本文由 发表于 2023年4月4日 15:34:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定