我正在尝试开发一个操作系统.设计是这样的:我有一个加载在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) 我有一个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) 我正在尝试编写自己的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) 我有一个简单的调试器(使用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) 这是我的计划:
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) 下面是我在 Commodore 64 上进行内存复制的自我修改例程。
我写了char codes并number 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) 我是 64 位 x86 编码新手,但我运行的是 Ubuntu 14.04(可靠),并且我有一段非常简单的 64 位代码,我使用as进行汇编。我得到的输出具有奇怪的权限和文件类型。
当我跑步时:
as file.s
Run Code Online (Sandbox Code Playgroud)
我得到一个具有 770 权限的文件a.out。
当我执行它时,我得到这个错误:
bash: ./a.out: 无法执行二进制文件: Exec 格式错误
当我跑步时:
file ./a.out
Run Code Online (Sandbox Code Playgroud)
我得到:
./a.out:ELF 64 位 LSB 可重定位,x86-64,版本 1 (SYSV),未剥离
我使用的汇编代码是:
.section .data
.LC0:
.string "/bin/sh"
.LC1:
.string "/bin/sh"
.LC3:
.quad .LC1, 0
.text
.globl _start
_start:
.LFB0:
pushq %rbp
movq %rsp, %rbp
movq $59,%rax # System Call to execve
movq $.LC0, %rdi # Pass program to execute
movq $.LC3, %rsi # Pass command …Run Code Online (Sandbox Code Playgroud) 我是Assembly的新手,下面的代码应该通过两个不同的函数交换两个整数:首先使用swap_c然后再使用swap_asm.
但是,我怀疑,我是否需要push(我的意思是保存)汇编代码之前的每个寄存器值以及pop它们之后(就在返回之前main).换句话说,如果我在运行函数后返回不同的寄存器内容(不是像ebp或者esp只是eax,但是,只是ebx,ecx&edx),CPU会不会生我的气swap_asm?取消组装部件中的线条是否更好?
这段代码对我来说运行正常,我设法将27行汇编C代码减少到7个装配线.
ps:系统是Windows 10,VS-2013 Express.
main.c 部分
#include <stdio.h>
extern void swap_asm(int *x, int *y);
void swap_c(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int main(int argc, char *argv[]) {
int x = 3, y = 5;
printf("before swap => x = %d y = …Run Code Online (Sandbox Code Playgroud) 我正在使用以下服务创建RESTFul Web服务:
@RequestMapping(value = "/test", produces = "application/json", method = RequestMethod.GET)
public ResponseEntity<List<GenericModel>> returnEmpty() {
List<GenericModel> genericModelList = new ArrayList<>();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
return responseEntity = new ResponseEntity<>(genericModelList, headers, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
当空列表返回时,我在浏览器中得到以下响应:
[]
Run Code Online (Sandbox Code Playgroud)
如何在浏览器中收到“空”响应而不是[]?有某种方法可以告诉Spring将列表大小0呈现为“空”而不是[]?
大家晚上好。我刚刚开始学习汇编语言,并且在网上找到了非常好的示例可以遵循。有人建议我使用 NASM 开始学习,但我发现的例子我看到他们使用 8086 汇编器。当我遵循这些示例时,我注意到如果我使用 NASM,它们不会在 Linux 终端上运行,但是如果我安装了 8086 汇编器模拟器,它确实可以工作。
我的问题是:NASM 和 8086 汇编器有什么区别吗?对我来说它们应该是同一件事,因为它是汇编代码。如果没有,有谁可以解释一下两者之间有什么区别吗?以及为什么它们不在 NASM 和 8086 上运行相同的代码
这是我跟踪的代码,它确实在 8086 汇编器上运行,但不在 Linux 上的 NASM 上运行
DATA SEGMENT
NUM1 DB ?
NUM2 DB ?
RESULT DB ?
MSG1 DB 10,13,"ENTER FIRST NUMBER TO ADD : $"
MSG2 DB 10,13,"ENTER SECOND NUMBER TO ADD : $"
MSG3 DB 10,13,"RESULT OF ADDITION IS : $"
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV …Run Code Online (Sandbox Code Playgroud) assembly ×8
x86 ×6
nasm ×3
c ×2
java ×2
osdev ×2
spring ×2
spring-boot ×2
x86-64 ×2
6502 ×1
bios ×1
bootloader ×1
disassembly ×1
emu8086 ×1
gcc ×1
gdb ×1
linux ×1
masm ×1
oauth ×1
rest ×1
ubuntu-14.04 ×1
web-services ×1