Thanks, everyone, for the helpful responses.
nullplan wrote:You can use inline assembler on file scope
Thanks, I will try following this example:
https://elixir.bootlin.com/linux/latest ... ioscalls.c
nullplan wrote:Of course the push instructions hurt something. They write to stack before you have the stack set up. Then you change the stack pointer as part of the assembler snippet, which is also not going to work with the compiler long-term. Just use well-defined unchanging interfaces, like the ABI.
I already set the stack pointer while in real mode to the top of a 30KB stack, and this is the first time that stack is getting used. Could VirtualBox be breaking due to the push instructions, even though real hardware works fine?
...
Octocontrabass wrote:What are the contents of GDTR? What are the contents of the GDT that GDTR points to? What are the attributes of the page(s) that map your GDT? What is the current privilege level? Make sure you're checking these values immediately before loading SS
Code: Select all
Bochs connected to screen "/dev/pts/2"
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (no symbol): jmpf 0xf000:e05b ; ea5be000f0
<bochs:1> c
^CNext at t=948344304
(0) [0x00000000c01e] 0008:000000000000c01e (code+1e): jmp .-2 (0x000000000000c01e) ; ebfe
<bochs:2> disasm 0xc000 0xc030
000000000000c000: ( code+0): push r15 ; 4157
000000000000c002: ( code+2): push r14 ; 4156
000000000000c004: ( code+4): push r13 ; 4155
000000000000c006: ( code+6): push r12 ; 4154
000000000000c008: ( code+8): push rbp ; 55
000000000000c009: ( code+9): push rbx ; 53
000000000000c00a: ( code+a): sub rsp, 0x00000000000000d8 ; 4881ecd8000000
000000000000c011: ( code+11): xor rax, rax ; 4831c0
000000000000c014: ( code+14): push rax ; 50
000000000000c015: ( code+15): popf ; 9d
000000000000c016: ( code+16): mov ax, 0x0010 ; 66b81000
000000000000c01a: ( code+1a): mov ds, ax ; 8ed8
000000000000c01c: ( code+1c): mov es, ax ; 8ec0
000000000000c01e: ( code+1e): jmp .-2 (0x000000000000c01e) ; ebfe
000000000000c020: ( code+20): mov ss, ax ; 8ed0
000000000000c022: ( code+22): mov rsp, 0x0000000000007dea ; 48c7c4ea7d0000
000000000000c029: ( code+29): mov fs, ax ; 8ee0
000000000000c02b: ( code+2b): mov gs, ax ; 8ee8
000000000000c02d: ( code+2d): xor eax, eax ; 31c0
000000000000c02f: ( code+2f): xor ebx, ebx ; 31db
<bochs:3> creg
CR0=0xe0040033: PG CD NW AC wp NE ET ts em MP PE
CR2=page fault laddr=0x0000000000000000
CR3=0x000000008000
PCD=page-level cache disable=0
PWT=page-level write-through=0
CR4=0x000007a6: cet pke smap smep osxsave pcid fsgsbase smx vmx OSXMMEXCPT umip OSFXSR PCE PGE mce PAE pse de TSD PVI vme
CR8: 0x0
EFER=0x00000501: ffxsr nxe LMA LME SCE
XCR0=0x00000001: pkru hi_zmm zmm_hi256 opmask bndcfg bndregs ymm sse FPU
<bochs:4> sreg
es:0x0010, dh=0x00009300, dl=0x00000000, valid=1
Data segment, base=0x00000000, limit=0x00000000, Read/Write, Accessed
cs:0x0008, dh=0x00209900, dl=0x00000000, valid=1
Code segment, base=0x00000000, limit=0x00000000, Execute-Only, Non-Conforming, Accessed, 64-bit
ss:0x0002, dh=0x00009300, dl=0x0020ffff, valid=7
Data segment, base=0x00000020, limit=0x0000ffff, Read/Write, Accessed
ds:0x0010, dh=0x00009300, dl=0x00000000, valid=1
Data segment, base=0x00000000, limit=0x00000000, Read/Write, Accessed
fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=1
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=1
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=1
tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=1
gdtr:base=0x0000000000008010, limit=0x1d
idtr:base=0x0000000000000000, limit=0x0
<bochs:5> x /16bx 0x8000
[bochs]:
0x0000000000008000 <bogus+ 0>: 0x23 0x90 0x00 0x00 0x00 0x00 0x00 0x00
0x0000000000008008 <bogus+ 8>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
<bochs:6> x /16bx 0x9000
[bochs]:
0x0000000000009000 <bogus+ 0>: 0x23 0xa0 0x00 0x00 0x00 0x00 0x00 0x00
0x0000000000009008 <bogus+ 8>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
<bochs:7> x /16bx 0xa000
[bochs]:
0x000000000000a000 <bogus+ 0>: 0xe3 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x000000000000a008 <bogus+ 8>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
<bochs:8> x /24bx 0x8010
[bochs]:
0x0000000000008010 <bogus+ 0>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x0000000000008018 <bogus+ 8>: 0x00 0x00 0x00 0x00 0x00 0x99 0x20 0x00
0x0000000000008020 <bogus+ 16>: 0x00 0x00 0x00 0x00 0x00 0x93 0x00 0x00
<bochs:9> r
CPU0:
rax: 00000000_00000010
rbx: 00000000_00000000
rcx: 00000000_c0000080
rdx: 00000000_00000000
rsp: 00000000_00007ad6
rbp: 00000000_00000000
rsi: 00000000_000e7d54
rdi: 00000000_0000800e
r8 : 00000000_00000000
r9 : 00000000_00000000
r10: 00000000_00000000
r11: 00000000_00000000
r12: 00000000_00000000
r13: 00000000_00000000
r14: 00000000_00000000
r15: 00000000_00000000
rip: 00000000_0000c01e
eflags 0x00000002: id vip vif ac vm rf nt IOPL=0 of df if tf sf zf af pf cf
VirtualBox logs attached.