Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions omf/comprehensive_test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
; Comprehensive OMF test file that demonstrates all identified parser issues
; Build with: wasm -ml -fo=comprehensive_test.obj comprehensive_test.asm

.model small
.386

; ========================================
; Segment definitions for various test scenarios
; ========================================

_TEXT segment word public 'CODE'
_TEXT ends

_DATA segment word public 'DATA'
_DATA ends

CONST segment word public 'DATA'
CONST ends

_BSS segment word public 'BSS'
_BSS ends

; Group definition to test GROUP handling
DGROUP group _DATA, CONST, _BSS

; ========================================
; Code segment with various relocation types
; ========================================

_TEXT segment
assume cs:_TEXT, ds:DGROUP

; Test 1: Thread subrecords and F/T bit handling
; This generates FIXUPP with thread definitions
test_threads proc near
; Establish thread subrecords
mov ax, seg DGROUP ; Group reference
mov ds, ax

; External references that may use threads
mov bx, offset external_var
call external_func

; Far pointer that should generate fixup
les di, dword ptr far_ptr
ret
test_threads endp

; Test 2: M-bit (segment-relative vs PC-relative)
test_mbit proc near
; PC-relative jumps (M=0)
jmp short next_label
next_label:
call near_func

; Segment-relative offsets (M=1)
mov ax, offset data_item
mov bx, offset test_threads

; Direct memory reference (M=1)
mov cx, [data_item]

ret
test_mbit endp

near_func proc near
xor ax, ax
ret
near_func endp

; Test 3: Frame Method 3 (would need special encoding)
; Note: OpenWatcom assembler may optimize this differently
test_frame proc near
; Attempt to generate explicit frame references
db 0EAh ; Far JMP opcode
dw 0 ; Offset
dw 0040h ; Frame number < 0x80

db 0EAh ; Far JMP
dw 0 ; Offset
dw 1234h ; Frame number > 0x80

ret
test_frame endp

_TEXT ends

; ========================================
; Data segment with various patterns
; ========================================

_DATA segment

; Test data for relocations
data_item dw 1234h
far_ptr dd test_threads ; Far pointer

; Test for LIDATA generation (if supported by assembler)
; Note: WASM typically generates LEDATA, not LIDATA
buffer1 db 100 dup(0) ; Repeated pattern
buffer2 dw 50 dup(0FFFFh) ; Repeated words

; References that generate fixups
code_refs dw offset test_threads
dw offset test_mbit
dw seg _TEXT

_DATA ends

; ========================================
; BSS segment (uninitialized data)
; ========================================

_BSS segment
uninit_data dw 100 dup(?)
_BSS ends

; ========================================
; COMDEF - Common definitions
; ========================================

; These generate COMDEF records
comm near shared_var:word:1
comm far shared_array:byte:256

; ========================================
; Absolute symbols - these should generate PUBDEF with segment_index == 0
; ========================================

; BIOS data area addresses
BIOS_TIMER_TICKS EQU 046Ch ; Absolute address 0040:006C
BIOS_KEYBOARD_FLAGS EQU 0417h ; Absolute address 0040:0017
VIDEO_MEMORY EQU 0B800h ; Video memory segment (frame number)

; ========================================
; External declarations for fixup generation
; ========================================

extern external_var:word
extern external_func:near

; ========================================
; Public symbols
; ========================================

public test_threads
public test_mbit
public data_item

end test_threads
Binary file added omf/comprehensive_test.obj
Binary file not shown.
69 changes: 69 additions & 0 deletions omf/test_comdat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// test_comdat.cpp - Test file to generate COMDAT records
// Compile with: wpp386 -d3i test_comdat.cpp

#include <stdio.h>

// Template function - should generate COMDAT
template<typename T>
T max_value(T a, T b) {
return (a > b) ? a : b;
}

// Inline function - should generate COMDAT with -d3i
inline int add(int a, int b) {
return a + b;
}

// Another inline function
inline int multiply(int x, int y) {
return x * y;
}

// Template class with inline methods
template<typename T>
class Container {
private:
T value;
public:
Container(T v) : value(v) {}

inline T get() const { return value; }
inline void set(T v) { value = v; }
};

// Regular function
void regular_function() {
printf("Regular function\n");
}

int main() {
// Use template functions to force instantiation
int a = 5, b = 10;
int max_int = max_value(a, b);

float f1 = 3.14f, f2 = 2.71f;
float max_float = max_value(f1, f2);

// Use inline functions
int sum = add(3, 4);
int product = multiply(5, 6);

// Use template class
Container<int> int_container(100);
int_container.set(200);
int val = int_container.get();

Container<double> double_container(3.14);
double_container.set(2.71);
double dval = double_container.get();

// Use regular function
regular_function();

printf("Max int: %d\n", max_int);
printf("Max float: %f\n", max_float);
printf("Sum: %d, Product: %d\n", sum, product);
printf("Container values: %d, %f\n", val, dval);

return 0;
}
Binary file added omf/test_comdat.obj
Binary file not shown.
26 changes: 26 additions & 0 deletions omf/test_lidata.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Simple C file to generate LIDATA records
// OpenWatcom C compiler generates LIDATA for large initialized arrays
// Build with: wcc -ms -bt=DOS -fo=test_lidata.obj test_lidata.c

// Arrays with >= 50 elements of the same value generate LIDATA
char zeros[100] = {0}; // 100 zero bytes -> LIDATA
int pattern[75] = {0x5555}; // 75 ints with same value -> LIDATA
unsigned short ffs[50] = {0xFFFF}; // 50 shorts -> LIDATA

// Smaller arrays use LEDATA
char small[10] = {0}; // Too small, uses LEDATA

// Mixed patterns don't generate LIDATA
char mixed[] = {1, 2, 3, 4, 5}; // Different values, uses LEDATA

// Function to reference the data
void use_arrays() {
zeros[0] = 1;
pattern[0] = 2;
ffs[0] = 3;
}

int main() {
use_arrays();
return 0;
}
Binary file added omf/test_lidata.obj
Binary file not shown.