llvm-mos-sdk
config.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Adrian "asie" Siekierka
3  *
4  * Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
5  * See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
6  * information.
7  */
8 
9 #ifndef _PCE_CONFIG_H_
10 #define _PCE_CONFIG_H_
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
23 #define __PCE_ROM_BANK_DECLARE(id, offset, size) \
24  asm(".global __rom_bank" #id "\n.global __rom_bank" #id \
25  "_size\n.equ __rom_bank" #id ", ((" #offset \
26  ") << 13)\n.equ __rom_bank" #id "_size, ((" #size ") << 13)\n")
27 
28 #define __PCE_ROM_BANK_USE(id, offset) \
29  static inline void pce_rom_bank##id##_map(void) { \
30  __attribute__((leaf)) asm volatile("lda #__rom_bank" #id "_bank\n" \
31  "tam #(1 << " #offset ")\n" \
32  : \
33  : \
34  : "a", "p"); \
35  }
36 
37 #define __PCE_ROM_BANK_CALLBACK_DECLARE(id, offset) \
38  __attribute__(( \
39  leaf, callback(1), noinline, \
40  section("text.pce_rom_bank" #id \
41  "_call"))) void pce_rom_bank##id##_call(void (*method)(void)) { \
42  pce_bank##offset##_size1_push(); \
43  pce_rom_bank##id##_map(); \
44  method(); \
45  pce_bank##offset##_size1_pop(); \
46  }
47 
48 #define __PCE_ROM_BANK_CALLBACK_USE(id) \
49  __attribute__((leaf, callback(1))) void pce_rom_bank##id##_call( \
50  void (*method)(void))
51 
52 #ifdef PCE_CONFIG_IMPLEMENTATION
53 #define PCE_ROM_BANK_AT(id, offset) \
54  __PCE_ROM_BANK_DECLARE(id, offset, 1); \
55  __PCE_ROM_BANK_USE(id, offset) \
56  __PCE_ROM_BANK_CALLBACK_DECLARE(id, offset)
57 #define PCE_ROM_FIXED_BANK_SIZE(size) __PCE_ROM_BANK_DECLARE(0, 8 - size, size)
58 #define PCE_SGX_RAM(size) \
59  asm(".global __ram_bank_size\n.equ __ram_bank_size, ((" #size ") << 13)\n")
60 #else
61 
81 #define PCE_ROM_BANK_AT(id, offset) \
82  __PCE_ROM_BANK_USE(id, offset) \
83  __PCE_ROM_BANK_CALLBACK_USE(id)
84 
89 #define PCE_ROM_FIXED_BANK_SIZE(size)
90 
103 #define PCE_SGX_RAM(size)
104 #endif
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* _PCE_CONFIG_H_ */