создание проекта
This commit is contained in:
commit
edc749eab2
46
Makefile
Normal file
46
Makefile
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Makefile для ndisasm-ru
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -O2 -std=c17 -U__STRICT_ANSI__ -g3 -ggdb -fwrapv -fno-common \
|
||||
-ffunction-sections -fdata-sections -fvisibility=hidden \
|
||||
-Wall -W -pedantic -Werror=implicit -Werror=missing-braces \
|
||||
-Werror=return-type -Werror=trigraphs -Werror=pointer-arith \
|
||||
-Werror=comment -Werror=vla -Werror=strict-prototypes \
|
||||
-Werror=missing-prototypes -Werror=missing-declarations \
|
||||
-Wno-variadic-macros -Wno-long-long -Wno-stringop-truncation \
|
||||
-Wno-shift-negative-value -DHAVE_CONFIG_H
|
||||
CPPFLAGS = -Werror=attributes
|
||||
INCLUDES = -Iinclude -Isrc
|
||||
LDFLAGS = -Wl,--as-needed -Wl,--gc-sections
|
||||
LIBS = -lz
|
||||
|
||||
SRCS_NDISASM = src/ndisasm.c src/zamenyator.c src/disasm.c src/sync.c \
|
||||
src/prefix.c src/diserror.c
|
||||
|
||||
SRCS_NASMLIB = $(wildcard src/nasmlib/*.c)
|
||||
SRCS_COMMON = $(wildcard src/common/*.c)
|
||||
SRCS_X86 = $(wildcard src/x86/*.c)
|
||||
SRCS_STDLIB = $(wildcard src/stdlib/*.c)
|
||||
SRCS_OUTPUT = $(wildcard src/output/*.c)
|
||||
|
||||
OBJS = $(SRCS_NDISASM:.c=.o) \
|
||||
$(SRCS_NASMLIB:.c=.o) \
|
||||
$(SRCS_COMMON:.c=.o) \
|
||||
$(SRCS_X86:.c=.o) \
|
||||
$(SRCS_STDLIB:.c=.o) \
|
||||
$(SRCS_OUTPUT:.c=.o)
|
||||
|
||||
TARGET = ndisasm-ru
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(TARGET)
|
||||
|
||||
.PHONY: all clean
|
||||
292
README.md
Normal file
292
README.md
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
```markdown
|
||||
# ndisasm-ru — Русский дизассемблер x86-64 для языка КВС
|
||||
|
||||
**ndisasm-ru** — это модифицированная версия утилиты `ndisasm` из пакета **Netwide Assembler (NASM)**, адаптированная для вывода дизассемблированного кода на русском языке в синтаксисе языка **КВС**.
|
||||
|
||||
---
|
||||
|
||||
## 📌 Особенности
|
||||
|
||||
- ✅ **Перевод мнемоник** инструкций x86-64 на русский язык
|
||||
- ✅ **Перевод регистров** (64, 32, 16, 8-битных) на русский язык
|
||||
- ✅ **Числовые значения** остаются без изменений
|
||||
- ✅ **Синтаксис** соответствует языку программирования КВС
|
||||
- ✅ **Полная совместимость** с оригинальным `ndisasm` по функциональности
|
||||
- ✅ **Независимая сборка** — не требует наличия NASM
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Быстрый старт
|
||||
|
||||
### Сборка
|
||||
|
||||
```bash
|
||||
git clone https://github.com/artradeskz/ndisasm-ru.git
|
||||
cd ndisasm-ru
|
||||
make
|
||||
```
|
||||
|
||||
### Использование
|
||||
|
||||
```bash
|
||||
./ndisasm-ru -b 32 файл.bin
|
||||
./ndisasm-ru -b 64 файл.elf
|
||||
```
|
||||
|
||||
### Пример
|
||||
|
||||
Входные байты: `B8 01 00 00 00`
|
||||
|
||||
| Оригинальный ndisasm | ndisasm-ru |
|
||||
|---|---|
|
||||
| `mov eax,0x1` | `переместить еаикс,0x1` |
|
||||
| `add eax,0x2` | `прибавить еаикс,0x2` |
|
||||
| `cmp eax,ebx` | `сравнить еаикс,ебикс` |
|
||||
| `jmp 0x1234` | `переход 0x1234` |
|
||||
|
||||
---
|
||||
|
||||
## 📂 Структура проекта
|
||||
|
||||
```
|
||||
ndisasm-ru/
|
||||
├── src/
|
||||
│ ├── ndisasm.c # Основной файл дизассемблера (с патчем)
|
||||
│ ├── zamenyator.c # Модуль перевода мнемоник и регистров
|
||||
│ ├── zamenyator.h # Заголовок модуля перевода
|
||||
│ ├── disasm.c # Ядро дизассемблера (оригинал)
|
||||
│ ├── sync.c # Синхронизация (оригинал)
|
||||
│ └── ... # Остальные файлы из NASM
|
||||
├── include/ # Заголовочные файлы
|
||||
├── Makefile # Makefile для сборки
|
||||
└── README.md # Этот файл
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 Таблица перевода
|
||||
|
||||
### Мнемоники (основные)
|
||||
|
||||
| Английская | Русская (КВС) |
|
||||
|---|---|
|
||||
| `mov` | `переместить` |
|
||||
| `add` | `прибавить` |
|
||||
| `sub` | `вычесть` |
|
||||
| `cmp` | `сравнить` |
|
||||
| `jmp` | `переход` |
|
||||
| `je` / `jz` | `переход_если_равно` / `переход_если_ноль` |
|
||||
| `jne` / `jnz` | `переход_если_неравно` / `переход_если_не_ноль` |
|
||||
| `call` | `вызвать` |
|
||||
| `ret` | `вернуться` |
|
||||
| `push` | `втолкнуть` |
|
||||
| `pop` | `вытолкнуть` |
|
||||
| `test` | `проверить` |
|
||||
| `xor` | `исключающее_или` |
|
||||
| `and` | `и` |
|
||||
| `or` | `или` |
|
||||
| `inc` | `увеличить` |
|
||||
| `dec` | `уменьшить` |
|
||||
| `syscall` | `вызов_системы` |
|
||||
| `nop` | `нет_операции` |
|
||||
| `lea` | `загрузить_адрес` |
|
||||
|
||||
Полный список мнемоник и регистров см. в файле `src/zamenyator.c`.
|
||||
|
||||
### Регистры
|
||||
|
||||
| Английский | Русский (КВС) |
|
||||
|---|---|
|
||||
| `rax` | `раикс` |
|
||||
| `rbx` | `рбикс` |
|
||||
| `rcx` | `рсикс` |
|
||||
| `rdx` | `рдикс` |
|
||||
| `rsi` | `рсиай` |
|
||||
| `rdi` | `рдиай` |
|
||||
| `rsp` | `рсипи` |
|
||||
| `rbp` | `рбипи` |
|
||||
| `r8` – `r15` | `р8` – `р15` |
|
||||
| `eax` | `еаикс` |
|
||||
| `ebx` | `ебикс` |
|
||||
| ... | ... |
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Сборка из исходников
|
||||
|
||||
```bash
|
||||
# Клонирование репозитория
|
||||
git clone https://github.com/artradeskz/ndisasm-ru.git
|
||||
cd ndisasm-ru
|
||||
|
||||
# Сборка
|
||||
make clean
|
||||
make
|
||||
|
||||
# Проверка
|
||||
echo -n -e "\xB8\x01\x00\x00\x00" > test.bin
|
||||
./ndisasm-ru -b 32 test.bin
|
||||
# Ожидаемый вывод: 00000000 B801000000 переместить еаикс,0x1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📖 Использование
|
||||
|
||||
### Основные опции
|
||||
|
||||
```bash
|
||||
./ndisasm-ru -b 16/32/64 файл # Установка разрядности
|
||||
./ndisasm-ru -o смещение файл # Установка базового адреса
|
||||
./ndisasm-ru -e байты файл # Пропуск заголовка
|
||||
./ndisasm-ru -k старт,байты # Пропуск региона
|
||||
./ndisasm-ru -h # Справка
|
||||
```
|
||||
|
||||
### Примеры
|
||||
|
||||
```bash
|
||||
# Дизассемблирование 32-битного бинарного файла
|
||||
./ndisasm-ru -b 32 program.bin
|
||||
|
||||
# Дизассемблирование 64-битного ELF-файла с пропуском заголовка
|
||||
./ndisasm-ru -b 64 -e 0x40 program.elf
|
||||
|
||||
# Дизассемблирование с указанием виртуального адреса
|
||||
./ndisasm-ru -b 64 -o 0x400000 -e 0x81380 program.elf
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Тестирование
|
||||
|
||||
```bash
|
||||
# Сборка и тестирование
|
||||
make test
|
||||
```
|
||||
|
||||
Или вручную:
|
||||
|
||||
```bash
|
||||
# Создание тестового файла
|
||||
echo -n -e "\xB8\x01\x00\x00\x00" > test.bin
|
||||
|
||||
# Запуск теста
|
||||
./ndisasm-ru -b 32 test.bin
|
||||
|
||||
# Ожидаемый вывод: 00000000 B801000000 переместить еаикс,0x1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Я добавил пример вывода дизассемблирования самого `ndisasm-ru`. Вот обновлённый раздел `README.md` с этим примером:
|
||||
|
||||
---
|
||||
|
||||
## 📖 Пример вывода
|
||||
|
||||
Ниже приведён фрагмент дизассемблирования самого `ndisasm-ru` в 64-битном режиме. Хорошо видно, как инструкции и регистры переводятся на русский язык:
|
||||
|
||||
```bash
|
||||
$ ./ndisasm-ru -b 64 -o 0x81380 -e 0x81380 ndisasm-ru | head -20
|
||||
00081380 B957040000 переместить есикс,0x457
|
||||
00081385 488D154C6A0000 загрузить_адрес рдикс,[rel 0x87dd8]
|
||||
0008138C 488D355D6F0000 загрузить_адрес рсиай,[rel 0x882f0]
|
||||
00081393 488D3D4B6A0000 загрузить_адрес рдиай,[rel 0x87de5]
|
||||
0008139A E87F010000 вызвать 0x8151e
|
||||
0008139F F30F1EFA endbr64
|
||||
000813A3 50 втолкнуть раикс
|
||||
000813A4 58 вытолкнуть раикс
|
||||
000813A5 50 втолкнуть раикс
|
||||
000813A6 E8B5540000 вызвать 0x86860
|
||||
000813AB E860FEFFFF вызвать 0x81210
|
||||
000813B0 F30F1EFA endbr64
|
||||
000813B4 50 втолкнуть раикс
|
||||
000813B5 58 вытолкнуть раикс
|
||||
000813B6 488D3DC3720000 загрузить_адрес рдиай,[rel 0x88680]
|
||||
000813BD 50 втолкнуть раикс
|
||||
000813BE 31C0 исключающее_или еаикс,еаикс
|
||||
000813C0 E805000000 вызвать 0x813ca
|
||||
000813C5 E8E6FFFFFF вызвать 0x813b0
|
||||
000813CA F30F1EFA endbr64
|
||||
```
|
||||
|
||||
**Что мы видим в этом выводе:**
|
||||
- `mov ecx,0x457` → `переместить есикс,0x457`
|
||||
- `lea rdx,[rel 0x87dd8]` → `загрузить_адрес рдикс,[rel 0x87dd8]`
|
||||
- `call 0x8151e` → `вызвать 0x8151e`
|
||||
- `push rax` → `втолкнуть раикс`
|
||||
- `pop rax` → `вытолкнуть раикс`
|
||||
- `xor eax,eax` → `исключающее_или еаикс,еаикс`
|
||||
|
||||
---
|
||||
|
||||
Этот пример наглядно демонстрирует, как `ndisasm-ru` переводит реальный машинный код в читаемый синтаксис КВС.
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
## ⚠️ Ограничения
|
||||
|
||||
- Поддерживаются только инструкции x86-64, присутствующие в таблице перевода
|
||||
- Некоторые специфические инструкции (SSE, AVX, CET) могут отображаться на английском
|
||||
- Сегментные префиксы пока не переведены
|
||||
|
||||
---
|
||||
|
||||
## 📜 Лицензия и авторство
|
||||
|
||||
### Оригинальный проект NASM
|
||||
|
||||
Исходный код основан на проекте **Netwide Assembler (NASM)**.
|
||||
|
||||
- **Автор:** Simon Tatham, Julian Hall и другие участники проекта NASM
|
||||
- **Официальный сайт:** https://www.nasm.us/
|
||||
- **Исходный код:** https://git.nasm.us/nasm.git
|
||||
- **Лицензия:** BSD 2-Clause License
|
||||
|
||||
```
|
||||
Авторские права © 1996-2025 Авторы NASM. Все права защищены.
|
||||
|
||||
Распространение и использование разрешены при условии сохранения
|
||||
уведомления об авторских правах и списка условий.
|
||||
Подробнее: https://opensource.org/licenses/BSD-2-Clause
|
||||
```
|
||||
|
||||
### Модификация для КВС
|
||||
|
||||
- **Автор модификации:** artradeskz
|
||||
- **Проект:** https://github.com/artradeskz/ndisasm-ru
|
||||
- **Назначение:** Адаптация для языка программирования КВС
|
||||
|
||||
Модификация включает:
|
||||
- Добавление модуля `zamenyator` для перевода мнемоник и регистров
|
||||
- Патч `ndisasm.c` для вызова переводчика в функции `output_ins()`
|
||||
- Сборка в независимый проект
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Благодарности
|
||||
|
||||
- Команде разработчиков **NASM** за отличный инструмент
|
||||
- Сообществу **КВС** за вдохновение
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Ссылки
|
||||
|
||||
- [Проект КВС](https://github.com/artradeskz/kvs)
|
||||
- [Официальный сайт NASM](https://www.nasm.us/)
|
||||
- [Исходный код NASM](https://git.nasm.us/nasm.git)
|
||||
|
||||
---
|
||||
|
||||
## 📧 Контакты
|
||||
|
||||
По вопросам и предложениям: [GitHub Issues](https://github.com/artradeskz/ndisasm-ru/issues)
|
||||
|
||||
---
|
||||
|
||||
*ndisasm-ru — Русский дизассемблер для КВС*
|
||||
20
include/alloc.h
Normal file
20
include/alloc.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASMLIB_ALLOC_H
|
||||
#define NASMLIB_ALLOC_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
fatal_func nasm_alloc_failed(void);
|
||||
|
||||
static inline void * pure_func validate_ptr(void *p)
|
||||
{
|
||||
if (unlikely(!p))
|
||||
nasm_alloc_failed();
|
||||
return p;
|
||||
}
|
||||
|
||||
extern size_t _nasm_last_string_size;
|
||||
|
||||
#endif /* NASMLIB_ALLOC_H */
|
||||
18
include/asmutil.h
Normal file
18
include/asmutil.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_ASMUTIL_H
|
||||
#define NASM_ASMUTIL_H
|
||||
|
||||
/*
|
||||
* Get a boolean option value; can be an expression or a set of special
|
||||
* ("yes", "no", "false", "true", ...)
|
||||
*
|
||||
* If the result is not a valid value, print an error message, leave
|
||||
* the option value unchanged, and return NULL.
|
||||
*
|
||||
* Returns the first character past the boolean expression.
|
||||
*/
|
||||
char *get_boolean_option(const char *, bool *);
|
||||
|
||||
#endif
|
||||
55
include/assemble.h
Normal file
55
include/assemble.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* assemble.h - header file for stuff private to the assembler
|
||||
*/
|
||||
|
||||
#ifndef NASM_ASSEMBLE_H
|
||||
#define NASM_ASSEMBLE_H
|
||||
|
||||
#include "nasm.h"
|
||||
#include "iflag.h"
|
||||
#include "asmutil.h"
|
||||
|
||||
extern iflag_t cpu, cmd_cpu;
|
||||
void set_cpu(const char *cpuspec);
|
||||
|
||||
extern bool in_absolute; /* Are we in an absolute segment? */
|
||||
extern struct location absolute;
|
||||
|
||||
int64_t increment_offset(int64_t delta);
|
||||
void process_insn(insn *instruction);
|
||||
|
||||
bool directive_valid(const char *);
|
||||
bool process_directives(char *);
|
||||
void process_pragma(char *);
|
||||
|
||||
/* Is this a compile-time absolute constant? */
|
||||
static inline bool op_compile_abs(const struct operand * const op)
|
||||
{
|
||||
if (op->opflags & OPFLAG_UNKNOWN)
|
||||
return true; /* Be optimistic in pass 1 */
|
||||
if (op->opflags & OPFLAG_RELATIVE)
|
||||
return false;
|
||||
if (op->wrt != NO_SEG)
|
||||
return false;
|
||||
|
||||
return op->segment == NO_SEG;
|
||||
}
|
||||
|
||||
/* Is this a compile-time relative constant? */
|
||||
static inline bool op_compile_rel(const insn * const ins,
|
||||
const struct operand * const op)
|
||||
{
|
||||
if (op->opflags & OPFLAG_UNKNOWN)
|
||||
return true; /* Be optimistic in pass 1 */
|
||||
if (!(op->opflags & OPFLAG_RELATIVE))
|
||||
return false;
|
||||
if (op->wrt != NO_SEG) /* Is this correct?! */
|
||||
return false;
|
||||
|
||||
return op->segment == ins->loc.segment;
|
||||
}
|
||||
|
||||
#endif
|
||||
38
include/attribute.h
Normal file
38
include/attribute.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Define a macro for compiler attributes. Use either gcc
|
||||
* syntax if __GNUC__ is defined, or try to look for the
|
||||
* modern standard [[x]] attributes.
|
||||
*
|
||||
* Unfortunately [[x]] doesn't always work when it comes to
|
||||
* GNUC-specific attributes, and some compilers support GCC
|
||||
* syntax without __attribute__ just to be confusing.
|
||||
* Therefore, this also needs an autoconf module to test
|
||||
* the validity.
|
||||
*
|
||||
* Use #ifdef and not defined() here; some compilers do the wrong
|
||||
* thing in the latter case.
|
||||
*/
|
||||
|
||||
#ifndef ATTRIBUTE
|
||||
# define MODERN_ATTRIBUTE(x) [[x]]
|
||||
# ifndef __GNUC__
|
||||
# ifdef __cplusplus
|
||||
# ifdef __has_cpp_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# ifdef __has_c_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# ifdef __has_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# define ATTRIBUTE(x) __attribute__((x))
|
||||
# endif
|
||||
#endif
|
||||
38
include/autoconf/attribute.h
Normal file
38
include/autoconf/attribute.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Define a macro for compiler attributes. Use either gcc
|
||||
* syntax if __GNUC__ is defined, or try to look for the
|
||||
* modern standard [[x]] attributes.
|
||||
*
|
||||
* Unfortunately [[x]] doesn't always work when it comes to
|
||||
* GNUC-specific attributes, and some compilers support GCC
|
||||
* syntax without __attribute__ just to be confusing.
|
||||
* Therefore, this also needs an autoconf module to test
|
||||
* the validity.
|
||||
*
|
||||
* Use #ifdef and not defined() here; some compilers do the wrong
|
||||
* thing in the latter case.
|
||||
*/
|
||||
|
||||
#ifndef ATTRIBUTE
|
||||
# define MODERN_ATTRIBUTE(x) [[x]]
|
||||
# ifndef __GNUC__
|
||||
# ifdef __cplusplus
|
||||
# ifdef __has_cpp_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# ifdef __has_c_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# ifdef __has_attribute
|
||||
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ATTRIBUTE
|
||||
# define ATTRIBUTE(x) __attribute__((x))
|
||||
# endif
|
||||
#endif
|
||||
373
include/bytesex.h
Normal file
373
include/bytesex.h
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* bytesex.h - byte order helper functions
|
||||
*
|
||||
* In this function, be careful about getting X86_MEMORY versus
|
||||
* LITTLE_ENDIAN correct: X86_MEMORY also means we are allowed to
|
||||
* do unaligned memory references; it is opportunistic.
|
||||
*/
|
||||
|
||||
#ifndef NASM_BYTEORD_H
|
||||
#define NASM_BYTEORD_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*
|
||||
* Endian control functions which work on a single integer
|
||||
*/
|
||||
/* Last resort implementations */
|
||||
#define CPU_TO_LE(w,x) \
|
||||
uint ## w ## _t xx = (x); \
|
||||
union { \
|
||||
uint ## w ## _t v; \
|
||||
uint8_t c[sizeof(xx)]; \
|
||||
} u; \
|
||||
size_t i; \
|
||||
for (i = 0; i < sizeof(xx); i++) { \
|
||||
u.c[i] = (uint8_t)xx; \
|
||||
xx >>= 8; \
|
||||
} \
|
||||
return u.v
|
||||
|
||||
#define LE_TO_CPU(w,x) \
|
||||
uint ## w ## _t xx = 0; \
|
||||
union { \
|
||||
uint ## w ## _t v; \
|
||||
uint8_t c[sizeof(xx)]; \
|
||||
} u; \
|
||||
u.v = (x); \
|
||||
for (i = 0; i < sizeof(xx); i++) \
|
||||
xx += (uint ## w ## _t)x.c[i] << (i << 3); \
|
||||
\
|
||||
return xx
|
||||
|
||||
#ifndef HAVE_HTOLE16
|
||||
static inline uint16_t htole16(uint16_t v)
|
||||
{
|
||||
# ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE_CPU_TO_LE16)
|
||||
return cpu_to_le16(v);
|
||||
# elif defined(HAVE___CPU_TO_LE16)
|
||||
return __cpu_to_le16(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
# ifdef HAVE___BSWAP_16
|
||||
return __bswap_16(v);
|
||||
# elif defined(HAVE___BUILTIN_BSWAP16)
|
||||
return __builtin_bswap16(v);
|
||||
# elif defined(HAVE__BYTESWAP_UINT16)
|
||||
return _byteswap_uint16(v);
|
||||
# else
|
||||
v = (v << 8) | (v >> 8);
|
||||
return v;
|
||||
# endif
|
||||
# else
|
||||
CPU_TO_LE(16);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HTOLE32
|
||||
static inline uint32_t htole32(uint32_t v)
|
||||
{
|
||||
# ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE_CPU_TO_LE32)
|
||||
return cpu_to_le32(v);
|
||||
# elif defined(HAVE___CPU_TO_LE32)
|
||||
return __cpu_to_le32(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
# ifdef HAVE___BSWAP_32
|
||||
return __bswap_32(v);
|
||||
# elif defined(HAVE___BUILTIN_BSWAP32)
|
||||
return __builtin_bswap32(v);
|
||||
# elif defined(HAVE__BYTESWAP_UINT32)
|
||||
return _byteswap_uint32(v);
|
||||
# else
|
||||
v = ((v << 8) & UINT32_C(0xff00ff00)) |
|
||||
((v >> 8) & UINT32_C(0x00ff00ff));
|
||||
return (v << 16) | (v >> 16);
|
||||
# endif
|
||||
# else
|
||||
CPU_TO_LE(32);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HTOLE64
|
||||
static inline uint64_t htole64(uint64_t v)
|
||||
{
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE_CPU_TO_LE64)
|
||||
return cpu_to_le64(v);
|
||||
# elif defined(HAVE___CPU_TO_LE64)
|
||||
return __cpu_to_le64(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
# ifdef HAVE___BSWAP_64
|
||||
return __bswap_64(v);
|
||||
# elif defined(HAVE___BUILTIN_BSWAP64)
|
||||
return __builtin_bswap64(v);
|
||||
# elif defined(HAVE__BYTESWAP_UINT64)
|
||||
return _byteswap_uint64(v);
|
||||
# else
|
||||
v = ((v << 8) & UINT64_C(0xff00ff00ff00ff00)) |
|
||||
((v >> 8) & UINT64_C(0x00ff00ff00ff00ff));
|
||||
v = ((v << 16) & UINT64_C(0xffff0000ffff0000)) |
|
||||
((v >> 16) & UINT64_C(0x0000ffff0000ffff));
|
||||
return (v << 32) | (v >> 32);
|
||||
# endif
|
||||
# else
|
||||
CPU_TO_LE(64);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HTOLE16
|
||||
static inline uint16_t le16toh(uint16_t v)
|
||||
{
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE___LE16_TO_CPU)
|
||||
return __le16_to_cpu(v);
|
||||
# elif defined(HAVE_LE16TOH)
|
||||
return le64toh(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
return htole16(v);
|
||||
# else
|
||||
LE_TO_CPU(16);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HTOLE32
|
||||
static inline uint32_t le32toh(uint32_t v)
|
||||
{
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE_CPU_TO_LE32)
|
||||
return le32_to_cpu(v);
|
||||
# elif defined(HAVE___CPU_TO_LE32)
|
||||
return __le32_to_cpu(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
return htole32(v);
|
||||
# else
|
||||
LE_TO_CPU(32);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HTOLE64
|
||||
static inline uint64_t le64toh(uint64_t v)
|
||||
{
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
return v;
|
||||
# elif defined(HAVE_CPU_TO_LE64)
|
||||
return le64_to_cpu(v);
|
||||
# elif defined(HAVE___CPU_TO_LE64)
|
||||
return __le64_to_cpu(v);
|
||||
# elif defined(WORDS_BIGENDIAN)
|
||||
return htole64(v);
|
||||
# else
|
||||
LE_TO_CPU(64);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Accessors for unaligned littleendian objects. These intentionally
|
||||
* take an arbitrary pointer type, such that e.g. getu32() can be
|
||||
* correctly executed on a void * or uint8_t *.
|
||||
*/
|
||||
#define getu8(p) (*(const uint8_t *)(p))
|
||||
#define setu8(p,v) (*(uint8_t *)(p) = (v))
|
||||
|
||||
/* Unaligned object referencing */
|
||||
#if X86_MEMORY
|
||||
|
||||
#define getu16(p) (*(const uint16_t *)(p))
|
||||
#define getu32(p) (*(const uint32_t *)(p))
|
||||
#define getu64(p) (*(const uint64_t *)(p))
|
||||
|
||||
#define setu16(p,v) (*(uint16_t *)(p) = (v))
|
||||
#define setu32(p,v) (*(uint32_t *)(p) = (v))
|
||||
#define setu64(p,v) (*(uint64_t *)(p) = (v))
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
struct unaligned16 {
|
||||
uint16_t v;
|
||||
} __attribute__((packed));
|
||||
static inline uint16_t getu16(const void *p)
|
||||
{
|
||||
return le16toh(((const struct unaligned16 *)p)->v);
|
||||
}
|
||||
static inline uint16_t setu16(void *p, uint16_t v)
|
||||
{
|
||||
((struct unaligned16 *)p)->v = htole16(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
struct unaligned32 {
|
||||
uint32_t v;
|
||||
} __attribute__((packed));
|
||||
static inline uint32_t getu32(const void *p)
|
||||
{
|
||||
return le32toh(((const struct unaligned32 *)p)->v);
|
||||
}
|
||||
static inline uint32_t setu32(void *p, uint32_t v)
|
||||
{
|
||||
((struct unaligned32 *)p)->v = htole32(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
struct unaligned64 {
|
||||
uint64_t v;
|
||||
} __attribute__((packed));
|
||||
static inline uint64_t getu64(const void *p)
|
||||
{
|
||||
return le64toh(((const struct unaligned64 *)p)->v);
|
||||
}
|
||||
static inline uint64_t setu64(void *p, uint64_t v)
|
||||
{
|
||||
((struct unaligned64 *)p)->v = htole64(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
static inline uint16_t getu16(const void *p)
|
||||
{
|
||||
const uint16_t _unaligned *pp = p;
|
||||
return le16toh(*pp);
|
||||
}
|
||||
static inline uint16_t setu16(void *p, uint16_t v)
|
||||
{
|
||||
uint16_t _unaligned *pp = p;
|
||||
*pp = htole16(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint32_t getu32(const void *p)
|
||||
{
|
||||
const uint32_t _unaligned *pp = p;
|
||||
return le32toh(*pp);
|
||||
}
|
||||
static inline uint32_t setu32(void *p, uint32_t v)
|
||||
{
|
||||
uint32_t _unaligned *pp = p;
|
||||
*pp = htole32(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint64_t getu64(const void *p)
|
||||
{
|
||||
const uint64_t _unaligned *pp = p;
|
||||
return le64toh(*pp);
|
||||
}
|
||||
static inline uint64_t setu64(void *p, uint64_t v)
|
||||
{
|
||||
uint32_t _unaligned *pp = p;
|
||||
*pp = htole64(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* No idea, do it the slow way... */
|
||||
|
||||
static inline uint16_t getu16(const void *p)
|
||||
{
|
||||
const uint8_t *pp = p;
|
||||
return pp[0] + (pp[1] << 8);
|
||||
}
|
||||
static inline uint16_t setu16(void *p, uint16_t v)
|
||||
{
|
||||
uint8_t *pp = p;
|
||||
pp[0] = (uint8_t)v;
|
||||
pp[1] = (uint8_t)(v >> 8);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint32_t getu32(const void *p)
|
||||
{
|
||||
const uint8_t *pp = p;
|
||||
return getu16(pp) + ((uint32_t)getu16(pp+2) << 16);
|
||||
}
|
||||
static inline uint32_t setu32(void *p, uint32_t v)
|
||||
{
|
||||
uint8_t *pp = p;
|
||||
setu16(pp, (uint16_t)v);
|
||||
setu16(pp+2, (uint16_t)(v >> 16));
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint64_t getu64(const void *p)
|
||||
{
|
||||
const uint8_t *pp = p;
|
||||
return getu32(pp) + ((uint64_t)getu32(pp+4) << 32);
|
||||
}
|
||||
static inline uint64_t setu64(void *p, uint64_t v)
|
||||
{
|
||||
uint8_t *pp = p;
|
||||
setu32(pp, (uint32_t)v);
|
||||
setu32(pp+4, (uint32_t)(v >> 32));
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Signed versions */
|
||||
#define gets8(p) ((int8_t) getu8(p))
|
||||
#define gets16(p) ((int16_t)getu16(p))
|
||||
#define gets32(p) ((int32_t)getu32(p))
|
||||
#define gets64(p) ((int64_t)getu64(p))
|
||||
|
||||
#define sets8(p,v) ((int8_t) setu8((p), (uint8_t)(v)))
|
||||
#define sets16(p,v) ((int16_t)setu16((p),(uint16_t)(v)))
|
||||
#define sets32(p,v) ((int32_t)setu32((p),(uint32_t)(v)))
|
||||
#define sets64(p,v) ((int64_t)setu64((p),(uint64_t)(v)))
|
||||
|
||||
/*
|
||||
* Some handy macros that will probably be of use in more than one
|
||||
* output format: convert integers into little-endian byte packed
|
||||
* format in memory, advancing the pointer.
|
||||
*/
|
||||
|
||||
#define WRITECHAR(p,v) \
|
||||
do { \
|
||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
||||
setu8(_wc_p, (v)); \
|
||||
(p) = (void *)(_wc_p+1); \
|
||||
} while (0)
|
||||
|
||||
#define WRITESHORT(p,v) \
|
||||
do { \
|
||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
||||
setu16(_wc_p, (v)); \
|
||||
(p) = (void *)(_wc_p+2); \
|
||||
} while (0)
|
||||
|
||||
#define WRITELONG(p,v) \
|
||||
do { \
|
||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
||||
setu32(_wc_p, (v)); \
|
||||
(p) = (void *)(_wc_p+4); \
|
||||
} while (0)
|
||||
|
||||
#define WRITEDLONG(p,v) \
|
||||
do { \
|
||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
||||
setu64(_wc_p, (v)); \
|
||||
(p) = (void *)(_wc_p+8); \
|
||||
} while (0)
|
||||
|
||||
#define WRITEADDR(p,v,s) \
|
||||
do { \
|
||||
const uint64_t _wa_v = htole64(v); \
|
||||
(p) = mempcpy((p), &_wa_v, (s)); \
|
||||
} while (0)
|
||||
|
||||
#endif /* NASM_BYTESEX_H */
|
||||
479
include/compiler.h
Normal file
479
include/compiler.h
Normal file
|
|
@ -0,0 +1,479 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2007-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* compiler.h
|
||||
*
|
||||
* Compiler-specific macros for NASM. Feel free to add support for
|
||||
* other compilers in here.
|
||||
*
|
||||
* This header file should be included before any other header.
|
||||
*/
|
||||
|
||||
#ifndef NASM_COMPILER_H
|
||||
#define NASM_COMPILER_H 1
|
||||
|
||||
/*
|
||||
* At least DJGPP and Cygwin have broken header files if __STRICT_ANSI__
|
||||
* is defined.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
# undef __STRICT_ANSI__
|
||||
#endif
|
||||
|
||||
/* On Microsoft platforms we support multibyte character sets in filenames */
|
||||
#define _MBCS 1
|
||||
|
||||
#include "autoconf/attribute.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config/config.h"
|
||||
#else
|
||||
# if defined(_MSC_VER) && (_MSC_VER >= 1310)
|
||||
# include "config/msvc.h"
|
||||
# elif defined(__WATCOMC__)
|
||||
# include "config/watcom.h"
|
||||
# else
|
||||
# include "config/unknown.h"
|
||||
# endif
|
||||
/* This unconditionally defines some macros we really want */
|
||||
# include "config/unconfig.h"
|
||||
#endif /* Configuration file */
|
||||
|
||||
/* This is required to get the standard <inttypes.h> macros when compiling
|
||||
with a C++ compiler. This must be defined *before* <inttypes.h> is
|
||||
included, directly or indirectly. */
|
||||
#define __STDC_CONSTANT_MACROS 1
|
||||
#define __STDC_LIMIT_MACROS 1
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# include "nasmint.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is impossible to do 100% accurately, because the actual type
|
||||
* of size_t may differ from its range.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
# define PRIz "I" /* Needed for msvcrt, not ucrt */
|
||||
#elif defined(PRINTF_SUPPORTS_Z) || \
|
||||
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
|
||||
# define PRIz "z"
|
||||
#elif SIZE_MAX == UINT_MAX
|
||||
# define PRIz ""
|
||||
#elif SIZE_MAX == ULONG_MAX
|
||||
# define PRIz "l"
|
||||
#elif SIZE_MAX == ULONGLONG_MAX
|
||||
# define PRIz "ll"
|
||||
#else
|
||||
# error "Unable to determine printf format for size_t"
|
||||
#endif
|
||||
#define PRIzd PRIz "u" /* size_t is always unsigned */
|
||||
#define PRIzu PRIz "u"
|
||||
#define PRIzu PRIz "u"
|
||||
#define PRIzx PRIz "x"
|
||||
#define PRIzX PRIz "X"
|
||||
|
||||
#ifdef HAVE_STDBIT_H
|
||||
|
||||
# include <stdbit.h>
|
||||
|
||||
# undef WORDS_LITTLEENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# if __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__
|
||||
# define WORDS_LITTLEENDIAN 1
|
||||
# elif __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_BIG__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
|
||||
#else /* No <stdbit.h> */
|
||||
|
||||
# ifdef HAVE_ENDIAN_H
|
||||
# include <endian.h>
|
||||
# elif defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
# elif defined(HAVE_MACHINE_ENDIAN_H)
|
||||
# include <machine/endian.h>
|
||||
# endif
|
||||
|
||||
/*
|
||||
* If we have BYTE_ORDER defined, or the compiler provides
|
||||
* __BIG_ENDIAN__ or __LITTLE_ENDIAN__, trust it over what autoconf
|
||||
* came up with, especially since autoconf obviously can't figure
|
||||
* things out for a universal compiler.
|
||||
*/
|
||||
# if defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
|
||||
# undef WORDS_LITTLEENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
||||
# undef WORDS_LITTLEENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# define WORDS_LITTLEENDIAN 1
|
||||
# elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
|
||||
# undef WORDS_LITTLEENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define WORDS_LITTLEENDIAN 1
|
||||
# elif BYTE_ORDER == BIG_ENDIAN
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define this to 1 for faster performance if this is a littleendian
|
||||
* platform *and* it can do arbitrary unaligned memory references. It
|
||||
* is safe to leave it defined to 0 even if that is true.
|
||||
*/
|
||||
#if defined(__386__) || defined(__i386__) || defined(__x86_64__) \
|
||||
|| defined(_M_IX86) || defined(_M_X64)
|
||||
# define X86_MEMORY 1
|
||||
# undef WORDS_BIGENDIAN
|
||||
# undef WORDS_LITTLEENDIAN
|
||||
# define WORDS_LITTLEENDIAN 1
|
||||
#else
|
||||
# define X86_MEMORY 0
|
||||
#endif
|
||||
|
||||
/* Some versions of MSVC have these only with underscores in front */
|
||||
#ifndef HAVE_SNPRINTF
|
||||
# ifdef HAVE__SNPRINTF
|
||||
# define snprintf _snprintf
|
||||
# else
|
||||
int snprintf(char *, size_t, const char *, ...);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef HAVE__VSNPRINTF
|
||||
# define vsnprintf _vsnprintf
|
||||
# else
|
||||
int vsnprintf(char *, size_t, const char *, va_list);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
#endif
|
||||
|
||||
/* C++ and C23 have bool, false, and true as proper keywords */
|
||||
#if !defined(__cplusplus) && (__STDC_VERSION__ < 202311L)
|
||||
# ifdef HAVE_STDBOOL_H
|
||||
# include <stdbool.h>
|
||||
# elif defined(HAVE___BOOL)
|
||||
typedef _Bool bool;
|
||||
# define false 0
|
||||
# define true 1
|
||||
# else
|
||||
/* This is a bit dangerous, because casting to this ersatz bool
|
||||
will not produce the same result as the standard (bool) cast.
|
||||
Instead, use the explicit construct !!x instead of relying on
|
||||
implicit conversions or casts. */
|
||||
typedef enum bool { false, true } bool;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Create a NULL pointer of the same type as the address of
|
||||
the argument, without actually evaluating said argument. */
|
||||
#define nullas(p) (0 ? &(p) : NULL)
|
||||
|
||||
/* Convert an offsetted NULL pointer dereference to a size_t offset.
|
||||
Technically non-portable as taking the offset from a NULL pointer
|
||||
is undefined behavior, but... */
|
||||
#define null_offset(p) ((size_t)((const char *)&(p) - (const char *)NULL))
|
||||
|
||||
/* Provide a substitute for offsetof() if we don't have one. This
|
||||
variant works on most (but not *all*) systems... */
|
||||
#ifndef offsetof
|
||||
# define offsetof(t,m) null_offset(((t *)NULL)->m)
|
||||
#endif
|
||||
|
||||
/* If typeof is defined as a macro, assume we have typeof even if
|
||||
HAVE_TYPEOF is not declared (e.g. due to not using autoconf.) */
|
||||
#ifdef typeof
|
||||
# define HAVE_TYPEOF 1
|
||||
#endif
|
||||
|
||||
/* This is like offsetof(), but takes an object rather than a type. */
|
||||
#ifndef offsetin
|
||||
# ifdef HAVE_TYPEOF
|
||||
# define offsetin(p,m) offsetof(typeof(p),m)
|
||||
# else
|
||||
# define offsetin(p,m) null_offset(nullas(p)->m)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The container_of construct: if p is a pointer to member m of
|
||||
container class c, then return a pointer to the container of which
|
||||
*p is a member. */
|
||||
#ifndef container_of
|
||||
# define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m)))
|
||||
#endif
|
||||
|
||||
/* Some misguided platforms hide the defs for these */
|
||||
#if defined(HAVE_STRCASECMP) && !HAVE_DECL_STRCASECMP
|
||||
int strcasecmp(const char *, const char *);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRICMP) && !HAVE_DECL_STRICMP
|
||||
int stricmp(const char *, const char *);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRNCASECMP) && !HAVE_DECL_STRNCASECMP
|
||||
int strncasecmp(const char *, const char *, size_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRNICMP) && !HAVE_DECL_STRNICMP
|
||||
int strnicmp(const char *, const char *, size_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRSEP) && !HAVE_DECL_STRSEP
|
||||
char *strsep(char **, const char *);
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_STRNLEN
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMPCPY
|
||||
static inline void *mempcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
return (char *)memcpy(dst, src, n) + n;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMPSET
|
||||
static inline void *mempset(void *dst, int c, size_t n)
|
||||
{
|
||||
return (char *)memset(dst, c, n) + n;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hack to support external-linkage inline functions
|
||||
*/
|
||||
#ifndef HAVE_STDC_INLINE
|
||||
# ifdef __GNUC__
|
||||
# ifdef __GNUC_STDC_INLINE__
|
||||
# define HAVE_STDC_INLINE
|
||||
# else
|
||||
# define HAVE_GNU_INLINE
|
||||
# endif
|
||||
# elif defined(__GNUC_GNU_INLINE__)
|
||||
/* Some other compiler implementing only GNU inline semantics? */
|
||||
# define HAVE_GNU_INLINE
|
||||
# elif defined(__STDC_VERSION__)
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# define HAVE_STDC_INLINE
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDC_INLINE
|
||||
# define extern_inline inline
|
||||
#elif defined(HAVE_GNU_INLINE)
|
||||
# define extern_inline extern inline
|
||||
# define inline_prototypes
|
||||
#else
|
||||
# define inline_prototypes
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hints to the compiler that a particular branch of code is more or
|
||||
* less likely to be taken.
|
||||
*/
|
||||
#ifdef HAVE___BUILTIN_EXPECT
|
||||
# define likely(x) __builtin_expect(!!(x), true)
|
||||
# define unlikely(x) __builtin_expect(!!(x), false)
|
||||
#else
|
||||
# define likely(x) (!!(x))
|
||||
# define unlikely(x) (!!(x))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE___BUILTIN_PREFETCH
|
||||
# define prefetch(x) __builtin_prefetch(x)
|
||||
#else
|
||||
# define prefetch(x) ((void)(x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Attributes
|
||||
*/
|
||||
|
||||
#define safe_alloc never_null malloc_func
|
||||
#define safe_alloc_ptr never_null_ptr malloc_func_ptr
|
||||
|
||||
#define safe_malloc(s) safe_alloc alloc_size_func1(s)
|
||||
#define safe_malloc2(s1,s2) safe_alloc alloc_size_func2(s1,s2)
|
||||
#define safe_realloc(s) never_null alloc_size_func1(s)
|
||||
#define safe_malloc_ptr(s) safe_alloc_ptr alloc_size_func1_ptr(s)
|
||||
#define safe_malloc2_ptr(s1,s2) safe_alloc_ptr alloc_size_func2_ptr(s1,s2)
|
||||
#define safe_realloc_ptr(s) never_null_ptr alloc_size_func1_ptr(s)
|
||||
|
||||
/*
|
||||
* How to tell the compiler that a function doesn't return
|
||||
*/
|
||||
#ifdef HAVE_STDNORETURN_H
|
||||
# include <stdnoreturn.h>
|
||||
# define no_return noreturn
|
||||
#elif defined(_MSC_VER)
|
||||
# define no_return __declspec(noreturn)
|
||||
#else
|
||||
# define no_return noreturn_func
|
||||
#endif
|
||||
|
||||
/* Function priority: pure < reproducible < unsequenced < const */
|
||||
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_REPRODUCIBLE
|
||||
# undef reproducible_func
|
||||
# define reproducible_func pure_func
|
||||
# undef reproducible_func_ptr
|
||||
# define reproducible_func_ptr pure_func_ptr
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_UNSEQUENCED
|
||||
# undef unsequenced_func
|
||||
# define unsequenced_func reproducible_func
|
||||
# undef unsequenced_func_ptr
|
||||
# define unsequenced_func_ptr reproducible_func_ptr
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_CONST
|
||||
# undef const_func
|
||||
# define const_func reproducible_func
|
||||
# undef const_func_ptr
|
||||
# define const_func_ptr reproducible_func_ptr
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A fatal function is both unlikely and no_return
|
||||
*/
|
||||
#define fatal_func no_return unlikely_func void
|
||||
#define static_fatal_func no_return unlikely_func static void
|
||||
|
||||
/*
|
||||
* How to tell the compiler that a function takes a printf-like string
|
||||
*/
|
||||
#define printf_func(fmt, list) format_func3(printf,fmt,list)
|
||||
#define printf_func_ptr(fmt, list) format_func3_ptr(printf,fmt,list)
|
||||
#define vprintf_func(fmt) format_func3(printf,fmt,0)
|
||||
#define vprintf_func_ptr(fmt) format_func3_ptr(printf,fmt,0)
|
||||
|
||||
/* Determine probabilistically if something is a compile-time constant */
|
||||
#ifdef HAVE___BUILTIN_CONSTANT_P
|
||||
# if defined(__GNUC__) && (__GNUC__ >= 5)
|
||||
# define is_constant(x) __builtin_constant_p((x))
|
||||
# else
|
||||
# define is_constant(x) false
|
||||
# endif
|
||||
#else
|
||||
# define is_constant(x) false
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If we can guarantee that a particular expression is constant, use it,
|
||||
* otherwise use a different version.
|
||||
*/
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 3)
|
||||
# define not_pedantic_start \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wpedantic\"")
|
||||
# define not_pedantic_end \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
# define not_pedantic_start
|
||||
# define not_pedantic_end
|
||||
#endif
|
||||
|
||||
#ifdef HAVE___BUILTIN_CHOOSE_EXPR
|
||||
# define if_constant(x,y) __builtin_choose_expr(is_constant(x),(x),(y))
|
||||
#else
|
||||
# define if_constant(x,y) (y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The autoconf documentation states:
|
||||
*
|
||||
* `va_copy'
|
||||
* The C99 standard provides `va_copy' for copying `va_list'
|
||||
* variables. It may be available in older environments too, though
|
||||
* possibly as `__va_copy' (e.g., `gcc' in strict pre-C99 mode).
|
||||
* These can be tested with `#ifdef'. A fallback to `memcpy (&dst,
|
||||
* &src, sizeof (va_list))' gives maximum portability.
|
||||
*/
|
||||
#ifndef va_copy
|
||||
# ifdef __va_copy
|
||||
# define va_copy(dst,src) __va_copy(dst,src)
|
||||
# else
|
||||
# define va_copy(dst,src) memcpy(&(dst),&(src),sizeof(va_list))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If SIZE_MAX is not defined, rely on size_t being unsigned
|
||||
*/
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX (((size_t)0) - 1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Current function name, if available, otherwise NULL
|
||||
*/
|
||||
#ifdef HAVE_FUNC_NAME
|
||||
# define NASM_FUNC __func__
|
||||
#else
|
||||
# define NASM_FUNC NULL
|
||||
#endif
|
||||
|
||||
/* Watcom doesn't handle switch statements with 64-bit types, hack around it */
|
||||
#ifdef __WATCOMC__
|
||||
# define BOGUS_CASE 0x76543210
|
||||
|
||||
static inline unsigned int watcom_switch_hack(uint64_t x)
|
||||
{
|
||||
if (x > (uint64_t)UINT_MAX)
|
||||
return BOGUS_CASE;
|
||||
else
|
||||
return (unsigned int)x;
|
||||
}
|
||||
|
||||
# define switch(x) switch(sizeof(x) > sizeof(unsigned int) \
|
||||
? watcom_switch_hack(x) : (unsigned int)(x))
|
||||
|
||||
/* This is to make sure BOGUS_CASE doesn't conflict with anything real... */
|
||||
# define default case BOGUS_CASE: default
|
||||
#endif
|
||||
|
||||
#ifndef unreachable /* C23 defines as a macro in <stddef.h> */
|
||||
# ifdef HAVE___BUILTIN_UNREACHABLE
|
||||
# define unreachable() __builtin_unreachable()
|
||||
# else
|
||||
# define unreachable() do { abort(); } while(1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This should be set from main() */
|
||||
extern const char *_progname;
|
||||
|
||||
#endif /* NASM_COMPILER_H */
|
||||
1036
include/config.h
Normal file
1036
include/config.h
Normal file
File diff suppressed because it is too large
Load diff
1036
include/config/config.h
Normal file
1036
include/config/config.h
Normal file
File diff suppressed because it is too large
Load diff
1035
include/config/config.h.in
Normal file
1035
include/config/config.h.in
Normal file
File diff suppressed because it is too large
Load diff
166
include/config/msvc.h
Normal file
166
include/config/msvc.h
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/msvc.h
|
||||
*
|
||||
* Compiler definitions for Microsoft Visual C++;
|
||||
* instead of unconfig.h. See config.h.in for the
|
||||
* variables which can be defined here.
|
||||
*
|
||||
* MSDN seems to have information back to Visual Studio 2003, so aim
|
||||
* for compatibility that far back.
|
||||
*
|
||||
* Relevant _MSC_VER values:
|
||||
* 1310 - Visual Studio 2003
|
||||
* 1400 - Visual Studio 2005
|
||||
* 1500 - Visual Studio 2008
|
||||
* 1600 - Visual Studio 2010
|
||||
* 1700 - Visual Studio 2012
|
||||
* 1800 - Visual Studio 2013
|
||||
* 1900 - Visual Studio 2015
|
||||
* 1910 - Visual Studio 2017
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_MSVC_H
|
||||
#define NASM_CONFIG_MSVC_H
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#if _MSC_VER >= 1800
|
||||
# define HAVE_INTTYPES_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
#define HAVE_IO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `access' function. */
|
||||
#define HAVE_ACCESS 1
|
||||
#if _MSC_VER < 1400
|
||||
# define access _access
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `fileno' function. */
|
||||
#define HAVE_FILENO 1
|
||||
#if _MSC_VER < 1400
|
||||
# define fileno _fileno
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#define HAVE_SNPRINTF 1
|
||||
#if _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `_chsize' function. */
|
||||
#define HAVE__CHSIZE 1
|
||||
|
||||
/* Define to 1 if you have the `_chsize_s' function. */
|
||||
#if _MSC_VER >= 1400
|
||||
# define HAVE__CHSIZE_S 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `_filelengthi64' function. */
|
||||
#define HAVE__FILELENGTHI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fseeki64' function. */
|
||||
#define HAVE__FSEEKI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fullpath' function. */
|
||||
#define HAVE__FULLPATH 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct _stati64'. */
|
||||
#define HAVE_STRUCT__STATI64
|
||||
|
||||
/* Define to 1 if you have the `_stati64' function. */
|
||||
#define HAVE__STATI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fstati64' function. */
|
||||
#define HAVE__FSTATI64 1
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#if _MSC_VER >= 1800
|
||||
# define HAVE_STDBOOL_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `stricmp' function. */
|
||||
#define HAVE_STRICMP 1
|
||||
/* Define to 1 if you have the declaration of `stricmp', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_STRICMP 1
|
||||
#if _MSC_VER < 1400
|
||||
# define stricmp _stricmp
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `strnicmp' function. */
|
||||
#define HAVE_STRNICMP 1
|
||||
/* Define to 1 if you have the declaration of `strnicmp', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_STRNICMP 1
|
||||
#if _MSC_VER < 1400
|
||||
# define strnicmp _strnicmp
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
# define HAVE_STRNLEN 1
|
||||
/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
|
||||
don't. */
|
||||
# define HAVE_DECL_STRNLEN 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the system has the type `uintptr_t'. */
|
||||
#if _MSC_VER >= 1900
|
||||
# define HAVE_UINTPTR_T 1
|
||||
#else
|
||||
/* Define to the type of an unsigned integer type wide enough to hold a
|
||||
pointer, if such a type exists, and if the system does not define it. */
|
||||
# define uintptr_t size_t
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#if _MSC_VER < 1400
|
||||
# define vsnprint _vsnprintf
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#if _MSC_VER >= 1900
|
||||
# define HAVE__BOOL 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if your processor stores words with the least significant byte
|
||||
first (like Intel and VAX, unlike Motorola and SPARC). */
|
||||
#define WORDS_LITTLEENDIAN 1
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#define inline __inline
|
||||
|
||||
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
nothing if this is not supported. Do not define if restrict is
|
||||
supported directly. */
|
||||
#if _MSC_VER >= 1700
|
||||
#define restrict __restrict
|
||||
#else
|
||||
#define restrict
|
||||
#endif
|
||||
|
||||
#endif /* NASM_CONFIG_MSVC_H */
|
||||
230
include/config/unconfig.h
Normal file
230
include/config/unconfig.h
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
/* config/unconfig.h: autogenerated by tools/unconfig.pl */
|
||||
|
||||
#ifndef CONFIG_UNCONFIG_H
|
||||
#define CONFIG_UNCONFIG_H
|
||||
|
||||
#ifndef alloc_size_func2
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_2_ALLOC_SIZE
|
||||
# define alloc_size_func2(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
|
||||
# else
|
||||
# define alloc_size_func2(x1,x2)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func2_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_2_ALLOC_SIZE
|
||||
# define alloc_size_func2_ptr(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
|
||||
# else
|
||||
# define alloc_size_func2_ptr(x1,x2)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef end_with_null
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_SENTINEL
|
||||
# define end_with_null ATTRIBUTE(sentinel)
|
||||
# else
|
||||
# define end_with_null
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef end_with_null_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_SENTINEL
|
||||
# define end_with_null_ptr ATTRIBUTE(sentinel)
|
||||
# else
|
||||
# define end_with_null_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef format_func3
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_3_FORMAT
|
||||
# define format_func3(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
|
||||
# else
|
||||
# define format_func3(x1,x2,x3)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef format_func3_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_3_FORMAT
|
||||
# define format_func3_ptr(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
|
||||
# else
|
||||
# define format_func3_ptr(x1,x2,x3)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef const_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_CONST
|
||||
# define const_func ATTRIBUTE(const)
|
||||
# else
|
||||
# define const_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef const_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_CONST
|
||||
# define const_func_ptr ATTRIBUTE(const)
|
||||
# else
|
||||
# define const_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unsequenced_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_UNSEQUENCED
|
||||
# define unsequenced_func ATTRIBUTE(unsequenced)
|
||||
# else
|
||||
# define unsequenced_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unsequenced_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_UNSEQUENCED
|
||||
# define unsequenced_func_ptr ATTRIBUTE(unsequenced)
|
||||
# else
|
||||
# define unsequenced_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef noreturn_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
|
||||
# define noreturn_func ATTRIBUTE(noreturn)
|
||||
# else
|
||||
# define noreturn_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef reproducible_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_REPRODUCIBLE
|
||||
# define reproducible_func ATTRIBUTE(reproducible)
|
||||
# else
|
||||
# define reproducible_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef reproducible_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_REPRODUCIBLE
|
||||
# define reproducible_func_ptr ATTRIBUTE(reproducible)
|
||||
# else
|
||||
# define reproducible_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef pure_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_PURE
|
||||
# define pure_func ATTRIBUTE(pure)
|
||||
# else
|
||||
# define pure_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef pure_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_PURE
|
||||
# define pure_func_ptr ATTRIBUTE(pure)
|
||||
# else
|
||||
# define pure_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unlikely_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_COLD
|
||||
# define unlikely_func ATTRIBUTE(cold)
|
||||
# else
|
||||
# define unlikely_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unlikely_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_COLD
|
||||
# define unlikely_func_ptr ATTRIBUTE(cold)
|
||||
# else
|
||||
# define unlikely_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef maybe_unused_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_MAYBE_UNUSED
|
||||
# define maybe_unused_func ATTRIBUTE(maybe_unused)
|
||||
# else
|
||||
# define maybe_unused_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef maybe_unused_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_MAYBE_UNUSED
|
||||
# define maybe_unused_func_ptr ATTRIBUTE(maybe_unused)
|
||||
# else
|
||||
# define maybe_unused_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unused_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
|
||||
# define unused_func ATTRIBUTE(unused)
|
||||
# else
|
||||
# define unused_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unused_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_UNUSED
|
||||
# define unused_func_ptr ATTRIBUTE(unused)
|
||||
# else
|
||||
# define unused_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef noreturn_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_NORETURN
|
||||
# define noreturn_func_ptr ATTRIBUTE(noreturn)
|
||||
# else
|
||||
# define noreturn_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef never_null
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
|
||||
# define never_null ATTRIBUTE(returns_nonnull)
|
||||
# else
|
||||
# define never_null
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef never_null_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_RETURNS_NONNULL
|
||||
# define never_null_ptr ATTRIBUTE(returns_nonnull)
|
||||
# else
|
||||
# define never_null_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef malloc_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
|
||||
# define malloc_func ATTRIBUTE(malloc)
|
||||
# else
|
||||
# define malloc_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef malloc_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_MALLOC
|
||||
# define malloc_func_ptr ATTRIBUTE(malloc)
|
||||
# else
|
||||
# define malloc_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func1
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_1_ALLOC_SIZE
|
||||
# define alloc_size_func1(x1) ATTRIBUTE(alloc_size(x1))
|
||||
# else
|
||||
# define alloc_size_func1(x1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func1_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_1_ALLOC_SIZE
|
||||
# define alloc_size_func1_ptr(x1) ATTRIBUTE(alloc_size(x1))
|
||||
# else
|
||||
# define alloc_size_func1_ptr(x1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_UNCONFIG_H */
|
||||
21
include/config/unknown.h
Normal file
21
include/config/unknown.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/unknown.h
|
||||
*
|
||||
* Compiler definitions for an unknown compiler. Assume the worst.
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_UNKNOWN_H
|
||||
#define NASM_CONFIG_UNKNOWN_H
|
||||
|
||||
/* Assume these don't exist */
|
||||
#ifndef inline
|
||||
# define inline
|
||||
#endif
|
||||
#ifndef restrict
|
||||
# define restrict
|
||||
#endif
|
||||
|
||||
#endif /* NASM_CONFIG_UNKNOWN_H */
|
||||
75
include/config/watcom.h
Normal file
75
include/config/watcom.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/watcom.h
|
||||
*
|
||||
* Compiler definitions for OpenWatcom instead of config.h.in.
|
||||
* See config.h.in for the variables which can be defined here.
|
||||
*
|
||||
* This was taken from openwcom.mak and needs to be actually validated.
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_WATCOM_H
|
||||
#define NASM_CONFIG_WATCOM_H
|
||||
|
||||
#define HAVE_DECL_STRCASECMP 1
|
||||
#define HAVE_DECL_STRICMP 1
|
||||
#define HAVE_DECL_STRLCPY 1
|
||||
#define HAVE_DECL_STRNCASECMP 1
|
||||
#define HAVE_DECL_STRNICMP 1
|
||||
#ifndef __LINUX__
|
||||
#define HAVE_IO_H 1
|
||||
#endif
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_MEMORY_H 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#if (__WATCOMC__ >= 1230)
|
||||
#undef HAVE__BOOL /* need stdbool.h */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_UINTPTR_T 1
|
||||
#endif
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRCSPN 1
|
||||
#define HAVE_STRICMP 1
|
||||
#define HAVE_STRNICMP 1
|
||||
#define HAVE_STRSPN 1
|
||||
#define HAVE_STRING_H 1
|
||||
#if (__WATCOMC__ >= 1240)
|
||||
#define HAVE_STRCASECMP 1
|
||||
#define HAVE_STRNCASECMP 1
|
||||
#define HAVE_STRLCPY 1
|
||||
#define HAVE_STRINGS_H 1
|
||||
#endif
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
#define HAVE__FULLPATH 1
|
||||
#define HAVE_ACCESS
|
||||
#define HAVE_STRUCT_STAT
|
||||
#define HAVE_STAT
|
||||
#define HAVE_FSTAT
|
||||
#define HAVE_FILENO
|
||||
#ifdef __LINUX__
|
||||
#define HAVE_FTRUNCATE
|
||||
#else
|
||||
#define HAVE_CHSIZE
|
||||
#define HAVE__CHSIZE
|
||||
#endif
|
||||
#define HAVE_ISASCII
|
||||
#define HAVE_ISCNTRL
|
||||
|
||||
#if (__WATCOMC__ >= 1250)
|
||||
#define restrict __restrict
|
||||
#else
|
||||
#define restrict
|
||||
#endif
|
||||
#define inline __inline
|
||||
|
||||
#endif /* NASM_CONFIG_WATCOM_H */
|
||||
9446
include/crc32.h
Normal file
9446
include/crc32.h
Normal file
File diff suppressed because it is too large
Load diff
85
include/dbginfo.h
Normal file
85
include/dbginfo.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* dbginfo.h - debugging info structures
|
||||
*/
|
||||
|
||||
#ifndef NASM_DBGINFO_H
|
||||
#define NASM_DBGINFO_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "srcfile.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
struct debug_macro_def; /* Definition */
|
||||
struct debug_macro_inv; /* Invocation */
|
||||
struct debug_macro_addr; /* Address range */
|
||||
|
||||
/*
|
||||
* Definitions structure, one for each non-.nolist macro invoked
|
||||
* anywhere in the program; unique for each macro, even if a macro is
|
||||
* redefined and/or overloaded.
|
||||
*/
|
||||
struct debug_macro_def {
|
||||
struct debug_macro_def *next; /* List of definitions */
|
||||
const char *name; /* Macro name */
|
||||
struct src_location where; /* Start of definition */
|
||||
size_t ninv; /* Call count */
|
||||
};
|
||||
|
||||
/*
|
||||
* Invocation structure. One for each invocation of a non-.nolist macro.
|
||||
*/
|
||||
struct debug_macro_inv_list {
|
||||
struct debug_macro_inv *l;
|
||||
size_t n;
|
||||
};
|
||||
|
||||
struct debug_macro_inv {
|
||||
struct debug_macro_inv *next; /* List of same-level invocations */
|
||||
struct debug_macro_inv_list down;
|
||||
struct debug_macro_inv *up; /* Parent invocation */
|
||||
struct debug_macro_def *def; /* Macro definition */
|
||||
struct src_location where; /* Start of invocation */
|
||||
struct { /* Address range pointers */
|
||||
struct rbtree *tree; /* rbtree of address ranges */
|
||||
struct debug_macro_addr *last; /* Quick lookup for latest section */
|
||||
} addr;
|
||||
uint32_t naddr; /* Number of address ranges */
|
||||
int32_t lastseg; /* lastaddr segment number */
|
||||
};
|
||||
|
||||
/*
|
||||
* Address range structure. An rbtree containing one address range for each
|
||||
* section which this particular macro has generated code/data/space into.
|
||||
*/
|
||||
struct debug_macro_addr {
|
||||
struct rbtree tree; /* rbtree; key = index, must be first */
|
||||
struct debug_macro_addr *up; /* same section in parent invocation */
|
||||
uint64_t start; /* starting offset */
|
||||
uint64_t len; /* length of range */
|
||||
};
|
||||
|
||||
/*
|
||||
* Complete information structure */
|
||||
struct debug_macro_info {
|
||||
struct debug_macro_inv_list inv;
|
||||
struct debug_macro_def_list {
|
||||
struct debug_macro_def *l;
|
||||
size_t n;
|
||||
} def;
|
||||
};
|
||||
|
||||
static inline int32_t debug_macro_seg(const struct debug_macro_addr *dma)
|
||||
{
|
||||
return dma->tree.key;
|
||||
}
|
||||
|
||||
/* Get/create a addr structure for the macro we are emitting for */
|
||||
struct debug_macro_addr *debug_macro_get_addr(int32_t seg);
|
||||
|
||||
/* The macro we are currently emitting for, if any */
|
||||
extern struct debug_macro_inv *debug_current_macro;
|
||||
|
||||
#endif /* NASM_DBGINFO_H */
|
||||
104
include/directiv.h
Normal file
104
include/directiv.h
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* This file is generated from ./asm/directiv.dat
|
||||
* by perfhash.pl; do not edit.
|
||||
*/
|
||||
|
||||
#ifndef DIRECTIV_H
|
||||
#define DIRECTIV_H 1
|
||||
|
||||
#include "perfhash.h"
|
||||
|
||||
enum directive {
|
||||
D_none,
|
||||
D_unknown,
|
||||
D_corrupt,
|
||||
D_ABSOLUTE,
|
||||
D_BITS,
|
||||
D_COMMON,
|
||||
D_CPU,
|
||||
D_DEBUG,
|
||||
D_DEFAULT,
|
||||
D_DOLLARHEX,
|
||||
D_EXTERN,
|
||||
D_FLOAT,
|
||||
D_GLOBAL,
|
||||
D_LIST,
|
||||
D_PRAGMA,
|
||||
D_REQUIRED,
|
||||
D_SECTALIGN,
|
||||
D_SECTION,
|
||||
D_SEGMENT,
|
||||
D_STATIC,
|
||||
D_WARNING,
|
||||
D_PREFIX,
|
||||
D_SUFFIX,
|
||||
D_POSTFIX,
|
||||
D_GPREFIX,
|
||||
D_GSUFFIX,
|
||||
D_GPOSTFIX,
|
||||
D_LPREFIX,
|
||||
D_LSUFFIX,
|
||||
D_LPOSTFIX,
|
||||
D_pseudo_ops,
|
||||
D_DB,
|
||||
D_DW,
|
||||
D_DD,
|
||||
D_DQ,
|
||||
D_DT,
|
||||
D_DO,
|
||||
D_DY,
|
||||
D_DZ,
|
||||
D_RESB,
|
||||
D_RESW,
|
||||
D_RESD,
|
||||
D_RESQ,
|
||||
D_REST,
|
||||
D_RESO,
|
||||
D_RESY,
|
||||
D_RESZ,
|
||||
D_INCBIN,
|
||||
D_EQU,
|
||||
D_ofmt,
|
||||
D_EXPORT,
|
||||
D_GROUP,
|
||||
D_IMPORT,
|
||||
D_LIBRARY,
|
||||
D_MAP,
|
||||
D_MODULE,
|
||||
D_ORG,
|
||||
D_OSABI,
|
||||
D_SAFESEH,
|
||||
D_UPPERCASE,
|
||||
D_pragma_tokens,
|
||||
D_LIMIT,
|
||||
D_OPTIONS,
|
||||
D_SUBSECTIONS_VIA_SYMBOLS,
|
||||
D_NO_DEAD_STRIP,
|
||||
D_MAXDUMP,
|
||||
D_NODEPEND,
|
||||
D_NOSECLABELS
|
||||
};
|
||||
|
||||
extern const struct perfect_hash directive_hash;
|
||||
extern const char * const directive_tbl[65];
|
||||
|
||||
static inline enum directive directive_find(const char *str)
|
||||
{
|
||||
return perfhash_find(&directive_hash, str);
|
||||
}
|
||||
|
||||
static inline const char * directive_name(enum directive x)
|
||||
{
|
||||
size_t ix = (size_t)x - (3);
|
||||
if (ix >= 65)
|
||||
return NULL;
|
||||
return directive_tbl[ix];
|
||||
}
|
||||
|
||||
static inline const char * directive_dname(enum directive x)
|
||||
{
|
||||
const char *y = directive_name(x);
|
||||
return y ? y : invalid_enum_str(x);
|
||||
}
|
||||
|
||||
#endif /* DIRECTIV_H */
|
||||
94
include/disasm.h
Normal file
94
include/disasm.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* disasm.h header file for disasm.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_DISASM_H
|
||||
#define NASM_DISASM_H
|
||||
|
||||
#include "nasm.h"
|
||||
#include "insnsi.h"
|
||||
#include "iflag.h"
|
||||
|
||||
/*
|
||||
* This buffer must be at least twice as long as the max instruction,
|
||||
* which must include the WAIT pseudo-prefix, for a total of 15+1 = 16
|
||||
* bytes.
|
||||
*/
|
||||
#define INSN_MAX 32
|
||||
|
||||
int32_t disasm(const uint8_t *dp, int32_t data_size,
|
||||
char *output, int outbufsize,
|
||||
int segsize, int64_t offset, int autosync,
|
||||
iflag_t *prefer);
|
||||
int32_t eatbyte(uint8_t byte, char *output, int outbufsize, int segsize);
|
||||
|
||||
/* The rex types that matter for the purpose of decoding */
|
||||
enum rextype {
|
||||
REX_NONE,
|
||||
REX_REX,
|
||||
REX_REX2,
|
||||
REX_VEX, /* Includes XOP */
|
||||
REX_EVEX
|
||||
};
|
||||
|
||||
/*
|
||||
* Prefix information
|
||||
*/
|
||||
struct rexfields {
|
||||
uint32_t raw; /* Raw value */
|
||||
uint32_t flags; /* REX_ flags from nasm.h */
|
||||
enum rextype type;
|
||||
uint8_t len; /* Length of REX prefix */
|
||||
uint8_t breg; /* B register */
|
||||
uint8_t bregbv; /* B register if B is a vector */
|
||||
uint8_t xreg; /* X register */
|
||||
uint8_t xregxv; /* X register if X is a vector */
|
||||
uint8_t vreg; /* V register */
|
||||
uint8_t vregxv; /* V register if X is a vector */
|
||||
uint8_t rreg;
|
||||
uint8_t opc; /* Masked opcode */
|
||||
uint8_t map;
|
||||
uint8_t xmap; /* Extended map (base from insnsi.h added) */
|
||||
uint8_t pp;
|
||||
uint8_t w;
|
||||
uint8_t l;
|
||||
uint8_t z;
|
||||
uint8_t b;
|
||||
uint8_t nd;
|
||||
uint8_t zu;
|
||||
uint8_t aaa;
|
||||
uint8_t nf;
|
||||
uint8_t dfl;
|
||||
uint8_t scc;
|
||||
};
|
||||
|
||||
struct prefix_info {
|
||||
uint8_t osize; /* Operand size */
|
||||
uint8_t asize; /* Address size */
|
||||
uint8_t osp; /* Operand size prefix present */
|
||||
uint8_t asp; /* Address size prefix present */
|
||||
uint8_t rep; /* Rep prefix present */
|
||||
uint8_t seg; /* Segment override prefix present */
|
||||
uint8_t wait; /* WAIT "prefix" present */
|
||||
uint8_t lock; /* Lock prefix present */
|
||||
enum reg_enum segover; /* Segment override register enum */
|
||||
struct rexfields rex; /* REX/REX2/VEX/EVEX */
|
||||
};
|
||||
|
||||
const uint8_t *parse_prefixes(struct prefix_info *pf, const uint8_t *data,
|
||||
int bits);
|
||||
|
||||
#define fetch_safe(_start, _ptr, _size, _need, _op) \
|
||||
do { \
|
||||
if (((_ptr) - (_start)) >= ((_size) - (_need))) \
|
||||
_op; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Error module */
|
||||
void usage(void);
|
||||
|
||||
#endif
|
||||
89
include/disp8.h
Normal file
89
include/disp8.h
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2024 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* disp8.h header file for disp8.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_DISP8_H
|
||||
#define NASM_DISP8_H
|
||||
|
||||
#include "nasm.h"
|
||||
|
||||
/*
|
||||
* Find shift value for compressed displacement (disp8 << shift)
|
||||
*/
|
||||
static inline unsigned int get_disp8_shift(const insn *ins)
|
||||
{
|
||||
bool evex_b;
|
||||
unsigned int evex_w;
|
||||
unsigned int vectlen;
|
||||
enum ttypes tuple = ins->evex_tuple;
|
||||
|
||||
if (likely(!tuple))
|
||||
return 0;
|
||||
|
||||
evex_b = !!(ins->evex & EVEX_B);
|
||||
evex_w = !!(ins->evex & EVEX_W);
|
||||
/* XXX: consider RC/SAE here?! */
|
||||
vectlen = getfield(EVEX_LL, ins->evex);
|
||||
|
||||
switch (tuple) {
|
||||
/* Full, half vector unless broadcast */
|
||||
case FV:
|
||||
return evex_b ? 2 + evex_w : vectlen + 4;
|
||||
case HV:
|
||||
return evex_b ? 2 + evex_w : vectlen + 3;
|
||||
|
||||
/* Full vector length */
|
||||
case FVM:
|
||||
return vectlen + 4;
|
||||
|
||||
/* Fixed tuple lengths */
|
||||
case T1S8:
|
||||
return 0;
|
||||
case T1S16:
|
||||
return 1;
|
||||
case T1F32:
|
||||
return 2;
|
||||
case T1F64:
|
||||
return 3;
|
||||
case M128:
|
||||
return 4;
|
||||
|
||||
/* One scalar */
|
||||
case T1S:
|
||||
return 2 + evex_w;
|
||||
|
||||
/* 2, 4, 8 32/64-bit elements */
|
||||
case T2:
|
||||
return 3 + evex_w;
|
||||
case T4:
|
||||
return 4 + evex_w;
|
||||
case T8:
|
||||
return 5 + evex_w;
|
||||
|
||||
/* Half, quarter, eigth mem */
|
||||
case HVM:
|
||||
return vectlen + 3;
|
||||
case QVM:
|
||||
return vectlen + 2;
|
||||
case OVM:
|
||||
return vectlen + 1;
|
||||
|
||||
/* MOVDDUP */
|
||||
case DUP:
|
||||
/*
|
||||
* 128-bit vector case doesn't follow the same formula as 256- and
|
||||
* 512-bit vectors.
|
||||
*/
|
||||
if (!vectlen)
|
||||
return 3;
|
||||
return vectlen + 4;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* NASM_DISP8_H */
|
||||
591
include/dwarf.h
Normal file
591
include/dwarf.h
Normal file
|
|
@ -0,0 +1,591 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef OUTPUT_DWARF_H
|
||||
#define OUTPUT_DWARF_H
|
||||
|
||||
/*
|
||||
* based on DWARF 3 standard
|
||||
*/
|
||||
|
||||
enum dwarf_tag {
|
||||
DW_TAG_padding = 0x00,
|
||||
DW_TAG_array_type = 0x01,
|
||||
DW_TAG_class_type = 0x02,
|
||||
DW_TAG_entry_point = 0x03,
|
||||
DW_TAG_enumeration_type = 0x04,
|
||||
DW_TAG_formal_parameter = 0x05,
|
||||
DW_TAG_global_subroutine = 0x06,
|
||||
DW_TAG_global_variable = 0x07,
|
||||
DW_TAG_label = 0x0a,
|
||||
DW_TAG_lexical_block = 0x0b,
|
||||
DW_TAG_local_variable = 0x0c,
|
||||
DW_TAG_member = 0x0d,
|
||||
DW_TAG_pointer_type = 0x0f,
|
||||
DW_TAG_reference_type = 0x10,
|
||||
DW_TAG_compile_unit = 0x11,
|
||||
DW_TAG_string_type = 0x12,
|
||||
DW_TAG_structure_type = 0x13,
|
||||
DW_TAG_subroutine = 0x14,
|
||||
DW_TAG_subroutine_type = 0x15,
|
||||
DW_TAG_typedef = 0x16,
|
||||
DW_TAG_union_type = 0x17,
|
||||
DW_TAG_unspecified_parameters = 0x18,
|
||||
DW_TAG_variant = 0x19,
|
||||
DW_TAG_common_block = 0x1a,
|
||||
DW_TAG_common_inclusion = 0x1b,
|
||||
DW_TAG_inheritance = 0x1c,
|
||||
DW_TAG_inlined_subroutine = 0x1d,
|
||||
DW_TAG_module = 0x1e,
|
||||
DW_TAG_ptr_to_member_type = 0x1f,
|
||||
DW_TAG_set_type = 0x20,
|
||||
DW_TAG_subrange_type = 0x21,
|
||||
DW_TAG_with_stmt = 0x22,
|
||||
DW_TAG_access_declaration = 0x23,
|
||||
DW_TAG_base_type = 0x24,
|
||||
DW_TAG_catch_block = 0x25,
|
||||
DW_TAG_const_type = 0x26,
|
||||
DW_TAG_constant = 0x27,
|
||||
DW_TAG_enumerator = 0x28,
|
||||
DW_TAG_file_type = 0x29,
|
||||
DW_TAG_friend = 0x2a,
|
||||
DW_TAG_namelist = 0x2b,
|
||||
DW_TAG_namelist_item = 0x2c,
|
||||
DW_TAG_packed_type = 0x2d,
|
||||
DW_TAG_subprogram = 0x2e,
|
||||
DW_TAG_template_type_parameter = 0x2f,
|
||||
DW_TAG_template_value_parameter = 0x30,
|
||||
DW_TAG_thrown_type = 0x31,
|
||||
DW_TAG_try_block = 0x32,
|
||||
DW_TAG_variant_part = 0x33,
|
||||
DW_TAG_variable = 0x34,
|
||||
DW_TAG_volatile_type = 0x35,
|
||||
/* DWARF 3 */
|
||||
DW_TAG_dwarf_procedure = 0x36,
|
||||
DW_TAG_restrict_type = 0x37,
|
||||
DW_TAG_interface_type = 0x38,
|
||||
DW_TAG_namespace = 0x39,
|
||||
DW_TAG_imported_module = 0x3a,
|
||||
DW_TAG_unspecified_type = 0x3b,
|
||||
DW_TAG_partial_unit = 0x3c,
|
||||
DW_TAG_imported_unit = 0x3d,
|
||||
DW_TAG_condition = 0x3f,
|
||||
DW_TAG_shared_type = 0x40,
|
||||
/* DWARF 4 */
|
||||
DW_TAG_type_unit = 0x41,
|
||||
DW_TAG_rvalue_reference_type = 0x42,
|
||||
DW_TAG_template_alias = 0x43,
|
||||
/* DWARF 5 */
|
||||
DW_TAG_atomic_type = 0x47,
|
||||
|
||||
DW_TAG_lo_user = 0x4080,
|
||||
DW_TAG_hi_user = 0xffff
|
||||
};
|
||||
|
||||
enum dwarf_child {
|
||||
DW_CHILDREN_no = 0x00,
|
||||
DW_CHILDREN_yes = 0x01
|
||||
};
|
||||
|
||||
enum dwarf_form {
|
||||
DW_FORM_addr = 0x01,
|
||||
DW_FORM_block2 = 0x03,
|
||||
DW_FORM_block4 = 0x04,
|
||||
DW_FORM_data2 = 0x05,
|
||||
DW_FORM_data4 = 0x06,
|
||||
DW_FORM_data8 = 0x07,
|
||||
DW_FORM_string = 0x08,
|
||||
DW_FORM_block = 0x09,
|
||||
DW_FORM_block1 = 0x0a,
|
||||
DW_FORM_data1 = 0x0b,
|
||||
DW_FORM_flag = 0x0c,
|
||||
DW_FORM_sdata = 0x0d,
|
||||
DW_FORM_strp = 0x0e,
|
||||
DW_FORM_udata = 0x0f,
|
||||
DW_FORM_ref_addr = 0x10,
|
||||
DW_FORM_ref1 = 0x11,
|
||||
DW_FORM_ref2 = 0x12,
|
||||
DW_FORM_ref4 = 0x13,
|
||||
DW_FORM_ref8 = 0x14,
|
||||
DW_FORM_ref_udata = 0x15,
|
||||
DW_FORM_indirect = 0x16,
|
||||
/* DWARF 4 */
|
||||
DW_FORM_sec_offset = 0x17,
|
||||
DW_FORM_exprloc = 0x18,
|
||||
DW_FORM_flag_present = 0x19,
|
||||
DW_FORM_ref_sig8 = 0x20
|
||||
};
|
||||
|
||||
enum dwarf_attribute {
|
||||
DW_AT_sibling = 0x01,
|
||||
DW_AT_location = 0x02,
|
||||
DW_AT_name = 0x03,
|
||||
DW_AT_ordering = 0x09,
|
||||
DW_AT_byte_size = 0x0b,
|
||||
DW_AT_bit_offset = 0x0c,
|
||||
DW_AT_bit_size = 0x0d,
|
||||
DW_AT_stmt_list = 0x10,
|
||||
DW_AT_low_pc = 0x11,
|
||||
DW_AT_high_pc = 0x12,
|
||||
DW_AT_language = 0x13,
|
||||
DW_AT_discr = 0x15,
|
||||
DW_AT_discr_value = 0x16,
|
||||
DW_AT_visibility = 0x17,
|
||||
DW_AT_import = 0x18,
|
||||
DW_AT_string_length = 0x19,
|
||||
DW_AT_common_reference = 0x1a,
|
||||
DW_AT_comp_dir = 0x1b,
|
||||
DW_AT_const_value = 0x1c,
|
||||
DW_AT_containing_type = 0x1d,
|
||||
DW_AT_default_value = 0x1e,
|
||||
DW_AT_inline = 0x20,
|
||||
DW_AT_is_optional = 0x21,
|
||||
DW_AT_lower_bound = 0x22,
|
||||
DW_AT_producer = 0x25,
|
||||
DW_AT_prototyped = 0x27,
|
||||
DW_AT_return_addr = 0x2a,
|
||||
DW_AT_start_scope = 0x2c,
|
||||
DW_AT_bit_stride = 0x2e,
|
||||
DW_AT_upper_bound = 0x2f,
|
||||
DW_AT_abstract_origin = 0x31,
|
||||
DW_AT_accessibility = 0x32,
|
||||
DW_AT_address_class = 0x33,
|
||||
DW_AT_artificial = 0x34,
|
||||
DW_AT_base_types = 0x35,
|
||||
DW_AT_calling_convention= 0x36,
|
||||
DW_AT_count = 0x37,
|
||||
DW_AT_data_member_location = 0x38,
|
||||
DW_AT_decl_column = 0x39,
|
||||
DW_AT_decl_file = 0x3a,
|
||||
DW_AT_decl_line = 0x3b,
|
||||
DW_AT_declaration = 0x3c,
|
||||
DW_AT_discr_list = 0x3d,
|
||||
DW_AT_encoding = 0x3e,
|
||||
DW_AT_external = 0x3f,
|
||||
DW_AT_frame_base = 0x40,
|
||||
DW_AT_friend = 0x41,
|
||||
DW_AT_identifier_case = 0x42,
|
||||
DW_AT_macro_info = 0x43,
|
||||
DW_AT_namelist_item = 0x44,
|
||||
DW_AT_priority = 0x45,
|
||||
DW_AT_segment = 0x46,
|
||||
DW_AT_specification = 0x47,
|
||||
DW_AT_static_link = 0x48,
|
||||
DW_AT_type = 0x49,
|
||||
DW_AT_use_location = 0x4a,
|
||||
DW_AT_variable_parameter = 0x4b,
|
||||
DW_AT_virtuality = 0x4c,
|
||||
DW_AT_vtable_elem_location = 0x4d,
|
||||
/* DWARF 3 */
|
||||
DW_AT_allocated = 0x4e,
|
||||
DW_AT_associated = 0x4f,
|
||||
DW_AT_data_location = 0x50,
|
||||
DW_AT_byte_stride = 0x51,
|
||||
DW_AT_entry_pc = 0x52,
|
||||
DW_AT_use_UTF8 = 0x53,
|
||||
DW_AT_extension = 0x54,
|
||||
DW_AT_ranges = 0x55,
|
||||
DW_AT_trampoline = 0x56,
|
||||
DW_AT_call_column = 0x57,
|
||||
DW_AT_call_file = 0x58,
|
||||
DW_AT_call_line = 0x59,
|
||||
DW_AT_description = 0x5a,
|
||||
DW_AT_binary_scale = 0x5b,
|
||||
DW_AT_decimal_scale = 0x5c,
|
||||
DW_AT_small = 0x5d,
|
||||
DW_AT_decimal_sign = 0x5e,
|
||||
DW_AT_digit_count = 0x5f,
|
||||
DW_AT_picture_string = 0x60,
|
||||
DW_AT_mutable = 0x61,
|
||||
DW_AT_threads_scaled = 0x62,
|
||||
DW_AT_explicit = 0x63,
|
||||
DW_AT_object_pointer = 0x64,
|
||||
DW_AT_endianity = 0x65,
|
||||
DW_AT_elemental = 0x66,
|
||||
DW_AT_pure = 0x67,
|
||||
DW_AT_recursive = 0x68,
|
||||
/* DWARF 4 */
|
||||
DW_AT_signature = 0x69,
|
||||
DW_AT_main_subprogram = 0x6a,
|
||||
DW_AT_data_bit_offset = 0x6b,
|
||||
DW_AT_const_expr = 0x6c,
|
||||
DW_AT_enum_class = 0x6d,
|
||||
DW_AT_linkage_name = 0x6e,
|
||||
/* DWARF 5 */
|
||||
DW_AT_noreturn = 0x87,
|
||||
|
||||
DW_AT_lo_user = 0x2000,
|
||||
DW_AT_hi_user = 0x3fff
|
||||
};
|
||||
|
||||
enum dwarf_op {
|
||||
DW_OP_addr = 0x03,
|
||||
DW_OP_deref = 0x06,
|
||||
DW_OP_const1u = 0x08,
|
||||
DW_OP_const1s = 0x09,
|
||||
DW_OP_const2u = 0x0a,
|
||||
DW_OP_const2s = 0x0b,
|
||||
DW_OP_const4u = 0x0c,
|
||||
DW_OP_const4s = 0x0d,
|
||||
DW_OP_const8u = 0x0e,
|
||||
DW_OP_const8s = 0x0f,
|
||||
DW_OP_constu = 0x10,
|
||||
DW_OP_consts = 0x11,
|
||||
DW_OP_dup = 0x12,
|
||||
DW_OP_drop = 0x13,
|
||||
DW_OP_over = 0x14,
|
||||
DW_OP_pick = 0x15,
|
||||
DW_OP_swap = 0x16,
|
||||
DW_OP_rot = 0x17,
|
||||
DW_OP_xderef = 0x18,
|
||||
DW_OP_abs = 0x19,
|
||||
DW_OP_and = 0x1a,
|
||||
DW_OP_div = 0x1b,
|
||||
DW_OP_minus = 0x1c,
|
||||
DW_OP_mod = 0x1d,
|
||||
DW_OP_mul = 0x1e,
|
||||
DW_OP_neg = 0x1f,
|
||||
DW_OP_not = 0x20,
|
||||
DW_OP_or = 0x21,
|
||||
DW_OP_plus = 0x22,
|
||||
DW_OP_plus_uconst = 0x23,
|
||||
DW_OP_shl = 0x24,
|
||||
DW_OP_shr = 0x25,
|
||||
DW_OP_shra = 0x26,
|
||||
DW_OP_xor = 0x27,
|
||||
DW_OP_skip = 0x2f,
|
||||
DW_OP_bra = 0x28,
|
||||
DW_OP_eq = 0x29,
|
||||
DW_OP_ge = 0x2a,
|
||||
DW_OP_gt = 0x2b,
|
||||
DW_OP_le = 0x2c,
|
||||
DW_OP_lt = 0x2d,
|
||||
DW_OP_ne = 0x2e,
|
||||
DW_OP_lit0 = 0x30,
|
||||
DW_OP_lit1 = 0x31,
|
||||
DW_OP_lit2 = 0x32,
|
||||
DW_OP_lit3 = 0x33,
|
||||
DW_OP_lit4 = 0x34,
|
||||
DW_OP_lit5 = 0x35,
|
||||
DW_OP_lit6 = 0x36,
|
||||
DW_OP_lit7 = 0x37,
|
||||
DW_OP_lit8 = 0x38,
|
||||
DW_OP_lit9 = 0x39,
|
||||
DW_OP_lit10 = 0x3a,
|
||||
DW_OP_lit11 = 0x3b,
|
||||
DW_OP_lit12 = 0x3c,
|
||||
DW_OP_lit13 = 0x3d,
|
||||
DW_OP_lit14 = 0x3e,
|
||||
DW_OP_lit15 = 0x3f,
|
||||
DW_OP_lit16 = 0x40,
|
||||
DW_OP_lit17 = 0x41,
|
||||
DW_OP_lit18 = 0x42,
|
||||
DW_OP_lit19 = 0x43,
|
||||
DW_OP_lit20 = 0x44,
|
||||
DW_OP_lit21 = 0x45,
|
||||
DW_OP_lit22 = 0x46,
|
||||
DW_OP_lit23 = 0x47,
|
||||
DW_OP_lit24 = 0x48,
|
||||
DW_OP_lit25 = 0x49,
|
||||
DW_OP_lit26 = 0x4a,
|
||||
DW_OP_lit27 = 0x4b,
|
||||
DW_OP_lit28 = 0x4c,
|
||||
DW_OP_lit29 = 0x4d,
|
||||
DW_OP_lit30 = 0x4e,
|
||||
DW_OP_lit31 = 0x4f,
|
||||
DW_OP_reg0 = 0x50,
|
||||
DW_OP_reg1 = 0x51,
|
||||
DW_OP_reg2 = 0x52,
|
||||
DW_OP_reg3 = 0x53,
|
||||
DW_OP_reg4 = 0x54,
|
||||
DW_OP_reg5 = 0x55,
|
||||
DW_OP_reg6 = 0x56,
|
||||
DW_OP_reg7 = 0x57,
|
||||
DW_OP_reg8 = 0x58,
|
||||
DW_OP_reg9 = 0x59,
|
||||
DW_OP_reg10 = 0x5a,
|
||||
DW_OP_reg11 = 0x5b,
|
||||
DW_OP_reg12 = 0x5c,
|
||||
DW_OP_reg13 = 0x5d,
|
||||
DW_OP_reg14 = 0x5e,
|
||||
DW_OP_reg15 = 0x5f,
|
||||
DW_OP_reg16 = 0x60,
|
||||
DW_OP_reg17 = 0x61,
|
||||
DW_OP_reg18 = 0x62,
|
||||
DW_OP_reg19 = 0x63,
|
||||
DW_OP_reg20 = 0x64,
|
||||
DW_OP_reg21 = 0x65,
|
||||
DW_OP_reg22 = 0x66,
|
||||
DW_OP_reg23 = 0x67,
|
||||
DW_OP_reg24 = 0x68,
|
||||
DW_OP_reg25 = 0x69,
|
||||
DW_OP_reg26 = 0x6a,
|
||||
DW_OP_reg27 = 0x6b,
|
||||
DW_OP_reg28 = 0x6c,
|
||||
DW_OP_reg29 = 0x6d,
|
||||
DW_OP_reg30 = 0x6e,
|
||||
DW_OP_reg31 = 0x6f,
|
||||
DW_OP_breg0 = 0x70,
|
||||
DW_OP_breg1 = 0x71,
|
||||
DW_OP_breg2 = 0x72,
|
||||
DW_OP_breg3 = 0x73,
|
||||
DW_OP_breg4 = 0x74,
|
||||
DW_OP_breg5 = 0x75,
|
||||
DW_OP_breg6 = 0x76,
|
||||
DW_OP_breg7 = 0x77,
|
||||
DW_OP_breg8 = 0x78,
|
||||
DW_OP_breg9 = 0x79,
|
||||
DW_OP_breg10 = 0x7a,
|
||||
DW_OP_breg11 = 0x7b,
|
||||
DW_OP_breg12 = 0x7c,
|
||||
DW_OP_breg13 = 0x7d,
|
||||
DW_OP_breg14 = 0x7e,
|
||||
DW_OP_breg15 = 0x7f,
|
||||
DW_OP_breg16 = 0x80,
|
||||
DW_OP_breg17 = 0x81,
|
||||
DW_OP_breg18 = 0x82,
|
||||
DW_OP_breg19 = 0x83,
|
||||
DW_OP_breg20 = 0x84,
|
||||
DW_OP_breg21 = 0x85,
|
||||
DW_OP_breg22 = 0x86,
|
||||
DW_OP_breg23 = 0x87,
|
||||
DW_OP_breg24 = 0x88,
|
||||
DW_OP_breg25 = 0x89,
|
||||
DW_OP_breg26 = 0x8a,
|
||||
DW_OP_breg27 = 0x8b,
|
||||
DW_OP_breg28 = 0x8c,
|
||||
DW_OP_breg29 = 0x8d,
|
||||
DW_OP_breg30 = 0x8e,
|
||||
DW_OP_breg31 = 0x8f,
|
||||
DW_OP_regx = 0x90,
|
||||
DW_OP_fbreg = 0x91,
|
||||
DW_OP_bregx = 0x92,
|
||||
DW_OP_piece = 0x93,
|
||||
DW_OP_deref_size = 0x94,
|
||||
DW_OP_xderef_size = 0x95,
|
||||
DW_OP_nop = 0x96,
|
||||
/* DWARF 3 */
|
||||
DW_OP_push_object_address = 0x97,
|
||||
DW_OP_call2 = 0x98,
|
||||
DW_OP_call4 = 0x99,
|
||||
DW_OP_call_ref = 0x9a ,
|
||||
DW_OP_form_tls_address = 0x9b,
|
||||
DW_OP_call_frame_cfa = 0x9c,
|
||||
DW_OP_bit_piece = 0x9d,
|
||||
/* DWARF 4 */
|
||||
DW_OP_implicit_value = 0x9e,
|
||||
DW_OP_stack_value = 0x9f,
|
||||
|
||||
DW_OP_lo_user = 0xe0,
|
||||
DW_OP_hi_user = 0xff
|
||||
};
|
||||
|
||||
enum dwarf_base_type {
|
||||
DW_ATE_address = 0x01,
|
||||
DW_ATE_boolean = 0x02,
|
||||
DW_ATE_complex_float = 0x03,
|
||||
DW_ATE_float = 0x04,
|
||||
DW_ATE_signed = 0x05,
|
||||
DW_ATE_signed_char = 0x06,
|
||||
DW_ATE_unsigned = 0x07,
|
||||
DW_ATE_unsigned_char = 0x08,
|
||||
/* DWARF 3 */
|
||||
DW_ATE_imaginary_float = 0x09,
|
||||
DW_ATE_packed_decimal = 0x0a,
|
||||
DW_ATE_numeric_string = 0x0b,
|
||||
DW_ATE_edited = 0x0c,
|
||||
DW_ATE_signed_fixed = 0x0d,
|
||||
DW_ATE_unsigned_fixed = 0x0e,
|
||||
DW_ATE_decimal_float = 0x0f,
|
||||
/* DWARF 4 */
|
||||
DW_ATE_UTF = 0x10,
|
||||
|
||||
DW_ATE_lo_user = 0x80,
|
||||
DW_ATE_hi_user = 0xff
|
||||
};
|
||||
|
||||
enum dwarf_decimal_sign {
|
||||
DW_DS_unsigned = 0x01,
|
||||
DW_DS_leading_overpunch = 0x02,
|
||||
DW_DS_trailing_overpunch = 0x03,
|
||||
DW_DS_leading_separate = 0x04,
|
||||
DW_DS_trailing_separate = 0x05
|
||||
};
|
||||
|
||||
enum dwarf_endianity {
|
||||
DW_END_default = 0x00,
|
||||
DW_END_big = 0x01,
|
||||
DW_END_little = 0x02,
|
||||
|
||||
DW_END_lo_user = 0x40,
|
||||
DW_END_hi_user = 0xff
|
||||
};
|
||||
|
||||
enum dwarf_accessibility {
|
||||
DW_ACCESS_public = 0x01,
|
||||
DW_ACCESS_protected = 0x02,
|
||||
DW_ACCESS_private = 0x03
|
||||
};
|
||||
|
||||
enum dwarf_visibility {
|
||||
DW_VIS_local = 0x01,
|
||||
DW_VIS_exported = 0x02,
|
||||
DW_VIS_qualified = 0x03
|
||||
};
|
||||
|
||||
enum dwarf_virtuality {
|
||||
DW_VIRTUALITY_none = 0x00,
|
||||
DW_VIRTUALITY_virtual = 0x01,
|
||||
DW_VIRTUALITY_pure_virtual = 0x02
|
||||
};
|
||||
|
||||
enum dwarf_language {
|
||||
DW_LANG_C89 = 0x0001,
|
||||
DW_LANG_C = 0x0002,
|
||||
DW_LANG_Ada83 = 0x0003,
|
||||
DW_LANG_C_plus_plus = 0x0004,
|
||||
DW_LANG_Cobol74 = 0x0005,
|
||||
DW_LANG_Cobol85 = 0x0006,
|
||||
DW_LANG_Fortran77 = 0x0007,
|
||||
DW_LANG_Fortran90 = 0x0008,
|
||||
DW_LANG_Pascal83 = 0x0009,
|
||||
DW_LANG_Modula2 = 0x000a,
|
||||
DW_LANG_Java = 0x000b,
|
||||
DW_LANG_C99 = 0x000c,
|
||||
DW_LANG_Ada95 = 0x000d,
|
||||
DW_LANG_Fortran95 = 0x000e,
|
||||
DW_LANG_PLI = 0x000f,
|
||||
DW_LANG_ObjC = 0x0010,
|
||||
DW_LANG_ObjC_plus_plus = 0x0011,
|
||||
DW_LANG_UPC = 0x0012,
|
||||
DW_LANG_D = 0x0013,
|
||||
DW_LANG_Python = 0x0014,
|
||||
DW_LANG_OpenCL = 0x0015,
|
||||
DW_LANG_Go = 0x0016,
|
||||
DW_LANG_Modula3 = 0x0017,
|
||||
DW_LANG_Haskell = 0x0018,
|
||||
DW_LANG_C_plus_plus_03 = 0x0019,
|
||||
DW_LANG_C_plus_plus_11 = 0x001a,
|
||||
DW_LANG_OCaml = 0x001b,
|
||||
DW_LANG_Rust = 0x001c,
|
||||
DW_LANG_C11 = 0x001d,
|
||||
DW_LANG_Swift = 0x001e,
|
||||
DW_LANG_Julia = 0x001f,
|
||||
DW_LANG_Dylan = 0x0020,
|
||||
DW_LANG_C_plus_plus_14 = 0x0021,
|
||||
DW_LANG_Fortran03 = 0x0022,
|
||||
DW_LANG_Fortran08 = 0x0023,
|
||||
DW_LANG_RenderScript = 0x0024,
|
||||
|
||||
DW_LANG_Mips_Assembler = 0x8001,
|
||||
|
||||
DW_LANG_lo_user = 0x8000,
|
||||
DW_LANG_hi_user = 0xffff,
|
||||
|
||||
DW_LANG_Rust_old = 0x9000
|
||||
};
|
||||
|
||||
enum dwarf_identifier_case {
|
||||
DW_ID_case_sensitive = 0x00,
|
||||
DW_ID_up_case = 0x01,
|
||||
DW_ID_down_case = 0x02,
|
||||
DW_ID_case_insensitive = 0x03
|
||||
};
|
||||
|
||||
enum dwarf_calling_conversion {
|
||||
DW_CC_normal = 0x01,
|
||||
DW_CC_program = 0x02,
|
||||
DW_CC_nocall = 0x03,
|
||||
DW_CC_pass_by_reference = 0x4,
|
||||
DW_CC_pass_by_value = 0x5,
|
||||
|
||||
DW_CC_lo_user = 0x40,
|
||||
DW_CC_hi_user = 0xff,
|
||||
|
||||
DW_CC_GNU_renesas_sh = 0x40,
|
||||
DW_CC_GNU_borland_fastcall_i386 = 0x41
|
||||
};
|
||||
|
||||
enum dwarf_inline {
|
||||
DW_INL_not_inlined = 0x00,
|
||||
DW_INL_inlined = 0x01,
|
||||
DW_INL_declared_not_inlined = 0x02,
|
||||
DW_INL_declared_inlined = 0x03
|
||||
};
|
||||
|
||||
enum dwarf_ordering {
|
||||
DW_ORD_row_major = 0x00,
|
||||
DW_ORD_col_major = 0x01
|
||||
};
|
||||
|
||||
enum dwarf_discriminant {
|
||||
DW_DSC_label = 0x00,
|
||||
DW_DSC_range = 0x01
|
||||
};
|
||||
|
||||
enum dwarf_line_number {
|
||||
DW_LNS_extended_op = 0x00,
|
||||
DW_LNS_copy = 0x01,
|
||||
DW_LNS_advance_pc = 0x02,
|
||||
DW_LNS_advance_line = 0x03,
|
||||
DW_LNS_set_file = 0x04,
|
||||
DW_LNS_set_column = 0x05,
|
||||
DW_LNS_negate_stmt = 0x06,
|
||||
DW_LNS_set_basic_block = 0x07,
|
||||
DW_LNS_const_add_pc = 0x08,
|
||||
DW_LNS_fixed_advance_pc = 0x09,
|
||||
DW_LNS_set_prologue_end = 0x0a,
|
||||
DW_LNS_set_epilogue_begin = 0x0b,
|
||||
DW_LNS_set_isa = 0x0c
|
||||
};
|
||||
|
||||
enum dwarf_line_number_extended {
|
||||
DW_LNE_end_sequence = 0x01,
|
||||
DW_LNE_set_address = 0x02,
|
||||
DW_LNE_define_file = 0x03,
|
||||
DW_LNE_set_discriminator= 0x04,
|
||||
DW_LNE_lo_user = 0x80,
|
||||
DW_LNE_hi_user = 0xff
|
||||
};
|
||||
|
||||
enum dwarf_macinfo_type {
|
||||
DW_MACINFO_define = 0x01,
|
||||
DW_MACINFO_undef = 0x02,
|
||||
DW_MACINFO_start_file = 0x03,
|
||||
DW_MACINFO_end_file = 0x04,
|
||||
DW_MACINFO_vendor_ext = 0xff
|
||||
};
|
||||
|
||||
enum dwarf_call_frame {
|
||||
DW_CFA_advance_loc = 0x01,
|
||||
DW_CFA_offset = 0x02,
|
||||
DW_CFA_restore = 0x03,
|
||||
DW_CFA_nop = 0x00,
|
||||
DW_CFA_set_loc = 0x01,
|
||||
DW_CFA_advance_loc1 = 0x02,
|
||||
DW_CFA_advance_loc2 = 0x03,
|
||||
DW_CFA_advance_loc4 = 0x04,
|
||||
DW_CFA_offset_extended = 0x05,
|
||||
DW_CFA_restore_extended = 0x06,
|
||||
DW_CFA_undefined = 0x07,
|
||||
DW_CFA_same_value = 0x08,
|
||||
DW_CFA_register = 0x09,
|
||||
DW_CFA_remember_state = 0x0a,
|
||||
DW_CFA_restore_state = 0x0b,
|
||||
DW_CFA_def_cfa = 0x0c,
|
||||
DW_CFA_def_cfa_register = 0x0d,
|
||||
DW_CFA_def_cfa_offset = 0x0e,
|
||||
/* DWARF 3 */
|
||||
DW_CFA_def_cfa_expression = 0x0f,
|
||||
DW_CFA_expression = 0x10,
|
||||
DW_CFA_offset_extended_sf = 0x11,
|
||||
DW_CFA_def_cfa_sf = 0x12,
|
||||
DW_CFA_def_cfa_offset_sf = 0x13,
|
||||
DW_CFA_val_offset = 0x14,
|
||||
DW_CFA_val_offset_sf = 0x15,
|
||||
DW_CFA_val_expression = 0x16,
|
||||
DW_CFA_lo_user = 0x1c,
|
||||
DW_CFA_hi_user = 0x3f
|
||||
};
|
||||
|
||||
#endif /* OUTPUT_DWARF_H */
|
||||
528
include/elf.h
Normal file
528
include/elf.h
Normal file
|
|
@ -0,0 +1,528 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef OUTPUT_ELF_H
|
||||
#define OUTPUT_ELF_H
|
||||
|
||||
/*
|
||||
* Since NASM support both Elf32/64 file formats
|
||||
* we need to cover all types, structures, typedefs and etc
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* Segment types */
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_LOOS 0x60000000
|
||||
#define PT_HIOS 0x6fffffff
|
||||
#define PT_LOPROC 0x70000000
|
||||
#define PT_HIPROC 0x7fffffff
|
||||
#define PT_GNU_EH_FRAME 0x6474e550 /* Extension, eh? */
|
||||
|
||||
/* ELF file types */
|
||||
#define ET_NONE 0
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
#define ET_DYN 3
|
||||
#define ET_CORE 4
|
||||
#define ET_LOPROC 0xff00
|
||||
#define ET_HIPROC 0xffff
|
||||
|
||||
/* ELF machine types */
|
||||
#define EM_NONE 0
|
||||
#define EM_M32 1
|
||||
#define EM_SPARC 2
|
||||
#define EM_386 3
|
||||
#define EM_68K 4
|
||||
#define EM_88K 5
|
||||
#define EM_486 6 /* Not used in Linux at least */
|
||||
#define EM_860 7
|
||||
#define EM_MIPS 8 /* R3k, bigendian(?) */
|
||||
#define EM_MIPS_RS4_BE 10 /* R4k BE */
|
||||
#define EM_PARISC 15
|
||||
#define EM_SPARC32PLUS 18
|
||||
#define EM_PPC 20
|
||||
#define EM_PPC64 21
|
||||
#define EM_S390 22
|
||||
#define EM_SH 42
|
||||
#define EM_SPARCV9 43 /* v9 = SPARC64 */
|
||||
#define EM_H8_300H 47
|
||||
#define EM_H8S 48
|
||||
#define EM_IA_64 50
|
||||
#define EM_X86_64 62
|
||||
#define EM_CRIS 76
|
||||
#define EM_V850 87
|
||||
#define EM_ALPHA 0x9026 /* Interim Alpha that stuck around */
|
||||
#define EM_CYGNUS_V850 0x9080 /* Old v850 ID used by Cygnus */
|
||||
#define EM_S390_OLD 0xA390 /* Obsolete interim value for S/390 */
|
||||
|
||||
/* Dynamic type values */
|
||||
#define DT_NULL 0
|
||||
#define DT_NEEDED 1
|
||||
#define DT_PLTRELSZ 2
|
||||
#define DT_PLTGOT 3
|
||||
#define DT_HASH 4
|
||||
#define DT_STRTAB 5
|
||||
#define DT_SYMTAB 6
|
||||
#define DT_RELA 7
|
||||
#define DT_RELASZ 8
|
||||
#define DT_RELAENT 9
|
||||
#define DT_STRSZ 10
|
||||
#define DT_SYMENT 11
|
||||
#define DT_INIT 12
|
||||
#define DT_FINI 13
|
||||
#define DT_SONAME 14
|
||||
#define DT_RPATH 15
|
||||
#define DT_SYMBOLIC 16
|
||||
#define DT_REL 17
|
||||
#define DT_RELSZ 18
|
||||
#define DT_RELENT 19
|
||||
#define DT_PLTREL 20
|
||||
#define DT_DEBUG 21
|
||||
#define DT_TEXTREL 22
|
||||
#define DT_JMPREL 23
|
||||
#define DT_LOPROC 0x70000000
|
||||
#define DT_HIPROC 0x7fffffff
|
||||
|
||||
/* Auxiliary table entries */
|
||||
#define AT_NULL 0 /* end of vector */
|
||||
#define AT_IGNORE 1 /* entry should be ignored */
|
||||
#define AT_EXECFD 2 /* file descriptor of program */
|
||||
#define AT_PHDR 3 /* program headers for program */
|
||||
#define AT_PHENT 4 /* size of program header entry */
|
||||
#define AT_PHNUM 5 /* number of program headers */
|
||||
#define AT_PAGESZ 6 /* system page size */
|
||||
#define AT_BASE 7 /* base address of interpreter */
|
||||
#define AT_FLAGS 8 /* flags */
|
||||
#define AT_ENTRY 9 /* entry point of program */
|
||||
#define AT_NOTELF 10 /* program is not ELF */
|
||||
#define AT_UID 11 /* real uid */
|
||||
#define AT_EUID 12 /* effective uid */
|
||||
#define AT_GID 13 /* real gid */
|
||||
#define AT_EGID 14 /* effective gid */
|
||||
#define AT_PLATFORM 15 /* string identifying CPU for optimizations */
|
||||
#define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
|
||||
#define AT_CLKTCK 17 /* frequency at which times() increments */
|
||||
/* 18..22 = ? */
|
||||
#define AT_SECURE 23 /* secure mode boolean */
|
||||
|
||||
/* Program header permission flags */
|
||||
#define PF_X 0x1
|
||||
#define PF_W 0x2
|
||||
#define PF_R 0x4
|
||||
|
||||
/* Section header types */
|
||||
#define SHT_NULL 0
|
||||
#define SHT_PROGBITS 1
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
#define SHT_RELA 4
|
||||
#define SHT_HASH 5
|
||||
#define SHT_DYNAMIC 6
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_NOBITS 8
|
||||
#define SHT_REL 9
|
||||
#define SHT_SHLIB 10
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_INIT_ARRAY 14
|
||||
#define SHT_FINI_ARRAY 15
|
||||
#define SHT_PREINIT_ARRAY 16
|
||||
#define SHT_GROUP 17
|
||||
#define SHT_SYMTAB_SHNDX 18
|
||||
#define SHT_LOPROC 0x70000000
|
||||
#define SHT_HIPROC 0x7fffffff
|
||||
#define SHT_LOUSER 0x80000000
|
||||
#define SHT_HIUSER 0xffffffff
|
||||
|
||||
/* Section header flags */
|
||||
#define SHF_WRITE (1 << 0) /* Writable */
|
||||
#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
|
||||
#define SHF_EXECINSTR (1 << 2) /* Executable */
|
||||
#define SHF_MERGE (1 << 4) /* Might be merged */
|
||||
#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
|
||||
#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
|
||||
#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
|
||||
#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling required */
|
||||
#define SHF_GROUP (1 << 9) /* Section is member of a group */
|
||||
#define SHF_TLS (1 << 10) /* Section hold thread-local data */
|
||||
|
||||
/* Special section numbers */
|
||||
#define SHN_UNDEF 0x0000
|
||||
#define SHN_LORESERVE 0xff00
|
||||
#define SHN_LOPROC 0xff00
|
||||
#define SHN_HIPROC 0xff1f
|
||||
#define SHN_ABS 0xfff1
|
||||
#define SHN_COMMON 0xfff2
|
||||
#define SHN_XINDEX 0xffff
|
||||
#define SHN_HIRESERVE 0xffff
|
||||
|
||||
/* Same, but signed/sign-extended */
|
||||
#define XSHN_UNDEF ((int16_t)SHN_UNDEF)
|
||||
#define XSHN_LORESERVE ((int16_t)SHN_LORESERVE)
|
||||
#define XSHN_LOPROC ((int16_t)SHN_LOPROC)
|
||||
#define XSHN_HIPROC ((int16_t)SHN_HIPROC)
|
||||
#define XSHN_ABS ((int16_t)SHN_ABS)
|
||||
#define XSHN_COMMON ((int16_t)SHN_COMMON)
|
||||
#define XSHN_XINDEX ((int16_t)SHN_XINDEX)
|
||||
#define XSHN_HIRESERVE ((int16_t)SHN_HIRESERVE)
|
||||
|
||||
/* Section align flag */
|
||||
#define SHA_ANY 1 /* No alignment constraint */
|
||||
|
||||
/* Length of magic at the start of a file */
|
||||
#define EI_NIDENT 16
|
||||
|
||||
/* Magic number constants... */
|
||||
#define EI_MAG0 0 /* e_ident[] indexes */
|
||||
#define EI_MAG1 1
|
||||
#define EI_MAG2 2
|
||||
#define EI_MAG3 3
|
||||
#define EI_CLASS 4
|
||||
#define EI_DATA 5
|
||||
#define EI_VERSION 6
|
||||
#define EI_OSABI 7
|
||||
#define EI_ABIVERSION 8
|
||||
#define EI_NINDENT 16
|
||||
|
||||
#define ELFMAG0 0x7f /* EI_MAG */
|
||||
#define ELFMAG1 'E'
|
||||
#define ELFMAG2 'L'
|
||||
#define ELFMAG3 'F'
|
||||
#define ELFMAG "\177ELF"
|
||||
#define SELFMAG 4
|
||||
|
||||
#define ELFCLASSNONE 0 /* EI_CLASS */
|
||||
#define ELFCLASS32 1
|
||||
#define ELFCLASS64 2
|
||||
#define ELFCLASSNUM 3
|
||||
|
||||
#define ELFDATANONE 0 /* e_ident[EI_DATA] */
|
||||
#define ELFDATA2LSB 1
|
||||
#define ELFDATA2MSB 2
|
||||
|
||||
#define EV_NONE 0 /* e_version, EI_VERSION */
|
||||
#define EV_CURRENT 1
|
||||
#define EV_NUM 2
|
||||
|
||||
#define ELFOSABI_NONE 0
|
||||
#define ELFOSABI_LINUX 3
|
||||
|
||||
/* Legal values for ST_BIND subfield of st_info (symbol binding) */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* Weak symbol */
|
||||
#define STB_NUM 3 /* Number of defined types */
|
||||
#define STB_LOOS 10 /* Start of OS-specific */
|
||||
#define STB_HIOS 12 /* End of OS-specific */
|
||||
#define STB_LOPROC 13 /* Start of processor-specific */
|
||||
#define STB_HIPROC 15 /* End of processor-specific */
|
||||
|
||||
/* Symbol types */
|
||||
#define STT_NOTYPE 0 /* Symbol type is unspecified */
|
||||
#define STT_OBJECT 1 /* Symbol is a data object */
|
||||
#define STT_FUNC 2 /* Symbol is a code object */
|
||||
#define STT_SECTION 3 /* Symbol associated with a section */
|
||||
#define STT_FILE 4 /* Symbol's name is file name */
|
||||
#define STT_COMMON 5 /* Symbol is a common data object */
|
||||
#define STT_TLS 6 /* Symbol is thread-local data object */
|
||||
#define STT_NUM 7 /* Number of defined types */
|
||||
#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */
|
||||
|
||||
/* Symbol visibilities */
|
||||
#define STV_DEFAULT 0 /* Default symbol visibility rules */
|
||||
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||
#define STV_HIDDEN 2 /* Sym unavailable in other modules */
|
||||
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||
|
||||
/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field */
|
||||
#define ELF32_ST_BIND(i) ((i) >> 4)
|
||||
#define ELF32_ST_MKBIND(i) ((i) << 4) /* just a helper */
|
||||
#define ELF32_ST_TYPE(i) ((i) & 0xf)
|
||||
#define ELF32_ST_INFO(b, i) (ELF32_ST_MKBIND(b) + ELF32_ST_TYPE(i))
|
||||
|
||||
#define ELF64_ST_BIND(i) ELF32_ST_BIND(i)
|
||||
#define ELF64_ST_MKBIND(i) ELF32_ST_MKBIND(i)
|
||||
#define ELF64_ST_TYPE(i) ELF32_ST_TYPE(i)
|
||||
#define ELF64_ST_INFO(b, i) ELF32_ST_INFO(b, i)
|
||||
|
||||
/*
|
||||
* ELF standard typedefs (yet more proof that <stdint.h> was way overdue)
|
||||
*/
|
||||
|
||||
typedef uint16_t Elf32_Half;
|
||||
typedef int16_t Elf32_SHalf;
|
||||
typedef uint32_t Elf32_Word;
|
||||
typedef int32_t Elf32_Sword;
|
||||
typedef uint64_t Elf32_Xword;
|
||||
typedef int64_t Elf32_Sxword;
|
||||
|
||||
typedef uint32_t Elf32_Off;
|
||||
typedef uint32_t Elf32_Addr;
|
||||
typedef uint16_t Elf32_Section;
|
||||
|
||||
typedef uint16_t Elf64_Half;
|
||||
typedef int16_t Elf64_SHalf;
|
||||
typedef uint32_t Elf64_Word;
|
||||
typedef int32_t Elf64_Sword;
|
||||
typedef uint64_t Elf64_Xword;
|
||||
typedef int64_t Elf64_Sxword;
|
||||
|
||||
typedef uint64_t Elf64_Off;
|
||||
typedef uint64_t Elf64_Addr;
|
||||
typedef uint16_t Elf64_Section;
|
||||
|
||||
/*
|
||||
* Dynamic header
|
||||
*/
|
||||
|
||||
typedef struct elf32_dyn {
|
||||
Elf32_Sword d_tag;
|
||||
union {
|
||||
Elf32_Sword d_val;
|
||||
Elf32_Addr d_ptr;
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
typedef struct elf64_dyn {
|
||||
Elf64_Sxword d_tag;
|
||||
union {
|
||||
Elf64_Xword d_val;
|
||||
Elf64_Addr d_ptr;
|
||||
} d_un;
|
||||
} Elf64_Dyn;
|
||||
|
||||
/*
|
||||
* Relocations
|
||||
*/
|
||||
|
||||
#define ELF32_R_SYM(x) ((x) >> 8)
|
||||
#define ELF32_R_TYPE(x) ((x) & 0xff)
|
||||
#define ELF32_R_INFO(s,t) (((Elf32_Word)(s) << 8) + ELF32_R_TYPE(t))
|
||||
|
||||
typedef struct elf32_rel {
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
} Elf32_Rel;
|
||||
|
||||
typedef struct elf32_rela {
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
enum reloc32_type {
|
||||
R_386_32 = 1, /* ordinary absolute relocation */
|
||||
R_386_PC32 = 2, /* PC-relative relocation */
|
||||
R_386_GOT32 = 3, /* an offset into GOT */
|
||||
R_386_PLT32 = 4, /* a PC-relative offset into PLT */
|
||||
R_386_COPY = 5, /* ??? */
|
||||
R_386_GLOB_DAT = 6, /* ??? */
|
||||
R_386_JUMP_SLOT = 7, /* ??? */
|
||||
R_386_RELATIVE = 8, /* ??? */
|
||||
R_386_GOTOFF = 9, /* an offset from GOT base */
|
||||
R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */
|
||||
R_386_TLS_TPOFF = 14, /* Offset in static TLS block */
|
||||
R_386_TLS_IE = 15, /* Address of GOT entry for static TLS block offset */
|
||||
/* These are GNU extensions, but useful */
|
||||
R_386_16 = 20, /* A 16-bit absolute relocation */
|
||||
R_386_PC16 = 21, /* A 16-bit PC-relative relocation */
|
||||
R_386_8 = 22, /* An 8-bit absolute relocation */
|
||||
R_386_PC8 = 23, /* An 8-bit PC-relative relocation */
|
||||
R_386_SEG16 = 45, /* A 16-bit real-mode segment */
|
||||
R_386_SUB16 = 46, /* Subtract 16-bit value */
|
||||
R_386_SUB32 = 47 /* Subtract 32-bit value */
|
||||
};
|
||||
|
||||
#define ELF64_R_SYM(x) ((x) >> 32)
|
||||
#define ELF64_R_TYPE(x) ((x) & 0xffffffff)
|
||||
#define ELF64_R_INFO(s,t) (((Elf64_Xword)(s) << 32) + ELF64_R_TYPE(t))
|
||||
|
||||
typedef struct elf64_rel {
|
||||
Elf64_Addr r_offset;
|
||||
Elf64_Xword r_info;
|
||||
} Elf64_Rel;
|
||||
|
||||
typedef struct elf64_rela {
|
||||
Elf64_Addr r_offset;
|
||||
Elf64_Xword r_info;
|
||||
Elf64_Sxword r_addend;
|
||||
} Elf64_Rela;
|
||||
|
||||
enum reloc64_type {
|
||||
R_X86_64_NONE = 0, /* No reloc */
|
||||
R_X86_64_64 = 1, /* Direct 64 bit */
|
||||
R_X86_64_PC32 = 2, /* PC relative 32 bit signed */
|
||||
R_X86_64_GOT32 = 3, /* 32 bit GOT entry */
|
||||
R_X86_64_PLT32 = 4, /* 32 bit PLT address */
|
||||
R_X86_64_COPY = 5, /* Copy symbol at runtime */
|
||||
R_X86_64_GLOB_DAT = 6, /* Create GOT entry */
|
||||
R_X86_64_JUMP_SLOT = 7, /* Create PLT entry */
|
||||
R_X86_64_RELATIVE = 8, /* Adjust by program base */
|
||||
R_X86_64_GOTPCREL = 9, /* 32 bit signed PC relative offset to GOT */
|
||||
R_X86_64_32 = 10, /* Direct 32 bit zero extended */
|
||||
R_X86_64_32S = 11, /* Direct 32 bit sign extended */
|
||||
R_X86_64_16 = 12, /* Direct 16 bit zero extended */
|
||||
R_X86_64_PC16 = 13, /* 16 bit sign extended pc relative */
|
||||
R_X86_64_8 = 14, /* Direct 8 bit sign extended */
|
||||
R_X86_64_PC8 = 15, /* 8 bit sign extended pc relative */
|
||||
R_X86_64_DTPMOD64 = 16, /* ID of module containing symbol */
|
||||
R_X86_64_DTPOFF64 = 17, /* Offset in module's TLS block */
|
||||
R_X86_64_TPOFF64 = 18, /* Offset in initial TLS block */
|
||||
R_X86_64_TLSGD = 19, /* 32 bit signed PC relative offset to two GOT entries for GD symbol */
|
||||
R_X86_64_TLSLD = 20, /* 32 bit signed PC relative offset to two GOT entries for LD symbol */
|
||||
R_X86_64_DTPOFF32 = 21, /* Offset in TLS block */
|
||||
R_X86_64_GOTTPOFF = 22, /* 32 bit signed PC relative offset to GOT entry for IE symbol */
|
||||
R_X86_64_TPOFF32 = 23, /* Offset in initial TLS block */
|
||||
R_X86_64_PC64 = 24, /* word64 S + A - P */
|
||||
R_X86_64_GOTOFF64 = 25, /* word64 S + A - GOT */
|
||||
R_X86_64_GOTPC32 = 26, /* word32 GOT + A - P */
|
||||
R_X86_64_GOT64 = 27, /* word64 G + A */
|
||||
R_X86_64_GOTPCREL64 = 28, /* word64 G + GOT - P + A */
|
||||
R_X86_64_GOTPC64 = 29, /* word64 GOT - P + A */
|
||||
R_X86_64_GOTPLT64 = 30, /* word64 G + A */
|
||||
R_X86_64_PLTOFF64 = 31, /* word64 L - GOT + A */
|
||||
R_X86_64_SIZE32 = 32, /* word32 Z + A */
|
||||
R_X86_64_SIZE64 = 33, /* word64 Z + A */
|
||||
R_X86_64_GOTPC32_TLSDESC= 34, /* word32 */
|
||||
R_X86_64_TLSDESC_CALL = 35, /* none */
|
||||
R_X86_64_TLSDESC = 36 /* word64?2 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Symbol
|
||||
*/
|
||||
|
||||
typedef struct elf32_sym {
|
||||
Elf32_Word st_name;
|
||||
Elf32_Addr st_value;
|
||||
Elf32_Word st_size;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
Elf32_Half st_shndx;
|
||||
} Elf32_Sym;
|
||||
|
||||
typedef struct elf64_sym {
|
||||
Elf64_Word st_name;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
Elf64_Half st_shndx;
|
||||
Elf64_Addr st_value;
|
||||
Elf64_Xword st_size;
|
||||
} Elf64_Sym;
|
||||
|
||||
/*
|
||||
* Main file header
|
||||
*/
|
||||
|
||||
typedef struct elf32_hdr {
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
Elf32_Half e_type;
|
||||
Elf32_Half e_machine;
|
||||
Elf32_Word e_version;
|
||||
Elf32_Addr e_entry;
|
||||
Elf32_Off e_phoff;
|
||||
Elf32_Off e_shoff;
|
||||
Elf32_Word e_flags;
|
||||
Elf32_Half e_ehsize;
|
||||
Elf32_Half e_phentsize;
|
||||
Elf32_Half e_phnum;
|
||||
Elf32_Half e_shentsize;
|
||||
Elf32_Half e_shnum;
|
||||
Elf32_Half e_shstrndx;
|
||||
} Elf32_Ehdr;
|
||||
|
||||
typedef struct elf64_hdr {
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
Elf64_Half e_type;
|
||||
Elf64_Half e_machine;
|
||||
Elf64_Word e_version;
|
||||
Elf64_Addr e_entry;
|
||||
Elf64_Off e_phoff;
|
||||
Elf64_Off e_shoff;
|
||||
Elf64_Word e_flags;
|
||||
Elf64_Half e_ehsize;
|
||||
Elf64_Half e_phentsize;
|
||||
Elf64_Half e_phnum;
|
||||
Elf64_Half e_shentsize;
|
||||
Elf64_Half e_shnum;
|
||||
Elf64_Half e_shstrndx;
|
||||
} Elf64_Ehdr;
|
||||
|
||||
/*
|
||||
* Program header
|
||||
*/
|
||||
|
||||
typedef struct elf32_phdr {
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
} Elf32_Phdr;
|
||||
|
||||
typedef struct elf64_phdr {
|
||||
Elf64_Word p_type;
|
||||
Elf64_Word p_flags;
|
||||
Elf64_Off p_offset;
|
||||
Elf64_Addr p_vaddr;
|
||||
Elf64_Addr p_paddr;
|
||||
Elf64_Xword p_filesz;
|
||||
Elf64_Xword p_memsz;
|
||||
Elf64_Xword p_align;
|
||||
} Elf64_Phdr;
|
||||
|
||||
/*
|
||||
* Section header
|
||||
*/
|
||||
|
||||
typedef struct elf32_shdr {
|
||||
Elf32_Word sh_name;
|
||||
Elf32_Word sh_type;
|
||||
Elf32_Word sh_flags;
|
||||
Elf32_Addr sh_addr;
|
||||
Elf32_Off sh_offset;
|
||||
Elf32_Word sh_size;
|
||||
Elf32_Word sh_link;
|
||||
Elf32_Word sh_info;
|
||||
Elf32_Word sh_addralign;
|
||||
Elf32_Word sh_entsize;
|
||||
} Elf32_Shdr;
|
||||
|
||||
typedef struct elf64_shdr {
|
||||
Elf64_Word sh_name;
|
||||
Elf64_Word sh_type;
|
||||
Elf64_Xword sh_flags;
|
||||
Elf64_Addr sh_addr;
|
||||
Elf64_Off sh_offset;
|
||||
Elf64_Xword sh_size;
|
||||
Elf64_Word sh_link;
|
||||
Elf64_Word sh_info;
|
||||
Elf64_Xword sh_addralign;
|
||||
Elf64_Xword sh_entsize;
|
||||
} Elf64_Shdr;
|
||||
|
||||
/*
|
||||
* Note header
|
||||
*/
|
||||
typedef struct elf32_note {
|
||||
Elf32_Word n_namesz; /* Name size */
|
||||
Elf32_Word n_descsz; /* Content size */
|
||||
Elf32_Word n_type; /* Content type */
|
||||
} Elf32_Nhdr;
|
||||
|
||||
typedef struct elf64_note {
|
||||
Elf64_Word n_namesz; /* Name size */
|
||||
Elf64_Word n_descsz; /* Content size */
|
||||
Elf64_Word n_type; /* Content type */
|
||||
} Elf64_Nhdr;
|
||||
|
||||
#endif /* OUTPUT_ELF_H */
|
||||
252
include/error.h
Normal file
252
include/error.h
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2024 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* Error reporting functions for the assembler
|
||||
*/
|
||||
|
||||
#ifndef NASM_ERROR_H
|
||||
#define NASM_ERROR_H 1
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*
|
||||
* Typedef for the severity field
|
||||
*/
|
||||
typedef uint32_t errflags;
|
||||
|
||||
/*
|
||||
* An error reporting function should look like this.
|
||||
*/
|
||||
void printf_func(2, 3) nasm_error(errflags severity, const char *fmt, ...);
|
||||
void printf_func(1, 2) nasm_listmsg(const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_listmsgf(errflags flags, const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_debug_(unsigned int level, const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_info_(unsigned int level, const char *fmt, ...);
|
||||
void printf_func(1, 2) nasm_note(const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_notef(errflags flags, const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_warn_(errflags flags, const char *fmt, ...);
|
||||
void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...);
|
||||
void printf_func(2, 3) nasm_nonfatalf(errflags flags, const char *fmt, ...);
|
||||
void printf_func(1, 2) nasm_holderr(const char *fmt, ...);
|
||||
fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
|
||||
fatal_func printf_func(2, 3) nasm_fatalf(errflags flags, const char *fmt, ...);
|
||||
fatal_func printf_func(1, 2) nasm_critical(const char *fmt, ...);
|
||||
fatal_func printf_func(2, 3) nasm_criticalf(errflags flags, const char *fmt, ...);
|
||||
fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
|
||||
fatal_func printf_func(2, 3) nasm_panicf(errflags flags, const char *fmt, ...);
|
||||
fatal_func nasm_panic_from_macro(const char *func, const char *file, int line);
|
||||
#define panic() nasm_panic_from_macro(NASM_FUNC,__FILE__,__LINE__)
|
||||
|
||||
void vprintf_func(2) nasm_verror(errflags severity, const char *fmt, va_list ap);
|
||||
fatal_func vprintf_func(2) nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
|
||||
|
||||
const char *error_pfx(errflags severity);
|
||||
|
||||
/*
|
||||
* These are the error severity codes which get passed as the first
|
||||
* argument to an efunc. The order here matters!
|
||||
*/
|
||||
|
||||
/* For the list file only */
|
||||
#define ERR_LISTMSG 0x00000000 /* for the listing file only (comment prefix) */
|
||||
#define ERR_NOTE 0x00000001 /* for the listing file only (with prefix) */
|
||||
|
||||
/* Non-terminating diagnostics; can be suppressed */
|
||||
#define ERR_DEBUG 0x00000004 /* internal debugging message */
|
||||
#define ERR_INFO 0x00000005 /* informational message */
|
||||
#define ERR_WARNING 0x00000006 /* warning */
|
||||
|
||||
/* Errors which terminate assembly without output */
|
||||
#define ERR_NONFATAL 0x00000008 /* terminate assembly after the current pass */
|
||||
|
||||
/*
|
||||
* From this point, errors cannot be suppressed, and the C compiler is
|
||||
* told that the call to nasm_verror() is terminating, to remove the
|
||||
* need to generate further code.
|
||||
*/
|
||||
#define ERR_FATAL 0x0000000c /* terminate immediately, but perform cleanup */
|
||||
|
||||
/*
|
||||
* Abort conditions - terminate with minimal or no cleanup.
|
||||
*
|
||||
* ERR_CRITICAL is used for system errors like out of memory, where the normal
|
||||
* error and cleanup paths may impede informing the user of the nature of the failure.
|
||||
*
|
||||
* ERR_PANIC is used exclusively to trigger on bugs in the NASM code itself.
|
||||
*/
|
||||
#define ERR_CRITICAL 0x0000000e /* fatal, but minimize code before exit */
|
||||
#define ERR_PANIC 0x0000000f /* internal error: panic instantly
|
||||
* and call abort() to dump core for reference */
|
||||
|
||||
#define ERR_MASK 0x0000000f /* mask off the above codes */
|
||||
#define ERR_UNDEAD 0x00000010 /* skip if we already have errors */
|
||||
#define ERR_NOFILE 0x00000020 /* don't give source file name/line */
|
||||
#define ERR_HERE 0x00000040 /* point to a specific source location */
|
||||
#define ERR_USAGE 0x00000080 /* print a usage message */
|
||||
#define ERR_PASS2 0x00000100 /* ignore unless on pass_final */
|
||||
|
||||
#define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
|
||||
#define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
|
||||
#define ERR_PP_LISTMACRO 0x00000800 /* from pp_error_list_macros() */
|
||||
#define ERR_HOLD 0x00001000 /* this error/warning can be held */
|
||||
#define ERR_PERROR 0x00002000 /* append strerror(errno) */
|
||||
|
||||
/*
|
||||
* These codes define specific types of suppressible warning.
|
||||
* They are assumed to occupy the most significant bits of the
|
||||
* severity code.
|
||||
*/
|
||||
#define WARN_SHR 16 /* how far to shift right */
|
||||
#define WARN_IDX(x) (((errflags)(x)) >> WARN_SHR)
|
||||
#define WARN_MASK ((~(errflags)0) << WARN_SHR)
|
||||
#define WARNING(x) ((errflags)(x) << WARN_SHR)
|
||||
|
||||
/* The same field is used for debug and info levels */
|
||||
#define LEVEL_SHR WARN_SHR
|
||||
#define LEVEL(x) WARNING(x)
|
||||
|
||||
/* This is a bitmask */
|
||||
#define WARN_ST_ENABLED 1 /* Warning is currently enabled */
|
||||
#define WARN_ST_ERROR 2 /* Treat this warning as an error */
|
||||
|
||||
/* Possible initial state for warnings */
|
||||
#define WARN_INIT_OFF 0
|
||||
#define WARN_INIT_ON WARN_ST_ENABLED
|
||||
#define WARN_INIT_ERR (WARN_ST_ENABLED|WARN_ST_ERROR)
|
||||
|
||||
/* Options and status to/from the error module */
|
||||
struct errinfo {
|
||||
FILE *file; /* Error output file pointer */
|
||||
errflags worst; /* Worst severity class encountered */
|
||||
errflags never; /* Error flags to unconditionally suppress */
|
||||
unsigned int debug_nasm; /* Debug message level */
|
||||
unsigned int verbose_info; /* Info message level */
|
||||
bool abort_on_panic; /* Call abort() on ERR_PANIC */
|
||||
};
|
||||
extern struct errinfo erropt;
|
||||
|
||||
int set_error_format(const char *fmt);
|
||||
void error_init(void);
|
||||
void error_pass_start(bool final);
|
||||
void error_pass_end(void);
|
||||
|
||||
/* Process a warning option or directive */
|
||||
bool set_warning_status(const char *value);
|
||||
|
||||
/* Warning stack management */
|
||||
void push_warnings(void);
|
||||
void pop_warnings(void);
|
||||
|
||||
/*
|
||||
* Tentative error hold for warnings/errors indicated with ERR_HOLD.
|
||||
*
|
||||
* This is a stack; the "hold" argument *must*
|
||||
* match the value returned from nasm_error_hold_push().
|
||||
* If "issue" is true the errors are committed (or promoted to the next
|
||||
* higher stack level), if false then they are discarded.
|
||||
*
|
||||
* Return the highest severity level issued or discarded; note that if
|
||||
* promoted, the severity level will be reported at the time the
|
||||
* messages are issued, when the top level stack is popped. Fix this if
|
||||
* this ever becomes a problem, but it would come at a cost.
|
||||
*
|
||||
* Errors stronger than ERR_NONFATAL cannot be held.
|
||||
*/
|
||||
struct nasm_errhold;
|
||||
typedef struct nasm_errhold *errhold;
|
||||
errhold nasm_error_hold_push(void);
|
||||
errflags nasm_error_hold_pop(errhold hold, bool issue);
|
||||
|
||||
/* Should be included from within error.h only */
|
||||
#include "warnings.h"
|
||||
|
||||
/* True if a warning is enabled, either as a warning or an error */
|
||||
static inline bool warn_active(errflags warn)
|
||||
{
|
||||
if (warn & erropt.never)
|
||||
return false;
|
||||
|
||||
return !!(warning_state[WARN_IDX(warn)] & WARN_ST_ENABLED);
|
||||
}
|
||||
|
||||
/*
|
||||
* By defining MAX_DEBUG or MAX_INFO, it is possible to
|
||||
* compile out messages entirely.
|
||||
*/
|
||||
#ifndef MAX_DEBUG
|
||||
# define MAX_DEBUG UINT_MAX
|
||||
#endif
|
||||
#ifndef MAX_INFO
|
||||
# define MAX_INFO UINT_MAX
|
||||
#endif
|
||||
|
||||
/* Debug level checks */
|
||||
static inline bool debug_level(unsigned int level)
|
||||
{
|
||||
if (is_constant(level) && level > MAX_DEBUG)
|
||||
return false;
|
||||
return unlikely(level <= erropt.debug_nasm);
|
||||
}
|
||||
|
||||
/* Info level checks */
|
||||
static inline bool info_level(unsigned int level)
|
||||
{
|
||||
if (is_constant(level) && level > MAX_INFO)
|
||||
return false;
|
||||
return unlikely(level <= erropt.verbose_info);
|
||||
}
|
||||
|
||||
#ifdef HAVE_VARIADIC_MACROS
|
||||
|
||||
/*
|
||||
* Marked unlikely() to avoid excessive speed penalties on disabled warnings;
|
||||
* if the warning is issued then the performance penalty is substantial
|
||||
* anyway.
|
||||
*/
|
||||
#define nasm_warn(w, ...) \
|
||||
do { \
|
||||
const errflags _w = (w); \
|
||||
if (unlikely(warn_active(_w))) { \
|
||||
nasm_warn_(_w, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define nasm_info(l, ...) \
|
||||
do { \
|
||||
const unsigned int _l = (l); \
|
||||
if (unlikely(info_level(_l))) \
|
||||
nasm_info_(_l, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define nasm_debug(l, ...) \
|
||||
do { \
|
||||
const unsigned int _l = (l); \
|
||||
if (unlikely(debug_level(_l))) \
|
||||
nasm_debug_(_l, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define nasm_warn nasm_warn_
|
||||
#if MAX_DEBUG
|
||||
# define nasm_debug nasm_debug_
|
||||
#else
|
||||
# define nasm_debug (void)
|
||||
#endif
|
||||
#if MAX_INFO
|
||||
# define nasm_info nasm_info_
|
||||
#else
|
||||
# define nasm_info (void)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Callbacks from the error module */
|
||||
void print_final_report(bool failure);
|
||||
void close_output(bool failure);
|
||||
bool pp_suppress_error(errflags flags);
|
||||
void pp_error_list_macros(errflags flags);
|
||||
|
||||
|
||||
#endif /* NASM_ERROR_H */
|
||||
19
include/eval.h
Normal file
19
include/eval.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* eval.h header file for eval.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_EVAL_H
|
||||
#define NASM_EVAL_H
|
||||
|
||||
/*
|
||||
* The evaluator itself.
|
||||
*/
|
||||
expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
|
||||
int *fwref, bool critical, struct eval_hints *hints);
|
||||
|
||||
void eval_cleanup(void);
|
||||
|
||||
#endif
|
||||
44
include/files.h
Normal file
44
include/files.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2026 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_FILES_H
|
||||
#define NASM_FILES_H 1
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h" /* For nasm_assert() */
|
||||
|
||||
/*
|
||||
* Primary file names set on the command line etc.
|
||||
* Wrapped in accessors to make them as constant as possible.
|
||||
*/
|
||||
enum filenames {
|
||||
/* These two entries must be first, in this order */
|
||||
FN_INFILE, /* Primary input file */
|
||||
FN_OUTFILE, /* Primary output file */
|
||||
|
||||
FN_ERRFILE, /* Error message file */
|
||||
FN_LISTFILE, /* Listing file */
|
||||
FN_DEPENDFILE, /* Dependency file */
|
||||
FN_MAPFILE, /* Map file (outbin) */
|
||||
FN_NFILES
|
||||
};
|
||||
|
||||
extern const char *_filenames[FN_NFILES];
|
||||
|
||||
static inline const char *get_filename(enum filenames fn)
|
||||
{
|
||||
nasm_assert((size_t)fn < ARRAY_SIZE(_filenames));
|
||||
return _filenames[fn];
|
||||
}
|
||||
|
||||
/*
|
||||
* copy_filename() makes a private copy for the files subsystem,
|
||||
* set_nocopy() expects an allocated string for the files subsystem to
|
||||
* take over.
|
||||
*/
|
||||
const char *copy_filename(enum filenames fn, const char *src);
|
||||
const char *set_filename(enum filenames fn, char *src);
|
||||
void check_overwrite_files(void);
|
||||
void cleanup_filenames(void);
|
||||
|
||||
#endif /* NASM_FILES_H */
|
||||
37
include/floats.h
Normal file
37
include/floats.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* floats.h header file for the floating-point constant module of
|
||||
* the Netwide Assembler
|
||||
*/
|
||||
|
||||
#ifndef NASM_FLOATS_H
|
||||
#define NASM_FLOATS_H
|
||||
|
||||
#include "nasm.h"
|
||||
|
||||
enum float_round {
|
||||
FLOAT_RC_NEAR,
|
||||
FLOAT_RC_ZERO,
|
||||
FLOAT_RC_DOWN,
|
||||
FLOAT_RC_UP
|
||||
};
|
||||
|
||||
/* Note: enum floatize and FLOAT_ERR are defined in nasm.h */
|
||||
|
||||
/* Floating-point format description */
|
||||
struct ieee_format {
|
||||
int bytes; /* Total bytes */
|
||||
int mantissa; /* Fractional bits in the mantissa */
|
||||
int explicit; /* Explicit integer */
|
||||
int exponent; /* Bits in the exponent */
|
||||
int offset; /* Offset into byte array for floatize op */
|
||||
};
|
||||
extern const struct ieee_format fp_formats[FLOAT_ERR];
|
||||
|
||||
int float_const(const char *str, int s, uint8_t *result, enum floatize ffmt);
|
||||
enum floatize const_func float_deffmt(int bytes);
|
||||
int float_option(const char *option);
|
||||
|
||||
#endif /* NASM_FLOATS_H */
|
||||
214
include/gzguts.h
Normal file
214
include/gzguts.h
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||
* Copyright (C) 2004-2024 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# ifndef _LARGEFILE_SOURCE
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
# endif
|
||||
# undef _FILE_OFFSET_BITS
|
||||
# undef _TIME_BITS
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
#ifdef STDC
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define WIDECHAR
|
||||
#endif
|
||||
|
||||
#ifdef WINAPI_FAMILY
|
||||
# define open _open
|
||||
# define read _read
|
||||
# define write _write
|
||||
# define close _close
|
||||
#endif
|
||||
|
||||
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||
# define NO_GZCOMPRESS
|
||||
#endif
|
||||
|
||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef MSDOS
|
||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||
but for now we just assume it doesn't. */
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __TURBOC__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef VMS
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __OS400__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __MVS__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
||||
null termination of the result -- however this is only used in gzlib.c where
|
||||
the result is assured to fit in the space provided */
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* since "static" is used to mean two completely different things in C, we
|
||||
define "local" for the non-static meaning of "static", for readability
|
||||
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||
|
||||
/* gz* functions always use library allocation functions */
|
||||
#ifndef STDC
|
||||
extern voidp malloc(uInt size);
|
||||
extern void free(voidpf ptr);
|
||||
#endif
|
||||
|
||||
/* get errno and strerror definition */
|
||||
#if defined UNDER_CE
|
||||
# include <windows.h>
|
||||
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
||||
#else
|
||||
# ifndef NO_STRERROR
|
||||
# include <errno.h>
|
||||
# define zstrerror() strerror(errno)
|
||||
# else
|
||||
# define zstrerror() "stdio error (consult errno)"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
||||
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
|
||||
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
|
||||
#endif
|
||||
|
||||
/* default memLevel */
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
|
||||
/* default i/o buffer size -- double this for output when reading (this and
|
||||
twice this must be able to fit in an unsigned type) */
|
||||
#define GZBUFSIZE 8192
|
||||
|
||||
/* gzip modes, also provide a little integrity check on the passed structure */
|
||||
#define GZ_NONE 0
|
||||
#define GZ_READ 7247
|
||||
#define GZ_WRITE 31153
|
||||
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
||||
|
||||
/* values for gz_state how */
|
||||
#define LOOK 0 /* look for a gzip header */
|
||||
#define COPY 1 /* copy input directly */
|
||||
#define GZIP 2 /* decompress a gzip stream */
|
||||
|
||||
/* internal gzip file state data structure */
|
||||
typedef struct {
|
||||
/* exposed contents for gzgetc() macro */
|
||||
struct gzFile_s x; /* "x" for exposed */
|
||||
/* x.have: number of bytes available at x.next */
|
||||
/* x.next: next output data to deliver or write */
|
||||
/* x.pos: current position in uncompressed data */
|
||||
/* used for both reading and writing */
|
||||
int mode; /* see gzip modes above */
|
||||
int fd; /* file descriptor */
|
||||
char *path; /* path or fd for error messages */
|
||||
unsigned size; /* buffer size, zero if not allocated yet */
|
||||
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
||||
unsigned char *in; /* input buffer (double-sized when writing) */
|
||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||
int direct; /* 0 if processing gzip, 1 if transparent */
|
||||
/* just for reading */
|
||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||
int eof; /* true if end of input file reached */
|
||||
int past; /* true if read requested past end */
|
||||
/* just for writing */
|
||||
int level; /* compression level */
|
||||
int strategy; /* compression strategy */
|
||||
int reset; /* true if a reset is pending after a Z_FINISH */
|
||||
/* seek request */
|
||||
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
||||
int seek; /* true if seek request pending */
|
||||
/* error information */
|
||||
int err; /* error code */
|
||||
char *msg; /* error message */
|
||||
/* zlib inflate or deflate stream */
|
||||
z_stream strm; /* stream structure in-place (not a pointer) */
|
||||
} gz_state;
|
||||
typedef gz_state FAR *gz_statep;
|
||||
|
||||
/* shared functions */
|
||||
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
|
||||
#if defined UNDER_CE
|
||||
char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
|
||||
#endif
|
||||
|
||||
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
||||
value -- needed when comparing unsigned to z_off64_t, which is signed
|
||||
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
||||
unsigned ZLIB_INTERNAL gz_intmax(void);
|
||||
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
||||
78
include/hashtbl.h
Normal file
78
include/hashtbl.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* hashtbl.h
|
||||
*
|
||||
* Efficient dictionary hash table class.
|
||||
*/
|
||||
|
||||
#ifndef NASM_HASHTBL_H
|
||||
#define NASM_HASHTBL_H
|
||||
|
||||
#include "nasmlib.h"
|
||||
|
||||
struct hash_node {
|
||||
uint64_t hash;
|
||||
const void *key;
|
||||
size_t keylen;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct hash_table {
|
||||
struct hash_node *table;
|
||||
size_t load;
|
||||
size_t size;
|
||||
size_t max_load;
|
||||
};
|
||||
|
||||
struct hash_insert {
|
||||
struct hash_table *head;
|
||||
struct hash_node *where;
|
||||
struct hash_node node;
|
||||
};
|
||||
|
||||
struct hash_iterator {
|
||||
const struct hash_table *head;
|
||||
const struct hash_node *next;
|
||||
};
|
||||
|
||||
uint64_t pure_func crc64(uint64_t crc, const char *string);
|
||||
uint64_t pure_func crc64i(uint64_t crc, const char *string);
|
||||
uint64_t pure_func crc64b(uint64_t crc, const void *data, size_t len);
|
||||
uint64_t pure_func crc64ib(uint64_t crc, const void *data, size_t len);
|
||||
#define CRC64_INIT UINT64_C(0xffffffffffffffff)
|
||||
|
||||
static inline uint64_t crc64_byte(uint64_t crc, uint8_t v)
|
||||
{
|
||||
extern const uint64_t crc64_tab[256];
|
||||
return crc64_tab[(uint8_t)(v ^ crc)] ^ (crc >> 8);
|
||||
}
|
||||
|
||||
uint32_t pure_func crc32b(uint32_t crc, const void *data, size_t len);
|
||||
|
||||
void **hash_find(struct hash_table *head, const char *string,
|
||||
struct hash_insert *insert);
|
||||
void **hash_findb(struct hash_table *head, const void *key, size_t keylen,
|
||||
struct hash_insert *insert);
|
||||
void **hash_findi(struct hash_table *head, const char *string,
|
||||
struct hash_insert *insert);
|
||||
void **hash_findib(struct hash_table *head, const void *key, size_t keylen,
|
||||
struct hash_insert *insert);
|
||||
void **hash_add(struct hash_insert *insert, const void *key, void *data);
|
||||
static inline void hash_iterator_init(const struct hash_table *head,
|
||||
struct hash_iterator *iterator)
|
||||
{
|
||||
iterator->head = head;
|
||||
iterator->next = head->table;
|
||||
}
|
||||
const struct hash_node *hash_iterate(struct hash_iterator *iterator);
|
||||
|
||||
#define hash_for_each(_head,_it,_np) \
|
||||
for (hash_iterator_init((_head), &(_it)), (_np) = hash_iterate(&(_it)) ; \
|
||||
(_np) ; (_np) = hash_iterate(&(_it)))
|
||||
|
||||
void hash_free(struct hash_table *head);
|
||||
void hash_free_all(struct hash_table *head, bool free_keys);
|
||||
|
||||
#endif /* NASM_HASHTBL_H */
|
||||
143
include/iflag.h
Normal file
143
include/iflag.h
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#ifndef NASM_IFLAG_H
|
||||
#define NASM_IFLAG_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "ilog2.h"
|
||||
|
||||
|
||||
#include "iflaggen.h"
|
||||
|
||||
#define IF_GENBIT(bit) (UINT32_C(1) << ((bit) & 31))
|
||||
|
||||
static inline int ifcomp(uint32_t a, uint32_t b)
|
||||
{
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
static inline bool iflag_test(const iflag_t *f, unsigned int bit)
|
||||
{
|
||||
return !!(f->field[bit >> 5] & IF_GENBIT(bit));
|
||||
}
|
||||
|
||||
static inline void iflag_set(iflag_t *f, unsigned int bit)
|
||||
{
|
||||
f->field[bit >> 5] |= IF_GENBIT(bit);
|
||||
}
|
||||
|
||||
static inline void iflag_clear(iflag_t *f, unsigned int bit)
|
||||
{
|
||||
f->field[bit >> 5] &= ~IF_GENBIT(bit);
|
||||
}
|
||||
|
||||
static inline void iflag_clear_all(iflag_t *f)
|
||||
{
|
||||
memset(f, 0, sizeof(*f));
|
||||
}
|
||||
|
||||
static inline void iflag_set_all(iflag_t *f)
|
||||
{
|
||||
memset(f, ~0, sizeof(*f));
|
||||
}
|
||||
|
||||
#define iflag_for_each_field(v) for ((v) = 0; (v) < IF_FIELD_COUNT; (v)++)
|
||||
|
||||
static inline int iflag_cmp(const iflag_t *a, const iflag_t *b)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* This is intentionally a reverse loop! */
|
||||
for (i = IF_FIELD_COUNT-1; i >= 0; i--) {
|
||||
if (a->field[i] == b->field[i])
|
||||
continue;
|
||||
|
||||
return ifcomp(a->field[i], b->field[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define IF_GEN_HELPER(name, op) \
|
||||
static inline iflag_t iflag_##name(const iflag_t *a, const iflag_t *b) \
|
||||
{ \
|
||||
unsigned int i; \
|
||||
iflag_t res; \
|
||||
\
|
||||
iflag_for_each_field(i) \
|
||||
res.field[i] = a->field[i] op b->field[i]; \
|
||||
\
|
||||
return res; \
|
||||
}
|
||||
|
||||
IF_GEN_HELPER(xor, ^)
|
||||
|
||||
/* Some helpers which are to work with predefined masks */
|
||||
/* TSMASK = "True size" mask */
|
||||
#define IF_TSMASK (IFM_SB|IFM_SW|IFM_SD|IFM_SQ|IFM_ST|IFM_SO|\
|
||||
IFM_SY|IFM_SZ)
|
||||
#define IF_SMASK (IF_TSMASK|IFM_NWSIZE|IFM_OSIZE|IFM_ASIZE|\
|
||||
IFM_ANYSIZE|IFM_SX)
|
||||
#define IF_ARMASK (IFM_AR0|IFM_AR1|IFM_AR2|IFM_AR3|IFM_AR4)
|
||||
#define IF_SMMASK (IFM_SM0|IFM_SM1|IFM_SM2|IFM_SM3|IFM_SM4)
|
||||
|
||||
#define _itemp_smask(idx) (insns_flags[(idx)].field[0] & IF_SMASK)
|
||||
#define _itemp_armask(idx) (insns_flags[(idx)].field[0] & IF_ARMASK)
|
||||
#define _itemp_smmask(idx) (insns_flags[(idx)].field[0] & IF_SMMASK)
|
||||
#define _itemp_arx(idx) (_itemp_armask(idx) >> IF_AR0)
|
||||
#define _itemp_smx(idx) (_itemp_smmask(idx) >> IF_SM0)
|
||||
|
||||
#define itemp_smask(itemp) _itemp_smask((itemp)->iflag_idx)
|
||||
#define itemp_armask(itemp) _itemp_armask((itemp)->iflag_idx)
|
||||
#define itemp_smmask(itemp) _itemp_smmask((itemp)->iflag_idx)
|
||||
#define itemp_arx(itemp) _itemp_arx((itemp)->iflag_idx)
|
||||
#define itemp_smx(itemp) _itemp_smx((itemp)->iflag_idx)
|
||||
|
||||
/*
|
||||
* IF_ANY is the highest CPU level by definition
|
||||
*/
|
||||
#define IF_CPU_LEVEL_MASK ((IFM_ANY << 1) - 1)
|
||||
|
||||
static inline int iflag_cmp_cpu(const iflag_t *a, const iflag_t *b)
|
||||
{
|
||||
return ifcomp(a->field[IF_CPU_FIELD], b->field[IF_CPU_FIELD]);
|
||||
}
|
||||
|
||||
static inline uint32_t _iflag_cpu_level(const iflag_t *a)
|
||||
{
|
||||
return a->field[IF_CPU_FIELD] & IF_CPU_LEVEL_MASK;
|
||||
}
|
||||
|
||||
static inline int iflag_cmp_cpu_level(const iflag_t *a, const iflag_t *b)
|
||||
{
|
||||
return ifcomp(_iflag_cpu_level(a), _iflag_cpu_level(b));
|
||||
}
|
||||
|
||||
/* Returns true if the CPU level is at least a certain value */
|
||||
static inline bool iflag_cpu_level_ok(const iflag_t *a, unsigned int bit)
|
||||
{
|
||||
return _iflag_cpu_level(a) >= IF_GENBIT(bit);
|
||||
}
|
||||
|
||||
static inline void iflag_set_all_features(iflag_t *a)
|
||||
{
|
||||
uint32_t *p = &a->field[IF_FEATURE_FIELD];
|
||||
|
||||
memset(p, -1, IF_FEATURE_NFIELDS * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
static inline iflag_t _iflag_pfmask(const iflag_t *a)
|
||||
{
|
||||
iflag_t r;
|
||||
|
||||
iflag_clear_all(&r);
|
||||
|
||||
if (iflag_test(a, IF_CYRIX))
|
||||
iflag_set(&r, IF_CYRIX);
|
||||
if (iflag_test(a, IF_AMD))
|
||||
iflag_set(&r, IF_AMD);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#define iflag_pfmask(itemp) _iflag_pfmask(&insns_flags[(itemp)->iflag_idx])
|
||||
|
||||
#endif /* NASM_IFLAG_H */
|
||||
431
include/iflaggen.h
Normal file
431
include/iflaggen.h
Normal file
|
|
@ -0,0 +1,431 @@
|
|||
/* This file is auto-generated. Don't edit. */
|
||||
#ifndef NASM_IFLAGGEN_H
|
||||
#define NASM_IFLAGGEN_H 1
|
||||
|
||||
#define IF_SM0 0 /* Size match operand 0 */
|
||||
#define IF_SM1 1 /* Size match operand 1 */
|
||||
#define IF_SM2 2 /* Size match operand 2 */
|
||||
#define IF_SM3 3 /* Size match operand 3 */
|
||||
#define IF_SM4 4 /* Size match operand 4 */
|
||||
#define IF_AR0 5 /* SB, SW, SD applies to operand 0 */
|
||||
#define IF_AR1 6 /* SB, SW, SD applies to operand 1 */
|
||||
#define IF_AR2 7 /* SB, SW, SD applies to operand 2 */
|
||||
#define IF_AR3 8 /* SB, SW, SD applies to operand 3 */
|
||||
#define IF_AR4 9 /* SB, SW, SD applies to operand 4 */
|
||||
#define IF_SB 10 /* Unsized operands can't be non-byte */
|
||||
#define IF_SW 11 /* Unsized operands can't be non-word */
|
||||
#define IF_SD 12 /* Unsized operands can't be non-dword */
|
||||
#define IF_SQ 13 /* Unsized operands can't be non-qword */
|
||||
#define IF_ST 14 /* Unsized operands can't be non-tword */
|
||||
#define IF_SO 15 /* Unsized operands can't be non-oword */
|
||||
#define IF_SY 16 /* Unsized operands can't be non-yword */
|
||||
#define IF_SZ 17 /* Unsized operands can't be non-zword */
|
||||
#define IF_NWSIZE 18 /* Operand size defaults to 64 in 64-bit mode */
|
||||
#define IF_OSIZE 19 /* Unsized operands must match the operand size */
|
||||
#define IF_ASIZE 20 /* Unsized operands must match the address size */
|
||||
#define IF_ANYSIZE 21 /* Ignore operand size even if explicit */
|
||||
#define IF_SX 22 /* Unsized operands not allowed */
|
||||
#define IF_SDWORD 23 /* Strict sdword64 matching */
|
||||
#define IF_PSEUDO 24 /* Pseudo-instruction (directive) */
|
||||
#define IF_JMP_RELAX 25 /* Relaxable jump instruction */
|
||||
#define IF_JCC_HINT 26 /* Hintable jump instruction */
|
||||
#define IF_OPT 27 /* Optimizing assembly only */
|
||||
#define IF_LATEVEX 28 /* Only if EVEX instructions are disabled */
|
||||
#define IF_NOREX 29 /* Instruction does not support REX encoding */
|
||||
#define IF_NOAPX 30 /* Instruction does not support APX registers or REX2 */
|
||||
#define IF_NF 31 /* Instruction supports the {nf} prefix */
|
||||
#define IF_NF_R 32 /* Instruction requires the {nf} prefix */
|
||||
#define IF_NF_N 33 /* Instruction doesn't allow the {nf} prefix */
|
||||
#define IF_NF_E 34 /* EVEX.NF set with {nf} prefix */
|
||||
#define IF_ZU 35 /* Instruction supports the {zu} prefix */
|
||||
#define IF_ZU_R 36 /* Instruction requires the {zu} prefix */
|
||||
#define IF_ZU_E 37 /* EVEX.ND set with {zu} prefix */
|
||||
#define IF_LIG 38 /* Ignore VEX/EVEX L field */
|
||||
#define IF_WIG 39 /* Ignore VEX/EVEX W field */
|
||||
#define IF_WW 40 /* VEX/EVEX W is REX.W */
|
||||
#define IF_SIB 41 /* SIB encoding required */
|
||||
#define IF_LOCK 42 /* Lockable if operand 0 is memory */
|
||||
#define IF_LOCK1 43 /* Lockable if operand 1 is memory */
|
||||
#define IF_NOLONG 44 /* Not available in long mode */
|
||||
#define IF_LONG 45 /* Long mode */
|
||||
#define IF_NOHLE 46 /* HLE prefixes forbidden */
|
||||
#define IF_MIB 47 /* split base/index EA */
|
||||
#define IF_BND 48 /* BND (0xF2) prefix available */
|
||||
#define IF_REX2 49 /* REX2 encoding required */
|
||||
#define IF_HLE 50 /* HLE prefixed */
|
||||
#define IF_FL 51 /* Instruction modifies the flags */
|
||||
#define IF_MOPVEC 52 /* M operand is a vector */
|
||||
#define IF_SCC 53 /* EVEX[27:24] is special condition code */
|
||||
#define IF_BESTDIS 54 /* Preferred disassembly pattern */
|
||||
#define IF_DFV 55 /* Destination flag values */
|
||||
/* 55...63 reserved */
|
||||
#define IF_VEX 64 /* VEX or XOP encoded instruction */
|
||||
#define IF_EVEX 65 /* EVEX encoded instruction */
|
||||
#define IF_PRIV 66 /* Privileged instruction */
|
||||
#define IF_SMM 67 /* Only valid in SMM */
|
||||
#define IF_PROT 68 /* Protected mode only */
|
||||
#define IF_UNDOC 69 /* Undocumented */
|
||||
#define IF_FPU 70 /* FPU */
|
||||
#define IF_MMX 71 /* MMX */
|
||||
#define IF_3DNOW 72 /* 3DNow! */
|
||||
#define IF_SSE 73 /* SSE (KNI, MMX2) */
|
||||
#define IF_SSE2 74 /* SSE2 */
|
||||
#define IF_SSE3 75 /* SSE3 (PNI) */
|
||||
#define IF_VMX 76 /* VMX */
|
||||
#define IF_SSSE3 77 /* SSSE3 */
|
||||
#define IF_SSE4A 78 /* AMD SSE4a */
|
||||
#define IF_SSE41 79 /* SSE4.1 */
|
||||
#define IF_SSE42 80 /* SSE4.2 */
|
||||
#define IF_SSE5 81 /* SSE5 */
|
||||
#define IF_AVX 82 /* AVX (256-bit floating point) */
|
||||
#define IF_AVX2 83 /* AVX2 (256-bit integer) */
|
||||
#define IF_FMA 84 /* Fused multiply-add */
|
||||
#define IF_BMI1 85 /* Bit manipulation instructions 1 */
|
||||
#define IF_BMI2 86 /* Bit manipulation instructions 2 */
|
||||
#define IF_TBM 87 /* */
|
||||
#define IF_RTM 88 /* */
|
||||
#define IF_AVX512 89 /* AVX-512 */
|
||||
#define IF_AVX512F 90 /* AVX-512F (base architecture) */
|
||||
#define IF_AVX512CD 91 /* AVX-512 Conflict Detection */
|
||||
#define IF_AVX512ER 92 /* AVX-512 Exponential and Reciprocal */
|
||||
#define IF_AVX512PF 93 /* AVX-512 Prefetch */
|
||||
#define IF_MPX 94 /* MPX */
|
||||
#define IF_SHA 95 /* SHA */
|
||||
#define IF_AVX512VL 96 /* AVX-512 Vector Length Orthogonality */
|
||||
#define IF_AVX512DQ 97 /* AVX-512 Dword and Qword */
|
||||
#define IF_AVX512BW 98 /* AVX-512 Byte and Word */
|
||||
#define IF_AVX512IFMA 99 /* AVX-512 IFMA instructions */
|
||||
#define IF_AVX512VBMI 100 /* AVX-512 VBMI instructions */
|
||||
#define IF_AES 101 /* AES instructions */
|
||||
#define IF_VAES 102 /* AES AVX instructions */
|
||||
#define IF_VPCLMULQDQ 103 /* AVX Carryless Multiplication */
|
||||
#define IF_GFNI 104 /* Galois Field instructions */
|
||||
#define IF_AVX512VBMI2 105 /* AVX-512 VBMI2 instructions */
|
||||
#define IF_AVX512VNNI 106 /* AVX-512 VNNI instructions */
|
||||
#define IF_AVX512BITALG 107 /* AVX-512 Bit Algorithm instructions */
|
||||
#define IF_AVX512VPOPCNTDQ 108 /* AVX-512 VPOPCNTD/VPOPCNTQ */
|
||||
#define IF_AVX5124FMAPS 109 /* AVX-512 4-iteration multiply-add */
|
||||
#define IF_AVX5124VNNIW 110 /* AVX-512 4-iteration dot product */
|
||||
#define IF_AVX512FP16 111 /* AVX-512 FP16 instructions */
|
||||
#define IF_AVX512BMM 112 /* AVX-512 BMM instructions */
|
||||
#define IF_F16C 113 /* F16C instructions */
|
||||
#define IF_SGX 114 /* Intel Software Guard Extensions (SGX) */
|
||||
#define IF_CET 115 /* Intel Control-Flow Enforcement Technology (CET) */
|
||||
#define IF_ENQCMD 116 /* Enqueue command instructions */
|
||||
#define IF_TSXLDTRK 117 /* TSX suspend load address tracking */
|
||||
#define IF_AVX512BF16 118 /* AVX-512 bfloat16 */
|
||||
#define IF_AVX512VP2INTERSECT 119 /* AVX-512 VP2INTERSECT instructions */
|
||||
#define IF_AMXTILE 120 /* AMX tile configuration instructions */
|
||||
#define IF_AMXBF16 121 /* AMX bfloat16 multiplication */
|
||||
#define IF_AMXFP16 122 /* AMX FP16 multiplication */
|
||||
#define IF_AMXFP8 123 /* AMX FP8 instructions */
|
||||
#define IF_AMXTF32 124 /* AMX TF32 multiplication */
|
||||
#define IF_AMXINT8 125 /* AMX 8-bit integer multiplication */
|
||||
#define IF_AMXCOMPLEX 126 /* AMX float16 complex multiplication */
|
||||
#define IF_AMXAVX512 127 /* EVEX zmm<-tmm conversion instructions */
|
||||
#define IF_AMXMOVRS 128 /* AMX loads with MOVRS hint */
|
||||
#define IF_AMXTRANSPOSE 129 /* AMX transpose instructions */
|
||||
#define IF_FRED 130 /* Flexible Return and Exception Delivery (FRED) */
|
||||
#define IF_RAOINT 131 /* Remote atomic operations (RAO-INT) */
|
||||
#define IF_UINTR 132 /* User interrupts */
|
||||
#define IF_CMPCCXADD 133 /* CMPccXADD instructions */
|
||||
#define IF_PREFETCHI 134 /* PREFETCHI0 and PREFETCHI1 */
|
||||
#define IF_MSRLIST 135 /* RDMSRLIST and WRMSRLIST */
|
||||
#define IF_AVXNECONVERT 136 /* AVX exceptionless floating-point conversions */
|
||||
#define IF_AVXVNNI 137 /* AVX Vector Neural Network instructions */
|
||||
#define IF_AVXVNNIINT8 138 /* AVX Vector Neural Network 8-bit integer instructions */
|
||||
#define IF_AVXVNNIINT16 139 /* AVX Vector Neural Network 16-bit integer instructions */
|
||||
#define IF_AVXIFMA 140 /* AVX integer multiply and add */
|
||||
#define IF_HRESET 141 /* History reset */
|
||||
#define IF_SMAP 142 /* Supervisor Mode Access Prevention (SMAP) */
|
||||
#define IF_SHA512 143 /* SHA512 instructions */
|
||||
#define IF_HSM3 144 /* SM3 hash instructions */
|
||||
#define IF_HSM4 145 /* SM4 hash instructions */
|
||||
#define IF_APX 146 /* Advanced Performance Extensions (APX) */
|
||||
#define IF_AVX10_1 147 /* AVX 10.1 instructions */
|
||||
#define IF_AVX10_2 148 /* AVX 10.2 instructions */
|
||||
#define IF_AVX10_VNNIINT 149 /* AVX Vector Neural Network integer instructions */
|
||||
#define IF_ADX 150 /* ADCX and ADOX instructions */
|
||||
#define IF_PKU 151 /* Protection key for user mode */
|
||||
#define IF_MONITOR 152 /* MONITOR and MWAIT */
|
||||
#define IF_MONITORX 153 /* MONITORX and MWAITX */
|
||||
#define IF_WAITPKG 154 /* User wait instruction package */
|
||||
#define IF_MSR_IMM 155 /* Immediate RDMSR/WRMSRNS instructions */
|
||||
#define IF_AESKLE 156 /* AES key locker */
|
||||
#define IF_AESKLEWIDE_KL 157 /* AES wide key locker */
|
||||
#define IF_INVPCID 158 /* INVPCID instruction */
|
||||
#define IF_PREFETCHWT1 159 /* PREFETCHWT1 instruction */
|
||||
#define IF_PBNDKB 160 /* PBNDKB instruction */
|
||||
#define IF_PCONFIG 161 /* PCONFIG instruction */
|
||||
#define IF_WBNOINVD 162 /* WBNOINVD instruction */
|
||||
#define IF_SERIALIZE 163 /* SERIALIZE instruction */
|
||||
#define IF_LKGS 164 /* LKGS instruction */
|
||||
#define IF_WRMSRNS 165 /* WRMSRNS instruction */
|
||||
#define IF_CLFLUSHOPT 166 /* CLFLUSHOPT instruction */
|
||||
#define IF_CLWB 167 /* CLWB instruction */
|
||||
#define IF_RDRAND 168 /* RDRAND instruction */
|
||||
#define IF_RDSEED 169 /* RDSEED instruction */
|
||||
#define IF_RDPID 170 /* RDPID instruction */
|
||||
#define IF_LZCNT 171 /* LZCNT instruction */
|
||||
#define IF_PTWRITE 172 /* PTWRITE instruction */
|
||||
#define IF_CLDEMOTE 173 /* CLDEMOTE instruction */
|
||||
#define IF_MOVDIRI 174 /* MOVDIRI instruction */
|
||||
#define IF_MOVDIR64B 175 /* MOVDIR64B instruction */
|
||||
#define IF_CLZERO 176 /* CLZERO instruction */
|
||||
#define IF_MOVBE 177 /* MOVBE instruction */
|
||||
#define IF_MOVRS 178 /* MOVRS instruction */
|
||||
#define IF_OBSOLETE 179 /* Instruction removed from architecture */
|
||||
#define IF_NEVER 180 /* Instruction never implemented */
|
||||
#define IF_NOP 181 /* Instruction is always a (nonintentional) NOP */
|
||||
/* 181...191 reserved */
|
||||
#define IF_8086 192 /* 8086 */
|
||||
#define IF_186 193 /* 186+ */
|
||||
#define IF_286 194 /* 286+ */
|
||||
#define IF_386 195 /* 386+ */
|
||||
#define IF_486 196 /* 486+ */
|
||||
#define IF_PENT 197 /* Pentium */
|
||||
#define IF_P6 198 /* P6 */
|
||||
#define IF_KATMAI 199 /* Katmai */
|
||||
#define IF_WILLAMETTE 200 /* Willamette */
|
||||
#define IF_PRESCOTT 201 /* Prescott */
|
||||
#define IF_IA64 202 /* IA64 (in x86 mode) */
|
||||
#define IF_X86_64 203 /* x86-64 (long or legacy mode) */
|
||||
#define IF_NEHALEM 204 /* Nehalem */
|
||||
#define IF_WESTMERE 205 /* Westmere */
|
||||
#define IF_SANDYBRIDGE 206 /* Sandy Bridge */
|
||||
#define IF_FUTURE 207 /* Ivy Bridge or newer */
|
||||
#define IF_DEFAULT 208 /* Default CPU level */
|
||||
#define IF_ANY 209 /* Allow any known instruction */
|
||||
#define IF_CYRIX 210 /* Cyrix-specific */
|
||||
#define IF_AMD 211 /* AMD-specific */
|
||||
/* 211...223 reserved */
|
||||
|
||||
/* Mask bits for field 0 : 0...31 */
|
||||
#define IFM_SM0 UINT32_C(0x00000001) /* 0 */
|
||||
#define IFM_SM1 UINT32_C(0x00000002) /* 1 */
|
||||
#define IFM_SM2 UINT32_C(0x00000004) /* 2 */
|
||||
#define IFM_SM3 UINT32_C(0x00000008) /* 3 */
|
||||
#define IFM_SM4 UINT32_C(0x00000010) /* 4 */
|
||||
#define IFM_AR0 UINT32_C(0x00000020) /* 5 */
|
||||
#define IFM_AR1 UINT32_C(0x00000040) /* 6 */
|
||||
#define IFM_AR2 UINT32_C(0x00000080) /* 7 */
|
||||
#define IFM_AR3 UINT32_C(0x00000100) /* 8 */
|
||||
#define IFM_AR4 UINT32_C(0x00000200) /* 9 */
|
||||
#define IFM_SB UINT32_C(0x00000400) /* 10 */
|
||||
#define IFM_SW UINT32_C(0x00000800) /* 11 */
|
||||
#define IFM_SD UINT32_C(0x00001000) /* 12 */
|
||||
#define IFM_SQ UINT32_C(0x00002000) /* 13 */
|
||||
#define IFM_ST UINT32_C(0x00004000) /* 14 */
|
||||
#define IFM_SO UINT32_C(0x00008000) /* 15 */
|
||||
#define IFM_SY UINT32_C(0x00010000) /* 16 */
|
||||
#define IFM_SZ UINT32_C(0x00020000) /* 17 */
|
||||
#define IFM_NWSIZE UINT32_C(0x00040000) /* 18 */
|
||||
#define IFM_OSIZE UINT32_C(0x00080000) /* 19 */
|
||||
#define IFM_ASIZE UINT32_C(0x00100000) /* 20 */
|
||||
#define IFM_ANYSIZE UINT32_C(0x00200000) /* 21 */
|
||||
#define IFM_SX UINT32_C(0x00400000) /* 22 */
|
||||
#define IFM_SDWORD UINT32_C(0x00800000) /* 23 */
|
||||
#define IFM_PSEUDO UINT32_C(0x01000000) /* 24 */
|
||||
#define IFM_JMP_RELAX UINT32_C(0x02000000) /* 25 */
|
||||
#define IFM_JCC_HINT UINT32_C(0x04000000) /* 26 */
|
||||
#define IFM_OPT UINT32_C(0x08000000) /* 27 */
|
||||
#define IFM_LATEVEX UINT32_C(0x10000000) /* 28 */
|
||||
#define IFM_NOREX UINT32_C(0x20000000) /* 29 */
|
||||
#define IFM_NOAPX UINT32_C(0x40000000) /* 30 */
|
||||
#define IFM_NF UINT32_C(0x80000000) /* 31 */
|
||||
/* Mask bits for field 1 : 32...63 */
|
||||
#define IFM_NF_R UINT32_C(0x00000001) /* 32 */
|
||||
#define IFM_NF_N UINT32_C(0x00000002) /* 33 */
|
||||
#define IFM_NF_E UINT32_C(0x00000004) /* 34 */
|
||||
#define IFM_ZU UINT32_C(0x00000008) /* 35 */
|
||||
#define IFM_ZU_R UINT32_C(0x00000010) /* 36 */
|
||||
#define IFM_ZU_E UINT32_C(0x00000020) /* 37 */
|
||||
#define IFM_LIG UINT32_C(0x00000040) /* 38 */
|
||||
#define IFM_WIG UINT32_C(0x00000080) /* 39 */
|
||||
#define IFM_WW UINT32_C(0x00000100) /* 40 */
|
||||
#define IFM_SIB UINT32_C(0x00000200) /* 41 */
|
||||
#define IFM_LOCK UINT32_C(0x00000400) /* 42 */
|
||||
#define IFM_LOCK1 UINT32_C(0x00000800) /* 43 */
|
||||
#define IFM_NOLONG UINT32_C(0x00001000) /* 44 */
|
||||
#define IFM_LONG UINT32_C(0x00002000) /* 45 */
|
||||
#define IFM_NOHLE UINT32_C(0x00004000) /* 46 */
|
||||
#define IFM_MIB UINT32_C(0x00008000) /* 47 */
|
||||
#define IFM_BND UINT32_C(0x00010000) /* 48 */
|
||||
#define IFM_REX2 UINT32_C(0x00020000) /* 49 */
|
||||
#define IFM_HLE UINT32_C(0x00040000) /* 50 */
|
||||
#define IFM_FL UINT32_C(0x00080000) /* 51 */
|
||||
#define IFM_MOPVEC UINT32_C(0x00100000) /* 52 */
|
||||
#define IFM_SCC UINT32_C(0x00200000) /* 53 */
|
||||
#define IFM_BESTDIS UINT32_C(0x00400000) /* 54 */
|
||||
#define IFM_DFV UINT32_C(0x00800000) /* 55 */
|
||||
/* Mask bits for field 2 : 64...95 */
|
||||
#define IFM_VEX UINT32_C(0x00000001) /* 64 */
|
||||
#define IFM_EVEX UINT32_C(0x00000002) /* 65 */
|
||||
#define IFM_PRIV UINT32_C(0x00000004) /* 66 */
|
||||
#define IFM_SMM UINT32_C(0x00000008) /* 67 */
|
||||
#define IFM_PROT UINT32_C(0x00000010) /* 68 */
|
||||
#define IFM_UNDOC UINT32_C(0x00000020) /* 69 */
|
||||
#define IFM_FPU UINT32_C(0x00000040) /* 70 */
|
||||
#define IFM_MMX UINT32_C(0x00000080) /* 71 */
|
||||
#define IFM_3DNOW UINT32_C(0x00000100) /* 72 */
|
||||
#define IFM_SSE UINT32_C(0x00000200) /* 73 */
|
||||
#define IFM_SSE2 UINT32_C(0x00000400) /* 74 */
|
||||
#define IFM_SSE3 UINT32_C(0x00000800) /* 75 */
|
||||
#define IFM_VMX UINT32_C(0x00001000) /* 76 */
|
||||
#define IFM_SSSE3 UINT32_C(0x00002000) /* 77 */
|
||||
#define IFM_SSE4A UINT32_C(0x00004000) /* 78 */
|
||||
#define IFM_SSE41 UINT32_C(0x00008000) /* 79 */
|
||||
#define IFM_SSE42 UINT32_C(0x00010000) /* 80 */
|
||||
#define IFM_SSE5 UINT32_C(0x00020000) /* 81 */
|
||||
#define IFM_AVX UINT32_C(0x00040000) /* 82 */
|
||||
#define IFM_AVX2 UINT32_C(0x00080000) /* 83 */
|
||||
#define IFM_FMA UINT32_C(0x00100000) /* 84 */
|
||||
#define IFM_BMI1 UINT32_C(0x00200000) /* 85 */
|
||||
#define IFM_BMI2 UINT32_C(0x00400000) /* 86 */
|
||||
#define IFM_TBM UINT32_C(0x00800000) /* 87 */
|
||||
#define IFM_RTM UINT32_C(0x01000000) /* 88 */
|
||||
#define IFM_AVX512 UINT32_C(0x02000000) /* 89 */
|
||||
#define IFM_AVX512F UINT32_C(0x04000000) /* 90 */
|
||||
#define IFM_AVX512CD UINT32_C(0x08000000) /* 91 */
|
||||
#define IFM_AVX512ER UINT32_C(0x10000000) /* 92 */
|
||||
#define IFM_AVX512PF UINT32_C(0x20000000) /* 93 */
|
||||
#define IFM_MPX UINT32_C(0x40000000) /* 94 */
|
||||
#define IFM_SHA UINT32_C(0x80000000) /* 95 */
|
||||
/* Mask bits for field 3 : 96...127 */
|
||||
#define IFM_AVX512VL UINT32_C(0x00000001) /* 96 */
|
||||
#define IFM_AVX512DQ UINT32_C(0x00000002) /* 97 */
|
||||
#define IFM_AVX512BW UINT32_C(0x00000004) /* 98 */
|
||||
#define IFM_AVX512IFMA UINT32_C(0x00000008) /* 99 */
|
||||
#define IFM_AVX512VBMI UINT32_C(0x00000010) /* 100 */
|
||||
#define IFM_AES UINT32_C(0x00000020) /* 101 */
|
||||
#define IFM_VAES UINT32_C(0x00000040) /* 102 */
|
||||
#define IFM_VPCLMULQDQ UINT32_C(0x00000080) /* 103 */
|
||||
#define IFM_GFNI UINT32_C(0x00000100) /* 104 */
|
||||
#define IFM_AVX512VBMI2 UINT32_C(0x00000200) /* 105 */
|
||||
#define IFM_AVX512VNNI UINT32_C(0x00000400) /* 106 */
|
||||
#define IFM_AVX512BITALG UINT32_C(0x00000800) /* 107 */
|
||||
#define IFM_AVX512VPOPCNTDQ UINT32_C(0x00001000) /* 108 */
|
||||
#define IFM_AVX5124FMAPS UINT32_C(0x00002000) /* 109 */
|
||||
#define IFM_AVX5124VNNIW UINT32_C(0x00004000) /* 110 */
|
||||
#define IFM_AVX512FP16 UINT32_C(0x00008000) /* 111 */
|
||||
#define IFM_AVX512BMM UINT32_C(0x00010000) /* 112 */
|
||||
#define IFM_F16C UINT32_C(0x00020000) /* 113 */
|
||||
#define IFM_SGX UINT32_C(0x00040000) /* 114 */
|
||||
#define IFM_CET UINT32_C(0x00080000) /* 115 */
|
||||
#define IFM_ENQCMD UINT32_C(0x00100000) /* 116 */
|
||||
#define IFM_TSXLDTRK UINT32_C(0x00200000) /* 117 */
|
||||
#define IFM_AVX512BF16 UINT32_C(0x00400000) /* 118 */
|
||||
#define IFM_AVX512VP2INTERSECT UINT32_C(0x00800000) /* 119 */
|
||||
#define IFM_AMXTILE UINT32_C(0x01000000) /* 120 */
|
||||
#define IFM_AMXBF16 UINT32_C(0x02000000) /* 121 */
|
||||
#define IFM_AMXFP16 UINT32_C(0x04000000) /* 122 */
|
||||
#define IFM_AMXFP8 UINT32_C(0x08000000) /* 123 */
|
||||
#define IFM_AMXTF32 UINT32_C(0x10000000) /* 124 */
|
||||
#define IFM_AMXINT8 UINT32_C(0x20000000) /* 125 */
|
||||
#define IFM_AMXCOMPLEX UINT32_C(0x40000000) /* 126 */
|
||||
#define IFM_AMXAVX512 UINT32_C(0x80000000) /* 127 */
|
||||
/* Mask bits for field 4 : 128...159 */
|
||||
#define IFM_AMXMOVRS UINT32_C(0x00000001) /* 128 */
|
||||
#define IFM_AMXTRANSPOSE UINT32_C(0x00000002) /* 129 */
|
||||
#define IFM_FRED UINT32_C(0x00000004) /* 130 */
|
||||
#define IFM_RAOINT UINT32_C(0x00000008) /* 131 */
|
||||
#define IFM_UINTR UINT32_C(0x00000010) /* 132 */
|
||||
#define IFM_CMPCCXADD UINT32_C(0x00000020) /* 133 */
|
||||
#define IFM_PREFETCHI UINT32_C(0x00000040) /* 134 */
|
||||
#define IFM_MSRLIST UINT32_C(0x00000080) /* 135 */
|
||||
#define IFM_AVXNECONVERT UINT32_C(0x00000100) /* 136 */
|
||||
#define IFM_AVXVNNI UINT32_C(0x00000200) /* 137 */
|
||||
#define IFM_AVXVNNIINT8 UINT32_C(0x00000400) /* 138 */
|
||||
#define IFM_AVXVNNIINT16 UINT32_C(0x00000800) /* 139 */
|
||||
#define IFM_AVXIFMA UINT32_C(0x00001000) /* 140 */
|
||||
#define IFM_HRESET UINT32_C(0x00002000) /* 141 */
|
||||
#define IFM_SMAP UINT32_C(0x00004000) /* 142 */
|
||||
#define IFM_SHA512 UINT32_C(0x00008000) /* 143 */
|
||||
#define IFM_HSM3 UINT32_C(0x00010000) /* 144 */
|
||||
#define IFM_HSM4 UINT32_C(0x00020000) /* 145 */
|
||||
#define IFM_APX UINT32_C(0x00040000) /* 146 */
|
||||
#define IFM_AVX10_1 UINT32_C(0x00080000) /* 147 */
|
||||
#define IFM_AVX10_2 UINT32_C(0x00100000) /* 148 */
|
||||
#define IFM_AVX10_VNNIINT UINT32_C(0x00200000) /* 149 */
|
||||
#define IFM_ADX UINT32_C(0x00400000) /* 150 */
|
||||
#define IFM_PKU UINT32_C(0x00800000) /* 151 */
|
||||
#define IFM_MONITOR UINT32_C(0x01000000) /* 152 */
|
||||
#define IFM_MONITORX UINT32_C(0x02000000) /* 153 */
|
||||
#define IFM_WAITPKG UINT32_C(0x04000000) /* 154 */
|
||||
#define IFM_MSR_IMM UINT32_C(0x08000000) /* 155 */
|
||||
#define IFM_AESKLE UINT32_C(0x10000000) /* 156 */
|
||||
#define IFM_AESKLEWIDE_KL UINT32_C(0x20000000) /* 157 */
|
||||
#define IFM_INVPCID UINT32_C(0x40000000) /* 158 */
|
||||
#define IFM_PREFETCHWT1 UINT32_C(0x80000000) /* 159 */
|
||||
/* Mask bits for field 5 : 160...191 */
|
||||
#define IFM_PBNDKB UINT32_C(0x00000001) /* 160 */
|
||||
#define IFM_PCONFIG UINT32_C(0x00000002) /* 161 */
|
||||
#define IFM_WBNOINVD UINT32_C(0x00000004) /* 162 */
|
||||
#define IFM_SERIALIZE UINT32_C(0x00000008) /* 163 */
|
||||
#define IFM_LKGS UINT32_C(0x00000010) /* 164 */
|
||||
#define IFM_WRMSRNS UINT32_C(0x00000020) /* 165 */
|
||||
#define IFM_CLFLUSHOPT UINT32_C(0x00000040) /* 166 */
|
||||
#define IFM_CLWB UINT32_C(0x00000080) /* 167 */
|
||||
#define IFM_RDRAND UINT32_C(0x00000100) /* 168 */
|
||||
#define IFM_RDSEED UINT32_C(0x00000200) /* 169 */
|
||||
#define IFM_RDPID UINT32_C(0x00000400) /* 170 */
|
||||
#define IFM_LZCNT UINT32_C(0x00000800) /* 171 */
|
||||
#define IFM_PTWRITE UINT32_C(0x00001000) /* 172 */
|
||||
#define IFM_CLDEMOTE UINT32_C(0x00002000) /* 173 */
|
||||
#define IFM_MOVDIRI UINT32_C(0x00004000) /* 174 */
|
||||
#define IFM_MOVDIR64B UINT32_C(0x00008000) /* 175 */
|
||||
#define IFM_CLZERO UINT32_C(0x00010000) /* 176 */
|
||||
#define IFM_MOVBE UINT32_C(0x00020000) /* 177 */
|
||||
#define IFM_MOVRS UINT32_C(0x00040000) /* 178 */
|
||||
#define IFM_OBSOLETE UINT32_C(0x00080000) /* 179 */
|
||||
#define IFM_NEVER UINT32_C(0x00100000) /* 180 */
|
||||
#define IFM_NOP UINT32_C(0x00200000) /* 181 */
|
||||
/* Mask bits for field 6 : 192...223 */
|
||||
#define IFM_8086 UINT32_C(0x00000001) /* 192 */
|
||||
#define IFM_186 UINT32_C(0x00000002) /* 193 */
|
||||
#define IFM_286 UINT32_C(0x00000004) /* 194 */
|
||||
#define IFM_386 UINT32_C(0x00000008) /* 195 */
|
||||
#define IFM_486 UINT32_C(0x00000010) /* 196 */
|
||||
#define IFM_PENT UINT32_C(0x00000020) /* 197 */
|
||||
#define IFM_P6 UINT32_C(0x00000040) /* 198 */
|
||||
#define IFM_KATMAI UINT32_C(0x00000080) /* 199 */
|
||||
#define IFM_WILLAMETTE UINT32_C(0x00000100) /* 200 */
|
||||
#define IFM_PRESCOTT UINT32_C(0x00000200) /* 201 */
|
||||
#define IFM_IA64 UINT32_C(0x00000400) /* 202 */
|
||||
#define IFM_X86_64 UINT32_C(0x00000800) /* 203 */
|
||||
#define IFM_NEHALEM UINT32_C(0x00001000) /* 204 */
|
||||
#define IFM_WESTMERE UINT32_C(0x00002000) /* 205 */
|
||||
#define IFM_SANDYBRIDGE UINT32_C(0x00004000) /* 206 */
|
||||
#define IFM_FUTURE UINT32_C(0x00008000) /* 207 */
|
||||
#define IFM_DEFAULT UINT32_C(0x00010000) /* 208 */
|
||||
#define IFM_ANY UINT32_C(0x00020000) /* 209 */
|
||||
#define IFM_CYRIX UINT32_C(0x00040000) /* 210 */
|
||||
#define IFM_AMD UINT32_C(0x00080000) /* 211 */
|
||||
|
||||
/* IF_SM0 (0) ... IF_DFV (55) */
|
||||
#define IF_IGEN_FIRST 0
|
||||
#define IF_IGEN_COUNT 56
|
||||
#define IF_IGEN_FIELD 0
|
||||
#define IF_IGEN_NFIELDS 2
|
||||
|
||||
/* IF_VEX (64) ... IF_NOP (181) */
|
||||
#define IF_FEATURE_FIRST 64
|
||||
#define IF_FEATURE_COUNT 118
|
||||
#define IF_FEATURE_FIELD 2
|
||||
#define IF_FEATURE_NFIELDS 4
|
||||
|
||||
/* IF_8086 (192) ... IF_AMD (211) */
|
||||
#define IF_CPU_FIRST 192
|
||||
#define IF_CPU_COUNT 20
|
||||
#define IF_CPU_FIELD 6
|
||||
#define IF_CPU_NFIELDS 1
|
||||
|
||||
#define IF_FIELD_COUNT 7
|
||||
typedef struct {
|
||||
uint32_t field[IF_FIELD_COUNT];
|
||||
} iflag_t;
|
||||
|
||||
/* All combinations of instruction flags used in instruction patterns */
|
||||
extern const iflag_t insns_flags[655];
|
||||
|
||||
#endif /* NASM_IFLAGGEN_H */
|
||||
171
include/ilog2.h
Normal file
171
include/ilog2.h
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* ilog2_xx(x) = x ? floor(log_2(x)) : 0
|
||||
*/
|
||||
#ifndef NASM_ILOG2_H
|
||||
#define NASM_ILOG2_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#ifdef ILOG2_C /* For generating the out-of-line functions */
|
||||
# undef extern_inline
|
||||
# define extern_inline
|
||||
# define inline_prototypes
|
||||
#endif
|
||||
|
||||
#ifdef inline_prototypes
|
||||
extern unsigned int const_func ilog2_32(uint32_t v);
|
||||
extern unsigned int const_func ilog2_64(uint64_t v);
|
||||
extern int const_func alignlog2_32(uint32_t v);
|
||||
extern int const_func alignlog2_64(uint64_t v);
|
||||
#endif
|
||||
|
||||
#ifdef extern_inline
|
||||
|
||||
# define ROUND(v, a, w) \
|
||||
do { \
|
||||
if (v & (((UINT32_C(1) << w) - 1) << w)) { \
|
||||
a += w; \
|
||||
v >>= w; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# define static_nz(x) (is_constant(x != 0) && (x != 0))
|
||||
# define defang_zero(x) ((x) | !static_nz(x))
|
||||
|
||||
# if defined(HAVE_STDC_LEADING_ZEROS)
|
||||
|
||||
extern_inline unsigned int const_func ilog2_32(uint32_t v)
|
||||
{
|
||||
return stdc_leading_zeros(defang_zero(v)) ^ 31;
|
||||
}
|
||||
|
||||
extern_inline unsigned int const_func ilog2_64(uint64_t v)
|
||||
{
|
||||
return stdc_leading_zeros(defang_zero(v)) ^ 63;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
# if defined(HAVE___BUILTIN_CLZ) && INT_MAX == 2147483647
|
||||
|
||||
extern_inline unsigned int const_func ilog2_32(uint32_t v)
|
||||
{
|
||||
return __builtin_clz(v|1) ^ 31;
|
||||
}
|
||||
|
||||
# elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
|
||||
|
||||
extern_inline unsigned int const_func ilog2_32(uint32_t v)
|
||||
{
|
||||
unsigned int n;
|
||||
|
||||
# ifdef __x86_64__
|
||||
__asm__("bsrl %1,%0"
|
||||
: "=r" (n)
|
||||
: "rm" (v), "0" (0));
|
||||
# else
|
||||
__asm__("bsrl %1,%0"
|
||||
: "=r" (n)
|
||||
: "rm" (defang_zero(v)));
|
||||
# endif
|
||||
return n;
|
||||
}
|
||||
|
||||
# elif defined(HAVE__BITSCANREVERSE)
|
||||
|
||||
extern_inline unsigned int const_func ilog2_32(uint32_t v)
|
||||
{
|
||||
unsigned long ix;
|
||||
return _BitScanReverse(&ix, v) ? v : 0;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
extern_inline unsigned int const_func ilog2_32(uint32_t v)
|
||||
{
|
||||
unsigned int p = 0;
|
||||
|
||||
ROUND(v, p, 16);
|
||||
ROUND(v, p, 8);
|
||||
ROUND(v, p, 4);
|
||||
ROUND(v, p, 2);
|
||||
ROUND(v, p, 1);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# if defined(HAVE__BUILTIN_CLZLL) && LLONG_MAX == 9223372036854775807LL
|
||||
|
||||
extern_inline unsigned int const_func ilog2_64(uint64_t v)
|
||||
{
|
||||
return __builtin_clzll(defang_zero(v)) ^ 63;
|
||||
}
|
||||
|
||||
# elif defined(__GNUC__) && defined(__x86_64__)
|
||||
|
||||
extern_inline unsigned int const_func ilog2_64(uint64_t v)
|
||||
{
|
||||
uint64_t n;
|
||||
|
||||
__asm__("bsrq %1,%0"
|
||||
: "=r" (n)
|
||||
: "rm" (v), "0" (UINT64_C(0)));
|
||||
return n;
|
||||
}
|
||||
|
||||
# elif defined(HAVE__BITSCANREVERSE64)
|
||||
|
||||
extern_inline unsigned int const_func ilog2_64(uint64_t v)
|
||||
{
|
||||
unsigned long ix;
|
||||
return _BitScanReverse64(&ix, v) ? ix : 0;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
extern_inline unsigned int const_func ilog2_64(uint64_t vv)
|
||||
{
|
||||
unsigned int p = 0;
|
||||
uint32_t v;
|
||||
|
||||
v = vv >> 32;
|
||||
if (v)
|
||||
p += 32;
|
||||
else
|
||||
v = vv;
|
||||
|
||||
return p + ilog2_32(v);
|
||||
}
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/*
|
||||
* v == 0 ? 0 : is_power2(x) ? ilog2_X(v) : -1
|
||||
*/
|
||||
extern_inline int const_func alignlog2_32(uint32_t v)
|
||||
{
|
||||
if (unlikely(v & (v-1)))
|
||||
return -1; /* invalid alignment */
|
||||
|
||||
return ilog2_32(v);
|
||||
}
|
||||
|
||||
extern_inline int const_func alignlog2_64(uint64_t v)
|
||||
{
|
||||
if (unlikely(v & (v-1)))
|
||||
return -1; /* invalid alignment */
|
||||
|
||||
return ilog2_64(v);
|
||||
}
|
||||
|
||||
#undef ROUND
|
||||
|
||||
#endif /* extern_inline */
|
||||
|
||||
#endif /* ILOG2_H */
|
||||
11
include/inffast.h
Normal file
11
include/inffast.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-2003, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);
|
||||
94
include/inffixed.h
Normal file
94
include/inffixed.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by makefixed().
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications.
|
||||
It is part of the implementation of this library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
static const code lenfix[512] = {
|
||||
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
||||
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
||||
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
||||
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
||||
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
||||
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
||||
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
||||
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
||||
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
||||
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
||||
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
||||
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
||||
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
||||
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
||||
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
||||
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
||||
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
||||
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
||||
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
||||
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
||||
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
||||
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
||||
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
||||
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
||||
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
||||
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
||||
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
||||
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
||||
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
||||
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
||||
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
||||
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
||||
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
||||
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
||||
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
||||
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
||||
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
||||
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
||||
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
||||
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
||||
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
||||
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
||||
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
||||
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
||||
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
||||
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
||||
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
||||
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
||||
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
||||
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
||||
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
||||
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
||||
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
||||
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
||||
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
||||
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
||||
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
||||
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
||||
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
||||
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
||||
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
||||
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
||||
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
||||
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
||||
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
||||
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
||||
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
||||
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
||||
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
||||
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
||||
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
||||
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
||||
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
||||
{0,9,255}
|
||||
};
|
||||
|
||||
static const code distfix[32] = {
|
||||
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
||||
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
||||
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
||||
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
||||
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
||||
{22,5,193},{64,5,0}
|
||||
};
|
||||
126
include/inflate.h
Normal file
126
include/inflate.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/* inflate.h -- internal inflate state definition
|
||||
* Copyright (C) 1995-2019 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip decoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GUNZIP
|
||||
#endif
|
||||
|
||||
/* Possible inflate modes between inflate() calls */
|
||||
typedef enum {
|
||||
HEAD = 16180, /* i: waiting for magic header */
|
||||
FLAGS, /* i: waiting for method and flags (gzip) */
|
||||
TIME, /* i: waiting for modification time (gzip) */
|
||||
OS, /* i: waiting for extra flags and operating system (gzip) */
|
||||
EXLEN, /* i: waiting for extra length (gzip) */
|
||||
EXTRA, /* i: waiting for extra bytes (gzip) */
|
||||
NAME, /* i: waiting for end of file name (gzip) */
|
||||
COMMENT, /* i: waiting for end of comment (gzip) */
|
||||
HCRC, /* i: waiting for header crc (gzip) */
|
||||
DICTID, /* i: waiting for dictionary check value */
|
||||
DICT, /* waiting for inflateSetDictionary() call */
|
||||
TYPE, /* i: waiting for type bits, including last-flag bit */
|
||||
TYPEDO, /* i: same, but skip check to exit inflate on new block */
|
||||
STORED, /* i: waiting for stored size (length and complement) */
|
||||
COPY_, /* i/o: same as COPY below, but only first time in */
|
||||
COPY, /* i/o: waiting for input or output to copy stored block */
|
||||
TABLE, /* i: waiting for dynamic block table lengths */
|
||||
LENLENS, /* i: waiting for code length code lengths */
|
||||
CODELENS, /* i: waiting for length/lit and distance code lengths */
|
||||
LEN_, /* i: same as LEN below, but only first time in */
|
||||
LEN, /* i: waiting for length/lit/eob code */
|
||||
LENEXT, /* i: waiting for length extra bits */
|
||||
DIST, /* i: waiting for distance code */
|
||||
DISTEXT, /* i: waiting for distance extra bits */
|
||||
MATCH, /* o: waiting for output space to copy string */
|
||||
LIT, /* o: waiting for output space to write literal */
|
||||
CHECK, /* i: waiting for 32-bit check value */
|
||||
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
||||
DONE, /* finished check, done -- remain here until reset */
|
||||
BAD, /* got a data error -- remain here until reset */
|
||||
MEM, /* got an inflate() memory error -- remain here until reset */
|
||||
SYNC /* looking for synchronization bytes to restart inflate() */
|
||||
} inflate_mode;
|
||||
|
||||
/*
|
||||
State transitions between above modes -
|
||||
|
||||
(most modes can go to BAD or MEM on error -- not shown for clarity)
|
||||
|
||||
Process header:
|
||||
HEAD -> (gzip) or (zlib) or (raw)
|
||||
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
|
||||
HCRC -> TYPE
|
||||
(zlib) -> DICTID or TYPE
|
||||
DICTID -> DICT -> TYPE
|
||||
(raw) -> TYPEDO
|
||||
Read deflate blocks:
|
||||
TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
|
||||
STORED -> COPY_ -> COPY -> TYPE
|
||||
TABLE -> LENLENS -> CODELENS -> LEN_
|
||||
LEN_ -> LEN
|
||||
Read deflate codes in fixed or dynamic block:
|
||||
LEN -> LENEXT or LIT or TYPE
|
||||
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
|
||||
LIT -> LEN
|
||||
Process trailer:
|
||||
CHECK -> LENGTH -> DONE
|
||||
*/
|
||||
|
||||
/* State maintained between inflate() calls -- approximately 7K bytes, not
|
||||
including the allocated sliding window, which is up to 32K bytes. */
|
||||
struct inflate_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
int last; /* true if processing last block */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
|
||||
bit 2 true to validate check value */
|
||||
int havedict; /* true if dictionary provided */
|
||||
int flags; /* gzip header method and flags, 0 if zlib, or
|
||||
-1 if raw or no header yet */
|
||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||
unsigned long check; /* protected copy of check value */
|
||||
unsigned long total; /* protected copy of output count */
|
||||
gz_headerp head; /* where to save gzip header information */
|
||||
/* sliding window */
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
unsigned bits; /* number of bits in "in" */
|
||||
/* for string and stored block copying */
|
||||
unsigned length; /* literal or length of data to copy */
|
||||
unsigned offset; /* distance back to copy string from */
|
||||
/* for table and code decoding */
|
||||
unsigned extra; /* extra bits needed */
|
||||
/* fixed and dynamic code tables */
|
||||
code const FAR *lencode; /* starting table for length/literal codes */
|
||||
code const FAR *distcode; /* starting table for distance codes */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
/* dynamic table building */
|
||||
unsigned ncode; /* number of code length code lengths */
|
||||
unsigned nlen; /* number of length code lengths */
|
||||
unsigned ndist; /* number of distance code lengths */
|
||||
unsigned have; /* number of code lengths in lens[] */
|
||||
code FAR *next; /* next available space in codes[] */
|
||||
unsigned short lens[320]; /* temporary storage for code lengths */
|
||||
unsigned short work[288]; /* work area for code table building */
|
||||
code codes[ENOUGH]; /* space for code tables */
|
||||
int sane; /* if false, allow invalid distance too far */
|
||||
int back; /* bits back of last unprocessed length/lit */
|
||||
unsigned was; /* initial length of match */
|
||||
};
|
||||
62
include/inftrees.h
Normal file
62
include/inftrees.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2005, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* Structure for decoding tables. Each entry provides either the
|
||||
information needed to do the operation requested by the code that
|
||||
indexed that table entry, or it provides a pointer to another
|
||||
table that indexes more bits of the code. op indicates whether
|
||||
the entry is a pointer to another table, a literal, a length or
|
||||
distance, an end-of-block, or an invalid code. For a table
|
||||
pointer, the low four bits of op is the number of index bits of
|
||||
that table. For a length or distance, the low four bits of op
|
||||
is the number of extra bits to get after the code. bits is
|
||||
the number of bits in this code or part of the code to drop off
|
||||
of the bit buffer. val is the actual byte to output in the case
|
||||
of a literal, the base length or distance, or the offset from
|
||||
the current table to the next table. Each entry is four bytes. */
|
||||
typedef struct {
|
||||
unsigned char op; /* operation, extra bits, table bits */
|
||||
unsigned char bits; /* bits in this part of the code */
|
||||
unsigned short val; /* offset in table or code value */
|
||||
} code;
|
||||
|
||||
/* op values as set by inflate_table():
|
||||
00000000 - literal
|
||||
0000tttt - table link, tttt != 0 is the number of table index bits
|
||||
0001eeee - length or distance, eeee is the number of extra bits
|
||||
01100000 - end of block
|
||||
01000000 - invalid code
|
||||
*/
|
||||
|
||||
/* Maximum size of the dynamic table. The maximum number of code structures is
|
||||
1444, which is the sum of 852 for literal/length codes and 592 for distance
|
||||
codes. These values were found by exhaustive searches using the program
|
||||
examples/enough.c found in the zlib distribution. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns 852, and "enough 30 6 15" for distance codes returns 592. The
|
||||
initial root table size (9 or 6) is found in the fifth argument of the
|
||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||
changed, then these maximum sizes would be need to be recalculated and
|
||||
updated. */
|
||||
#define ENOUGH_LENS 852
|
||||
#define ENOUGH_DISTS 592
|
||||
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
|
||||
|
||||
/* Type of code to build for inflate_table() */
|
||||
typedef enum {
|
||||
CODES,
|
||||
LENS,
|
||||
DISTS
|
||||
} codetype;
|
||||
|
||||
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work);
|
||||
122
include/insns.h
Normal file
122
include/insns.h
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* insns.h header file for insns.c
|
||||
*
|
||||
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
|
||||
* Julian Hall. All rights reserved. The software is
|
||||
* redistributable under the license given in the file "LICENSE"
|
||||
* distributed in the NASM archive.
|
||||
*/
|
||||
|
||||
#ifndef NASM_INSNS_H
|
||||
#define NASM_INSNS_H
|
||||
|
||||
#include "nasm.h"
|
||||
#include "tokens.h"
|
||||
#include "iflag.h"
|
||||
|
||||
struct itemplate {
|
||||
enum opcode opcode; /* the token, passed from "parser.c" */
|
||||
int operands; /* number of operands */
|
||||
opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */
|
||||
decoflags_t deco[MAX_OPERANDS]; /* bit flags for operand decorators */
|
||||
const uint8_t *code; /* the code it assembles to */
|
||||
uint32_t iflag_idx; /* some flags referenced by index */
|
||||
unsigned int xdaline; /* line # in insns.xda (for debug) */
|
||||
};
|
||||
|
||||
/* Use this helper to test instruction template flags */
|
||||
static inline bool itemp_has(const struct itemplate *itemp, unsigned int bit)
|
||||
{
|
||||
return iflag_test(&insns_flags[itemp->iflag_idx], bit);
|
||||
}
|
||||
|
||||
/* Disassembler table structure */
|
||||
|
||||
/* Instruction tables for the assembler */
|
||||
struct itemplate_list {
|
||||
unsigned int ntemp;
|
||||
const struct itemplate *temp;
|
||||
};
|
||||
extern const struct itemplate_list nasm_instructions[];
|
||||
|
||||
/* Instruction tables for the disassembler */
|
||||
extern const struct itemplate * const * const * const ndisasm_itable[];
|
||||
|
||||
/* Common table for the byte codes */
|
||||
extern const uint8_t nasm_bytecodes[];
|
||||
|
||||
/*
|
||||
* Pseudo-op tests
|
||||
*/
|
||||
/* DB-type instruction (DB, DW, ...) */
|
||||
static inline bool const_func opcode_is_db(enum opcode opcode)
|
||||
{
|
||||
return opcode >= I_DB && opcode < I_RESB;
|
||||
}
|
||||
|
||||
/* RESB-type instruction (RESB, RESW, ...) */
|
||||
static inline bool const_func opcode_is_resb(enum opcode opcode)
|
||||
{
|
||||
return opcode >= I_RESB && opcode < I_INCBIN;
|
||||
}
|
||||
|
||||
/* Width of Dx and RESx instructions */
|
||||
|
||||
/*
|
||||
* initialized data bytes length from opcode
|
||||
*/
|
||||
static inline int const_func db_bytes(enum opcode opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case I_DB:
|
||||
return 1;
|
||||
case I_DW:
|
||||
return 2;
|
||||
case I_DD:
|
||||
return 4;
|
||||
case I_DQ:
|
||||
return 8;
|
||||
case I_DT:
|
||||
return 10;
|
||||
case I_DO:
|
||||
return 16;
|
||||
case I_DY:
|
||||
return 32;
|
||||
case I_DZ:
|
||||
return 64;
|
||||
case I_none:
|
||||
return -1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Uninitialized data bytes length from opcode
|
||||
*/
|
||||
static inline int const_func resb_bytes(enum opcode opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case I_RESB:
|
||||
return 1;
|
||||
case I_RESW:
|
||||
return 2;
|
||||
case I_RESD:
|
||||
return 4;
|
||||
case I_RESQ:
|
||||
return 8;
|
||||
case I_REST:
|
||||
return 10;
|
||||
case I_RESO:
|
||||
return 16;
|
||||
case I_RESY:
|
||||
return 32;
|
||||
case I_RESZ:
|
||||
return 64;
|
||||
case I_none:
|
||||
return -1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* NASM_INSNS_H */
|
||||
2664
include/insnsi.h
Normal file
2664
include/insnsi.h
Normal file
File diff suppressed because it is too large
Load diff
42
include/labels.h
Normal file
42
include/labels.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* labels.h header file for labels.c
|
||||
*/
|
||||
|
||||
#ifndef LABELS_H
|
||||
#define LABELS_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
enum label_type {
|
||||
LBL_none = -1, /* No label */
|
||||
LBL_LOCAL = 0, /* Must be zero */
|
||||
LBL_STATIC,
|
||||
LBL_GLOBAL,
|
||||
LBL_EXTERN,
|
||||
LBL_REQUIRED, /* Like extern but emit even if unused */
|
||||
LBL_COMMON,
|
||||
LBL_SPECIAL, /* Magic symbols like ..start */
|
||||
LBL_BACKEND /* Backend-defined symbols like ..got */
|
||||
};
|
||||
|
||||
enum label_type lookup_label(const char *label, int32_t *segment, int64_t *offset);
|
||||
static inline bool is_extern(enum label_type type)
|
||||
{
|
||||
return type == LBL_EXTERN || type == LBL_REQUIRED;
|
||||
}
|
||||
void define_label(const char *label, int32_t segment, int64_t offset,
|
||||
bool normal);
|
||||
void backend_label(const char *label, int32_t segment, int64_t offset);
|
||||
bool declare_label(const char *label, enum label_type type,
|
||||
const char *special);
|
||||
void set_label_mangle(enum directive which, const char *what);
|
||||
int init_labels(void);
|
||||
void cleanup_labels(void);
|
||||
const char *local_scope(const char *label);
|
||||
|
||||
extern uint64_t global_offset_changed;
|
||||
|
||||
#endif /* LABELS_H */
|
||||
175
include/listing.h
Normal file
175
include/listing.h
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* listing.h header file for listing.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_LISTING_H
|
||||
#define NASM_LISTING_H
|
||||
|
||||
#include "nasm.h"
|
||||
|
||||
/* List options implied by -L+ */
|
||||
#define LIST_PLUS_OPTIONS "bdefFmps"
|
||||
|
||||
/* Listing type values flags */
|
||||
enum list_type {
|
||||
/* Flags for lfmt->line() */
|
||||
LIST_READ,
|
||||
LIST_MACRO,
|
||||
LIST_INFO,
|
||||
/* Flags for lfmt->uplevel() */
|
||||
LIST_INCLUDE,
|
||||
LIST_INCBIN,
|
||||
LIST_TIMES
|
||||
};
|
||||
|
||||
/*
|
||||
* List-file generators should look like this:
|
||||
*/
|
||||
struct lfmt {
|
||||
/*
|
||||
* Called to initialize the listing file generator. Before this
|
||||
* is called, the other routines will silently do nothing when
|
||||
* called. The `char *' parameter is the file name to write the
|
||||
* listing to.
|
||||
*/
|
||||
void (*init)(const char *fname);
|
||||
|
||||
/*
|
||||
* Called to clear stuff up and close the listing file.
|
||||
*/
|
||||
void (*cleanup)(void);
|
||||
|
||||
/*
|
||||
* Called to output binary data. Parameters are: the offset;
|
||||
* the data; the data type. Data types are similar to the
|
||||
* output-format interface, only OUT_ADDRESS will _always_ be
|
||||
* displayed as if it's relocatable, so ensure that any non-
|
||||
* relocatable address has been converted to OUT_RAWDATA by
|
||||
* then.
|
||||
*/
|
||||
void (*output)(const struct out_data *data);
|
||||
|
||||
/*
|
||||
* Called to send a text line to the listing generator. The
|
||||
* `int' parameter is LIST_READ or LIST_MACRO depending on
|
||||
* whether the line came directly from an input file or is the
|
||||
* result of a multi-line macro expansion.
|
||||
*
|
||||
* If a line number is provided, print it; if the line number is
|
||||
* -1 then use the same line number as the previous call.
|
||||
*/
|
||||
void (*line)(enum list_type type, int32_t lineno, const char *line);
|
||||
|
||||
/*
|
||||
* Called to change one of the various levelled mechanisms in the
|
||||
* listing generator. LIST_INCLUDE and LIST_MACRO can be used to
|
||||
* increase the nesting level of include files and macro
|
||||
* expansions; LIST_TIMES and LIST_INCBIN switch on the two
|
||||
* binary-output-suppression mechanisms for large-scale
|
||||
* pseudo-instructions; the size argument prints the size or
|
||||
* repetiiton count.
|
||||
*
|
||||
* LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that
|
||||
* it indicates the beginning of the expansion of a `nolist'
|
||||
* macro, so anything under that level won't be expanded unless
|
||||
* it includes another file.
|
||||
*/
|
||||
void (*uplevel)(enum list_type type, int64_t size);
|
||||
|
||||
/*
|
||||
* Reverse the effects of uplevel.
|
||||
*/
|
||||
void (*downlevel)(enum list_type type);
|
||||
|
||||
/*
|
||||
* Called on a warning or error, with the error message.
|
||||
*/
|
||||
void printf_func_ptr(2, 3) (*error)(errflags severity, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Update the current offset. Used to give the listing generator
|
||||
* an offset to work with when doing things like
|
||||
* uplevel(LIST_TIMES) or uplevel(LIST_INCBIN); see
|
||||
* list_set_offset();
|
||||
*/
|
||||
void (*set_offset)(uint64_t offset);
|
||||
};
|
||||
|
||||
extern const struct lfmt *lfmt;
|
||||
extern bool user_nolist;
|
||||
|
||||
/*
|
||||
* list_options are the requested options; active_list_options gets
|
||||
* set when a pass starts.
|
||||
*
|
||||
* These are simple bitmasks of ASCII-64 mapping directly to option
|
||||
* letters.
|
||||
*/
|
||||
extern uint64_t list_options, active_list_options, cmdline_list_options;
|
||||
|
||||
/*
|
||||
* This maps the characters a-z, A-Z and 0-9 onto a 64-bit bitmask.
|
||||
* Bit 0 is used to indicate that the listing engine is active, and
|
||||
* bit 1 is reserved, so this will only return mask bits 2 and higher;
|
||||
* as there are 62 possible characters this fits nicely.
|
||||
*
|
||||
* The mask returned is 0 for invalid characters, accessing no bits at
|
||||
* all.
|
||||
*
|
||||
* This isn't particularly efficient code, but just about every
|
||||
* instance of it should be fed a constant, so the entire function can
|
||||
* be precomputed at compile time. The only cases where the full
|
||||
* computation is needed is in list_update_options(), which is not
|
||||
* performance critical.
|
||||
*/
|
||||
static inline const_func uint64_t list_option_mask(unsigned char x)
|
||||
{
|
||||
if (x >= 'a') {
|
||||
if (x > 'z')
|
||||
return 0;
|
||||
x = x - 'a' + 2;
|
||||
} else if (x >= 'A') {
|
||||
if (x > 'Z')
|
||||
return 0;
|
||||
x = x - 'A' + 2 + 26;
|
||||
} else if (x >= '0') {
|
||||
if (x > '9')
|
||||
return 0;
|
||||
x = x - '0' + 2 + 26*2;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return UINT64_C(1) << x;
|
||||
}
|
||||
|
||||
#define LIST_ALL_OPTIONS_MASK (~UINT64_C(3))
|
||||
|
||||
/* Return true if the listing engine is active and a certain option is set. */
|
||||
static inline pure_func bool list_option(unsigned char x)
|
||||
{
|
||||
return unlikely(active_list_options & list_option_mask(x));
|
||||
}
|
||||
|
||||
/* This test is used to see if we should initialize the listing engine */
|
||||
static inline pure_func bool list_on_this_pass(void)
|
||||
{
|
||||
return pass_final() || unlikely(list_options & list_option_mask('p'));
|
||||
}
|
||||
|
||||
/* Is the listing engine active? */
|
||||
static inline pure_func bool list_active(void)
|
||||
{
|
||||
return (active_list_options & 1);
|
||||
}
|
||||
|
||||
/* Change listing options */
|
||||
void list_update_options(const char *str, bool from_cmdline);
|
||||
|
||||
/* Pragma handler */
|
||||
enum directive_result list_pragma(const struct pragma *);
|
||||
|
||||
#endif
|
||||
287
include/macho.h
Normal file
287
include/macho.h
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef OUTPUT_MACHO_H
|
||||
#define OUTPUT_MACHO_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* Magics */
|
||||
#define MH_MAGIC 0xfeedface
|
||||
#define MH_MAGIC_64 0xfeedfacf
|
||||
|
||||
/* File types */
|
||||
#define MH_OBJECT 0x1
|
||||
|
||||
/* CPUs */
|
||||
#define CPU_ARCH_MASK 0xff000000
|
||||
#define CPU_ARCH_ABI64 0x01000000
|
||||
#define CPU_TYPE_X86 7
|
||||
#define CPU_TYPE_I386 CPU_TYPE_X86
|
||||
#define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
|
||||
|
||||
#define CPU_SUBTYPE_MASK 0xff000000
|
||||
#define CPU_SUBTYPE_I386_ALL 3
|
||||
|
||||
/* Header flags */
|
||||
#define MH_SUBSECTIONS_VIA_SYMBOLS 0x00002000
|
||||
|
||||
/* Load commands */
|
||||
#define LC_SEGMENT 0x1
|
||||
#define LC_SEGMENT_64 0x19
|
||||
#define LC_SYMTAB 0x2
|
||||
#define LC_BUILD_VERSION 0x32
|
||||
|
||||
/* Symbol type bits */
|
||||
#define N_STAB 0xe0
|
||||
#define N_PEXT 0x10
|
||||
#define N_TYPE 0x0e
|
||||
#define N_EXT 0x01
|
||||
|
||||
/* To mask with N_TYPE */
|
||||
#define N_UNDF 0x00
|
||||
#define N_ABS 0x02
|
||||
#define N_INDR 0x0a
|
||||
#define N_PBUD 0x0c
|
||||
#define N_SECT 0x0e
|
||||
|
||||
/* Section ordinals */
|
||||
#define NO_SECT 0x00
|
||||
#define MAX_SECT 0xff
|
||||
|
||||
/* Section bits */
|
||||
#define SECTION_TYPE 0x000000ff
|
||||
#define SECTION_ATTRIBUTES 0xffffff00
|
||||
#define SECTION_ATTRIBUTES_USR 0xff000000
|
||||
#define SECTION_ATTRIBUTES_SYS 0x00ffff00
|
||||
|
||||
#define S_REGULAR 0x00
|
||||
#define S_ZEROFILL 0x01
|
||||
#define S_CSTRING_LITERALS 0x02
|
||||
#define S_4BYTE_LITERALS 0x03
|
||||
#define S_8BYTE_LITERALS 0x04
|
||||
#define S_LITERAL_POINTERS 0x05
|
||||
#define S_NON_LAZY_SYMBOL_POINTERS 0x06
|
||||
#define S_LAZY_SYMBOL_POINTERS 0x07
|
||||
#define S_SYMBOL_STUBS 0x08
|
||||
#define S_MOD_INIT_FUNC_POINTERS 0x09
|
||||
#define S_MOD_TERM_FUNC_POINTERS 0x0a
|
||||
#define S_COALESCED 0x0b
|
||||
#define S_GB_ZEROFILL 0x0c
|
||||
#define S_INTERPOSING 0x0d
|
||||
#define S_16BYTE_LITERALS 0x0e
|
||||
#define S_DTRACE_DOF 0x0f
|
||||
#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10
|
||||
#define S_THREAD_LOCAL_REGULAR 0x11
|
||||
#define S_THREAD_LOCAL_ZEROFILL 0x12
|
||||
#define S_THREAD_LOCAL_VARIABLES 0x13
|
||||
#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
|
||||
#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
|
||||
|
||||
#define S_ATTR_PURE_INSTRUCTIONS 0x80000000
|
||||
#define S_ATTR_NO_TOC 0x40000000
|
||||
#define S_ATTR_STRIP_STATIC_SYMS 0x20000000
|
||||
#define S_ATTR_NO_DEAD_STRIP 0x10000000
|
||||
#define S_ATTR_LIVE_SUPPORT 0x08000000
|
||||
#define S_ATTR_SELF_MODIFYING_CODE 0x04000000
|
||||
#define S_ATTR_DEBUG 0x02000000
|
||||
|
||||
#define S_ATTR_SOME_INSTRUCTIONS 0x00000400
|
||||
#define S_ATTR_EXT_RELOC 0x00000200
|
||||
#define S_ATTR_LOC_RELOC 0x00000100
|
||||
#define INDIRECT_SYMBOL_LOCAL 0x80000000
|
||||
#define INDIRECT_SYMBOL_ABS 0x40000000
|
||||
|
||||
/* Relocation info type */
|
||||
#define GENERIC_RELOC_VANILLA 0
|
||||
#define GENERIC_RELOC_PAIR 1
|
||||
#define GENERIC_RELOC_SECTDIFF 2
|
||||
#define GENERIC_RELOC_PB_LA_PTR 3
|
||||
#define GENERIC_RELOC_LOCAL_SECTDIFF 4
|
||||
#define GENERIC_RELOC_TLV 5
|
||||
|
||||
#define X86_64_RELOC_UNSIGNED 0
|
||||
#define X86_64_RELOC_SIGNED 1
|
||||
#define X86_64_RELOC_BRANCH 2
|
||||
#define X86_64_RELOC_GOT_LOAD 3
|
||||
#define X86_64_RELOC_GOT 4
|
||||
#define X86_64_RELOC_SUBTRACTOR 5
|
||||
#define X86_64_RELOC_SIGNED_1 6
|
||||
#define X86_64_RELOC_SIGNED_2 7
|
||||
#define X86_64_RELOC_SIGNED_4 8
|
||||
#define X86_64_RELOC_TLV 9
|
||||
|
||||
/* Relocation info */
|
||||
#define R_ABS 0
|
||||
#define R_SCATTERED 0x80000000
|
||||
|
||||
/* VM permission constants */
|
||||
#define VM_PROT_NONE 0x00
|
||||
#define VM_PROT_READ 0x01
|
||||
#define VM_PROT_WRITE 0x02
|
||||
#define VM_PROT_EXECUTE 0x04
|
||||
|
||||
/* Platforms */
|
||||
/* X-macro X(_platform, _id, _name) */
|
||||
#define MACHO_ALL_PLATFORMS \
|
||||
X(PLATFORM_UNKNOWN, 0, "unknown") \
|
||||
X(PLATFORM_MACOS, 1, "macos") \
|
||||
X(PLATFORM_IOS, 2, "ios") \
|
||||
X(PLATFORM_TVOS, 3, "tvos") \
|
||||
X(PLATFORM_WATCHOS, 4, "watchos") \
|
||||
X(PLATFORM_BRIDGEOS, 5, "bridgeos") \
|
||||
X(PLATFORM_MACCATALYST, 6, "macCatalyst") \
|
||||
X(PLATFORM_IOSSIMULATOR, 7, "iossimulator") \
|
||||
X(PLATFORM_TVOSSIMULATOR, 8, "tvossimulator") \
|
||||
X(PLATFORM_WATCHOSSIMULATOR, 9, "watchossimulator") \
|
||||
X(PLATFORM_DRIVERKIT, 10, "driverkit") \
|
||||
X(PLATFORM_XROS, 11, "xros") \
|
||||
X(PLATFORM_XROS_SIMULATOR, 12, "xrsimulator") \
|
||||
/* end */
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t cputype;
|
||||
uint32_t cpusubtype;
|
||||
uint32_t filetype;
|
||||
uint32_t ncmds;
|
||||
uint32_t sizeofcmds;
|
||||
uint32_t flags;
|
||||
} macho_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t cputype;
|
||||
uint32_t cpusubtype;
|
||||
uint32_t filetype;
|
||||
uint32_t ncmds;
|
||||
uint32_t sizeofcmds;
|
||||
uint32_t flags;
|
||||
uint32_t reserved;
|
||||
} macho_header_64_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cmd;
|
||||
uint32_t cmdsize;
|
||||
} macho_load_command_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cmd;
|
||||
uint32_t cmdsize;
|
||||
char segname[16];
|
||||
uint32_t vmaddr;
|
||||
uint32_t vmsize;
|
||||
uint32_t fileoff;
|
||||
uint32_t filesize;
|
||||
uint32_t maxprot;
|
||||
uint32_t initprot;
|
||||
uint32_t nsects;
|
||||
uint32_t flags;
|
||||
} macho_segment_command_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cmd;
|
||||
uint32_t cmdsize;
|
||||
char segname[16];
|
||||
uint64_t vmaddr;
|
||||
uint64_t vmsize;
|
||||
uint64_t fileoff;
|
||||
uint64_t filesize;
|
||||
uint32_t maxprot;
|
||||
uint32_t initprot;
|
||||
uint32_t nsects;
|
||||
uint32_t flags;
|
||||
} macho_segment_command_64_t;
|
||||
|
||||
typedef struct {
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
uint32_t offset;
|
||||
uint32_t align;
|
||||
uint32_t reloff;
|
||||
uint32_t nreloc;
|
||||
uint32_t flags;
|
||||
uint32_t reserved1;
|
||||
uint32_t reserved2;
|
||||
} macho_section_t;
|
||||
|
||||
typedef struct {
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
uint64_t addr;
|
||||
uint64_t size;
|
||||
uint32_t offset;
|
||||
uint32_t align;
|
||||
uint32_t reloff;
|
||||
uint32_t nreloc;
|
||||
uint32_t flags;
|
||||
uint32_t reserved1;
|
||||
uint32_t reserved2;
|
||||
uint32_t reserved3;
|
||||
} macho_section_64_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cmd;
|
||||
uint32_t cmdsize;
|
||||
uint32_t symoff;
|
||||
uint32_t nsyms;
|
||||
uint32_t stroff;
|
||||
uint32_t strsize;
|
||||
} macho_symtab_command_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t r_address;
|
||||
union {
|
||||
struct {
|
||||
uint32_t r_symbolnum: 24,
|
||||
r_pcrel: 1,
|
||||
r_length: 2,
|
||||
r_extern: 1,
|
||||
r_type: 4;
|
||||
} s;
|
||||
uint32_t r_raw;
|
||||
} u;
|
||||
} macho_relocation_info_t;
|
||||
|
||||
typedef struct nlist_base {
|
||||
uint32_t n_strx;
|
||||
uint8_t n_type;
|
||||
uint8_t n_sect;
|
||||
uint16_t n_desc;
|
||||
} macho_nlist_base_t;
|
||||
|
||||
typedef struct nlist {
|
||||
uint32_t n_strx;
|
||||
uint8_t n_type;
|
||||
uint8_t n_sect;
|
||||
int16_t n_desc;
|
||||
uint32_t n_value;
|
||||
} macho_nlist_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t n_strx;
|
||||
uint8_t n_type;
|
||||
uint8_t n_sect;
|
||||
uint16_t n_desc;
|
||||
uint64_t n_value;
|
||||
} macho_nlist_64_t;
|
||||
|
||||
/* Adapted from LLVM include/llvm/BinaryFormat/MachO.h */
|
||||
typedef struct {
|
||||
uint32_t tool;
|
||||
uint32_t version;
|
||||
} macho_build_tool_version_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cmd;
|
||||
uint32_t cmdsize;
|
||||
uint32_t platform;
|
||||
uint32_t minos; /* x.y.z is 0xXXXXYYZZ */
|
||||
uint32_t sdk; /* x.y.z is 0xXXXXYYZZ */
|
||||
uint32_t ntools;
|
||||
/* ntools macho_build_tool_version_t follow this */
|
||||
} macho_build_version_command_t;
|
||||
|
||||
#endif /* OUTPUT_MACHO_H */
|
||||
36
include/macros.h
Normal file
36
include/macros.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* macros.h - format of builtin macro data
|
||||
*/
|
||||
|
||||
#ifndef NASM_MACROS_H
|
||||
#define NASM_MACROS_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* Builtin macro set */
|
||||
struct builtin_macros {
|
||||
unsigned int dsize, zsize;
|
||||
const void *zdata;
|
||||
};
|
||||
typedef const struct builtin_macros macros_t;
|
||||
|
||||
char *uncompress_stdmac(macros_t *sm);
|
||||
|
||||
/* --- From standard.mac via macros.pl -> macros.c --- */
|
||||
|
||||
extern macros_t nasm_stdmac_tasm;
|
||||
extern macros_t nasm_stdmac_nasm;
|
||||
extern macros_t nasm_stdmac_version;
|
||||
|
||||
struct use_package {
|
||||
const char *package;
|
||||
macros_t *macros;
|
||||
unsigned int index;
|
||||
};
|
||||
extern const struct use_package *nasm_find_use_package(const char *);
|
||||
extern const unsigned int use_package_count;
|
||||
|
||||
#endif
|
||||
21
include/md5.h
Normal file
21
include/md5.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#define MD5_HASHBYTES 16
|
||||
|
||||
typedef struct MD5Context {
|
||||
uint32_t buf[4];
|
||||
uint32_t bits[2];
|
||||
unsigned char in[64];
|
||||
} MD5_CTX;
|
||||
|
||||
extern void MD5Init(MD5_CTX *context);
|
||||
extern void MD5Update(MD5_CTX *context, unsigned char const *buf,
|
||||
unsigned len);
|
||||
extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
|
||||
extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
|
||||
extern char * MD5End(MD5_CTX *, char *);
|
||||
|
||||
#endif /* !MD5_H */
|
||||
166
include/msvc.h
Normal file
166
include/msvc.h
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/msvc.h
|
||||
*
|
||||
* Compiler definitions for Microsoft Visual C++;
|
||||
* instead of unconfig.h. See config.h.in for the
|
||||
* variables which can be defined here.
|
||||
*
|
||||
* MSDN seems to have information back to Visual Studio 2003, so aim
|
||||
* for compatibility that far back.
|
||||
*
|
||||
* Relevant _MSC_VER values:
|
||||
* 1310 - Visual Studio 2003
|
||||
* 1400 - Visual Studio 2005
|
||||
* 1500 - Visual Studio 2008
|
||||
* 1600 - Visual Studio 2010
|
||||
* 1700 - Visual Studio 2012
|
||||
* 1800 - Visual Studio 2013
|
||||
* 1900 - Visual Studio 2015
|
||||
* 1910 - Visual Studio 2017
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_MSVC_H
|
||||
#define NASM_CONFIG_MSVC_H
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#if _MSC_VER >= 1800
|
||||
# define HAVE_INTTYPES_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
#define HAVE_IO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `access' function. */
|
||||
#define HAVE_ACCESS 1
|
||||
#if _MSC_VER < 1400
|
||||
# define access _access
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `fileno' function. */
|
||||
#define HAVE_FILENO 1
|
||||
#if _MSC_VER < 1400
|
||||
# define fileno _fileno
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#define HAVE_SNPRINTF 1
|
||||
#if _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `_chsize' function. */
|
||||
#define HAVE__CHSIZE 1
|
||||
|
||||
/* Define to 1 if you have the `_chsize_s' function. */
|
||||
#if _MSC_VER >= 1400
|
||||
# define HAVE__CHSIZE_S 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `_filelengthi64' function. */
|
||||
#define HAVE__FILELENGTHI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fseeki64' function. */
|
||||
#define HAVE__FSEEKI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fullpath' function. */
|
||||
#define HAVE__FULLPATH 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct _stati64'. */
|
||||
#define HAVE_STRUCT__STATI64
|
||||
|
||||
/* Define to 1 if you have the `_stati64' function. */
|
||||
#define HAVE__STATI64 1
|
||||
|
||||
/* Define to 1 if you have the `_fstati64' function. */
|
||||
#define HAVE__FSTATI64 1
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#if _MSC_VER >= 1800
|
||||
# define HAVE_STDBOOL_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `stricmp' function. */
|
||||
#define HAVE_STRICMP 1
|
||||
/* Define to 1 if you have the declaration of `stricmp', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_STRICMP 1
|
||||
#if _MSC_VER < 1400
|
||||
# define stricmp _stricmp
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `strnicmp' function. */
|
||||
#define HAVE_STRNICMP 1
|
||||
/* Define to 1 if you have the declaration of `strnicmp', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_STRNICMP 1
|
||||
#if _MSC_VER < 1400
|
||||
# define strnicmp _strnicmp
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
# define HAVE_STRNLEN 1
|
||||
/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
|
||||
don't. */
|
||||
# define HAVE_DECL_STRNLEN 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the system has the type `uintptr_t'. */
|
||||
#if _MSC_VER >= 1900
|
||||
# define HAVE_UINTPTR_T 1
|
||||
#else
|
||||
/* Define to the type of an unsigned integer type wide enough to hold a
|
||||
pointer, if such a type exists, and if the system does not define it. */
|
||||
# define uintptr_t size_t
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#if _MSC_VER < 1400
|
||||
# define vsnprint _vsnprintf
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#if _MSC_VER >= 1900
|
||||
# define HAVE__BOOL 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if your processor stores words with the least significant byte
|
||||
first (like Intel and VAX, unlike Motorola and SPARC). */
|
||||
#define WORDS_LITTLEENDIAN 1
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#define inline __inline
|
||||
|
||||
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
nothing if this is not supported. Do not define if restrict is
|
||||
supported directly. */
|
||||
#if _MSC_VER >= 1700
|
||||
#define restrict __restrict
|
||||
#else
|
||||
#define restrict
|
||||
#endif
|
||||
|
||||
#endif /* NASM_CONFIG_MSVC_H */
|
||||
1583
include/nasm.h
Normal file
1583
include/nasm.h
Normal file
File diff suppressed because it is too large
Load diff
219
include/nasmint.h
Normal file
219
include/nasmint.h
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* nasmint.h
|
||||
*
|
||||
* Small ersatz subset of <inttypes.h>, deriving the types from
|
||||
* <limits.h>.
|
||||
*
|
||||
* Important: the preprocessor may truncate numbers too large for it.
|
||||
* Therefore, test the signed types only ... truncation won't generate
|
||||
* a 01111111... bit pattern.
|
||||
*/
|
||||
|
||||
#ifndef NASM_NASMINT_H
|
||||
#define NASM_NASMINT_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/*** 64-bit type: __int64, long or long long ***/
|
||||
|
||||
/* Some old versions of gcc <limits.h> omit LLONG_MAX */
|
||||
#ifndef LLONG_MAX
|
||||
# ifdef __LONG_LONG_MAX__
|
||||
# define LLONG_MAX __LONG_LONG_MAX__
|
||||
# else
|
||||
# define LLONG_MAX 0 /* Assume long long is unusable */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _I64_MAX
|
||||
# ifdef _MSC_VER
|
||||
# define _I64_MAX 9223372036854775807
|
||||
# else
|
||||
# define _I64_MAX 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if _I64_MAX == 9223372036854775807
|
||||
|
||||
/* Windows-based compiler: use __int64 */
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#define _scn64 "I64"
|
||||
#define _pri64 "I64"
|
||||
#define INT64_C(x) x ## i64
|
||||
#define UINT64_C(x) x ## ui64
|
||||
|
||||
#elif LONG_MAX == 9223372036854775807L
|
||||
|
||||
/* long is 64 bits */
|
||||
typedef signed long int64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
#define _scn64 "l"
|
||||
#define _pri64 "l"
|
||||
#define INT64_C(x) x ## L
|
||||
#define UINT64_C(x) x ## UL
|
||||
|
||||
#elif LLONG_MAX == 9223372036854775807LL
|
||||
|
||||
/* long long is 64 bits */
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#define _scn64 "ll"
|
||||
#define _pri64 "ll"
|
||||
#define INT64_C(x) x ## LL
|
||||
#define UINT64_C(x) x ## ULL
|
||||
|
||||
#else
|
||||
|
||||
#error "Neither long nor long long is 64 bits in size"
|
||||
|
||||
#endif
|
||||
|
||||
/*** 32-bit type: int or long ***/
|
||||
|
||||
#if INT_MAX == 2147483647
|
||||
|
||||
/* int is 32 bits */
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#define _scn32 ""
|
||||
#define _pri32 ""
|
||||
#define INT32_C(x) x
|
||||
#define UINT32_C(x) x ## U
|
||||
|
||||
#elif LONG_MAX == 2147483647L
|
||||
|
||||
/* long is 32 bits */
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#define _scn32 "l"
|
||||
#define _pri32 "l"
|
||||
#define INT32_C(x) x ## L
|
||||
#define UINT32_C(x) x ## UL
|
||||
|
||||
#else
|
||||
|
||||
#error "Neither int nor long is 32 bits in size"
|
||||
|
||||
#endif
|
||||
|
||||
/*** 16-bit size: int or short ***/
|
||||
|
||||
#if INT_MAX == 32767
|
||||
|
||||
/* int is 16 bits */
|
||||
typedef signed int int16_t;
|
||||
typedef unsigned int uint16_t;
|
||||
#define _scn16 ""
|
||||
#define _pri16 ""
|
||||
#define INT16_C(x) x
|
||||
#define UINT16_C(x) x ## U
|
||||
|
||||
#elif SHRT_MAX == 32767
|
||||
|
||||
/* short is 16 bits */
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
#define _scn16 "h"
|
||||
#define _pri16 ""
|
||||
#define INT16_C(x) x
|
||||
#define UINT16_C(x) x ## U
|
||||
|
||||
#else
|
||||
|
||||
#error "Neither short nor int is 16 bits in size"
|
||||
|
||||
#endif
|
||||
|
||||
/*** 8-bit size: char ***/
|
||||
|
||||
#if SCHAR_MAX == 127
|
||||
|
||||
/* char is 8 bits */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
#define _scn8 "hh"
|
||||
#define _pri8 ""
|
||||
#define INT8_C(x) x
|
||||
#define UINT8_C(x) x ## U
|
||||
|
||||
#else
|
||||
|
||||
#error "char is not 8 bits in size"
|
||||
|
||||
#endif
|
||||
|
||||
/* The rest of this is common to all models */
|
||||
|
||||
#define PRId8 _pri8 "d"
|
||||
#define PRId16 _pri16 "d"
|
||||
#define PRId32 _pri32 "d"
|
||||
#define PRId64 _pri64 "d"
|
||||
|
||||
#define PRIi8 _pri8 "i"
|
||||
#define PRIi16 _pri16 "i"
|
||||
#define PRIi32 _pri32 "i"
|
||||
#define PRIi64 _pri64 "i"
|
||||
|
||||
#define PRIo8 _pri8 "o"
|
||||
#define PRIo16 _pri16 "o"
|
||||
#define PRIo32 _pri32 "o"
|
||||
#define PRIo64 _pri64 "o"
|
||||
|
||||
#define PRIu8 _pri8 "u"
|
||||
#define PRIu16 _pri16 "u"
|
||||
#define PRIu32 _pri32 "u"
|
||||
#define PRIu64 _pri64 "u"
|
||||
|
||||
#define PRIx8 _pri8 "x"
|
||||
#define PRIx16 _pri16 "x"
|
||||
#define PRIx32 _pri32 "x"
|
||||
#define PRIx64 _pri64 "x"
|
||||
|
||||
#define PRIX8 _pri8 "X"
|
||||
#define PRIX16 _pri16 "X"
|
||||
#define PRIX32 _pri32 "X"
|
||||
#define PRIX64 _pri64 "X"
|
||||
|
||||
#define SCNd8 _scn8 "d"
|
||||
#define SCNd16 _scn16 "d"
|
||||
#define SCNd32 _scn32 "d"
|
||||
#define SCNd64 _scn64 "d"
|
||||
|
||||
#define SCNi8 _scn8 "i"
|
||||
#define SCNi16 _scn16 "i"
|
||||
#define SCNi32 _scn32 "i"
|
||||
#define SCNi64 _scn64 "i"
|
||||
|
||||
#define SCNo8 _scn8 "o"
|
||||
#define SCNo16 _scn16 "o"
|
||||
#define SCNo32 _scn32 "o"
|
||||
#define SCNo64 _scn64 "o"
|
||||
|
||||
#define SCNu8 _scn8 "u"
|
||||
#define SCNu16 _scn16 "u"
|
||||
#define SCNu32 _scn32 "u"
|
||||
#define SCNu64 _scn64 "u"
|
||||
|
||||
#define SCNx8 _scn8 "x"
|
||||
#define SCNx16 _scn16 "x"
|
||||
#define SCNx32 _scn32 "x"
|
||||
#define SCNx64 _scn64 "x"
|
||||
|
||||
#define INT8_MIN INT8_C(-128)
|
||||
#define INT8_MAX INT8_C(127)
|
||||
#define UINT8_MAX UINT8_C(255)
|
||||
|
||||
#define INT16_MIN INT16_C(-32768)
|
||||
#define INT16_MAX INT16_C(32767)
|
||||
#define UINT16_MAX UINT16_C(65535)
|
||||
|
||||
#define INT32_MIN INT32_C(-2147483648)
|
||||
#define INT32_MAX INT32_C(2147483647)
|
||||
#define UINT32_MAX UINT32_C(4294967295)
|
||||
|
||||
#define INT64_MIN INT64_C(-9223372036854775808)
|
||||
#define INT64_MAX INT64_C(9223372036854775807)
|
||||
#define UINT64_MAX UINT64_C(18446744073709551615)
|
||||
|
||||
#endif /* NASM_NASMINT_H */
|
||||
627
include/nasmlib.h
Normal file
627
include/nasmlib.h
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* nasmlib.h header file for nasmlib.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_NASMLIB_H
|
||||
#define NASM_NASMLIB_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "bytesex.h"
|
||||
|
||||
/*
|
||||
* Useful construct for private values
|
||||
*/
|
||||
union intorptr {
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
size_t s;
|
||||
void *p;
|
||||
const void *cp;
|
||||
uintptr_t up;
|
||||
};
|
||||
typedef union intorptr intorptr;
|
||||
|
||||
/*
|
||||
* Handy macro to use as the base of shifts
|
||||
*/
|
||||
#define ONE ((uintmax_t)1)
|
||||
|
||||
/*
|
||||
* Handy macros for defining and accessing enums of bitfields;
|
||||
* provides a set of standard-named parameters for each field.
|
||||
*
|
||||
* mk_field_mask() is indended to be used for non-contiguous fields.
|
||||
*/
|
||||
|
||||
#define mk_field_mask(name,pos,width,basemask) \
|
||||
name ## _POS = (pos), \
|
||||
name ## _WIDTH = (width), \
|
||||
name ## _BASEMASK = (basemask), \
|
||||
name ## _MASK = name ## _BASEMASK << name ## _POS, \
|
||||
name = name ## _MASK
|
||||
|
||||
#define mk_field(name,pos,width) \
|
||||
mk_field_mask(name,pos,width, \
|
||||
(1 << name ## _WIDTH)-1)
|
||||
|
||||
/*
|
||||
* Cast a value to a suitable type to represent the encoded
|
||||
* (post-shift) and extracted (pre-shift) values, respectively.
|
||||
*/
|
||||
#ifdef HAVE_TYPEOF
|
||||
# define fieldenc_cast(x,y) ((typeof(x ## _MASK))(y))
|
||||
# define fieldval_cast(x,y) ((typeof(x ## _BASEMASK))(y))
|
||||
#else
|
||||
/*
|
||||
* Using int here matches the strict ISO C before C23 which only allows
|
||||
* an enum to be in the range of "int". This also means that these macros
|
||||
* are only usable for bitfields up to 32 bits wide, which is extremely
|
||||
* unfortunate, but covers most of all the NASM use cases.
|
||||
*
|
||||
* The (int) should at least give a warning on overflow.
|
||||
*/
|
||||
# define fieldenc_cast(x,y) ((int)(y))
|
||||
# define fieldval_cast(x,y) (y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros to get/set bitfield values (the set macro returns the
|
||||
* updated value, it does not change the input.)
|
||||
*
|
||||
* The fieldenc() macro produces the masked and shifted value
|
||||
* corresponding to a base value; it is equivalent to
|
||||
* setfield(field,0,val).
|
||||
*/
|
||||
#define getfield(field,from) \
|
||||
fieldval_cast(field, \
|
||||
(((from) >> field ## _POS) & \
|
||||
field ## _BASEMASK))
|
||||
#define fieldval(field,val) \
|
||||
(((val) & fieldenc_cast(field,field ## _BASEMASK)) \
|
||||
<< field ## _POS)
|
||||
#define setfield(field,from,val) \
|
||||
(((from) & ~(field ## _MASK)) + fieldval(field,val))
|
||||
|
||||
/*
|
||||
* Wrappers around malloc, realloc, free and a few more. nasm_malloc
|
||||
* will fatal-error and die rather than return NULL; nasm_realloc will
|
||||
* do likewise, and will also guarantee to work right on being passed
|
||||
* a NULL pointer; nasm_free will do nothing if it is passed a NULL
|
||||
* pointer.
|
||||
*/
|
||||
void * safe_malloc(1) nasm_malloc(size_t);
|
||||
void * safe_malloc(1) nasm_zalloc(size_t);
|
||||
void * safe_malloc2(1,2) nasm_calloc(size_t, size_t);
|
||||
void * safe_realloc(2) nasm_realloc(void *, size_t);
|
||||
void nasm_free(void *);
|
||||
char * safe_alloc nasm_strdup(const char *);
|
||||
char * safe_alloc nasm_strndup(const char *, size_t);
|
||||
char * safe_alloc nasm_strcat(const char *one, const char *two);
|
||||
char * safe_alloc end_with_null nasm_strcatn(const char *one, ...);
|
||||
|
||||
/*
|
||||
* Replace a string in a string pointer variable with a nasm_strdup()
|
||||
* copy of the argument on the right, freeing the contents of the
|
||||
* previous contents of the variable if non-NULL.
|
||||
*
|
||||
* If *str is NULL, simply return the old value of *ptrp.
|
||||
*/
|
||||
char *nasm_strdupto(char **ptrp, const char *str);
|
||||
|
||||
/*
|
||||
* Similar, but the new pointer must already have been heap allocated
|
||||
* by the creating function.
|
||||
*/
|
||||
static inline char *nasm_strto(char **ptrp, char *str)
|
||||
{
|
||||
char *ptr = *ptrp;
|
||||
if (!str)
|
||||
return ptr;
|
||||
if (ptr)
|
||||
nasm_free(ptr);
|
||||
return *ptrp = str;
|
||||
}
|
||||
|
||||
/*
|
||||
* nasm_[v]asprintf() are variants of the semi-standard [v]asprintf()
|
||||
* functions, except that we return the pointer instead of a count.
|
||||
* The size of the string (including the final NUL!) is available
|
||||
* by calling nasm_last_string_size() afterwards.
|
||||
*
|
||||
* nasm_[v]axprintf() are similar, but allocates a user-defined amount
|
||||
* of storage before the string, and returns a pointer to the
|
||||
* allocated buffer. The value of nasm_last_string_size() does *not* include
|
||||
* this additional storage.
|
||||
*/
|
||||
char * safe_alloc printf_func(1, 2) nasm_asprintf(const char *fmt, ...);
|
||||
char * safe_alloc vprintf_func(1) nasm_vasprintf(const char *fmt, va_list ap);
|
||||
void * safe_alloc printf_func(2, 3) nasm_axprintf(size_t extra, const char *fmt, ...);
|
||||
void * safe_alloc vprintf_func(2) nasm_vaxprintf(size_t extra, const char *fmt, va_list ap);
|
||||
|
||||
/*
|
||||
* nasm_last_string_len() returns the length of the last string allocated
|
||||
* by [v]asprintf, nasm_strdup, nasm_strcat, or nasm_strcatn.
|
||||
*
|
||||
* nasm_last_string_size() returns the equivalent size including the
|
||||
* final NUL.
|
||||
*/
|
||||
static inline size_t nasm_last_string_len(void)
|
||||
{
|
||||
extern size_t _nasm_last_string_size;
|
||||
return _nasm_last_string_size - 1;
|
||||
}
|
||||
static inline size_t nasm_last_string_size(void)
|
||||
{
|
||||
extern size_t _nasm_last_string_size;
|
||||
return _nasm_last_string_size;
|
||||
}
|
||||
|
||||
/*
|
||||
* All zero data buffer
|
||||
*/
|
||||
#define ZERO_BUF_SIZE 65536 /* Default value */
|
||||
#if defined(BUFSIZ) && (BUFSIZ > ZERO_BUF_SIZE)
|
||||
# undef ZERO_BUF_SIZE
|
||||
# define ZERO_BUF_SIZE BUFSIZ
|
||||
#endif
|
||||
extern const uint8_t zero_buffer[ZERO_BUF_SIZE];
|
||||
|
||||
/*
|
||||
* Statically assert the argument is a pointer without evaluating it.
|
||||
* ? : requires that the types on both sides are compatible, and
|
||||
* const volatile void * is compatible with any pointer type.
|
||||
* Avoid a simple cast from NULL because it might make some compilers
|
||||
* confused; a pointer to any object works there.
|
||||
*/
|
||||
#define nasm_assert_pointer(p) \
|
||||
((void)sizeof(1 ? (p) : (const volatile void *)&zero_buffer))
|
||||
|
||||
#define nasm_new(p) ((p) = nasm_zalloc(sizeof(*(p))))
|
||||
#define nasm_newn(p,n) ((p) = nasm_calloc((n), sizeof(*(p))))
|
||||
/*
|
||||
* This is broken on platforms where there are pointers which don't
|
||||
* match void * in their internal layout. It unfortunately also
|
||||
* loses any "const" part of the argument, although hopefully the
|
||||
* compiler will warn in that case.
|
||||
*/
|
||||
#define nasm_delete(p) \
|
||||
do { \
|
||||
void **_pp = (void **)&(p); \
|
||||
nasm_assert_pointer(p); \
|
||||
nasm_free(*_pp); \
|
||||
*_pp = NULL; \
|
||||
} while (0)
|
||||
#define nasm_zero(x) (memset(&(x), 0, sizeof(x)))
|
||||
#define nasm_zeron(p,n) (memset((p), 0, (n)*sizeof(*(p))))
|
||||
|
||||
/*
|
||||
* Wrappers around fread()/fwrite() which fatal-errors on failure.
|
||||
* For fread(), only use this if EOF is supposed to be a fatal error!
|
||||
*/
|
||||
void nasm_read(void *, size_t, FILE *);
|
||||
void nasm_write(const void *, size_t, FILE *);
|
||||
|
||||
/*
|
||||
* NASM failure at build time if the argument is false
|
||||
*/
|
||||
#ifdef static_assert
|
||||
# define nasm_static_assert(x) static_assert((x), #x)
|
||||
#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__)
|
||||
# define nasm_static_assert(x) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
extern void __attribute__((error("assertion " #x " failed"))) \
|
||||
_nasm_static_fail(void); \
|
||||
_nasm_static_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
/* See http://www.drdobbs.com/compile-time-assertions/184401873 */
|
||||
# define nasm_static_assert(x) \
|
||||
do { enum { _static_assert_failed = 1/(!!(x)) }; } while (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* conditional static assert, if we know it is possible to determine
|
||||
* the assert value at compile time. Since if_constant triggers
|
||||
* pedantic warnings on gcc, turn them off explicitly around this code.
|
||||
*/
|
||||
#ifdef static_assert
|
||||
# define nasm_try_static_assert(x) \
|
||||
do { \
|
||||
not_pedantic_start \
|
||||
static_assert(if_constant(x, true), #x); \
|
||||
not_pedantic_end \
|
||||
} while (0)
|
||||
#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__)
|
||||
# define nasm_try_static_assert(x) \
|
||||
do { \
|
||||
if (!if_constant(x, true)) { \
|
||||
extern void __attribute__((error("assertion " #x " failed"))) \
|
||||
_nasm_static_fail(void); \
|
||||
_nasm_static_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
# define nasm_try_static_assert(x) ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NASM assert failure
|
||||
*/
|
||||
fatal_func nasm_assert_failed(const char *msg, const char *func,
|
||||
const char *file, int line);
|
||||
|
||||
/* Plain assert, gives the source location as an error message */
|
||||
#define nasm_assert(x) \
|
||||
do { \
|
||||
nasm_try_static_assert(x); \
|
||||
if (unlikely(!(x))) \
|
||||
nasm_assert_failed(#x,NASM_FUNC,__FILE__,__LINE__); \
|
||||
} while (0)
|
||||
|
||||
/* Assert with custom message */
|
||||
#define nasm_assert_msg(x,m) \
|
||||
do { \
|
||||
nasm_try_static_assert(x); \
|
||||
if (unlikely(!(x))) \
|
||||
nasm_panic("%s", m); \
|
||||
} while (0)
|
||||
|
||||
/* Utility function to generate a string for an invalid enum */
|
||||
const char *invalid_enum_str(int);
|
||||
|
||||
/*
|
||||
* ANSI doesn't guarantee the presence of `stricmp' or
|
||||
* `strcasecmp'.
|
||||
*/
|
||||
#if defined(HAVE_STRCASECMP)
|
||||
#define nasm_stricmp strcasecmp
|
||||
#elif defined(HAVE_STRICMP)
|
||||
#define nasm_stricmp stricmp
|
||||
#else
|
||||
int pure_func nasm_stricmp(const char *, const char *);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRNCASECMP)
|
||||
#define nasm_strnicmp strncasecmp
|
||||
#elif defined(HAVE_STRNICMP)
|
||||
#define nasm_strnicmp strnicmp
|
||||
#else
|
||||
int pure_func nasm_strnicmp(const char *, const char *, size_t);
|
||||
#endif
|
||||
|
||||
int pure_func nasm_memicmp(const char *, const char *, size_t);
|
||||
|
||||
#if defined(HAVE_STRSEP)
|
||||
#define nasm_strsep strsep
|
||||
#else
|
||||
char *nasm_strsep(char **stringp, const char *delim);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DECL_STRNLEN
|
||||
size_t pure_func strnlen(const char *, size_t);
|
||||
#endif
|
||||
|
||||
/* This returns the numeric value of a given 'digit'; no check for validity */
|
||||
static inline unsigned int numvalue(unsigned char c)
|
||||
{
|
||||
c |= 0x20;
|
||||
return c >= 'a' ? c - 'a' + 10 : c - '0';
|
||||
}
|
||||
|
||||
/* The same except returns -1U for non-digits, so it can be directly
|
||||
* compared against the base used to test for validity. */
|
||||
static inline unsigned int numvalue_chk(unsigned char c)
|
||||
{
|
||||
unsigned int v;
|
||||
v = c - '0';
|
||||
if (v < 10)
|
||||
return v;
|
||||
|
||||
v = (c | 0x20) - 'a';
|
||||
if (v < 26)
|
||||
return v + 10;
|
||||
|
||||
return -1U;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string into a number, using NASM number rules. Sets
|
||||
* `*error' to true if an error occurs, and false otherwise.
|
||||
*/
|
||||
int64_t readnum(const char *str, bool *error);
|
||||
|
||||
/*
|
||||
* Warn for the use of $ as a hexadecimal prefix
|
||||
*/
|
||||
void warn_dollar_hex(void);
|
||||
|
||||
/*
|
||||
* Get the numeric base corresponding to a character
|
||||
*/
|
||||
static inline unsigned int radix_letter(char c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b': case 'B':
|
||||
case 'y': case 'Y':
|
||||
return 2; /* Binary */
|
||||
case 'o': case 'O':
|
||||
case 'q': case 'Q':
|
||||
return 8; /* Octal */
|
||||
case 'h': case 'H':
|
||||
case 'x': case 'X':
|
||||
return 16; /* Hexadecimal */
|
||||
case 'd': case 'D':
|
||||
case 't': case 'T':
|
||||
return 10; /* Decimal */
|
||||
default:
|
||||
return 0; /* Not a known radix letter */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a character constant into a number. Sets
|
||||
* `*warn' to true if an overflow occurs, and false otherwise.
|
||||
* str points to and length covers the middle of the string,
|
||||
* without the quotes.
|
||||
*/
|
||||
int64_t readstrnum(char *str, int length, bool *warn);
|
||||
|
||||
/*
|
||||
* Produce an unsigned integer string from a number with a specified
|
||||
* base, digits and signedness
|
||||
*/
|
||||
#define NUMSTR_MAXBASE 64
|
||||
int numstr(char *buf, size_t buflen, uint64_t n,
|
||||
int digits, unsigned int base, bool ucase);
|
||||
|
||||
extern const char * const nasmlib_digit_chars[2];
|
||||
static inline const char *nasm_digit_chars(bool ucase)
|
||||
{
|
||||
return nasmlib_digit_chars[ucase];
|
||||
}
|
||||
|
||||
/*
|
||||
* seg_alloc: allocate a hitherto unused segment number.
|
||||
*/
|
||||
int32_t seg_alloc(void);
|
||||
|
||||
/*
|
||||
* Add/replace or remove an extension to the end of a filename;
|
||||
* returns a newly allocated buffer with the modified filename.
|
||||
*/
|
||||
char *filename_set_extension(const char *inname, const char *extension);
|
||||
|
||||
/*
|
||||
* Utility macros...
|
||||
*
|
||||
* This is a useful #define which I keep meaning to use more often:
|
||||
* the number of elements of a statically defined array.
|
||||
*/
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#define ARRAY_END(arr) (&(arr)[ARRAY_SIZE(arr)])
|
||||
#define array_for_each(var,arr) \
|
||||
for ((var) = (arr); (var) < ARRAY_END(arr); (var)++)
|
||||
|
||||
|
||||
/*
|
||||
* List handling
|
||||
*
|
||||
* list_for_each - regular iterator over list
|
||||
* list_for_each_safe - the same but safe against list items removal
|
||||
* list_last - find the last element in a list
|
||||
* list_reverse - reverse the order of a list
|
||||
*
|
||||
* Arguments named with _ + single letter should be temp variables
|
||||
* of the appropriate pointer type.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = head; pos; pos = pos->next)
|
||||
#define list_for_each_safe(pos, _n, head) \
|
||||
for (pos = head, _n = (pos ? pos->next : NULL); pos; \
|
||||
pos = _n, _n = (_n ? _n->next : NULL))
|
||||
#define list_last(pos, head) \
|
||||
do { \
|
||||
for (pos = head; pos && pos->next; pos = pos->next) \
|
||||
; \
|
||||
} while (0)
|
||||
#define list_reverse(head) \
|
||||
do { \
|
||||
void *_p, *_n; \
|
||||
if (!head || !head->next) \
|
||||
break; \
|
||||
_p = NULL; \
|
||||
while (head) { \
|
||||
_n = head->next; \
|
||||
head->next = _p; \
|
||||
_p = head; \
|
||||
head = _n; \
|
||||
} \
|
||||
head = _p; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Power of 2 align helpers
|
||||
*/
|
||||
#undef ALIGN_MASK /* Some BSD flavors define these in system headers */
|
||||
#undef ALIGN
|
||||
#define ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask))
|
||||
#define ALIGN(v, a) ALIGN_MASK(v, (a) - 1)
|
||||
#define IS_ALIGNED(v, a) (((v) & ((a) - 1)) == 0)
|
||||
|
||||
/*
|
||||
* Routines to write littleendian data to a file
|
||||
*/
|
||||
#define fwriteint8_t(d,f) putc(d,f)
|
||||
void fwriteint16_t(uint16_t data, FILE * fp);
|
||||
void fwriteint32_t(uint32_t data, FILE * fp);
|
||||
void fwriteint64_t(uint64_t data, FILE * fp);
|
||||
void fwriteaddr(uint64_t data, int size, FILE * fp);
|
||||
|
||||
/*
|
||||
* Binary search routine. Returns index into `array' of an entry
|
||||
* matching `string', or <0 if no match. `array' is taken to
|
||||
* contain `size' elements.
|
||||
*
|
||||
* bsi() is case sensitive, bsii() is case insensitive.
|
||||
*/
|
||||
int pure_func bsi(const char *string, const char **array, int size);
|
||||
int pure_func bsii(const char *string, const char **array, int size);
|
||||
|
||||
/*
|
||||
* Convenient string processing helper routines
|
||||
*/
|
||||
char * pure_func nasm_skip_spaces(const char *p);
|
||||
char * pure_func nasm_skip_word(const char *p);
|
||||
char *nasm_zap_spaces_fwd(char *p);
|
||||
char *nasm_zap_spaces_rev(char *p);
|
||||
char *nasm_trim_spaces(char *p);
|
||||
char *nasm_get_word(char *p, char **tail);
|
||||
char *nasm_opt_val(char *p, char **opt, char **val);
|
||||
|
||||
/*
|
||||
* Converts a relative pathname rel_path into an absolute path name.
|
||||
*
|
||||
* The buffer returned must be freed by the caller
|
||||
*/
|
||||
char * safe_alloc nasm_realpath(const char *rel_path);
|
||||
|
||||
/*
|
||||
* Path-splitting and merging functions
|
||||
*/
|
||||
char * safe_alloc nasm_dirname(const char *path);
|
||||
char * safe_alloc nasm_basename(const char *path);
|
||||
char * safe_alloc nasm_catfile(const char *dir, const char *path);
|
||||
|
||||
/*
|
||||
* Various tokens to readable strings, with limit checking
|
||||
*/
|
||||
const char * const_func register_name(int);
|
||||
const char * const_func prefix_name(int);
|
||||
bool const_func is_hint_nop(uint64_t);
|
||||
|
||||
/*
|
||||
* Wrappers around fopen()... for future change to a dedicated structure
|
||||
*/
|
||||
enum file_flags {
|
||||
NF_BINARY = 0x00000000, /* Binary file (default) */
|
||||
NF_TEXT = 0x00000001, /* Text file */
|
||||
NF_NONFATAL = 0x00000000, /* Don't die on open failure (default) */
|
||||
NF_FATAL = 0x00000002, /* Die on open failure */
|
||||
NF_FORMAP = 0x00000004, /* Intended to use nasm_map_file() */
|
||||
NF_IONBF = 0x00000010, /* Force unbuffered stdio */
|
||||
NF_IOLBF = 0x00000020, /* Force line buffered stdio */
|
||||
NF_IOFBF = 0000000030 /* Force fully buffered stdio */
|
||||
};
|
||||
#define NF_BUF_MASK 0x30
|
||||
|
||||
FILE *nasm_open_read(const char *filename, enum file_flags flags);
|
||||
FILE *nasm_open_write(const char *filename, enum file_flags flags);
|
||||
|
||||
void nasm_set_binary_mode(FILE *f);
|
||||
|
||||
/* Probe for existence of a file */
|
||||
bool nasm_file_exists(const char *filename);
|
||||
|
||||
/* Missing fseeko/ftello */
|
||||
#ifndef HAVE_FSEEKO
|
||||
# undef off_t /* Just in case it is a macro */
|
||||
# ifdef HAVE__FSEEKI64
|
||||
# define fseeko _fseeki64
|
||||
# define ftello _ftelli64
|
||||
# define off_t int64_t
|
||||
# else
|
||||
# define fseeko fseek
|
||||
# define ftello ftell
|
||||
# define off_t long
|
||||
# endif
|
||||
#endif
|
||||
|
||||
const void *nasm_map_file(FILE *fp, off_t start, off_t len);
|
||||
void nasm_unmap_file(const void *p, size_t len);
|
||||
off_t nasm_file_size(FILE *f);
|
||||
off_t nasm_file_size_by_path(const char *pathname);
|
||||
bool nasm_file_time(time_t *t, const char *pathname);
|
||||
void fwritezero(off_t bytes, FILE *fp);
|
||||
|
||||
/* Remove a file; explicitly defined to ignore a NULL or empty pathname */
|
||||
int nasm_remove(const char *pathname);
|
||||
|
||||
/* Sign-extend a value to an arbitrary number of bits */
|
||||
static inline int64_t const_func sext(int64_t value, unsigned int bits)
|
||||
{
|
||||
if (is_constant(bits)) {
|
||||
switch (bits) {
|
||||
case 8:
|
||||
return (int8_t)value;
|
||||
case 16:
|
||||
return (int16_t)value;
|
||||
case 32:
|
||||
return (int32_t)value;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bits >= 64)
|
||||
return value;
|
||||
|
||||
/* sext(foo,0) == sext(foo,1) */
|
||||
bits = bits ? 64-bits : 63;
|
||||
|
||||
return value << bits >> bits;
|
||||
}
|
||||
|
||||
/* Zero-extend a value to an arbitrary number of bits */
|
||||
static inline uint64_t const_func zext(uint64_t value, unsigned int bits)
|
||||
{
|
||||
if (is_constant(bits)) {
|
||||
switch (bits) {
|
||||
case 8:
|
||||
return (uint8_t)value;
|
||||
case 16:
|
||||
return (uint16_t)value;
|
||||
case 32:
|
||||
return (uint32_t)value;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bits >= 64)
|
||||
return value;
|
||||
|
||||
if (!bits)
|
||||
return 0;
|
||||
|
||||
bits = 64-bits;
|
||||
return value << bits >> bits;
|
||||
}
|
||||
|
||||
static inline bool const_func overflow_signed(int64_t value, unsigned int bytes)
|
||||
{
|
||||
return sext(value, bytes << 3) != value;
|
||||
}
|
||||
|
||||
static inline bool const_func overflow_unsigned(uint64_t value, unsigned int bytes)
|
||||
{
|
||||
return zext(value, bytes << 3) != value;
|
||||
}
|
||||
|
||||
/* This is very conservative, but otherwise things like ~0x80 break */
|
||||
static inline bool const_func overflow_general(int64_t value, unsigned int bytes)
|
||||
{
|
||||
return overflow_unsigned(value, bytes) && overflow_unsigned(-value, bytes);
|
||||
}
|
||||
|
||||
/* check if value is power of 2 */
|
||||
#define is_power2(v) ((v) && ((v) & ((v) - 1)) == 0)
|
||||
|
||||
/* try to get the system stack size */
|
||||
extern size_t nasm_get_stack_size_limit(void);
|
||||
|
||||
#endif
|
||||
108
include/nctype.h
Normal file
108
include/nctype.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* ctype-like functions specific to NASM
|
||||
*/
|
||||
#ifndef NASM_NCTYPE_H
|
||||
#define NASM_NCTYPE_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
void nasm_ctype_init(void);
|
||||
|
||||
extern unsigned char nasm_tolower_tab[256];
|
||||
static inline char nasm_tolower(char x)
|
||||
{
|
||||
return nasm_tolower_tab[(unsigned char)x];
|
||||
}
|
||||
|
||||
/*
|
||||
* NASM ctype table
|
||||
*/
|
||||
enum nasm_ctype {
|
||||
NCT_CTRL = 0x0001,
|
||||
NCT_SPACE = 0x0002,
|
||||
NCT_ASCII = 0x0004,
|
||||
NCT_LOWER = 0x0008, /* isalpha(x) && tolower(x) == x */
|
||||
NCT_UPPER = 0x0010, /* isalpha(x) && tolower(x) != x */
|
||||
NCT_DIGIT = 0x0020,
|
||||
NCT_HEX = 0x0040,
|
||||
NCT_ID = 0x0080,
|
||||
NCT_IDSTART = 0x0100,
|
||||
NCT_MINUS = 0x0200, /* - */
|
||||
NCT_DOLLAR = 0x0400, /* $ */
|
||||
NCT_UNDER = 0x0800, /* _ */
|
||||
NCT_QUOTE = 0x1000 /* " ' ` */
|
||||
};
|
||||
|
||||
extern uint16_t nasm_ctype_tab[256];
|
||||
static inline bool nasm_ctype(unsigned char x, enum nasm_ctype mask)
|
||||
{
|
||||
return (nasm_ctype_tab[x] & mask) != 0;
|
||||
}
|
||||
|
||||
static inline bool nasm_isspace(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_SPACE);
|
||||
}
|
||||
|
||||
static inline bool nasm_isalpha(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_LOWER|NCT_UPPER);
|
||||
}
|
||||
|
||||
static inline bool nasm_isdigit(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_DIGIT);
|
||||
}
|
||||
static inline bool nasm_isalnum(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_LOWER|NCT_UPPER|NCT_DIGIT);
|
||||
}
|
||||
static inline bool nasm_isxdigit(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_HEX);
|
||||
}
|
||||
static inline bool nasm_isidstart(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_IDSTART);
|
||||
}
|
||||
static inline bool nasm_isidchar(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_ID);
|
||||
}
|
||||
static inline bool nasm_isbrcchar(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_ID|NCT_MINUS);
|
||||
}
|
||||
static inline bool nasm_isnumstart(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_DIGIT|NCT_DOLLAR);
|
||||
}
|
||||
static inline bool nasm_isnumchar(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_DIGIT|NCT_LOWER|NCT_UPPER|NCT_UNDER);
|
||||
}
|
||||
static inline bool nasm_isquote(char x)
|
||||
{
|
||||
return nasm_ctype(x, NCT_QUOTE);
|
||||
}
|
||||
|
||||
static inline void nasm_ctype_tasm_mode(void)
|
||||
{
|
||||
/* No differences at the present moment */
|
||||
}
|
||||
|
||||
/* Returns a value >= 16 if not a valid hex digit */
|
||||
static inline unsigned int nasm_hexval(char c)
|
||||
{
|
||||
unsigned int v = (unsigned char) c;
|
||||
|
||||
if (v >= '0' && v <= '9')
|
||||
return v - '0';
|
||||
else
|
||||
return (v|0x20) - 'a' + 10;
|
||||
}
|
||||
|
||||
#endif /* NASM_NCTYPE_H */
|
||||
320
include/opflags.h
Normal file
320
include/opflags.h
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2024 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* opflags.h - operand flags
|
||||
*/
|
||||
|
||||
#ifndef NASM_OPFLAGS_H
|
||||
#define NASM_OPFLAGS_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "tables.h"
|
||||
#include "regs.h"
|
||||
|
||||
/*
|
||||
* Here we define the operand types. These are implemented as bit
|
||||
* masks, since some are subsets of others; e.g. AX in a MOV
|
||||
* instruction is a special operand type, whereas AX in other
|
||||
* contexts is just another 16-bit register. (Also, consider CL in
|
||||
* shift instructions, DX in OUT, etc.)
|
||||
*
|
||||
* The basic concept here is that
|
||||
* (class & ~operand) == 0
|
||||
*
|
||||
* if and only if "operand" belongs to class type "class".
|
||||
*/
|
||||
|
||||
#define OP_GENMASK(bits, shift) (((UINT64_C(1) << (bits)) - 1) << (shift))
|
||||
#define OP_GENBIT(bit, shift) (UINT64_C(1) << ((shift) + (bit)))
|
||||
|
||||
/*
|
||||
* Type of operand: memory reference, register, etc.
|
||||
*
|
||||
* Bits: 0 - 3
|
||||
*/
|
||||
#define OPTYPE_SHIFT (0)
|
||||
#define OPTYPE_BITS (4)
|
||||
#define OPTYPE_MASK OP_GENMASK(OPTYPE_BITS, OPTYPE_SHIFT)
|
||||
#define GEN_OPTYPE(bit) OP_GENBIT(bit, OPTYPE_SHIFT)
|
||||
|
||||
/*
|
||||
* Modifiers.
|
||||
*
|
||||
* Bits: 4 - 6
|
||||
*/
|
||||
#define MODIFIER_SHIFT (OPTYPE_SHIFT + OPTYPE_BITS)
|
||||
#define MODIFIER_BITS (3)
|
||||
#define MODIFIER_MASK OP_GENMASK(MODIFIER_BITS, MODIFIER_SHIFT)
|
||||
#define GEN_MODIFIER(bit) OP_GENBIT(bit, MODIFIER_SHIFT)
|
||||
|
||||
/*
|
||||
* Register classes.
|
||||
*
|
||||
* Bits: 7 - 17
|
||||
*/
|
||||
#define REG_CLASS_SHIFT (MODIFIER_SHIFT + MODIFIER_BITS)
|
||||
#define REG_CLASS_BITS (11)
|
||||
#define REG_CLASS_MASK OP_GENMASK(REG_CLASS_BITS, REG_CLASS_SHIFT)
|
||||
#define GEN_REG_CLASS(bit) OP_GENBIT(bit, REG_CLASS_SHIFT)
|
||||
|
||||
/*
|
||||
* Subclasses. Depends on type of operand.
|
||||
*
|
||||
* Bits: 18 - 31
|
||||
*/
|
||||
#define SUBCLASS_SHIFT (REG_CLASS_SHIFT + REG_CLASS_BITS)
|
||||
#define SUBCLASS_BITS (14)
|
||||
#define SUBCLASS_MASK OP_GENMASK(SUBCLASS_BITS, SUBCLASS_SHIFT)
|
||||
#define GEN_SUBCLASS(bit) OP_GENBIT(bit, SUBCLASS_SHIFT)
|
||||
|
||||
/*
|
||||
* Sizes of the operands and attributes.
|
||||
*
|
||||
* Bits: 32 - 47
|
||||
*/
|
||||
#define SIZE_SHIFT (SUBCLASS_SHIFT + SUBCLASS_BITS)
|
||||
#define SIZE_BITS (16)
|
||||
#define SIZE_MASK OP_GENMASK(SIZE_BITS, SIZE_SHIFT)
|
||||
#define GEN_SIZE(bit) OP_GENBIT(bit, SIZE_SHIFT)
|
||||
|
||||
/*
|
||||
* Register set count
|
||||
*
|
||||
* Bits: 48 - 52
|
||||
*/
|
||||
#define REGSET_SHIFT (SIZE_SHIFT + SIZE_BITS)
|
||||
#define REGSET_BITS (5)
|
||||
#define REGSET_MASK OP_GENMASK(REGSET_BITS, REGSET_SHIFT)
|
||||
#define GEN_REGSET(bit) OP_GENBIT(bit, REGSET_SHIFT)
|
||||
|
||||
/*
|
||||
* Remaining bits
|
||||
*/
|
||||
#define OPFLAGS_USED_BITS (REGSET_SHIFT + REGSET_BITS)
|
||||
#define OPFLAGS_UNUSED_BITS (64-OPFLAGS_USED_BITS)
|
||||
|
||||
#define REGISTER GEN_OPTYPE(0) /* register number in 'basereg' */
|
||||
#define IMMEDIATE GEN_OPTYPE(1)
|
||||
#define REGMEM GEN_OPTYPE(2) /* for r/m, ie EA, operands */
|
||||
#define MEMORY (GEN_OPTYPE(3) | REGMEM)
|
||||
|
||||
/* First, the actual sizes */
|
||||
#define BITS8 GEN_SIZE(0) /* 8 bits (BYTE) */
|
||||
#define BITS16 GEN_SIZE(1) /* 16 bits (WORD) */
|
||||
#define BITS32 GEN_SIZE(2) /* 32 bits (DWORD) */
|
||||
#define BITS64 GEN_SIZE(3) /* 64 bits (QWORD), x64 and FPU only */
|
||||
#define BITS80 GEN_SIZE(4) /* 80 bits (TWORD), FPU only */
|
||||
#define BITS128 GEN_SIZE(5) /* 128 bits (OWORD) */
|
||||
#define BITS256 GEN_SIZE(6) /* 256 bits (YWORD) */
|
||||
#define BITS512 GEN_SIZE(7) /* 512 bits (ZWORD) */
|
||||
|
||||
/* Then, size modifiers */
|
||||
#define FAR GEN_SIZE(8) /* grotty: this means 16:16 or 16:32, like in CALL/JMP */
|
||||
#define NEAR GEN_SIZE(9)
|
||||
#define SHORT GEN_SIZE(10) /* and this means what it says :) */
|
||||
#define ABS GEN_SIZE(11) /* JMP ABS, MOV ABS */
|
||||
|
||||
/* Special modifiers */
|
||||
#define TO GEN_MODIFIER(0) /* reverse effect in FADD, FSUB &c */
|
||||
#define COLON GEN_MODIFIER(1) /* operand is followed by a colon */
|
||||
#define STRICT GEN_MODIFIER(2) /* do not optimize this operand */
|
||||
|
||||
#define REG_CLASS_CDT GEN_REG_CLASS(0)
|
||||
#define REG_CLASS_GPR GEN_REG_CLASS(1)
|
||||
#define REG_CLASS_SREG GEN_REG_CLASS(2)
|
||||
#define REG_CLASS_FPUREG GEN_REG_CLASS(3)
|
||||
#define REG_CLASS_RM_MMX GEN_REG_CLASS(4)
|
||||
#define REG_CLASS_RM_XMM GEN_REG_CLASS(5)
|
||||
#define REG_CLASS_RM_YMM GEN_REG_CLASS(6)
|
||||
#define REG_CLASS_RM_ZMM GEN_REG_CLASS(7)
|
||||
#define REG_CLASS_OPMASK GEN_REG_CLASS(8)
|
||||
#define REG_CLASS_BND GEN_REG_CLASS(9)
|
||||
#define REG_CLASS_RM_TMM GEN_REG_CLASS(10)
|
||||
|
||||
/* Register classes treated as vectors for EVEX/REX2 encoding purposes */
|
||||
#define REG_CLASS_VECTOR (REG_CLASS_RM_XMM|REG_CLASS_RM_YMM|\
|
||||
REG_CLASS_RM_ZMM|REG_CLASS_RM_TMM)
|
||||
|
||||
/* Helper function to test for a value matching a class */
|
||||
static inline bool is_class(opflags_t class, opflags_t op)
|
||||
{
|
||||
return !(class & ~op);
|
||||
}
|
||||
|
||||
/* Verify a token value is a valid register */
|
||||
static inline bool is_register(int reg)
|
||||
{
|
||||
return reg >= EXPR_REG_START && reg < REG_ENUM_LIMIT;
|
||||
}
|
||||
|
||||
/* Helper function to test if a token is a register matching a class */
|
||||
static inline bool is_reg_class(opflags_t class, int reg)
|
||||
{
|
||||
if (!is_register(reg))
|
||||
return false;
|
||||
|
||||
return is_class(class, nasm_reg_flags[reg]);
|
||||
}
|
||||
|
||||
#define IS_SREG(reg) is_reg_class(REG_SREG, (reg))
|
||||
#define IS_FSGS(reg) is_reg_class(REG_FSGS, (reg))
|
||||
|
||||
/*
|
||||
* These are used across the RM classes so cannot conflict with neither EA
|
||||
* nor REG subtypes! x86/insns.pl automatically adds RN_FLAGS(x) to the
|
||||
* defintion of each register type.
|
||||
*/
|
||||
#define RN_L16 GEN_SUBCLASS(10) /* Register number 0-15 */
|
||||
#define RN_ZERO (GEN_SUBCLASS(11) | RN_L16) /* Register number 0 */
|
||||
#define RN_NZERO GEN_SUBCLASS(12) /* Register number 1+ */
|
||||
#define RN_1_15 (RN_NZERO | RN_L16) /* Register number 1-15 */
|
||||
|
||||
#define RN_FLAGS(n) \
|
||||
(((n) == 0 ? RN_ZERO : RN_NZERO) | \
|
||||
((n) < 16 ? RN_L16 : 0))
|
||||
|
||||
#define RM_L16 (RN_L16 | REGMEM)
|
||||
#define RM_ZERO (RN_ZERO | REGMEM)
|
||||
#define RM_NZERO (RN_NZERO | REGMEM)
|
||||
#define RM_1_15 (RM_1_15 | REGMEM)
|
||||
#define RM_SEL (GEN_SUBCLASS(13) | REGMEM) /* valid segment selector */
|
||||
|
||||
/* Register classes */
|
||||
|
||||
#define REG_L16 (RN_L16 | REGISTER)
|
||||
#define REG_ZERO (RN_ZERO | REGISTER)
|
||||
#define REG_NZERO (RN_NZERO | REGISTER)
|
||||
#define REG_1_15 (RN_1_15 | REGISTER)
|
||||
|
||||
#define REG_SMASK SUBCLASS_MASK
|
||||
|
||||
#define REG_EA ( REGMEM | REGISTER ) /* 'normal' reg, qualifies as EA */
|
||||
#define RM_GPR (REG_CLASS_GPR | REGMEM ) /* integer operand */
|
||||
#define REG_GPR (REG_CLASS_GPR | REG_EA ) /* integer register */
|
||||
#define FPUREG (REG_CLASS_FPUREG | REGISTER ) /* fp stack registers */
|
||||
#define FPU0 (REG_CLASS_FPUREG | REG_ZERO ) /* fp stack register zero */
|
||||
#define RM_MMX (REG_CLASS_RM_MMX | REGMEM ) /* MMX operand */
|
||||
#define MMXREG (REG_CLASS_RM_MMX | REG_EA ) /* MMX register */
|
||||
#define RM_XMM (REG_CLASS_RM_XMM | REGMEM ) /* XMM operand */
|
||||
#define XMMREG (REG_CLASS_RM_XMM | REG_EA ) /* XMM register */
|
||||
#define RM_XMM_L16 (REG_CLASS_RM_XMM | REGMEM | RN_L16 ) /* XMM operand reg 0-15 */
|
||||
#define XMM_L16 (REG_CLASS_RM_XMM | REG_EA | RN_L16 ) /* XMM register 0-15 */
|
||||
#define XMM0 (REG_CLASS_RM_XMM | REGMEM | REG_ZERO ) /* XMM register 0 */
|
||||
#define RM_YMM (REG_CLASS_RM_YMM | REGMEM ) /* YMM operand */
|
||||
#define YMMREG (REG_CLASS_RM_YMM | REG_EA ) /* YMM register */
|
||||
#define RM_YMM_L16 (REG_CLASS_RM_YMM | REGMEM | RN_L16 ) /* YMM operand reg 0-15 */
|
||||
#define YMM_L16 (REG_CLASS_RM_YMM | REG_EA | RN_L16 ) /* YMM register 0-15 */
|
||||
#define YMM0 (REG_CLASS_RM_YMM | REGMEM | REG_ZERO ) /* YMM register 0 */
|
||||
#define RM_ZMM (REG_CLASS_RM_ZMM | REGMEM ) /* ZMM operand */
|
||||
#define ZMMREG (REG_CLASS_RM_ZMM | REG_EA ) /* ZMM register */
|
||||
#define RM_ZMM_L16 (REG_CLASS_RM_ZMM | REGMEM | RN_L16 ) /* ZMM operand reg 0-15 */
|
||||
#define ZMM_L16 (REG_CLASS_RM_ZMM | REG_EA | RN_L16 ) /* ZMM register 0-15 */
|
||||
#define ZMM0 (REG_CLASS_RM_ZMM | REGMEM | REG_ZERO ) /* ZMM register 0 */
|
||||
#define RM_OPMASK (REG_CLASS_OPMASK | REGMEM ) /* Opmask operand */
|
||||
#define OPMASKREG (REG_CLASS_OPMASK | REG_EA ) /* Opmask register */
|
||||
#define OPMASK0 (REG_CLASS_OPMASK | REG_EA ) /* Opmask register zero (k0) */
|
||||
#define RM_K RM_OPMASK
|
||||
#define KREG OPMASKREG
|
||||
#define RM_BND (REG_CLASS_BND | REGMEM ) /* Bounds operand */
|
||||
#define BNDREG (REG_CLASS_BND | REG_EA ) /* Bounds register */
|
||||
#define TMMREG (REG_CLASS_RM_TMM | REG_EA ) /* TMM (AMX) register */
|
||||
|
||||
#define REG_CDT (REG_CLASS_CDT | REGISTER) /* CRn, DRn and TRn */
|
||||
#define REG_CREG (GEN_SUBCLASS(0) | REG_CDT ) /* CRn */
|
||||
#define REG_DREG (GEN_SUBCLASS(1) | REG_CDT ) /* DRn */
|
||||
#define REG_TREG (GEN_SUBCLASS(2) | REG_CDT ) /* TRn */
|
||||
|
||||
#define REG_SREG (REG_CLASS_SREG | REG_L16 | BITS16) /* segment register */
|
||||
|
||||
/* Segment registers */
|
||||
#define REG_ES (GEN_SUBCLASS(0) | GEN_SUBCLASS(2) | REG_SREG) /* ES */
|
||||
#define REG_CS (GEN_SUBCLASS(1) | GEN_SUBCLASS(2) | REG_SREG) /* CS */
|
||||
#define REG_SS (GEN_SUBCLASS(0) | GEN_SUBCLASS(3) | REG_SREG) /* SS */
|
||||
#define REG_DS (GEN_SUBCLASS(1) | GEN_SUBCLASS(3) | REG_SREG) /* DS */
|
||||
#define REG_FS (GEN_SUBCLASS(0) | GEN_SUBCLASS(4) | REG_SREG) /* FS */
|
||||
#define REG_GS (GEN_SUBCLASS(1) | GEN_SUBCLASS(4) | REG_SREG) /* GS */
|
||||
#define REG_FSGS ( GEN_SUBCLASS(4) | REG_SREG) /* FS or GS */
|
||||
#define REG_SEG6 (GEN_SUBCLASS(0) | GEN_SUBCLASS(5) | REG_SREG)
|
||||
#define REG_SEG7 (GEN_SUBCLASS(1) | GEN_SUBCLASS(5) | REG_SREG)
|
||||
#define REG_SEG67 ( GEN_SUBCLASS(5) | REG_SREG)
|
||||
|
||||
/* GPRs */
|
||||
|
||||
#define REG8 (REG_GPR | BITS8 )
|
||||
#define REG16 (REG_GPR | BITS16 | RM_SEL)
|
||||
#define REG32 (REG_GPR | BITS32 | RM_SEL)
|
||||
#define REG64 (REG_GPR | BITS64 | RM_SEL)
|
||||
|
||||
/* accumulator: AL, AX, EAX, RAX */
|
||||
#define REG_ACCUM (REG_GPR | REG_ZERO)
|
||||
#define REG_AL (REG_ACCUM | REG8 )
|
||||
#define REG_AX (REG_ACCUM | REG16)
|
||||
#define REG_EAX (REG_ACCUM | REG32)
|
||||
#define REG_RAX (REG_ACCUM | REG64)
|
||||
|
||||
/* counter: CL, CX, ECX, RDX */
|
||||
#define REG_COUNT (REG_GPR | REG_1_15 | GEN_SUBCLASS(0))
|
||||
#define REG_CL (REG_COUNT | REG8 )
|
||||
#define REG_CX (REG_COUNT | REG16)
|
||||
#define REG_ECX (REG_COUNT | REG32)
|
||||
#define REG_RCX (REG_COUNT | REG64)
|
||||
|
||||
/* data: DL, DX, EDX, RDX */
|
||||
#define REG_DATA (REG_GPR | REG_1_15 | GEN_SUBCLASS(1))
|
||||
#define REG_DL (REG_DATA | REG8 )
|
||||
#define REG_DX (REG_DATA | REG16)
|
||||
#define REG_EDX (REG_DATA | REG32)
|
||||
#define REG_RDX (REG_DATA | REG64)
|
||||
|
||||
/* base: BL, BX, EBX, RBX */
|
||||
#define REG_BASE (REG_GPR | REG_1_15 | GEN_SUBCLASS(2))
|
||||
#define REG_BL (REG_BASE | REG8 )
|
||||
#define REG_BX (REG_BASE | REG16)
|
||||
#define REG_EBX (REG_BASE | REG32)
|
||||
#define REG_RBX (REG_BASE | REG64)
|
||||
|
||||
/* high 8-bit regs: AH, CH, DH, BH */
|
||||
#define REG_HIGH (REG8 | REG_1_15 | GEN_SUBCLASS(3))
|
||||
|
||||
/* Non-accumulator registers */
|
||||
#define REG_NA (REG_GPR | REG_NZERO)
|
||||
#define REG8NA (REG_NA | REG8 )
|
||||
#define REG16NA (REG_NA | REG16)
|
||||
#define REG32NA (REG_NA | REG32)
|
||||
#define REG64NA (REG_NA | REG64)
|
||||
|
||||
/* special types of EAs */
|
||||
#define MEM_OFFS (GEN_SUBCLASS(0) | MEMORY) /* simple [address] offset - absolute! */
|
||||
#define IP_REL (GEN_SUBCLASS(1) | MEMORY) /* IP-relative offset */
|
||||
#define XMEM (GEN_SUBCLASS(2) | MEMORY) /* 128-bit vector SIB */
|
||||
#define YMEM (GEN_SUBCLASS(3) | MEMORY) /* 256-bit vector SIB */
|
||||
#define ZMEM (GEN_SUBCLASS(4) | MEMORY) /* 512-bit vector SIB */
|
||||
|
||||
/*
|
||||
* operand bits to match an instruction carrying any type of memory r/m operand
|
||||
*/
|
||||
#define MEMORY_ANY (MEMORY | RM_GPR | RM_MMX | RM_XMM | RM_YMM | RM_ZMM | \
|
||||
RM_L16 | RM_ZERO | RM_NZERO | RM_OPMASK | RM_BND)
|
||||
|
||||
/* special immediate values */
|
||||
#define IMM_NORMAL (GEN_SUBCLASS(0) | IMMEDIATE) /* operand is NOT a brcconst */
|
||||
#define UNITY (GEN_SUBCLASS(1) | IMMEDIATE) /* operand equals 1 */
|
||||
#define SBYTEWORD (GEN_SUBCLASS(2) | IMMEDIATE) /* operand is in the range -128..127 mod 2^16 */
|
||||
#define SBYTEDWORD (GEN_SUBCLASS(3) | IMMEDIATE) /* operand is in the range -128..127 mod 2^32 */
|
||||
#define SDWORD (GEN_SUBCLASS(4) | IMMEDIATE) /* operand is in the range -0x80000000..0x7FFFFFFF */
|
||||
#define UDWORD (GEN_SUBCLASS(5) | IMMEDIATE) /* operand is in the range 0..0xFFFFFFFF */
|
||||
#define FOURBITS (GEN_SUBCLASS(6) | IMMEDIATE) /* operand is in the range 0-15 */
|
||||
#define IMM_KNOWN (GEN_SUBCLASS(7) | IMMEDIATE) /* operand value is known at compile time */
|
||||
|
||||
#define BYTEEXTMASK (GEN_SUBCLASS(2) | GEN_SUBCLASS(3))
|
||||
#define DWORDEXTMASK (GEN_SUBCLASS(4) | GEN_SUBCLASS(5))
|
||||
|
||||
/* Register set sizes */
|
||||
#define RS2 GEN_REGSET(0)
|
||||
#define RS4 GEN_REGSET(1)
|
||||
#define RS8 GEN_REGSET(2)
|
||||
#define RS16 GEN_REGSET(3)
|
||||
#define RS32 GEN_REGSET(4)
|
||||
|
||||
#endif /* NASM_OPFLAGS_H */
|
||||
103
include/outelf.h
Normal file
103
include/outelf.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2019 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* Internal definitions common to outelf32 and outelf64
|
||||
*/
|
||||
#ifndef OUTPUT_OUTELF_H
|
||||
#define OUTPUT_OUTELF_H
|
||||
|
||||
#include "elf.h"
|
||||
#include "rbtree.h"
|
||||
#include "saa.h"
|
||||
|
||||
#define GLOBAL_TEMP_BASE 0x40000000 /* bigger than any sane symbol index */
|
||||
|
||||
/* alignment of sections in file */
|
||||
#define SEC_FILEALIGN 16
|
||||
|
||||
/* this stuff is needed for the dwarf/stabs debugging format */
|
||||
#define TY_DEBUGSYMLIN 0x40 /* internal call to debug_out */
|
||||
|
||||
/*
|
||||
* Debugging ELF sections (section indices starting with sec_debug)
|
||||
*/
|
||||
|
||||
/* stabs */
|
||||
#define sec_stab (sec_debug + 0)
|
||||
#define sec_stabstr (sec_debug + 1)
|
||||
#define sec_rel_stab (sec_debug + 2)
|
||||
|
||||
/* stabs symbol table format */
|
||||
struct stabentry {
|
||||
uint32_t n_strx;
|
||||
uint8_t n_type;
|
||||
uint8_t n_other;
|
||||
uint16_t n_desc;
|
||||
uint32_t n_value;
|
||||
};
|
||||
|
||||
/* dwarf */
|
||||
#define sec_debug_aranges (sec_debug + 0)
|
||||
#define sec_rela_debug_aranges (sec_debug + 1)
|
||||
#define sec_debug_pubnames (sec_debug + 2)
|
||||
#define sec_debug_info (sec_debug + 3)
|
||||
#define sec_rela_debug_info (sec_debug + 4)
|
||||
#define sec_debug_abbrev (sec_debug + 5)
|
||||
#define sec_debug_line (sec_debug + 6)
|
||||
#define sec_rela_debug_line (sec_debug + 7)
|
||||
#define sec_debug_frame (sec_debug + 8)
|
||||
#define sec_debug_loc (sec_debug + 9)
|
||||
|
||||
extern uint8_t elf_osabi;
|
||||
extern uint8_t elf_abiver;
|
||||
|
||||
#define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value) \
|
||||
do { \
|
||||
WRITELONG(p, n_strx); \
|
||||
WRITECHAR(p, n_type); \
|
||||
WRITECHAR(p, n_other); \
|
||||
WRITESHORT(p, n_desc); \
|
||||
WRITELONG(p, n_value); \
|
||||
} while (0)
|
||||
|
||||
struct elf_reloc {
|
||||
struct elf_reloc *next;
|
||||
int64_t address; /* relative to _start_ of section */
|
||||
int64_t symbol; /* symbol index */
|
||||
int64_t offset; /* symbol addend */
|
||||
int type; /* type of relocation */
|
||||
};
|
||||
|
||||
struct elf_symbol {
|
||||
struct rbtree symv; /* symbol value and symbol rbtree */
|
||||
int32_t strpos; /* string table position of name */
|
||||
int32_t section; /* section ID of the symbol */
|
||||
int type; /* symbol type */
|
||||
int other; /* symbol visibility */
|
||||
int32_t size; /* size of symbol */
|
||||
int32_t globnum; /* symbol table offset if global */
|
||||
struct elf_symbol *nextfwd; /* list of unresolved-size symbols */
|
||||
char *name; /* used temporarily if in above list */
|
||||
};
|
||||
|
||||
struct elf_section {
|
||||
struct SAA *data;
|
||||
uint64_t len;
|
||||
uint64_t size;
|
||||
uint64_t nrelocs;
|
||||
int32_t index; /* NASM index or NO_SEG if internal */
|
||||
int shndx; /* ELF index */
|
||||
int type; /* SHT_* */
|
||||
uint64_t align; /* alignment: power of two */
|
||||
uint64_t flags; /* section flags */
|
||||
int64_t pass_last_seen;
|
||||
uint64_t entsize; /* entry size */
|
||||
char *name;
|
||||
struct SAA *rel;
|
||||
struct elf_reloc *head;
|
||||
struct elf_reloc **tail;
|
||||
struct rbtree *gsyms; /* global symbols in section */
|
||||
};
|
||||
|
||||
#endif /* OUTPUT_OUTELF_H */
|
||||
344
include/outform.h
Normal file
344
include/outform.h
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2022 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* outform.h header file for binding output format drivers to the
|
||||
* remainder of the code in the Netwide Assembler
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header file allows configuration of which output formats
|
||||
* get compiled into the NASM binary. You can configure by defining
|
||||
* various preprocessor symbols beginning with "OF_", either on the
|
||||
* compiler command line or at the top of this file.
|
||||
*
|
||||
* OF_ONLY -- only include specified object formats
|
||||
* OF_name -- ensure that output format 'name' is included
|
||||
* OF_NO_name -- remove output format 'name'
|
||||
* OF_DOS -- ensure that 'obj', 'obj2', 'bin', 'win32' & 'win64' are included.
|
||||
* OF_UNIX -- ensure that 'aout', 'aoutb', 'coff', 'elf32' & 'elf64' are in.
|
||||
* OF_OTHERS -- ensure that 'bin', 'as86', 'rdf' 'macho32' & 'macho64' are in.
|
||||
* OF_ALL -- ensure that all formats are included.
|
||||
* note that this doesn't include 'dbg', which is
|
||||
* only really useful if you're doing development
|
||||
* work on NASM. Define OF_DBG if you want this.
|
||||
*
|
||||
* OF_DEFAULT=of_name -- ensure that 'name' is the default format.
|
||||
*
|
||||
* eg: -DOF_UNIX -DOF_ELF32 -DOF_DEFAULT=of_elf32 would be a suitable config
|
||||
* for an average linux system.
|
||||
*
|
||||
* Default config = -DOF_ALL -DOF_DEFAULT=of_bin
|
||||
*
|
||||
* You probably only want to set these options while compiling 'nasm.c'. */
|
||||
|
||||
#ifndef NASM_OUTFORM_H
|
||||
#define NASM_OUTFORM_H
|
||||
|
||||
#include "nasm.h"
|
||||
|
||||
/* -------------- USER MODIFIABLE PART ---------------- */
|
||||
|
||||
/*
|
||||
* Insert #defines here in accordance with the configuration
|
||||
* instructions above.
|
||||
*
|
||||
* E.g.
|
||||
*
|
||||
* #define OF_ONLY
|
||||
* #define OF_OBJ
|
||||
* #define OF_BIN
|
||||
*
|
||||
* for a 16-bit DOS assembler with no extraneous formats.
|
||||
*/
|
||||
|
||||
/* ------------ END USER MODIFIABLE PART -------------- */
|
||||
|
||||
/* ====configurable info begins here==== */
|
||||
/* formats configurable:
|
||||
* bin,obj,obj2,elf32,elf64,aout,aoutb,coff,win32,as86,rdf2,macho32,macho64 */
|
||||
|
||||
/* process options... */
|
||||
|
||||
#ifndef OF_ONLY
|
||||
#ifndef OF_ALL
|
||||
#define OF_ALL /* default is to have all formats */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef OF_ALL /* set all formats on... */
|
||||
#ifndef OF_BIN
|
||||
#define OF_BIN
|
||||
#endif
|
||||
#ifndef OF_OBJ
|
||||
#define OF_OBJ
|
||||
#endif
|
||||
#ifndef OF_OBJ2
|
||||
#define OF_OBJ2
|
||||
#endif
|
||||
#ifndef OF_ELF32
|
||||
#define OF_ELF32
|
||||
#endif
|
||||
#ifndef OF_ELFX32
|
||||
#define OF_ELFX32
|
||||
#endif
|
||||
#ifndef OF_ELF64
|
||||
#define OF_ELF64
|
||||
#endif
|
||||
#ifndef OF_COFF
|
||||
#define OF_COFF
|
||||
#endif
|
||||
#ifndef OF_AOUT
|
||||
#define OF_AOUT
|
||||
#endif
|
||||
#ifndef OF_AOUTB
|
||||
#define OF_AOUTB
|
||||
#endif
|
||||
#ifndef OF_WIN32
|
||||
#define OF_WIN32
|
||||
#endif
|
||||
#ifndef OF_WIN64
|
||||
#define OF_WIN64
|
||||
#endif
|
||||
#ifndef OF_AS86
|
||||
#define OF_AS86
|
||||
#endif
|
||||
#ifndef OF_IEEE
|
||||
#define OF_IEEE
|
||||
#endif
|
||||
#ifndef OF_MACHO32
|
||||
#define OF_MACHO32
|
||||
#endif
|
||||
#ifndef OF_MACHO64
|
||||
#define OF_MACHO64
|
||||
#endif
|
||||
#ifndef OF_DBG
|
||||
#define OF_DBG
|
||||
#endif
|
||||
#endif /* OF_ALL */
|
||||
|
||||
/* turn on groups of formats specified.... */
|
||||
#ifdef OF_DOS
|
||||
#ifndef OF_OBJ
|
||||
#define OF_OBJ
|
||||
#endif
|
||||
#ifndef OF_OBJ2
|
||||
#define OF_OBJ2
|
||||
#endif
|
||||
#ifndef OF_BIN
|
||||
#define OF_BIN
|
||||
#endif
|
||||
#ifndef OF_COFF
|
||||
#define OF_COFF /* COFF is used by DJGPP */
|
||||
#endif
|
||||
#ifndef OF_WIN32
|
||||
#define OF_WIN32
|
||||
#endif
|
||||
#ifndef OF_WIN64
|
||||
#define OF_WIN64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef OF_UNIX
|
||||
#ifndef OF_AOUT
|
||||
#define OF_AOUT
|
||||
#endif
|
||||
#ifndef OF_AOUTB
|
||||
#define OF_AOUTB
|
||||
#endif
|
||||
#ifndef OF_COFF
|
||||
#define OF_COFF
|
||||
#endif
|
||||
#ifndef OF_ELF32
|
||||
#define OF_ELF32
|
||||
#endif
|
||||
#ifndef OF_ELF64
|
||||
#define OF_ELF64
|
||||
#endif
|
||||
#ifndef OF_ELFX32
|
||||
#define OF_ELFX32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef OF_OTHERS
|
||||
#ifndef OF_BIN
|
||||
#define OF_BIN
|
||||
#endif
|
||||
#ifndef OF_AS86
|
||||
#define OF_AS86
|
||||
#endif
|
||||
#ifndef OF_IEEE
|
||||
#define OF_IEEE
|
||||
#endif
|
||||
#ifndef OF_MACHO32
|
||||
#define OF_MACHO32
|
||||
#endif
|
||||
#ifndef OF_MACHO64
|
||||
#define OF_MACHO64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* finally... override any format specifically specified to be off */
|
||||
#ifdef OF_NO_BIN
|
||||
#undef OF_BIN
|
||||
#endif
|
||||
#ifdef OF_NO_OBJ
|
||||
#undef OF_OBJ
|
||||
#endif
|
||||
#ifdef OF_NO_OBJ2
|
||||
#undef OF_OBJ2
|
||||
#endif
|
||||
#ifdef OF_NO_ELF32
|
||||
#undef OF_ELF32
|
||||
#endif
|
||||
#ifdef OF_NO_ELF64
|
||||
#undef OF_ELF64
|
||||
#endif
|
||||
#ifdef OF_NO_ELFX32
|
||||
#undef OF_ELFX32
|
||||
#endif
|
||||
#ifdef OF_NO_AOUT
|
||||
#undef OF_AOUT
|
||||
#endif
|
||||
#ifdef OF_NO_AOUTB
|
||||
#undef OF_AOUTB
|
||||
#endif
|
||||
#ifdef OF_NO_COFF
|
||||
#undef OF_COFF
|
||||
#endif
|
||||
#ifdef OF_NO_WIN32
|
||||
#undef OF_WIN32
|
||||
#endif
|
||||
#ifdef OF_NO_WIN64
|
||||
#undef OF_WIN64
|
||||
#endif
|
||||
#ifdef OF_NO_AS86
|
||||
#undef OF_AS86
|
||||
#endif
|
||||
#ifdef OF_NO_IEEE
|
||||
#undef OF_IEEE
|
||||
#endif
|
||||
#ifdef OF_NO_MACHO32
|
||||
#undef OF_MACHO32
|
||||
#endif
|
||||
#ifdef OF_NO_MACHO64
|
||||
#undef OF_MACHO64
|
||||
#endif
|
||||
#ifdef OF_NO_DBG
|
||||
#undef OF_DBG
|
||||
#endif
|
||||
|
||||
#ifndef OF_DEFAULT
|
||||
#define OF_DEFAULT of_bin
|
||||
#endif
|
||||
|
||||
extern const struct ofmt of_bin;
|
||||
extern const struct ofmt of_ith;
|
||||
extern const struct ofmt of_srec;
|
||||
extern const struct ofmt of_aout;
|
||||
extern const struct ofmt of_aoutb;
|
||||
extern const struct ofmt of_coff;
|
||||
extern const struct ofmt of_elf32;
|
||||
extern const struct ofmt of_elfx32;
|
||||
extern const struct ofmt of_elf64;
|
||||
extern const struct ofmt of_as86;
|
||||
extern const struct ofmt of_obj;
|
||||
extern const struct ofmt of_obj2;
|
||||
extern const struct ofmt of_win32;
|
||||
extern const struct ofmt of_win64;
|
||||
extern const struct ofmt of_ieee;
|
||||
extern const struct ofmt of_macho32;
|
||||
extern const struct ofmt of_macho64;
|
||||
extern const struct ofmt of_dbg;
|
||||
|
||||
#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */
|
||||
|
||||
/*
|
||||
* pull in the externs for the different formats, then make the
|
||||
* drivers array based on the above defines
|
||||
*/
|
||||
|
||||
static const struct ofmt * const drivers[] = {
|
||||
#ifdef OF_BIN
|
||||
&of_bin,
|
||||
&of_ith,
|
||||
&of_srec,
|
||||
#endif
|
||||
#ifdef OF_AOUT
|
||||
&of_aout,
|
||||
#endif
|
||||
#ifdef OF_AOUTB
|
||||
&of_aoutb,
|
||||
#endif
|
||||
#ifdef OF_COFF
|
||||
&of_coff,
|
||||
#endif
|
||||
#ifdef OF_ELF32
|
||||
&of_elf32,
|
||||
#endif
|
||||
#ifdef OF_ELF64
|
||||
&of_elf64,
|
||||
#endif
|
||||
#ifdef OF_ELFX32
|
||||
&of_elfx32,
|
||||
#endif
|
||||
#ifdef OF_AS86
|
||||
&of_as86,
|
||||
#endif
|
||||
#ifdef OF_OBJ
|
||||
&of_obj,
|
||||
#endif
|
||||
#ifdef OF_OBJ2
|
||||
&of_obj2,
|
||||
#endif
|
||||
#ifdef OF_WIN32
|
||||
&of_win32,
|
||||
#endif
|
||||
#ifdef OF_WIN64
|
||||
&of_win64,
|
||||
#endif
|
||||
#ifdef OF_IEEE
|
||||
&of_ieee,
|
||||
#endif
|
||||
#ifdef OF_MACHO32
|
||||
&of_macho32,
|
||||
#endif
|
||||
#ifdef OF_MACHO64
|
||||
&of_macho64,
|
||||
#endif
|
||||
#ifdef OF_DBG
|
||||
&of_dbg,
|
||||
#endif
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ofmt_alias ofmt_aliases[] = {
|
||||
#ifdef OF_ELF32
|
||||
{ "elf", &of_elf32 },
|
||||
#endif
|
||||
#ifdef OF_MACHO32
|
||||
{ "macho", &of_macho32 },
|
||||
#endif
|
||||
#ifdef OF_OBJ
|
||||
{ "omf", &of_obj },
|
||||
#endif
|
||||
#ifdef OF_OBJ2
|
||||
{ "omf2", &of_obj2 },
|
||||
{ "os2", &of_obj2 },
|
||||
#endif
|
||||
#ifdef OF_WIN32
|
||||
{ "win", &of_win32 },
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#endif /* BUILD_DRIVERS_ARRAY */
|
||||
|
||||
const struct ofmt *ofmt_find(const char *name, const struct ofmt_alias **ofmt_alias);
|
||||
const struct dfmt * pure_func dfmt_find(const struct ofmt *, const char *);
|
||||
void ofmt_list(const struct ofmt *, FILE *);
|
||||
void dfmt_list(FILE *);
|
||||
extern const struct dfmt null_debug_form;
|
||||
|
||||
#endif /* NASM_OUTFORM_H */
|
||||
292
include/outlib.h
Normal file
292
include/outlib.h
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_OUTLIB_H
|
||||
#define NASM_OUTLIB_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasm.h"
|
||||
#include "error.h"
|
||||
#include "hashtbl.h"
|
||||
#include "saa.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
uint64_t realsize(enum out_type type, uint64_t size);
|
||||
|
||||
/* Do-nothing versions of some output routines */
|
||||
enum directive_result
|
||||
null_directive(enum directive directive, char *value);
|
||||
void null_sectalign(int32_t seg, unsigned int value);
|
||||
void null_reset(void);
|
||||
int32_t null_segbase(int32_t seg);
|
||||
|
||||
/* Do-nothing versions of all the debug routines */
|
||||
void null_debug_init(void);
|
||||
void null_debug_linenum(const char *filename, int32_t linenumber,
|
||||
int32_t segto);
|
||||
void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
int is_global, char *special);
|
||||
void null_debug_directive(const char *directive, const char *params);
|
||||
void null_debug_typevalue(int32_t type);
|
||||
void null_debug_output(int type, void *param);
|
||||
void null_debug_cleanup(void);
|
||||
extern const struct dfmt * const null_debug_arr[2];
|
||||
|
||||
/*
|
||||
* This macro expands the legacy output information into separate
|
||||
* variables, to make gradual porting of backends easier.
|
||||
*/
|
||||
#define OUT_LEGACY(_out,_segto,_data,_type,_size,_segment,_wrt) \
|
||||
int32_t _segto = (_out)->loc.segment; \
|
||||
const void *_data = (_out)->legacy.data; \
|
||||
enum out_type _type = (_out)->legacy.type; \
|
||||
uint64_t _size = (_out)->legacy.size; \
|
||||
int32_t _segment = (_out)->legacy.tsegment; \
|
||||
int32_t _wrt = (_out)->legacy.twrt
|
||||
|
||||
/*
|
||||
* Common routines for tasks that really should migrate into the core.
|
||||
* This provides a common interface for maintaining sections and symbols,
|
||||
* and provide quick lookups as well as declared-order sequential walks.
|
||||
*
|
||||
* These structures are intended to be embedded at the *top* of a
|
||||
* backend-specific structure containing additional information.
|
||||
*
|
||||
* The tokens O_Section, O_Symbol and O_Reloc are intended to be
|
||||
* defined as macros by the backend before including this file!
|
||||
*/
|
||||
|
||||
struct ol_sect;
|
||||
struct ol_sym;
|
||||
|
||||
#ifndef O_Section
|
||||
typedef struct ol_sect O_Section;
|
||||
#endif
|
||||
#ifndef O_Symbol
|
||||
typedef struct ol_sym O_Symbol;
|
||||
#endif
|
||||
#ifndef O_Reloc
|
||||
typedef void * O_Reloc;
|
||||
#endif
|
||||
|
||||
/* Common section structure */
|
||||
|
||||
/*
|
||||
* Common flags for sections and symbols; low values reserved for
|
||||
* backend. Note that both ol_sect and ol_sym begin with a flags
|
||||
* field, so if a section pointer points to an external symbol instead
|
||||
* they can be trivially resolved.
|
||||
*/
|
||||
#define OF_SYMBOL 0x80000000
|
||||
#define OF_GLOBAL 0x40000000
|
||||
#define OF_IMPSEC 0x20000000
|
||||
#define OF_COMMON 0x10000000
|
||||
|
||||
struct ol_sym;
|
||||
|
||||
struct ol_symlist {
|
||||
struct ol_symlist *next;
|
||||
struct rbtree tree;
|
||||
};
|
||||
struct ol_symhead {
|
||||
struct ol_symlist *head, **tail;
|
||||
struct rbtree *tree;
|
||||
uint64_t n;
|
||||
};
|
||||
|
||||
struct ol_sect {
|
||||
uint32_t flags; /* Section/symbol flags */
|
||||
struct ol_sect *next; /* Next section in declared order */
|
||||
const char *name; /* Name of section */
|
||||
struct ol_symhead syml; /* All symbols in this section */
|
||||
struct ol_symhead symg; /* Global symbols in this section */
|
||||
struct SAA *data; /* Contents of section */
|
||||
struct SAA *reloc; /* Section relocations */
|
||||
uint32_t index; /* Primary section index */
|
||||
uint32_t subindex; /* Current subsection index */
|
||||
};
|
||||
|
||||
/* Segment reference */
|
||||
enum ol_seg_type {
|
||||
OS_NOSEG = 0, /* Plain number (no segment) */
|
||||
OS_SEGREF = 1, /* It is a segment reference */
|
||||
OS_ABS = 1, /* Absolute segment reference */
|
||||
OS_SECT = 2, /* It is a real section */
|
||||
OS_OFFS = OS_SECT, /* Offset reference in section */
|
||||
OS_SEG = OS_SECT|OS_SEGREF /* Section reference */
|
||||
};
|
||||
|
||||
union ol_segval {
|
||||
struct ol_sect *sect; /* Section structure */
|
||||
struct ol_sym *sym; /* External symbol structure */
|
||||
};
|
||||
|
||||
struct ol_seg {
|
||||
union ol_segval s;
|
||||
enum ol_seg_type t;
|
||||
|
||||
/*
|
||||
* For a section: subsection index
|
||||
* For a metasymbol: virtual segment index
|
||||
* For an absolute symbol: absolute value
|
||||
*/
|
||||
uint32_t index;
|
||||
};
|
||||
|
||||
/* seg:offs representing the full location value and type */
|
||||
struct ol_loc {
|
||||
int64_t offs;
|
||||
struct ol_seg seg;
|
||||
};
|
||||
|
||||
/* Common symbol structure */
|
||||
struct ol_sym {
|
||||
uint32_t flags; /* Section/symbol flags */
|
||||
uint32_t size; /* Size value (for backend) */
|
||||
struct ol_sym *next; /* Next symbol in declared order */
|
||||
const char *name; /* Symbol name */
|
||||
struct ol_symlist syml; /* Section-local symbol list */
|
||||
struct ol_symlist symg; /* Section-local global symbol list */
|
||||
struct ol_loc p; /* Symbol position ("where") */
|
||||
struct ol_loc v; /* Symbol value ("what") */
|
||||
};
|
||||
|
||||
/*
|
||||
* Operations
|
||||
*/
|
||||
void ol_init(void);
|
||||
void ol_cleanup(void);
|
||||
|
||||
/* Convert offs:seg to a location structure */
|
||||
extern void
|
||||
ol_mkloc(struct ol_loc *loc, int64_t offs, int32_t seg);
|
||||
|
||||
/* Get the section or external symbol from a struct ol_seg */
|
||||
static inline O_Section *seg_sect(struct ol_seg *seg)
|
||||
{
|
||||
return (O_Section *)seg->s.sect;
|
||||
}
|
||||
static inline O_Symbol *seg_xsym(struct ol_seg *seg)
|
||||
{
|
||||
return (O_Symbol *)seg->s.sym;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a pointer to the symbol structure if and only if a section is
|
||||
* really a symbol of some kind (extern, common...)
|
||||
*/
|
||||
static inline struct ol_sym *_seg_extsym(struct ol_sect *sect)
|
||||
{
|
||||
return (sect->flags & OF_SYMBOL) ? (struct ol_sym *)sect : NULL;
|
||||
}
|
||||
static inline O_Symbol *seg_extsym(O_Section *sect)
|
||||
{
|
||||
return (O_Symbol *)_seg_extsym((struct ol_sect *)sect);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a section or create a new section structure if it does not exist
|
||||
* and allocate it an index value via seg_alloc().
|
||||
*/
|
||||
extern struct ol_sect *
|
||||
_ol_get_sect(const char *name, size_t ssize, size_t rsize);
|
||||
static inline O_Section *ol_get_sect(const char *name)
|
||||
{
|
||||
return (O_Section *)_ol_get_sect(name, sizeof(O_Section), sizeof(O_Reloc));
|
||||
}
|
||||
|
||||
/* Find a section by name without creating one */
|
||||
extern struct ol_sect *_ol_sect_by_name(const char *);
|
||||
static inline O_Section *ol_sect_by_name(const char *name)
|
||||
{
|
||||
return (O_Section *)_ol_sect_by_name(name);
|
||||
}
|
||||
|
||||
/* Find a section or external symbol by index; NULL if not valid */
|
||||
extern struct ol_sect *_ol_sect_by_index(int32_t index);
|
||||
static inline O_Section *ol_sect_by_index(int32_t index)
|
||||
{
|
||||
return (O_Section *)_ol_sect_by_index(index);
|
||||
}
|
||||
|
||||
/* Global list of sections (not including external symbols) */
|
||||
extern struct ol_sect *_ol_sect_list;
|
||||
static inline O_Section *ol_sect_list(void)
|
||||
{
|
||||
return (O_Section *)_ol_sect_list;
|
||||
}
|
||||
|
||||
/* Count of sections (not including external symbols) */
|
||||
extern uint64_t _ol_nsects;
|
||||
static inline uint64_t ol_nsects(void)
|
||||
{
|
||||
return _ol_nsects;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start a new subsection for the given section. At the moment, once a
|
||||
* subsection has been created, it is not possible to revert to an
|
||||
* earlier subsection. ol_sect_by_index() will return the main section
|
||||
* structure. Returns the new section index. This is used to prevent
|
||||
* the front end from optimizing across subsection boundaries.
|
||||
*/
|
||||
extern int32_t _ol_new_subsection(struct ol_sect *sect);
|
||||
static inline int32_t ol_new_subsection(O_Section *sect)
|
||||
{
|
||||
return _ol_new_subsection((struct ol_sect *)sect);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new symbol. If this symbol is OS_OFFS, add it to the relevant
|
||||
* section, too. If the symbol already exists, return NULL; this is
|
||||
* different from ol_get_section() as a single section may be invoked
|
||||
* many times. On the contrary, the front end will prevent a single symbol
|
||||
* from being defined more than once.
|
||||
*
|
||||
* If flags has OF_GLOBAL set, add it to the global symbol hash for the
|
||||
* containing section. If flags has OF_IMPSEC set, allocate a segment
|
||||
* index for it via seg_alloc() and add it to the section by index list.
|
||||
*/
|
||||
extern struct ol_sym *_ol_new_sym(const char *name, const struct ol_loc *v,
|
||||
uint32_t flags, size_t size);
|
||||
static inline O_Symbol *ol_new_sym(const char *name, const struct ol_loc *v,
|
||||
uint32_t flags)
|
||||
{
|
||||
return (O_Symbol *)_ol_new_sym(name, v, flags, sizeof(O_Symbol));
|
||||
}
|
||||
|
||||
/* Find a symbol by name in the global namespace */
|
||||
extern struct ol_sym *_ol_sym_by_name(const char *name);
|
||||
static inline O_Symbol *ol_sym_by_name(const char *name)
|
||||
{
|
||||
return (O_Symbol *)_ol_sym_by_name(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a symbol by address in a specific section. If no symbol is defined
|
||||
* at that exact address, return the immediately previously defined one.
|
||||
* If global is set, then only return global symbols.
|
||||
*/
|
||||
extern struct ol_sym *_ol_sym_by_address(struct ol_sect *sect, int64_t addr,
|
||||
bool global);
|
||||
static inline O_Symbol *ol_sym_by_address(O_Section *sect, int64_t addr,
|
||||
bool global)
|
||||
{
|
||||
return (O_Symbol *)_ol_sym_by_address((struct ol_sect *)sect, addr, global);
|
||||
}
|
||||
|
||||
/* Global list of symbols */
|
||||
extern struct ol_sym *_ol_sym_list;
|
||||
static inline O_Symbol *ol_sym_list(void)
|
||||
{
|
||||
return (O_Symbol *)_ol_sym_list;
|
||||
}
|
||||
|
||||
/* Global count of symbols */
|
||||
extern uint64_t _ol_nsyms;
|
||||
static inline uint64_t ol_nsyms(void)
|
||||
{
|
||||
return _ol_nsyms;
|
||||
}
|
||||
|
||||
#endif /* NASM_OUTLIB_H */
|
||||
15
include/parser.h
Normal file
15
include/parser.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* parser.h header file for the parser module of the Netwide
|
||||
* Assembler
|
||||
*/
|
||||
|
||||
#ifndef NASM_PARSER_H
|
||||
#define NASM_PARSER_H
|
||||
|
||||
insn *parse_line(char *buffer, insn *result, const int bits);
|
||||
void cleanup_insn(insn *instruction);
|
||||
|
||||
#endif
|
||||
520
include/pecoff.h
Normal file
520
include/pecoff.h
Normal file
|
|
@ -0,0 +1,520 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef PECOFF_H
|
||||
#define PECOFF_H
|
||||
|
||||
/*
|
||||
* Microsoft Portable Executable and Common Object
|
||||
* File Format Specification
|
||||
*
|
||||
* Revision 8.1 – February 15, 2008
|
||||
*/
|
||||
|
||||
/*
|
||||
* Machine types
|
||||
*/
|
||||
#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
|
||||
#define IMAGE_FILE_MACHINE_AM33 0x01d3
|
||||
#define IMAGE_FILE_MACHINE_AMD64 0x8664
|
||||
#define IMAGE_FILE_MACHINE_EBC 0x0ebc
|
||||
#define IMAGE_FILE_MACHINE_M32R 0x9041
|
||||
#define IMAGE_FILE_MACHINE_ALPHA 0x0184
|
||||
#define IMAGE_FILE_MACHINE_ARM 0x01c0
|
||||
#define IMAGE_FILE_MACHINE_ALPHA64 0x0284
|
||||
#define IMAGE_FILE_MACHINE_I386 0x014c
|
||||
#define IMAGE_FILE_MACHINE_IA64 0x0200
|
||||
#define IMAGE_FILE_MACHINE_M68K 0x0268
|
||||
#define IMAGE_FILE_MACHINE_MIPS16 0x0266
|
||||
#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
|
||||
#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
|
||||
#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
|
||||
#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
|
||||
#define IMAGE_FILE_MACHINE_R3000 0x0162
|
||||
#define IMAGE_FILE_MACHINE_R4000 0x0166
|
||||
#define IMAGE_FILE_MACHINE_R10000 0x0168
|
||||
#define IMAGE_FILE_MACHINE_SH3 0x01a2
|
||||
#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
|
||||
#define IMAGE_FILE_MACHINE_SH4 0x01a6
|
||||
#define IMAGE_FILE_MACHINE_SH5 0x01a8
|
||||
#define IMAGE_FILE_MACHINE_THUMB 0x01c2
|
||||
#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
|
||||
#define IMAGE_FILE_MACHINE_MASK 0xffff
|
||||
|
||||
/*
|
||||
* Characteristics
|
||||
*/
|
||||
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
|
||||
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
|
||||
#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
|
||||
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
|
||||
#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
|
||||
#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
|
||||
#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
|
||||
#define IMAGE_FILE_32BIT_MACHINE 0x0100
|
||||
#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
|
||||
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
|
||||
#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
|
||||
#define IMAGE_FILE_SYSTEM 0x1000
|
||||
#define IMAGE_FILE_DLL 0x2000
|
||||
#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
|
||||
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
|
||||
|
||||
/*
|
||||
* Windows subsystem
|
||||
*/
|
||||
#define IMAGE_SUBSYSTEM_UNKNOWN 0
|
||||
#define IMAGE_SUBSYSTEM_NATIVE 1
|
||||
#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
|
||||
#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
|
||||
#define IMAGE_SUBSYSTEM_POSIX_CUI 7
|
||||
#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
|
||||
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
|
||||
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
|
||||
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
|
||||
#define IMAGE_SUBSYSTEM_EFI_ROM 13
|
||||
#define IMAGE_SUBSYSTEM_XBOX 14
|
||||
|
||||
/*
|
||||
* DLL characteristics
|
||||
*/
|
||||
#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
|
||||
#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
|
||||
#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
|
||||
#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
|
||||
#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
|
||||
#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
|
||||
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
|
||||
#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
|
||||
|
||||
/*
|
||||
* Section flags
|
||||
*/
|
||||
#define IMAGE_SCN_TYPE_REG 0x00000000
|
||||
#define IMAGE_SCN_TYPE_DSECT 0x00000001
|
||||
#define IMAGE_SCN_TYPE_NOLOAD 0x00000002
|
||||
#define IMAGE_SCN_TYPE_GROUP 0x00000004
|
||||
#define IMAGE_SCN_TYPE_NO_PAD 0x00000008
|
||||
#define IMAGE_SCN_TYPE_COPY 0x00000010
|
||||
|
||||
#define IMAGE_SCN_CNT_CODE 0x00000020
|
||||
#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
|
||||
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
|
||||
|
||||
#define IMAGE_SCN_LNK_OTHER 0x00000100
|
||||
#define IMAGE_SCN_LNK_INFO 0x00000200
|
||||
#define IMAGE_SCN_TYPE_OVER 0x00000400
|
||||
#define IMAGE_SCN_LNK_REMOVE 0x00000800
|
||||
#define IMAGE_SCN_LNK_COMDAT 0x00001000
|
||||
|
||||
#define IMAGE_SCN_MAX_RELOC 0xffff
|
||||
|
||||
#define IMAGE_SCN_MEM_FARDATA 0x00008000
|
||||
#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
|
||||
#define IMAGE_SCN_MEM_16BIT 0x00020000
|
||||
#define IMAGE_SCN_MEM_LOCKED 0x00040000
|
||||
#define IMAGE_SCN_MEM_PRELOAD 0x00080000
|
||||
|
||||
#define IMAGE_SCN_ALIGN_1BYTES 0x00100000
|
||||
#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
|
||||
#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
|
||||
#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
|
||||
#define IMAGE_SCN_ALIGN_16BYTES 0x00500000
|
||||
#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
|
||||
#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
|
||||
#define IMAGE_SCN_ALIGN_128BYTES 0x00800000
|
||||
#define IMAGE_SCN_ALIGN_256BYTES 0x00900000
|
||||
#define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
|
||||
#define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
|
||||
#define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
|
||||
#define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
|
||||
#define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
|
||||
#define IMAGE_SCN_ALIGN_MASK 0x00f00000
|
||||
|
||||
#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
|
||||
#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
|
||||
#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000
|
||||
#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000
|
||||
#define IMAGE_SCN_MEM_SHARED 0x10000000
|
||||
#define IMAGE_SCN_MEM_EXECUTE 0x20000000
|
||||
#define IMAGE_SCN_MEM_READ 0x40000000
|
||||
#define IMAGE_SCN_MEM_WRITE 0x80000000
|
||||
|
||||
/*
|
||||
* Relocation type x86-64
|
||||
*/
|
||||
#define IMAGE_REL_AMD64_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_AMD64_ADDR64 0x0001
|
||||
#define IMAGE_REL_AMD64_ADDR32 0x0002
|
||||
#define IMAGE_REL_AMD64_ADDR32NB 0x0003
|
||||
#define IMAGE_REL_AMD64_REL32 0x0004
|
||||
#define IMAGE_REL_AMD64_REL32_1 0x0005
|
||||
#define IMAGE_REL_AMD64_REL32_2 0x0006
|
||||
#define IMAGE_REL_AMD64_REL32_3 0x0007
|
||||
#define IMAGE_REL_AMD64_REL32_4 0x0008
|
||||
#define IMAGE_REL_AMD64_REL32_5 0x0009
|
||||
#define IMAGE_REL_AMD64_SECTION 0x000a
|
||||
#define IMAGE_REL_AMD64_SECREL 0x000b
|
||||
#define IMAGE_REL_AMD64_SECREL7 0x000c
|
||||
#define IMAGE_REL_AMD64_TOKEN 0x000d
|
||||
#define IMAGE_REL_AMD64_SREL32 0x000e
|
||||
#define IMAGE_REL_AMD64_PAIR 0x000f
|
||||
#define IMAGE_REL_AMD64_SSPAN32 0x0010
|
||||
|
||||
/*
|
||||
* Relocation types i386
|
||||
*/
|
||||
#define IMAGE_REL_I386_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_I386_DIR16 0x0001
|
||||
#define IMAGE_REL_I386_REL16 0x0002
|
||||
#define IMAGE_REL_I386_DIR32 0x0006
|
||||
#define IMAGE_REL_I386_DIR32NB 0x0007
|
||||
#define IMAGE_REL_I386_SEG12 0x0009
|
||||
#define IMAGE_REL_I386_SECTION 0x000a
|
||||
#define IMAGE_REL_I386_SECREL 0x000b
|
||||
#define IMAGE_REL_I386_TOKEN 0x000c
|
||||
#define IMAGE_REL_I386_SECREL7 0x000d
|
||||
#define IMAGE_REL_I386_REL32 0x0014
|
||||
|
||||
/*
|
||||
* Relocation types ARM
|
||||
*/
|
||||
#define IMAGE_REL_ARM_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_ARM_ADDR32 0x0001
|
||||
#define IMAGE_REL_ARM_ADDR32NB 0x0002
|
||||
#define IMAGE_REL_ARM_BRANCH24 0x0003
|
||||
#define IMAGE_REL_ARM_BRANCH11 0x0004
|
||||
#define IMAGE_REL_ARM_SECTION 0x000e
|
||||
#define IMAGE_REL_ARM_SECREL 0x000f
|
||||
|
||||
/*
|
||||
* Relocation types Hitachi SuperH
|
||||
*/
|
||||
#define IMAGE_REL_SH3_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_SH3_DIRECT16 0x0001
|
||||
#define IMAGE_REL_SH3_DIRECT32 0x0002
|
||||
#define IMAGE_REL_SH3_DIRECT8 0x0003
|
||||
#define IMAGE_REL_SH3_DIRECT8_WORD 0x0004
|
||||
#define IMAGE_REL_SH3_DIRECT8_LONG 0x0005
|
||||
#define IMAGE_REL_SH3_DIRECT4 0x0006
|
||||
#define IMAGE_REL_SH3_DIRECT4_WORD 0x0007
|
||||
#define IMAGE_REL_SH3_DIRECT4_LONG 0x0008
|
||||
#define IMAGE_REL_SH3_PCREL8_WORD 0x0009
|
||||
#define IMAGE_REL_SH3_PCREL8_LONG 0x000a
|
||||
#define IMAGE_REL_SH3_PCREL12_WORD 0x000b
|
||||
#define IMAGE_REL_SH3_STARTOF_SECTION 0x000c
|
||||
#define IMAGE_REL_SH3_SIZEOF_SECTION 0x000d
|
||||
#define IMAGE_REL_SH3_SECTION 0x000e
|
||||
#define IMAGE_REL_SH3_SECREL 0x000f
|
||||
#define IMAGE_REL_SH3_DIRECT32_NB 0x0010
|
||||
#define IMAGE_REL_SH3_GPREL4_LONG 0x0011
|
||||
#define IMAGE_REL_SH3_TOKEN 0x0012
|
||||
#define IMAGE_REL_SHM_PCRELPT 0x0013
|
||||
#define IMAGE_REL_SHM_REFLO 0x0014
|
||||
#define IMAGE_REL_SHM_REFHALF 0x0015
|
||||
#define IMAGE_REL_SHM_RELLO 0x0016
|
||||
#define IMAGE_REL_SHM_RELHALF 0x0017
|
||||
#define IMAGE_REL_SHM_PAIR 0x0018
|
||||
#define IMAGE_REL_SHM_NOMODE 0x8000
|
||||
|
||||
/*
|
||||
* Relocation types IBM PowerPC processors
|
||||
*/
|
||||
#define IMAGE_REL_PPC_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_PPC_ADDR64 0x0001
|
||||
#define IMAGE_REL_PPC_ADDR32 0x0002
|
||||
#define IMAGE_REL_PPC_ADDR24 0x0003
|
||||
#define IMAGE_REL_PPC_ADDR16 0x0004
|
||||
#define IMAGE_REL_PPC_ADDR14 0x0005
|
||||
#define IMAGE_REL_PPC_REL24 0x0006
|
||||
#define IMAGE_REL_PPC_REL14 0x0007
|
||||
#define IMAGE_REL_PPC_ADDR32NB 0x000a
|
||||
#define IMAGE_REL_PPC_SECREL 0x000b
|
||||
#define IMAGE_REL_PPC_SECTION 0x000c
|
||||
#define IMAGE_REL_PPC_SECREL16 0x000f
|
||||
#define IMAGE_REL_PPC_REFHI 0x0010
|
||||
#define IMAGE_REL_PPC_REFLO 0x0011
|
||||
#define IMAGE_REL_PPC_PAIR 0x0012
|
||||
#define IMAGE_REL_PPC_SECRELLO 0x0013
|
||||
#define IMAGE_REL_PPC_GPREL 0x0015
|
||||
#define IMAGE_REL_PPC_TOKEN 0x0016
|
||||
|
||||
/*
|
||||
* Relocation types Intel Itanium processor family (IPF)
|
||||
*/
|
||||
#define IMAGE_REL_IA64_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_IA64_IMM14 0x0001
|
||||
#define IMAGE_REL_IA64_IMM22 0x0002
|
||||
#define IMAGE_REL_IA64_IMM64 0x0003
|
||||
#define IMAGE_REL_IA64_DIR32 0x0004
|
||||
#define IMAGE_REL_IA64_DIR64 0x0005
|
||||
#define IMAGE_REL_IA64_PCREL21B 0x0006
|
||||
#define IMAGE_REL_IA64_PCREL21M 0x0007
|
||||
#define IMAGE_REL_IA64_PCREL21F 0x0008
|
||||
#define IMAGE_REL_IA64_GPREL22 0x0009
|
||||
#define IMAGE_REL_IA64_LTOFF22 0x000a
|
||||
#define IMAGE_REL_IA64_SECTION 0x000b
|
||||
#define IMAGE_REL_IA64_SECREL22 0x000c
|
||||
#define IMAGE_REL_IA64_SECREL64I 0x000d
|
||||
#define IMAGE_REL_IA64_SECREL32 0x000e
|
||||
#define IMAGE_REL_IA64_DIR32NB 0x0010
|
||||
#define IMAGE_REL_IA64_SREL14 0x0011
|
||||
#define IMAGE_REL_IA64_SREL22 0x0012
|
||||
#define IMAGE_REL_IA64_SREL32 0x0013
|
||||
#define IMAGE_REL_IA64_UREL32 0x0014
|
||||
#define IMAGE_REL_IA64_PCREL60X 0x0015
|
||||
#define IMAGE_REL_IA64_PCREL 60B 0x0016
|
||||
#define IMAGE_REL_IA64_PCREL60F 0x0017
|
||||
#define IMAGE_REL_IA64_PCREL60I 0x0018
|
||||
#define IMAGE_REL_IA64_PCREL60M 0x0019
|
||||
#define IMAGE_REL_IA64_IMMGPREL64 0x001a
|
||||
#define IMAGE_REL_IA64_TOKEN 0x001b
|
||||
#define IMAGE_REL_IA64_GPREL32 0x001c
|
||||
#define IMAGE_REL_IA64_ADDEND 0x001f
|
||||
|
||||
/*
|
||||
* Relocation types MIPS Processors
|
||||
*/
|
||||
#define IMAGE_REL_MIPS_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_MIPS_REFHALF 0x0001
|
||||
#define IMAGE_REL_MIPS_REFWORD 0x0002
|
||||
#define IMAGE_REL_MIPS_JMPADDR 0x0003
|
||||
#define IMAGE_REL_MIPS_REFHI 0x0004
|
||||
#define IMAGE_REL_MIPS_REFLO 0x0005
|
||||
#define IMAGE_REL_MIPS_GPREL 0x0006
|
||||
#define IMAGE_REL_MIPS_LITERAL 0x0007
|
||||
#define IMAGE_REL_MIPS_SECTION 0x000a
|
||||
#define IMAGE_REL_MIPS_SECREL 0x000b
|
||||
#define IMAGE_REL_MIPS_SECRELLO 0x000c
|
||||
#define IMAGE_REL_MIPS_SECRELHI 0x000d
|
||||
#define IMAGE_REL_MIPS_JMPADDR16 0x0010
|
||||
#define IMAGE_REL_MIPS_REFWORDNB 0x0022
|
||||
#define IMAGE_REL_MIPS_PAIR 0x0025
|
||||
|
||||
/*
|
||||
* Relocation types Mitsubishi M32R
|
||||
*/
|
||||
#define IMAGE_REL_M32R_ABSOLUTE 0x0000
|
||||
#define IMAGE_REL_M32R_ADDR32 0x0001
|
||||
#define IMAGE_REL_M32R_ADDR32NB 0x0002
|
||||
#define IMAGE_REL_M32R_ADDR24 0x0003
|
||||
#define IMAGE_REL_M32R_GPREL16 0x0004
|
||||
#define IMAGE_REL_M32R_PCREL24 0x0005
|
||||
#define IMAGE_REL_M32R_PCREL16 0x0006
|
||||
#define IMAGE_REL_M32R_PCREL8 0x0007
|
||||
#define IMAGE_REL_M32R_REFHALF 0x0008
|
||||
#define IMAGE_REL_M32R_REFHI 0x0009
|
||||
#define IMAGE_REL_M32R_REFLO 0x000a
|
||||
#define IMAGE_REL_M32R_PAIR 0x000b
|
||||
#define IMAGE_REL_M32R_SECTION 0x000c
|
||||
#define IMAGE_REL_M32R_SECREL 0x000d
|
||||
#define IMAGE_REL_M32R_TOKEN 0x000e
|
||||
|
||||
/*
|
||||
* Section number values
|
||||
*/
|
||||
#define IMAGE_SYM_UNDEFINED 0
|
||||
#define IMAGE_SYM_ABSOLUTE -1
|
||||
#define IMAGE_SYM_DEBUG -2
|
||||
|
||||
/*
|
||||
* Type representation
|
||||
*/
|
||||
#define IMAGE_SYM_TYPE_NULL 0
|
||||
#define IMAGE_SYM_TYPE_VOID 1
|
||||
#define IMAGE_SYM_TYPE_CHAR 2
|
||||
#define IMAGE_SYM_TYPE_SHORT 3
|
||||
#define IMAGE_SYM_TYPE_INT 4
|
||||
#define IMAGE_SYM_TYPE_LONG 5
|
||||
#define IMAGE_SYM_TYPE_FLOAT 6
|
||||
#define IMAGE_SYM_TYPE_DOUBLE 7
|
||||
#define IMAGE_SYM_TYPE_STRUCT 8
|
||||
#define IMAGE_SYM_TYPE_UNION 9
|
||||
#define IMAGE_SYM_TYPE_ENUM 10
|
||||
#define IMAGE_SYM_TYPE_MOE 11
|
||||
#define IMAGE_SYM_TYPE_BYTE 12
|
||||
#define IMAGE_SYM_TYPE_WORD 13
|
||||
#define IMAGE_SYM_TYPE_UINT 14
|
||||
#define IMAGE_SYM_TYPE_DWORD 15
|
||||
|
||||
#define IMAGE_SYM_DTYPE_NULL 0
|
||||
#define IMAGE_SYM_DTYPE_POINTER 1
|
||||
#define IMAGE_SYM_DTYPE_FUNCTION 2
|
||||
#define IMAGE_SYM_DTYPE_ARRAY 3
|
||||
|
||||
/*
|
||||
* Storage class
|
||||
*/
|
||||
#define IMAGE_SYM_CLASS_END_OF_FUNCTION -1
|
||||
#define IMAGE_SYM_CLASS_NULL 0
|
||||
#define IMAGE_SYM_CLASS_AUTOMATIC 1
|
||||
#define IMAGE_SYM_CLASS_EXTERNAL 2
|
||||
#define IMAGE_SYM_CLASS_STATIC 3
|
||||
#define IMAGE_SYM_CLAS S_REGISTER 4
|
||||
#define IMAGE_SYM_CLASS_EXTERNAL_DEF 5
|
||||
#define IMAGE_SYM_CLASS_LABEL 6
|
||||
#define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
|
||||
#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
|
||||
#define IMAGE_SYM_CLASS_ARGUMENT 9
|
||||
#define IMAGE_SYM_CLASS_STRUCT_TAG 10
|
||||
#define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
|
||||
#define IMAGE_SYM_CLASS_UNION_TAG 12
|
||||
#define IMAGE_SYM_CLASS_TYPE_DEFINITION 13
|
||||
#define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
|
||||
#define IMAGE_SYM_CLASS_ENUM_TAG 15
|
||||
#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
|
||||
#define IMAGE_SYM_CLASS_REGISTER_PARAM 17
|
||||
#define IMAGE_SYM_CLASS_BIT_FIELD 18
|
||||
#define IMAGE_SYM_CLASS_BLOCK 100
|
||||
#define IMAGE_SYM_CLASS_FUNCTION 101
|
||||
#define IMAGE_SYM_CLASS_END_OF_STRUCT 102
|
||||
#define IMAGE_SYM_CLASS_FILE 103
|
||||
#define IMAGE_SYM_CLASS_SECTION 104
|
||||
#define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
|
||||
#define IMAGE_SYM_CLASS_CLR_TOKEN 107
|
||||
|
||||
/*
|
||||
* COMDAT sections
|
||||
*/
|
||||
#define IMAGE_COMDAT_SELECT_NODUPLICATES 1
|
||||
#define IMAGE_COMDAT_SELECT_ANY 2
|
||||
#define IMAGE_COMDAT_SELECT_SAME_SIZE 3
|
||||
#define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
|
||||
#define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
|
||||
#define IMAGE_COMDAT_SELECT_LARGEST 6
|
||||
|
||||
/*
|
||||
* Attribute certificate table
|
||||
*/
|
||||
#define WIN_CERT_REVISION_1_0 0x0100
|
||||
#define WIN_CERT_REVISION_2_0 0x0200
|
||||
#define WIN_CERT_TYPE_X509 0x0001
|
||||
#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
|
||||
#define WIN_CERT_TYPE_RESERVED_1 0x0003
|
||||
#define WIN_CERT_TYPE_TS_STACK_SIGNED 0x0004
|
||||
|
||||
/*
|
||||
* Debug type
|
||||
*/
|
||||
#define IMAGE_DEBUG_TYPE_UNKNOWN 0
|
||||
#define IMAGE_DEBUG_TYPE_COFF 1
|
||||
#define IMAGE_DEBUG_TYPE_CODEVIEW 2
|
||||
#define IMAGE_DEBUG_TYPE_FPO 3
|
||||
#define IMAGE_DEBUG_TYPE_MISC 4
|
||||
#define IMAGE_DEBUG_TYPE_EXCEPTION 5
|
||||
#define IMAGE_DEBUG_TYPE_FIXUP 6
|
||||
#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
|
||||
#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
|
||||
#define IMAGE_DEBUG_TYP E_BORLAND 9
|
||||
#define IMAGE_DEBUG_TYPE_RESERVED10 10
|
||||
#define IMAGE_DEBUG_TYPE_CLSID 11
|
||||
|
||||
/*
|
||||
* Base relocation types
|
||||
*/
|
||||
#define IMAGE_REL_BASED_ABSOLUTE 0
|
||||
#define IMAGE_REL_BASED_HIGH 1
|
||||
#define IMAGE_REL_BASED_LOW 2
|
||||
#define IMAGE_REL_BASED_HIGHLOW 3
|
||||
#define IMAGE_REL_BASED_HIGHADJ 4
|
||||
#define IMAGE_REL_BASED_MIPS_JMPADDR 5
|
||||
#define IMAGE_REL_BASED_MIPS_JMPADDR16 9
|
||||
#define IMAGE_REL_BASED_DIR64 10
|
||||
|
||||
/*
|
||||
* TLS callback functions
|
||||
*/
|
||||
#define DLL_PROCESS_ATTACH 1
|
||||
#define DLL_THREAD_ATTACH 2
|
||||
#define DLL_THREAD_DETACH 3
|
||||
#define DLL_PROCESS_DETACH 0
|
||||
|
||||
/*
|
||||
* Import Type
|
||||
*/
|
||||
#define IMPORT_CODE 0
|
||||
#define IMPORT_DATA 1
|
||||
#define IMPORT_CONST 2
|
||||
|
||||
/*
|
||||
* Import name type
|
||||
*/
|
||||
#define IMPORT_ORDINAL 0
|
||||
#define IMPORT_NAME 1
|
||||
#define IMPORT_NAME_NOPREFIX 2
|
||||
#define IMPORT_NAME_UNDECORATE 3
|
||||
|
||||
struct coff_Section {
|
||||
struct SAA *data;
|
||||
uint32_t len;
|
||||
int nrelocs;
|
||||
int32_t index;
|
||||
struct coff_Reloc *head, **tail;
|
||||
uint32_t flags; /* section flags */
|
||||
uint32_t align_flags; /* user-specified alignment flags */
|
||||
uint32_t sectalign_flags; /* minimum alignment from sectalign */
|
||||
char *name;
|
||||
int32_t namepos; /* Offset of name into the strings table */
|
||||
int32_t pos, relpos;
|
||||
int64_t pass_last_seen;
|
||||
struct coff_SymIdxReloc *symidx_reloc_head;
|
||||
|
||||
/* comdat-related members */
|
||||
char *comdat_name;
|
||||
uint32_t checksum; /* set only for comdat sections */
|
||||
int8_t comdat_selection;
|
||||
int8_t comdat_symbol; /* is the "comdat name" in symbol table? */
|
||||
int32_t comdat_associated; /* associated section for selection==5 */
|
||||
};
|
||||
|
||||
struct coff_Reloc {
|
||||
struct coff_Reloc *next;
|
||||
int32_t address; /* relative to _start_ of section */
|
||||
int32_t symbol; /* symbol number */
|
||||
enum {
|
||||
SECT_SYMBOLS,
|
||||
ABS_SYMBOL,
|
||||
REAL_SYMBOLS
|
||||
} symbase; /* relocation for symbol number :) */
|
||||
int16_t type;
|
||||
};
|
||||
|
||||
struct coff_SymIdxReloc {
|
||||
struct coff_SymIdxReloc *next;
|
||||
uint32_t symbol; /* symbol number */
|
||||
uint32_t offset; /* byte offset into the secetion. */
|
||||
uint32_t size; /* the size of the area to fix up */
|
||||
};
|
||||
|
||||
struct coff_Symbol {
|
||||
char name[9];
|
||||
int32_t strpos; /* string table position of name */
|
||||
int32_t value; /* address, or COMMON variable size */
|
||||
int section; /* section number where it's defined
|
||||
* - in COFF codes, not NASM codes */
|
||||
bool is_global; /* is it a global symbol or not? */
|
||||
int16_t type; /* 0 - notype, 0x20 - function */
|
||||
int32_t namlen; /* full name length */
|
||||
};
|
||||
|
||||
struct coff_DebugInfo {
|
||||
int32_t segto;
|
||||
int32_t seg;
|
||||
uint64_t size;
|
||||
struct coff_Section *section;
|
||||
};
|
||||
|
||||
extern struct coff_Section **coff_sects;
|
||||
extern int coff_nsects;
|
||||
extern struct SAA *coff_syms;
|
||||
extern uint32_t coff_nsyms;
|
||||
extern struct SAA *coff_strs;
|
||||
extern bool win32, win64;
|
||||
|
||||
extern char coff_infile[FILENAME_MAX];
|
||||
extern char coff_outfile[FILENAME_MAX];
|
||||
|
||||
extern int coff_make_section(char *name, uint32_t flags);
|
||||
|
||||
|
||||
#endif /* PECOFF_H */
|
||||
22
include/perfhash.h
Normal file
22
include/perfhash.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef PERFHASH_H
|
||||
#define PERFHASH_H 1
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h" /* For invalid_enum_str() */
|
||||
|
||||
struct perfect_hash {
|
||||
uint64_t crcinit;
|
||||
uint32_t hashmask;
|
||||
uint32_t tbllen;
|
||||
int tbloffs;
|
||||
int errval;
|
||||
const int16_t *hashvals;
|
||||
const char * const *strings;
|
||||
};
|
||||
|
||||
int pure_func perfhash_find(const struct perfect_hash *, const char *);
|
||||
|
||||
#endif /* PERFHASH_H */
|
||||
330
include/pptok.h
Normal file
330
include/pptok.h
Normal file
|
|
@ -0,0 +1,330 @@
|
|||
/* Automatically generated from ./asm/pptok.dat by ./asm/pptok.pl */
|
||||
/* Do not edit */
|
||||
|
||||
enum preproc_token {
|
||||
PP_IF = 0,
|
||||
PP_IF_BOGUS = 1,
|
||||
PP_IFCTX = 2,
|
||||
PP_IFDEF = 3,
|
||||
PP_IFDEFALIAS = 4,
|
||||
PP_IFDIFI = 5,
|
||||
PP_IFDIRECTIVE = 6,
|
||||
PP_IFEMPTY = 7,
|
||||
PP_IFENV = 8,
|
||||
PP_IFFILE = 9,
|
||||
PP_IFID = 10,
|
||||
PP_IFIDN = 11,
|
||||
PP_IFIDNI = 12,
|
||||
PP_IFMACRO = 13,
|
||||
PP_IFNUM = 14,
|
||||
PP_IFSTR = 15,
|
||||
PP_IFTOKEN = 16,
|
||||
PP_IFUSABLE = 17,
|
||||
PP_IFUSING = 18,
|
||||
PP_IF_COND_19 = 19,
|
||||
PP_IF_COND_20 = 20,
|
||||
PP_IF_COND_21 = 21,
|
||||
PP_IF_COND_22 = 22,
|
||||
PP_IF_COND_23 = 23,
|
||||
PP_IF_COND_24 = 24,
|
||||
PP_IF_COND_25 = 25,
|
||||
PP_IF_COND_26 = 26,
|
||||
PP_IF_COND_27 = 27,
|
||||
PP_IF_COND_28 = 28,
|
||||
PP_IF_COND_29 = 29,
|
||||
PP_IF_COND_30 = 30,
|
||||
PP_IF_COND_31 = 31,
|
||||
PP_IFN = 32,
|
||||
PP_IFN_BOGUS = 33,
|
||||
PP_IFNCTX = 34,
|
||||
PP_IFNDEF = 35,
|
||||
PP_IFNDEFALIAS = 36,
|
||||
PP_IFNDIFI = 37,
|
||||
PP_IFNDIRECTIVE = 38,
|
||||
PP_IFNEMPTY = 39,
|
||||
PP_IFNENV = 40,
|
||||
PP_IFNFILE = 41,
|
||||
PP_IFNID = 42,
|
||||
PP_IFNIDN = 43,
|
||||
PP_IFNIDNI = 44,
|
||||
PP_IFNMACRO = 45,
|
||||
PP_IFNNUM = 46,
|
||||
PP_IFNSTR = 47,
|
||||
PP_IFNTOKEN = 48,
|
||||
PP_IFNUSABLE = 49,
|
||||
PP_IFNUSING = 50,
|
||||
PP_IFN_COND_19 = 51,
|
||||
PP_IFN_COND_20 = 52,
|
||||
PP_IFN_COND_21 = 53,
|
||||
PP_IFN_COND_22 = 54,
|
||||
PP_IFN_COND_23 = 55,
|
||||
PP_IFN_COND_24 = 56,
|
||||
PP_IFN_COND_25 = 57,
|
||||
PP_IFN_COND_26 = 58,
|
||||
PP_IFN_COND_27 = 59,
|
||||
PP_IFN_COND_28 = 60,
|
||||
PP_IFN_COND_29 = 61,
|
||||
PP_IFN_COND_30 = 62,
|
||||
PP_IFN_COND_31 = 63,
|
||||
PP_ELIF = 64,
|
||||
PP_ELIF_BOGUS = 65,
|
||||
PP_ELIFCTX = 66,
|
||||
PP_ELIFDEF = 67,
|
||||
PP_ELIFDEFALIAS = 68,
|
||||
PP_ELIFDIFI = 69,
|
||||
PP_ELIFDIRECTIVE = 70,
|
||||
PP_ELIFEMPTY = 71,
|
||||
PP_ELIFENV = 72,
|
||||
PP_ELIFFILE = 73,
|
||||
PP_ELIFID = 74,
|
||||
PP_ELIFIDN = 75,
|
||||
PP_ELIFIDNI = 76,
|
||||
PP_ELIFMACRO = 77,
|
||||
PP_ELIFNUM = 78,
|
||||
PP_ELIFSTR = 79,
|
||||
PP_ELIFTOKEN = 80,
|
||||
PP_ELIFUSABLE = 81,
|
||||
PP_ELIFUSING = 82,
|
||||
PP_ELIF_COND_19 = 83,
|
||||
PP_ELIF_COND_20 = 84,
|
||||
PP_ELIF_COND_21 = 85,
|
||||
PP_ELIF_COND_22 = 86,
|
||||
PP_ELIF_COND_23 = 87,
|
||||
PP_ELIF_COND_24 = 88,
|
||||
PP_ELIF_COND_25 = 89,
|
||||
PP_ELIF_COND_26 = 90,
|
||||
PP_ELIF_COND_27 = 91,
|
||||
PP_ELIF_COND_28 = 92,
|
||||
PP_ELIF_COND_29 = 93,
|
||||
PP_ELIF_COND_30 = 94,
|
||||
PP_ELIF_COND_31 = 95,
|
||||
PP_ELIFN = 96,
|
||||
PP_ELIFN_BOGUS = 97,
|
||||
PP_ELIFNCTX = 98,
|
||||
PP_ELIFNDEF = 99,
|
||||
PP_ELIFNDEFALIAS = 100,
|
||||
PP_ELIFNDIFI = 101,
|
||||
PP_ELIFNDIRECTIVE = 102,
|
||||
PP_ELIFNEMPTY = 103,
|
||||
PP_ELIFNENV = 104,
|
||||
PP_ELIFNFILE = 105,
|
||||
PP_ELIFNID = 106,
|
||||
PP_ELIFNIDN = 107,
|
||||
PP_ELIFNIDNI = 108,
|
||||
PP_ELIFNMACRO = 109,
|
||||
PP_ELIFNNUM = 110,
|
||||
PP_ELIFNSTR = 111,
|
||||
PP_ELIFNTOKEN = 112,
|
||||
PP_ELIFNUSABLE = 113,
|
||||
PP_ELIFNUSING = 114,
|
||||
PP_ELIFN_COND_19 = 115,
|
||||
PP_ELIFN_COND_20 = 116,
|
||||
PP_ELIFN_COND_21 = 117,
|
||||
PP_ELIFN_COND_22 = 118,
|
||||
PP_ELIFN_COND_23 = 119,
|
||||
PP_ELIFN_COND_24 = 120,
|
||||
PP_ELIFN_COND_25 = 121,
|
||||
PP_ELIFN_COND_26 = 122,
|
||||
PP_ELIFN_COND_27 = 123,
|
||||
PP_ELIFN_COND_28 = 124,
|
||||
PP_ELIFN_COND_29 = 125,
|
||||
PP_ELIFN_COND_30 = 126,
|
||||
PP_ELIFN_COND_31 = 127,
|
||||
PP_ALIASES = 128,
|
||||
PP_ARG = 129,
|
||||
PP_CLEAR = 130,
|
||||
PP_DEPEND = 131,
|
||||
PP_ELSE = 132,
|
||||
PP_ENDIF = 133,
|
||||
PP_ENDM = 134,
|
||||
PP_ENDMACRO = 135,
|
||||
PP_ENDREP = 136,
|
||||
PP_ERROR = 137,
|
||||
PP_EXITMACRO = 138,
|
||||
PP_EXITREP = 139,
|
||||
PP_FATAL = 140,
|
||||
PP_INCLUDE = 141,
|
||||
PP_LINE = 142,
|
||||
PP_LOCAL = 143,
|
||||
PP_NOTE = 144,
|
||||
PP_NULL = 145,
|
||||
PP_POP = 146,
|
||||
PP_PRAGMA = 147,
|
||||
PP_PUSH = 148,
|
||||
PP_REP = 149,
|
||||
PP_REPL = 150,
|
||||
PP_REQUIRE = 151,
|
||||
PP_ROTATE = 152,
|
||||
PP_STACKSIZE = 153,
|
||||
PP_UNDEF = 154,
|
||||
PP_UNDEFALIAS = 155,
|
||||
PP_USE = 156,
|
||||
PP_WARNING = 157,
|
||||
PP_ASSIGN = 158,
|
||||
PP_IASSIGN = 159,
|
||||
PP_DEFALIAS = 160,
|
||||
PP_IDEFALIAS = 161,
|
||||
PP_DEFINE = 162,
|
||||
PP_IDEFINE = 163,
|
||||
PP_DEFSTR = 164,
|
||||
PP_IDEFSTR = 165,
|
||||
PP_DEFTOK = 166,
|
||||
PP_IDEFTOK = 167,
|
||||
PP_MACRO = 168,
|
||||
PP_IMACRO = 169,
|
||||
PP_PATHSEARCH = 170,
|
||||
PP_IPATHSEARCH = 171,
|
||||
PP_RMACRO = 172,
|
||||
PP_IRMACRO = 173,
|
||||
PP_STRCAT = 174,
|
||||
PP_ISTRCAT = 175,
|
||||
PP_STRLEN = 176,
|
||||
PP_ISTRLEN = 177,
|
||||
PP_SUBSTR = 178,
|
||||
PP_ISUBSTR = 179,
|
||||
PP_XDEFINE = 180,
|
||||
PP_IXDEFINE = 181,
|
||||
PP_UNMACRO = 182,
|
||||
PP_UNIMACRO = 183,
|
||||
PP_count = 184,
|
||||
PP_invalid = -1
|
||||
};
|
||||
|
||||
#define PP_COND(x) ((x) & 0x1f)
|
||||
#define PP_IS_COND(x) ((unsigned int)(x) < PP_ALIASES)
|
||||
#define PP_COND_NEGATIVE(x) (!!((x) & 0x20))
|
||||
|
||||
#define PP_HAS_CASE(x) ((x) >= PP_ASSIGN)
|
||||
#define PP_INSENSITIVE(x) ((x) & 1)
|
||||
#define PP_TOKLEN_MAX 15
|
||||
|
||||
#define CASE_PP_IF \
|
||||
case PP_IF:\
|
||||
case PP_IF_BOGUS:\
|
||||
case PP_IFCTX:\
|
||||
case PP_IFDEF:\
|
||||
case PP_IFDEFALIAS:\
|
||||
case PP_IFDIFI:\
|
||||
case PP_IFDIRECTIVE:\
|
||||
case PP_IFEMPTY:\
|
||||
case PP_IFENV:\
|
||||
case PP_IFFILE:\
|
||||
case PP_IFID:\
|
||||
case PP_IFIDN:\
|
||||
case PP_IFIDNI:\
|
||||
case PP_IFMACRO:\
|
||||
case PP_IFNUM:\
|
||||
case PP_IFSTR:\
|
||||
case PP_IFTOKEN:\
|
||||
case PP_IFUSABLE:\
|
||||
case PP_IFUSING:\
|
||||
case PP_IF_COND_19:\
|
||||
case PP_IF_COND_20:\
|
||||
case PP_IF_COND_21:\
|
||||
case PP_IF_COND_22:\
|
||||
case PP_IF_COND_23:\
|
||||
case PP_IF_COND_24:\
|
||||
case PP_IF_COND_25:\
|
||||
case PP_IF_COND_26:\
|
||||
case PP_IF_COND_27:\
|
||||
case PP_IF_COND_28:\
|
||||
case PP_IF_COND_29:\
|
||||
case PP_IF_COND_30:\
|
||||
case PP_IF_COND_31:\
|
||||
case PP_IFN:\
|
||||
case PP_IFN_BOGUS:\
|
||||
case PP_IFNCTX:\
|
||||
case PP_IFNDEF:\
|
||||
case PP_IFNDEFALIAS:\
|
||||
case PP_IFNDIFI:\
|
||||
case PP_IFNDIRECTIVE:\
|
||||
case PP_IFNEMPTY:\
|
||||
case PP_IFNENV:\
|
||||
case PP_IFNFILE:\
|
||||
case PP_IFNID:\
|
||||
case PP_IFNIDN:\
|
||||
case PP_IFNIDNI:\
|
||||
case PP_IFNMACRO:\
|
||||
case PP_IFNNUM:\
|
||||
case PP_IFNSTR:\
|
||||
case PP_IFNTOKEN:\
|
||||
case PP_IFNUSABLE:\
|
||||
case PP_IFNUSING:\
|
||||
case PP_IFN_COND_19:\
|
||||
case PP_IFN_COND_20:\
|
||||
case PP_IFN_COND_21:\
|
||||
case PP_IFN_COND_22:\
|
||||
case PP_IFN_COND_23:\
|
||||
case PP_IFN_COND_24:\
|
||||
case PP_IFN_COND_25:\
|
||||
case PP_IFN_COND_26:\
|
||||
case PP_IFN_COND_27:\
|
||||
case PP_IFN_COND_28:\
|
||||
case PP_IFN_COND_29:\
|
||||
case PP_IFN_COND_30:\
|
||||
case PP_IFN_COND_31
|
||||
#define CASE_PP_ELIF \
|
||||
case PP_ELIF:\
|
||||
case PP_ELIF_BOGUS:\
|
||||
case PP_ELIFCTX:\
|
||||
case PP_ELIFDEF:\
|
||||
case PP_ELIFDEFALIAS:\
|
||||
case PP_ELIFDIFI:\
|
||||
case PP_ELIFDIRECTIVE:\
|
||||
case PP_ELIFEMPTY:\
|
||||
case PP_ELIFENV:\
|
||||
case PP_ELIFFILE:\
|
||||
case PP_ELIFID:\
|
||||
case PP_ELIFIDN:\
|
||||
case PP_ELIFIDNI:\
|
||||
case PP_ELIFMACRO:\
|
||||
case PP_ELIFNUM:\
|
||||
case PP_ELIFSTR:\
|
||||
case PP_ELIFTOKEN:\
|
||||
case PP_ELIFUSABLE:\
|
||||
case PP_ELIFUSING:\
|
||||
case PP_ELIF_COND_19:\
|
||||
case PP_ELIF_COND_20:\
|
||||
case PP_ELIF_COND_21:\
|
||||
case PP_ELIF_COND_22:\
|
||||
case PP_ELIF_COND_23:\
|
||||
case PP_ELIF_COND_24:\
|
||||
case PP_ELIF_COND_25:\
|
||||
case PP_ELIF_COND_26:\
|
||||
case PP_ELIF_COND_27:\
|
||||
case PP_ELIF_COND_28:\
|
||||
case PP_ELIF_COND_29:\
|
||||
case PP_ELIF_COND_30:\
|
||||
case PP_ELIF_COND_31:\
|
||||
case PP_ELIFN:\
|
||||
case PP_ELIFN_BOGUS:\
|
||||
case PP_ELIFNCTX:\
|
||||
case PP_ELIFNDEF:\
|
||||
case PP_ELIFNDEFALIAS:\
|
||||
case PP_ELIFNDIFI:\
|
||||
case PP_ELIFNDIRECTIVE:\
|
||||
case PP_ELIFNEMPTY:\
|
||||
case PP_ELIFNENV:\
|
||||
case PP_ELIFNFILE:\
|
||||
case PP_ELIFNID:\
|
||||
case PP_ELIFNIDN:\
|
||||
case PP_ELIFNIDNI:\
|
||||
case PP_ELIFNMACRO:\
|
||||
case PP_ELIFNNUM:\
|
||||
case PP_ELIFNSTR:\
|
||||
case PP_ELIFNTOKEN:\
|
||||
case PP_ELIFNUSABLE:\
|
||||
case PP_ELIFNUSING:\
|
||||
case PP_ELIFN_COND_19:\
|
||||
case PP_ELIFN_COND_20:\
|
||||
case PP_ELIFN_COND_21:\
|
||||
case PP_ELIFN_COND_22:\
|
||||
case PP_ELIFN_COND_23:\
|
||||
case PP_ELIFN_COND_24:\
|
||||
case PP_ELIFN_COND_25:\
|
||||
case PP_ELIFN_COND_26:\
|
||||
case PP_ELIFN_COND_27:\
|
||||
case PP_ELIFN_COND_28:\
|
||||
case PP_ELIFN_COND_29:\
|
||||
case PP_ELIFN_COND_30:\
|
||||
case PP_ELIFN_COND_31
|
||||
23
include/preproc.h
Normal file
23
include/preproc.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* preproc.h header file for preproc.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_PREPROC_H
|
||||
#define NASM_PREPROC_H
|
||||
|
||||
#include "nasmlib.h"
|
||||
#include "pptok.h"
|
||||
|
||||
extern const char * const pp_directives[];
|
||||
extern const uint8_t pp_directives_len[];
|
||||
|
||||
enum preproc_token pp_token_hash(const char *token);
|
||||
enum preproc_token pp_tasm_token_hash(const char *token);
|
||||
|
||||
/* Opens an include file or input file. This uses the include path. */
|
||||
FILE *pp_input_fopen(const char *filename, enum file_flags mode);
|
||||
|
||||
#endif
|
||||
30
include/quote.h
Normal file
30
include/quote.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_QUOTE_H
|
||||
#define NASM_QUOTE_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
char *nasm_quote(const char *str, size_t *len);
|
||||
char *nasm_quote_cstr(const char *str, size_t *len);
|
||||
size_t nasm_unquote_anystr(char *str, char **endptr,
|
||||
uint32_t badctl, char qstart);
|
||||
size_t nasm_unquote(char *str, char **endptr);
|
||||
size_t nasm_unquote_cstr(char *str, char **endptr);
|
||||
char *nasm_skip_string(const char *str);
|
||||
|
||||
/* Arguments used with nasm_quote_anystr() */
|
||||
|
||||
/*
|
||||
* These are the only control characters when we produce a C string:
|
||||
* BEL BS TAB ESC
|
||||
*/
|
||||
#define OKCTL ((1U << '\a') | (1U << '\b') | (1U << '\t') | (1U << 27))
|
||||
#define BADCTL (~(uint32_t)OKCTL)
|
||||
|
||||
/* Initial quotation mark */
|
||||
#define STR_C '\"'
|
||||
#define STR_NASM '`'
|
||||
|
||||
#endif /* NASM_QUOTE_H */
|
||||
19
include/raa.h
Normal file
19
include/raa.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_RAA_H
|
||||
#define NASM_RAA_H 1
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
struct RAA;
|
||||
typedef uint64_t raaindex;
|
||||
|
||||
#define raa_init() NULL
|
||||
void raa_free(struct RAA *);
|
||||
int64_t pure_func raa_read(struct RAA *, raaindex);
|
||||
void * pure_func raa_read_ptr(struct RAA *, raaindex);
|
||||
struct RAA * never_null raa_write(struct RAA *r, raaindex posn, int64_t value);
|
||||
struct RAA * never_null raa_write_ptr(struct RAA *r, raaindex posn, void *value);
|
||||
|
||||
#endif /* NASM_RAA_H */
|
||||
78
include/rbtree.h
Normal file
78
include/rbtree.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_RBTREE_H
|
||||
#define NASM_RBTREE_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*
|
||||
* This structure should be embedded in a larger data structure;
|
||||
* the final output from rb_search() can then be converted back
|
||||
* to the larger data structure via container_of().
|
||||
*
|
||||
* An empty tree is simply represented by a NULL pointer.
|
||||
*/
|
||||
|
||||
/* Note: the values of these flags is significant */
|
||||
enum rbtree_node_flags {
|
||||
RBTREE_NODE_BLACK = 1, /* Node color is black */
|
||||
RBTREE_NODE_PRED = 2, /* Left pointer is an uplink */
|
||||
RBTREE_NODE_SUCC = 4 /* Right pointer is an uplink */
|
||||
};
|
||||
|
||||
struct rbtree {
|
||||
uint64_t key;
|
||||
struct rbtree_metadata {
|
||||
struct rbtree *left, *right;
|
||||
enum rbtree_node_flags flags;
|
||||
} m;
|
||||
};
|
||||
|
||||
/*
|
||||
* Add a node to a tree. Returns the new root pointer.
|
||||
* The key value in the structure needs to be preinitialized;
|
||||
* the rest of the structure should be zero.
|
||||
*/
|
||||
struct rbtree *rb_insert(struct rbtree *, struct rbtree *);
|
||||
|
||||
/*
|
||||
* Find a node in the tree corresponding to the key immediately
|
||||
* <= the passed-in key value.
|
||||
*/
|
||||
struct rbtree * pure_func rb_search(const struct rbtree *, uint64_t);
|
||||
|
||||
/*
|
||||
* Find a node in the tree exactly matching the key value.
|
||||
*/
|
||||
struct rbtree * pure_func rb_search_exact(const struct rbtree *, uint64_t);
|
||||
|
||||
/*
|
||||
* Return the immediately previous or next node in key order.
|
||||
* Returns NULL if this node is the end of the tree.
|
||||
* These operations are safe for complete (but not partial!)
|
||||
* tree walk-with-destruction in key order.
|
||||
*/
|
||||
struct rbtree * pure_func rb_prev(const struct rbtree *);
|
||||
struct rbtree * pure_func rb_next(const struct rbtree *);
|
||||
|
||||
/*
|
||||
* Return the very first or very last node in key order.
|
||||
*/
|
||||
struct rbtree * pure_func rb_first(const struct rbtree *);
|
||||
struct rbtree * pure_func rb_last(const struct rbtree *);
|
||||
|
||||
/*
|
||||
* Left and right nodes, if real. These operations are
|
||||
* safe for tree destruction, but not for splitting a tree.
|
||||
*/
|
||||
static inline struct rbtree *rb_left(const struct rbtree *rb)
|
||||
{
|
||||
return (rb->m.flags & RBTREE_NODE_PRED) ? NULL : rb->m.left;
|
||||
}
|
||||
static inline struct rbtree *rb_right(const struct rbtree *rb)
|
||||
{
|
||||
return (rb->m.flags & RBTREE_NODE_SUCC) ? NULL : rb->m.right;
|
||||
}
|
||||
|
||||
#endif /* NASM_RBTREE_H */
|
||||
139
include/rdoff.h
Normal file
139
include/rdoff.h
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* rdoff.h RDOFF Object File manipulation routines header file
|
||||
*/
|
||||
|
||||
#ifndef RDOFF_H
|
||||
#define RDOFF_H 1
|
||||
|
||||
/*
|
||||
* RDOFF definitions. They are used by RDOFF utilities and by NASM's
|
||||
* 'outrdf2.c' output module.
|
||||
*/
|
||||
|
||||
/* RDOFF format revision (currently used only when printing the version) */
|
||||
#define RDOFF2_REVISION "0.6.1"
|
||||
|
||||
/* RDOFF2 file signature */
|
||||
#define RDOFF2_SIGNATURE "RDOFF2"
|
||||
|
||||
/* Maximum size of an import/export label (including trailing zero) */
|
||||
#define EXIM_LABEL_MAX 256
|
||||
|
||||
/* Maximum size of library or module name (including trailing zero) */
|
||||
#define MODLIB_NAME_MAX 128
|
||||
|
||||
/* Maximum number of segments that we can handle in one file */
|
||||
#define RDF_MAXSEGS 64
|
||||
|
||||
/* Record types that may present the RDOFF header */
|
||||
#define RDFREC_GENERIC 0
|
||||
#define RDFREC_RELOC 1
|
||||
#define RDFREC_IMPORT 2
|
||||
#define RDFREC_GLOBAL 3
|
||||
#define RDFREC_DLL 4
|
||||
#define RDFREC_BSS 5
|
||||
#define RDFREC_SEGRELOC 6
|
||||
#define RDFREC_FARIMPORT 7
|
||||
#define RDFREC_MODNAME 8
|
||||
#define RDFREC_COMMON 10
|
||||
|
||||
/*
|
||||
* Generic record - contains the type and length field, plus a 128 byte
|
||||
* array 'data'
|
||||
*/
|
||||
struct GenericRec {
|
||||
uint8_t type;
|
||||
uint8_t reclen;
|
||||
char data[128];
|
||||
};
|
||||
|
||||
/*
|
||||
* Relocation record
|
||||
*/
|
||||
struct RelocRec {
|
||||
uint8_t type; /* must be 1 */
|
||||
uint8_t reclen; /* content length */
|
||||
uint8_t segment; /* only 0 for code, or 1 for data supported,
|
||||
but add 64 for relative refs (ie do not require
|
||||
reloc @ loadtime, only linkage) */
|
||||
int32_t offset; /* from start of segment in which reference is loc'd */
|
||||
uint8_t length; /* 1 2 or 4 bytes */
|
||||
uint16_t refseg; /* segment to which reference refers to */
|
||||
};
|
||||
|
||||
/*
|
||||
* Extern/import record
|
||||
*/
|
||||
struct ImportRec {
|
||||
uint8_t type; /* must be 2 */
|
||||
uint8_t reclen; /* content length */
|
||||
uint8_t flags; /* SYM_* flags (see below) */
|
||||
uint16_t segment; /* segment number allocated to the label for reloc
|
||||
records - label is assumed to be at offset zero
|
||||
in this segment, so linker must fix up with offset
|
||||
of segment and of offset within segment */
|
||||
char label[EXIM_LABEL_MAX]; /* zero terminated, should be written to file
|
||||
until the zero, but not after it */
|
||||
};
|
||||
|
||||
/*
|
||||
* Public/export record
|
||||
*/
|
||||
struct ExportRec {
|
||||
uint8_t type; /* must be 3 */
|
||||
uint8_t reclen; /* content length */
|
||||
uint8_t flags; /* SYM_* flags (see below) */
|
||||
uint8_t segment; /* segment referred to (0/1/2) */
|
||||
int32_t offset; /* offset within segment */
|
||||
char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
|
||||
};
|
||||
|
||||
/*
|
||||
* DLL record
|
||||
*/
|
||||
struct DLLRec {
|
||||
uint8_t type; /* must be 4 */
|
||||
uint8_t reclen; /* content length */
|
||||
char libname[MODLIB_NAME_MAX]; /* name of library to link with at load time */
|
||||
};
|
||||
|
||||
/*
|
||||
* BSS record
|
||||
*/
|
||||
struct BSSRec {
|
||||
uint8_t type; /* must be 5 */
|
||||
uint8_t reclen; /* content length */
|
||||
int32_t amount; /* number of bytes BSS to reserve */
|
||||
};
|
||||
|
||||
/*
|
||||
* Module name record
|
||||
*/
|
||||
struct ModRec {
|
||||
uint8_t type; /* must be 8 */
|
||||
uint8_t reclen; /* content length */
|
||||
char modname[MODLIB_NAME_MAX]; /* module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* Common variable record
|
||||
*/
|
||||
struct CommonRec {
|
||||
uint8_t type; /* must be 10 */
|
||||
uint8_t reclen; /* equals 7+label length */
|
||||
uint16_t segment; /* segment number */
|
||||
int32_t size; /* size of common variable */
|
||||
uint16_t align; /* alignment (power of two) */
|
||||
char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
|
||||
};
|
||||
|
||||
/* Flags for ExportRec */
|
||||
#define SYM_DATA 1
|
||||
#define SYM_FUNCTION 2
|
||||
#define SYM_GLOBAL 4
|
||||
#define SYM_IMPORT 8
|
||||
|
||||
#endif /* RDOFF_H */
|
||||
28
include/regdis.h
Normal file
28
include/regdis.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* automatically generated from ./x86/regs.dat - do not edit */
|
||||
|
||||
#ifndef NASM_REGDIS_H
|
||||
#define NASM_REGDIS_H
|
||||
|
||||
#include "regs.h"
|
||||
|
||||
#define DISREGTBLSZ 32
|
||||
|
||||
extern const enum reg_enum nasm_rd_bndreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_creg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_dreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_fpureg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_mmxreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_opmaskreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_reg16[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_reg32[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_reg64[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_reg8[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_reg8_rex[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_sreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_tmmreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_treg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_xmmreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_ymmreg[DISREGTBLSZ];
|
||||
extern const enum reg_enum nasm_rd_zmmreg[DISREGTBLSZ];
|
||||
|
||||
#endif /* NASM_REGDIS_H */
|
||||
706
include/regs.h
Normal file
706
include/regs.h
Normal file
|
|
@ -0,0 +1,706 @@
|
|||
/* automatically generated from ./x86/regs.dat - do not edit */
|
||||
|
||||
#ifndef NASM_REGS_H
|
||||
#define NASM_REGS_H
|
||||
|
||||
#define EXPR_REG_START 1
|
||||
|
||||
enum reg_enum {
|
||||
R_zero = 0,
|
||||
R_none = -1,
|
||||
R_AH = EXPR_REG_START,
|
||||
R_AL,
|
||||
R_AX,
|
||||
R_BH,
|
||||
R_BL,
|
||||
R_BND0,
|
||||
R_BND1,
|
||||
R_BND2,
|
||||
R_BND3,
|
||||
R_BP,
|
||||
R_BPL,
|
||||
R_BX,
|
||||
R_CH,
|
||||
R_CL,
|
||||
R_CR0,
|
||||
R_CR1,
|
||||
R_CR10,
|
||||
R_CR11,
|
||||
R_CR12,
|
||||
R_CR13,
|
||||
R_CR14,
|
||||
R_CR15,
|
||||
R_CR16,
|
||||
R_CR17,
|
||||
R_CR18,
|
||||
R_CR19,
|
||||
R_CR2,
|
||||
R_CR20,
|
||||
R_CR21,
|
||||
R_CR22,
|
||||
R_CR23,
|
||||
R_CR24,
|
||||
R_CR25,
|
||||
R_CR26,
|
||||
R_CR27,
|
||||
R_CR28,
|
||||
R_CR29,
|
||||
R_CR3,
|
||||
R_CR30,
|
||||
R_CR31,
|
||||
R_CR4,
|
||||
R_CR5,
|
||||
R_CR6,
|
||||
R_CR7,
|
||||
R_CR8,
|
||||
R_CR9,
|
||||
R_CS,
|
||||
R_CX,
|
||||
R_DH,
|
||||
R_DI,
|
||||
R_DIL,
|
||||
R_DL,
|
||||
R_DR0,
|
||||
R_DR1,
|
||||
R_DR10,
|
||||
R_DR11,
|
||||
R_DR12,
|
||||
R_DR13,
|
||||
R_DR14,
|
||||
R_DR15,
|
||||
R_DR16,
|
||||
R_DR17,
|
||||
R_DR18,
|
||||
R_DR19,
|
||||
R_DR2,
|
||||
R_DR20,
|
||||
R_DR21,
|
||||
R_DR22,
|
||||
R_DR23,
|
||||
R_DR24,
|
||||
R_DR25,
|
||||
R_DR26,
|
||||
R_DR27,
|
||||
R_DR28,
|
||||
R_DR29,
|
||||
R_DR3,
|
||||
R_DR30,
|
||||
R_DR31,
|
||||
R_DR4,
|
||||
R_DR5,
|
||||
R_DR6,
|
||||
R_DR7,
|
||||
R_DR8,
|
||||
R_DR9,
|
||||
R_DS,
|
||||
R_DX,
|
||||
R_EAX,
|
||||
R_EBP,
|
||||
R_EBX,
|
||||
R_ECX,
|
||||
R_EDI,
|
||||
R_EDX,
|
||||
R_ES,
|
||||
R_ESI,
|
||||
R_ESP,
|
||||
R_FS,
|
||||
R_GS,
|
||||
R_K0,
|
||||
R_K1,
|
||||
R_K2,
|
||||
R_K3,
|
||||
R_K4,
|
||||
R_K5,
|
||||
R_K6,
|
||||
R_K7,
|
||||
R_MM0,
|
||||
R_MM1,
|
||||
R_MM2,
|
||||
R_MM3,
|
||||
R_MM4,
|
||||
R_MM5,
|
||||
R_MM6,
|
||||
R_MM7,
|
||||
R_R10,
|
||||
R_R10B,
|
||||
R_R10D,
|
||||
R_R10W,
|
||||
R_R11,
|
||||
R_R11B,
|
||||
R_R11D,
|
||||
R_R11W,
|
||||
R_R12,
|
||||
R_R12B,
|
||||
R_R12D,
|
||||
R_R12W,
|
||||
R_R13,
|
||||
R_R13B,
|
||||
R_R13D,
|
||||
R_R13W,
|
||||
R_R14,
|
||||
R_R14B,
|
||||
R_R14D,
|
||||
R_R14W,
|
||||
R_R15,
|
||||
R_R15B,
|
||||
R_R15D,
|
||||
R_R15W,
|
||||
R_R16,
|
||||
R_R16B,
|
||||
R_R16D,
|
||||
R_R16W,
|
||||
R_R17,
|
||||
R_R17B,
|
||||
R_R17D,
|
||||
R_R17W,
|
||||
R_R18,
|
||||
R_R18B,
|
||||
R_R18D,
|
||||
R_R18W,
|
||||
R_R19,
|
||||
R_R19B,
|
||||
R_R19D,
|
||||
R_R19W,
|
||||
R_R20,
|
||||
R_R20B,
|
||||
R_R20D,
|
||||
R_R20W,
|
||||
R_R21,
|
||||
R_R21B,
|
||||
R_R21D,
|
||||
R_R21W,
|
||||
R_R22,
|
||||
R_R22B,
|
||||
R_R22D,
|
||||
R_R22W,
|
||||
R_R23,
|
||||
R_R23B,
|
||||
R_R23D,
|
||||
R_R23W,
|
||||
R_R24,
|
||||
R_R24B,
|
||||
R_R24D,
|
||||
R_R24W,
|
||||
R_R25,
|
||||
R_R25B,
|
||||
R_R25D,
|
||||
R_R25W,
|
||||
R_R26,
|
||||
R_R26B,
|
||||
R_R26D,
|
||||
R_R26W,
|
||||
R_R27,
|
||||
R_R27B,
|
||||
R_R27D,
|
||||
R_R27W,
|
||||
R_R28,
|
||||
R_R28B,
|
||||
R_R28D,
|
||||
R_R28W,
|
||||
R_R29,
|
||||
R_R29B,
|
||||
R_R29D,
|
||||
R_R29W,
|
||||
R_R30,
|
||||
R_R30B,
|
||||
R_R30D,
|
||||
R_R30W,
|
||||
R_R31,
|
||||
R_R31B,
|
||||
R_R31D,
|
||||
R_R31W,
|
||||
R_R8,
|
||||
R_R8B,
|
||||
R_R8D,
|
||||
R_R8W,
|
||||
R_R9,
|
||||
R_R9B,
|
||||
R_R9D,
|
||||
R_R9W,
|
||||
R_RAX,
|
||||
R_RBP,
|
||||
R_RBX,
|
||||
R_RCX,
|
||||
R_RDI,
|
||||
R_RDX,
|
||||
R_RSI,
|
||||
R_RSP,
|
||||
R_SEGR6,
|
||||
R_SEGR7,
|
||||
R_SI,
|
||||
R_SIL,
|
||||
R_SP,
|
||||
R_SPL,
|
||||
R_SS,
|
||||
R_ST0,
|
||||
R_ST1,
|
||||
R_ST2,
|
||||
R_ST3,
|
||||
R_ST4,
|
||||
R_ST5,
|
||||
R_ST6,
|
||||
R_ST7,
|
||||
R_TMM0,
|
||||
R_TMM1,
|
||||
R_TMM2,
|
||||
R_TMM3,
|
||||
R_TMM4,
|
||||
R_TMM5,
|
||||
R_TMM6,
|
||||
R_TMM7,
|
||||
R_TR0,
|
||||
R_TR1,
|
||||
R_TR2,
|
||||
R_TR3,
|
||||
R_TR4,
|
||||
R_TR5,
|
||||
R_TR6,
|
||||
R_TR7,
|
||||
R_XMM0,
|
||||
R_XMM1,
|
||||
R_XMM10,
|
||||
R_XMM11,
|
||||
R_XMM12,
|
||||
R_XMM13,
|
||||
R_XMM14,
|
||||
R_XMM15,
|
||||
R_XMM16,
|
||||
R_XMM17,
|
||||
R_XMM18,
|
||||
R_XMM19,
|
||||
R_XMM2,
|
||||
R_XMM20,
|
||||
R_XMM21,
|
||||
R_XMM22,
|
||||
R_XMM23,
|
||||
R_XMM24,
|
||||
R_XMM25,
|
||||
R_XMM26,
|
||||
R_XMM27,
|
||||
R_XMM28,
|
||||
R_XMM29,
|
||||
R_XMM3,
|
||||
R_XMM30,
|
||||
R_XMM31,
|
||||
R_XMM4,
|
||||
R_XMM5,
|
||||
R_XMM6,
|
||||
R_XMM7,
|
||||
R_XMM8,
|
||||
R_XMM9,
|
||||
R_YMM0,
|
||||
R_YMM1,
|
||||
R_YMM10,
|
||||
R_YMM11,
|
||||
R_YMM12,
|
||||
R_YMM13,
|
||||
R_YMM14,
|
||||
R_YMM15,
|
||||
R_YMM16,
|
||||
R_YMM17,
|
||||
R_YMM18,
|
||||
R_YMM19,
|
||||
R_YMM2,
|
||||
R_YMM20,
|
||||
R_YMM21,
|
||||
R_YMM22,
|
||||
R_YMM23,
|
||||
R_YMM24,
|
||||
R_YMM25,
|
||||
R_YMM26,
|
||||
R_YMM27,
|
||||
R_YMM28,
|
||||
R_YMM29,
|
||||
R_YMM3,
|
||||
R_YMM30,
|
||||
R_YMM31,
|
||||
R_YMM4,
|
||||
R_YMM5,
|
||||
R_YMM6,
|
||||
R_YMM7,
|
||||
R_YMM8,
|
||||
R_YMM9,
|
||||
R_ZMM0,
|
||||
R_ZMM1,
|
||||
R_ZMM10,
|
||||
R_ZMM11,
|
||||
R_ZMM12,
|
||||
R_ZMM13,
|
||||
R_ZMM14,
|
||||
R_ZMM15,
|
||||
R_ZMM16,
|
||||
R_ZMM17,
|
||||
R_ZMM18,
|
||||
R_ZMM19,
|
||||
R_ZMM2,
|
||||
R_ZMM20,
|
||||
R_ZMM21,
|
||||
R_ZMM22,
|
||||
R_ZMM23,
|
||||
R_ZMM24,
|
||||
R_ZMM25,
|
||||
R_ZMM26,
|
||||
R_ZMM27,
|
||||
R_ZMM28,
|
||||
R_ZMM29,
|
||||
R_ZMM3,
|
||||
R_ZMM30,
|
||||
R_ZMM31,
|
||||
R_ZMM4,
|
||||
R_ZMM5,
|
||||
R_ZMM6,
|
||||
R_ZMM7,
|
||||
R_ZMM8,
|
||||
R_ZMM9,
|
||||
REG_ENUM_LIMIT
|
||||
};
|
||||
|
||||
#define EXPR_REG_END 344
|
||||
|
||||
#define REG_NUM_AH 4
|
||||
#define REG_NUM_AL 0
|
||||
#define REG_NUM_AX 0
|
||||
#define REG_NUM_BH 7
|
||||
#define REG_NUM_BL 3
|
||||
#define REG_NUM_BND0 0
|
||||
#define REG_NUM_BND1 1
|
||||
#define REG_NUM_BND2 2
|
||||
#define REG_NUM_BND3 3
|
||||
#define REG_NUM_BP 5
|
||||
#define REG_NUM_BPL 5
|
||||
#define REG_NUM_BX 3
|
||||
#define REG_NUM_CH 5
|
||||
#define REG_NUM_CL 1
|
||||
#define REG_NUM_CR0 0
|
||||
#define REG_NUM_CR1 1
|
||||
#define REG_NUM_CR10 10
|
||||
#define REG_NUM_CR11 11
|
||||
#define REG_NUM_CR12 12
|
||||
#define REG_NUM_CR13 13
|
||||
#define REG_NUM_CR14 14
|
||||
#define REG_NUM_CR15 15
|
||||
#define REG_NUM_CR16 16
|
||||
#define REG_NUM_CR17 17
|
||||
#define REG_NUM_CR18 18
|
||||
#define REG_NUM_CR19 19
|
||||
#define REG_NUM_CR2 2
|
||||
#define REG_NUM_CR20 20
|
||||
#define REG_NUM_CR21 21
|
||||
#define REG_NUM_CR22 22
|
||||
#define REG_NUM_CR23 23
|
||||
#define REG_NUM_CR24 24
|
||||
#define REG_NUM_CR25 25
|
||||
#define REG_NUM_CR26 26
|
||||
#define REG_NUM_CR27 27
|
||||
#define REG_NUM_CR28 28
|
||||
#define REG_NUM_CR29 29
|
||||
#define REG_NUM_CR3 3
|
||||
#define REG_NUM_CR30 30
|
||||
#define REG_NUM_CR31 31
|
||||
#define REG_NUM_CR4 4
|
||||
#define REG_NUM_CR5 5
|
||||
#define REG_NUM_CR6 6
|
||||
#define REG_NUM_CR7 7
|
||||
#define REG_NUM_CR8 8
|
||||
#define REG_NUM_CR9 9
|
||||
#define REG_NUM_CS 1
|
||||
#define REG_NUM_CX 1
|
||||
#define REG_NUM_DH 6
|
||||
#define REG_NUM_DI 7
|
||||
#define REG_NUM_DIL 7
|
||||
#define REG_NUM_DL 2
|
||||
#define REG_NUM_DR0 0
|
||||
#define REG_NUM_DR1 1
|
||||
#define REG_NUM_DR10 10
|
||||
#define REG_NUM_DR11 11
|
||||
#define REG_NUM_DR12 12
|
||||
#define REG_NUM_DR13 13
|
||||
#define REG_NUM_DR14 14
|
||||
#define REG_NUM_DR15 15
|
||||
#define REG_NUM_DR16 16
|
||||
#define REG_NUM_DR17 17
|
||||
#define REG_NUM_DR18 18
|
||||
#define REG_NUM_DR19 19
|
||||
#define REG_NUM_DR2 2
|
||||
#define REG_NUM_DR20 20
|
||||
#define REG_NUM_DR21 21
|
||||
#define REG_NUM_DR22 22
|
||||
#define REG_NUM_DR23 23
|
||||
#define REG_NUM_DR24 24
|
||||
#define REG_NUM_DR25 25
|
||||
#define REG_NUM_DR26 26
|
||||
#define REG_NUM_DR27 27
|
||||
#define REG_NUM_DR28 28
|
||||
#define REG_NUM_DR29 29
|
||||
#define REG_NUM_DR3 3
|
||||
#define REG_NUM_DR30 30
|
||||
#define REG_NUM_DR31 31
|
||||
#define REG_NUM_DR4 4
|
||||
#define REG_NUM_DR5 5
|
||||
#define REG_NUM_DR6 6
|
||||
#define REG_NUM_DR7 7
|
||||
#define REG_NUM_DR8 8
|
||||
#define REG_NUM_DR9 9
|
||||
#define REG_NUM_DS 3
|
||||
#define REG_NUM_DX 2
|
||||
#define REG_NUM_EAX 0
|
||||
#define REG_NUM_EBP 5
|
||||
#define REG_NUM_EBX 3
|
||||
#define REG_NUM_ECX 1
|
||||
#define REG_NUM_EDI 7
|
||||
#define REG_NUM_EDX 2
|
||||
#define REG_NUM_ES 0
|
||||
#define REG_NUM_ESI 6
|
||||
#define REG_NUM_ESP 4
|
||||
#define REG_NUM_FS 4
|
||||
#define REG_NUM_GS 5
|
||||
#define REG_NUM_K0 0
|
||||
#define REG_NUM_K1 1
|
||||
#define REG_NUM_K2 2
|
||||
#define REG_NUM_K3 3
|
||||
#define REG_NUM_K4 4
|
||||
#define REG_NUM_K5 5
|
||||
#define REG_NUM_K6 6
|
||||
#define REG_NUM_K7 7
|
||||
#define REG_NUM_MM0 0
|
||||
#define REG_NUM_MM1 1
|
||||
#define REG_NUM_MM2 2
|
||||
#define REG_NUM_MM3 3
|
||||
#define REG_NUM_MM4 4
|
||||
#define REG_NUM_MM5 5
|
||||
#define REG_NUM_MM6 6
|
||||
#define REG_NUM_MM7 7
|
||||
#define REG_NUM_R10 10
|
||||
#define REG_NUM_R10B 10
|
||||
#define REG_NUM_R10D 10
|
||||
#define REG_NUM_R10W 10
|
||||
#define REG_NUM_R11 11
|
||||
#define REG_NUM_R11B 11
|
||||
#define REG_NUM_R11D 11
|
||||
#define REG_NUM_R11W 11
|
||||
#define REG_NUM_R12 12
|
||||
#define REG_NUM_R12B 12
|
||||
#define REG_NUM_R12D 12
|
||||
#define REG_NUM_R12W 12
|
||||
#define REG_NUM_R13 13
|
||||
#define REG_NUM_R13B 13
|
||||
#define REG_NUM_R13D 13
|
||||
#define REG_NUM_R13W 13
|
||||
#define REG_NUM_R14 14
|
||||
#define REG_NUM_R14B 14
|
||||
#define REG_NUM_R14D 14
|
||||
#define REG_NUM_R14W 14
|
||||
#define REG_NUM_R15 15
|
||||
#define REG_NUM_R15B 15
|
||||
#define REG_NUM_R15D 15
|
||||
#define REG_NUM_R15W 15
|
||||
#define REG_NUM_R16 16
|
||||
#define REG_NUM_R16B 16
|
||||
#define REG_NUM_R16D 16
|
||||
#define REG_NUM_R16W 16
|
||||
#define REG_NUM_R17 17
|
||||
#define REG_NUM_R17B 17
|
||||
#define REG_NUM_R17D 17
|
||||
#define REG_NUM_R17W 17
|
||||
#define REG_NUM_R18 18
|
||||
#define REG_NUM_R18B 18
|
||||
#define REG_NUM_R18D 18
|
||||
#define REG_NUM_R18W 18
|
||||
#define REG_NUM_R19 19
|
||||
#define REG_NUM_R19B 19
|
||||
#define REG_NUM_R19D 19
|
||||
#define REG_NUM_R19W 19
|
||||
#define REG_NUM_R20 20
|
||||
#define REG_NUM_R20B 20
|
||||
#define REG_NUM_R20D 20
|
||||
#define REG_NUM_R20W 20
|
||||
#define REG_NUM_R21 21
|
||||
#define REG_NUM_R21B 21
|
||||
#define REG_NUM_R21D 21
|
||||
#define REG_NUM_R21W 21
|
||||
#define REG_NUM_R22 22
|
||||
#define REG_NUM_R22B 22
|
||||
#define REG_NUM_R22D 22
|
||||
#define REG_NUM_R22W 22
|
||||
#define REG_NUM_R23 23
|
||||
#define REG_NUM_R23B 23
|
||||
#define REG_NUM_R23D 23
|
||||
#define REG_NUM_R23W 23
|
||||
#define REG_NUM_R24 24
|
||||
#define REG_NUM_R24B 24
|
||||
#define REG_NUM_R24D 24
|
||||
#define REG_NUM_R24W 24
|
||||
#define REG_NUM_R25 25
|
||||
#define REG_NUM_R25B 25
|
||||
#define REG_NUM_R25D 25
|
||||
#define REG_NUM_R25W 25
|
||||
#define REG_NUM_R26 26
|
||||
#define REG_NUM_R26B 26
|
||||
#define REG_NUM_R26D 26
|
||||
#define REG_NUM_R26W 26
|
||||
#define REG_NUM_R27 27
|
||||
#define REG_NUM_R27B 27
|
||||
#define REG_NUM_R27D 27
|
||||
#define REG_NUM_R27W 27
|
||||
#define REG_NUM_R28 28
|
||||
#define REG_NUM_R28B 28
|
||||
#define REG_NUM_R28D 28
|
||||
#define REG_NUM_R28W 28
|
||||
#define REG_NUM_R29 29
|
||||
#define REG_NUM_R29B 29
|
||||
#define REG_NUM_R29D 29
|
||||
#define REG_NUM_R29W 29
|
||||
#define REG_NUM_R30 30
|
||||
#define REG_NUM_R30B 30
|
||||
#define REG_NUM_R30D 30
|
||||
#define REG_NUM_R30W 30
|
||||
#define REG_NUM_R31 31
|
||||
#define REG_NUM_R31B 31
|
||||
#define REG_NUM_R31D 31
|
||||
#define REG_NUM_R31W 31
|
||||
#define REG_NUM_R8 8
|
||||
#define REG_NUM_R8B 8
|
||||
#define REG_NUM_R8D 8
|
||||
#define REG_NUM_R8W 8
|
||||
#define REG_NUM_R9 9
|
||||
#define REG_NUM_R9B 9
|
||||
#define REG_NUM_R9D 9
|
||||
#define REG_NUM_R9W 9
|
||||
#define REG_NUM_RAX 0
|
||||
#define REG_NUM_RBP 5
|
||||
#define REG_NUM_RBX 3
|
||||
#define REG_NUM_RCX 1
|
||||
#define REG_NUM_RDI 7
|
||||
#define REG_NUM_RDX 2
|
||||
#define REG_NUM_RSI 6
|
||||
#define REG_NUM_RSP 4
|
||||
#define REG_NUM_SEGR6 6
|
||||
#define REG_NUM_SEGR7 7
|
||||
#define REG_NUM_SI 6
|
||||
#define REG_NUM_SIL 6
|
||||
#define REG_NUM_SP 4
|
||||
#define REG_NUM_SPL 4
|
||||
#define REG_NUM_SS 2
|
||||
#define REG_NUM_ST0 0
|
||||
#define REG_NUM_ST1 1
|
||||
#define REG_NUM_ST2 2
|
||||
#define REG_NUM_ST3 3
|
||||
#define REG_NUM_ST4 4
|
||||
#define REG_NUM_ST5 5
|
||||
#define REG_NUM_ST6 6
|
||||
#define REG_NUM_ST7 7
|
||||
#define REG_NUM_TMM0 0
|
||||
#define REG_NUM_TMM1 1
|
||||
#define REG_NUM_TMM2 2
|
||||
#define REG_NUM_TMM3 3
|
||||
#define REG_NUM_TMM4 4
|
||||
#define REG_NUM_TMM5 5
|
||||
#define REG_NUM_TMM6 6
|
||||
#define REG_NUM_TMM7 7
|
||||
#define REG_NUM_TR0 0
|
||||
#define REG_NUM_TR1 1
|
||||
#define REG_NUM_TR2 2
|
||||
#define REG_NUM_TR3 3
|
||||
#define REG_NUM_TR4 4
|
||||
#define REG_NUM_TR5 5
|
||||
#define REG_NUM_TR6 6
|
||||
#define REG_NUM_TR7 7
|
||||
#define REG_NUM_XMM0 0
|
||||
#define REG_NUM_XMM1 1
|
||||
#define REG_NUM_XMM10 10
|
||||
#define REG_NUM_XMM11 11
|
||||
#define REG_NUM_XMM12 12
|
||||
#define REG_NUM_XMM13 13
|
||||
#define REG_NUM_XMM14 14
|
||||
#define REG_NUM_XMM15 15
|
||||
#define REG_NUM_XMM16 16
|
||||
#define REG_NUM_XMM17 17
|
||||
#define REG_NUM_XMM18 18
|
||||
#define REG_NUM_XMM19 19
|
||||
#define REG_NUM_XMM2 2
|
||||
#define REG_NUM_XMM20 20
|
||||
#define REG_NUM_XMM21 21
|
||||
#define REG_NUM_XMM22 22
|
||||
#define REG_NUM_XMM23 23
|
||||
#define REG_NUM_XMM24 24
|
||||
#define REG_NUM_XMM25 25
|
||||
#define REG_NUM_XMM26 26
|
||||
#define REG_NUM_XMM27 27
|
||||
#define REG_NUM_XMM28 28
|
||||
#define REG_NUM_XMM29 29
|
||||
#define REG_NUM_XMM3 3
|
||||
#define REG_NUM_XMM30 30
|
||||
#define REG_NUM_XMM31 31
|
||||
#define REG_NUM_XMM4 4
|
||||
#define REG_NUM_XMM5 5
|
||||
#define REG_NUM_XMM6 6
|
||||
#define REG_NUM_XMM7 7
|
||||
#define REG_NUM_XMM8 8
|
||||
#define REG_NUM_XMM9 9
|
||||
#define REG_NUM_YMM0 0
|
||||
#define REG_NUM_YMM1 1
|
||||
#define REG_NUM_YMM10 10
|
||||
#define REG_NUM_YMM11 11
|
||||
#define REG_NUM_YMM12 12
|
||||
#define REG_NUM_YMM13 13
|
||||
#define REG_NUM_YMM14 14
|
||||
#define REG_NUM_YMM15 15
|
||||
#define REG_NUM_YMM16 16
|
||||
#define REG_NUM_YMM17 17
|
||||
#define REG_NUM_YMM18 18
|
||||
#define REG_NUM_YMM19 19
|
||||
#define REG_NUM_YMM2 2
|
||||
#define REG_NUM_YMM20 20
|
||||
#define REG_NUM_YMM21 21
|
||||
#define REG_NUM_YMM22 22
|
||||
#define REG_NUM_YMM23 23
|
||||
#define REG_NUM_YMM24 24
|
||||
#define REG_NUM_YMM25 25
|
||||
#define REG_NUM_YMM26 26
|
||||
#define REG_NUM_YMM27 27
|
||||
#define REG_NUM_YMM28 28
|
||||
#define REG_NUM_YMM29 29
|
||||
#define REG_NUM_YMM3 3
|
||||
#define REG_NUM_YMM30 30
|
||||
#define REG_NUM_YMM31 31
|
||||
#define REG_NUM_YMM4 4
|
||||
#define REG_NUM_YMM5 5
|
||||
#define REG_NUM_YMM6 6
|
||||
#define REG_NUM_YMM7 7
|
||||
#define REG_NUM_YMM8 8
|
||||
#define REG_NUM_YMM9 9
|
||||
#define REG_NUM_ZMM0 0
|
||||
#define REG_NUM_ZMM1 1
|
||||
#define REG_NUM_ZMM10 10
|
||||
#define REG_NUM_ZMM11 11
|
||||
#define REG_NUM_ZMM12 12
|
||||
#define REG_NUM_ZMM13 13
|
||||
#define REG_NUM_ZMM14 14
|
||||
#define REG_NUM_ZMM15 15
|
||||
#define REG_NUM_ZMM16 16
|
||||
#define REG_NUM_ZMM17 17
|
||||
#define REG_NUM_ZMM18 18
|
||||
#define REG_NUM_ZMM19 19
|
||||
#define REG_NUM_ZMM2 2
|
||||
#define REG_NUM_ZMM20 20
|
||||
#define REG_NUM_ZMM21 21
|
||||
#define REG_NUM_ZMM22 22
|
||||
#define REG_NUM_ZMM23 23
|
||||
#define REG_NUM_ZMM24 24
|
||||
#define REG_NUM_ZMM25 25
|
||||
#define REG_NUM_ZMM26 26
|
||||
#define REG_NUM_ZMM27 27
|
||||
#define REG_NUM_ZMM28 28
|
||||
#define REG_NUM_ZMM29 29
|
||||
#define REG_NUM_ZMM3 3
|
||||
#define REG_NUM_ZMM30 30
|
||||
#define REG_NUM_ZMM31 31
|
||||
#define REG_NUM_ZMM4 4
|
||||
#define REG_NUM_ZMM5 5
|
||||
#define REG_NUM_ZMM6 6
|
||||
#define REG_NUM_ZMM7 7
|
||||
#define REG_NUM_ZMM8 8
|
||||
#define REG_NUM_ZMM9 9
|
||||
|
||||
|
||||
#endif /* NASM_REGS_H */
|
||||
64
include/saa.h
Normal file
64
include/saa.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef NASM_SAA_H
|
||||
#define NASM_SAA_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*
|
||||
* Routines to manage a dynamic sequential-access array, under the
|
||||
* same restriction on maximum mallocable block. This array may be
|
||||
* written to in two ways: a contiguous chunk can be reserved of a
|
||||
* given size with a pointer returned OR single-byte data may be
|
||||
* written. The array can also be read back in the same two ways:
|
||||
* as a series of big byte-data blocks or as a list of structures
|
||||
* of a given size.
|
||||
*/
|
||||
|
||||
struct SAA {
|
||||
/*
|
||||
* members `end' and `elem_len' are only valid in first link in
|
||||
* list; `rptr' and `rpos' are used for reading
|
||||
*/
|
||||
size_t elem_len; /* Size of each element */
|
||||
size_t blk_len; /* Size of each allocation block */
|
||||
size_t nblks; /* Total number of allocated blocks */
|
||||
size_t nblkptrs; /* Total number of allocation block pointers */
|
||||
size_t length; /* Total allocated length of the array */
|
||||
size_t datalen; /* Total data length of the array */
|
||||
char **wblk; /* Write block pointer */
|
||||
size_t wpos; /* Write position inside block */
|
||||
size_t wptr; /* Absolute write position */
|
||||
char **rblk; /* Read block pointer */
|
||||
size_t rpos; /* Read position inside block */
|
||||
size_t rptr; /* Absolute read position */
|
||||
char **blk_ptrs; /* Pointer to pointer blocks */
|
||||
};
|
||||
|
||||
struct SAA * never_null saa_init(size_t elem_len); /* 1 == byte */
|
||||
void saa_free(struct SAA *);
|
||||
void *saa_wstruct(struct SAA *); /* return a structure of elem_len */
|
||||
void saa_wbytes(struct SAA *, const void *, size_t); /* write arbitrary bytes */
|
||||
size_t saa_wcstring(struct SAA *s, const char *str); /* write a C string */
|
||||
void saa_rewind(struct SAA *); /* for reading from beginning */
|
||||
void *saa_rstruct(struct SAA *); /* return NULL on EOA */
|
||||
const void *saa_rbytes(struct SAA *, size_t *); /* return 0 on EOA */
|
||||
void saa_rnbytes(struct SAA *, void *, size_t); /* read a given no. of bytes */
|
||||
/* random access */
|
||||
void saa_fread(struct SAA *, size_t, void *, size_t);
|
||||
void saa_fwrite(struct SAA *, size_t, const void *, size_t);
|
||||
|
||||
/* dump to file */
|
||||
void saa_fpwrite(struct SAA *, FILE *);
|
||||
|
||||
/* Write specific-sized values */
|
||||
void saa_write8(struct SAA *s, uint8_t v);
|
||||
void saa_write16(struct SAA *s, uint16_t v);
|
||||
void saa_write32(struct SAA *s, uint32_t v);
|
||||
void saa_write64(struct SAA *s, uint64_t v);
|
||||
void saa_wleb128u(struct SAA *, uint64_t v); /* unsigned LEB128 value */
|
||||
void saa_wleb128s(struct SAA *, int64_t v); /* signed LEB128 value */
|
||||
void saa_writeaddr(struct SAA *, uint64_t, size_t); /* specific size integer */
|
||||
|
||||
#endif /* NASM_SAA_H */
|
||||
153
include/srcfile.h
Normal file
153
include/srcfile.h
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* These functions are used to keep track of the source code file and name.
|
||||
*/
|
||||
#ifndef ASM_SRCFILE_H
|
||||
#define ASM_SRCFILE_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
struct src_location {
|
||||
const char *filename;
|
||||
int32_t lineno;
|
||||
};
|
||||
|
||||
static inline const_func struct src_location src_nowhere(void)
|
||||
{
|
||||
struct src_location no_where = { NULL, 0 };
|
||||
return no_where;
|
||||
}
|
||||
|
||||
/*
|
||||
* Comparing the *pointer value* of filenames is valid, because the
|
||||
* filename hash system guarantees that each unique filename string is
|
||||
* permanently allocated in exactly one location.
|
||||
*/
|
||||
static inline bool
|
||||
src_location_same(struct src_location here, struct src_location there)
|
||||
{
|
||||
return here.filename == there.filename && here.lineno == there.lineno;
|
||||
}
|
||||
|
||||
struct src_location_stack {
|
||||
struct src_location l;
|
||||
struct src_location_stack *up, *down;
|
||||
const void *macro;
|
||||
};
|
||||
extern struct src_location_stack _src_top;
|
||||
extern struct src_location_stack *_src_bottom;
|
||||
extern struct src_location_stack *_src_error;
|
||||
|
||||
void src_init(void);
|
||||
void src_free(void);
|
||||
const char *src_set_fname(const char *newname);
|
||||
static inline const char *src_get_fname(void)
|
||||
{
|
||||
return _src_bottom->l.filename;
|
||||
}
|
||||
static inline int32_t src_set_linnum(int32_t newline)
|
||||
{
|
||||
int32_t oldline = _src_bottom->l.lineno;
|
||||
_src_bottom->l.lineno = newline;
|
||||
return oldline;
|
||||
}
|
||||
static inline int32_t src_get_linnum(void)
|
||||
{
|
||||
return _src_bottom->l.lineno;
|
||||
}
|
||||
|
||||
/* Can be used when there is no need for the old information */
|
||||
void src_set(int32_t line, const char *filename);
|
||||
|
||||
/*
|
||||
* src_get gets both the source file name and line.
|
||||
* It is also used if you maintain private status about the source location
|
||||
* It return 0 if the information was the same as the last time you
|
||||
* checked, -2 if the name changed and (new-old) if just the line changed.
|
||||
*
|
||||
* xname must point to a filename string previously returned from any
|
||||
* function of this subsystem or be NULL; another string value will
|
||||
* not work.
|
||||
*/
|
||||
static inline int32_t src_get(int32_t *xline, const char **xname)
|
||||
{
|
||||
const char *xn = *xname;
|
||||
int32_t xl = *xline;
|
||||
int32_t line = _src_bottom->l.lineno;
|
||||
|
||||
*xline = line;
|
||||
*xname = _src_bottom->l.filename;
|
||||
|
||||
/* The return value is expected to be optimized out almost everywhere */
|
||||
if (!xn || xn != _src_bottom->l.filename)
|
||||
return -2;
|
||||
else
|
||||
return line - xl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the current information as a structure.
|
||||
*/
|
||||
static inline struct src_location src_where(void)
|
||||
{
|
||||
return _src_bottom->l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the top-level information as a structure. Use this for panic
|
||||
* errors, since descent is not possible there.
|
||||
*/
|
||||
static inline struct src_location src_where_top(void)
|
||||
{
|
||||
return _src_top.l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the appropriate level of the location stack to use for error
|
||||
* messages. This is the same as the top level except during the descent
|
||||
* through the macro hierarchy for elucidation;
|
||||
*/
|
||||
static inline struct src_location src_where_error(void)
|
||||
{
|
||||
return _src_error->l;
|
||||
}
|
||||
static inline const void *src_error_down(void)
|
||||
{
|
||||
if (_src_error->down) {
|
||||
_src_error = _src_error->down;
|
||||
return _src_error->macro;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static inline void src_error_reset(void)
|
||||
{
|
||||
_src_error = &_src_top;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the current information. The filename member of the structure
|
||||
* *must* have been previously returned by src_get(), src_where(), or
|
||||
* src_get_fname() and therefore be present in the hash.
|
||||
*/
|
||||
static inline struct src_location src_update(struct src_location whence)
|
||||
{
|
||||
struct src_location old = _src_bottom->l;
|
||||
_src_bottom->l = whence;
|
||||
return old;
|
||||
}
|
||||
|
||||
/*
|
||||
* Push/pop macro expansion level. "macroname" must remain constant at
|
||||
* least until the same macro expansion level is popped.
|
||||
*/
|
||||
void src_macro_push(const void *macroname, struct src_location where);
|
||||
static inline const void *src_macro_current(void)
|
||||
{
|
||||
return _src_bottom->macro;
|
||||
}
|
||||
void src_macro_pop(void);
|
||||
|
||||
#endif /* ASM_SRCFILE_H */
|
||||
120
include/stabs.h
Normal file
120
include/stabs.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef STABS_H_
|
||||
#define STABS_H_
|
||||
|
||||
#include "nctype.h"
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "nasm.h"
|
||||
|
||||
/* offsets */
|
||||
enum stab_offsets {
|
||||
STAB_strdxoff = 0,
|
||||
STAB_typeoff = 4,
|
||||
STAB_otheroff = 5,
|
||||
STAB_descoff = 6,
|
||||
STAB_valoff = 8,
|
||||
STAB_stabsize = 12
|
||||
};
|
||||
|
||||
/* stab/non-stab types */
|
||||
enum stab_types {
|
||||
N_UNDF = 0x00, /* Undefined symbol */
|
||||
N_EXT = 0x01, /* External symbol */
|
||||
N_ABS = 0x02, /* Absolute symbol */
|
||||
N_ABS_EXT = 0x03, /* Absolute external symbol */
|
||||
N_TEXT = 0x04, /* Symbol in text segment */
|
||||
N_TEXT_EXT = 0x05, /* Symbol in external text segment */
|
||||
N_DATA = 0x06,
|
||||
N_DATA_EXT = 0x07,
|
||||
N_BSS = 0x08,
|
||||
N_BSS_EXT = 0x09,
|
||||
N_INDR = 0x0a,
|
||||
N_FN_SEQ = 0x0c, /* N_FN from Sequent compilers */
|
||||
N_WEAKU = 0x0d, /* Weak undefined symbol */
|
||||
N_WEAKA = 0x0e, /* Weak absolute symbl */
|
||||
N_WEAKT = 0x0f, /* Weak text symbol */
|
||||
N_WEAKD = 0x10, /* Weak data symbol */
|
||||
N_WEAKB = 0x11, /* Weak bss symbol */
|
||||
N_COMM = 0x12, /* Common symbol */
|
||||
N_SETA = 0x14, /* Absolute set element symbol */
|
||||
N_SETA_EXT = 0x15,
|
||||
N_SETT = 0x16, /* Text set element symbol */
|
||||
N_SETT_EXT = 0x17,
|
||||
N_SETD = 0x18, /* Data set element symbol */
|
||||
N_SETD_EXT = 0x19,
|
||||
N_SETB = 0x1a, /* BSS set element symbol */
|
||||
N_SETB_EXT = 0x1b,
|
||||
N_SETV = 0x1c, /* Pointer to set vector in data area */
|
||||
N_SETV_EXT = 0x1d,
|
||||
N_WARNING = 0x1e, /* Warning symbol */
|
||||
N_FN = 0x1f, /* Filename of .o file */
|
||||
N_GSYM = 0x20, /* Global variable */
|
||||
N_FNAME = 0x22, /* Function name for BSD Fortran */
|
||||
N_FUN = 0x24, /* Function name or text segment variable for C */
|
||||
N_STSYM = 0x26, /* Data-segment variable with internal linkage */
|
||||
N_LCSYM = 0x28, /* BSS-segment variable with internal linkage */
|
||||
N_MAIN = 0x2a, /* Name of main routine */
|
||||
N_ROSYM = 0x2c, /* Read-only data symbols */
|
||||
N_BNSYM = 0x2e, /* The beginning of a relocatable function block */
|
||||
N_PC = 0x30, /* Global symbol in Pascal */
|
||||
N_NSYMS = 0x32, /* Number of symbols */
|
||||
N_NOMAP = 0x34, /* No DST map for sym */
|
||||
N_OBJ = 0x38, /* Like N_SO, but for the object file */
|
||||
N_OPT = 0x3c, /* Options for the debugger */
|
||||
N_RSYM = 0x40, /* Register variable */
|
||||
N_M2C = 0x42, /* Modula-2 compilation unit */
|
||||
N_SLINE = 0x44, /* Line number in text segment */
|
||||
N_DSLINE = 0x46, /* Line number in data segment */
|
||||
N_BSLINE = 0x48, /* Line number in bss segment */
|
||||
N_BROWS = 0x48, /* Sun's source-code browser stabs */
|
||||
N_DEFD = 0x4a, /* GNU Modula-2 definition module dependency */
|
||||
N_FLINE = 0x4c, /* Function start/body/end line numbers */
|
||||
N_ENSYM = 0x4e, /* This tells the end of a relocatable function */
|
||||
N_EHDECL = 0x50, /* GNU C++ exception variable */
|
||||
N_MOD2 = 0x50, /* Modula2 info "for imc" */
|
||||
N_CATCH = 0x54, /* GNU C++ `catch' clause */
|
||||
N_SSYM = 0x60, /* Structure or union element */
|
||||
N_ENDM = 0x62, /* Last stab emitted for module */
|
||||
N_SO = 0x64, /* ID for main source file */
|
||||
N_OSO = 0x66, /* Apple: This is the stab that associated the .o file */
|
||||
N_ALIAS = 0x6c, /* SunPro F77: Name of alias */
|
||||
N_LSYM = 0x80, /* Automatic variable in the stack */
|
||||
N_BINCL = 0x82, /* Beginning of an include file */
|
||||
N_SOL = 0x84, /* ID for sub-source file */
|
||||
N_PSYM = 0xa0, /* Parameter variable */
|
||||
N_EINCL = 0xa2, /* End of an include file */
|
||||
N_ENTRY = 0xa4, /* Alternate entry point */
|
||||
N_LBRAC = 0xc0, /* Beginning of lexical block */
|
||||
N_EXCL = 0xc2, /* Place holder for deleted include file */
|
||||
N_SCOPE = 0xc4, /* Modula-2 scope information */
|
||||
N_PATCH = 0xd0, /* Solaris2: Patch Run Time Checker */
|
||||
N_RBRAC = 0xe0, /* End of a lexical block */
|
||||
N_BCOMM = 0xe2, /* Begin named common block */
|
||||
N_ECOMM = 0xe4, /* End named common block */
|
||||
N_ECOML = 0xe8, /* Member of a common block */
|
||||
N_WITH = 0xea, /* Solaris2: Pascal "with" statement */
|
||||
N_NBTEXT = 0xf0,
|
||||
N_NBDATA = 0xf2,
|
||||
N_NBBSS = 0xf4,
|
||||
N_NBSTS = 0xf6,
|
||||
N_NBLCS = 0xf8,
|
||||
N_LENG = 0xfe /* Second symbol entry whih a length-value for the preceding entry */
|
||||
};
|
||||
|
||||
enum stab_source_file {
|
||||
N_SO_AS = 0x01,
|
||||
N_SO_C = 0x02,
|
||||
N_SO_ANSI_C = 0x03,
|
||||
N_SO_CC = 0x04,
|
||||
N_SO_FORTRAN = 0x05,
|
||||
N_SO_PASCAL = 0x06,
|
||||
N_SO_FORTRAN90 = 0x07,
|
||||
N_SO_OBJC = 0x32,
|
||||
N_SO_OBJCPLUS = 0x33
|
||||
};
|
||||
|
||||
#endif /* STABS_H_ */
|
||||
23
include/stdscan.h
Normal file
23
include/stdscan.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* stdscan.h header file for stdscan.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_STDSCAN_H
|
||||
#define NASM_STDSCAN_H
|
||||
|
||||
/* Standard scanner */
|
||||
struct stdscan_state;
|
||||
|
||||
void stdscan_set(const struct stdscan_state *);
|
||||
const struct stdscan_state *stdscan_get(void);
|
||||
char * pure_func stdscan_tell(void);
|
||||
void stdscan_reset(char *buffer);
|
||||
int stdscan(void *pvt, struct tokenval *tv);
|
||||
void stdscan_pushback(const struct tokenval *tv);
|
||||
int nasm_token_hash(const char *token, struct tokenval *tv);
|
||||
void stdscan_cleanup(void);
|
||||
|
||||
#endif
|
||||
63
include/strlist.h
Normal file
63
include/strlist.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* strlist.h - list of unique, ordered strings
|
||||
*/
|
||||
|
||||
#ifndef NASM_STRLIST_H
|
||||
#define NASM_STRLIST_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "hashtbl.h"
|
||||
|
||||
struct strlist_entry {
|
||||
struct strlist_entry *next;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
intorptr pvt;
|
||||
char str[1];
|
||||
};
|
||||
|
||||
struct strlist {
|
||||
struct hash_table hash;
|
||||
struct strlist_entry *head, **tailp;
|
||||
size_t nstr, size;
|
||||
bool uniq;
|
||||
};
|
||||
|
||||
static inline const struct strlist_entry *
|
||||
strlist_head(const struct strlist *list)
|
||||
{
|
||||
return list ? list->head : NULL;
|
||||
}
|
||||
static inline struct strlist_entry *strlist_tail(struct strlist *list)
|
||||
{
|
||||
if (!list || !list->head)
|
||||
return NULL;
|
||||
return container_of(list->tailp, struct strlist_entry, next);
|
||||
}
|
||||
static inline size_t strlist_count(const struct strlist *list)
|
||||
{
|
||||
return list ? list->nstr : 0;
|
||||
}
|
||||
static inline size_t strlist_size(const struct strlist *list)
|
||||
{
|
||||
return list ? list->size : 0;
|
||||
}
|
||||
|
||||
struct strlist * safe_alloc strlist_alloc(bool uniq);
|
||||
const struct strlist_entry *strlist_add(struct strlist *list, const char *str);
|
||||
const struct strlist_entry * printf_func(2, 3)
|
||||
strlist_printf(struct strlist *list, const char *fmt, ...);
|
||||
const struct strlist_entry * vprintf_func(2)
|
||||
strlist_vprintf(struct strlist *list, const char *fmt, va_list ap);
|
||||
const struct strlist_entry *
|
||||
strlist_find(const struct strlist *list, const char *str);
|
||||
void * safe_alloc strlist_linearize(const struct strlist *list, char sep);
|
||||
void strlist_write(const struct strlist *list, const char *sep, FILE *f);
|
||||
void strlist_free(struct strlist **listp);
|
||||
#define strlist_for_each(p,h) list_for_each((p), strlist_head(h))
|
||||
|
||||
#endif /* NASM_STRLIST_H */
|
||||
15
include/sync.h
Normal file
15
include/sync.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2009 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* sync.h header file for sync.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_SYNC_H
|
||||
#define NASM_SYNC_H
|
||||
|
||||
void init_sync(void);
|
||||
void add_sync(uint64_t position, uint64_t length);
|
||||
uint64_t next_sync(uint64_t position, uint64_t *length);
|
||||
|
||||
#endif
|
||||
32
include/tables.h
Normal file
32
include/tables.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* tables.h
|
||||
*
|
||||
* Declarations for auto-generated tables
|
||||
*/
|
||||
|
||||
#ifndef NASM_TABLES_H
|
||||
#define NASM_TABLES_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "insnsi.h" /* For enum opcode */
|
||||
|
||||
/* --- From insns.dat via insns.pl: --- */
|
||||
|
||||
/* insnsn.c */
|
||||
extern const char * const nasm_insn_names[];
|
||||
|
||||
/* --- From regs.dat via regs.pl: --- */
|
||||
|
||||
/* regs.c */
|
||||
extern const char * const nasm_reg_names[];
|
||||
/* regflags.c */
|
||||
typedef uint64_t opflags_t;
|
||||
typedef uint16_t decoflags_t;
|
||||
extern const opflags_t nasm_reg_flags[];
|
||||
/* regvals.c */
|
||||
extern const int nasm_regvals[];
|
||||
|
||||
#endif /* NASM_TABLES_H */
|
||||
11
include/template.h
Normal file
11
include/template.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-20xx The NASM Authors - All Rights Reserved */
|
||||
|
||||
#ifndef FILENAME_H
|
||||
#define FILENAME_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* Code goes here */
|
||||
|
||||
#endif /* FILENAME_H */
|
||||
11
include/tokens.h
Normal file
11
include/tokens.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* This file is generated from insns.dat, regs.dat and token.dat
|
||||
* by tokhash.pl; do not edit.
|
||||
*/
|
||||
|
||||
#ifndef NASM_TOKENS_H
|
||||
#define NASM_TOKENS_H
|
||||
|
||||
#define MAX_KEYWORD 17 /* length of longest keyword */
|
||||
|
||||
#endif /* NASM_TOKENS_H */
|
||||
230
include/unconfig.h
Normal file
230
include/unconfig.h
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
/* config/unconfig.h: autogenerated by tools/unconfig.pl */
|
||||
|
||||
#ifndef CONFIG_UNCONFIG_H
|
||||
#define CONFIG_UNCONFIG_H
|
||||
|
||||
#ifndef alloc_size_func2
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_2_ALLOC_SIZE
|
||||
# define alloc_size_func2(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
|
||||
# else
|
||||
# define alloc_size_func2(x1,x2)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func2_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_2_ALLOC_SIZE
|
||||
# define alloc_size_func2_ptr(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
|
||||
# else
|
||||
# define alloc_size_func2_ptr(x1,x2)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef end_with_null
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_SENTINEL
|
||||
# define end_with_null ATTRIBUTE(sentinel)
|
||||
# else
|
||||
# define end_with_null
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef end_with_null_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_SENTINEL
|
||||
# define end_with_null_ptr ATTRIBUTE(sentinel)
|
||||
# else
|
||||
# define end_with_null_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef format_func3
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_3_FORMAT
|
||||
# define format_func3(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
|
||||
# else
|
||||
# define format_func3(x1,x2,x3)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef format_func3_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_3_FORMAT
|
||||
# define format_func3_ptr(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
|
||||
# else
|
||||
# define format_func3_ptr(x1,x2,x3)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef const_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_CONST
|
||||
# define const_func ATTRIBUTE(const)
|
||||
# else
|
||||
# define const_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef const_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_CONST
|
||||
# define const_func_ptr ATTRIBUTE(const)
|
||||
# else
|
||||
# define const_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unsequenced_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_UNSEQUENCED
|
||||
# define unsequenced_func ATTRIBUTE(unsequenced)
|
||||
# else
|
||||
# define unsequenced_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unsequenced_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_UNSEQUENCED
|
||||
# define unsequenced_func_ptr ATTRIBUTE(unsequenced)
|
||||
# else
|
||||
# define unsequenced_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef noreturn_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
|
||||
# define noreturn_func ATTRIBUTE(noreturn)
|
||||
# else
|
||||
# define noreturn_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef reproducible_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_REPRODUCIBLE
|
||||
# define reproducible_func ATTRIBUTE(reproducible)
|
||||
# else
|
||||
# define reproducible_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef reproducible_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_REPRODUCIBLE
|
||||
# define reproducible_func_ptr ATTRIBUTE(reproducible)
|
||||
# else
|
||||
# define reproducible_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef pure_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_PURE
|
||||
# define pure_func ATTRIBUTE(pure)
|
||||
# else
|
||||
# define pure_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef pure_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_PURE
|
||||
# define pure_func_ptr ATTRIBUTE(pure)
|
||||
# else
|
||||
# define pure_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unlikely_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_COLD
|
||||
# define unlikely_func ATTRIBUTE(cold)
|
||||
# else
|
||||
# define unlikely_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unlikely_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_COLD
|
||||
# define unlikely_func_ptr ATTRIBUTE(cold)
|
||||
# else
|
||||
# define unlikely_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef maybe_unused_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_MAYBE_UNUSED
|
||||
# define maybe_unused_func ATTRIBUTE(maybe_unused)
|
||||
# else
|
||||
# define maybe_unused_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef maybe_unused_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_MAYBE_UNUSED
|
||||
# define maybe_unused_func_ptr ATTRIBUTE(maybe_unused)
|
||||
# else
|
||||
# define maybe_unused_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unused_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
|
||||
# define unused_func ATTRIBUTE(unused)
|
||||
# else
|
||||
# define unused_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef unused_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_UNUSED
|
||||
# define unused_func_ptr ATTRIBUTE(unused)
|
||||
# else
|
||||
# define unused_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef noreturn_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_NORETURN
|
||||
# define noreturn_func_ptr ATTRIBUTE(noreturn)
|
||||
# else
|
||||
# define noreturn_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef never_null
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
|
||||
# define never_null ATTRIBUTE(returns_nonnull)
|
||||
# else
|
||||
# define never_null
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef never_null_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_RETURNS_NONNULL
|
||||
# define never_null_ptr ATTRIBUTE(returns_nonnull)
|
||||
# else
|
||||
# define never_null_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef malloc_func
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
|
||||
# define malloc_func ATTRIBUTE(malloc)
|
||||
# else
|
||||
# define malloc_func
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef malloc_func_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_MALLOC
|
||||
# define malloc_func_ptr ATTRIBUTE(malloc)
|
||||
# else
|
||||
# define malloc_func_ptr
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func1
|
||||
# ifdef HAVE_FUNC_ATTRIBUTE_1_ALLOC_SIZE
|
||||
# define alloc_size_func1(x1) ATTRIBUTE(alloc_size(x1))
|
||||
# else
|
||||
# define alloc_size_func1(x1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef alloc_size_func1_ptr
|
||||
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_1_ALLOC_SIZE
|
||||
# define alloc_size_func1_ptr(x1) ATTRIBUTE(alloc_size(x1))
|
||||
# else
|
||||
# define alloc_size_func1_ptr(x1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_UNCONFIG_H */
|
||||
21
include/unknown.h
Normal file
21
include/unknown.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/unknown.h
|
||||
*
|
||||
* Compiler definitions for an unknown compiler. Assume the worst.
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_UNKNOWN_H
|
||||
#define NASM_CONFIG_UNKNOWN_H
|
||||
|
||||
/* Assume these don't exist */
|
||||
#ifndef inline
|
||||
# define inline
|
||||
#endif
|
||||
#ifndef restrict
|
||||
# define restrict
|
||||
#endif
|
||||
|
||||
#endif /* NASM_CONFIG_UNKNOWN_H */
|
||||
25
include/ver.h
Normal file
25
include/ver.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2020 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* NASM version strings, defined in ver.c
|
||||
*/
|
||||
|
||||
#ifndef NASM_VER_H
|
||||
#define NASM_VER_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
extern const char nasm_version[];
|
||||
extern const char nasm_date[];
|
||||
extern const char nasm_compile_options[];
|
||||
|
||||
extern bool reproducible;
|
||||
|
||||
extern const char * pure_func nasm_comment(void);
|
||||
extern size_t pure_func nasm_comment_len(void);
|
||||
|
||||
extern const char * pure_func nasm_signature(void);
|
||||
extern size_t pure_func nasm_signature_len(void);
|
||||
|
||||
#endif /* NASM_VER_H */
|
||||
9
include/version.h
Normal file
9
include/version.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef NASM_VERSION_H
|
||||
#define NASM_VERSION_H
|
||||
#define NASM_MAJOR_VER 3
|
||||
#define NASM_MINOR_VER 2
|
||||
#define NASM_SUBMINOR_VER 0
|
||||
#define NASM_PATCHLEVEL_VER 0
|
||||
#define NASM_VERSION_ID 0x03020000
|
||||
#define NASM_VER "3.02"
|
||||
#endif /* NASM_VERSION_H */
|
||||
166
include/warnings.h
Normal file
166
include/warnings.h
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
#ifndef NASM_WARNINGS_H
|
||||
#define NASM_WARNINGS_H
|
||||
|
||||
#ifndef WARN_SHR
|
||||
# error "warnings.h should only be included from within error.h"
|
||||
#endif
|
||||
|
||||
enum warn_index {
|
||||
WARN_IDX_NONE = 0, /* not suppressible */
|
||||
WARN_IDX_DB_EMPTY = 1, /* no operand for data declaration */
|
||||
WARN_IDX_DIRECTIVE_GARBAGE_EOL = 2, /* garbage after directive */
|
||||
WARN_IDX_EA_ABSOLUTE = 3, /* absolute address cannot be RIP-relative */
|
||||
WARN_IDX_EA_DISPSIZE = 4, /* displacement size ignored on absolute address */
|
||||
WARN_IDX_FLOAT_DENORM = 5, /* floating point denormal */
|
||||
WARN_IDX_FLOAT_OVERFLOW = 6, /* floating point overflow */
|
||||
WARN_IDX_FLOAT_TOOLONG = 7, /* too many digits in floating-point number */
|
||||
WARN_IDX_FLOAT_UNDERFLOW = 8, /* floating point underflow */
|
||||
WARN_IDX_FORWARD = 9, /* forward reference may have unpredictable results */
|
||||
WARN_IDX_IMPLICIT_ABS_DEPRECATED = 10, /* implicit DEFAULT ABS is deprecated */
|
||||
WARN_IDX_LABEL_ORPHAN = 11, /* labels alone on lines without trailing : */
|
||||
WARN_IDX_LABEL_REDEF = 12, /* label redefined to an identical value */
|
||||
WARN_IDX_LABEL_REDEF_LATE = 13, /* label (re)defined during code generation */
|
||||
WARN_IDX_NUMBER_DEPRECATED_HEX = 14, /* $ prefix for hexadecimal is deprecated */
|
||||
WARN_IDX_NUMBER_OVERFLOW = 15, /* numeric constant does not fit */
|
||||
WARN_IDX_OBSOLETE_NOP = 16, /* instruction obsolete and is a noop on the target CPU */
|
||||
WARN_IDX_OBSOLETE_REMOVED = 17, /* instruction obsolete and removed on the target CPU */
|
||||
WARN_IDX_OBSOLETE_VALID = 18, /* instruction obsolete but valid on the target CPU */
|
||||
WARN_IDX_PHASE = 19, /* phase error during stabilization */
|
||||
WARN_IDX_PP_ELSE_ELIF = 20, /* %elif after %else */
|
||||
WARN_IDX_PP_ELSE_ELSE = 21, /* %else after %else */
|
||||
WARN_IDX_PP_EMPTY_BRACES = 22, /* empty %{} construct */
|
||||
WARN_IDX_PP_ENVIRONMENT = 23, /* nonexistent environment variable */
|
||||
WARN_IDX_PP_MACRO_DEF_CASE_SINGLE = 24, /* single-line macro defined both case sensitive and insensitive */
|
||||
WARN_IDX_PP_MACRO_DEF_GREEDY_SINGLE = 25, /* single-line macro */
|
||||
WARN_IDX_PP_MACRO_DEF_PARAM_SINGLE = 26, /* single-line macro defined with and without parameters */
|
||||
WARN_IDX_PP_MACRO_DEFAULTS = 27, /* macros with more default than optional parameters */
|
||||
WARN_IDX_PP_MACRO_PARAMS_LEGACY = 28, /* improperly calling multi-line macro for legacy support */
|
||||
WARN_IDX_PP_MACRO_PARAMS_MULTI = 29, /* multi-line macro calls with wrong parameter count */
|
||||
WARN_IDX_PP_MACRO_PARAMS_SINGLE = 30, /* single-line macro calls with wrong parameter count */
|
||||
WARN_IDX_PP_MACRO_REDEF_MULTI = 31, /* redefining multi-line macro */
|
||||
WARN_IDX_PP_OPEN_BRACES = 32, /* unterminated %{...} */
|
||||
WARN_IDX_PP_OPEN_BRACKETS = 33, /* unterminated %[...] */
|
||||
WARN_IDX_PP_OPEN_STRING = 34, /* unterminated string */
|
||||
WARN_IDX_PP_REP_NEGATIVE = 35, /* negative %rep count */
|
||||
WARN_IDX_PP_RESERVED = 36, /* reserved unimplemented preprocessor directive */
|
||||
WARN_IDX_PP_SEL_RANGE = 37, /* %sel() argument out of range */
|
||||
WARN_IDX_PP_TRAILING = 38, /* trailing garbage ignored */
|
||||
WARN_IDX_PRAGMA_BAD = 39, /* malformed %pragma */
|
||||
WARN_IDX_PRAGMA_EMPTY = 40, /* empty %pragma directive */
|
||||
WARN_IDX_PRAGMA_NA = 41, /* %pragma not applicable to this compilation */
|
||||
WARN_IDX_PRAGMA_UNKNOWN = 42, /* unknown %pragma facility or directive */
|
||||
WARN_IDX_PREFIX_BADMODE_O64 = 43, /* o64 prefix invalid in 16/32-bit mode */
|
||||
WARN_IDX_PREFIX_BND = 44, /* invalid BND prefix */
|
||||
WARN_IDX_PREFIX_HINT_DROPPED = 45, /* invalid branch hint prefix dropped */
|
||||
WARN_IDX_PREFIX_HLE = 46, /* invalid HLE prefix */
|
||||
WARN_IDX_PREFIX_INVALID = 47, /* invalid prefix for instruction */
|
||||
WARN_IDX_PREFIX_LOCK_ERROR = 48, /* LOCK prefix on unlockable instruction */
|
||||
WARN_IDX_PREFIX_LOCK_XCHG = 49, /* superfluous LOCK prefix on XCHG instruction */
|
||||
WARN_IDX_PREFIX_OPSIZE = 50, /* invalid operand size prefix */
|
||||
WARN_IDX_PREFIX_SEG = 51, /* segment prefix ignored in 64-bit mode */
|
||||
WARN_IDX_PTR = 52, /* non-NASM keyword used in other assemblers */
|
||||
WARN_IDX_REGSIZE = 53, /* register size specification ignored */
|
||||
WARN_IDX_RELOC_ABS_BYTE = 54, /* 8-bit absolute section-crossing relocation */
|
||||
WARN_IDX_RELOC_ABS_DWORD = 55, /* 32-bit absolute section-crossing relocation */
|
||||
WARN_IDX_RELOC_ABS_QWORD = 56, /* 64-bit absolute section-crossing relocation */
|
||||
WARN_IDX_RELOC_ABS_WORD = 57, /* 16-bit absolute section-crossing relocation */
|
||||
WARN_IDX_RELOC_REL_BYTE = 58, /* 8-bit relative section-crossing relocation */
|
||||
WARN_IDX_RELOC_REL_DWORD = 59, /* 32-bit relative section-crossing relocation */
|
||||
WARN_IDX_RELOC_REL_QWORD = 60, /* 64-bit relative section-crossing relocation */
|
||||
WARN_IDX_RELOC_REL_WORD = 61, /* 16-bit relative section-crossing relocation */
|
||||
WARN_IDX_SECTION_ALIGNMENT_ROUNDED = 62, /* section alignment rounded up */
|
||||
WARN_IDX_UNKNOWN_WARNING = 63, /* unknown warning in -W/-w or warning directive */
|
||||
WARN_IDX_USER = 64, /* %warning directives */
|
||||
WARN_IDX_WARN_STACK_EMPTY = 65, /* warning stack empty */
|
||||
WARN_IDX_ZEROING = 66, /* RESx in initialized section becomes zero */
|
||||
WARN_IDX_ZEXT_RELOC = 67, /* relocation zero-extended to match output format */
|
||||
WARN_IDX_OTHER = 68, /* any warning not assigned to a specific warning class */
|
||||
WARN_IDX_ALL = 69 /* all possible warnings */
|
||||
};
|
||||
|
||||
enum warn_const {
|
||||
WARN_NONE = 0 << WARN_SHR,
|
||||
WARN_DB_EMPTY = 1 << WARN_SHR,
|
||||
WARN_DIRECTIVE_GARBAGE_EOL = 2 << WARN_SHR,
|
||||
WARN_EA_ABSOLUTE = 3 << WARN_SHR,
|
||||
WARN_EA_DISPSIZE = 4 << WARN_SHR,
|
||||
WARN_FLOAT_DENORM = 5 << WARN_SHR,
|
||||
WARN_FLOAT_OVERFLOW = 6 << WARN_SHR,
|
||||
WARN_FLOAT_TOOLONG = 7 << WARN_SHR,
|
||||
WARN_FLOAT_UNDERFLOW = 8 << WARN_SHR,
|
||||
WARN_FORWARD = 9 << WARN_SHR,
|
||||
WARN_IMPLICIT_ABS_DEPRECATED = 10 << WARN_SHR,
|
||||
WARN_LABEL_ORPHAN = 11 << WARN_SHR,
|
||||
WARN_LABEL_REDEF = 12 << WARN_SHR,
|
||||
WARN_LABEL_REDEF_LATE = 13 << WARN_SHR,
|
||||
WARN_NUMBER_DEPRECATED_HEX = 14 << WARN_SHR,
|
||||
WARN_NUMBER_OVERFLOW = 15 << WARN_SHR,
|
||||
WARN_OBSOLETE_NOP = 16 << WARN_SHR,
|
||||
WARN_OBSOLETE_REMOVED = 17 << WARN_SHR,
|
||||
WARN_OBSOLETE_VALID = 18 << WARN_SHR,
|
||||
WARN_PHASE = 19 << WARN_SHR,
|
||||
WARN_PP_ELSE_ELIF = 20 << WARN_SHR,
|
||||
WARN_PP_ELSE_ELSE = 21 << WARN_SHR,
|
||||
WARN_PP_EMPTY_BRACES = 22 << WARN_SHR,
|
||||
WARN_PP_ENVIRONMENT = 23 << WARN_SHR,
|
||||
WARN_PP_MACRO_DEF_CASE_SINGLE = 24 << WARN_SHR,
|
||||
WARN_PP_MACRO_DEF_GREEDY_SINGLE = 25 << WARN_SHR,
|
||||
WARN_PP_MACRO_DEF_PARAM_SINGLE = 26 << WARN_SHR,
|
||||
WARN_PP_MACRO_DEFAULTS = 27 << WARN_SHR,
|
||||
WARN_PP_MACRO_PARAMS_LEGACY = 28 << WARN_SHR,
|
||||
WARN_PP_MACRO_PARAMS_MULTI = 29 << WARN_SHR,
|
||||
WARN_PP_MACRO_PARAMS_SINGLE = 30 << WARN_SHR,
|
||||
WARN_PP_MACRO_REDEF_MULTI = 31 << WARN_SHR,
|
||||
WARN_PP_OPEN_BRACES = 32 << WARN_SHR,
|
||||
WARN_PP_OPEN_BRACKETS = 33 << WARN_SHR,
|
||||
WARN_PP_OPEN_STRING = 34 << WARN_SHR,
|
||||
WARN_PP_REP_NEGATIVE = 35 << WARN_SHR,
|
||||
WARN_PP_RESERVED = 36 << WARN_SHR,
|
||||
WARN_PP_SEL_RANGE = 37 << WARN_SHR,
|
||||
WARN_PP_TRAILING = 38 << WARN_SHR,
|
||||
WARN_PRAGMA_BAD = 39 << WARN_SHR,
|
||||
WARN_PRAGMA_EMPTY = 40 << WARN_SHR,
|
||||
WARN_PRAGMA_NA = 41 << WARN_SHR,
|
||||
WARN_PRAGMA_UNKNOWN = 42 << WARN_SHR,
|
||||
WARN_PREFIX_BADMODE_O64 = 43 << WARN_SHR,
|
||||
WARN_PREFIX_BND = 44 << WARN_SHR,
|
||||
WARN_PREFIX_HINT_DROPPED = 45 << WARN_SHR,
|
||||
WARN_PREFIX_HLE = 46 << WARN_SHR,
|
||||
WARN_PREFIX_INVALID = 47 << WARN_SHR,
|
||||
WARN_PREFIX_LOCK_ERROR = 48 << WARN_SHR,
|
||||
WARN_PREFIX_LOCK_XCHG = 49 << WARN_SHR,
|
||||
WARN_PREFIX_OPSIZE = 50 << WARN_SHR,
|
||||
WARN_PREFIX_SEG = 51 << WARN_SHR,
|
||||
WARN_PTR = 52 << WARN_SHR,
|
||||
WARN_REGSIZE = 53 << WARN_SHR,
|
||||
WARN_RELOC_ABS_BYTE = 54 << WARN_SHR,
|
||||
WARN_RELOC_ABS_DWORD = 55 << WARN_SHR,
|
||||
WARN_RELOC_ABS_QWORD = 56 << WARN_SHR,
|
||||
WARN_RELOC_ABS_WORD = 57 << WARN_SHR,
|
||||
WARN_RELOC_REL_BYTE = 58 << WARN_SHR,
|
||||
WARN_RELOC_REL_DWORD = 59 << WARN_SHR,
|
||||
WARN_RELOC_REL_QWORD = 60 << WARN_SHR,
|
||||
WARN_RELOC_REL_WORD = 61 << WARN_SHR,
|
||||
WARN_SECTION_ALIGNMENT_ROUNDED = 62 << WARN_SHR,
|
||||
WARN_UNKNOWN_WARNING = 63 << WARN_SHR,
|
||||
WARN_USER = 64 << WARN_SHR,
|
||||
WARN_WARN_STACK_EMPTY = 65 << WARN_SHR,
|
||||
WARN_ZEROING = 66 << WARN_SHR,
|
||||
WARN_ZEXT_RELOC = 67 << WARN_SHR,
|
||||
WARN_OTHER = 68 << WARN_SHR
|
||||
};
|
||||
|
||||
struct warning_alias {
|
||||
const char *name;
|
||||
enum warn_index warning;
|
||||
};
|
||||
|
||||
#define NUM_WARNINGS 69
|
||||
#define NUM_WARNING_ALIAS 85
|
||||
extern const char * const warning_name[70];
|
||||
extern const char * const warning_help[70];
|
||||
extern const struct warning_alias warning_alias[NUM_WARNING_ALIAS];
|
||||
|
||||
#endif /* NASM_WARNINGS_H */
|
||||
extern uint8_t warning_state[NUM_WARNINGS];
|
||||
extern const uint8_t warning_default[NUM_WARNINGS];
|
||||
309
include/warnings_c.h
Normal file
309
include/warnings_c.h
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
#include "error.h"
|
||||
|
||||
const char * const warning_name[70] = {
|
||||
NULL,
|
||||
"db-empty",
|
||||
"directive-garbage-eol",
|
||||
"ea-absolute",
|
||||
"ea-dispsize",
|
||||
"float-denorm",
|
||||
"float-overflow",
|
||||
"float-toolong",
|
||||
"float-underflow",
|
||||
"forward",
|
||||
"implicit-abs-deprecated",
|
||||
"label-orphan",
|
||||
"label-redef",
|
||||
"label-redef-late",
|
||||
"number-deprecated-hex",
|
||||
"number-overflow",
|
||||
"obsolete-nop",
|
||||
"obsolete-removed",
|
||||
"obsolete-valid",
|
||||
"phase",
|
||||
"pp-else-elif",
|
||||
"pp-else-else",
|
||||
"pp-empty-braces",
|
||||
"pp-environment",
|
||||
"pp-macro-def-case-single",
|
||||
"pp-macro-def-greedy-single",
|
||||
"pp-macro-def-param-single",
|
||||
"pp-macro-defaults",
|
||||
"pp-macro-params-legacy",
|
||||
"pp-macro-params-multi",
|
||||
"pp-macro-params-single",
|
||||
"pp-macro-redef-multi",
|
||||
"pp-open-braces",
|
||||
"pp-open-brackets",
|
||||
"pp-open-string",
|
||||
"pp-rep-negative",
|
||||
"pp-reserved",
|
||||
"pp-sel-range",
|
||||
"pp-trailing",
|
||||
"pragma-bad",
|
||||
"pragma-empty",
|
||||
"pragma-na",
|
||||
"pragma-unknown",
|
||||
"prefix-badmode-o64",
|
||||
"prefix-bnd",
|
||||
"prefix-hint-dropped",
|
||||
"prefix-hle",
|
||||
"prefix-invalid",
|
||||
"prefix-lock-error",
|
||||
"prefix-lock-xchg",
|
||||
"prefix-opsize",
|
||||
"prefix-seg",
|
||||
"ptr",
|
||||
"regsize",
|
||||
"reloc-abs-byte",
|
||||
"reloc-abs-dword",
|
||||
"reloc-abs-qword",
|
||||
"reloc-abs-word",
|
||||
"reloc-rel-byte",
|
||||
"reloc-rel-dword",
|
||||
"reloc-rel-qword",
|
||||
"reloc-rel-word",
|
||||
"section-alignment-rounded",
|
||||
"unknown-warning",
|
||||
"user",
|
||||
"warn-stack-empty",
|
||||
"zeroing",
|
||||
"zext-reloc",
|
||||
"other",
|
||||
"all"
|
||||
};
|
||||
|
||||
const struct warning_alias warning_alias[85] = {
|
||||
{ "all", WARN_IDX_ALL },
|
||||
{ "bad-pragma", WARN_IDX_PRAGMA_BAD },
|
||||
{ "bnd", WARN_IDX_PREFIX_BND },
|
||||
{ "db-empty", WARN_IDX_DB_EMPTY },
|
||||
{ "directive-garbage-eol", WARN_IDX_DIRECTIVE_GARBAGE_EOL },
|
||||
{ "ea-absolute", WARN_IDX_EA_ABSOLUTE },
|
||||
{ "ea-dispsize", WARN_IDX_EA_DISPSIZE },
|
||||
{ "environment", WARN_IDX_PP_ENVIRONMENT },
|
||||
{ "float-denorm", WARN_IDX_FLOAT_DENORM },
|
||||
{ "float-overflow", WARN_IDX_FLOAT_OVERFLOW },
|
||||
{ "float-toolong", WARN_IDX_FLOAT_TOOLONG },
|
||||
{ "float-underflow", WARN_IDX_FLOAT_UNDERFLOW },
|
||||
{ "forward", WARN_IDX_FORWARD },
|
||||
{ "hle", WARN_IDX_PREFIX_HLE },
|
||||
{ "implicit-abs-deprecated", WARN_IDX_IMPLICIT_ABS_DEPRECATED },
|
||||
{ "label-orphan", WARN_IDX_LABEL_ORPHAN },
|
||||
{ "label-redef", WARN_IDX_LABEL_REDEF },
|
||||
{ "label-redef-late", WARN_IDX_LABEL_REDEF_LATE },
|
||||
{ "lock", WARN_IDX_PREFIX_LOCK_ERROR },
|
||||
{ "macro-def-case-single", WARN_IDX_PP_MACRO_DEF_CASE_SINGLE },
|
||||
{ "macro-def-greedy-single", WARN_IDX_PP_MACRO_DEF_GREEDY_SINGLE },
|
||||
{ "macro-def-param-single", WARN_IDX_PP_MACRO_DEF_PARAM_SINGLE },
|
||||
{ "macro-defaults", WARN_IDX_PP_MACRO_DEFAULTS },
|
||||
{ "macro-params-legacy", WARN_IDX_PP_MACRO_PARAMS_LEGACY },
|
||||
{ "macro-params-multi", WARN_IDX_PP_MACRO_PARAMS_MULTI },
|
||||
{ "macro-params-single", WARN_IDX_PP_MACRO_PARAMS_SINGLE },
|
||||
{ "negative-rep", WARN_IDX_PP_REP_NEGATIVE },
|
||||
{ "not-my-pragma", WARN_IDX_PRAGMA_NA },
|
||||
{ "number-deprecated-hex", WARN_IDX_NUMBER_DEPRECATED_HEX },
|
||||
{ "number-overflow", WARN_IDX_NUMBER_OVERFLOW },
|
||||
{ "obsolete-nop", WARN_IDX_OBSOLETE_NOP },
|
||||
{ "obsolete-removed", WARN_IDX_OBSOLETE_REMOVED },
|
||||
{ "obsolete-valid", WARN_IDX_OBSOLETE_VALID },
|
||||
{ "orphan-labels", WARN_IDX_LABEL_ORPHAN },
|
||||
{ "other", WARN_IDX_OTHER },
|
||||
{ "phase", WARN_IDX_PHASE },
|
||||
{ "pp-else-elif", WARN_IDX_PP_ELSE_ELIF },
|
||||
{ "pp-else-else", WARN_IDX_PP_ELSE_ELSE },
|
||||
{ "pp-empty-braces", WARN_IDX_PP_EMPTY_BRACES },
|
||||
{ "pp-environment", WARN_IDX_PP_ENVIRONMENT },
|
||||
{ "pp-macro-def-case-single", WARN_IDX_PP_MACRO_DEF_CASE_SINGLE },
|
||||
{ "pp-macro-def-greedy-single", WARN_IDX_PP_MACRO_DEF_GREEDY_SINGLE },
|
||||
{ "pp-macro-def-param-single", WARN_IDX_PP_MACRO_DEF_PARAM_SINGLE },
|
||||
{ "pp-macro-defaults", WARN_IDX_PP_MACRO_DEFAULTS },
|
||||
{ "pp-macro-params-legacy", WARN_IDX_PP_MACRO_PARAMS_LEGACY },
|
||||
{ "pp-macro-params-multi", WARN_IDX_PP_MACRO_PARAMS_MULTI },
|
||||
{ "pp-macro-params-single", WARN_IDX_PP_MACRO_PARAMS_SINGLE },
|
||||
{ "pp-macro-redef-multi", WARN_IDX_PP_MACRO_REDEF_MULTI },
|
||||
{ "pp-open-braces", WARN_IDX_PP_OPEN_BRACES },
|
||||
{ "pp-open-brackets", WARN_IDX_PP_OPEN_BRACKETS },
|
||||
{ "pp-open-string", WARN_IDX_PP_OPEN_STRING },
|
||||
{ "pp-rep-negative", WARN_IDX_PP_REP_NEGATIVE },
|
||||
{ "pp-reserved", WARN_IDX_PP_RESERVED },
|
||||
{ "pp-sel-range", WARN_IDX_PP_SEL_RANGE },
|
||||
{ "pp-trailing", WARN_IDX_PP_TRAILING },
|
||||
{ "pragma-bad", WARN_IDX_PRAGMA_BAD },
|
||||
{ "pragma-empty", WARN_IDX_PRAGMA_EMPTY },
|
||||
{ "pragma-na", WARN_IDX_PRAGMA_NA },
|
||||
{ "pragma-unknown", WARN_IDX_PRAGMA_UNKNOWN },
|
||||
{ "prefix-badmode-o64", WARN_IDX_PREFIX_BADMODE_O64 },
|
||||
{ "prefix-bnd", WARN_IDX_PREFIX_BND },
|
||||
{ "prefix-hint-dropped", WARN_IDX_PREFIX_HINT_DROPPED },
|
||||
{ "prefix-hle", WARN_IDX_PREFIX_HLE },
|
||||
{ "prefix-invalid", WARN_IDX_PREFIX_INVALID },
|
||||
{ "prefix-lock-error", WARN_IDX_PREFIX_LOCK_ERROR },
|
||||
{ "prefix-lock-xchg", WARN_IDX_PREFIX_LOCK_XCHG },
|
||||
{ "prefix-opsize", WARN_IDX_PREFIX_OPSIZE },
|
||||
{ "prefix-seg", WARN_IDX_PREFIX_SEG },
|
||||
{ "ptr", WARN_IDX_PTR },
|
||||
{ "regsize", WARN_IDX_REGSIZE },
|
||||
{ "reloc-abs-byte", WARN_IDX_RELOC_ABS_BYTE },
|
||||
{ "reloc-abs-dword", WARN_IDX_RELOC_ABS_DWORD },
|
||||
{ "reloc-abs-qword", WARN_IDX_RELOC_ABS_QWORD },
|
||||
{ "reloc-abs-word", WARN_IDX_RELOC_ABS_WORD },
|
||||
{ "reloc-rel-byte", WARN_IDX_RELOC_REL_BYTE },
|
||||
{ "reloc-rel-dword", WARN_IDX_RELOC_REL_DWORD },
|
||||
{ "reloc-rel-qword", WARN_IDX_RELOC_REL_QWORD },
|
||||
{ "reloc-rel-word", WARN_IDX_RELOC_REL_WORD },
|
||||
{ "section-alignment-rounded", WARN_IDX_SECTION_ALIGNMENT_ROUNDED },
|
||||
{ "unknown-pragma", WARN_IDX_PRAGMA_UNKNOWN },
|
||||
{ "unknown-warning", WARN_IDX_UNKNOWN_WARNING },
|
||||
{ "user", WARN_IDX_USER },
|
||||
{ "warn-stack-empty", WARN_IDX_WARN_STACK_EMPTY },
|
||||
{ "zeroing", WARN_IDX_ZEROING },
|
||||
{ "zext-reloc", WARN_IDX_ZEXT_RELOC }
|
||||
};
|
||||
|
||||
const char * const warning_help[70] = {
|
||||
NULL,
|
||||
"no operand for data declaration",
|
||||
"garbage after directive",
|
||||
"absolute address cannot be RIP-relative",
|
||||
"displacement size ignored on absolute address",
|
||||
"floating point denormal",
|
||||
"floating point overflow",
|
||||
"too many digits in floating-point number",
|
||||
"floating point underflow",
|
||||
"forward reference may have unpredictable results",
|
||||
"implicit DEFAULT ABS is deprecated",
|
||||
"labels alone on lines without trailing :",
|
||||
"label redefined to an identical value",
|
||||
"label (re)defined during code generation",
|
||||
"$ prefix for hexadecimal is deprecated",
|
||||
"numeric constant does not fit",
|
||||
"instruction obsolete and is a noop on the target CPU",
|
||||
"instruction obsolete and removed on the target CPU",
|
||||
"instruction obsolete but valid on the target CPU",
|
||||
"phase error during stabilization",
|
||||
"%elif after %else",
|
||||
"%else after %else",
|
||||
"empty %{} construct",
|
||||
"nonexistent environment variable",
|
||||
"single-line macro defined both case sensitive and insensitive",
|
||||
"single-line macro",
|
||||
"single-line macro defined with and without parameters",
|
||||
"macros with more default than optional parameters",
|
||||
"improperly calling multi-line macro for legacy support",
|
||||
"multi-line macro calls with wrong parameter count",
|
||||
"single-line macro calls with wrong parameter count",
|
||||
"redefining multi-line macro",
|
||||
"unterminated %{...}",
|
||||
"unterminated %[...]",
|
||||
"unterminated string",
|
||||
"negative %rep count",
|
||||
"reserved unimplemented preprocessor directive",
|
||||
"%sel() argument out of range",
|
||||
"trailing garbage ignored",
|
||||
"malformed %pragma",
|
||||
"empty %pragma directive",
|
||||
"%pragma not applicable to this compilation",
|
||||
"unknown %pragma facility or directive",
|
||||
"o64 prefix invalid in 16/32-bit mode",
|
||||
"invalid BND prefix",
|
||||
"invalid branch hint prefix dropped",
|
||||
"invalid HLE prefix",
|
||||
"invalid prefix for instruction",
|
||||
"LOCK prefix on unlockable instruction",
|
||||
"superfluous LOCK prefix on XCHG instruction",
|
||||
"invalid operand size prefix",
|
||||
"segment prefix ignored in 64-bit mode",
|
||||
"non-NASM keyword used in other assemblers",
|
||||
"register size specification ignored",
|
||||
"8-bit absolute section-crossing relocation",
|
||||
"32-bit absolute section-crossing relocation",
|
||||
"64-bit absolute section-crossing relocation",
|
||||
"16-bit absolute section-crossing relocation",
|
||||
"8-bit relative section-crossing relocation",
|
||||
"32-bit relative section-crossing relocation",
|
||||
"64-bit relative section-crossing relocation",
|
||||
"16-bit relative section-crossing relocation",
|
||||
"section alignment rounded up",
|
||||
"unknown warning in -W/-w or warning directive",
|
||||
"%warning directives",
|
||||
"warning stack empty",
|
||||
"RESx in initialized section becomes zero",
|
||||
"relocation zero-extended to match output format",
|
||||
"any warning not assigned to a specific warning class",
|
||||
"all possible warnings"
|
||||
};
|
||||
|
||||
const uint8_t warning_default[69] = {
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ERR,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ERR,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ERR,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ERR,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_OFF,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON,
|
||||
WARN_INIT_ON
|
||||
};
|
||||
|
||||
uint8_t warning_state[69]; /* Current state */
|
||||
75
include/watcom.h
Normal file
75
include/watcom.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* config/watcom.h
|
||||
*
|
||||
* Compiler definitions for OpenWatcom instead of config.h.in.
|
||||
* See config.h.in for the variables which can be defined here.
|
||||
*
|
||||
* This was taken from openwcom.mak and needs to be actually validated.
|
||||
*/
|
||||
|
||||
#ifndef NASM_CONFIG_WATCOM_H
|
||||
#define NASM_CONFIG_WATCOM_H
|
||||
|
||||
#define HAVE_DECL_STRCASECMP 1
|
||||
#define HAVE_DECL_STRICMP 1
|
||||
#define HAVE_DECL_STRLCPY 1
|
||||
#define HAVE_DECL_STRNCASECMP 1
|
||||
#define HAVE_DECL_STRNICMP 1
|
||||
#ifndef __LINUX__
|
||||
#define HAVE_IO_H 1
|
||||
#endif
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_MEMORY_H 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#if (__WATCOMC__ >= 1230)
|
||||
#undef HAVE__BOOL /* need stdbool.h */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_UINTPTR_T 1
|
||||
#endif
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRCSPN 1
|
||||
#define HAVE_STRICMP 1
|
||||
#define HAVE_STRNICMP 1
|
||||
#define HAVE_STRSPN 1
|
||||
#define HAVE_STRING_H 1
|
||||
#if (__WATCOMC__ >= 1240)
|
||||
#define HAVE_STRCASECMP 1
|
||||
#define HAVE_STRNCASECMP 1
|
||||
#define HAVE_STRLCPY 1
|
||||
#define HAVE_STRINGS_H 1
|
||||
#endif
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
#define HAVE__FULLPATH 1
|
||||
#define HAVE_ACCESS
|
||||
#define HAVE_STRUCT_STAT
|
||||
#define HAVE_STAT
|
||||
#define HAVE_FSTAT
|
||||
#define HAVE_FILENO
|
||||
#ifdef __LINUX__
|
||||
#define HAVE_FTRUNCATE
|
||||
#else
|
||||
#define HAVE_CHSIZE
|
||||
#define HAVE__CHSIZE
|
||||
#endif
|
||||
#define HAVE_ISASCII
|
||||
#define HAVE_ISCNTRL
|
||||
|
||||
#if (__WATCOMC__ >= 1250)
|
||||
#define restrict __restrict
|
||||
#else
|
||||
#define restrict
|
||||
#endif
|
||||
#define inline __inline
|
||||
|
||||
#endif /* NASM_CONFIG_WATCOM_H */
|
||||
14
include/x86const.h
Normal file
14
include/x86const.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef NASM_X86CONST_H
|
||||
#define NASM_X86CONST_H
|
||||
|
||||
/*
|
||||
* Values used for the DFV bits in the CCMPcc and CTESTcc instructions.
|
||||
*/
|
||||
enum dfv_mask {
|
||||
DFV_CF = 1,
|
||||
DFV_ZF = 2,
|
||||
DFV_SF = 4,
|
||||
DFV_OF = 8
|
||||
};
|
||||
|
||||
#endif /* NASM_X86CONST_H */
|
||||
6
include/zamenyator.h
Normal file
6
include/zamenyator.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef ZAMENYATOR_H
|
||||
#define ZAMENYATOR_H
|
||||
|
||||
const char *translate_insn(const char *insn);
|
||||
|
||||
#endif
|
||||
554
include/zconf.h
Normal file
554
include/zconf.h
Normal file
|
|
@ -0,0 +1,554 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#define HAVE_VSNPRINTF 1 /* If it doesn't exist we add it */
|
||||
#define Z_SOLO 1
|
||||
#define z_off_t off_t
|
||||
#define z_off64_t off_t
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
* Even better than compiling with -DZ_PREFIX would be to use configure to set
|
||||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols and init macros */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
# define _tr_tally z__tr_tally
|
||||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# define adler32_z z_adler32_z
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
# define crc32_combine_gen z_crc32_combine_gen
|
||||
# define crc32_combine_gen64 z_crc32_combine_gen64
|
||||
# define crc32_combine_op z_crc32_combine_op
|
||||
# define crc32_z z_crc32_z
|
||||
# define deflate z_deflate
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define deflateGetDictionary z_deflateGetDictionary
|
||||
# define deflateInit z_deflateInit
|
||||
# define deflateInit2 z_deflateInit2
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzfread z_gzfread
|
||||
# define gzfwrite z_gzfwrite
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# define gzopen_w z_gzopen_w
|
||||
# endif
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzseek64 z_gzseek64
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzvprintf z_gzvprintf
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define inflateBackInit z_inflateBackInit
|
||||
# define inflateBackInit_ z_inflateBackInit_
|
||||
# define inflateCodesUsed z_inflateCodesUsed
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define inflateGetDictionary z_inflateGetDictionary
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit z_inflateInit
|
||||
# define inflateInit2 z_inflateInit2
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflateMark z_inflateMark
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateResetKeep z_inflateResetKeep
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateUndermine z_inflateUndermine
|
||||
# define inflateValidate z_inflateValidate
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# define uncompress2 z_uncompress2
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
# define Byte z_Byte
|
||||
# define Bytef z_Bytef
|
||||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
# define intf z_intf
|
||||
# define out_func z_out_func
|
||||
# define uInt z_uInt
|
||||
# define uIntf z_uIntf
|
||||
# define uLong z_uLong
|
||||
# define uLongf z_uLongf
|
||||
# define voidp z_voidp
|
||||
# define voidpc z_voidpc
|
||||
# define voidpf z_voidpf
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
# define gz_header_s z_gz_header_s
|
||||
# define internal_state z_internal_state
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# define z_const
|
||||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
# ifdef _WIN64
|
||||
typedef unsigned long long z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
# endif
|
||||
#else
|
||||
# define z_longlong long long
|
||||
# if defined(NO_SIZE_T)
|
||||
typedef unsigned NO_SIZE_T z_size_t;
|
||||
# elif defined(STDC)
|
||||
# include <stddef.h>
|
||||
typedef size_t z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
# endif
|
||||
# undef z_longlong
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#if 0 /* NASM hack: this breaks stuff */
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
* though the former does not conform to the LFS document), but considering
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#ifndef Z_HAVE_UNISTD_H
|
||||
# ifdef __WATCOMC__
|
||||
# define Z_HAVE_UNISTD_H
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_HAVE_UNISTD_H
|
||||
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* NASM hack */
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
#pragma map(deflateInit_,"DEIN")
|
||||
#pragma map(deflateInit2_,"DEIN2")
|
||||
#pragma map(deflateEnd,"DEEND")
|
||||
#pragma map(deflateBound,"DEBND")
|
||||
#pragma map(inflateInit_,"ININ")
|
||||
#pragma map(inflateInit2_,"ININ2")
|
||||
#pragma map(inflateEnd,"INEND")
|
||||
#pragma map(inflateSync,"INSY")
|
||||
#pragma map(inflateSetDictionary,"INSEDI")
|
||||
#pragma map(compressBound,"CMBND")
|
||||
#pragma map(inflate_table,"INTABL")
|
||||
#pragma map(inflate_fast,"INFA")
|
||||
#pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
1939
include/zlib.h
Normal file
1939
include/zlib.h
Normal file
File diff suppressed because it is too large
Load diff
255
include/zutil.h
Normal file
255
include/zutil.h
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZUTIL_H
|
||||
#define ZUTIL_H
|
||||
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#if defined(STDC) && !defined(Z_SOLO)
|
||||
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* since "static" is used to mean two completely different things in C, we
|
||||
define "local" for the non-static meaning of "static", for readability
|
||||
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef uch FAR uchf;
|
||||
typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (ULONG_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned long
|
||||
# elif (ULLONG_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned long long
|
||||
# elif (UINT_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned
|
||||
# endif
|
||||
#endif
|
||||
|
||||
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
|
||||
#ifndef DEF_WBITS
|
||||
# define DEF_WBITS MAX_WBITS
|
||||
#endif
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
#define STORED_BLOCK 0
|
||||
#define STATIC_TREES 1
|
||||
#define DYN_TREES 2
|
||||
/* The three kinds of block type */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths */
|
||||
|
||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||
|
||||
/* target dependencies */
|
||||
|
||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||
# define OS_CODE 0x00
|
||||
# ifndef Z_SOLO
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
# define OS_CODE 1
|
||||
#endif
|
||||
|
||||
#if defined(VAXC) || defined(VMS)
|
||||
# define OS_CODE 2
|
||||
# define F_OPEN(name, mode) \
|
||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||
#endif
|
||||
|
||||
#ifdef __370__
|
||||
# if __TARGET_LIB__ < 0x20000000
|
||||
# define OS_CODE 4
|
||||
# elif __TARGET_LIB__ < 0x40000000
|
||||
# define OS_CODE 11
|
||||
# else
|
||||
# define OS_CODE 8
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ATARI) || defined(atarist)
|
||||
# define OS_CODE 5
|
||||
#endif
|
||||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 6
|
||||
# if defined(M_I86) && !defined(Z_SOLO)
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MACOS)
|
||||
# define OS_CODE 7
|
||||
#endif
|
||||
|
||||
#ifdef __acorn
|
||||
# define OS_CODE 13
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define OS_CODE 10
|
||||
#endif
|
||||
|
||||
#ifdef _BEOS_
|
||||
# define OS_CODE 16
|
||||
#endif
|
||||
|
||||
#ifdef __TOS_OS400__
|
||||
# define OS_CODE 18
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
# define OS_CODE 19
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(MSDOS)
|
||||
#pragma warn -8004
|
||||
#pragma warn -8008
|
||||
#pragma warn -8066
|
||||
#endif
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if 0 && /* NASM hack */ \
|
||||
!defined(_WIN32) && \
|
||||
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
|
||||
#endif
|
||||
|
||||
/* common defaults */
|
||||
|
||||
#ifndef OS_CODE
|
||||
# define OS_CODE 3 /* assume Unix */
|
||||
#endif
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
/* functions */
|
||||
|
||||
#if defined(pyr) || defined(Z_SOLO)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||
* You may have to use the same strategy for Borland C (untested).
|
||||
* The __SC__ check is for Symantec.
|
||||
*/
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||
# define zmemcpy _fmemcpy
|
||||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
# define zmemcpy memcpy
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
|
||||
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
|
||||
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
|
||||
#endif
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <stdio.h>
|
||||
extern int ZLIB_INTERNAL z_verbose;
|
||||
extern void ZLIB_INTERNAL z_error(char *m);
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||
#else
|
||||
# define Assert(cond,msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c,x)
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
#ifndef Z_SOLO
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
|
||||
unsigned size);
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
|
||||
#endif
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
/* Reverse the bytes in a 32-bit value */
|
||||
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||
|
||||
#endif /* ZUTIL_H */
|
||||
80
src/common/common.c
Normal file
80
src/common/common.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* common.c - code common to nasm and ndisasm
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasm.h"
|
||||
#include "nasmlib.h"
|
||||
#include "insns.h"
|
||||
|
||||
/*
|
||||
* Per-pass global (across segments) state
|
||||
*/
|
||||
struct globalopt globl;
|
||||
|
||||
void reset_global_defaults(int bits)
|
||||
{
|
||||
globl.bits = bits;
|
||||
globl.bnd = false;
|
||||
globl.rel = 0;
|
||||
globl.reldef = EAF_FS|EAF_GS;
|
||||
globl.dollarhex = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of a register token, if applicable; otherwise NULL
|
||||
*/
|
||||
const char *register_name(int token)
|
||||
{
|
||||
if (is_register(token))
|
||||
return nasm_reg_names[token - EXPR_REG_START];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Common list of prefix names; ideally should be auto-generated
|
||||
* from tokens.dat. This MUST match the enum in include/nasm.h.
|
||||
*/
|
||||
const char *prefix_name(int token)
|
||||
{
|
||||
static const char * const
|
||||
prefix_names[PREFIX_ENUM_LIMIT - PREFIX_ENUM_START] = {
|
||||
"a16", "a32", "a64", "asp", "lock", "o16", "o32", "o64", "osp",
|
||||
"rep", "repe", "repne", "repnz", "repz", "wait",
|
||||
"xacquire", "xrelease", "bnd", "nobnd", "{rex}", "{rex2}",
|
||||
"{evex}", "{vex}", "{vex3}", "{vex2}", "{nf}", "{zu}",
|
||||
"{pt}", "{pn}"
|
||||
};
|
||||
const char *name;
|
||||
|
||||
/* A register can also be a prefix */
|
||||
name = register_name(token);
|
||||
|
||||
if (!name) {
|
||||
const unsigned int prefix = token - PREFIX_ENUM_START;
|
||||
if (prefix < ARRAY_SIZE(prefix_names))
|
||||
name = prefix_names[prefix];
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* True for a valid hinting-NOP opcode, after 0F.
|
||||
*/
|
||||
bool is_hint_nop(uint64_t op)
|
||||
{
|
||||
if (op >> 16)
|
||||
return false;
|
||||
|
||||
if ((op >> 8) == 0x0f)
|
||||
op = (uint8_t)op;
|
||||
else if (op >> 8)
|
||||
return false;
|
||||
|
||||
return ((op & ~7) == 0x18) || (op == 0x0d);
|
||||
}
|
||||
109
src/common/errstubs.c
Normal file
109
src/common/errstubs.c
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "error.h"
|
||||
|
||||
struct errinfo erropt;
|
||||
|
||||
/* Common function body */
|
||||
#define nasm_do_error(_sev,_flags) \
|
||||
do { \
|
||||
const errflags nde_severity = (_sev); \
|
||||
const errflags nde_flags = nde_severity | (_flags); \
|
||||
va_list ap; \
|
||||
va_start(ap, fmt); \
|
||||
if (nde_severity >= ERR_CRITICAL) { \
|
||||
nasm_verror_critical(nde_flags, fmt, ap); \
|
||||
unreachable(); \
|
||||
} else { \
|
||||
nasm_verror(nde_flags, fmt, ap); \
|
||||
if (nde_severity >= ERR_FATAL) \
|
||||
unreachable(); \
|
||||
} \
|
||||
va_end(ap); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* This is the generic function to use when the error type is not
|
||||
* known a priori. For ERR_DEBUG and ERR_INFO the level can be
|
||||
* included by
|
||||
*/
|
||||
void nasm_error(errflags flags, const char *fmt, ...)
|
||||
{
|
||||
nasm_do_error(flags & ERR_MASK, flags);
|
||||
}
|
||||
|
||||
#define nasm_err_helpers(_type, _name, _sev) \
|
||||
_type nasm_ ## _name ## f (errflags flags, const char *fmt, ...) \
|
||||
{ \
|
||||
nasm_do_error(_sev, flags); \
|
||||
} \
|
||||
_type nasm_ ## _name (const char *fmt, ...) \
|
||||
{ \
|
||||
nasm_do_error(_sev, 0); \
|
||||
}
|
||||
|
||||
nasm_err_helpers(void, listmsg, ERR_LISTMSG)
|
||||
nasm_err_helpers(void, note, ERR_NOTE)
|
||||
nasm_err_helpers(void, nonfatal, ERR_NONFATAL)
|
||||
nasm_err_helpers(fatal_func, fatal, ERR_FATAL)
|
||||
nasm_err_helpers(fatal_func, critical, ERR_CRITICAL)
|
||||
nasm_err_helpers(fatal_func, panic, ERR_PANIC)
|
||||
|
||||
/*
|
||||
* Strongly discourage warnings without level by require flags on warnings.
|
||||
* This means nasm_warn() is the equivalent of the -f variants of the
|
||||
* other ones.
|
||||
*
|
||||
* This is wrapped in a macro to be able to elide it if the warning is
|
||||
* disabled, hence the extra underscore.
|
||||
*/
|
||||
void nasm_warn_(errflags flags, const char *fmt, ...)
|
||||
{
|
||||
nasm_do_error(ERR_WARNING, flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* nasm_info() and nasm_debug() takes mandatory enabling levels.
|
||||
*/
|
||||
void nasm_info_(unsigned int level, const char *fmt, ...)
|
||||
{
|
||||
if (info_level(level))
|
||||
nasm_do_error(ERR_INFO, LEVEL(level));
|
||||
}
|
||||
|
||||
void nasm_debug_(unsigned int level, const char *fmt, ...)
|
||||
{
|
||||
if (debug_level(level))
|
||||
nasm_do_error(ERR_DEBUG, LEVEL(level));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience function for nasm_nonfatal(ERR_HOLD, ...)
|
||||
*/
|
||||
void nasm_holderr(const char *fmt, ...)
|
||||
{
|
||||
nasm_do_error(ERR_NONFATAL, ERR_NONFATAL|ERR_HOLD);
|
||||
}
|
||||
|
||||
/*
|
||||
* panic() and nasm_assert()
|
||||
*/
|
||||
fatal_func nasm_panic_from_macro(const char *func, const char *file, int line)
|
||||
{
|
||||
if (!func)
|
||||
func = "<unknown>";
|
||||
|
||||
nasm_panic("internal error in %s at %s:%d\n", func, file, line);
|
||||
}
|
||||
|
||||
fatal_func nasm_assert_failed(const char *msg, const char *func,
|
||||
const char *file, int line)
|
||||
{
|
||||
if (!func)
|
||||
func = "<unknown>";
|
||||
|
||||
nasm_panic("assertion %s failed in %s at %s:%d", msg, func, file, line);
|
||||
}
|
||||
64
src/common/files.c
Normal file
64
src/common/files.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2026 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "files.h"
|
||||
#include "error.h"
|
||||
|
||||
static const char * const filename_names[FN_NFILES] = {
|
||||
"input",
|
||||
"output",
|
||||
"error",
|
||||
"list",
|
||||
"dependency"
|
||||
};
|
||||
|
||||
const char *_filenames[FN_NFILES];
|
||||
|
||||
const char *copy_filename(enum filenames fn, const char *src)
|
||||
{
|
||||
return set_filename(fn, nasm_strdup(src));
|
||||
}
|
||||
|
||||
const char *set_filename(enum filenames fn, char *src)
|
||||
{
|
||||
const char **dstp, *dst;
|
||||
nasm_assert((size_t)fn < ARRAY_SIZE(_filenames));
|
||||
|
||||
dstp = &_filenames[fn];
|
||||
dst = *dstp;
|
||||
|
||||
if (dst) {
|
||||
nasm_fatal("more than one %s file specified: %s and %s",
|
||||
filename_names[fn], dst, src);
|
||||
}
|
||||
|
||||
return *dstp = src;
|
||||
}
|
||||
|
||||
void check_overwrite_files(void)
|
||||
{
|
||||
enum filenames fn;
|
||||
const char *inname = get_filename(FN_INFILE);
|
||||
|
||||
if (!inname)
|
||||
return;
|
||||
|
||||
for (fn = FN_INFILE+1; fn < FN_NFILES; fn++) {
|
||||
const char *outname = get_filename(fn);
|
||||
if (outname && !strcmp(inname, outname)) {
|
||||
nasm_fatal("%s file would overwrite input file",
|
||||
filename_names[fn]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cleanup_filenames(void)
|
||||
{
|
||||
enum filenames fn;
|
||||
|
||||
for (fn = 0; fn < FN_NFILES; fn++) {
|
||||
nasm_free((char *)_filenames[fn]);
|
||||
_filenames[fn] = NULL;
|
||||
}
|
||||
}
|
||||
1800
src/disasm.c
Normal file
1800
src/disasm.c
Normal file
File diff suppressed because it is too large
Load diff
46
src/diserror.c
Normal file
46
src/diserror.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2025 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* diserror.c - stubs for the error functions for the disassembler
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
#include "error.h"
|
||||
#include "disasm.h"
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
const char help[] =
|
||||
"usage: ndisasm [-aihlruvw] [-b bits] [-o origin] [-s sync...]\n"
|
||||
" [-e bytes] [-k start,bytes] [-p vendor] file\n"
|
||||
" -a or -i activates auto (intelligent) sync\n"
|
||||
" -b 16, -b 32 or -b 64 sets the processor mode\n"
|
||||
" -u same as -b 32\n"
|
||||
" -l same as -b 64\n"
|
||||
" -w wide output (avoids continuation lines)\n"
|
||||
" -h displays this text\n"
|
||||
" -r or -v displays the version number\n"
|
||||
" -e skips <bytes> bytes of header\n"
|
||||
" -k avoids disassembling <bytes> bytes from position <start>\n"
|
||||
" -p selects the preferred vendor instruction set (intel, amd, cyrix, idt)\n";
|
||||
|
||||
fputs(help, stderr);
|
||||
}
|
||||
|
||||
void nasm_verror(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
severity &= ERR_MASK;
|
||||
|
||||
vfprintf(stderr, fmt, val);
|
||||
if (severity >= ERR_FATAL)
|
||||
exit(severity - ERR_FATAL + 1);
|
||||
}
|
||||
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
nasm_verror(severity, fmt, val);
|
||||
abort();
|
||||
}
|
||||
|
||||
uint8_t warning_state[NUM_WARNINGS];
|
||||
178
src/nasmlib/alloc.c
Normal file
178
src/nasmlib/alloc.c
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2019 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* nasmlib.c library routines for the Netwide Assembler
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "error.h"
|
||||
#include "alloc.h"
|
||||
|
||||
size_t _nasm_last_string_size;
|
||||
|
||||
fatal_func nasm_alloc_failed(void)
|
||||
{
|
||||
nasm_critical("out of memory!");
|
||||
}
|
||||
|
||||
void *nasm_malloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
again:
|
||||
p = malloc(size);
|
||||
|
||||
if (unlikely(!p)) {
|
||||
if (!size) {
|
||||
size = 1;
|
||||
goto again;
|
||||
}
|
||||
nasm_alloc_failed();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void *nasm_calloc(size_t nelem, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
again:
|
||||
p = calloc(nelem, size);
|
||||
|
||||
if (unlikely(!p)) {
|
||||
if (!nelem || !size) {
|
||||
nelem = size = 1;
|
||||
goto again;
|
||||
}
|
||||
nasm_alloc_failed();
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void *nasm_zalloc(size_t size)
|
||||
{
|
||||
return nasm_calloc(size, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike the system realloc, we do *not* allow size == 0 to be
|
||||
* the equivalent to free(); we guarantee returning a non-NULL pointer.
|
||||
*
|
||||
* The check for calling malloc() is theoretically redundant, but be
|
||||
* paranoid about the system library...
|
||||
*/
|
||||
void *nasm_realloc(void *q, size_t size)
|
||||
{
|
||||
if (unlikely(!size))
|
||||
size = 1;
|
||||
q = q ? realloc(q, size) : malloc(size);
|
||||
return validate_ptr(q);
|
||||
}
|
||||
|
||||
void nasm_free(void *q)
|
||||
{
|
||||
if (q)
|
||||
free(q);
|
||||
}
|
||||
|
||||
char *nasm_strdup(const char *s)
|
||||
{
|
||||
char *p;
|
||||
const size_t size = strlen(s) + 1;
|
||||
|
||||
_nasm_last_string_size = size;
|
||||
p = nasm_malloc(size);
|
||||
return memcpy(p, s, size);
|
||||
}
|
||||
|
||||
char *nasm_strndup(const char *s, size_t len)
|
||||
{
|
||||
char *p;
|
||||
|
||||
len = strnlen(s, len);
|
||||
_nasm_last_string_size = len + 1;
|
||||
p = nasm_malloc(len+1);
|
||||
p[len] = '\0';
|
||||
return memcpy(p, s, len);
|
||||
}
|
||||
|
||||
char *nasm_strdupto(char **ptrp, const char *str)
|
||||
{
|
||||
char *ptr = *ptrp;
|
||||
if (str) {
|
||||
if (ptr)
|
||||
nasm_free(ptr);
|
||||
*ptrp = ptr = nasm_strdup(str);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *nasm_strcat(const char *one, const char *two)
|
||||
{
|
||||
char *rslt;
|
||||
const size_t l1 = strlen(one);
|
||||
const size_t s2 = strlen(two) + 1;
|
||||
|
||||
_nasm_last_string_size = l1 + s2;
|
||||
rslt = nasm_malloc(l1 + s2);
|
||||
memcpy(rslt, one, l1);
|
||||
memcpy(rslt + l1, two, s2);
|
||||
return rslt;
|
||||
}
|
||||
|
||||
char *nasm_strcatn(const char *str1, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *rslt; /* Output buffer */
|
||||
size_t s; /* Total buffer size */
|
||||
size_t n; /* Number of arguments */
|
||||
size_t *ltbl; /* Table of lengths */
|
||||
size_t l, *lp; /* Length for current argument */
|
||||
const char *p; /* Currently examined argument */
|
||||
char *q; /* Output pointer */
|
||||
|
||||
n = 0; /* No strings encountered yet */
|
||||
p = str1;
|
||||
va_start(ap, str1);
|
||||
while (p) {
|
||||
n++;
|
||||
p = va_arg(ap, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
ltbl = nasm_malloc(n * sizeof(size_t));
|
||||
|
||||
s = 1; /* Space for final NULL */
|
||||
p = str1;
|
||||
lp = ltbl;
|
||||
va_start(ap, str1);
|
||||
while (p) {
|
||||
*lp++ = l = strlen(p);
|
||||
s += l;
|
||||
p = va_arg(ap, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
_nasm_last_string_size = s;
|
||||
|
||||
q = rslt = nasm_malloc(s);
|
||||
|
||||
p = str1;
|
||||
lp = ltbl;
|
||||
va_start(ap, str1);
|
||||
while (p) {
|
||||
l = *lp++;
|
||||
memcpy(q, p, l);
|
||||
q += l;
|
||||
p = va_arg(ap, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
*q = '\0';
|
||||
|
||||
nasm_free(ltbl);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
68
src/nasmlib/asprintf.c
Normal file
68
src/nasmlib/asprintf.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "alloc.h"
|
||||
|
||||
/*
|
||||
* nasm_[v]asprintf() are variants of the semi-standard [v]asprintf()
|
||||
* functions, except that we return the pointer instead of a count.
|
||||
* The length of the string (with or without the final NUL) is available
|
||||
* by calling nasm_last_string_{len,size}() afterwards.
|
||||
*
|
||||
* nasm_[v]axprintf() are similar, but allocates a user-defined amount
|
||||
* of storage before the string, and returns a pointer to the
|
||||
* allocated buffer. The size of that area is not included in the value
|
||||
* returned by nasm_last_string_size().
|
||||
*/
|
||||
|
||||
void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap)
|
||||
{
|
||||
char *strp;
|
||||
va_list xap;
|
||||
size_t bytes;
|
||||
int len;
|
||||
|
||||
va_copy(xap, ap);
|
||||
len = vsnprintf(NULL, 0, fmt, xap);
|
||||
nasm_assert(len >= 0);
|
||||
bytes = (size_t)len + 1;
|
||||
_nasm_last_string_size = bytes;
|
||||
va_end(xap);
|
||||
|
||||
strp = nasm_malloc(extra+bytes);
|
||||
memset(strp, 0, extra);
|
||||
len = vsnprintf(strp+extra, bytes, fmt, ap);
|
||||
nasm_assert(bytes == (size_t)len + 1);
|
||||
return strp;
|
||||
}
|
||||
|
||||
char *nasm_vasprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
return nasm_vaxprintf(0, fmt, ap);
|
||||
}
|
||||
|
||||
void *nasm_axprintf(size_t extra, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
void *strp;
|
||||
|
||||
va_start(ap, fmt);
|
||||
strp = nasm_vaxprintf(extra, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return strp;
|
||||
}
|
||||
|
||||
char *nasm_asprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *strp;
|
||||
|
||||
va_start(ap, fmt);
|
||||
strp = nasm_vaxprintf(0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return strp;
|
||||
}
|
||||
13
src/nasmlib/badenum.c
Normal file
13
src/nasmlib/badenum.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "nasmlib.h"
|
||||
|
||||
/* Used to avoid returning NULL to a debug printing function */
|
||||
const char *invalid_enum_str(int x)
|
||||
{
|
||||
static char buf[64];
|
||||
|
||||
snprintf(buf, sizeof buf, "<invalid %d>", x);
|
||||
return buf;
|
||||
}
|
||||
46
src/nasmlib/bsi.c
Normal file
46
src/nasmlib/bsi.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2016 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* nasmlib.c library routines for the Netwide Assembler
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
|
||||
#include "nasmlib.h"
|
||||
|
||||
/*
|
||||
* Binary search.
|
||||
*/
|
||||
int bsi(const char *string, const char **array, int size)
|
||||
{
|
||||
int i = -1, j = size; /* always, i < index < j */
|
||||
while (j - i >= 2) {
|
||||
int k = (i + j) / 2;
|
||||
int l = strcmp(string, array[k]);
|
||||
if (l < 0) /* it's in the first half */
|
||||
j = k;
|
||||
else if (l > 0) /* it's in the second half */
|
||||
i = k;
|
||||
else /* we've got it :) */
|
||||
return k;
|
||||
}
|
||||
return -1; /* we haven't got it :( */
|
||||
}
|
||||
|
||||
int bsii(const char *string, const char **array, int size)
|
||||
{
|
||||
int i = -1, j = size; /* always, i < index < j */
|
||||
while (j - i >= 2) {
|
||||
int k = (i + j) / 2;
|
||||
int l = nasm_stricmp(string, array[k]);
|
||||
if (l < 0) /* it's in the first half */
|
||||
j = k;
|
||||
else if (l > 0) /* it's in the second half */
|
||||
i = k;
|
||||
else /* we've got it :) */
|
||||
return k;
|
||||
}
|
||||
return -1; /* we haven't got it :( */
|
||||
}
|
||||
85
src/nasmlib/crc32b.c
Normal file
85
src/nasmlib/crc32b.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2021 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "hashtbl.h"
|
||||
|
||||
const uint32_t crc32_tab[256] = {
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
||||
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
|
||||
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
||||
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
|
||||
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
||||
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
|
||||
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
||||
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
|
||||
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
||||
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
|
||||
0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
||||
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
|
||||
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
||||
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
|
||||
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
|
||||
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
|
||||
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
||||
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
|
||||
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
||||
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
||||
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
|
||||
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
||||
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
|
||||
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
||||
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
|
||||
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
|
||||
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
||||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
|
||||
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
||||
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
|
||||
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
||||
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
||||
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
|
||||
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
||||
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
|
||||
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
||||
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
|
||||
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
|
||||
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
||||
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
|
||||
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
||||
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
|
||||
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
||||
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
|
||||
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
||||
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
|
||||
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
||||
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
|
||||
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
|
||||
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
|
||||
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
||||
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
|
||||
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
|
||||
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
||||
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
|
||||
};
|
||||
|
||||
uint32_t crc32b(uint32_t crc, const void *data, size_t len)
|
||||
{
|
||||
register const uint8_t *p = data;
|
||||
register uint32_t hashval = crc;
|
||||
|
||||
while (len--)
|
||||
{
|
||||
hashval = (hashval >> 8) ^ crc32_tab[(hashval ^ *p++) & 0xff];
|
||||
}
|
||||
|
||||
return hashval;
|
||||
}
|
||||
177
src/nasmlib/crc64.c
Normal file
177
src/nasmlib/crc64.c
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2014 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nctype.h"
|
||||
#include "hashtbl.h"
|
||||
|
||||
const uint64_t crc64_tab[256] = {
|
||||
UINT64_C(0x0000000000000000), UINT64_C(0x7ad870c830358979),
|
||||
UINT64_C(0xf5b0e190606b12f2), UINT64_C(0x8f689158505e9b8b),
|
||||
UINT64_C(0xc038e5739841b68f), UINT64_C(0xbae095bba8743ff6),
|
||||
UINT64_C(0x358804e3f82aa47d), UINT64_C(0x4f50742bc81f2d04),
|
||||
UINT64_C(0xab28ecb46814fe75), UINT64_C(0xd1f09c7c5821770c),
|
||||
UINT64_C(0x5e980d24087fec87), UINT64_C(0x24407dec384a65fe),
|
||||
UINT64_C(0x6b1009c7f05548fa), UINT64_C(0x11c8790fc060c183),
|
||||
UINT64_C(0x9ea0e857903e5a08), UINT64_C(0xe478989fa00bd371),
|
||||
UINT64_C(0x7d08ff3b88be6f81), UINT64_C(0x07d08ff3b88be6f8),
|
||||
UINT64_C(0x88b81eabe8d57d73), UINT64_C(0xf2606e63d8e0f40a),
|
||||
UINT64_C(0xbd301a4810ffd90e), UINT64_C(0xc7e86a8020ca5077),
|
||||
UINT64_C(0x4880fbd87094cbfc), UINT64_C(0x32588b1040a14285),
|
||||
UINT64_C(0xd620138fe0aa91f4), UINT64_C(0xacf86347d09f188d),
|
||||
UINT64_C(0x2390f21f80c18306), UINT64_C(0x594882d7b0f40a7f),
|
||||
UINT64_C(0x1618f6fc78eb277b), UINT64_C(0x6cc0863448deae02),
|
||||
UINT64_C(0xe3a8176c18803589), UINT64_C(0x997067a428b5bcf0),
|
||||
UINT64_C(0xfa11fe77117cdf02), UINT64_C(0x80c98ebf2149567b),
|
||||
UINT64_C(0x0fa11fe77117cdf0), UINT64_C(0x75796f2f41224489),
|
||||
UINT64_C(0x3a291b04893d698d), UINT64_C(0x40f16bccb908e0f4),
|
||||
UINT64_C(0xcf99fa94e9567b7f), UINT64_C(0xb5418a5cd963f206),
|
||||
UINT64_C(0x513912c379682177), UINT64_C(0x2be1620b495da80e),
|
||||
UINT64_C(0xa489f35319033385), UINT64_C(0xde51839b2936bafc),
|
||||
UINT64_C(0x9101f7b0e12997f8), UINT64_C(0xebd98778d11c1e81),
|
||||
UINT64_C(0x64b116208142850a), UINT64_C(0x1e6966e8b1770c73),
|
||||
UINT64_C(0x8719014c99c2b083), UINT64_C(0xfdc17184a9f739fa),
|
||||
UINT64_C(0x72a9e0dcf9a9a271), UINT64_C(0x08719014c99c2b08),
|
||||
UINT64_C(0x4721e43f0183060c), UINT64_C(0x3df994f731b68f75),
|
||||
UINT64_C(0xb29105af61e814fe), UINT64_C(0xc849756751dd9d87),
|
||||
UINT64_C(0x2c31edf8f1d64ef6), UINT64_C(0x56e99d30c1e3c78f),
|
||||
UINT64_C(0xd9810c6891bd5c04), UINT64_C(0xa3597ca0a188d57d),
|
||||
UINT64_C(0xec09088b6997f879), UINT64_C(0x96d1784359a27100),
|
||||
UINT64_C(0x19b9e91b09fcea8b), UINT64_C(0x636199d339c963f2),
|
||||
UINT64_C(0xdf7adabd7a6e2d6f), UINT64_C(0xa5a2aa754a5ba416),
|
||||
UINT64_C(0x2aca3b2d1a053f9d), UINT64_C(0x50124be52a30b6e4),
|
||||
UINT64_C(0x1f423fcee22f9be0), UINT64_C(0x659a4f06d21a1299),
|
||||
UINT64_C(0xeaf2de5e82448912), UINT64_C(0x902aae96b271006b),
|
||||
UINT64_C(0x74523609127ad31a), UINT64_C(0x0e8a46c1224f5a63),
|
||||
UINT64_C(0x81e2d7997211c1e8), UINT64_C(0xfb3aa75142244891),
|
||||
UINT64_C(0xb46ad37a8a3b6595), UINT64_C(0xceb2a3b2ba0eecec),
|
||||
UINT64_C(0x41da32eaea507767), UINT64_C(0x3b024222da65fe1e),
|
||||
UINT64_C(0xa2722586f2d042ee), UINT64_C(0xd8aa554ec2e5cb97),
|
||||
UINT64_C(0x57c2c41692bb501c), UINT64_C(0x2d1ab4dea28ed965),
|
||||
UINT64_C(0x624ac0f56a91f461), UINT64_C(0x1892b03d5aa47d18),
|
||||
UINT64_C(0x97fa21650afae693), UINT64_C(0xed2251ad3acf6fea),
|
||||
UINT64_C(0x095ac9329ac4bc9b), UINT64_C(0x7382b9faaaf135e2),
|
||||
UINT64_C(0xfcea28a2faafae69), UINT64_C(0x8632586aca9a2710),
|
||||
UINT64_C(0xc9622c4102850a14), UINT64_C(0xb3ba5c8932b0836d),
|
||||
UINT64_C(0x3cd2cdd162ee18e6), UINT64_C(0x460abd1952db919f),
|
||||
UINT64_C(0x256b24ca6b12f26d), UINT64_C(0x5fb354025b277b14),
|
||||
UINT64_C(0xd0dbc55a0b79e09f), UINT64_C(0xaa03b5923b4c69e6),
|
||||
UINT64_C(0xe553c1b9f35344e2), UINT64_C(0x9f8bb171c366cd9b),
|
||||
UINT64_C(0x10e3202993385610), UINT64_C(0x6a3b50e1a30ddf69),
|
||||
UINT64_C(0x8e43c87e03060c18), UINT64_C(0xf49bb8b633338561),
|
||||
UINT64_C(0x7bf329ee636d1eea), UINT64_C(0x012b592653589793),
|
||||
UINT64_C(0x4e7b2d0d9b47ba97), UINT64_C(0x34a35dc5ab7233ee),
|
||||
UINT64_C(0xbbcbcc9dfb2ca865), UINT64_C(0xc113bc55cb19211c),
|
||||
UINT64_C(0x5863dbf1e3ac9dec), UINT64_C(0x22bbab39d3991495),
|
||||
UINT64_C(0xadd33a6183c78f1e), UINT64_C(0xd70b4aa9b3f20667),
|
||||
UINT64_C(0x985b3e827bed2b63), UINT64_C(0xe2834e4a4bd8a21a),
|
||||
UINT64_C(0x6debdf121b863991), UINT64_C(0x1733afda2bb3b0e8),
|
||||
UINT64_C(0xf34b37458bb86399), UINT64_C(0x8993478dbb8deae0),
|
||||
UINT64_C(0x06fbd6d5ebd3716b), UINT64_C(0x7c23a61ddbe6f812),
|
||||
UINT64_C(0x3373d23613f9d516), UINT64_C(0x49aba2fe23cc5c6f),
|
||||
UINT64_C(0xc6c333a67392c7e4), UINT64_C(0xbc1b436e43a74e9d),
|
||||
UINT64_C(0x95ac9329ac4bc9b5), UINT64_C(0xef74e3e19c7e40cc),
|
||||
UINT64_C(0x601c72b9cc20db47), UINT64_C(0x1ac40271fc15523e),
|
||||
UINT64_C(0x5594765a340a7f3a), UINT64_C(0x2f4c0692043ff643),
|
||||
UINT64_C(0xa02497ca54616dc8), UINT64_C(0xdafce7026454e4b1),
|
||||
UINT64_C(0x3e847f9dc45f37c0), UINT64_C(0x445c0f55f46abeb9),
|
||||
UINT64_C(0xcb349e0da4342532), UINT64_C(0xb1eceec59401ac4b),
|
||||
UINT64_C(0xfebc9aee5c1e814f), UINT64_C(0x8464ea266c2b0836),
|
||||
UINT64_C(0x0b0c7b7e3c7593bd), UINT64_C(0x71d40bb60c401ac4),
|
||||
UINT64_C(0xe8a46c1224f5a634), UINT64_C(0x927c1cda14c02f4d),
|
||||
UINT64_C(0x1d148d82449eb4c6), UINT64_C(0x67ccfd4a74ab3dbf),
|
||||
UINT64_C(0x289c8961bcb410bb), UINT64_C(0x5244f9a98c8199c2),
|
||||
UINT64_C(0xdd2c68f1dcdf0249), UINT64_C(0xa7f41839ecea8b30),
|
||||
UINT64_C(0x438c80a64ce15841), UINT64_C(0x3954f06e7cd4d138),
|
||||
UINT64_C(0xb63c61362c8a4ab3), UINT64_C(0xcce411fe1cbfc3ca),
|
||||
UINT64_C(0x83b465d5d4a0eece), UINT64_C(0xf96c151de49567b7),
|
||||
UINT64_C(0x76048445b4cbfc3c), UINT64_C(0x0cdcf48d84fe7545),
|
||||
UINT64_C(0x6fbd6d5ebd3716b7), UINT64_C(0x15651d968d029fce),
|
||||
UINT64_C(0x9a0d8ccedd5c0445), UINT64_C(0xe0d5fc06ed698d3c),
|
||||
UINT64_C(0xaf85882d2576a038), UINT64_C(0xd55df8e515432941),
|
||||
UINT64_C(0x5a3569bd451db2ca), UINT64_C(0x20ed197575283bb3),
|
||||
UINT64_C(0xc49581ead523e8c2), UINT64_C(0xbe4df122e51661bb),
|
||||
UINT64_C(0x3125607ab548fa30), UINT64_C(0x4bfd10b2857d7349),
|
||||
UINT64_C(0x04ad64994d625e4d), UINT64_C(0x7e7514517d57d734),
|
||||
UINT64_C(0xf11d85092d094cbf), UINT64_C(0x8bc5f5c11d3cc5c6),
|
||||
UINT64_C(0x12b5926535897936), UINT64_C(0x686de2ad05bcf04f),
|
||||
UINT64_C(0xe70573f555e26bc4), UINT64_C(0x9ddd033d65d7e2bd),
|
||||
UINT64_C(0xd28d7716adc8cfb9), UINT64_C(0xa85507de9dfd46c0),
|
||||
UINT64_C(0x273d9686cda3dd4b), UINT64_C(0x5de5e64efd965432),
|
||||
UINT64_C(0xb99d7ed15d9d8743), UINT64_C(0xc3450e196da80e3a),
|
||||
UINT64_C(0x4c2d9f413df695b1), UINT64_C(0x36f5ef890dc31cc8),
|
||||
UINT64_C(0x79a59ba2c5dc31cc), UINT64_C(0x037deb6af5e9b8b5),
|
||||
UINT64_C(0x8c157a32a5b7233e), UINT64_C(0xf6cd0afa9582aa47),
|
||||
UINT64_C(0x4ad64994d625e4da), UINT64_C(0x300e395ce6106da3),
|
||||
UINT64_C(0xbf66a804b64ef628), UINT64_C(0xc5bed8cc867b7f51),
|
||||
UINT64_C(0x8aeeace74e645255), UINT64_C(0xf036dc2f7e51db2c),
|
||||
UINT64_C(0x7f5e4d772e0f40a7), UINT64_C(0x05863dbf1e3ac9de),
|
||||
UINT64_C(0xe1fea520be311aaf), UINT64_C(0x9b26d5e88e0493d6),
|
||||
UINT64_C(0x144e44b0de5a085d), UINT64_C(0x6e963478ee6f8124),
|
||||
UINT64_C(0x21c640532670ac20), UINT64_C(0x5b1e309b16452559),
|
||||
UINT64_C(0xd476a1c3461bbed2), UINT64_C(0xaeaed10b762e37ab),
|
||||
UINT64_C(0x37deb6af5e9b8b5b), UINT64_C(0x4d06c6676eae0222),
|
||||
UINT64_C(0xc26e573f3ef099a9), UINT64_C(0xb8b627f70ec510d0),
|
||||
UINT64_C(0xf7e653dcc6da3dd4), UINT64_C(0x8d3e2314f6efb4ad),
|
||||
UINT64_C(0x0256b24ca6b12f26), UINT64_C(0x788ec2849684a65f),
|
||||
UINT64_C(0x9cf65a1b368f752e), UINT64_C(0xe62e2ad306bafc57),
|
||||
UINT64_C(0x6946bb8b56e467dc), UINT64_C(0x139ecb4366d1eea5),
|
||||
UINT64_C(0x5ccebf68aecec3a1), UINT64_C(0x2616cfa09efb4ad8),
|
||||
UINT64_C(0xa97e5ef8cea5d153), UINT64_C(0xd3a62e30fe90582a),
|
||||
UINT64_C(0xb0c7b7e3c7593bd8), UINT64_C(0xca1fc72bf76cb2a1),
|
||||
UINT64_C(0x45775673a732292a), UINT64_C(0x3faf26bb9707a053),
|
||||
UINT64_C(0x70ff52905f188d57), UINT64_C(0x0a2722586f2d042e),
|
||||
UINT64_C(0x854fb3003f739fa5), UINT64_C(0xff97c3c80f4616dc),
|
||||
UINT64_C(0x1bef5b57af4dc5ad), UINT64_C(0x61372b9f9f784cd4),
|
||||
UINT64_C(0xee5fbac7cf26d75f), UINT64_C(0x9487ca0fff135e26),
|
||||
UINT64_C(0xdbd7be24370c7322), UINT64_C(0xa10fceec0739fa5b),
|
||||
UINT64_C(0x2e675fb4576761d0), UINT64_C(0x54bf2f7c6752e8a9),
|
||||
UINT64_C(0xcdcf48d84fe75459), UINT64_C(0xb71738107fd2dd20),
|
||||
UINT64_C(0x387fa9482f8c46ab), UINT64_C(0x42a7d9801fb9cfd2),
|
||||
UINT64_C(0x0df7adabd7a6e2d6), UINT64_C(0x772fdd63e7936baf),
|
||||
UINT64_C(0xf8474c3bb7cdf024), UINT64_C(0x829f3cf387f8795d),
|
||||
UINT64_C(0x66e7a46c27f3aa2c), UINT64_C(0x1c3fd4a417c62355),
|
||||
UINT64_C(0x935745fc4798b8de), UINT64_C(0xe98f353477ad31a7),
|
||||
UINT64_C(0xa6df411fbfb21ca3), UINT64_C(0xdc0731d78f8795da),
|
||||
UINT64_C(0x536fa08fdfd90e51), UINT64_C(0x29b7d047efec8728),
|
||||
};
|
||||
|
||||
uint64_t crc64(uint64_t crc, const char *str)
|
||||
{
|
||||
uint8_t c;
|
||||
|
||||
while ((c = *str++) != 0)
|
||||
crc = crc64_byte(crc, c);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint64_t crc64i(uint64_t crc, const char *str)
|
||||
{
|
||||
uint8_t c;
|
||||
|
||||
while ((c = *str++) != 0)
|
||||
crc = crc64_byte(crc, nasm_tolower(c));
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint64_t crc64b(uint64_t crc, const void *data, size_t len)
|
||||
{
|
||||
const uint8_t *str = data;
|
||||
|
||||
while (len--)
|
||||
crc = crc64_byte(crc, *str++);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint64_t crc64ib(uint64_t crc, const void *data, size_t len)
|
||||
{
|
||||
const uint8_t *str = data;
|
||||
|
||||
while (len--)
|
||||
crc = crc64_byte(crc, nasm_tolower(*str++));
|
||||
|
||||
return crc;
|
||||
}
|
||||
427
src/nasmlib/file.c
Normal file
427
src/nasmlib/file.c
Normal file
|
|
@ -0,0 +1,427 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "error.h"
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef R_OK
|
||||
# define R_OK 4 /* Classic Unix constant, same on Windows */
|
||||
#endif
|
||||
|
||||
#ifdef S_ISREG
|
||||
/* all good */
|
||||
#elif defined(HAVE_S_ISREG)
|
||||
/* exists, but not a macro */
|
||||
# define S_ISREG S_ISREG
|
||||
#elif defined(S_IFMT) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#elif defined(_S_IFMT) && defined(_S_IFREG)
|
||||
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* On Windows, we want to use _wfopen(), as fopen() has a much smaller limit
|
||||
* on the path length that it supports.
|
||||
*
|
||||
* Previously we tried to prefix the path name with \\?\ in order to
|
||||
* let the Windows kernel know that we are not limited to PATH_MAX
|
||||
* characters, but it breaks relative paths among other things, and
|
||||
* apparently Windows 10 contains a registry option to override this
|
||||
* limit anyway... but only for the wide character interfaces.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#include <wchar.h>
|
||||
#include <stringapiset.h>
|
||||
|
||||
typedef wchar_t *os_filename;
|
||||
typedef wchar_t os_fopenflag;
|
||||
|
||||
static os_filename os_mangle_filename(const char *filename)
|
||||
{
|
||||
size_t wclen;
|
||||
wchar_t *buf;
|
||||
|
||||
wclen = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, filename,
|
||||
-1, NULL, 0);
|
||||
if (!wclen)
|
||||
return NULL;
|
||||
|
||||
/* wclen is in "characters" (UTF-16 code points) */
|
||||
buf = nasm_malloc(wclen << 1);
|
||||
|
||||
wclen = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, filename,
|
||||
-1, buf, wclen);
|
||||
if (!wclen) {
|
||||
nasm_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline void os_free_filename(os_filename filename)
|
||||
{
|
||||
nasm_free(filename);
|
||||
}
|
||||
|
||||
# define os_fopen _wfopen
|
||||
# define os_access _waccess
|
||||
# define os_remove _wremove
|
||||
|
||||
/*
|
||||
* On Win32/64, we have to use the _wstati64() function. Note that
|
||||
* we can't use _wstat64() without depending on a needlessly new
|
||||
* version os MSVCRT.
|
||||
*/
|
||||
|
||||
typedef struct _stati64 os_struct_stat;
|
||||
|
||||
# define os_stat _wstati64
|
||||
# define os_fstat _fstati64
|
||||
|
||||
static inline void os_set_binary_mode(FILE *f) {
|
||||
int ret = _setmode(_fileno(f), _O_BINARY);
|
||||
|
||||
if (ret == -1) {
|
||||
nasm_fatalf(ERR_NOFILE, "unable to set file mode to binary: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
#else /* not _WIN32 */
|
||||
|
||||
typedef const char *os_filename;
|
||||
typedef char os_fopenflag;
|
||||
|
||||
static inline os_filename os_mangle_filename(const char *filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
static inline void os_free_filename(os_filename filename)
|
||||
{
|
||||
(void)filename; /* Nothing to do */
|
||||
}
|
||||
|
||||
static inline void os_set_binary_mode(FILE *f) {
|
||||
(void)f;
|
||||
}
|
||||
|
||||
# define os_fopen fopen
|
||||
# define os_remove remove
|
||||
|
||||
#if defined(HAVE_FACCESSAT) && defined(AT_EACCESS)
|
||||
static inline int os_access(os_filename pathname, int mode)
|
||||
{
|
||||
return faccessat(AT_FDCWD, pathname, mode, AT_EACCESS);
|
||||
}
|
||||
# define os_access os_access
|
||||
#elif defined(HAVE_ACCESS)
|
||||
# define os_access access
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRUCT_STAT
|
||||
typedef struct stat os_struct_stat;
|
||||
# ifdef HAVE_STAT
|
||||
# define os_stat stat
|
||||
# endif
|
||||
# ifdef HAVE_FSTAT
|
||||
# define os_fstat fstat
|
||||
# endif
|
||||
#else
|
||||
struct dummy_struct_stat {
|
||||
int st_mode;
|
||||
int st_size;
|
||||
};
|
||||
typedef struct dummy_struct_stat os_struct_stat;
|
||||
#endif
|
||||
|
||||
#endif /* Not _WIN32 */
|
||||
|
||||
#ifdef fileno
|
||||
/* all good */
|
||||
#elif defined(HAVE_FILENO)
|
||||
/* exists, but not a macro */
|
||||
# define fileno fileno
|
||||
#elif defined(_fileno) || defined(HAVE__FILENO)
|
||||
# define fileno _fileno
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
# undef os_stat
|
||||
# undef os_fstat
|
||||
#endif
|
||||
|
||||
/* Disable these functions if they don't support something we need */
|
||||
#ifndef fileno
|
||||
# undef os_fstat
|
||||
# undef os_ftruncate
|
||||
# undef HAVE_MMAP
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If we don't have functional versions of these functions,
|
||||
* stub them out so we don't need so many #ifndefs
|
||||
*/
|
||||
#ifndef os_stat
|
||||
static inline int os_stat(os_filename osfname, os_struct_stat *st)
|
||||
{
|
||||
(void)osfname;
|
||||
(void)st;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef os_fstat
|
||||
static inline int os_fstat(int fd, os_struct_stat *st)
|
||||
{
|
||||
(void)fd;
|
||||
(void)st;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
static inline bool S_ISREG(int m)
|
||||
{
|
||||
(void)m;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nasm_set_binary_mode(FILE *f)
|
||||
{
|
||||
os_set_binary_mode(f);
|
||||
}
|
||||
|
||||
FILE *nasm_open_read(const char *filename, enum file_flags flags)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
os_filename osfname;
|
||||
|
||||
osfname = os_mangle_filename(filename);
|
||||
if (osfname) {
|
||||
os_fopenflag fopen_flags[4];
|
||||
memset(fopen_flags, 0, sizeof fopen_flags);
|
||||
|
||||
fopen_flags[0] = 'r';
|
||||
fopen_flags[1] = (flags & NF_TEXT) ? 't' : 'b';
|
||||
|
||||
#if defined(__GLIBC__) || defined(__linux__)
|
||||
/*
|
||||
* Try to open this file with memory mapping for speed, unless we are
|
||||
* going to do it "manually" with nasm_map_file()
|
||||
*/
|
||||
if (!(flags & NF_FORMAP))
|
||||
fopen_flags[2] = 'm';
|
||||
#endif
|
||||
|
||||
while (true) {
|
||||
f = os_fopen(osfname, fopen_flags);
|
||||
if (f || errno != EINVAL || !fopen_flags[2])
|
||||
break;
|
||||
|
||||
/* We got EINVAL but with 'm'; try again without 'm' */
|
||||
fopen_flags[2] = '\0';
|
||||
}
|
||||
|
||||
os_free_filename(osfname);
|
||||
}
|
||||
|
||||
if (!f && (flags & NF_FATAL))
|
||||
nasm_fatalf(ERR_NOFILE, "unable to open input file: `%s': %s",
|
||||
filename, strerror(errno));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
FILE *nasm_open_write(const char *filename, enum file_flags flags)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
os_filename osfname;
|
||||
|
||||
osfname = os_mangle_filename(filename);
|
||||
if (osfname) {
|
||||
os_fopenflag fopen_flags[3];
|
||||
|
||||
fopen_flags[0] = 'w';
|
||||
fopen_flags[1] = (flags & NF_TEXT) ? 't' : 'b';
|
||||
fopen_flags[2] = '\0';
|
||||
|
||||
f = os_fopen(osfname, fopen_flags);
|
||||
os_free_filename(osfname);
|
||||
}
|
||||
|
||||
if (!f && (flags & NF_FATAL))
|
||||
nasm_fatalf(ERR_NOFILE, "unable to open output file: `%s': %s",
|
||||
filename, strerror(errno));
|
||||
|
||||
switch (flags & NF_BUF_MASK) {
|
||||
case NF_IONBF:
|
||||
setvbuf(f, NULL, _IONBF, 0);
|
||||
break;
|
||||
case NF_IOLBF:
|
||||
setvbuf(f, NULL, _IOLBF, 0);
|
||||
break;
|
||||
case NF_IOFBF:
|
||||
setvbuf(f, NULL, _IOFBF, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* The appropriate "rb" strings for os_fopen() */
|
||||
static const os_fopenflag fopenflags_rb[3] = { 'r', 'b', 0 };
|
||||
|
||||
/*
|
||||
* Report the existence of a file
|
||||
*/
|
||||
bool nasm_file_exists(const char *filename)
|
||||
{
|
||||
#ifndef os_access
|
||||
FILE *f;
|
||||
#endif
|
||||
os_filename osfname;
|
||||
bool exists;
|
||||
|
||||
osfname = os_mangle_filename(filename);
|
||||
if (!osfname)
|
||||
return false;
|
||||
|
||||
#ifdef os_access
|
||||
exists = os_access(osfname, R_OK) == 0;
|
||||
#else
|
||||
f = os_fopen(osfname, fopenflags_rb);
|
||||
exists = f != NULL;
|
||||
if (f)
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
os_free_filename(osfname);
|
||||
return exists;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report the file size of an open file. This MAY move the file pointer.
|
||||
*/
|
||||
off_t nasm_file_size(FILE *f)
|
||||
{
|
||||
off_t where, end;
|
||||
os_struct_stat st;
|
||||
|
||||
if (!os_fstat(fileno(f), &st) && S_ISREG(st.st_mode))
|
||||
return st.st_size;
|
||||
|
||||
/* Do it the hard way... this tests for seekability */
|
||||
|
||||
if (fseeko(f, 0, SEEK_CUR))
|
||||
goto fail; /* Not seekable, don't even try */
|
||||
|
||||
where = ftello(f);
|
||||
if (where == (off_t)-1)
|
||||
goto fail;
|
||||
|
||||
if (fseeko(f, 0, SEEK_END))
|
||||
goto fail;
|
||||
|
||||
end = ftello(f);
|
||||
if (end == (off_t)-1)
|
||||
goto fail;
|
||||
|
||||
/*
|
||||
* Move the file pointer back. If this fails, this is probably
|
||||
* not a plain file.
|
||||
*/
|
||||
if (fseeko(f, where, SEEK_SET))
|
||||
goto fail;
|
||||
|
||||
return end;
|
||||
|
||||
fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report file size given pathname
|
||||
*/
|
||||
off_t nasm_file_size_by_path(const char *pathname)
|
||||
{
|
||||
os_filename osfname;
|
||||
off_t len = -1;
|
||||
os_struct_stat st;
|
||||
FILE *fp;
|
||||
|
||||
osfname = os_mangle_filename(pathname);
|
||||
|
||||
if (!os_stat(osfname, &st) && S_ISREG(st.st_mode))
|
||||
len = st.st_size;
|
||||
|
||||
fp = os_fopen(osfname, fopenflags_rb);
|
||||
if (fp) {
|
||||
len = nasm_file_size(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report the timestamp on a file, returns true if successful
|
||||
*/
|
||||
bool nasm_file_time(time_t *t, const char *pathname)
|
||||
{
|
||||
#ifdef os_stat
|
||||
os_filename osfname;
|
||||
os_struct_stat st;
|
||||
bool rv = false;
|
||||
|
||||
osfname = os_mangle_filename(pathname);
|
||||
if (!osfname)
|
||||
return false;
|
||||
|
||||
rv = !os_stat(osfname, &st);
|
||||
*t = st.st_mtime;
|
||||
os_free_filename(osfname);
|
||||
|
||||
return rv;
|
||||
#else
|
||||
return false; /* No idea how to do this on this OS */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a file (allows NULL as input -> do nothing)
|
||||
*/
|
||||
int nasm_remove(const char *pathname)
|
||||
{
|
||||
int rv;
|
||||
os_filename osfname;
|
||||
|
||||
if (!pathname || !*pathname)
|
||||
return 0;
|
||||
|
||||
osfname = os_mangle_filename(pathname);
|
||||
if (!osfname)
|
||||
return false;
|
||||
|
||||
rv = os_remove(osfname);
|
||||
os_free_filename(osfname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
91
src/nasmlib/fileio.c
Normal file
91
src/nasmlib/fileio.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2017 The NASM Authors - All Rights Reserved */
|
||||
|
||||
#include "compiler.h"
|
||||
#include "nasmlib.h"
|
||||
#include "error.h"
|
||||
|
||||
void nasm_read(void *ptr, size_t size, FILE *f)
|
||||
{
|
||||
size_t n = fread(ptr, 1, size, f);
|
||||
if (ferror(f)) {
|
||||
nasm_fatal("unable to read input: %s", strerror(errno));
|
||||
} else if (n != size || feof(f)) {
|
||||
nasm_fatal("fatal short read on input");
|
||||
}
|
||||
}
|
||||
|
||||
void nasm_write(const void *ptr, size_t size, FILE *f)
|
||||
{
|
||||
size_t n = fwrite(ptr, 1, size, f);
|
||||
if (n != size || ferror(f) || feof(f))
|
||||
nasm_fatal("unable to write output: %s", strerror(errno));
|
||||
}
|
||||
|
||||
void fwriteint16_t(uint16_t data, FILE * fp)
|
||||
{
|
||||
data = htole16(data);
|
||||
nasm_write(&data, 2, fp);
|
||||
}
|
||||
|
||||
void fwriteint32_t(uint32_t data, FILE * fp)
|
||||
{
|
||||
data = htole32(data);
|
||||
nasm_write(&data, 4, fp);
|
||||
}
|
||||
|
||||
void fwriteint64_t(uint64_t data, FILE * fp)
|
||||
{
|
||||
data = htole64(data);
|
||||
nasm_write(&data, 8, fp);
|
||||
}
|
||||
|
||||
void fwriteaddr(uint64_t data, int size, FILE * fp)
|
||||
{
|
||||
data = htole64(data);
|
||||
nasm_write(&data, size, fp);
|
||||
}
|
||||
|
||||
/* Can we adjust the file size without actually writing all the bytes? */
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE__CHSIZE_S
|
||||
# define os_ftruncate(fd,size) _chsize_s(fd,size)
|
||||
#elif defined(HAVE__CHSIZE)
|
||||
# define os_ftruncate(fd,size) _chsize(fd,size)
|
||||
#elif defined(HAVE_FTRUNCATE)
|
||||
# define os_ftruncate(fd,size) ftruncate(fd,size)
|
||||
#endif
|
||||
|
||||
void fwritezero(off_t bytes, FILE *fp)
|
||||
{
|
||||
size_t blksize;
|
||||
|
||||
#ifdef os_ftruncate
|
||||
if (bytes >= BUFSIZ && !ferror(fp) && !feof(fp)) {
|
||||
off_t pos = ftello(fp);
|
||||
if (pos != (off_t)-1) {
|
||||
off_t end = pos + bytes;
|
||||
if (!fflush(fp) && !os_ftruncate(fileno(fp), end)) {
|
||||
fseeko(fp, 0, SEEK_END);
|
||||
pos = ftello(fp);
|
||||
if (pos != (off_t)-1)
|
||||
bytes = end - pos; /* This SHOULD be zero */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (bytes > 0) {
|
||||
blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE;
|
||||
|
||||
nasm_write(zero_buffer, blksize, fp);
|
||||
bytes -= blksize;
|
||||
}
|
||||
}
|
||||
261
src/nasmlib/hashtbl.c
Normal file
261
src/nasmlib/hashtbl.c
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
/* Copyright 1996-2018 The NASM Authors - All Rights Reserved */
|
||||
|
||||
/*
|
||||
* hashtbl.c
|
||||
*
|
||||
* Efficient dictionary hash table class.
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#include "nasm.h"
|
||||
#include "hashtbl.h"
|
||||
|
||||
#define HASH_MAX_LOAD 2 /* Higher = more memory-efficient, slower */
|
||||
#define HASH_INIT_SIZE 16 /* Initial size (power of 2, min 4) */
|
||||
|
||||
#define hash_calc(key,keylen) crc64b(CRC64_INIT, (key), (keylen))
|
||||
#define hash_calci(key,keylen) crc64ib(CRC64_INIT, (key), (keylen))
|
||||
#define hash_max_load(size) ((size) * (HASH_MAX_LOAD - 1) / HASH_MAX_LOAD)
|
||||
#define hash_expand(size) ((size) << 1)
|
||||
#define hash_mask(size) ((size) - 1)
|
||||
#define hash_pos(hash, mask) ((hash) & (mask))
|
||||
#define hash_inc(hash, mask) ((((hash) >> 32) & (mask)) | 1) /* always odd */
|
||||
#define hash_pos_next(pos, inc, mask) (((pos) + (inc)) & (mask))
|
||||
|
||||
static void hash_init(struct hash_table *head)
|
||||
{
|
||||
head->size = HASH_INIT_SIZE;
|
||||
head->load = 0;
|
||||
head->max_load = hash_max_load(head->size);
|
||||
nasm_newn(head->table, head->size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find an entry in a hash table. The key can be any binary object.
|
||||
*
|
||||
* On failure, if "insert" is non-NULL, store data in that structure
|
||||
* which can be used to insert that node using hash_add().
|
||||
* See hash_add() for constraints on the uses of the insert object.
|
||||
*
|
||||
* On success, return a pointer to the "data" element of the hash
|
||||
* structure.
|
||||
*/
|
||||
void **hash_findb(struct hash_table *head, const void *key,
|
||||
size_t keylen, struct hash_insert *insert)
|
||||
{
|
||||
struct hash_node *np = NULL;
|
||||
struct hash_node *tbl = head->table;
|
||||
uint64_t hash = hash_calc(key, keylen);
|
||||
size_t mask = hash_mask(head->size);
|
||||
size_t pos = hash_pos(hash, mask);
|
||||
size_t inc = hash_inc(hash, mask);
|
||||
|
||||
if (likely(tbl)) {
|
||||
while ((np = &tbl[pos])->key) {
|
||||
if (hash == np->hash &&
|
||||
keylen == np->keylen &&
|
||||
!memcmp(key, np->key, keylen))
|
||||
return &np->data;
|
||||
pos = hash_pos_next(pos, inc, mask);
|
||||
}
|
||||
}
|
||||
|
||||
/* Not found. Store info for insert if requested. */
|
||||
if (insert) {
|
||||
insert->node.hash = hash;
|
||||
insert->node.key = key;
|
||||
insert->node.keylen = keylen;
|
||||
insert->node.data = NULL;
|
||||
insert->head = head;
|
||||
insert->where = np;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Same as hash_findb(), but for a C string.
|
||||
*/
|
||||
void **hash_find(struct hash_table *head, const char *key,
|
||||
struct hash_insert *insert)
|
||||
{
|
||||
prefetch(key);
|
||||
|
||||
return hash_findb(head, key, strlen(key)+1, insert);
|
||||
}
|
||||
|
||||
/*
|
||||
* Same as hash_findb(), but for case-insensitive hashing.
|
||||
*/
|
||||
void **hash_findib(struct hash_table *head, const void *key, size_t keylen,
|
||||
struct hash_insert *insert)
|
||||
{
|
||||
struct hash_node *np = NULL;
|
||||
struct hash_node *tbl = head->table;
|
||||
uint64_t hash = hash_calci(key, keylen);
|
||||
size_t mask = hash_mask(head->size);
|
||||
size_t pos = hash_pos(hash, mask);
|
||||
size_t inc = hash_inc(hash, mask);
|
||||
|
||||
if (likely(tbl)) {
|
||||
while ((np = &tbl[pos])->key) {
|
||||
if (hash == np->hash &&
|
||||
keylen == np->keylen &&
|
||||
!nasm_memicmp(key, np->key, keylen))
|
||||
return &np->data;
|
||||
pos = hash_pos_next(pos, inc, mask);
|
||||
}
|
||||
}
|
||||
|
||||
/* Not found. Store info for insert if requested. */
|
||||
if (insert) {
|
||||
insert->node.hash = hash;
|
||||
insert->node.key = key;
|
||||
insert->node.keylen = keylen;
|
||||
insert->node.data = NULL;
|
||||
insert->head = head;
|
||||
insert->where = np;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Same as hash_find(), but for case-insensitive hashing.
|
||||
*/
|
||||
void **hash_findi(struct hash_table *head, const char *key,
|
||||
struct hash_insert *insert)
|
||||
{
|
||||
prefetch(key);
|
||||
|
||||
return hash_findib(head, key, strlen(key)+1, insert);
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert node. Return a pointer to the "data" element of the newly
|
||||
* created hash node.
|
||||
*
|
||||
* The following constraints apply:
|
||||
* 1. A call to hash_add() invalidates all other outstanding hash_insert
|
||||
* objects; attempting to use them causes a wild pointer reference.
|
||||
* 2. The key provided must exactly match the key passed to hash_find*(),
|
||||
* but it does not have to point to the same storage address. The key
|
||||
* buffer provided to this function must not be freed for the lifespan
|
||||
* of the hash. NULL will use the same pointer that was passed to
|
||||
* hash_find*().
|
||||
*/
|
||||
void **hash_add(struct hash_insert *insert, const void *key, void *data)
|
||||
{
|
||||
struct hash_table *head = insert->head;
|
||||
struct hash_node *np = insert->where;
|
||||
|
||||
if (unlikely(!np)) {
|
||||
hash_init(head);
|
||||
/* The hash table is empty, so we don't need to iterate here */
|
||||
np = &head->table[hash_pos(insert->node.hash, hash_mask(head->size))];
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert node. We can always do this, even if we need to
|
||||
* rebalance immediately after.
|
||||
*/
|
||||
*np = insert->node;
|
||||
np->data = data;
|
||||
if (key)
|
||||
np->key = key;
|
||||
|
||||
if (unlikely(++head->load > head->max_load)) {
|
||||
/* Need to expand the table */
|
||||
size_t newsize = hash_expand(head->size);
|
||||
struct hash_node *newtbl;
|
||||
size_t mask = hash_mask(newsize);
|
||||
struct hash_node *op, *xp;
|
||||
size_t i;
|
||||
|
||||
nasm_newn(newtbl, newsize);
|
||||
|
||||
/* Rebalance all the entries */
|
||||
for (i = 0, op = head->table; i < head->size; i++, op++) {
|
||||
if (op->key) {
|
||||
size_t pos = hash_pos(op->hash, mask);
|
||||
size_t inc = hash_inc(op->hash, mask);
|
||||
|
||||
while ((xp = &newtbl[pos])->key)
|
||||
pos = hash_pos_next(pos, inc, mask);
|
||||
|
||||
*xp = *op;
|
||||
if (op == np)
|
||||
np = xp;
|
||||
}
|
||||
}
|
||||
nasm_free(head->table);
|
||||
|
||||
head->table = newtbl;
|
||||
head->size = newsize;
|
||||
head->max_load = hash_max_load(newsize);
|
||||
}
|
||||
|
||||
return &np->data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over all members of a hash set. For the first call, iter
|
||||
* should be as initialized by hash_iterator_init(). Returns a struct
|
||||
* hash_node representing the current object, or NULL if we have
|
||||
* reached the end of the hash table.
|
||||
*
|
||||
* Calling hash_add() will invalidate the iterator.
|
||||
*/
|
||||
const struct hash_node *hash_iterate(struct hash_iterator *iter)
|
||||
{
|
||||
const struct hash_table *head = iter->head;
|
||||
const struct hash_node *cp = iter->next;
|
||||
const struct hash_node *ep = head->table + head->size;
|
||||
|
||||
/* For an empty table, cp == ep == NULL */
|
||||
while (cp < ep) {
|
||||
if (cp->key) {
|
||||
iter->next = cp+1;
|
||||
return cp;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
iter->next = head->table;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the hash itself. Doesn't free the data elements; use
|
||||
* hash_iterate() to do that first, if needed. This function is normally
|
||||
* used when the hash data entries are either freed separately, or
|
||||
* compound objects which can't be freed in a single operation.
|
||||
*/
|
||||
void hash_free(struct hash_table *head)
|
||||
{
|
||||
void *p = head->table;
|
||||
memset(head, 0, sizeof *head);
|
||||
nasm_free(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees the hash *and* all data elements. This is applicable only in
|
||||
* the case where the data element is a single allocation. If the
|
||||
* second argument is false, the key string is part of the data
|
||||
* allocation or belongs to an allocation which will be freed
|
||||
* separately, if it is true the keys are also freed.
|
||||
*/
|
||||
void hash_free_all(struct hash_table *head, bool free_keys)
|
||||
{
|
||||
struct hash_iterator it;
|
||||
const struct hash_node *np;
|
||||
|
||||
hash_for_each(head, it, np) {
|
||||
if (np->data)
|
||||
nasm_free(np->data);
|
||||
if (free_keys && np->key)
|
||||
nasm_free((void *)np->key);
|
||||
}
|
||||
|
||||
hash_free(head);
|
||||
}
|
||||
2
src/nasmlib/ilog2.c
Normal file
2
src/nasmlib/ilog2.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define ILOG2_C
|
||||
#include "ilog2.h"
|
||||
246
src/nasmlib/md5c.c
Normal file
246
src/nasmlib/md5c.c
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* This code implements the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*/
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
#define byteReverse(buf, len) /* Nothing */
|
||||
#else
|
||||
static void byteReverse(unsigned char *buf, unsigned longs);
|
||||
|
||||
/*
|
||||
* Note: this code is harmless on little-endian machines.
|
||||
*/
|
||||
static void byteReverse(unsigned char *buf, unsigned longs)
|
||||
{
|
||||
uint32_t t;
|
||||
do {
|
||||
t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||
((unsigned) buf[1] << 8 | buf[0]);
|
||||
*(uint32_t *) buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
void MD5Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update context to reflect the concatenation of another buffer full
|
||||
* of bytes.
|
||||
*/
|
||||
void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len)
|
||||
{
|
||||
uint32_t t;
|
||||
|
||||
/* Update bitcount */
|
||||
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if (t) {
|
||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
memcpy(p, buf, len);
|
||||
return;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||
*/
|
||||
void MD5Final(unsigned char digest[16], MD5_CTX *ctx)
|
||||
{
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count - 8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((uint32_t *) ctx->in)[14] = ctx->bits[0];
|
||||
((uint32_t *) ctx->in)[15] = ctx->bits[1];
|
||||
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
byteReverse((unsigned char *) ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset((char *) ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
/* #define F1(x, y, z) (x & y | ~x & z) */
|
||||
#define F1(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define F2(x, y, z) F1(z, x, y)
|
||||
#define F3(x, y, z) (x ^ y ^ z)
|
||||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f, w, x, y, z, data, s) \
|
||||
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
void MD5Transform(uint32_t buf[4], uint32_t const in[16])
|
||||
{
|
||||
register uint32_t a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue