On Jan 20, 12:27 am, "Wilton Helm" <
wh...@compuserve.com> wrote:
> I went back and looked more carefully at the original example. It is a
> fragment, so I can't tell for sure what happened. What I would need to see
> is what assume statements were in effect at that time. There should have
> been an
> assume cs:DGROUP
> if there was an
> assume cs:_TEXT
> that would cause the problem.
>
The code is generated from a c file by wcc.
The following is a complete example.
*********************** file1.nasm ************************
segment ENTRY class=CODE USE16 align=1 CPU=686
group DGROUP ENTRY
%define BIOS16_STACK_BASE 0xfff0
extern _init
entry:
mov ax, cs
mov ds, ax
xor ax, ax
mov ss, ax
mov sp, BIOS16_STACK_BASE
call _init
cli
.infloop:
hlt
jmp .infloop
*********************** file2.c ************************
static void switch_test(int val)
{
switch (val) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
void init()
{
switch_test(0);
}
*********************** file3.link ************************
name test.bin
format dos com
file file1.o
file file2.o
order
clname CODE segment ENTRY segment _TEXT
clname DATA
option nodefaultlibs
option map
disable 1023
***********************************************************
nasm command line:
nasm -f obj -o file1.o file1.nasm
wcc command line:
~/watcom/binl/wcc -q -6 -ecc -zls -ms -zc -zu -s -os -we file2.c
link command line:
~/watcom/binl/wlink option q @file3.link
****************** map file ******************************
Open Watcom Linker Version 1.9
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Created on: 12/01/20 14:23:45
Executable Image: test.bin
creating a DOS .COM executable
+------------+
| Groups |
+------------+
Group Address Size
===== ======= ====
DGROUP 0000:0000 0000003e
+--------------+
| Segments |
+--------------+
Segment Class Group Address
Size
======= ===== ===== =======
====
ENTRY CODE DGROUP 0000:0000
00000012
_TEXT CODE AUTO 0001:0002
0000002b
CONST DATA DGROUP 0003:000e
00000000
CONST2 DATA DGROUP 0003:000e
00000000
_DATA DATA DGROUP 0003:000e
00000000
+----------------+
| Memory Map |
+----------------+
* = unreferenced symbol
+ = symbol only referenced locally
Address Symbol
======= ======
Module: file2.o(~/bug_example/file2.c)
0001:0024 _init
+-----------------------+
| Linker Statistics |
+-----------------------+
Stack size: 1000 (4096.)
Memory size: 003e (62.)
Entry point address: 0000:0000
Link time: 00:00.00
****************** linker output ******************************
test.bin: file format binary
Disassembly of section .data:
00000000 <.data>:
0: 8c c8 mov %cs,%ax
2: 8e d8 mov %ax,%ds
4: 31 c0 xor %ax,%ax
6: 8e d0 mov %ax,%ss
8: bc f0 ff mov $0xfff0,%sp
b: e8 26 00 call 0x34
e: fa cli
f: f4 hlt
10: eb fd jmp 0xf
12: 22 00 and (%bx,%si),%al
14: 22 00 and (%bx,%si),%al
16: 22 00 and (%bx,%si),%al
18: 22 00 and (%bx,%si),%al
1a: 22 00 and (%bx,%si),%al
1c: 22 00 and (%bx,%si),%al
1e: 55 push %bp
1f: 89 e5 mov %sp,%bp
21: 8b 46 04 mov 0x4(%bp),%ax
24: 3d 05 00 cmp $0x5,%ax
27: 77 09 ja 0x32
29: 89 c3 mov %ax,%bx
2b: 01 c3 add %ax,%bx
2d: 2e ff a7 02 00 jmp *%cs:0x2(%bx)
32: 5d pop %bp
33: c3 ret
34: 6a 00 push $0x0
36: e8 e5 ff call 0x1e
39: 83 c4 02 add $0x2,%sp
3c: c3 ret
*****************************************************************
As you can see at address 0x2d the jump table address
is 0x2 instead of 0x12 and also all the addresses in the jump
table itself are 0x22 instead of 0x32. In both cases the delta
is 0x10 (i.e. cs == _TEXT)
Ron