[metal] Export struct offsets from C code (#625)

Rather than computing them by hand.
This commit is contained in:
tkchia 2022-09-18 17:54:55 +08:00 committed by GitHub
parent cdf9e8c8a3
commit c937fbb222
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 17 deletions

View file

@ -128,7 +128,26 @@ static noasan textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
}
}
/**
* Exports information about the offset of a field within a structure type,
* so that assembly language routines can use it. This macro can be invoked
* from inside a function whose code is known to be emitted.
*/
#define export_offsetof(type, member) \
do { \
asm volatile(".globl \"" #type "::" #member "\"\n\t" \
".set \"" #type "::" #member "\",%c0" \
: /* no outputs */ \
: "i" (offsetof(type, member))); \
} while (0)
noasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t) {
export_offsetof(struct mman, pc_drive_base_table);
export_offsetof(struct mman, pc_drive_last_sector);
export_offsetof(struct mman, pc_drive_last_head);
export_offsetof(struct mman, e820);
export_offsetof(struct mman, e820_end);
export_offsetof(struct mman, bad_idt);
__normalize_e820(mm);
__invert_memory(mm, pml4t);
}

View file

@ -9,14 +9,15 @@ struct mman {
int32_t pdpi; /* 0x0508 */
int32_t e820n; /* 0x050c */
struct SmapEntry e820[256]; /* 0x0510 */
struct SmapEntry e820_end[0]; /* 0x1d10 */
char pc_drive_base_table[11]; /* 0x1d10 */
unsigned char pc_drive_type; /* 0x1d1b */
unsigned char pc_drive_last_sector; /* 0x1d1c */
unsigned short pc_drive_last_cylinder; /* 0x1d1d */
unsigned char pc_drives_attached; /* 0x1d1f */
unsigned char pc_drive_last_head; /* 0x1d20 */
unsigned char pc_drive; /* 0x1d21 */
char bad_idt[6]; /* 0x1d22 */
unsigned short pc_drive_last_cylinder; /* 0x1d1e */
unsigned char pc_drives_attached; /* 0x1d20 */
unsigned char pc_drive_last_head; /* 0x1d21 */
unsigned char pc_drive; /* 0x1d22 */
char bad_idt[6]; /* 0x1d23 */
};
COSMOPOLITAN_C_END_