小编Mic*_*tch的帖子

加载引导加载程序的第二阶段

我正在尝试为x86机器创建一个小型操作系统,并开始为相当小的引导程序编写代码.我创建的引导加载程序非常简单,它从主引导记录之后的扇区加载一个小的第二个引导加载程序并跳转到该代码.主引导记录中的引导加载程序代码似乎运行正常,当它尝试跳转到第二阶段引导加载程序时会出现问题.这个第二阶段的引导加载程序应该输出一个表示成功的字母(字母S),这样我就能告诉代码正在执行.问题是屏幕上没有出现任何问题,所以我怀疑第二阶段的引导程序从未执行过.我使用的代码如下:

主引导记录中的Bootloader:

[BITS 16] ; 16 bit mode
[ORG 0x7C00] ; Boot loader start address

Boot:
    ; Initial, dl contains drive number
    ; Set data segment to code segment
    mov ax, cs
    mov ds, ax
    mov es, ax
    ; Set the stack segment to 0xA000
    add ax, 0xA000
    mov ss, ax
    mov sp, 0x00
    ; Reset the drive, dl contains drive number
    mov ah, 0x00
    int 0x13
    ; Read from drive, dl contains drive number
    ;     Set up output location …
Run Code Online (Sandbox Code Playgroud)

x86 assembly real-mode nasm bootloader

5
推荐指数
1
解决办法
899
查看次数

如何组装 .asm 文件并将其链接到 Win32 可执行文件?

我有NASM开发-CPP我的系统上安装。Dev-cpp带有LD(GNU 链接器)。我不熟悉汇编代码和从汇编程序文件创建 32 位 Windows 可执行文件的过程。我尝试使用这个:

nasm -f win32 ass.asm
nasm -o ass ass.o
Run Code Online (Sandbox Code Playgroud)

我使用这些命令创建可执行文件没有成功。组装(使用NASM)和链接以生成将在 32 位 Windows 上运行的可执行文件的正确方法是什么?

windows x86 assembly linker nasm

5
推荐指数
1
解决办法
1万
查看次数

无法跳转或调用在0x8000加载的内核

我正在尝试开发一个操作系统.设计是这样的:我有一个加载在0x7c00的引导程序,它加载第二阶段并在0x7e00跳转到它.第二阶段也处于实模式并且执行许多操作,例如加载gdt,启用A20并切换到保护模式.它还在0x8000处加载一个非常简单的32位内核.现在的问题是我无法调用或jmp到0x8000,因为内核似乎没有加载(我在VirtualBox中进行了内存转储).我已经在第二阶段完成了FAR JMP来设置CS寄存器.我在VirtualBox中测试我的操作系统.

我的启动加载程序的代码:

org 0x7c00
bits 16
Start:
      jmp Reset
      bpbOEM DB "SKULLOS " 
      bpbBytesPerSector:    DW 512
      bpbSectorsPerCluster:     DB 1
      bpbReservedSectors:   DW 1
      bpbNumberOfFATs:      DB 2
      bpbRootEntries:       DW 224
      bpbTotalSectors:      DW 2880
      bpbMedia:                 DB 0xF0
      bpbSectorsPerFAT:         DW 9
      bpbSectorsPerTrack:   DW 18
      bpbHeadsPerCylinder:  DW 2
      bpbHiddenSectors:         DD 0
      bpbTotalSectorsBig:     DD 0
      bsDriveNumber:            DB 0
      bsUnused:                 DB 0
      bsExtBootSignature:   DB 0x29
      bsSerialNumber:           DD 0xa0a1a2a3
      bsVolumeLabel:            DB "MOS FLOPPY "
      bsFileSystem:             DB "SKFS    "
Set: …
Run Code Online (Sandbox Code Playgroud)

x86 assembly nasm osdev

5
推荐指数
1
解决办法
507
查看次数

在刷新令牌上找不到AuthenticationProvider - Spring OAuth2 java config

我有一个Spring Boot项目,我在其中配置了一个部分有效的Spring OAuth2身份验证过程.我可以验证确定,但是当我尝试获取刷新令牌时,我得到一个例外.

OAuth配置:

@Configuration
public class OAuth2ServerConfiguration {

