[LM8]KOZOS移植(2)標準LIB自作
そのままkozosソースもってくると、以下のWarningが出た。
自作した標準ライブラリと、MSBで用意してるライブラリが競合してるようだ。
In file included from main.c:3:
lib.h:4: warning: conflicting types for built-in function ‘putc’
lib.h:10: warning: conflicting types for built-in function ‘strlen’
lib.h:13: warning: conflicting types for built-in function ‘strncmp’
libkozos_msb.a ってやつが標準ライブラリ含んでるのかと思ったが、そうではないようだ。
(ちなみに、半角<をそのまま書くとHTML文法と混じって表示が崩れるので、以下は全角<に置換してる)
[bob@localhost kozos]$ lm8-elf-objdump -D libkozos_msb.a | grep '<' | grep '^0'
00000000 <LatticeDDInit>:
00000000 <.comment>:
00000000 <lm8_LM8>:
00000004 <gpio_LED>:
00000016 <uart_core_uart>:
00000000 <.rodata.str1.1>:
00000000 <.comment>:
00000000 <MicoGPIOInit>:
00000000 <MicoGPIOISR>:
00000000 <.comment>:
00000000 <.comment>:
00000000 <s_uiInterruptContext>:
00000000 <MicoDisableInterrupt>:
00000000 <MicoEnableInterrupt>:
00000000 <.comment>:
00000000 <MicoSleepMicroSecs>:
00000021 <MicoSleepMilliSecs>:
00000000 <MICO_STDIN_DEV_NAME>:
00000004 <MICO_STDOUT_DEV_NAME>:
00000008 <MICO_STDERR_DEV_NAME>:
00000000 <.rodata.str1.1>:
00000000 <.comment>:
00000000 <MicoUartInit>:
00000000 <MicoUartISR>:
00000000 <MicoUart_getC>:
00000000 <MicoUart_putC>:
00000000 <.comment>:
どこにputcとかの標準ライブラリがあるのか?を探す。
っと思ったが見つからないので、競合した標準ライブラリ名はすべて_kozosで改名してしのぐ。
すると、競合のワーニングは消えたが、これが残る。
pointer targets in passing argument 1 of ‘puts’ differ in signedness
[LM8]KOZOS移植(1)バッチ化
■MSBコマンド通りのバッチ環境構築
MSBのGUIでビルドするのと同様に、必要なファイルを全て同じフォルダへ集めて以下バッチを実行すると、
ソースのビルド+Software Deployment(Verilogシミュレーション用.mem生成)まで実行に成功。
しかし、libkozos_msb.aだけは、どうやって生成してるのか分からず、MSBで生成されたものをそのまま使った。
スタートアップルーチンとリンカスクリプトは自作すると動かず。
stackの設定がミスってるようだが、MSBで使用してたスタートアップルーチンを真似してR14に設定すると、
「relocation truncated to fit」と出て原因分からず。
諦めてMSBが使ってるものをそのまま使う事にした。
とにかく、これで自分のmain.c(現状はGPIOへのLEDチカチカ)を動かせる環境が出来た。
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall DDInit.c -o DDInit.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall DDStructs.c -o DDStructs.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall MicoGPIO.c -o MicoGPIO.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall MicoUart.c -o MicoUart.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall main.c -o main.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall Mico8Interrupts.c -o Mico8Interrupts.o
lm8-elf-gcc -c -mcall-stack-size=32 -mcmodel=large -I. -ffunction-sections -mcall-prologues -Os -Wall crt0.S -o crt0.o
lm8-elf-gcc -mcall-stack-size=32 -mcmodel=large -T linker.ld -omain main.o Mico8Interrupts.o crt0.o DDInit.o DDStructs.o MicoGPIO.o MicoUart.o -lgcc -nostdlib -Wl,--gc-sections
lm8-elf-objcopy -O srec $src_name $src_name.srec
lm8-elf-objcopy -O ihex $src_name $src_name.hex
set sw_dir = /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos
set msb_util_dir = /usr/local/diamond/3.5/micosystem/utilities
lm8-elf-objcopy -j .text -O binary $src_name prom_init.bin
$msb_util_dir/bin_to_verilog --LM8 --h --EB --width 3 prom_init.bin prom_init.mem
lm8-elf-objcopy -j .data -j .irq_stack -O binary $src_name scratchpad_init.bin
$msb_util_dir/bin_to_verilog --LM8 --h --EB --width 1 scratchpad_init.bin scratchpad_init.mem
[LM8]relocation truncated to fit
INFO : gcc ---------------------------
INFO : as ---------------------------
INFO : ld ---------------------------
crt0.o: In function `_start':
(.vectors+0x8): relocation truncated to fit: R_LM8_8 against symbol `__stack' defined in *ABS* section in main
echo "INFO : gcc ---------------------------"
lm8-elf-gcc -c $src_name.c
echo "INFO : as ---------------------------"
lm8-elf-as crt0.S -o crt0.o
echo "INFO : ld ---------------------------"
lm8-elf-ld -Map $src_name.map -T linker.ld crt0.o $src_name.o -o $src_name
crt0.S
.section .vectors,"ax"
.globl _start
_start:
/* Clear bss */
movi r0,_lo(__bss_start)
movi r1,0
/* Setup the stack */
movi r14,__stack
/* Mark the end-of-stack */
movi r15,0
seti
call main
clri
__irq_save_restore2:
iret
linker.ld
output_format("elf32-lm8")
output_arch("lm8")
entry(_start)
/*
* this section defines memory attributes (name, origin, length) for the platform
*/
memory
{
text (rx) : origin = 0, length = 12288
data (rw!x) : origin = 0, length = 1024
}
sections
{
.text :
{
_ftext = .;
*(.vectors)
keep (*(.vectors))
*(.text .text.*)
/* constructors and destructors */
keep (*crtbegin*.o(.ctors))
keep (*(exclude_file (*crtend*.o ) .ctors))
keep (*(sort(.ctors.*)))
keep (*(.ctors))
keep (*crtbegin*.o(.dtors))
keep (*(exclude_file (*crtend*.o ) .dtors))
keep (*(sort(.dtors.*)))
keep (*(.dtors))
keep (*(.jcr))
_etext = .;
} > text
.data :
at (loadaddr (.text) + 12288)
{
provide (__data_start = .);
/* reserved for interrupts */
long(0)
*(.data .data.* .gnu.linkonce.d.*)
*(.data*)
sort(constructors)
*(.sdata .sdata.* .gnu.linkonce.s.*)
*(.rodata .rodata.* .gnu.linkonce.r.*)
*(.rodata*)
. = align(2);
_edata = .;
provide (__data_end = .);
} > data
.bss :
at (loadaddr (.text) + 12288 + sizeof (.data))
{
provide (__bss_start = .);
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(common)
provide (__bss_end = .);
} > data
.irq_stack :
at (loadaddr (.text) + 12288 + sizeof (.data) + sizeof(.bss))
{
*(.irq_stack)
} > data
. = align(4);
.end = .;
provide(__stack = origin (data) + length (data) - 4);
__data_load_start = loadaddr(.data);
__data_load_end = __data_load_start + sizeof(.data);
/* stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* dwarf debug sections.
symbols in the dwarf debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* dwarf 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* gnu dwarf 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* dwarf 1.1 and dwarf 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* dwarf 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* sgi/mips dwarf 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}
[LM8]バッチでビルド(MSB使用しない)
バッチで行ってみる。何をどう使っているのか理解するため。
・まずは以下へ移動する。ここにmakefileが存在する。
/mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/Release
・試しに既に生成されているkozos.elfを削除してから、make all と実行してみる。
すると、kozos.elfが生成されるはずだ。これで.elfをバッチで生成するコマンドは分かった。
・次に、.elfから.memを生成する手順だ。最初はMSBのGUIメニューから実行していた。
これのバッチコマンドを知るために、再度MSBのGUIメニューで実行してみるとConsoleに次のように表示される。
lm8-elf-objcopy -j .text -O binary /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/Release/kozos.elf /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./prom_init.bin
/usr/local/diamond/3.5/micosystem/utilities//bin_to_verilog --LM8 --h --EB --width 3 /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./prom_init.bin /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./prom_init.mem
lm8-elf-objcopy -j .data -j .irq_stack -O binary /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/Release/kozos.elf /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./scratchpad_init.bin
/usr/local/diamond/3.5/micosystem/utilities//bin_to_verilog --LM8 --h --EB --width 1 /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./scratchpad_init.bin /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/./scratchpad_init.mem
これを使えば良いようだ。
・試しにバッチを書いて実行してみる。
#!/bin/csh -f
set sw_dir = /mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos
set msb_util_dir = /usr/local/diamond/3.5/micosystem/utilities
make all
lm8-elf-objcopy -j .text -O binary $sw_dir/Release/kozos.elf $sw_dir/./prom_init.bin
$msb_util_dir/bin_to_verilog --LM8 --h --EB --width 3 $sw_dir/./prom_init.bin $sw_dir/./prom_init.mem
lm8-elf-objcopy -j .data -j .irq_stack -O binary $sw_dir/Release/kozos.elf $sw_dir/./scratchpad_init.bin
$msb_util_dir/bin_to_verilog --LM8 --h --EB --width 1 $sw_dir/./scratchpad_init.bin $sw_dir/./scratchpad_init.mem
確かにこのバッチを実行すると、例えば.elfが無ければ生成されて、さらに.memまで作ってくれた。
[LM8]LEDチカSIMが動くまで → 完了
H8のフリーVerilogソースがあれば嬉しいが見つからない。
なので、フリー & Verilog & 理解し易いCPU という事で、Lattice Mico8を選択。
VHDLでも良いんだけど、VHDLの良いシミュレータ知らない。VerilogならVeritak使えるし。
<Lattice Mico8のLEDチカチカSIMできるまで>
・Mico System BuilderはVMware上のCentOS6.7 i386で動作。CentOS x64ではRun Generatorが押せない。
Windows 8.1も64bit版なのか動かなかった。
・pmi_def.vは使わない。
components/lm8/rtl/verilog/lm8_include_all.v の `include "pmi_def.v" をコメントアウト。
・pmi_def.vを読まない事でエラーになるmoduleを現場にコピーする。
\cp /usr/local/diamond/3.5/cae_library/simulation/verilog/pmi/pmi_addsub.v .
\cp /usr/local/diamond/3.5/cae_library/simulation/verilog/pmi/pmi_distributed_spram.v .
\cp /usr/local/diamond/3.5/cae_library/simulation/verilog/pmi/pmi_distributed_dpram.v .
\cp /usr/local/diamond/3.5/cae_library/simulation/verilog/pmi/pmi_ram_dq.v . (2015.9追記)
・SWはMico System Builderでビルド。その後、Software Deploymentでhex形式の.memを生成する。
まずはMico8用のLEDテストサンプルをそのまま使ってる。
・Veritakでシミュレーションするので、soc/kozos_msb.v内の.memファイルへのパスを変える。//.CFG_PROM_INIT_FILE("/mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/prom_init.mem"),
.CFG_PROM_INIT_FILE("../sw/kozos/prom_init.mem"),
.CFG_PROM_INIT_FILE_FORMAT("hex"),
//.CFG_SP_INIT_FILE("/mnt/hgfs/onedrive/kozos/micosystem/kozos_msb/sw/kozos/scratchpad_init.mem"),
.CFG_SP_INIT_FILE("../sw/kozos/scratchpad_init.mem"),
.CFG_SP_INIT_FILE_FORMAT("hex"),
・テストベンチはリセットをLで入れて、3クロック後にHに戻してるだけ。reset_n <= 1'b0 ;
@(posedge clk_i) ;
@(posedge clk_i) ;
@(posedge clk_i) ;
reset_n <= 1'b1 ;
ここまでやると、プログラムROMもスクラッチパッドRAMも.memが正常に読み込めてるようで、
動き出した。
そして、16.042msあたりまでシミュレーションしたところで、LEDPIO_OUT[0]がHからLへ変化した。
その後、32.078msあたりで、LからHへトグル。ちゃんと動いてるようだ。