ami*_*awi 1 x86 assembly nasm object-files
我正在尝试将程序集文件编译为目标文件。该汇编文件调用 ac 函数。但我遇到这个错误:二进制输出格式不支持外部引用
我在汇编文件第17行调用c函数
我尝试用这个命令编译它:
cpu/interrupt.o: cpu/interrupt.asm
nasm $< -f bin -o $@
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题
[extern isr_handler]
; Common ISR code
isr_common_stub:
; 1. Save CPU state
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; 2. Call C handler
call isr_handler
; 3. Restore state
pop eax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
; We don't get information about which interrupt was caller
; when the handler is run, so we will need to have a different handler
; for every interrupt.
; Furthermore, some interrupts push an error code onto the stack but others
; don't, so we will push a dummy error code for those which don't, so that
; we have a consistent stack for all of them.
; First make the ISRs global
global isr0
global isr1
global isr2
global isr3
global isr4
global isr5
global isr6
global isr7
global isr8
global isr9
global isr10
global isr11
global isr12
global isr13
global isr14
global isr15
global isr16
global isr17
global isr18
global isr19
global isr20
global isr21
global isr22
global isr23
global isr24
global isr25
global isr26
global isr27
global isr28
global isr29
global isr30
global isr31
Run Code Online (Sandbox Code Playgroud)
平面二进制文件没有符号表的元数据;没有地方可以nasm放置链接器的符号名称来填充符号的地址extern。
您想要创建一个.o可以提供给链接器的目标文件 ( ):
nasm -felf32 foo.asm
平面二进制文件实际上只是从 asm 源组装的字节,如 MBR 引导扇区或 DOS.com可执行文件。
如果要将 C 函数链接到最终的平面二进制文件中,可以将 asm 部分组装成.o,然后链接,然后将objcopy生成的可执行文件的文本部分链接到平面二进制文件中。