    private static final String RESOURCE_ID = "xxx";

    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) {
            resources.resourceId(RESOURCE_ID);
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http
            .authorizeRequests()
            .antMatchers("/api/**").authenticated();
        }
    }

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

        @Value("${clientDetailsService.clientName}")
        private String clientName;

        @Value("${clientDetailsService.clientSecret}")
        private String clientSecret;

        @Autowired
        @Qualifier("authenticationManager")
        private AuthenticationManager authenticationManager;

        @Autowired
        private ClientDetailsService clientDetailsService;

        @Autowired
        @Qualifier("tokenServices")
        private AuthorizationServerTokenServices tokenServices;

        @Autowired
        @Qualifier("codeServices")
        private …
Run Code Online (Sandbox Code Playgroud)

java authentication spring oauth spring-boot

5
推荐指数
2
解决办法
4618
查看次数

Bootloader在真实硬件上打印垃圾

我正在尝试编写自己的bootloader.虽然它在QEMU,Bochs和VirtualBox中运行良好,但我似乎无法在笔记本电脑上运行.

在我的笔记本电脑上,引导加载程序与所有模拟器的行为完全不同,挂起看似随机的地方,拒绝打印,甚至跳过一些jmp $指令.

虽然我对"真实硬件"有很多麻烦,但我认为它们都有一个原因.

以下代码是一个短引导加载程序,应该打印"TEST"消息3次,然后跳转到同一位置挂起:

[BITS 16]                                                                          
[ORG 0x7C00]                                                                                                    
    jmp 0x0000:start_16  ; In case bootloader is at 0x07C0:0x0000                                                             
start_16:                                                                          
    xor ax, ax                                                                 
    mov ds, ax                                                                 
    mov es, ax                                                                 
    cli                             ; Disable interrupts                       
    mov ss, ax                                                                 
    mov sp, 0x7C00                                                             
    sti                             ; Enable interrupts                        
    cld                             ; Clear Direction Flag                     
    ; Store the drive number                                                   
    mov [drive_number], dl                                                     
    ; Print message(s)                                                         
    mov si, msg                                                                
    call print_string                                                          
    mov si, msg                                                                
    call print_string                                                          
    mov si, msg                                                                
    call print_string                                                          

    jmp $   ; HALT                                                                                   

; …
Run Code Online (Sandbox Code Playgroud)

x86 assembly bios osdev bootloader

5
推荐指数
1
解决办法
377
查看次数

执行指令的数量与Hello World程序Nasm Assembly和C不同

我有一个简单的调试器(使用ptrace:http://pastebin.com/D0um3bUi)来计算给定输入可执行程序执行的指令数.它使用ptrace单步执行模式来计算指令.

为此,当程序1)的可执行文件(来自gcc main.c的a.out)作为输入提供给我的测试调试器时,它会在执行指令时打印大约100k.当我使用-static选项时,它会给出10681条指令.

现在在2)我创建一个汇编程序并使用NASM进行编译和链接,然后当这个可执行文件作为测试调试器输入时,它显示8个指令作为计数,哪个是apt.

程序1)中执行的指令数量很高,因为在运行时将程序与系统库链接起来了?使用-static并将计数减少1/10.如何确保指令计数仅是程序1)中主要功能的指令,以及程序2)为调试器报告的方式?

1)

#include <stdio.h>

int main()
{
    printf("Hello, world!\n");
    return 0;
}    
Run Code Online (Sandbox Code Playgroud)

我使用gcc来创建可执行文件.

2)

; 64-bit "Hello World!" in Linux NASM

global _start            ; global entry point export for ld

section .text
_start:

    ; sys_write(stdout, message, length)

    mov    rax, 1        ; sys_write
    mov    rdi, 1        ; stdout
    mov    rsi, message    ; message address
    mov    rdx, length    ; message string length
    syscall

    ; sys_exit(return_code)

    mov    rax, 60        ; sys_exit
    mov    rdi, …
Run Code Online (Sandbox Code Playgroud)

linux assembly gcc x86-64 nasm

5
推荐指数
2
解决办法
1198
查看次数

浪费内存分配局部变量

这是我的计划:

void test_function(int a, int b, int c, int d){
    int flag;
    char buffer[10];

   flag = 31337;
   buffer[0] = 'A';
}

