Closed Quuxplusone closed 13 years ago
Attached locore.s
(13358 bytes, application/octet-stream): pre-processed locore.s
reduced testcase:
.data
.globl IdlePTD
IdlePTD: .long 0
.text
movl ((IdlePTD)-0xc0000000), %eax
It is bad that we assert instead of producing a nice error, but gas produces
the same output for
movl ((IdlePTD)-0xc0000000), %eax
and
movl ((IdlePTD)+0x40000000), %eax
which I would call a bug. Any reason you need to use the -0xc form?
0xc0000000 is used because that's the kernel base macro. The expection here I guess is explicitly 32bit (or 64bit for ELF64) wraparound.
Yes, the original non-preprocessed code has:
#define KERNBASE 0xc000000 (this via all kinds of in-between macros)
...
#define R(foo) ((foo)-KERNBASE)
...
movl R(IdlePTD), %eax
And obviously, in two's complement 32 bits, subtracting 0xc0000000 is
the same as adding 0x40000000. :)
Even the MS assembler agrees. This:
.model flat
.data
foo dd 0
.code
mov eax,foo-0c0000000h
mov eax,foo+040000000h
mov eax,foo-0ffffffffh
mov eax,foo+000000001h
end
results in:
00000000: A1 00 00 00 40 mov eax,dword ptr ds:[40000000h]
00000005: A1 00 00 00 40 mov eax,dword ptr ds:[40000000h]
0000000A: A1 01 00 00 00 mov eax,dword ptr ds:[00000001h]
0000000F: A1 01 00 00 00 mov eax,dword ptr ds:[00000001h]
Yikes!
okay, looks like the way forward is to relax the assert a bit.
I couldn't find a Warn() equivalent of an assert() in wide use so assert stays for now.
r136954 probably fixes this.
locore.s
(13358 bytes, application/octet-stream)