xref: /XiangShan/tools/readmemh/gen-treadle-readmemh.c (revision c6d439803a044ea209139672b25e35fe8d7f4aa0)
1*c6d43980SLemover /***************************************************************************************
2*c6d43980SLemover * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3*c6d43980SLemover *
4*c6d43980SLemover * XiangShan is licensed under Mulan PSL v2.
5*c6d43980SLemover * You can use this software according to the terms and conditions of the Mulan PSL v2.
6*c6d43980SLemover * You may obtain a copy of Mulan PSL v2 at:
7*c6d43980SLemover *          http://license.coscl.org.cn/MulanPSL2
8*c6d43980SLemover *
9*c6d43980SLemover * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10*c6d43980SLemover * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11*c6d43980SLemover * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
12*c6d43980SLemover *
13*c6d43980SLemover * See the Mulan PSL v2 for more details.
14*c6d43980SLemover ***************************************************************************************/
15*c6d43980SLemover 
16b543b09fSZihao Yu #include <stdio.h>
17b543b09fSZihao Yu #include <assert.h>
18b543b09fSZihao Yu #include <stdint.h>
19b543b09fSZihao Yu 
20b543b09fSZihao Yu int main(int argc, char *argv[]) {
21b543b09fSZihao Yu   assert(argc == 3);
22b543b09fSZihao Yu 
23b543b09fSZihao Yu   FILE *in = fopen(argv[1], "rb");
24b543b09fSZihao Yu   assert(in != NULL);
25b543b09fSZihao Yu 
26b543b09fSZihao Yu   FILE *out = fopen(argv[2], "w");
27b543b09fSZihao Yu   assert(out != NULL);
28b543b09fSZihao Yu 
29b543b09fSZihao Yu   int i;
30b543b09fSZihao Yu   for (i = 0; i < 0x100000; i ++) {
31b543b09fSZihao Yu     fprintf(out, "00\n");
32b543b09fSZihao Yu   }
33b543b09fSZihao Yu 
34b543b09fSZihao Yu   uint8_t b;
35b543b09fSZihao Yu   int ret;
36b543b09fSZihao Yu   while ((ret = fread(&b, 1, 1, in)) != 0) {
37b543b09fSZihao Yu     fprintf(out, "%1x%1x\n", b >> 4, b & 0xf);
38b543b09fSZihao Yu   }
39b543b09fSZihao Yu 
40b543b09fSZihao Yu   fclose(in);
41b543b09fSZihao Yu   fclose(out);
42b543b09fSZihao Yu 
43b543b09fSZihao Yu   return 0;
44b543b09fSZihao Yu }
45