程序集:用于自定义操作系统键盘支持的引导加载程序 [英] Assembly: boot loader for custom OS keyboard support

查看:29
本文介绍了程序集:用于自定义操作系统键盘支持的引导加载程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的自定义操作系统(目前没有做太多事情:D).现在我正在使用不支持键盘的程序集文件 (boot.s).

I have a working simple custom OS (doesn't do much for now :D). Right now i'm using an assembly file (boot.s) that has no keyboard support.

汇编文件(boot.s):

The assembly file (boot.s):

# set magic number to 0x1BADB002 to identified by bootloader 
.set MAGIC,    0x1BADB002
# set flags to 0
.set FLAGS,    0
# set the checksum
.set CHECKSUM, -(MAGIC + FLAGS)
# set multiboot enabled
.section .multiboot
# define type to long for each data defined as above
.long MAGIC
.long FLAGS
.long CHECKSUM
# set the stack bottom 
stackBottom:
# define the maximum size of stack to 512 bytes
.skip 512
# set the stack top which grows from higher to lower
stackTop:
.section .text
.global _start
.type _start, @function

_start:
  # assign current stack pointer location to stackTop
    mov $stackTop, %esp
  # call the kernel main source
    call KERNEL_MAIN
    cli
# put system in infinite loop
hltLoop:
    hlt
    jmp hltLoop
.size _start, . - _start

我认为这是缺失的部分,但它是 intel 语法,我无法使用它.

I think this is the missing part but it is in intel syntax and i cannot use it.

load_idt:
mov edx, [esp + 4]
lidt [edx]
sti
ret

read_port:
mov edx, [esp + 4]
in al, dx   
ret

write_port:
mov edx, [esp + 4]    
mov al, [esp + 4 + 4]  
out dx, al  
ret

keyboard_handler:                 
call keyboard_handler
iretd

我正在使用以下命令编译 boot.s:

I'm compiling the boot.s with the following command:

as --32 boot.s -o boot.o

谁能帮我将键盘部分(英特尔语法)翻译成 AT&T?:)

Can anyone help me translating the keyboard part (Intel syntax) to AT&T? :)

推荐答案

有关如何将 NASM Intel 语法转换为 GAS 的 AT&T 语法的信息可以在此 Stackoverflow 答案,此IBM 文章.您的代码将如下所示:

Information on how you can go about translating NASM Intel syntax to GAS's AT&T syntax can be found in this Stackoverflow Answer, and a lot of useful information is provided in this IBM article. Your code in particular would look like:

load_idt:
    mov 4(%esp), %edx
    lidt (%edx)
    sti
    ret

read_port:
    mov 4(%esp), %edx
    in %dx, %al
    ret

write_port:
    mov 4(%esp), %edx
    mov 8(%esp), %al
    out %al, %dx
    ret

keyboard_handler:                 
    call keyboard_handler
    iret

总的来说,最大的区别是:

In general the biggest differences are:

  • 对于 AT&T 语法,源在左侧,目的地在右侧,而英特尔则相反.
  • 使用 AT&T 语法的寄存器名称前面带有 %
  • 在 AT&T 语法中,立即数前面带有 $
  • 内存操作数可能是最大的区别.NASM 使用 [segment:disp+base+index*scale] 而不是 GAS 的 segment:disp(base, index, scale) 语法.
  • With AT&T syntax the source is on the left and destination is on the right and Intel is the reverse.
  • With AT&T syntax register names are prepended with a %
  • With AT&T syntax immediate values are prepended with a $
  • Memory operands are probably the biggest difference. NASM uses [segment:disp+base+index*scale] instead of GAS's syntax of segment:disp(base, index, scale).

我建议将堆栈从多重引导部分移到 .bss 部分.BSS 部分通常不会占用输出可执行文件中的空间(假设使用的是正常或默认的链接器脚本).可以在 .text 部分之后以这种方式定义堆栈:

I recommend moving the stack out of the multiboot section into the .bss section. The BSS section doesn't generally take up space in the output executable (assuming one is using a sane or default linker script). The stack could be defined this way after the .text section:

.section .bss
    .lcomm stackBottom 512
stackTop:

这篇关于程序集:用于自定义操作系统键盘支持的引导加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