int main() {
    test_function(1, 2, 3, 4);
}
Run Code Online (Sandbox Code Playgroud)

我用debug选项编译这个程序:

gcc -g my_program.c
Run Code Online (Sandbox Code Playgroud)

我使用gdb并使用intel语法反汇编test_function:

(gdb) disassemble test_function
Dump of assembler code for function test_function:
0x08048344 <test_function+0>:   push   ebp
0x08048345 <test_function+1>:   mov    ebp,esp
0x08048347 <test_function+3>:   sub    esp,0x28
0x0804834a <test_function+6>:   mov    DWORD PTR [ebp-12],0x7a69
0x08048351 <test_function+13>:  mov    BYTE PTR [ebp-40],0x41
0x08048355 <test_function+17>:  leave  
0x08048356 <test_function+18>:  ret    
End of assembler dump.
Run Code Online (Sandbox Code Playgroud)

我拆卸了主要的:

(gdb) …
Run Code Online (Sandbox Code Playgroud)

c x86 assembly gdb disassembly

5
推荐指数
1
解决办法
580
查看次数

自修改内存复制例程练习,6502 ASM

下面是我在 Commodore 64 上进行内存复制的自我修改例程。

我写了char codesnumber of repeats在一个表中,充满了screen_ram的这个套路。

我正在寻找优化建议。在这种情况下,我的优先事项是内存。

memCopy:    
  sourceAddress=*+1 ; mark self modifying addrres
fetchNewData:
  lda data_table    ; read char value into A
  ldx data_table+1  ; read repeat value into x
  inc sourceAddress     
  inc sourceAddress 

  cpx #00           ; if X=0 
  beq end           ; finish copying

  destination=*+1
- sta SCREEN_RAM
  inc destination
  dex
  bne -

  jmp fetchNewData

end:
  rts   

; data format:  <char>,<number of repeats>,[<char>,<number of repeats>,...],00,00

data_table: 
!by 01,03,02,02,......,00,00
Run Code Online (Sandbox Code Playgroud)

assembly 6502

5
推荐指数
1
解决办法
879
查看次数

模拟器使用 int21h/ah=09h 显示“在 2000 个字节之后找不到错误字节 24h”

我必须使用EMU8086在汇编中做一个简单的计算器,但每次我尝试启动它时,EMU8086都会出现此错误:

INT 21h, AH=09h - 
address: 170B5
byte 24h not found after 2000 bytes.
; correct example of INT 21h/9h:
mov dx, offset msg
mov ah, 9
int 21h
ret
msg db "Hello$"
Run Code Online (Sandbox Code Playgroud)

我检查了其他东西,但没有错误:

data segment
    choice db ?
    snum1 db 4 dup(?)
    snum2 db 4 dup(?)
    sres db 4 dup(?)
    num1 db ?
    num2 db ?
    res db ?
    ;;menu1 db "Chose a function to procced", 10, 13, "Add [+]", 10, 13, "Sub [-]", 10, …
Run Code Online (Sandbox Code Playgroud)

x86 assembly dos x86-16 emu8086

5
推荐指数
1
解决办法
3589
查看次数

INT 16h/AH=0h 不等待引导加载程序中的按键

我使用 GNU 汇编器和 AT&T 语法编写了我的第一个引导加载程序。它应该打印hello world到屏幕上,然后通知用户按任意键将导致重新启动。只有按下某个键后才会启动重新启动。我的引导加载程序代码不等待按键,并在打印信息后自动重新启动。为什么此代码不等待击键,我该如何修复它?

我的引导扇区代码:

#generate 16-bit code
.code16

#hint the assembler that here is the executable code located
.text
.globl _start;
#boot code entry
_start:
  jmp _boot                           #jump to boot code
  welcome: .asciz "Hello, World\n\r"  #here we define the string
  AnyKey: .asciz "Press any key to reboot...\n\r"
 .macro mWriteString str              #macro which calls a function to print a string
      leaw  \str, %si
      call .writeStringIn
 .endm

 #function to print the string
 .writeStringIn:
      lodsb
      orb  %al, %al …
Run Code Online (Sandbox Code Playgroud)

assembly gnu-assembler bootloader att x86-16

5
推荐指数
1
解决办法
1354
查看次数