Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in codegen?


Fixed. Thanks.

On Sun, 18 Jan 2015 15:23:18 -0600
Ryan Gonzalez <rymg19@xxxxxxxxx> wrote:

> Here I am again! With another bug! This is produced by trying to compile
> this program:
> 
> pkg interrupt =
>     const init_idt : (-> void)
> ;;
> 
> const gdt_addr = 0x0000000000001000 /* see Pure64/src/sysvar.asm for more
> info */
> 
> extern const on_keyboard_w : (-> void)
> extern const write_port : (-> void)
> 
> const Idt_size = 256
> 
> type idt_entry = struct
>     loffs: uint16
>     selec: uint16
>     zero : byte
>     typea: byte
>     hoffs: uint16
> ;;
> 
> var idt: idt_entry[Idt_size]
> 
> const init_idt = {
>     var kaddr = on_keyboard_w castto (uint64)
>     idt[0x21] = [.loffs = kaddr & 0xFFFF castto (uint16), .selec =
> gdt_addr, .zero = 0,
>                  .typea = 0x8e, .hoffs = ((kaddr & 0xffff0000) >> 16 castto
> (uint16))]
> }
> 
> This is the shortest thing I can come up with that reproduces the error.
> Trying to build yields this:
> 
> /tmp/tmp6120cb341da66-interrupt.myr.s: Assembler messages:
> /tmp/tmp6120cb341da66-interrupt.myr.s:62: Error: operand type mismatch for
> `and'
> Couldn't run assembler
> Aborted (core dumped)
> 
> This is the referenced assembler line:
> 
> andq $4294901760,%rdx
> 
> Looking at GCC's assembler output, it seems like andq needs two registers
> when working with constant that are very large (like 0xffff0000).
> 
> The workaround right now is to save the constant into an intermediate
> variable manually:
> 
>     var kaddr = on_keyboard_w castto (uint64)
>     var c = 0xffff0000
>     idt[0x21] = [.loffs = kaddr & 0xFFFF castto (uint16), .selec =
> gdt_addr, .zero = 0,
>                  .typea = 0x8e, .hoffs = ((kaddr & c) >> 16 castto
> (uint16))]
> 
> -- 
> Ryan
> If anybody ever asks me why I prefer C++ to C, my answer will be simple:
> "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
> nul-terminated."
> Personal reality distortion fields are immune to contradictory evidence. -
> srean
> Check out my website: http://kirbyfan64.github.io/


-- 
Ori Bernstein <ori@xxxxxxxxxxxxxx>

References:
Bug in codegen?Ryan Gonzalez <rymg19@xxxxxxxxx>