My email: 704975...@qq.com
thank you.
Hello,Can you give me your files[kickstart32.s kmain.d linker32.ld makefile]?
My english is poor. My code to build is wrong.so need make some improvements. I would like to refer to your 32-bit code, make some improvements.
Re: asm+D build bootloader
On Tuesday, 27 October 2015 at 12:13:13 UTC, guodemone wrote: sorry,My english is poot. file asm.h [...] Can ldc work with C header files? I don't think it can but I could be wrong. Here's how I build my 32-bit bootloader and link with my kernel main (you will have to replace names etc.): --- nasm -felf -o kickstart32.o kickstart32.s (I don't have an asm.h) gdc -m32 -gdwarf-2 -nostdlib -fPIC -c -o kernel32.main.o kmain.d ld -nodefaultlibs -melf_i386 -z max-page-size=0x1000 -T linker32.ld -o kernel32.bin kickstart32.o kernel32.main.o --- For this build setup you will need a linker script. Here's mine in case you don't have one. 'kickstart' is the entry point in my kickstart.s. Replace names and offsets as required for your code. --- /* Use -melf_i386 or -melf64_x86-64 * to specify the architecture * ld -nodefaultlibs -melf_i386 -z max-page-size=0x1000 -T -o */ ENTRY (kickstart) SECTIONS{ . = 0x0010; .text :{ code = .; _code = .; __code = .; *(.text) *(.rodata) } .rodata ALIGN (0x1000) : { *(.rodata) } .data ALIGN (0x1000) : { data = .; _data = .; __data = .; *(.data) start_ctors = .; *(.ctors) end_ctors = .; start_dtors = .; *(.dtors) end_dtors = .; } .bss : { sbss = .; bss = .; _bss = .; __bss = .; *(COMMON) *(.bss) ebss = .; } end = .; _end = .; __end = .; } --- I got a lot of info from these sites: https://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf https://en.wikibooks.org/wiki/X86_Assembly/Bootloaders http://wiki.osdev.org/Bare_bones (NOTE: wiki.osdev.org has a lot of incorrect information, but it was useful as a starting point when I got stuck moving to a 64-bit kernel) bye, lobo
Re: splitter, compilation issue
On Wednesday, 28 October 2015 at 00:07:23 UTC, sigod wrote: Only removed `filter` from code. You know, I was just writing an answer for this and I kinda changed my mind. Without filter... I think splitter.splitter ought to work. The implementation requires slicing unless you pass it a predicate. Only that overload works on minimal forward ranges. This compiles: import std.algorithm; import std.array; import std.stdio; void main(string[] args) { auto t = "foo\nbar\ncool---beans" .splitter('\n') .filter!(e => e.length) .splitter!(a => a == "bar") ; writeln(t); } It returns [["foo"], ["cool---beans"]]; it split it on the "bar" line in the middle. I think that might be basically what you want.
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 22:56:07 UTC, sigod wrote: On Tuesday, 27 October 2015 at 22:33:32 UTC, Adam D. Ruppe wrote: On Tuesday, 27 October 2015 at 22:18:55 UTC, sigod wrote: P.S. Maybe I should repost my question on SO? I really thought it was a bug, so I posted it here. You could, but I'd say the same thing there I don't expect different answer there. Main idea is to increase language presence and therefore popularity. I saw someone (I think it was Martin Nowak) somewhere saying that maybe we should move questions from Learn forum to SO. or just stick in .array somewhere to do an easy, generic solution Which completely works in this case. Since I'm writing just a code generation tool, which I'll need to use just a few times. Posted it here: http://stackoverflow.com/q/33380674/944911 Only removed `filter` from code.
Re: Metaprogramming get type and field at compile time
On Tuesday, 27 October 2015 at 22:53:35 UTC, Ali Çehreli wrote: On 10/27/2015 03:34 PM, bioinfornatics wrote: > I use FieldTypeTuple and FieldNameTuple to get type and correponding > field name but I fail to loop over these tuple. You can use the .tupleof property and a compile-time foreach: http://dlang.org/class.html (Search for .tuplof on that page) http://ddili.org/ders/d.en/tuples.html#ix_tuples..tupleof http://ddili.org/ders/d.en/tuples.html#ix_tuples.compile-time%20foreach Ali wow Nice without traits thanks Ali for your amazing work best regards
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 22:33:32 UTC, Adam D. Ruppe wrote: On Tuesday, 27 October 2015 at 22:18:55 UTC, sigod wrote: P.S. Maybe I should repost my question on SO? I really thought it was a bug, so I posted it here. You could, but I'd say the same thing there I don't expect different answer there. Main idea is to increase language presence and therefore popularity. I saw someone (I think it was Martin Nowak) somewhere saying that maybe we should move questions from Learn forum to SO. or just stick in .array somewhere to do an easy, generic solution Which completely works in this case. Since I'm writing just a code generation tool, which I'll need to use just a few times.
How to set Global Log level in an application
On Tuesday, 27 October 2015 at 21:50:31 UTC, Chris Piker wrote: I get the following compile errors from the experimental logger class: /usr/include/dmd/phobos/std/experimental/logger/core.d(702): Error: long has no effect in expression (cast(ubyte)160u) Solved: Finally found how to set the global log level for the entire app... import std.experimental.logger; globalLogLevel(LogLevel.warning); Could a list of the module-level functions be provided in the documentation page for std.experimental.logger ? Other modules such as std.file have this but it appears to be lacking for this one.
Re: Metaprogramming get type and field at compile time
On 10/27/2015 03:34 PM, bioinfornatics wrote: > I use FieldTypeTuple and FieldNameTuple to get type and correponding > field name but I fail to loop over these tuple. You can use the .tupleof property and a compile-time foreach: http://dlang.org/class.html (Search for .tuplof on that page) http://ddili.org/ders/d.en/tuples.html#ix_tuples..tupleof http://ddili.org/ders/d.en/tuples.html#ix_tuples.compile-time%20foreach Ali
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 22:18:55 UTC, sigod wrote: P.S. Maybe I should repost my question on SO? I really thought it was a bug, so I posted it here. You could, but I'd say the same thing there - it is no bug, the algorithm legitimately needs that functionality to split successfully. At the same time, filter legitimately needs to /drop/ that functionality to work efficiently. So the error kinda sucks (maybe i should write this as a tip, whenever you see that pattern, adding a .array can work around it), but it isn't a bug. The reason splitter doesn't try to automatically buffer or something like that is that std.algorithm tries to be as low cost as possible in all cases, and asks you to be aware of and pay the cost when it needs to occur. So if it needs a buffer and can't get one for free, it fails to compile, so you are aware of the problem and can provide one that works best for you (or just stick in .array somewhere to do an easy, generic solution)
Metaprogramming get type and field at compile time
Dear, I use FieldTypeTuple and FieldNameTuple to get type and correponding field name but I fail to loop over these tuple. As example: struct Person{ private string name; private ushort age; private bool isMale; this(string name, ushort age, bool isMale){ this.name= name; this.age = age; this.isMale = isMale; } } I would like to print with pragma msg: string name ushort age bool isMale for this I tried: template getDeclarationFields( FieldTypeName...){ enum typeIndex = 0; enum nameIndex = FieldTypeName.length / 2; enum res = FieldTypeName[typeIndex] ~ ' ' ~ FieldTypeName[nameIndex] ~';'; static if( FieldTypeName.length == 1) enum getDeclarationFields = res; else enum getDeclarationFields = res ~ getDeclarationFields!( FieldTypeName[typeIndex+1..nameIndex] ~ FieldTypeName[nameIndex+1..$] ); } but that don't build I though that orange lib should do this somewhere but the lib usi his self trait method thanks for your help
Re: splitter, compilation issue
Well, problem boils down to `splitter` having a greater constraints than most functions can meet. Thanks everyone for clarification. P.S. Maybe I should repost my question on SO? I really thought it was a bug, so I posted it here.
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 21:54:33 UTC, Jonathan M Davis wrote: Well, split calls splitter, and it doesn't make much of an attempt to check its arguments in its template constraint, mostly passing the buck onto splitter, since it's really just a wrapper around splitter that calls array on the result. Looks like one more way to improve documentation.
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 21:45:10 UTC, Ali Çehreli wrote: split's documentation says that it requires a ForwardRange but the output of filter is an InputRange. (I can't imagine now why split has that requirement.) You need to .save at the beginning so when you hit the split point, it can present the whole string as front. You don't know if you've hit the split point until after you've done a fair amount of popFront calls, so if you haven't saved it before, it is impossible to return the first element before the splitter string.
Re: splitter, compilation issue
On 10/27/2015 02:55 PM, Adam D. Ruppe wrote: On Tuesday, 27 October 2015 at 21:45:10 UTC, Ali Çehreli wrote: split's documentation says that it requires a ForwardRange but the output of filter is an InputRange. (I can't imagine now why split has that requirement.) You need to .save at the beginning so when you hit the split point, it can present the whole string as front. You don't know if you've hit the split point until after you've done a fair amount of popFront calls, so if you haven't saved it before, it is impossible to return the first element before the splitter string. I knew that! :p Ali
Comple error in std.experimental.logger.core.d
Using DMD64 (v2.068.2) on Linux CentOS 6.7, compiler was downloaded from this link: http://downloads.dlang.org/releases/2.x/2.068.2/dmd-2.068.2-0.fedora.x86_64.rpm I get the following compile errors from the experimental logger class: /usr/include/dmd/phobos/std/experimental/logger/core.d(702): Error: long has no effect in expression (cast(ubyte)160u) /usr/include/dmd/phobos/std/experimental/logger/core.d(700): Error: long has no effect in expression (cast(ubyte)128u) /usr/include/dmd/phobos/std/experimental/logger/core.d(698): Error: long has no effect in expression (cast(ubyte)96u) ... etc. going on for each instance of the enum core.LogLevel that I use in my code. Has anyone else seen this problem with the newest DMD? Also, is there a work around. I'm happy to provide any further information desired to debug the problem as I'm trying to bring D into my worksite to replace code that we've previously written using a combination of Python and C. Thanks
Re: splitter, compilation issue
On Tuesday, 27 October 2015 at 21:45:10 UTC, Ali Çehreli wrote: On 10/27/2015 01:58 PM, sigod wrote: Here's simple code: import std.algorithm; import std.array; import std.file; void main(string[] args) { auto t = args[1].readText() .splitter('\n') .filter!(e => e.length) .split("---") ; } Looks like it should work split's documentation says that it requires a ForwardRange but the output of filter is an InputRange. (I can't imagine now why split has that requirement.) Ali It still doesn't work. src\phobos\std\array.d(1562): Error: template std.algorithm.iteration.splitter cannot deduce function from argument types !()(Result, string) Sorry, I should've simplified example more.
Re: splitter, compilation issue
On Tuesday, October 27, 2015 20:58:56 sigod via Digitalmars-d-learn wrote: > Here's simple code: > > import std.algorithm; > import std.array; > import std.file; > > void main(string[] args) > { > auto t = args[1].readText() > .splitter('\n') > .filter!(e => e.length) > .split("---") > ; > } > > Looks like it should work, but it won't compile. DMD 2.068.2 > fails with this error: > > Error: template std.algorithm.iteration.splitter cannot deduce > function from argument types !()(FilterResult!(__lambda2, > Result), string), candidates are: > ... > Error: template instance > std.array.split!(FilterResult!(__lambda2, Result), string) error > instantiating > > It compiles if I insert `.array` before `.split(...`. > > Am I missing something? Or it's a bug? I've tried to make a brief > search in the bug tracker, but didn't found anything. > > P.S. dpaste gives very strange error: > > /d712/f815.d(8): Error: unterminated character constant > /d712/f815.d(9): Error: unterminated character constant > ... and so on Well, split calls splitter, and it doesn't make much of an attempt to check its arguments in its template constraint, mostly passing the buck onto splitter, since it's really just a wrapper around splitter that calls array on the result. You could actually reduce your code down to something more like auto t = "hello".filter!"true"().splitter(" "); and you'd have the same problem. And looking at splitter's template constraint, it requires either a narrow string (which the result of filter is not) or a range for which hasSlicing is true (which is not the case for the result of filter). Whether splitter could be implemented without that (e.g. returning a range of Take), I don't know, but it's pretty clear that the current implementation requires slicing, and if you're using filter, that means that you'd need to do something like use array to convert it to a range which _can_ be sliced to pass to split or splitter. - Jonathan M Davis
Re: splitter, compilation issue
On 10/27/2015 01:58 PM, sigod wrote: Here's simple code: import std.algorithm; import std.array; import std.file; void main(string[] args) { auto t = args[1].readText() .splitter('\n') .filter!(e => e.length) .split("---") ; } Looks like it should work split's documentation says that it requires a ForwardRange but the output of filter is an InputRange. (I can't imagine now why split has that requirement.) Ali
Re: What's in a empty class?
On Tuesday, 27 October 2015 at 21:28:31 UTC, Adam D. Ruppe wrote: On Tuesday, 27 October 2015 at 21:23:45 UTC, TheFlyingFiddle wrote: I can account for the first thing a vtable. But that should only cover 4bytes. What's in the other 4bytes? The monitor used for `synchronized`. (yes, this is something a lot of people want to remove as it is rarely all that useful yet you pay the price in all D class objects) I see Thanks.
Re: What's in a empty class?
On Tuesday, 27 October 2015 at 21:23:45 UTC, TheFlyingFiddle wrote: I can account for the first thing a vtable. But that should only cover 4bytes. What's in the other 4bytes? The monitor used for `synchronized`. (yes, this is something a lot of people want to remove as it is rarely all that useful yet you pay the price in all D class objects)
What's in a empty class?
With this code: class A { } pragma(msg, __traits(classInstanceSize, A)); I get the output 8 (32-bit). I can account for the first thing a vtable. But that should only cover 4bytes. What's in the other 4bytes?
splitter, compilation issue
Here's simple code: import std.algorithm; import std.array; import std.file; void main(string[] args) { auto t = args[1].readText() .splitter('\n') .filter!(e => e.length) .split("---") ; } Looks like it should work, but it won't compile. DMD 2.068.2 fails with this error: Error: template std.algorithm.iteration.splitter cannot deduce function from argument types !()(FilterResult!(__lambda2, Result), string), candidates are: ... Error: template instance std.array.split!(FilterResult!(__lambda2, Result), string) error instantiating It compiles if I insert `.array` before `.split(...`. Am I missing something? Or it's a bug? I've tried to make a brief search in the bug tracker, but didn't found anything. P.S. dpaste gives very strange error: /d712/f815.d(8): Error: unterminated character constant /d712/f815.d(9): Error: unterminated character constant ... and so on
asm+D build bootloader
Asm + D with the ability to write on behalf of Clang bootloader, and prove that he can completely replace Clang. This is my wish.
Re: asm+D build bootloader
You chose quite advanced topic. Maybe you want to build common skills in system programming first?
asm+D build bootloader
sorry,My english is poot. file asm.h /* 是bootasm.S汇编文件所需要的头文件,主要是一些与X86保护模式的段访问方式相关的宏定义 */ #ifndef __BOOT_ASM_H__ #define __BOOT_ASM_H__ /* Assembler macros to create x86 segments */ /* Normal segment */ #define SEG_NULLASM \ .word 0, 0; \ .byte 0, 0, 0, 0 #define SEG_ASM(type,base,lim) \ .word (((lim) >> 12) & 0x), ((base) & 0x); \ .byte (((base) >> 16) & 0xff), (0x90 | (type)), \ (0xC0 | (((lim) >> 28) & 0xf)), (((base) >> 24) & 0xff) /* Application segment type bits */ #define STA_X 0x8 // 可执行 #define STA_E 0x4 // 向下扩展段(非可执行段) #define STA_C 0x4 // 一致性代码段(只执行) #define STA_W 0x2 // 段可写(非可执行段) #define STA_R 0x2 // 段可读 (可执行段) #define STA_A 0x1 // 可访问 #endif /* !__BOOT_ASM_H__ */ ** file bootasm.S # 定义并实现了bootloader最先执行的函数start,此函数进行了一定的初始化,完成了 # 从实模式到保护模式的转换,并调用bootmain.c中的bootmain函数 #include # Start the CPU: switch to 32-bit protected mode, jump into C. # The BIOS loads this code from the first sector of the hard disk into # memory at physical address 0x7c00 and starts executing in real mode # with %cs=0 %ip=7c00. # gdt 全局描述符表内的数组索引 .set PROT_MODE_CSEG,0x8 # kernel code segment selector .set PROT_MODE_DSEG,0x10# kernel data segment selector .set CR0_PE_ON, 0x1 # protected mode enable flag .globl start start: .code16 # Assemble for 16-bit mode cli # 禁用中断 cld # 字符串操作设定为递增 si++ di++ ,cld的作用是将direct flag标志位清零 # Set up the important data segment registers (DS, ES, SS). xorw %ax, %ax # Segment number zero movw %ax, %ds # -> Data Segment movw %ax, %es # -> Extra Segment movw %ax, %ss # -> Stack Segment # A20地址线控制打开工作 # Enable A20: # 为了向后兼容早期的PC机,让物理地址线20接低电平 # 如果A20是关闭的,16bit的寻址范围2^20是1M,如果是打开的,那么就是2^21次方, # 但是寻址还是h:h=0h+h=10FFEFh=1M+64K-16Bytes seta20.1: inb $0x64, %al # Wait for not busy testb $0x2, %al jnz seta20.1 #测试 bit 1 是不是为0,如果不是跳回去继续执行 # 对于键盘的8042控制芯片 0x64是命令端口 0xd1 代表写命令 movb $0xd1, %al # 0xd1 -> port 0x64 outb %al, $0x64 seta20.2: inb $0x64, %al # Wait for not busy testb $0x2, %al jnz seta20.2 # 设置写命令后 给0x60端口 发送命令数据0xdf就是打开A20地址线,0xdd就是关闭 movb $0xdf, %al # 0xdf -> port 0x60 outb %al, $0x60 # 转入保护模式,这里需要指定一个临时的GDT,来翻译逻辑地址。 # 这里使用的GDT通过gdtdesc段定义,它翻译得到的物理地址和虚拟地址相同, # 所以转换过程中内存映射不会改变 lgdt gdtdesc # 启动保护模式前建立好的段描述符合段描述符表 # 打开保护模式标志位,相当于按下了保护模式的开关。 # cr0寄存器的第0位就是这个开关,通过CR0_PE_ON或cr0寄存器,将第0位置1 movl %cr0, %eax orl $CR0_PE_ON, %eax movl %eax, %cr0 # 由于上面的代码已经打开了保护模式了,所以这里要使用逻辑地址, # 而不是之前实模式的地址了。这里用到了PROT_MODE_CSEG, # 他的值是0x8。根据段选择子的格式定义,0x8就翻译成: # INDEX TI CPL # 1 00 0 # INDEX代表GDT中的索引,TI代表使用GDTR中的GDT, CPL代表处于特权级。 # PROT_MODE_CSEG选择子选择了GDT中的第1个段描述符。 # 这里使用的gdt就是变量gdt,下面可以看到gdt的第1个段描述符的基地址是0x, # 所以经过映射后和转换前的内存映射的物理地址一样。:7C00=0x7C00 :protcseg 都是相对于物理内存基址的 ljmp $PROT_MODE_CSEG, $protcseg .code32 # Assemble for 32-bit mode protcseg: # 重新初始化各个段寄存器。也就是采用平坦式内存方式, # 代码段同其它段都采用一个内存空间 movw $PROT_MODE_DSEG, %ax # 自定义数据段选择子,因为段选择子是16位的
Re: Mixin template, "no identifier for declarator"
On Tuesday, 27 October 2015 at 08:41:24 UTC, Andrea Fontana wrote: Template mixins can be used only for declaration. Thanks for the quick reply! I didn't know that. Now the error message makes sense. Probably what you need is a (non-template) mixin. Yes, it's gonna be a string mixin, or a private method with lots of ref parameters. -- Simon
Re: Playing audio files and related functions?
Thanks all for the answers, I'll investigate all.
Re: Mixin template, "no identifier for declarator"
On Tuesday, 27 October 2015 at 07:56:51 UTC, SimonN wrote: Hi, I'd like to generate several very similar class methods with a mixin template. The mixin template shall take alias parameters, so that different methods can bind it to different fields. Reduced problem case: Template mixins can be used only for declaration. Probably what you need is a (non-template) mixin. Check this: http://dlang.org/mixin.html You should generate code you need and then mixin it.
Mixin template, "no identifier for declarator"
Hi, I'd like to generate several very similar class methods with a mixin template. The mixin template shall take alias parameters, so that different methods can bind it to different fields. Reduced problem case: class A { int myField; mixin template fieldSetter(alias whatField) { whatField = newVal; } int setMyField(in int newVal) { mixin fieldSetter!myField; } } Compiler error message, DMD64 v2.068.2, line 6 is "whatField = newVal;": (6): Error: no identifier for declarator whatField (6): Error: declaration expected, not '=' I believe I'm following as closely as appropriate what's described at http://dlang.org/template-mixin.html under "Mixins can parameterize symbols using alias parameters". Why does it error out on whatField, apparently deeming it to be a type? Can I get this done with mixin templates? (I'd like to avoid string mixins, the workaround with them got a little ugly.) -- Simon