diff --git a/README b/README index abad36d5b..f4f71e87d 100644 --- a/README +++ b/README @@ -1,20 +1,25 @@ ELKS, the Embeddable Linux Kernel Subset ---------------------------------------- -This is a project to write a Linux-like operating system for ancient -computers running an Intel 8086-compatible processor. +This is a project to write a Linux-like operating system for systems based on +the Intel IA16 architecture (16 bits processors: i8088, i8086, i80188, i80186, +i80286, V20, V30 and compatibles). -To build ELKS, you will need a cross build chain, mainly based on DEV86, and -also on GCC-IA16 if you select that latest in place of BCC to build the kernel. +Such systems are ancient computers (IBM-PC XT/AT and clones) or more recent +embedded ones that reuse their huge hardware & software legacy. + +To build ELKS, you need a cross build chain, mainly based on DEV86 (still used +for the user land) and GCC-IA16 (now used for the kernel). A script is provided to automatically download and build that cross chain: 'tools/build.sh' -Note: all the scripts must be executed with top folder 'elks/' as the current one. +Note: all the scripts must be executed with the top folder 'elks/' as the +current one. -A script that attempts to automate the whole build process and make it easier -for ELKS newbies has been provided: +A script is provided to automate the whole build process (configuration, +kernel, user land and target image) and make it easier for ELKS newbies: './build.sh' @@ -29,29 +34,24 @@ The general build procedure for ELKS is as follows: '. tools/env.sh' (note the '.' before the script) -* Configure the build chain, the kernel, the commands and select the target - image format (the default configuration is for an IBM PC/XT/AT): +* Configure the build chain, the kernel, the user land and the target image + format: 'make menuconfig' -* Build the kernel and the commands: +* Build the kernel, the user land and the target image: 'make all' -* Build the target image as a user with the 'sudoer' privilege: - - 'cd elkscmd' - 'make image' - The target root folder is built in 'target/', and depending on your configuration, that folder is packed as either a floppy disk image (fd1440, fd1680, fd1200, fd720, fd360, without MBR), a hard-disk image (hd, with MBR), or a file image (rom, tar), into the '/image' folder. -Before writting the image on the real device, you can test it first on QEMU with -'./qemu.sh' (will configure QEMU to be close as possible to an ISA system). +Before writting the image on the real device, you can test it first on QEMU +with './qemu.sh' (will configure QEMU for an ISA system). Questions? Problems? Patches? Open an issue in this project! You can also join -and email the 'Linux-8086' mailing list at linux-8086@vger.kernel.org. +and email the 'Linux-8086' list at linux-8086@vger.kernel.org. More information in the Documentation folder: Documentation/index.html diff --git a/elks/Makefile-rules b/elks/Makefile-rules index 94aa593fa..c292cdcc0 100644 --- a/elks/Makefile-rules +++ b/elks/Makefile-rules @@ -115,15 +115,9 @@ DISTDIR = $(shell $(BASEDIR)/scripts/setdir $(TOPDIR)/elks-$(DIST)/$(MYDIR)) ######################################################################### # Specify the standard definitions to be given to system programs. -ifdef USEIA16 -CCDEFS_IA16= -DUSE_IA16 -else -CCDEFS_IA16= -endif - CCDEFS = -DELKS_VERSION_CODE=$(VSNCODE) \ -DUTS_RELEASE=\"$(DIST)\" \ - -D__KERNEL__ $(CCDEFS_IA16) + -D__KERNEL__ -DUSE_IA16 ######################################################################### # Set the target environment and the compiler to use. @@ -131,26 +125,16 @@ CCDEFS = -DELKS_VERSION_CODE=$(VSNCODE) \ ifeq ($(wildcard $(TOPDIR)/.config),) MK_ARCH = ibmpc MK_CPU = 8086 - MK_CC = bcc else MK_ARCH = $(shell grep '^CONFIG_ARCH_' $(TOPDIR)/.config \ | cut -d = -f 1 | cut -d _ -f 3- | tr A-Z a-z) MK_CPU = $(shell grep '^CONFIG_CPU_' $(TOPDIR)/.config \ | cut -d = -f 1 | cut -d _ -f 3- | tr A-Z a-z) - MK_CCN = $(shell grep '^CONFIG_COMPILER_' $(TOPDIR)/.config \ - | cut -d = -f 1 | cut -d _ -f 3- ) -ifeq ($(MK_CCN), 1) - MK_CC = bcc -else -ifeq ($(MK_CCN), 2) - MK_CC = ia16-elf-gcc -else - MK_CC = ia16-unknown-elks-gcc -endif - USEIA16 = y -endif endif +CROSS_CC = ia16-elf-gcc +CROSS_CFLAGS = -fno-inline -mcmodel=small -mno-segment-relocation-stuff -ffreestanding + ######################################################################### # Define architecture-specific flags. @@ -170,39 +154,21 @@ endif # Define CPU-specific flags. ifeq ($(MK_CPU), 8086) -ifeq ($(USEIA16), y) - CPU_AS = -0 -O - CPU_CC = -mtune=i8086 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections - CPU_LD = -0 -else - CPU_AS = -0 -O - CPU_CC = -0 - CPU_LD = -0 -endif + CPU_AS = -mtune=i8086 + CPU_CC = -mtune=i8086 + CPU_LD = endif ifeq ($(MK_CPU), 80186) -ifeq ($(USEIA16), y) - CPU_AS = -1 -O - CPU_CC = -mtune=i80186 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections - CPU_LD = -0 -else - CPU_AS = -1 -O - CPU_CC = -0 - CPU_LD = -0 -endif + CPU_AS = -mtune=i18086 + CPU_CC = -mtune=i80186 + CPU_LD = endif ifeq ($(MK_CPU), 80286) -ifeq ($(USEIA16), y) - CPU_AS = -2 -O - CPU_CC = -mtune=i80286 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections - CPU_LD = -0 -else - CPU_AS = -2 -O - CPU_CC = -0 - CPU_LD = -0 -endif + CPU_AS = -mtune=i80286 + CPU_CC = -mtune=i80286 + CPU_LD = endif ######################################################################### @@ -216,7 +182,6 @@ endif ################################ # Common definitions -AR = ar CC_PROTO = gcc $(INCLUDES) -M -MG $(CCDEFS) CFLBASE = $(INCLUDES) $(CCDEFS) CPP = $(CC) $(INCLUDES) -E $(CCDEFS) -ansi @@ -229,34 +194,21 @@ LHFLAGS = $(LCFLAGS) -exportfcn -declundef -fcnuse -fielduse \ ifneq ($(USEBCC), N) -ifeq ($(USEIA16), y) ################################ # Definitions using ia16-unknown-elks-gcc compiler -AS = as86 -ASFLAGS = $(CPU_AS) $(ARCH_AS) -CC = $(MK_CC) -CFLAGS = $(CPU_CC) $(ARCH_CC) -Os $(CFLBASE) -Wall -LD = ld86 -LDFLAGS = $(CPU_LD) -s - -else -################################ -# Definitions using BCC compiler - -AS = as86 -ASFLAGS = $(CPU_AS) $(ARCH_AS) -CC = bcc -CFLAGS = $(CPU_CC) $(ARCH_CC) -O $(CFLBASE) -ansi -LD = ld86 -LDFLAGS = $(CPU_LD) -s - -endif +AS = ia16-elf-as +ASFLAGS = $(CPU_AS) $(ARCH_AS) +CC = $(CROSS_CC) -Os +CFLAGS = $(CROSS_CFLAGS) $(CPU_CC) $(ARCH_CC) $(CFLBASE) -Wall +LD = ia16-elf-ld +LDFLAGS = $(CPU_LD) -s +AR = ia16-elf-ar else ################################ -# Definitions using GCC compiler +# Definitions using GCC host compiler AS = as ASFLAGS = @@ -264,6 +216,7 @@ CC = gcc CFLAGS = -Wall $(CFLBASE) LD = ld LDFLAGS = +AR = ar endif @@ -279,18 +232,8 @@ endif $(AS) $(ASFLAGS) -o $*.o $< ifneq ($(USEBCC), N) -ifeq ($(USEIA16), y) -.c.o: - $(CC) $(CFLAGS) -S -o $*.s $< - att2as86 < $*.s > $*.asm - $(AS) $(ASFLAGS) -u -o $*.o $*.asm - rm $*.s $*.asm - -else .c.o: $(CC) $(CFLAGS) -c -o $*.o $< - -endif endif ######################################################################### diff --git a/elks/arch/i86/Makefile b/elks/arch/i86/Makefile index a2953426b..dfe71d778 100644 --- a/elks/arch/i86/Makefile +++ b/elks/arch/i86/Makefile @@ -39,8 +39,6 @@ SIBOFLAGS = endif -LDFLAGS = -0 -i $(SIBOFLAGS) - ######################################################################### # Objects to be compiled. @@ -62,62 +60,42 @@ XINCLUDE = $(BASEDIR)/include/arch/asm-offsets.h ######################################################################### # Things to make. -.PHONY: boot/system toolkit - -boot/bootsect: boot/bootsect.o - $(LD) -0 -M $(ARCH_LD) -s -o boot/bootsect boot/bootsect.o > boot/bootsect.map - -boot/bootsect.o: boot/bootsect.s +.PHONY: toolkit -boot/crt0.o: boot/crt0.s - -boot/crt1.o: boot/crt1.c +boot/bootsect.o: boot/bootsect.S +boot/bootsect.o: boot/bootsect.s +boot/bootsect: boot/bootsect.o + $(LD) $(LDFLAGS) $(SIBOFLAGS) -M -T $(TOPDIR)/elks/elks-tiny.ld -o boot/bootsect boot/bootsect.o > boot/bootsect.map boot/netbootsect: boot/netbootsect.o - $(LD) $(LDFLAGS) -M $(ARCH_LD) -s -o boot/netbootsect boot/netbootsect.o > boot/netbootsect.map + $(LD) $(LDFLAGS) $(SIBOFLAGS) -M $(ARCH_LD) -s -o boot/netbootsect boot/netbootsect.o > boot/netbootsect.map boot/netbootsect.o: boot/netbootsect.s -boot/setup: boot/setup.o - $(LD) -0 -M $(ARCH_LD) -s -o boot/setup boot/setup.o > boot/setup.tmp - sort -k3,4 boot/setup.tmp > boot/setup.map - rm -f boot/setup.tmp +boot/setup.s: boot/setup.S +boot/setup.o: boot/setup.s +boot/setup: boot/setup.o + $(LD) $(LDFLAGS) $(SIBOFLAGS) -M -T $(TOPDIR)/elks/elks-tiny.ld -o boot/setup boot/setup.o > boot/setup.map -boot/setup.o: boot/setup.s +boot/crt0.s: boot/crt0.S +boot/crt0.o: boot/crt0.s + +boot/crt1.o: boot/crt1.c toolkit: ${MAKE} -C tools all -ifeq ($(USEIA16), y) $(BASEDIR)/include/arch/asm-offsets.h: kernel/asm-offsets.c echo '#ifndef ASM_OFFSETS_H' > $(BASEDIR)/include/arch/asm-offsets.h echo '#define ASM_OFFSETS_H' >> $(BASEDIR)/include/arch/asm-offsets.h $(CC) $(CFLAGS) -S -o asm-offsets.s kernel/asm-offsets.c sed -e '/^\tm/ !d' \ -e "s/\(.*\t\\$$\)/\#define /" \ - -e "s/\([0-9][0-9]*\),\t_\([a-zA-Z][_0-9a-zA-Z]*\)/\2 \1/" \ + -e "s/\([0-9][0-9]*\),\t\([a-zA-Z][_0-9a-zA-Z]*\)/\2 \1/" \ < asm-offsets.s >> $(BASEDIR)/include/arch/asm-offsets.h echo '#endif' >> $(BASEDIR)/include/arch/asm-offsets.h rm asm-offsets.s -else -$(BASEDIR)/include/arch/asm-offsets.h: kernel/asm-offsets.c - echo '#ifndef ASM_OFFSETS_H' > $(BASEDIR)/include/arch/asm-offsets.h - echo '#define ASM_OFFSETS_H' >> $(BASEDIR)/include/arch/asm-offsets.h - $(CC) $(CFLAGS) -S -o asm-offsets.s kernel/asm-offsets.c - sed -e '/^[^m].*/ d' \ - -e 's/\],/ /' \ - -e 's/ #/ /' \ - -e 's/ \*/ /' \ - -e 's/ \$$/0x/' \ - -e 's/^.*\[_/#define /' \ - -e 's/ax/0/' \ - < asm-offsets.s | grep -e define >> $(BASEDIR)/include/arch/asm-offsets.h - echo '#endif' >> $(BASEDIR)/include/arch/asm-offsets.h - rm asm-offsets.s - -endif - ######################################################################### # Image selection. @@ -126,7 +104,7 @@ ifeq ($(CONFIG_ARCH_SIBO), y) # Begin SIBO image build boot/system: $(XINCLUDE) $(AARCHIVES) $(ADRIVERS) sibo/crt1.o sibo/crt0.o - (cd $(BASEDIR) ; $(LD) $(LDFLAGS) -t -M $(ARCH_LD) \ + (cd $(BASEDIR) ; $(LD) $(LDFLAGS) $(SIBOFLAGS) -M $(ARCH_LD) \ $(ARCH_DIR)/sibo/crt0.o $(ARCH_DIR)/sibo/crt1.o \ init/main.o $(ARCHIVES) $(DRIVERS) \ -o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.tmp ; \ @@ -143,12 +121,12 @@ else # Begin PC image build boot/system: $(XINCLUDE) $(AARCHIVES) $(ADRIVERS) boot/crt1.o boot/crt0.o - (cd $(BASEDIR) ; $(LD) $(LDFLAGS) -t -M $(ARCH_LD) \ + (cd $(BASEDIR) ; $(LD) $(LDFLAGS) -M $(ARCH_LD) -T $(TOPDIR)/elks/elks-small.ld \ $(ARCH_DIR)/boot/crt0.o $(ARCH_DIR)/boot/crt1.o \ - init/main.o $(ARCHIVES) $(DRIVERS) \ - -o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.tmp ; \ - sort -k3,4 $(ARCH_DIR)/boot/system.tmp > $(ARCH_DIR)/boot/system.map ; \ - rm -f $(ARCH_DIR)/boot/system.tmp ) + init/main.o '-(' $(ARCHIVES) $(DRIVERS) '-)' \ + -o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.map) +# sort -k3,4 $(ARCH_DIR)/boot/system.tmp > $(ARCH_DIR)/boot/system.map ; \ +# rm -f $(ARCH_DIR)/boot/system.tmp ) ifneq ($(CONFIG_ROMCODE), y) diff --git a/elks/arch/i86/boot/bootsect.S b/elks/arch/i86/boot/bootsect.S index ac6a5225e..310c455e8 100644 --- a/elks/arch/i86/boot/bootsect.S +++ b/elks/arch/i86/boot/bootsect.S @@ -1,16 +1,21 @@ +/* ! ! SYS_SIZE is the number of clicks (16 bytes) to be loaded. ! 0x7F00 is 0x7F000 bytes = 508kB, more than enough for current ! versions of linux which compress the kernel ! +*/ + #include SYSSIZE = DEF_SYSSIZE + +/* ! ! bootsect.s Copyright (C) 1991, 1992 Linus Torvalds ! modified by Drew Eckhardt ! modified by Bruce Evans (bde) -! modified by Alan Cox for Linux/ELKS and 8088 compatiblity +! modified by Alan Cox for Linux/ELKS and 8088 compatiblity ! modified for Linux/16 by Chad Page ! ! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves @@ -31,17 +36,20 @@ SYSSIZE = DEF_SYSSIZE ! The loader has been made as simple as possible, and continuous ! read errors will result in a unbreakable loop. Reboot by hand. It ! loads pretty fast by getting whole tracks at a time whenever possible. +*/ + +.code16 .text -SETUPSECS = 4 ! nr of setup-sectors -BOOTSEG = 0x07C0 ! original address of boot-sector -INITSEG = DEF_INITSEG ! we move boot here - out of the way +SETUPSECS = 4 /* nr of setup-sectors */ +BOOTSEG = 0x07C0 /* original address of boot-sector */ +INITSEG = DEF_INITSEG /* we move boot here - out of the way */ SETUPSEG = DEF_SETUPSEG -SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536). +SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536). */ SYSSEGB = DEF_SYSSEG + 2 -! ROOT_DEV & SWAP_DEV are now written by "build". +// ROOT_DEV & SWAP_DEV are now written by "build". ROOT_DEV = 0 SWAP_DEV = 0 @@ -55,27 +63,29 @@ SWAP_DEV = 0 #include -! ld86 requires an entry symbol. This may as well be the usual one. -.globl _main -_main: -#if 0 /* hook for debugger, harmless unless BIOS is fussy (old HP) */ - int 3 +// ld86 requires an entry symbol. This may as well be the usual one. + +.global start +start: +#if 0 /* hook for debugger, harmless unless BIOS is fussy (old HP) */ + int 3 #endif - mov ax,#BOOTSEG - mov ds,ax - mov ax,#INITSEG - mov es,ax - mov cx,#256 - xor si,si - xor di,di + mov $BOOTSEG,%ax + mov %ax,%ds + mov $INITSEG,%ax + mov %ax,%es + mov $256,%cx + xor %si,%si + xor %di,%di cld rep movsw - jmpi go,INITSEG + ljmp $INITSEG,$go -! ax and es already contain INITSEG +// ax and es already contain INITSEG -go: mov di,#0x4000-12 +go: mov $0x4000-12,%di +/* ! 0x4000 is arbitrary value >= length of ! bootsect + length of setup + room for stack ! 12 is disk parm size @@ -85,10 +95,11 @@ go: mov di,#0x4000-12 ! my BIOS can be configured to put the wini drive tables in high memory ! instead of in the vector table. The old stack might have clobbered the ! drive table. +*/ - mov ds,ax - mov ss,ax ! put stack at INITSEG:0x4000-12. - mov sp,di + mov %ax,%ds + mov %ax,%ss /* put stack at INITSEG:0x4000-12. */ + mov %di,%sp /* * Many BIOS's default disk parameter tables will not * recognize multi-sector reads beyond the maximum sector number @@ -105,105 +116,111 @@ go: mov di,#0x4000-12 * Segments are as follows: ds=es=ss=cs - INITSEG, */ - mov bx,#0x78 -! 0:bx is parameter table address - push ds - push es - xor ax,ax - mov es,ax ! - seg es - lds si,[bx] - pop es - -! ds:si is source - - mov cl,#6 -! copy 12 bytes - cld - push di - - rep - movsw - - pop di - pop ds - ! what kind of instruction is this? - movb 4[di],*36 ! patch sector count - - push ds -! xor ax,ax ax still 0 - mov ds,ax - mov [bx],di - mov 2[bx],es - pop ds + mov $0x78,%bx +// 0:bx is parameter table address + push %ds + push %es + xor %ax,%ax + mov %ax,%es + lds %es:(%bx),%si + pop %es + +// ds:si is source + + mov $6,%cl +// copy 12 bytes + cld + push %di + + rep + movsw + + pop %di + pop %ds + /* what kind of instruction is this? */ + movb $36,4(%di) /* patch sector count */ + + push %ds +// xor ax,ax ax still 0 + mov %ax,%ds + mov %di,(%bx) + mov %es,2(%bx) + pop %ds +/* ! load the setup-sectors directly after the bootblock. ! Note that 'es' is already set up. ! Also cx is 0 from rep movsw above. +*/ load_setup: - xor ah,ah ! reset FDC - xor dl,dl - int 0x13 - - xor dx, dx ! drive 0, head 0 - mov cx,#0x0002 ! sector 2, track 0 - mov bx,#0x0200 ! address = 512, in INITSEG - mov ah,#0x02 ! service 2, nr of sectors - mov al,setup_sects ! (assume all on head 0, track 0) - int 0x13 ! read it - jnc ok_load_setup ! ok - continue - - push ax ! dump error code - call print_nl - mov bp, sp - call print_hex - pop ax - - jmp load_setup + xor %ah,%ah /* reset FDC */ + xor %dl,%dl + int $0x13 + + xor %dx,%dx /* drive 0, head 0 */ + mov $0x0002,%cx /* sector 2, track 0 */ + mov $0x0200,%bx /* address = 512, in INITSEG */ + mov $0x02,%ah /* service 2, nr of sectors */ + mov setup_sects,%al /* (assume all on head 0, track 0) */ + int $0x13 /* read it */ + jnc ok_load_setup /* ok - continue */ + + push %ax /* dump error code */ + call print_nl + mov %sp,%bp + call print_hex + pop %ax + + jmp load_setup ok_load_setup: -! Get disk drive parameters, specifically nr of sectors/track +// Get disk drive parameters, specifically nr of sectors/track #if 0 +/* ! bde - the Phoenix BIOS manual says function 0x08 only works for fixed ! disks. It doesn't work for one of my BIOS's (1987 Award). It was ! fatal not to check the error code. +*/ xor dl,dl mov ah,#0x08 ! AH=8 is get drive parameters - int 0x13 + int $0x13 xor ch,ch #else +/* ! It seems that there is no BIOS call to get the number of sectors. Guess ! 36 sectors if sector 36 can be read, 18 sectors if sector 18 can be read, ! 15 if sector 15 can be read. Otherwise guess 9. +*/ - mov si,#disksizes ! table of sizes to try + mov $disksizes,%si /* table of sizes to try */ probe_loop: lodsb - cbw ! extend to word - mov sectors, ax - cmp si,#disksizes_end - jae got_sectors ! if all else fails, try 9 - xchg ax, cx ! cx = track and sector - xor dx, dx ! drive 0, head 0 - xor bl, bl - mov bh,setup_sects - inc bh - shl bh,#1 ! address after setup (es = cs) - mov ax,#0x0201 ! service 2, 1 sector - int 0x13 - jc probe_loop ! try next value + cbw /* extend to word */ + mov %ax,sectors + cmp $disksizes_end,%si + jae got_sectors /* if all else fails, try 9 */ + xchg %cx,%ax /* cx = track and sector */ + xor %dx,%dx /* drive 0, head 0 */ + xor %bl,%bl + mov setup_sects,%bh + inc %bh + shl $1,%bh /* address after setup (es = cs) */ + mov $0x0201,%ax /* service 2, 1 sector */ + int $0x13 + jc probe_loop /* try next value */ #endif got_sectors: +/* ! Restore es ! mov ax,#INITSEG @@ -220,26 +237,29 @@ got_sectors: ! mov bp,#msg1 ! mov ax,#0x1301 ! write string, move cursor ! int 0x10 +*/ - mov cx,#msg1end-msg1 - mov si,#msg1 + mov $msg1end-msg1,%cx + mov $msg1,%si nxt_chr: lodsb - call print_chr - loop nxt_chr - + call print_chr + loop nxt_chr +/* ! ok, we've written the message, now ! we want to load the system (at 0x10000) +*/ - mov ax,#SYSSEG - mov es,ax ! segment of 0x010000 - call read_it - call kill_motor - mov al,#': - call print_chr - call print_nl + mov $SYSSEG,%ax + mov %ax,%es /* segment of 0x010000 */ + call read_it + call kill_motor + mov $':',%al + call print_chr + call print_nl +/* ! After that we check which root-device to use. If the device is ! defined (!= 0), nothing is done and the given device is used. ! Otherwise, one of /dev/fd0H2880 (2,32) or /dev/PS0 (2,28) or /dev/at0 (2,8), @@ -269,141 +289,154 @@ nxt_chr: ! after that (everything loaded), we jump to ! the setup-routine loaded directly after ! the bootblock: - jmpi 0,SETUPSEG +*/ + ljmp $SETUPSEG,$0 +/* ! This routine loads the system at address 0x10000, making sure ! no 64kB boundaries are crossed. We try to load it as fast as ! possible, loading whole tracks whenever we can. ! ! in: es - starting address segment (normally 0x1000) ! -head: .word 0 ! current head -track: .word 0 ! current track +*/ +head: .word 0 // current head +track: .word 0 // current track +/* !dx=sectors read of current track !bx=offset in memory of block !si=sectors read to block !al=number to read ! +*/ read_it: - mov dx,setup_sects - inc dx - mov ax,es - test ax,#0x0fff -die: jne die ! es must be at 64kB boundary - xor si,si ! zero sectors read + mov setup_sects,%dx + inc %dx + mov %es,%ax + test $0x0fff,%ax + +die: + jne die /* es must be at 64kB boundary */ + xor %si,%si /* zero sectors read */ + rp_read: - mov ax,es - sub ax,#SYSSEG - cmp ax,syssize ! have we loaded all yet? - jbe ok1_read + mov %es,%ax + sub $SYSSEG,%ax + cmp syssize,%ax /* have we loaded all yet? */ + jbe ok1_read ret + ok1_read: - mov ax,sectors ! nr of sectors/track + mov sectors,%ax /* nr of sectors/track */ - sub ax,dx ! remaining of track + sub %dx,%ax /* remaining of track */ - mov cx,ax ! cx= remaining + mov %ax,%cx /* cx= remaining */ - add cx,si ! boundary check - cmp cl,#128 - jbe ok2_read ! - ! to much-> fill block - mov ax,#128 ! ax=0 - sub ax,si ! so much may be read + add %si,%cx /* boundary check */ + cmp $128,%cl + jbe ok2_read /* to much-> fill block */ + + mov $128,%ax /* ax=0 */ + sub %si,%ax /* so much may be read */ - ok2_read: - mov bx,si - mov cx,#9 - shl bx,cl - call read_track ! do it - mov cx,ax ! cl=read blocks - - add ax,dx ! ax=new sectors - - cmp ax,sectors ! track done? - jne ok3_read - mov ax,#1 ! yes - sub ax,head - jne ok4_read ! next head - inc track ! next track + mov %si,%bx + mov $9,%cx + shl %cl,%bx + call read_track /* do it */ + mov %ax,%cx /* cl=read blocks */ + + add %dx,%ax /* %ax=new sectors */ + + cmp sectors,%ax /* track done? */ + jne ok3_read + mov $1,%ax /* yes */ + sub head,%ax + jne ok4_read /* next head */ + incw track /* next track */ ok4_read: - mov head,ax - xor ax,ax + mov %ax,head + xor %ax,%ax ok3_read: - mov dx,ax - - add si,cx - cmp si,#128 - jne rp_read + mov %ax,%dx - mov ax,es - add ah,#0x10 - mov es,ax + add %cx,%si + cmp $128,%si + jne rp_read - xor si,si - jmp rp_read + mov %es,%ax + add $0x10,%ah + mov %ax,%es + xor %si,%si + jmp rp_read read_track: - push dx - push ax - push bx + push %dx + push %ax + push %bx - mov al, #'. ! loading... message 2e = . - call print_chr - - pop bx - pop ax - push ax - push bx - - mov cx,dx - mov dx,track - inc cx - mov ch,dl - mov dx,head - mov dh,dl - and dx,#0x0100 - mov ah,#2 - - push dx ! save for error dump - push cx - push bx - push ax + mov $'.',%al /* loading... message 2e = . */ + call print_chr + + pop %bx + pop %ax + push %ax + push %bx + + mov %dx,%cx + mov track,%dx + inc %cx + mov %dl,%ch + mov head,%dx + mov %dl,%dh + and $0x0100,%dx + mov $2,%ah + + push %dx /* save for error dump */ + push %cx + push %bx + push %ax + + int $0x13 - int 0x13 +/* !ah=02h al=nr sectors to read !ch=cylinder !cl=sector !dh=head !dl=drive !es:bx=buffer +*/ - jc bad_rt - add sp, #8 - pop bx - pop ax - pop dx + jc bad_rt + add $8,%sp + pop %bx + pop %ax + pop %dx ret -bad_rt: push ax ! save error code +bad_rt: + push %ax /* save error code */ +/* ! push sectors - call print_all ! ah = error, al = read +*/ + call print_all /* ah = error, al = read */ - xor ah,ah - xor dl,dl - int 0x13 + xor %ah,%ah + xor %dl,%dl + int $0x13 - add sp, #10 + add $10,%sp - pop bx - pop ax - pop dx - jmp read_track + pop %bx + pop %ax + pop %dx + jmp read_track /* * print_all is for debugging purposes. * It will print out all of the registers. The assumption is that this is @@ -418,38 +451,40 @@ bad_rt: push ax ! save error code */ print_all: - mov cx, #5 ! error code + 4 registers - mov bp, sp + mov $5,%cx /* error code + 4 registers */ + mov %sp,%bp no_reg: - push cx ! save count left - add bp, #2 ! next register - call print_hex ! print it - pop cx - loop print_loop + push %cx /* save count left */ + add $2,%bp /* next register */ + call print_hex /* print it */ + pop %cx + loop print_loop ret print_loop: - call print_nl ! nl for readability + call print_nl /* nl for readability */ - mov ax, #0xe05 + 'A - 1 - sub al, cl - int 0x10 + mov $0x0e05 + 'A' - 1,%ax + sub %cl,%al + int $0x10 - mov al, #'X - int 0x10 + mov $'X',%al + int $0x10 - mov al, #': - int 0x10 - jmp no_reg + mov $':',%al + int $0x10 + jmp no_reg print_nl: - mov al, #0x0d ! CR - call print_chr - mov al, #0xa ! LF + mov $0x0d,%al /* CR */ + call print_chr + mov $0x0a,%al /* LF */ +/* ! int 0x10 - call print_chr +*/ + call print_chr ret /* @@ -458,30 +493,40 @@ print_nl: */ print_hex: +/* ! mov bl,#7 - mov cx, #4 ! 4 hex digits - mov dx, [bp] ! load word into dx +*/ + mov $4,%cx /* 4 hex digits */ + mov (%bp),%dx /* load word into dx */ + print_digit: - push cx - mov cl,#4 - rol dx, cl ! rotate so that lowest 4 bits are used - pop cx + push %cx + mov $4,%cl + rol %cl,%dx /* rotate so that lowest 4 bits are used */ + pop %cx +/* ! mov ax, #0xe0f ! ah = request, al = mask for nybble - mov al, #0xf - and al, dl - add al, #0x90 ! convert al to ascii hex (four instructions) +*/ + mov $0xf,%al + and %dl,%al + add $0x90,%al /* convert al to ascii hex (four instructions) */ daa - adc al, #0x40 + adc $0x40,%al daa +/* ! int 0x10 - call print_chr - loop print_digit +*/ + call print_chr + loop print_digit ret + print_chr: +/* ! mov bl,#7 - mov bx,#7 ! for older BIOS, bh must be current page - mov ah,#0xe - int 0x10 +*/ + mov $7,%bx /* for older BIOS, bh must be current page */ + mov $0xe,%ah + int $0x10 ret /* @@ -490,11 +535,11 @@ print_chr: * don't have to worry about it later. */ kill_motor: - push dx - mov dx,#0x3f2 - xor al, al - outb - pop dx + push %dx + mov $0x03f2,%dx + xor %al,%al + outb %al,%dx + pop %dx ret .org 0x1DD diff --git a/elks/arch/i86/boot/crt0.S b/elks/arch/i86/boot/crt0.S index 1d1a5c65b..9849c4fe1 100644 --- a/elks/arch/i86/boot/crt0.S +++ b/elks/arch/i86/boot/crt0.S @@ -1,29 +1,31 @@ -! enable the autoconfig tool +// enable the autoconfig tool #define __ASSEMBLY__ #include #include -! Assembler boot strap hooks. This is called by setup +// Assembler boot strap hooks. This is called by setup + .code16 .text - .globl _main - .extern _start_kernel - .extern _arch_boot - .globl _early_printk + .global start + .extern start_kernel + .extern arch_boot + .global early_printk -! note: this next instruction is part of the kernel restart fix for -! protexted mode. it must be 3 bytes long. +// note: this next instruction is part of the kernel restart fix for +// protexted mode. it must be 3 bytes long. - .extern _kernel_restarted - br _kernel_restarted +// .extern kernel_restarted +// jmp kernel_restarted -! Setup passes these on the stack -! Setup patched to pass parameters in registers to avoid clobbering the -! kernel when using the 286pmode extender. +// Setup passes these on the stack +// Setup patched to pass parameters in registers to avoid clobbering the +// kernel when using the 286pmode extender. -_main: +start: +/* ! Setup.S already initialized DS and ES (but not SS) ! In addition, registers contain: ! BX, Text size @@ -31,29 +33,31 @@ _main: ! DX, BSS size ! CX, Kernel DS ! - mov __endtext, bx - mov __enddata, si - add si, dx - mov __endbss, si - -! Start cleaning BSS. Still using setup.S stack - - mov di,__enddata ! start of BSS - xchg cx,dx ! CX = BSS size, DX = Kernel DS - xor ax,ax - shr cx,#1 +*/ + mov %bx,_endtext + mov %si,_enddata + add %dx,%si + mov %si,_endbss + +// Start cleaning BSS. Still using setup.S stack + + mov _enddata,%di // start of BSS + xchg %dx,%cx // CX = BSS size, DX = Kernel DS + xor %ax,%ax + shr $1,%cx cld rep stosw -! End cleaning BSS +// End cleaning BSS - mov _kernel_cs, cs - mov _kernel_ds, ds + mov %cs,kernel_cs + mov %ds,kernel_ds - mov ss,dx ! in ROMCODE stack is ready placed - mov sp,#(_task + TASK_USER_AX) + mov %dx,%ss // in ROMCODE stack is ready placed + mov $task + TASK_USER_AX,%sp +/* ! Space for temporary stack space _bootstack removed!! ! Saved 768 byte boot stack. ! Print sp in wake_up and you'll see that more than 512 bytes of stack are used! @@ -65,50 +69,52 @@ _main: ! .extern _redirect_main ! call _redirect_main +*/ - call _arch_boot - call _start_kernel ! Break point if it returns - int 3 + call arch_boot + call start_kernel // Break point if it returns + int $3 -_early_printk: - push bp - mov bp,sp - push si - mov si,[bp+4] +early_printk: + push %bp + mov %sp,%bp + push %si + mov 4(%bp),%si cld ep_loop: lodsb - or al,al + or %al,%al jz ep_end - mov ah,#0x0E - mov bx,#0x0007 - int 0x10 + mov $0x0E,%ah + mov $0x0007,%bx + int $0x10 jmp ep_loop ep_end: - pop si - pop bp + pop %si + pop %bp ret -! Segment beginnings +// Segment beginnings .data - .globl __endtext - .globl __enddata - .globl __endbss - .extern _kernel_cs - .extern _kernel_ds - .extern _task - -__endtext: + .global _endtext + .global _enddata + .global _endbss + .extern kernel_cs + .extern kernel_ds + .extern task + .global mfld + +_endtext: .word 0 -__enddata: +_enddata: .word 0 -__endbss: +_endbss: .word 0 .bss -__sbss: +_sbss: diff --git a/elks/arch/i86/boot/setup.S b/elks/arch/i86/boot/setup.S index 9449f1ea4..b95e3028d 100644 --- a/elks/arch/i86/boot/setup.S +++ b/elks/arch/i86/boot/setup.S @@ -1,3 +1,4 @@ +/* ! ! setup.S Copyright (C) 1991, 1992 Linus Torvalds ! @@ -93,11 +94,12 @@ ! 0x1ff: 0xAA = boot_flag, High part/PS2 mouse device present (0, not present) ! ! NOTE! These had better be the same as in bootsect.s! +*/ #define __ASSEMBLY__ #include -! Signature words to ensure LILO loaded us right +// Signature words to ensure LILO loaded us right #define SIG1 0xAA55 #define SIG2 0x5A5A @@ -105,268 +107,273 @@ #define KERNEL_MAGICNUMBER MINIX_SPLITID_LOW #ifndef CONFIG_ROMCODE - INITSEG = DEF_INITSEG ! (DATASEG) we move boot here - out of the way - SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536). - SETUPSEG = DEF_SETUPSEG ! this is the current code segment + INITSEG = DEF_INITSEG // (DATASEG) we move boot here - out of the way + SYSSEG = DEF_SYSSEG // system loaded at 0x10000 (65536). + SETUPSEG = DEF_SETUPSEG // this is the current code segment #else INITSEG = CONFIG_ROM_SETUP_DATA SYSSEG = CONFIG_ROM_KERNEL_CODE SETUPSEG = CONFIG_ROM_SETUP_CODE #endif +.code16 + .text -entry start +.global start start: #ifdef CONFIG_ROMCODE - .byte 0x55, 0xaa ;sign for ROM-Extention - .byte 0x04 ;space for lengthcode (promsize/512) + .byte 0x55, 0xaa //;sign for ROM-Extention + .byte 0x04 //;space for lengthcode (promsize/512) - push ds + push %ds #else -! Bootlin depends on this being done early - mov ax,#0x01500 ;Read disk type/DASD - mov dl,#0x81 - int 0x13 +// Bootlin depends on this being done early + mov $0x01500,%ax //;Read disk type/DASD + mov $0x81,%dl + int $0x13 #endif -! Check signature at end of setup - mov ax,#SETUPSEG ;setup codesegment - mov ds,ax - cmp setup_sig1,#SIG1 +// Check signature at end of setup + mov $SETUPSEG,%ax //;setup codesegment + mov %ax,%ds + cmpw $SIG1,setup_sig1 jne bad_sig - cmp setup_sig2,#SIG2 + cmpw $SIG2,setup_sig2 jne bad_sig - jmp near good_sig ;why double jmp + jmp good_sig //;why double jmp + nop -! Routine to print asciiz-string at DS:SI -prts_1: mov bx,#0x0007 !page 0 - mov ah,#0x0e - int 0x10 +// Routine to print asciiz-string at DS:SI +prts_1: mov $0x0007,%bx //page 0 + mov $0x0e,%ah + int $0x10 prtstr: lodsb - test al,al + test %al,%al jnz prts_1 ret -! We now have to find the rest of the setup code/data -! in ROM the code is complete +// We now have to find the rest of the setup code/data +// in ROM the code is complete bad_sig: #ifndef CONFIG_ROMCODE - mov ax,#INITSEG ;code setup - mov ds,ax - xor bh,bh - mov bl,[497] ! get setup sects from boot sector (SETUPSECS) - sub bx,#4 ! LILO loads 4 sectors of setup - mov cl,#8 - shl bx,cl ! convert to words - mov cx,bx - push cx ! This may not be needed - Chad. - mov cl,#3 - shr bx,cl ! convert to segment - pop cx - add bx,#SYSSEG - seg cs - mov start_sys_seg,bx - -! Move rest of setup code/data to here - mov di,#2048 ! four sectors loaded by LILO - sub si,si - mov ax,#SETUPSEG - mov es,ax - mov ax,#SYSSEG - mov ds,ax + mov $INITSEG,%ax //;code setup + mov %ax,%ds + xor %bh,%bh + mov 497,%bl // get setup sects from boot sector (SETUPSECS) + sub $4,%bx // LILO loads 4 sectors of setup + mov $8,%cl + shl %cl,%bx // convert to words + mov %bx,%cx + push %cx // This may not be needed - Chad. + mov $3,%cl + shr %cl,%bx // convert to segment + pop %cx + add $SYSSEG,%bx +// seg cs + mov %bx,%cs:start_sys_seg + +// Move rest of setup code/data to here + mov $2048,%di // four sectors loaded by LILO + sub %si,%si + mov $SETUPSEG,%ax + mov %ax,%es + mov $SYSSEG,%ax + mov %ax,%ds rep movsw - mov ax,#SETUPSEG - mov ds,ax - cmp setup_sig1,#SIG1 + mov $SETUPSEG,%ax + mov %ax,%ds + cmpw $SIG1,setup_sig1 jne no_sig - cmp setup_sig2,#SIG2 + cmpw $SIG2,setup_sig2 je good_sig no_sig: #endif - lea si,no_sig_mess + lea no_sig_mess,%si call prtstr -no_sig_loop: ! And halt +no_sig_loop: // And halt jmp no_sig_loop -;------------------------------------------------ +//;------------------------------------------------ good_sig: #ifdef CONFIG_ROMCODE - xor ax,ax - mov ds,ax ;Interrupttable + xor %ax,%ax + mov %ax,%ds //;Interrupttable - mov word ptr[4*0x19],#start_os - mov word ptr[4*0x19+2],cs ;set os/loader int + movw $start_os,4*0x19 + mov %cs,4*0x19+2 //;set os/loader int - pop ds - retf ;back to BIOS + pop %ds + lret //;back to BIOS #endif -;------------------------------------------------------- -;-- from here the real loader starts -;------------------------------------------------------- +//;------------------------------------------------------- +//;-- from here the real loader starts +//;------------------------------------------------------- start_os: - mov ax,#INITSEG ;datasegment setup.S - mov ds,ax + mov $INITSEG,%ax //;datasegment setup.S + mov %ax,%ds -; The root device is obviously /dev/rom0 -; when setup starts in ROM / Flash memory +//; The root device is obviously /dev/rom0 +//; when setup starts in ROM / Flash memory #ifdef CONFIG_ROMCODE #ifdef CONFIG_ROMFS_FS - mov [0x01FC], #0x0600 /* rom-flash */ + movw $0x0600,0x01FC /* rom-flash */ #else - mov [0x01FC], #0x0380 /* bioshd */ + movw $0x0380,0x01FC /* bioshd */ #endif #endif -! Get memory size (extended mem, kB) +// Get memory size (extended mem, kB) #ifdef CONFIG_XMS_SIZE - mov [2],#CONFIG_XMS_SIZE + movw $CONFIG_XMS_SIZE,2 #else - mov ah,#0x88 - int 0x15 - mov [2],ax + mov $0x88,%ah + int $0x15 + mov %ax,2 #endif -! set the keyboard repeat rate to the max +// set the keyboard repeat rate to the max #ifdef CONFIG_HW_KEYBOARD_BIOS - mov ax,#0x0305 - xor bx,bx ! clear bx - int 0x16 + mov $0x0305,%ax + xor %bx,%bx // clear bx + int $0x16 #endif -! check for EGA/VGA and some config parameters +// check for EGA/VGA and some config parameters #ifdef CONFIG_HW_VGA - mov ah,#0x12 ! Get video data - mov bl,#0x10 - int 0x10 - mov [8],ax - mov [10],bx - mov [12],cx - mov ax,#0x5019 - cmp bl,#0x10 + mov $0x12,%ah // Get video data + mov $0x10,%bl + int $0x10 + mov %ax,8 + mov %bx,10 + mov %cx,12 + mov $0x5019,%ax + cmp $0x10,%bl je novga - mov ax,#0x1a00 ! Added check for EGA/VGA discrimination - int 0x10 - mov bx,ax - mov ax,#0x5019 - movb [15],#0 ! by default, no VGA - cmp bl,#0x1a ! 1a means VGA, anything else EGA or lower + mov $0x1a00,%ax // Added check for EGA/VGA discrimination + int $0x10 + mov %ax,%bx + mov $0x5019,%ax + movb $0,15 // by default, no VGA + cmp $0x1a,%bl // 1a means VGA, anything else EGA or lower jne novga - movb [15],#1 ! we've detected a VGA -! call chsvga + movb $1,15 // we've detected a VGA +// call chsvga #else - movb [15],#0 ! no VGA in system + movb $0,15 // no VGA in system #ifdef CONFIG_HW_VIDEO_LINES_PER_SCREEN - mov al,#CONFIG_HW_VIDEO_LINES_PER_SCREEN + mov $CONFIG_HW_VIDEO_LINES_PER_SCREEN,%al #else - mov al,#0x19 ! height of display (0x19 == 25 rows) + mov $0x19,%al // height of display (0x19 == 25 rows) #endif #endif -novga: mov [14],al ! CGA 25 rows - mov ah,#0x03 ! read cursor pos - xor bh,bh ! clear bh - int 0x10 ! save it in known place, con_init fetches - mov [0],dx ! it from INITSEG. +novga: mov %al,14 // CGA 25 rows + mov $0x03,%ah // read cursor pos + xor %bh,%bh // clear bh + int $0x10 // save it in known place, con_init fetches + mov %dx,0 // it from INITSEG. -! Get video-card data: - mov ah,#0x0f - int 0x10 - mov [4],bx ! bh = display page - mov [6],ax ! al = video mode, ah = window width +// Get video-card data: + mov $0x0f,%ah + int $0x10 + mov %bx,4 // bh = display page + mov %ax,6 // al = video mode, ah = window width #ifdef CONFIG_HW_VIDEO_LINES_PER_CHARACTER - mov [16],#CONFIG_HW_VIDEO_LINES_PER_CHARACTER + mov $CONFIG_HW_VIDEO_LINES_PER_CHARACTER,16 #else - xor ax,ax - mov es,ax ! Access BIOS DATA AREA - seg es - mov ax,[0x485] ! POINTS - Height of character matrix - mov [16],ax + xor %ax,%ax + mov %ax,%es // Access BIOS DATA AREA +// seg es + mov %es:0x485,%ax // POINTS - Height of character matrix + mov %ax,16 #endif -! check for PS/2 pointing device +// check for PS/2 pointing device -! mov ax,#INITSEG !ds was not changed sinse good_gig -! mov ds,ax - mov [0x1ff],#0 ! default is no pointing device +// mov ax,#INITSEG //ds was not changed sinse good_gig +// mov ds,ax + movb $0,0x1ff // default is no pointing device + nop #ifdef CONFIG_HW_PS2_MOUSE - int 0x11 ! int 0x11: equipment determination - test al,#0x04 ! check if pointing device installed + int $0x11 // int 0x11: equipment determination + test $0x04,%al // check if pointing device installed jz no_psmouse - mov [0x1ff],#0xaa ! device present + movb $0xaa,0x1ff // device present + nop no_psmouse: #endif call getcpu - push es ! clear BIOS data for harddisk 0/1, 12 bytes - mov ax,#INITSEG ! and BIOS data for floppy disk 0/1, 12 bytes - mov es,ax - mov cx,#24 - mov di,#0x80 - xor ax,ax + push %es // clear BIOS data for harddisk 0/1, 12 bytes + mov $INITSEG,%ax // and BIOS data for floppy disk 0/1, 12 bytes + mov %ax,%es + mov $24,%cx + mov $0x80,%di + xor %ax,%ax cld rep stosw - pop es + pop %es #ifdef CONFIG_HW_HARD_DRIVE - call gethd ! Get geometry for harddisk 0/1. + call gethd // Get geometry for harddisk 0/1. #endif #ifdef CONFIG_HW_FLOPPY_DRIVE - call getfloppy ! Get geometry for floppy disk 0/1. + call getfloppy // Get geometry for floppy disk 0/1. #endif - mov ax,#INITSEG - mov ds,ax - int 0x12 ! determine the size of the basememory - mov [0x2a],ax + mov $INITSEG,%ax + mov %ax,%ds + int $0x12 // determine the size of the basememory + mov %ax,0x2a -!---------------------------- +//---------------------------- #ifdef CONFIG_ROMCODE -! We must now copy the kernel to RAM (SYSSEG) +// We must now copy the kernel to RAM (SYSSEG) - mov ax,cs ;string is in this codeseg - mov ds,ax - lea si,load_kernel + mov %cs,%ax //;string is in this codeseg + mov %ax,%ds + lea load_kernel,%si call prtstr - mov ax,#CONFIG_ROM_KERNEL_CODE ;the ROM image - mov ds,ax + mov $CONFIG_ROM_KERNEL_CODE,%ax //;the ROM image + mov %ax,%ds -! test, if correct a.out header +// test, if correct a.out header - cmp word ptr[0],#KERNEL_MAGICNUMBER + cmpw $KERNEL_MAGICNUMBER,0 jne aouterr - cmp byte ptr [3],#0x04 ;prozessortype = 8086 + cmpb $0x04,3 //;prozessortype = 8086 jne test1 - jmp near aout_ok + jmp aout_ok test1: - cmp byte ptr [3],#0x10 ;prozessortype = 80386 + cmpb $0x10,[3] //;prozessortype = 80386 jne aouterr - jmp near aout_ok + jmp aout_ok aouterr: - mov ax,cs - mov ds,ax - lea si,kernel_aouterr + mov %cs,%ax + mov %ax,%ds + lea kernel_aouterr,%si call prtstr err_loop: jmp err_loop @@ -384,38 +391,39 @@ kernel_to_big: .byte 13,10 aout_ok: - mov ax,#CONFIG_ROM_KERNEL_DATA - mov es,ax + mov $CONFIG_ROM_KERNEL_DATA,%ax + mov %ax,%es - mov cx,[10] ;hi of text size - or cx,cx ;max 64k + mov 10,%cx //;hi of text size + or %cx,%cx //;max 64k jz size_ok size_error: - mov ax,cs - mov ds,ax - lea si,kernel_to_big + mov %cs,%ax + mov %ax,%ds + lea kernel_to_big,%si call prtstr - jmp near err_loop ;and halt + jmp err_loop //;and halt size_ok: - mov cx,[14] ; Check data section size - or cx,cx - jnz size_error ; .data section too big - -;and now copy the kerneldata -! WARNING: Next code fails if code_size+data_size+32 > 64K - mov si,[0x08] ;code size - add si,[0x04] ;+header size - xor di,di - mov cx,[0x0c] ;data size - shr cx,#1 ;copy words + mov 14,%cx //; Check data section size + or %cx,%cx + jnz size_error //; .data section too big + +//;and now copy the kerneldata +// WARNING: Next code fails if code_size+data_size+32 > 64K + mov 0x08,%si //;code size + add 0x04,%si //;+header size + xor %di,%di + mov 0x0c,%cx //;data size + shr $1,%cx //;copy words cld rep movsw -; now ist the data and code ad the right position +//; now ist the data and code ad the right position #endif +/* !-------------------------------------------------------- ! We setup ds, es, and ss now ! @@ -429,198 +437,225 @@ size_ok: !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ! Case for kernel in ROM ! +*/ #if defined(CONFIG_ROMCODE) - mov dx,[0x10] ;bbs size - mov si,[0x0c] ;data size - mov bx,[0x08] ;text size + mov 0x10,%dx //;bbs size + mov 0x0c,%si //;data size + mov 0x08,%bx //;text size - mov cx,es - mov ds,cx + mov %es,%cx + mov %cx,%ds #ifdef CONFIG_ROM_DEBUG - int 3 ! break for debugger just before kernel + int $3 // break for debugger just before kernel #endif - jmp far SYSSEG+2:3 + ljmp $SYSSEG+2:$0 -!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -! Case for kernel in disk to be relocated -! +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Case for kernel in disk to be relocated +// #elif defined(REL_SYS) -! Relocate setup data +// Relocate setup data - mov ax,#INITSEG - mov ds,ax - mov ax,#REL_INITSEG - mov es,ax - xor si,si - xor di,di - mov cx,#256 + mov $INITSEG,%ax + mov %ax,%ds + mov $REL_INITSEG,%ax + mov %ax,%es + xor %si,%si + xor %di,%di + mov $256,%cx cld rep movsw -! Assume kernel data+bss size > 5 Kbytes -! Calculate values needed - - mov ax,#SYSSEG - mov ds,ax - mov bx,[12] - mov dx,bx - push bx ! Data size - add bx,[16] - add bx,#0xF ! align on next paragraph (issue #209) - mov cl,#4 - shr bx,cl - add bx,#REL_SYSSEG ! BX = Relocated kernel code segment - mov ax,[8] - push ax ! Code size - mov cl,#4 - shr ax,cl - mov cx,ax - add ax,bx ! AX = Relocated kernel data segment - add cx,#SYSSEG+2 - push [16] ! Bss size - push cx ! Kernel data segment - add dx,#0xF ! align on next paragraph (issue #209) - mov cl,#4 - shr dx,cl - add dx,ax ! DX = Rel rel segment - mov bp,sp +// Assume kernel data+bss size > 5 Kbytes +// Calculate values needed + + mov $SYSSEG,%ax + mov %ax,%ds + +// Check system header + cmpw $0x0301,0 // ELKS a.out magic + jne sys_hdr_bad + cmpw $0x0430,2 // i8086 - executable with separated I & D + jne sys_hdr_bad + cmpb $0x20,4 // header size (no relocs) + jne sys_hdr_bad + jmp sys_hdr_good + +sys_hdr_bad: + mov $SETUPSEG,%ax + mov %ax,%ds + lea sys_hdr_msg,%si + call prtstr +sys_hdr_loop: + jmp sys_hdr_loop +sys_hdr_msg: + .ascii "Bad sys hdr!" + .byte 0 + +// System header is good + +sys_hdr_good: + mov 12,%bx + mov %bx,%dx + push %bx // Data size + add 16,%bx + add $0xF,%bx // align on next paragraph (issue #209) + mov $4,%cl + shr %cl,%bx + add $REL_SYSSEG,%bx // BX = Relocated kernel code segment + mov 8,%ax + push %ax // Code size + mov $4,%cl + shr %cl,%ax + mov %ax,%cx + add %bx,%ax // AX = Relocated kernel data segment + add $SYSSEG+2,%cx + push 16 // Bss size + push %cx // Kernel data segment + add $0xF,%dx // align on next paragraph (issue #209) + mov $4,%cl + shr %cl,%dx + add %ax,%dx // DX = Rel rel segment + mov %sp,%bp + + +/* ! Variables in stack as follows: ! Offset from BP variable ! 6 data size ! 4 code size ! 2 bss size ! 0 kernel data segment +*/ - cmp bx,#SYSSEG+2 + cmp $SYSSEG+2,%bx ja move_back -! Move forward +// Move forward - mov es,bx ! Move code segment - mov cx,#SYSSEG+2 - mov ds,cx - mov cx,4[bp] - xor si,si - mov di,si + mov %bx,%es // Move code segment + mov $SYSSEG+2,%cx + mov %cx,%ds + mov 4(%bp),%cx + xor %si,%si + mov %si,%di rep movsb - mov es,ax ! Move data segment - mov ds,[bp] - mov cx,6[bp] - xor si,si + mov %ax,%es // Move data segment + mov (%bp),%ds + mov 6(%bp),%cx + xor %si,%si jmp rel_rel -! Move backward +// Move backward move_back: std - mov es,ax ! Move data segment - mov ds,[bp] - mov cx,6[bp] - mov si,cx - dec si - mov di,si + mov %ax,%es // Move data segment + mov (%bp),%ds + mov 6(%bp),%cx + mov %cx,%si + dec %si + mov %si,%di rep movsb - mov es,bx ! Move code segment - mov cx,#SYSSEG+2 - mov ds,cx - mov cx,4[bp] - mov si,cx - dec si + mov %bx,%es // Move code segment + mov $SYSSEG+2,%cx + mov %cx,%ds + mov 4(%bp),%cx + mov %cx,%si + dec %si rel_rel: - mov di,si + mov %si,%di rep movsb -! Relocate relocation code to next to relocated kernel data -! segment because current setup code might be overwritten - - mov es,dx - mov cx,cs - mov ds,cx - mov si,#cont - xor di,di - push es ! build far return address - push di - mov cx,#(end_reloc-cont) +// Relocate relocation code to next to relocated kernel data +// segment because current setup code might be overwritten + + mov %dx,%es + mov %cs,%cx + mov %cx,%ds + mov $cont,%si + xor %di,%di + push %es // build far return address + push %di + mov $end_reloc-cont,%cx cld rep movsb - retf ! jump to dx:0 - -! Still using the old stack. Switch to new stack -! AX = Rel. kernel data seg. BX = Rel. kernel code seg. DX = Rel. rel. seg. - -cont: mov ds,ax - pop di ! Empty old stack - pop di - pop ax - pop si - mov ss,dx ! Set new stack - mov sp,#(end_reloc-cont+512) - mov dx,di ! Move kernel data segment to REL_SYSSEG - mov cx,#REL_SYSSEG - mov es,cx - mov cx,si - push cx - xor si,si - xor di,di + lret // jump to dx:0 + +// Still using the old stack. Switch to new stack +// AX = Rel. kernel data seg. BX = Rel. kernel code seg. DX = Rel. rel. seg. + +cont: mov %ax,%ds + pop %di // Empty old stack + pop %di + pop %ax + pop %si + mov %dx,%ss // Set new stack + mov $end_reloc-cont+512,%sp + mov %di,%dx // Move kernel data segment to REL_SYSSEG + mov $REL_SYSSEG,%cx + mov %cx,%es + mov %si,%cx + push %cx + xor %si,%si + xor %di,%di rep movsb +/* ! Load registers as expected by crt0.S ! BX, Text size ! SI, Data size ! DX, BSS size ! DS,ES,CX, Kernel DS - - xchg ax,bx - pop si - mov cx,es - mov ds,cx - push ax ! Build far return address to relocated code segment - mov ax,#3 ! Address to offset 3 - push ax - -! changed jmpi 0,0x1002 to 3,0x1002 for kernel restart fix -AJB -! jmpi 0x00003,SYSSEG+2 !jmp offset 3 of segment 0x1002 (cs) - retf +*/ + + xchg %bx,%ax + pop %si + mov %es,%cx + mov %cx,%ds + push %ax // Build far return address to relocated code segment + mov $0,%ax // Address to offset 0 (start) + push %ax + +// changed jmpi 0,0x1002 to 3,0x1002 for kernel restart fix -AJB +// jmpi 0x00003,SYSSEG+2 !jmp offset 3 of segment 0x1002 (cs) + lret end_reloc: -!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -! Case for kernel in disk, no kernel relocation -! +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Case for kernel in disk, no kernel relocation +// #else - mov ax, #SYSSEG ! in ROM ds ist always set - mov ds, ax ! Get the header into DS - mov bx, [8] ! TSeg - mov si, [12] ! DSeg - mov dx, [16] ! BSeg - mov ax, bx ! Get Text size - mov cl, #4 - shr ax, cl ! Data in paragraphs - - mov cx, #SYSSEG+2 ! Code starts here - push cx ! Build far return address to SYSSEG+2:3 - add cx, ax ! Segment base for data/bss/stack - mov ds, cx - mov es, cx - mov ax, #3 - push ax -! mov ss, cx -! mov sp, #0xFFFE ! Top of stack right at the end (temporary) - -! changed jmpi 0,0x1002 to 3,0x1002 for kernel restart fix -AJB -! jmpi 0x00003,SYSSEG+2 !jmp offset 3 of segment 0x1002 (cs) + mov $SYSSEG,%ax // in ROM ds ist always set + mov %ax,%ds // Get the header into DS + mov 8,%bx // TSeg + mov 12,%si // DSeg + mov 16,%dx // BSeg + mov %bx,%ax // Get Text size + mov $4,%cl + shr %cl,%ax // Data in paragraphs + + mov $SYSSEG+2,%cx // Code starts here + push %cx // Build far return address to SYSSEG+2:3 + add %ax,%cx // Segment base for data/bss/stack + mov %cx,%ds + mov %cx,%es + mov $0,%ax + push %ax retf #endif +/* !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ! ! This routine checks that the keyboard command queue is empty @@ -630,6 +665,7 @@ end_reloc: ! the machine, and we probably couldn't proceed anyway. ! no call to this functions +*/ #if 0 empty_8042: call delay @@ -707,171 +743,176 @@ delay: .word 0x00eb ! jmp $+2 ret #endif -;from never calls +//;from never calls -!form this position are calles code +//form this position are calles code +/* ! ! Probe for the CPU/Coprocessor ! These information is taken from "PC intern 3.0", Data Becker Verlag, 1992 ! and from the Linux-Kernel, arch/i386/kernel/head.S ! +*/ getcpu: - mov ax,#SETUPSEG /* Codesegment setup.S */ - mov ds,ax + mov $SETUPSEG,%ax /* Codesegment setup.S */ + mov %ax,%ds #ifndef CONFIG_ROMCODE pushf - xor ax,ax - push ax + xor %ax,%ax + push %ax popf pushf - pop ax + pop %ax popf - and ax,#0xf000 - cmp ax,#0xf000 + and $0xf000,%ax + cmp $0xf000,%ax je is8086 - mov ax,#0x7000 + mov $0x7000,%ax pushf - push ax + push %ax popf pushf - pop ax + pop %ax popf - and ax,#0x7000 + and $0x7000,%ax je is80286 -! -! Default & unknown CPU -! - mov cl,#0xff - lea si,px86 - br getfpu +// +// Default & unknown CPU +// + mov $0xff,%cl + lea px86,%si + jmp getfpu + nop #endif #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) is8086: - mov al,#0xff - mov cl,#0x21 ! 80188/86 uses only the five lower - shr al,cl ! bits of cl to determine the number - jnz is80186 ! of shifts. + mov $0xff,%al + mov $0x21,%cl // 80188/86 uses only the five lower + shr %cl,%al // bits of cl to determine the number + jnz is80186 // of shifts. sti - xor si,si - mov cx,#0xffff + xor %si,%si + mov $0xffff,%cx + nop rep - seg es +// seg es lodsb - or cx,cx + or %cx,%cx jz isv30 call queue jz is8088 - mov cl,#1 - lea si,p8086 + mov $1,%cl + lea p8086,%si jmp getfpu -is8088: xor cl,cl - lea si,p8088 +is8088: xor %cl,%cl + lea p8088,%si jmp getfpu is80186:call queue jz is80188 - mov cl,#5 - lea si,p80186 + mov $5,%cl + lea p80186,%si jmp getfpu -is80188:mov cl,#4 - lea si,p80188 +is80188:mov $4,%cl + lea p80188,%si jmp getfpu isv30: call queue jz isv20 - mov cl,#3 - lea si,pv30 + mov $3,%cl + lea pv30,%si jmp getfpu -isv20: mov cl,#2 - lea si,pv20 +isv20: mov $2,%cl + lea pv20,%si jmp getfpu #endif #if !defined (CONFIG_ROMCODE) || defined(CONFIG_CPU_80286) -is80286:mov cl,#6 - lea si,p80286 -! jmp getfpu +is80286:mov $6,%cl + lea p80286,%si +// jmp getfpu #endif getfpu: - ! - ! Store the processor name and type - ! - push cx - mov ax,#INITSEG - mov es,ax - mov di,#0x30 - mov cx,#16 + // + // Store the processor name and type + // + push %cx + mov $INITSEG,%ax + mov %ax,%es + mov $0x30,%di + mov $16,%cx cld con_cp1: lodsb stosb - or al,al + or %al,%al loopnz con_cp1 - mov di,#0x50 - lea si,v_id - mov cx,#13 + mov $0x50,%di + lea v_id,%si + mov $13,%cx rep movsb - pop cx - mov ax,#INITSEG - mov ds,ax - mov [0x20],cl + pop %cx + mov $INITSEG,%ax + mov %ax,%ds + mov %cl,0x20 #ifdef CONFIG_HW_FPU fninit fnstcw copro - mov ax,copro - cmp ah,#3 + mov copro,%ax + cmp $3,%ah jne nofpu - and copro,#0xff7f + and $0xff7f,copro fldcw copro fdisi fstcw copro - test copro,#0x0080 + test $0x0080,copro jnz is8087 - finit ! 80287/387 test + finit // 80287/387 test fld1 fldz - fdiv st,st(1) - fld st + fdiv %st,%st(1) + fld %st fchs fcompp fstsw copro - mov ax,copro + mov copro,%ax sahf jz is80287 - mov cl,#3 + mov $3,%cl jmp gotfpu -is80287: mov cl,#2 +is80287: mov $2,%cl jmp gotfpu -is8087: mov cl,#1 +is8087: mov $1,%cl jmp gotfpu #endif -nofpu: xor cl,cl - -gotfpu: mov ax,#INITSEG - mov es,ax - mov ax,#SETUPSEG - mov ds,ax - seg es - mov [0x21],cl - xor ch,ch - add cx,cx - lea si,fpu_t - add si,cx - mov si,[si] - mov di,#0x40 - mov cx,#16 +nofpu: xor %cl,%cl + +gotfpu: mov $INITSEG,%ax + mov %ax,%es + mov $SETUPSEG,%ax + mov %ax,%ds +// seg es + mov %cl,%es:0x21 + xor %ch,%ch + add %cx,%cx + lea fpu_t,%si + add %cx,%si + mov (%si),%si + mov $0x40,%di + mov $16,%cx cld con_cp2: lodsb stosb - or al,al + or %al,%al loopnz con_cp2 ret #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) +/* ! ! Determine the length of the prefetch queue. 8088/188/v20 has ! a 4 bytes queue, 8086/186/v30 has 6 bytes. @@ -879,6 +920,7 @@ con_cp2: ! In ROM we can't change the code, we must copy to RAM ! Using Kernel dataseg ! +*/ queue: #ifdef CONFIG_ROMCODE push ds @@ -902,16 +944,16 @@ queue: #endif queue_start: - mov ax,cs - mov es,ax - xor dx,dx + mov %cs,%ax + mov %ax,%es + xor %dx,%dx std - lea di,q_end + lea q_end,%di #ifdef CONFIG_ROMCODE - sub di,#queue_start ;we have new offset + sub $queue_start,%di //;we have new offset #endif - mov al,#0xfb - mov cx,#0x03 + mov $0xfb,%al + mov $0x03,%cx cli rep stosb @@ -919,220 +961,226 @@ queue_start: nop nop nop - inc dx + inc %dx q_end: nop sti #ifdef CONFIG_ROMCODE - jmp far CONFIG_ROM_SETUP_CODE:queue_end + ljmp $CONFIG_ROM_SETUP_CODE,$queue_end queue_end: #endif - or dx,dx + or %dx,%dx ret #endif +/* ! ! Determine the number and type of floppy disks ! attached to our system. ! +*/ #ifdef CONFIG_HW_FLOPPY_DRIVE getfloppy: - mov ax,#INITSEG - mov es,ax - mov ds,ax - mov bl,[0x20] ! Get processor type - mov ax,#SETUPSEG - mov ds,ax - int 0x11 ! only ax is changed by int 0x11 - test al,#1 ! bit 0 set -> floppy present + mov $INITSEG,%ax + mov %ax,%es + mov %ax,%ds + mov 0x20,%bl // Get processor type + mov $SETUPSEG,%ax + mov %ax,%ds + int $0x11 // only ax is changed by int 0x11 + test $1,%al // bit 0 set -> floppy present jz no_floppy - cmp bl,#5 + cmp $5,%bl jle is_xt +/* ! ! AT architecture. The BIOS tells us the number and capacity of the ! available floppy disks. ! - xor dl,dl - mov ah,#0x08 - push es - int 0x13 ! changes es - pop es - jc no_floppy ! c-flag is set if operation fails - or bl,bl ! the drive code is returned in bl - jz no_floppy ! it has to be in the range 1..6 - cmp bl,#6 +*/ + xor %dl,%dl + mov $0x08,%ah + push %es + int $0x13 // changes es + pop %es + jc no_floppy // c-flag is set if operation fails + or %bl,%bl // the drive code is returned in bl + jz no_floppy // it has to be in the range 1..6 + cmp $6,%bl ja no_floppy - xor bh,bh - dec bl - add bl,bl - mov si,floppies[bx] - mov di,#0x8c - mov cx,#3 + xor %bh,%bh + dec %bl + add %bl,%bl + mov floppies(%bx),%si + mov $0x8c,%di + mov $3,%cx rep movsw - int 0x11 ! check for second floppy - test al,#0xc0 ! Bit 6,7 + int $0x11 // check for second floppy + test $0xc0,%al // Bit 6,7 jz no_floppy - mov ah,#0x08 - mov dl,#0x01 - push es - int 0x13 ! changes es - pop es - jc no_floppy ! c-flag is set if operation fails - or bl,bl ! the drive code is returned in bl - jz no_floppy ! it has to be in the range 1..6 - cmp bl,#6 + mov $0x08,%ah + mov $0x01,%dl + push %es + int $0x13 // changes es + pop %es + jc no_floppy // c-flag is set if operation fails + or %bl,%bl // the drive code is returned in bl + jz no_floppy // it has to be in the range 1..6 + cmp $6,%bl ja no_floppy - xor bh,bh - dec bl - add bl,bl - mov si,floppies[bx] - mov di,#(0x8c+6) - mov cx,#3 + xor %bh,%bh + dec %bl + add %bl,%bl + mov floppies(%bx),%si + mov $0x8c+6,%di + mov $3,%cx rep movsw ret is_xt: +/* ! ! XT architecture. Ask the BIOS about the number of available floppy ! disks and assume that they have a capacity of 360 KB. ! ! ax contains the result of int 0x11 when jumped here! ! - int 0x11 - mov cx,#3 - mov di,#0x8c - lea si,f360 +*/ + int $0x11 + mov $3,%cx + mov $0x8c,%di + lea f360,%si rep movsw - test al,#0xc0 ! Bit 6,7 - jz no_floppy ! second floppy detected - mov cx,#3 - lea si,f360 + test $0xc0,%al // Bit 6,7 + jz no_floppy // second floppy detected + mov $3,%cx + lea f360,%si rep movsw no_floppy: ret -f360: dw 2,9,40 -f720: dw 2,9,80 -f1200: dw 2,15,80 -f1440: dw 2,18,80 -f2880: dw 2,36,80 -floppies: dw f360, f1200, f720, f1440, f2880, f2880 +f360: .word 2,9,40 +f720: .word 2,9,80 +f1200: .word 2,15,80 +f1440: .word 2,18,80 +f2880: .word 2,36,80 +floppies: .word f360, f1200, f720, f1440, f2880, f2880 #endif -! -! gethd -! +// +// gethd +// #ifdef CONFIG_HW_HARD_DRIVE gethd: - mov ax,#INITSEG - mov ds,ax - mov es,ax -! mov ah,#0x10 ! Test for drive 0 ready -! mov dl,#0x80 -! int 0x13 -! jc no_hd0 -! or ah,ah -! jnz no_hd0 - mov ah,#0x08 ! check for first drive - mov dl,#0x80 - int 0x13 - jc no_hd0 ! carry flag set -> an error occured - or ah,ah - jnz no_hd0 ! error code != 0 -> bad - or dl,dl - jz no_hd0 ! dl contains the number of harddisks - push dx - mov dl,dh - xor dh,dh - inc dx ! DX -> no. of heads - mov bx,cx - and bx,#0x3f ! BX -> no. of sectors - mov al,ch - mov ah,cl - mov cl, #6 - shr ah,cl ! AX -> no. of cylinders - 1 - mov [0x80],dx - mov [0x82],bx - mov [0x84],ax - pop dx - dec dl ! only one harddisk? + mov $INITSEG,%ax + mov %ax,%ds + mov %ax,%es + + + + + + + mov $0x08,%ah // check for first drive + mov $0x80,%dl + int $0x13 + jc no_hd0 // carry flag set -> an error occured + or %ah,%ah + jnz no_hd0 // error code != 0 -> bad + or %dl,%dl + jz no_hd0 // dl contains the number of harddisks + push %dx + mov %dh,%dl + xor %dh,%dh + inc %dx // DX -> no. of heads + mov %cx,%bx + and $0x3f,%bx // BX -> no. of sectors + mov %ch,%al + mov %cl,%ah + mov $6,%cl + shr %cl,%ah // AX -> no. of cylinders - 1 + mov %dx,0x80 + mov %bx,0x82 + mov %ax,0x84 + pop %dx + dec %dl // only one harddisk? jz no_hd1 no_hd0: -! mov ah,#0x10 ! Test for drive 1 ready -! mov dl,#0x81 -! int 0x13 -! jc no_hd1 -! or ah,ah -! jnz no_hd1 - mov ah,#0x08 ! check for second drive - mov dl,#0x81 - int 0x13 + + + + + + + mov $0x08,%ah // check for second drive + mov $0x81,%dl + int $0x13 jc no_hd1 - or ah,ah + or %ah,%ah jnz no_hd1 - mov dl,dh - xor dh,dh - inc dx ! DX -> no. of heads - mov bx,cx - and bx,#0x3f ! BX -> no. of sectors - mov al,ch - mov ah,cl - mov cl,#6 - shr ah,cl ! AX -> no. of cylinders - 1 - mov [0x86],dx - mov [0x88],bx - mov [0x8a],ax + mov %dh,%dl + xor %dh,%dh + inc %dx // DX -> no. of heads + mov %cx,%bx + and $0x3f,%bx // BX -> no. of sectors + mov %ch,%al + mov %cl,%ah + mov $6,%cl + shr %cl,%ah // AX -> no. of cylinders - 1 + mov %dx,0x86 + mov %bx,0x88 + mov %ax,0x8a no_hd1: ret #endif -! -! The processor name must not be longer than 15 characters! -! +// +// The processor name must not be longer than 15 characters! +// #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) p8088: .ascii "Intel 8088" - db 0 + .byte 0 p8086: .ascii "Intel 8086" - db 0 + .byte 0 pv20: .ascii "NEC V20" - db 0 + .byte 0 pv30: .ascii "NEC V30" - db 0 + .byte 0 p80188: .ascii "Intel 80188" - db 0 + .byte 0 p80186: .ascii "Intel 80186" - db 0 + .byte 0 #endif #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_80286) p80286: .ascii "Intel 80286" - db 0 + .byte 0 #endif #if !defined(CONFIG_ROMCODE) px86: .ascii "Unknown x86" - db 0 + .byte 0 #endif -! -! Here is the CPU id stored -! -v_id: db 0,0,0,0 -v_id2: db 0,0,0,0 -v_id3: db 0,0,0,0 - db 0 -! -! FPU names. must be not longer than 15 characters! -! +// +// Here is the CPU id stored +// +v_id: .byte 0,0,0,0 +v_id2: .byte 0,0,0,0 +v_id3: .byte 0,0,0,0 + .byte 0 +// +// FPU names. must be not longer than 15 characters! +// f_none: .ascii "no fpu" - db 0 + .byte 0 #ifdef CONFIG_HW_FPU f8087: .ascii "8087" - db 0 + .byte 0 f80287: .ascii "80287" - db 0 + .byte 0 f80387: .ascii "80387 or above" - db 0 + .byte 0 #endif fpu_t: .word f_none #ifdef CONFIG_HW_FPU @@ -1140,23 +1188,16 @@ fpu_t: .word f_none #endif #ifdef CONFIG_HW_FPU -copro: dw 0 +copro: .word 0 #endif no_sig_mess: .ascii "No ELKS setup signature found ..." - db 0x00 + .byte 0x00 -! variables in ROM are not very usefull +// variables in ROM are not very usefull start_sys_seg: .word SYSSEG -! This must be last +// This must be last setup_sig1: .word SIG1 setup_sig2: .word SIG2 - -.text -endtext: -.data -enddata: -.bss -endbss: diff --git a/elks/arch/i86/drivers/char/Makefile b/elks/arch/i86/drivers/char/Makefile index 8ab20a750..e9ae80be1 100644 --- a/elks/arch/i86/drivers/char/Makefile +++ b/elks/arch/i86/drivers/char/Makefile @@ -40,10 +40,15 @@ ifeq ($(CONFIG_ARCH_SIBO), y) OBJS = init.o con_asm.o font.o sibo_key.o key_asm.o mem.o \ sibo_con.o meta.o ntty.o ser_asm.o pty.o else -OBJS = bioscon.o bioscon-low.o serial.o lp.o xt_key.o init.o dircon.o mem.o \ - ntty.o meta.o tcpdev.o pty.o bell.o # clist.o tty.o +OBJS = serial.o lp.o xt_key.o init.o dircon.o mem.o \ + ntty.o meta.o tcpdev.o pty.o bell.o + +ifdef CONFIG_CONSOLE_BIOS +OBJS += bioscon.o bioscon-low.o endif +endif # CONFIG_ARCH_SIBO + ######################################################################### # Commands. diff --git a/elks/arch/i86/drivers/char/bioscon-low.s b/elks/arch/i86/drivers/char/bioscon-low.s index 97ece015c..96f879f7d 100644 --- a/elks/arch/i86/drivers/char/bioscon-low.s +++ b/elks/arch/i86/drivers/char/bioscon-low.s @@ -1,87 +1,87 @@ .text -; int poll_kbd () +// int poll_kbd () - .define _poll_kbd + .global poll_kbd -_poll_kbd: - mov ah,#1 - int 0x16 +poll_kbd: + mov $1,%ah + int $0x16 jnz nhp1 - xor ax,ax + xor %ax,%ax nhp1: - or ax,ax + or %ax,%ax jz nhp2 - xor ah,ah - int 0x16 + xor %ah,%ah + int $0x16 nhp2: ret -; void SetDisplayPage (byte_t page) -; compiler pushes byte as word +// void SetDisplayPage (byte_t page) +// compiler pushes byte as word - .define _SetDisplayPage + .global SetDisplayPage -_SetDisplayPage: - mov bx,sp - mov al,[bx+2] - mov ah,#5 - int 0x10 +SetDisplayPage: + mov %sp,%bx + mov 2(%bx),%al + mov $5,%ah + int $0x10 ret -; void PosCursLow (byte_t x, byte_t y, byte_t page) -; compiler pushes byte as word +// void PosCursLow (byte_t x, byte_t y, byte_t page) +// compiler pushes byte as word - .define _PosCursLow + .global PosCursLow -_PosCursLow: - mov bx,sp - mov dl,[bx+2] - mov dh,[bx+4] - mov bh,[bx+6] - mov ah,#2 - int 0x10 +PosCursLow: + mov %sp,%bx + mov 2(%bx),%dl + mov 4(%bx),%dh + mov 6(%bx),%bh + mov $2,%ah + int $0x10 ret -; void VideoWriteLow (byte_t c, byte_t attr, byte_t page) -; compiler pushes byte as word +// void VideoWriteLow (byte_t c, byte_t attr, byte_t page) +// compiler pushes byte as word - .define _VideoWriteLow + .global VideoWriteLow -_VideoWriteLow: - mov bx,sp - mov al,[bx+2] - mov cl,[bx+4] - mov bh,[bx+6] - mov bl,cl - mov cx,#1 - mov ah,#9 - int 0x10 +VideoWriteLow: + mov %sp,%bx + mov 2(%bx),%al + mov 4(%bx),%cl + mov 6(%bx),%bh + mov %cl,%bl + mov $1,%cx + mov $9,%ah + int $0x10 ret -; void ScrollLow (byte_t attr, byte_t n, byte_t x, byte_t y, byte_t xx, byte_t yy) -; compiler pushes byte as word - - .define _ScrollLow - -_ScrollLow: - mov bx,sp - mov cl,[bx+6] - mov ch,[bx+8] - mov dl,[bx+10] - mov dh,[bx+12] - mov al,[bx+4] - mov bh,[bx+2] - mov ah,#6 - cmp al,#0 +// void ScrollLow (byte_t attr, byte_t n, byte_t x, byte_t y, byte_t xx, byte_t yy) +// compiler pushes byte as word + + .global ScrollLow + +ScrollLow: + mov %sp,%bx + mov 6(%bx),%cl + mov 8(%bx),%ch + mov 10(%bx),%dl + mov 12(%bx),%dh + mov 4(%bx),%al + mov 2(%bx),%bh + mov $6,%ah + cmp $0,%al jge scroll_next - inc ah - neg al + inc %ah + neg %al scroll_next: - int 0x10 + int $0x10 ret diff --git a/elks/arch/i86/drivers/net/ne2k-mac.s b/elks/arch/i86/drivers/net/ne2k-mac.s index f8b70e17d..e5e2884c9 100644 --- a/elks/arch/i86/drivers/net/ne2k-mac.s +++ b/elks/arch/i86/drivers/net/ne2k-mac.s @@ -1,939 +1,859 @@ -;------------------------------------------------------------------------------ -; NE2K driver - low part - MAC routines -;------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- +// NE2K driver - low part - MAC routines +//----------------------------------------------------------------------------- -; TODO: move definitions to ne2k-defs.s + .code16 -; I/O base @ 300h +// TODO: move definitions to ne2k-defs.s -io_ne2k_command EQU $300 +// I/O base @ 300h -io_ne2k_rx_first EQU $301 ; page 0 -io_ne2k_rx_last EQU $302 ; page 0 -io_ne2k_rx_get EQU $303 ; page 0 +io_ne2k_command = 0x0300 -; This is not a true NE2K register -;io_ne2k_rx_put1 EQU $306 ; page 0 - read +io_ne2k_rx_first = 0x0301 // page 0 +io_ne2k_rx_last = 0x0302 // page 0 +io_ne2k_rx_get = 0x0303 // page 0 -io_ne2k_tx_start EQU $304 ; page 0 - write -io_ne2k_tx_len1 EQU $305 ; page 0 - write -io_ne2k_tx_len2 EQU $306 ; page 0 - write +// This is not a true NE2K register +//io_ne2k_rx_put1 = 0x0306 // page 0 - read -io_ne2k_int_stat EQU $307 ; page 0 +io_ne2k_tx_start = 0x0304 // page 0 - write +io_ne2k_tx_len1 = 0x0305 // page 0 - write +io_ne2k_tx_len2 = 0x0306 // page 0 - write -io_ne2k_dma_addr1 EQU $308 ; page 0 -io_ne2k_dma_addr2 EQU $309 ; page 0 -io_ne2k_dma_len1 EQU $30A ; page 0 - write -io_ne2k_dma_len2 EQU $30B ; page 0 - write +io_ne2k_int_stat = 0x0307 // page 0 -io_ne2k_rx_stat EQU $30C ; page 0 - read +io_ne2k_dma_addr1 = 0x0308 // page 0 +io_ne2k_dma_addr2 = 0x0309 // page 0 +io_ne2k_dma_len1 = 0x030A // page 0 - write +io_ne2k_dma_len2 = 0x030B // page 0 - write -io_ne2k_rx_conf EQU $30C ; page 0 - write -io_ne2k_tx_conf EQU $30D ; page 0 - write -io_ne2k_data_conf EQU $30E ; page 0 - write -io_ne2k_int_mask EQU $30F ; page 0 - write +io_ne2k_rx_stat = 0x030C // page 0 - read -io_ne2k_unicast EQU $301 ; page 1 - 6 bytes -io_ne2k_rx_put EQU $307 ; page 1 -io_ne2k_multicast EQU $308 ; page 1 - 8 bytes +io_ne2k_rx_conf = 0x030C // page 0 - write +io_ne2k_tx_conf = 0x030D // page 0 - write +io_ne2k_data_conf = 0x030E // page 0 - write +io_ne2k_int_mask = 0x030F // page 0 - write -io_ne2k_data_io EQU $310 ; 2 bytes +io_ne2k_unicast = 0x0301 // page 1 - 6 bytes +io_ne2k_rx_put = 0x0307 // page 1 +io_ne2k_multicast = 0x0308 // page 1 - 8 bytes -io_ne2k_reset EQU $31F +io_ne2k_data_io = 0x0310 // 2 bytes +io_ne2k_reset = 0x031F -; Ring segmentation -tx_first EQU $40 -rx_first EQU $46 -rx_last EQU $80 +// Ring segmentation +tx_first = 0x40 +rx_first = 0x46 +rx_last = 0x80 - .TEXT +tx_first_word = 0x4000 +rx_first_word = 0x4600 +rx_last_word = 0x8000 + .text -;------------------------------------------------------------------------------- -; Select register page -;------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Select register page +//----------------------------------------------------------------------------- -; AL : page number (0 or 1) +// AL : page number (0 or 1) page_select: - push ax - push dx + mov %al,%ah + and $0x01,%ah + shl $6,%ah - mov ah, al - and ah, #$01 - shl ah, #6 + mov $io_ne2k_command,%dx + in %dx,%al + and $0x3F,%al + or %ah,%al + out %al,%dx - mov dx, #io_ne2k_command - in al, dx - and al, #$3F - or al, ah - out dx, al - - pop dx - pop ax ret +//----------------------------------------------------------------------------- +// Set unicast address (aka MAC address) +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; Set unicast address (aka MAC address) -;------------------------------------------------------------------------------- - -; arg1 : pointer to unicast address (6 bytes) +// arg1 : pointer to unicast address (6 bytes) -_ne2k_addr_set: + .global ne2k_addr_set - push bp - mov bp, sp +ne2k_addr_set: - push ax - push cx - push dx - push si + push %bp + mov %sp,%bp + push %si // used by compiler - mov si, [bp + $4] + mov 4(%bp),%si - ; select page 1 + // select page 1 - mov al, #1 + mov $1,%al call page_select - ; load MAC address + // load MAC address - mov dx, #io_ne2k_unicast - mov cx, #6 + mov $io_ne2k_unicast,%dx + mov $6,%cx cld ems_loop: lodsb - out dx, al - inc dx + out %al,%dx + inc %dx loop ems_loop - pop si - pop dx - pop cx - pop ax - - pop bp + pop %si + pop %bp ret +//----------------------------------------------------------------------------- +// DMA initialization +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; DMA initialization -;------------------------------------------------------------------------------- - -; BX : chip memory address (4000h...8000h) -; CX : byte count +// BX : chip memory address (4000h...8000h) +// CX : byte count dma_init: - push ax - push dx + push %ax + push %dx - ; select page 0 + // select page 0 - xor al, al + xor %al,%al call page_select - ; set DMA start address + // set DMA start address - mov dx, #io_ne2k_dma_addr1 - mov al, bl - out dx, al + mov $io_ne2k_dma_addr1,%dx + mov %bl,%al + out %al,%dx - ; mov dx, #io_ne2k_dma_addr2 - inc dx - mov al, bh - out dx, al + inc %dx // io_ne2k_dma_addr2 + mov %bh,%al + out %al,%dx - ; set DMA byte count + // set DMA byte count - ; mov dx, #io_ne2k_dma_len1 - inc dx - mov al, cl - out dx, al + inc %dx // io_ne2k_dma_len1 + mov %cl,%al + out %al,%dx - ; mov dx, #io_ne2k_dma_len2 - inc dx - mov al, ch - out dx, al + inc %dx // io_ne2k_dma_len2 + mov %ch,%al + out %al,%dx - pop dx - pop ax + pop %dx + pop %ax ret +//----------------------------------------------------------------------------- +// Write block to chip with internal DMA +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; Write block to chip with internal DMA -;------------------------------------------------------------------------------- - -; BX : chip memory address (to write to) -; CX : byte count -; DS:SI : host memory address (to read from) +// BX : chip memory address (to write to) +// CX : byte count +// DS:SI : host memory address (to read from) dma_write: - push ax - push cx - push dx - push si + push %ax + push %cx + push %dx + push %si call dma_init - ; start DMA write + // start DMA write - mov dx, #io_ne2k_command - in al, dx - and al, #$C7 - or al, #$10 - out dx, al + mov $io_ne2k_command,%dx + in %dx,%al + and $0xC7,%al + or $0x10,%al // 010b : write + out %al,%dx - ; I/O write loop + // I/O write loop - mov dx, #io_ne2k_data_io + mov $io_ne2k_data_io,%dx cld emw_loop: lodsb - out dx, al + out %al,%dx loop emw_loop - ; maybe check DMA completed ? + // maybe check DMA completed ? - pop si - pop dx - pop cx - pop ax + pop %si + pop %dx + pop %cx + pop %ax ret +//----------------------------------------------------------------------------- +// Read block from chip with internal DMA +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; Read block from chip with internal DMA -;------------------------------------------------------------------------------ - -; BX : chip memory to read from -; CX : byte count -; ES:DI : host memory to write to +// BX : chip memory to read from +// CX : byte count +// ES:DI : host memory to write to dma_read: - push ax - push cx - push dx - push di + push %ax + push %cx + push %dx + push %di call dma_init - ; start DMA read + // start DMA read + + mov $io_ne2k_command,%dx + in %dx,%al + and $0xC7,%al + or $0x08,%al // 001b : read + out %al,%dx - mov dx, #io_ne2k_command - in al, dx - and al, #$C7 - or al, #$08 - out dx, al + // I/O read loop - ; I/O read loop + push %es // compiler scratch + mov %ds,%ax + mov %ax,%es - mov dx, #io_ne2k_data_io + mov $io_ne2k_data_io,%dx cld emr_loop: - in al, dx + in %dx,%al stosb loop emr_loop - ; maybe check DMA completed ? + pop %es - pop di - pop dx - pop cx - pop ax - ret + // maybe check DMA completed ? + pop %di + pop %dx + pop %cx + pop %ax + ret -;------------------------------------------------------------------------------ -; Get RX status -;------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- +// Get RX status +//----------------------------------------------------------------------------- -; returns: +// returns: -; AX: status -; 01h = packet received +// AX: status +// 01h = packet received -_ne2k_rx_stat: + .global ne2k_rx_stat - push cx - push dx +ne2k_rx_stat: - ; get RX put pointer + // get RX put pointer - mov al, #1 + mov $1,%al call page_select - mov dx, #io_ne2k_rx_put - in al, dx - mov cl, al + mov $io_ne2k_rx_put,%dx + in %dx,%al + mov %al,%cl - ; get RX get pointer + // get RX get pointer - xor al, al + xor %al,%al call page_select - mov dx, #io_ne2k_rx_get - in al, dx - inc al - cmp al, #rx_last + mov $io_ne2k_rx_get,%dx + in %dx,%al + inc %al + cmp $rx_last,%al jnz nrs_nowrap - mov al, #rx_first + mov $rx_first,%al nrs_nowrap: - ; check ring is not empty + // check ring is not empty - cmp cl, al + cmp %al,%cl jz nrs_empty - mov ax, #1 + mov $1,%ax jmp nrs_exit nrs_empty: - xor ax, ax + xor %ax,%ax nrs_exit: - pop dx - pop cx ret +//----------------------------------------------------------------------------- +// Get received packet +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; Get received packet -;------------------------------------------------------------------------------ +// arg1 : packet buffer to write to -; arg1 : packet buffer to write to +// returns: -; returns: +// AX : error code -; AX : error code + .global ne2k_pack_get -_ne2k_pack_get: +ne2k_pack_get: - push bp - mov bp,sp + push %bp + mov %sp,%bp + push %di // used by compiler - push bx - push cx - push dx - push di + // get RX put pointer - ; get RX put pointer - - mov al, #1 + mov $1,%al call page_select - mov dx, #io_ne2k_rx_put - in al, dx - mov cl, al + mov $io_ne2k_rx_put,%dx + in %dx,%al + mov %al,%cl - ; get RX get pointer + // get RX get pointer - xor al, al + xor %al,%al call page_select - mov dx, #io_ne2k_rx_get - in al, dx - inc al - cmp al, #rx_last + mov $io_ne2k_rx_get,%dx + in %dx,%al + inc %al + cmp $rx_last,%al jnz npg_nowrap1 - mov al, #rx_first + mov $rx_first,%al npg_nowrap1: - ; check ring is not empty + // check ring is not empty - cmp cl, al + cmp %al,%cl jz npg_err - xor bl, bl - mov bh, al + xor %bl,%bl + mov %al,%bh - ; get packet header + // get packet header - mov di, [bp + 4] - mov cx, #4 + mov 4(%bp),%di + mov $4,%cx call dma_read - mov ax, [di + 0] ; AH : next record, AL : status - mov cx, [di + 2] ; packet size (without CRC) + mov 0(%di),%ax // AH : next record, AL : status + mov 2(%di),%cx // packet size (without CRC) - ; check packet size + // check packet size - or cx, cx + or %cx,%cx jz npg_err - cmp cx, #1528 ; max - head - crc + cmp $1528,%cx // max - head - crc jnc npg_err - add bx, #4 - add di, #4 + add $4,%bx + add $4,%di - push ax - push cx + push %ax + push %cx - mov ax, bx - add ax, cx - cmp ax, #$8000 + mov %bx,%ax + add %cx,%ax + cmp $rx_last_word,%ax jbe npg_nowrap2 - mov ax, #$8000 - sub ax, bx - mov cx, ax + mov $rx_last_word,%ax + sub %bx,%ax + mov %ax,%cx npg_nowrap2: - ; get packet body (first segment) + // get packet body (first segment) call dma_read - add di, cx + add %cx,%di - mov ax, cx - pop cx - sub cx, ax + mov %cx,%ax + pop %cx + sub %ax,%cx jz npg_nowrap3 - ; get packet body (second segment) + // get packet body (second segment) - mov bx, #$4000 + mov $rx_first_word,%bx call dma_read npg_nowrap3: - ; update RX get pointer + // update RX get pointer - pop ax - xchg ah, al - dec al - cmp al, #rx_first + pop %ax + xchg %al,%ah + dec %al + cmp $rx_first,%al jae npg_next - mov al, #rx_last - 1 + mov $rx_last - 1,%al npg_next: - mov dx, #io_ne2k_rx_get - out dx, al + mov $io_ne2k_rx_get,%dx + out %al,%dx - xor ax, ax + xor %ax,%ax jmp npg_exit npg_err: - mov ax, #$FFFF + mov $-1,%ax npg_exit: - pop di - pop dx - pop cx - pop bx - pop bp + pop %di + pop %bp ret +//----------------------------------------------------------------------------- +// Get TX status +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; Get TX status -;------------------------------------------------------------------------------ - -; returns: +// returns: -; AX: -; 02h = ready to send +// AX: +// 02h = ready to send -_ne2k_tx_stat: + .global ne2k_tx_stat - push dx +ne2k_tx_stat: - mov dx, #io_ne2k_command - in al, dx - and al, #$04 + mov $io_ne2k_command,%dx + in %dx,%al + and $0x04,%al jz nts_ready - xor ax, ax + xor %ax,%ax jmp nts_exit nts_ready: - mov ax, #2 + mov $2,%ax nts_exit: - pop dx ret +//----------------------------------------------------------------------------- +// Put packet to send +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; Put packet to send -;------------------------------------------------------------------------------ +// arg1 : packet buffer to read from +// arg2 : size in bytes -; arg1 : packet buffer to read from -; arg2 : size in bytes +// returns: -; returns: +// AX : error code -; AX : error code + .global ne2k_pack_put -_ne2k_pack_put: +ne2k_pack_put: - push bp - mov bp,sp + push %bp + mov %sp,%bp + push %si // used by compiler - push bx - push cx - push dx - push si - - xor al,al + xor %al,%al call page_select - ; write packet to chip memory + // write packet to chip memory - mov cx, [bp + 6] - xor bl,bl - mov bh, #tx_first - mov si, [bp + 4] + mov 6(%bp),%cx + xor %bl,%bl + mov $tx_first,%bh + mov 4(%bp),%si call dma_write - ; set TX pointer and length + // set TX pointer and length - mov dx, #io_ne2k_tx_start - mov al, #tx_first - out dx, al + mov $io_ne2k_tx_start,%dx + mov $tx_first,%al + out %al,%dx - mov dx, #io_ne2k_tx_len1 - mov al, cl - out dx, al - inc dx ; = io_ne2k_tx_len2 - mov al, ch - out dx, al + inc %dx // io_ne2k_tx_len1 + mov %cl,%al + out %al,%dx + inc %dx // = io_ne2k_tx_len2 + mov %ch,%al + out %al,%dx - ; start TX + // start TX - mov dx, #io_ne2k_command - mov al, #$26 - out dx, al + mov $io_ne2k_command,%dx + mov $0x26,%al + out %al,%dx - xor ax, ax + xor %ax, %ax - pop si - pop dx - pop cx - pop bx - pop bp + pop %si + pop %bp ret +//----------------------------------------------------------------------------- +// Get NE2K interrupt status +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; Get NE2K interrupt status -;------------------------------------------------------------------------------ - -; returns: +// returns: -; AX : status -; 01h = packet received -; 02h = packet sent -; 10h = RX ring overflow +// AX : status +// 01h = packet received +// 02h = packet sent +// 10h = RX ring overflow -_ne2k_int_stat: + .global ne2k_int_stat - push dx +ne2k_int_stat: - ; select page 0 + // select page 0 - xor al, al + xor %al,%al call page_select - ; get interrupt status + // get interrupt status - xor ah, ah + xor %ah,%ah - mov dx, #io_ne2k_int_stat - in al, dx - test al, #$03 + mov $io_ne2k_int_stat,%dx + in %dx,%al + test $0x03,%al jz nis_next - ; acknowledge interrupt + // acknowledge interrupt - out dx, al + out %al,%dx nis_next: - pop dx ret +//----------------------------------------------------------------------------- +// NE2K initialization +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; NE2K initialization -;------------------------------------------------------------------------------- + .global ne2k_init -_ne2k_init: +ne2k_init: - push cx - push dx + // select page 0 - ; select page 0 - - xor al,al + xor %al,%al call page_select - ; Stop DMA and MAC - ; TODO: is this really needed after a reset ? + // Stop DMA and MAC + // TODO: is this really needed after a reset ? - mov dx, #io_ne2k_command - in al, dx - and al, #$C0 - or al, #$21 - out dx, al + mov $io_ne2k_command,%dx + in %dx,%al + and $0xC0,%al + or $0x21,%al + out %al,%dx - ; data I/O in single bytes - ; and low endian for 80188 - ; plus magical stuff (48h) + // data I/O in single bytes + // and low endian for 80188 + // plus magical stuff (48h) - mov dx, #io_ne2k_data_conf - mov al, #$48 - out dx, al + mov $io_ne2k_data_conf,%dx + mov $0x48,%al + out %al,%dx - ; accept packet without error - ; unicast & broadcast & promiscuous + // accept packet without error + // unicast & broadcast & promiscuous - mov dx, #io_ne2k_rx_conf - mov al, #$54 - out dx, al + mov $io_ne2k_rx_conf,%dx + mov $0x54,%al + out %al,%dx - ; half-duplex and internal loopback - ; to insulate the MAC while stopped - ; TODO: loopback cannot be turned off later ! + // half-duplex and internal loopback + // to insulate the MAC while stopped + // TODO: loopback cannot be turned off later ! - mov dx, #io_ne2k_tx_conf - mov al, #0 ; 2 - out dx, al + mov $io_ne2k_tx_conf,%dx + mov $0,%al // 2 for loopback + out %al,%dx - ; set RX ring limits - ; all 16KB on-chip memory - ; except one TX frame at beginning (6 x 256B) + // set RX ring limits + // all 16KB on-chip memory + // except one TX frame at beginning (6 x 256B) - mov dx, #io_ne2k_rx_first - mov al, #rx_first - out dx, al + mov $io_ne2k_rx_first,%dx + mov $rx_first,%al + out %al,%dx - mov dx, #io_ne2k_rx_last - mov al, #rx_last - out dx, al + inc %dx // io_ne2k_rx_last + mov $rx_last,%al + out %al,%dx - mov dx, #io_ne2k_tx_start - mov al, #tx_first - out dx, al + mov $io_ne2k_tx_start,%dx + mov $tx_first,%al + out %al,%dx - ; set RX get pointer + // set RX get pointer - mov dx, #io_ne2k_rx_get - mov al, #rx_first - out dx, al + mov $io_ne2k_rx_get,%dx + mov $rx_first,%al + out %al,%dx - ; clear DMA length - ; TODO: is this really needed after a reset ? + // clear DMA length + // TODO: is this really needed after a reset ? - xor al, al - mov dx, #io_ne2k_dma_len1 - out dx, al - inc dx ; = io_ne2k_dma_len2 - out dx, al + xor %al,%al + mov $io_ne2k_dma_len1,%dx + out %al,%dx + inc %dx // = io_ne2k_dma_len2 + out %al,%dx - ; clear all interrupt flags + // clear all interrupt flags - mov dx, #io_ne2k_int_stat - mov al, #$7F - out dx, al + mov $io_ne2k_int_stat,%dx + mov $0x7F,%al + out %al,%dx - ; set interrupt mask - ; TX & RX without error and overflow + // set interrupt mask + // TX & RX without error and overflow - mov dx, #io_ne2k_int_mask - mov al, #$03 - out dx, al + mov $io_ne2k_int_mask,%dx + mov $0x03,%al + out %al,%dx - ; select page 1 + // select page 1 - mov al, #1 + mov $1,%al call page_select - ; clear unicast address + // clear unicast address - mov cx, #6 - mov dx, #io_ne2k_unicast - xor al, al + mov $6,%cx + mov io_ne2k_unicast,%dx + xor %al,%al ei_loop_u: - out dx, al - inc dx + out %al,%dx + inc %dx loop ei_loop_u - ; clear multicast bitmap + // clear multicast bitmap - mov cx, #8 - mov dx, #io_ne2k_multicast - xor al, al + mov $8,%cx + mov $io_ne2k_multicast,%dx ei_loop_m: - out dx, al - inc dx + out %al,%dx + inc %dx loop ei_loop_m - ; set RX put pointer to first bloc + 1 - - mov dx, #io_ne2k_rx_put - mov al, #rx_first - inc al - out dx, al + // set RX put pointer to first bloc + 1 - ; return no error + mov $io_ne2k_rx_put,%dx + mov $rx_first,%al + inc %al + out %al,%dx - xor ax,ax + // return no error - pop dx - pop cx + xor %ax,%ax ret +//----------------------------------------------------------------------------- +// NE2K startup +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; NE2K startup -;------------------------------------------------------------------------------- - -_ne2k_start: - - push dx + .global ne2k_start - ; start the transceiver +ne2k_start: - mov dx, #io_ne2k_command - in al, dx - and al, #$FC - or al, #$02 - out dx, al + // start the transceiver - ; move out of internal loopback + mov $io_ne2k_command,%dx + in %dx,%al + and $0xFC,%al + or $0x02,%al + out %al,%dx - ; TODO: read PHY status to update the duplex mode ? + // move out of internal loopback + // TODO: read PHY status to update the duplex mode ? - mov dx, #io_ne2k_tx_conf - xor al, al - out dx, al + mov $io_ne2k_tx_conf,%dx + xor %al,%al + out %al,%dx - xor ax, ax - - pop dx + xor %ax,%ax ret +//----------------------------------------------------------------------------- +// NE2K stop +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; NE2K stop -;------------------------------------------------------------------------------- - -_ne2k_stop: + .global ne2k_stop - push ax - push dx +ne2k_stop: - ; Stop the DMA and the MAC + // Stop the DMA and the MAC - mov dx, #io_ne2k_command - in al, dx - and al, #$C0 - or al, #$21 - out dx, al + mov $io_ne2k_command,%dx + in %dx,%al + and $0xC0,%al + or $0x21,%al + out %al,%dx - ; select page 0 + // select page 0 - xor al, al + xor %al,%al call page_select - ; half-duplex and internal loopback - ; to insulate the MAC while stopped - ; and ensure TX finally ends + // half-duplex and internal loopback + // to insulate the MAC while stopped + // and ensure TX finally ends - mov dx, #io_ne2k_tx_conf - mov al, #2 - out dx, al + mov $io_ne2k_tx_conf,%dx + mov $2,%al + out %al,%dx - ; clear DMA length + // clear DMA length - xor al, al - mov dx, #io_ne2k_dma_len1 - out dx, al - inc dx ; = io_ne2k_dma_len2 - out dx, al + xor %al,%al + mov $io_ne2k_dma_len1,%dx + out %al,%dx + inc %dx // = io_ne2k_dma_len2 + out %al,%dx - ; TODO: wait for the chip to get stable + // TODO: wait for the chip to get stable - pop dx - pop ax ret +//----------------------------------------------------------------------------- +// NE2K termination +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -; NE2K termination -;------------------------------------------------------------------------------- - -; call ne2k_stop() before +// call ne2k_stop() before -_ne2k_term: + .global ne2k_term - push ax - push dx +ne2k_term: - ; select page 0 + // select page 0 - xor al, al + xor %al,%al call page_select - ; mask all interrrupts + // mask all interrrupts - mov dx, #io_ne2k_int_mask - xor al, al - out dx, al + mov $io_ne2k_int_mask,%dx + xor %al,%al + out %al,%dx - pop dx - pop ax ret +//----------------------------------------------------------------------------- +// NE2K probe +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; NE2K probe -;------------------------------------------------------------------------------ +// Read few registers at supposed I/O addresses +// and check their values for NE2K presence -; Read few registers at supposed I/O addresses -; and check their values for NE2K presence +// returns: -; returns: +// AX: 0=found 1=not found -; AX: 0=found 1=not found + .global ne2k_probe -_ne2k_probe: +ne2k_probe: - push dx + // query command register + // MAC & DMA should be stopped + // and no TX in progress - ; query command register - ; MAC & DMA should be stopped - ; and no TX in progress + // register not initialized in QEMU + // so do not rely on this one - ; register not initialized in QEMU - ; so do not rely on this one + //mov dx, #io_ne2k_command + //in al, dx + //and al, #$3F + //cmp al, #$21 + //jnz np_err - ;mov dx, #io_ne2k_command - ;in al, dx - ;and al, #$3F - ;cmp al, #$21 - ;jnz np_err - - xor ax, ax + xor %ax,%ax jmp np_exit np_err: - mov ax, #1 + mov $1,%ax np_exit: - pop dx ret +//----------------------------------------------------------------------------- +// NE2K reset +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; NE2K reset -;------------------------------------------------------------------------------ - -_ne2k_reset: + .global ne2k_reset - push ax - push dx +ne2k_reset: - ; reset device - ; with pulse on reset port + // reset device + // with pulse on reset port - mov dx, #io_ne2k_reset - in al, dx - out dx, al + mov $io_ne2k_reset,%dx + in %dx,%al + out %al,%dx - ; stop all and select page 0 + // stop all and select page 0 - mov dx, #io_ne2k_command - mov al, #$21 - out dx, al + mov $io_ne2k_command,%dx + mov $0x21,%al + out %al,%dx nr_loop: - ; wait for reset - ; without too much CPU + // wait for reset + // without too much CPU hlt - mov dx, #io_ne2k_int_stat - in al, dx - test al, #$80 + mov $io_ne2k_int_stat,%dx + in %dx,%al + test $0x80,%al jz nr_loop - pop dx - pop ax ret +//----------------------------------------------------------------------------- +// NE2K test +//----------------------------------------------------------------------------- -;------------------------------------------------------------------------------ -; NE2K test -;------------------------------------------------------------------------------ + .global ne2k_test -_ne2k_test: +ne2k_test: - push dx + // TODO: test sequence - ; TODO: test sequence - - mov ax, #1 - - pop dx + mov $1,%ax ret - -;------------------------------------------------------------------------------ - - EXPORT _ne2k_addr_set - - EXPORT _ne2k_rx_stat - EXPORT _ne2k_tx_stat - - EXPORT _ne2k_pack_get - EXPORT _ne2k_pack_put - - EXPORT _ne2k_int_stat - - EXPORT _ne2k_init - EXPORT _ne2k_term - - EXPORT _ne2k_start - EXPORT _ne2k_stop - - EXPORT _ne2k_probe - EXPORT _ne2k_reset - EXPORT _ne2k_test - - END - -;------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- diff --git a/elks/arch/i86/drivers/net/ne2k-main.c b/elks/arch/i86/drivers/net/ne2k-main.c index cc92443e0..6e66e5441 100644 --- a/elks/arch/i86/drivers/net/ne2k-main.c +++ b/elks/arch/i86/drivers/net/ne2k-main.c @@ -9,6 +9,7 @@ #include #include #include +#include // Shared declarations between low and high parts @@ -32,7 +33,7 @@ static byte_t send_buf [MAX_PACKET_ETH]; // Get packet static size_t ne2k_read (struct inode * inode, struct file * filp, - char * data, unsigned int len) + char * data, size_t len) { size_t res; @@ -191,7 +192,6 @@ static void ne2k_int (int irq, struct pt_regs * regs, void * dev_id) word_t stat; stat = ne2k_int_stat (); - if (stat & NE2K_STAT_RX) { wake_up (&rx_queue); diff --git a/elks/arch/i86/drivers/net/ne2k.h b/elks/arch/i86/drivers/net/ne2k.h index 7e36de8e8..98e64b8f9 100644 --- a/elks/arch/i86/drivers/net/ne2k.h +++ b/elks/arch/i86/drivers/net/ne2k.h @@ -42,5 +42,6 @@ extern word_t ne2k_tx_stat (); extern word_t ne2k_pack_get (byte_t * pack); extern word_t ne2k_pack_put (byte_t * pack, word_t len); +extern word_t ne2k_test (); #endif /* !NE2K_H */ diff --git a/elks/arch/i86/kernel/Makefile b/elks/arch/i86/kernel/Makefile index 50cc8b5fa..fbb75edfa 100644 --- a/elks/arch/i86/kernel/Makefile +++ b/elks/arch/i86/kernel/Makefile @@ -47,14 +47,17 @@ endif ######################################################################### # Commands. +irqtab.s: irqtab.S irqtab.o: irqtab.s +bios16.s: bios16.S bios16.o: bios16.s +printreg.s: printreg.S printreg.o: printreg.s +entry.s: entry.S entry.o: entry.s - as86 -0 -u -o entry.o entry.s all: akernel.a diff --git a/elks/arch/i86/kernel/bios16.S b/elks/arch/i86/kernel/bios16.S index 806531a6a..8bb65f419 100644 --- a/elks/arch/i86/kernel/bios16.S +++ b/elks/arch/i86/kernel/bios16.S @@ -11,84 +11,86 @@ * Quick drop into assembler for this one. */ + .code16 + .text - .globl _call_bios + .global call_bios -_call_bios: - push bp - mov bp,sp +call_bios: + push %bp + mov %sp,%bp -! Things we want to save - direction flag BP ES +// Things we want to save - direction flag BP ES pushf - push es - push si - push di + push %es + push %si + push %di -! DS also in SS +// DS also in SS - mov bx,4[bp] + mov 4(%bp),%bx -! Load the register block from the table +// Load the register block from the table - mov ax,2[bx] - mov cx,6[bx] - mov dx,8[bx] - mov si,10[bx] - mov di,12[bx] - mov bp,14[bx] - mov es,16[bx] - push 18[bx] ! DS in stack - push 20[bx] + mov 2(%bx),%ax + mov 6(%bx),%cx + mov 8(%bx),%dx + mov 10(%bx),%si + mov 12(%bx),%di + mov 14(%bx),%bp + mov 16(%bx),%es + push 18(%bx) // DS in stack + push 20(%bx) popf - mov bx, 4[bx] ! Load BX -! -! Stack now holds the call value for DS -! - pop ds ! DS desired + mov 4(%bx),%bx // Load BX +// +// Stack now holds the call value for DS +// + pop %ds // DS desired -! ***** DS is now wrong we cannot load from the array again ***** +// ***** DS is now wrong we cannot load from the array again ***** -! Do a disk interrupt. +// Do a disk interrupt. - int #0x13 + int $0x13 -! Now recover the results -! Make some breathing room +// Now recover the results +// Make some breathing room pushf - push ds - push bx + push %ds + push %bx -! Stack is now returned FL, DS, BX -! Recover our DS segment +// Stack is now returned FL, DS, BX +// Recover our DS segment - push ss - pop ds + push %ss + pop %ds -! ***** We can now use the bios data table again ***** +// ***** We can now use the bios data table again ***** - mov bx,sp - mov bx,18[bx] ! Load BX with table address + mov %sp,%bx + mov 18(%bx),%bx // Load BX with table address - mov 2[bx],ax ! Save the old AX - pop 4[bx] ! Save the old BX - mov 6[bx], cx - mov 8[bx], dx - mov 10[bx], si - mov 12[bx], di - mov 14[bx], bp - mov 16[bx], es - pop 18[bx] ! Save the old DS - pop 20[bx] ! Pop the returned flags off + mov %ax,2(%bx) // Save the old AX + pop 4(%bx) // Save the old BX + mov %cx,6(%bx) + mov %dx,8(%bx) + mov %si,10(%bx) + mov %di,12(%bx) + mov %bp,14(%bx) + mov %es,16(%bx) + pop 18(%bx) // Save the old DS + pop 20(%bx) // Pop the returned flags off -! Restore things we must save +// Restore things we must save - pop di - pop si - pop es + pop %di + pop %si + pop %es popf - pop bp - mov ax,20[bx] ! Return CARRY value - and ax,#1 + pop %bp + mov 20(%bx),%ax // Return CARRY value + and $1,%ax ret diff --git a/elks/arch/i86/kernel/irqtab.S b/elks/arch/i86/kernel/irqtab.S index f1559f56a..90a01b96e 100644 --- a/elks/arch/i86/kernel/irqtab.S +++ b/elks/arch/i86/kernel/irqtab.S @@ -1,6 +1,8 @@ #include #include + .code16 + .text /* @@ -10,7 +12,7 @@ * predefined contents is the kernel data segment */ - .even + .align 1 ds_kernel: #if defined(REL_SYS) .word REL_SYSSEG @@ -48,136 +50,136 @@ ds_kernel: #define MINT (1 | MCD | MRS | MHD | MFD | METH) - .globl _irqtab_init -_irqtab_init: + .global irqtab_init +irqtab_init: cli #if !defined(REL_SYS) && !defined(CONFIG_ROMCODE) - seg cs - mov ds_kernel,ss +// seg cs + mov %ss,%cs:ds_kernel #endif - xor ax,ax - mov ds,ax + xor %ax,%ax + mov %ax,%ds -! CS points to this kernel code segment -! DS points to page 0 (interrupt table) -! ES points to the kernel data segment +// CS points to this kernel code segment +// DS points to page 0 (interrupt table) +// ES points to the kernel data segment - mov [512],#_syscall_int ! syscall - mov [514],cs + movw $_syscall_int,512 // syscall + mov %cs,514 - mov bx,#32 - mov ax,[bx] ! get the old timer intr - seg es - mov _stashed_irq0_l,ax - mov ax,2[bx] - seg es - mov [_stashed_irq0_l+2],ax + mov $32,%bx + mov (%bx),%ax // get the old timer intr +// seg es + mov %ax,%es:_stashed_irq0_l + mov 2(%bx),%ax +// seg es + mov %ax,%es:_stashed_irq0_l+2 - mov cx,#MINT - mov ax,#_irq0 + mov $MINT,%cx + mov $_irq0,%ax init_tab1: - shr cx,#1 + shr $1,%cx jnc init_tab2 - mov [bx],ax - mov 2[bx],cs - add ax,#4 + mov %ax,(%bx) + mov %cs,2(%bx) + add $4,%ax init_tab2: - add bx,#4 - cmp bx,#64 + add $4,%bx + cmp $64,%bx jne init_tab3 - add bx,#384 ! IRQ 8-15 are mapped to vectors INT 70h-77h + add $384,%bx // IRQ 8-15 are mapped to vectors INT 70h-77h init_tab3: - or cx,cx + or %cx,%cx jnz init_tab1 -! -! Tidy up -! - push ss ! restore DS - pop ds +// +// Tidy up +// + push %ss // restore DS + pop %ds sti ret -! IRQ and IRQ return paths for Linux 8086 -! -! The execution thread will not return from the function call. -! Instead, the address pushed in the stack will be used to get -! the interrupt number. +// IRQ and IRQ return paths for Linux 8086 +// +// The execution thread will not return from the function call. +// Instead, the address pushed in the stack will be used to get +// the interrupt number. -_irq0: ! Timer +_irq0: // Timer call _irqit .byte 0 #ifdef CONFIG_CONSOLE_DIRECT -_irq1: ! Keyboard +_irq1: // Keyboard call _irqit .byte 1 #endif #if 0 -_irq2: ! Cascade +_irq2: // Cascade call _irqit .byte 2 #endif #ifdef CONFIG_CHAR_DEV_RS -_irq3: ! COM2 +_irq3: // COM2 call _irqit .byte 3 -_irq4: ! COM1 +_irq4: // COM1 call _irqit .byte 4 #endif #ifdef CONFIG_BLK_DEV_HD -_irq5: ! XT HD +_irq5: // XT HD call _irqit .byte 5 #endif #ifdef CONFIG_BLK_DEV_FD -_irq6: ! Floppy +_irq6: // Floppy call _irqit .byte 6 #endif #if 0 -_irq7: ! Lp1 +_irq7: // Lp1 call _irqit .byte 7 ! ! AT interrupts ! -_irq8: ! RTC +_irq8: // RTC call _irqit .byte 8 #endif #ifdef CONFIG_ETH_NE2K -_irq9: ! Ethernet device +_irq9: // Ethernet device call _irqit .byte 9 #endif #if 0 -_irq10: ! USB +_irq10: // USB call _irqit .byte 10 -_irq11: ! Sound +_irq11: // Sound call _irqit .byte 11 -_irq12: ! Mouse +_irq12: // Mouse call _irqit .byte 12 -_irq13: ! Math coproc. +_irq13: // Math coproc. call _irqit .byte 13 #endif #ifdef CONFIG_BLK_DEV_HD -_irq14: ! AT HD ide primary +_irq14: // AT HD ide primary call _irqit .byte 14 -_irq15: ! AT HD ide secondary +_irq15: // AT HD ide secondary call _irqit .byte 15 #endif -! -! Traps (we use IRQ 16->31 for these) -! -! Currently not used so removed for space. +// +// Traps (we use IRQ 16->31 for these) +// +// Currently not used so removed for space. #ifdef ENABLE_TRAPS _div0: call _irqit @@ -234,10 +236,11 @@ _algn: call _irqit .byte 33 #endif -_syscall_int: ! Syscall +_syscall_int: // Syscall call _irqit .byte 128 +/* ! ! On entry CS:IP is all we can trust ! @@ -261,12 +264,13 @@ _syscall_int: ! Syscall ! We do all of this to avoid per process interrupt stacks and ! related nonsense. This way we need only one dedicated int stack ! - .globl _ret_from_syscall - .extern _schedule - .extern _do_signal - .extern _do_IRQ - .extern _stack_check - .extern _syscall +*/ + .global ret_from_syscall + .extern schedule + .extern do_signal + .extern do_IRQ + .extern stack_check + .extern syscall #ifdef CHECK_SS .extern _panic #endif @@ -276,225 +280,229 @@ _syscall_int: ! Syscall #endif _irqit: -! -! Make room -! - push ds - push si -! -! Recover data segment -! - seg cs - mov ds,ds_kernel -! -! Determine which stack to use -! - cmp _gint_count,#1 - jc utask ! We were in user mode - jz itask ! Using a process's kernel stack -ktask: ! Already using interrupt stack -! -! Already using interrupt stack, keep using it -! - mov si,sp - sub si,#8 - j save_regs -! -! Using a process's kernel stack, switch to interrupt stack -! +// +// Make room +// + push %ds + push %si +// +// Recover data segment +// +// seg cs + mov %cs:ds_kernel,%ds +// +// Determine which stack to use +// + cmpw $1,_gint_count + jc utask // We were in user mode + jz itask // Using a process's kernel stack +ktask: // Already using interrupt stack +// +// Already using interrupt stack, keep using it +// + mov %sp,%si + sub $8,%si + jmp save_regs +// +// Using a process's kernel stack, switch to interrupt stack +// itask: - mov si,#(_intstack-12) - j save_regs -! -! User mode case -! + mov $_intstack-12,%si + jmp save_regs +// +// User mode case +// utask: - mov si,_current + mov current,%si #ifdef CHECK_SS -! -! We were in user mode, first confirm -! - cmp di,TASK_USER_SS[si] ! entry SS = current->t_regs.ss? - je utask1 ! User using the right stack -! -! System got crazy -! - mov ax,#pmsg - push ax +// +// We were in user mode, first confirm +// + cmp TASK_USER_SS(%si),%di // entry SS = current->t_regs.ss? + je utask1 // User using the right stack +// +// System got crazy +// + mov $pmsg,%ax + push %ax call _panic -! -! Switch to kernel stack -! +// +// Switch to kernel stack +// utask1: #endif - add si,#TASK_USER_DI -! -! Save segment, index, BP and SP registers -! + add $TASK_USER_DI,%si +// +// Save segment, index, BP and SP registers +// save_regs: - inc _gint_count - mov [si],di ! DI - pop 2[si] ! SI - pop 6[si] ! DS - pop di ! Pointer to interrupt number - push bp ! BP - mov 8[si],sp ! SP - mov 10[si],ss ! SS - mov 4[si],es ! ES -! -! Load new segment and SP registers -! - mov sp,si - mov si,ds - mov ss,si - mov es,si -! -! Save remaining registers -! - push dx ! DX - push cx ! CX - push bx ! BX - push ax ! AX -! -! cs:[di] has interrupt number -! - seg cs - movb al,[di] - cmpb al,#0x80 + incw _gint_count + mov %di,(%si) // DI + pop 2(%si) // SI + pop 6(%si) // DS + pop %di // Pointer to interrupt number + push %bp // BP + mov %sp,8(%si) // SP + mov %ss,10(%si) // SS + mov %es,4(%si) // ES +// +// Load new segment and SP registers +// + mov %si,%sp + mov %ds,%si + mov %si,%ss + mov %si,%es +// +// Save remaining registers +// + push %dx // DX + push %cx // CX + push %bx // BX + push %ax // AX +// +// cs:[di] has interrupt number +// +// seg cs + movb %cs:(%di),%al + cmpb $0x80,%al jne updct -! -! ----------PROCESS SYSCALL---------- -! +// +// ----------PROCESS SYSCALL---------- +// sti - call _stack_check ! Check USER stack - pop ax ! Get syscall function code + call stack_check // Check USER stack + pop %ax // Get syscall function code #ifdef CONFIG_STRACE -! -! strace(syscall#, params...) -! - push ax +// +// strace(syscall#, params...) +// + push %ax call _strace - pop ax + pop %ax #endif -! -! syscall(params...) -! - call _syscall - push ax ! syscall returns a value in ax +// +// syscall(params...) +// + call syscall + push %ax // syscall returns a value in ax #ifdef CONFIG_STRACE -! -! ret_strace(retval) -! +// +// ret_strace(retval) +// call _ret_strace #endif -! -! Restore registers -! - call _do_signal +// +// Restore registers +// + call do_signal cli - j restore_regs -! -! Done. -! -_ret_from_syscall: - mov bx,_current ! Ensure we have the - lea sp,TASK_USER_BX[bx] ! right kernel SP - xor ax,ax ! Just in case we are starting a new task - push ax + jmp restore_regs +// +// Done. +// +ret_from_syscall: + mov current,%bx // Ensure we have the + lea TASK_USER_BX(%bx),%sp // right kernel SP + xor %ax,%ax // Just in case we are starting a new task + push %ax cli - j restore_regs + jmp restore_regs +/* ! ! ----------PROCESS INTERRUPT---------- ! ! Update intr_count ! +*/ updct: - inc _intr_count -! -! Call the C code -! - sti ! Reenable interrupts - mov bx,sp ! Get pointer to pt_regs + incw intr_count +// +// Call the C code +// + sti // Reenable interrupts + mov %sp,%bx // Get pointer to pt_regs cbw - push ax ! IRQ for later - - push bx ! Register base - push ax ! IRQ number - call _do_IRQ ! Do the work - pop ax ! Clean parameters - pop bx - - pop ax ! Saved IRQ -! -! Send EOI to interrupt controller -! - cli ! Disable interrupts to avoid reentering ISR - cmp ax,#16 - jge was_trap ! Traps need no reset - or ax,ax ! Is int #0? + push %ax // IRQ for later + + push %bx // Register base + push %ax // IRQ number + call do_IRQ // Do the work + pop %ax // Clean parameters + pop %bx + + pop %ax // Saved IRQ +// +// Send EOI to interrupt controller +// + cli // Disable interrupts to avoid reentering ISR + cmp $16,%ax + jge was_trap // Traps need no reset + or %ax,%ax // Is int #0? jnz a4 -! -! IRQ 0 (timer) has to go on to the bios for some systems -! - dec _bios_call_cnt_l ! Will call bios int? +// +// IRQ 0 (timer) has to go on to the bios for some systems +// + decw _bios_call_cnt_l // Will call bios int? jne a4 - mov _bios_call_cnt_l,#5 + movw $5,_bios_call_cnt_l pushf - callf [_stashed_irq0_l] - jmp was_trap ! EOI already sent by bios int + lcall *_stashed_irq0_l + jmp was_trap // EOI already sent by bios int a4: - cmp ax,#8 - movb al,#0x20 ! EOI - jb a6 ! IRQ on low chip + cmp $8,%ax + mov $0x20,%al // EOI + jb a6 // IRQ on low chip +/* ! ! Reset secondary 8259 if we have taken an AT rather ! than XT irq. We also have to prod the primay ! controller EOI.. ! - outb 0xA0,al +*/ + out %al,$0xA0 jmp a5 a5: jmp a6 -a6: outb 0x20,al ! Ack on primary controller -! -! And a trap does no hardware work -! +a6: out %al,$0x20 // Ack on primary controller +// +// And a trap does no hardware work +// was_trap: -! -! Restore intr_count -! - dec _intr_count -! -! Now look at rescheduling -! - cmp _gint_count,#1 - jne restore_regs ! No -! cmp _need_resched,#0 ! Schedule needed ? -! je restore_regs ! No -! -! This path will return directly to user space -! - call _schedule ! Task switch - call _do_signal ! Check signals -! -! Restore registers and return -! +// +// Restore intr_count +// + decw intr_count +// +// Now look at rescheduling +// + cmpw $1,_gint_count + jne restore_regs // No +// cmp $0,_need_resched // Schedule needed ? +// je restore_regs // No +// +// This path will return directly to user space +// + call schedule // Task switch + call do_signal // Check signals +// +// Restore registers and return +// restore_regs: - dec _gint_count - pop ax - pop bx - pop cx - pop dx - pop di - pop si - pop es - pop ds - pop bp - pop ss - mov sp,bp - pop bp -! -! Iret restores CS:IP and F (thus including the interrupt bit) -! + decw _gint_count + pop %ax + pop %bx + pop %cx + pop %dx + pop %di + pop %si + pop %es + pop %ds + pop %bp + pop %ss + mov %bp,%sp + pop %bp +// +// Iret restores CS:IP and F (thus including the interrupt bit) +// iret /* @@ -509,34 +517,34 @@ restore_regs: * context and returns running the current task. */ - .globl _tswitch + .global tswitch -_tswitch: - push bp ! schedule()'s bp +tswitch: + push %bp // schedule()'s bp #ifdef USE_IA16 - push es + push %es #endif - push di - push si - mov bx,_previous - mov TASK_KRNL_SP[bx],sp - mov bx,_current - mov sp,TASK_KRNL_SP[bx] - pop si - pop di + push %di + push %si + mov previous,%bx + mov %sp,TASK_KRNL_SP(%bx) + mov current,%bx + mov TASK_KRNL_SP(%bx),%sp + pop %si + pop %di #ifdef USE_IA16 - pop es + pop %es #endif - pop bp ! BP of schedule() + pop %bp // BP of schedule() ret -; Halt on idle helper -; Wait for next interrupt to save CPU power +//; Halt on idle helper +//; Wait for next interrupt to save CPU power #ifdef CONFIG_IDLE_HALT - .define _idle_halt + .global _idle_halt _idle_halt: hlt @@ -546,26 +554,25 @@ _idle_halt: .data - .globl _intr_count - .extern _current - .extern _previous + .global intr_count + .extern current + .extern previous .extern _kernel_ds - .even + .align 1 _bios_call_cnt_l: .word 5 _stashed_irq0_l: .long 0 -_intr_count: ! Hardware interrupts count +intr_count: // Hardware interrupts count .word 0 -_gint_count: ! General interrupts count. Start with 1 - .word 1 ! because init_task() is in kernel mode +_gint_count: // General interrupts count. Start with 1 + .word 1 // because init_task() is in kernel mode #ifdef CHECK_SS pmsg: .ascii "Running unknown code" - db 0 + .byte 0 #endif - - .zerow 256 ! (was) 128 byte interrupt stack + .skip 512,0 // (was) 128 byte interrupt stack _intstack: diff --git a/elks/arch/i86/kernel/mkentry.sh b/elks/arch/i86/kernel/mkentry.sh index 2859132b0..bfb8dca08 100755 --- a/elks/arch/i86/kernel/mkentry.sh +++ b/elks/arch/i86/kernel/mkentry.sh @@ -2,14 +2,15 @@ # # This program generates entry.c from syscall.dat -cat << .eof +cat <<'.eof' #include /* Switched to V7 system call layout... Chad - 1/5/96 */ #ifndef S_SPLINT_S -#asm -! The call table - autogenerated from syscall.dat +// The call table - autogenerated from syscall.dat + + .code16 .data sys_call_table: @@ -34,8 +35,8 @@ awk '/^#/{next;} if ( maxno < callno ) maxno = callno; - str = "\t.word _sys_" $1; - line[callno] = sprintf("%-25s ! %3d", str, callno); + str = "\t.word sys_" $1; + line[callno] = sprintf("%-25s // %3d", str, callno); } END{ for (maxstd=maxno; depends_on[maxstd]!=""; maxstd--) @@ -65,7 +66,7 @@ END{ # } # else str = "\t.word _no_syscall"; - printf "%-25s ! %3d - %s\n", str, callno, assigned_to[callno]; + printf "%-25s // %3d - %s\n", str, callno, assigned_to[callno]; } if ( depends_on[callno] != "" ) @@ -73,7 +74,7 @@ END{ if ( callno < maxno ) { str = "\t.word _no_syscall"; - printf "#else\n%-25s ! %3d - %s\n", str, callno, assigned_to[callno] + printf "#else\n%-25s // %3d - %s\n", str, callno, assigned_to[callno] } printf "#endif\n" @@ -82,31 +83,32 @@ END{ } ' -cat <<.eof +cat <<'.eof' sys_call_table_end: -! Despatch a syscall (called from syscall_int) -! Entry: ax=function code, stack contains parameters +.set sys_call_len, (sys_call_table_end - sys_call_table)/2 + +// Dispatch a syscall (called from syscall_int) +// Entry: ax=function code, stack contains parameters .text - .globl _syscall - .globl _no_syscall + .global syscall + .global _no_syscall -_syscall: - cmp ax,#((sys_call_table_end - sys_call_table)/2) +syscall: + cmp $sys_call_len,%ax ja _no_syscall - ! look up address and jump to function - mov bx,ax - add bx,ax ! multiply by 2 - j sys_call_table[bx] + // look up address and jump to function + mov %ax,%bx + add %ax,%bx // multiply by 2 + jmp *sys_call_table(%bx) -! All unimplemented calls +// All unimplemented calls _no_syscall: - mov ax,#-38 + mov $-38,%ax ret -#endasm #endif .eof diff --git a/elks/arch/i86/kernel/printreg.S b/elks/arch/i86/kernel/printreg.S index ba33fe591..870afe7be 100644 --- a/elks/arch/i86/kernel/printreg.S +++ b/elks/arch/i86/kernel/printreg.S @@ -9,52 +9,56 @@ /*void printsp(void);*/ #ifndef S_SPLINT_S -#asm + +.code16 + +.text + .extern _printk - .globl _print_regs + .global _print_regs _print_regs: - push bp - push ss - push es - push ds - push cs - push si - push di - push dx - push cx - push bx - push ax - mov ax,#fmtprg - push ax + push %bp + push %ss + push %es + push %ds + push %cs + push %si + push %di + push %dx + push %cx + push %bx + push %ax + mov $fmtprg,%ax + push %ax call _printk - pop ax - pop ax - pop bx - pop cx - pop dx - pop di - pop si - pop ds ! Can not pop cs. - pop ds - pop es - pop ss - pop bp + pop %ax + pop %ax + pop %bx + pop %cx + pop %dx + pop %di + pop %si + pop %ds // Can not pop cs. + pop %ds + pop %es + pop %ss + pop %bp ret - .globl _printsp + .global _printsp _printsp: - mov ax,sp - add ax,#2 - push ax - push ss - mov ax,#msg - push ax + mov %sp,%ax + add $2,%ax + push %ax + push %ss + mov $msg,%ax + push %ax call _printk - pop ax - pop ax - pop ax + pop %ax + pop %ax + pop %ax ret .data @@ -63,5 +67,4 @@ msg: .ascii "SP=%x:%x\n" fmtprg: .ascii "AX=%x BX=%x CX=%x DX=%x DI=%x SI=%x\nCS=%x DS=%x ES=%x SS=%x BP=%x\n" .byte 0 -#endasm #endif diff --git a/elks/arch/i86/kernel/system.c b/elks/arch/i86/kernel/system.c index 8e2e3802f..4418cff08 100644 --- a/elks/arch/i86/kernel/system.c +++ b/elks/arch/i86/kernel/system.c @@ -7,7 +7,9 @@ #include -int arch_cpu; /* Processor type */ + +byte_t arch_cpu; // processor number (from setup data) + #ifdef CONFIG_ARCH_SIBO extern long int basmem; #endif @@ -70,10 +72,10 @@ void hard_reset_now(void) ); #endif #ifdef __ia16__ - asm("movw $64,%ax\n\t" - "movw %ax,%ds\n\t" - "movw $4660,114\n\t" - "jmp 65535:0\n\t" + asm("mov $0x40,%ax\n\t" + "mov %ax,%ds\n\t" + "movw $0x1234,0x72\n\t" + "ljmp $0xFFFF,$0\n\t" ); #endif } diff --git a/elks/arch/i86/lib/Makefile b/elks/arch/i86/lib/Makefile index 305814f49..5334dd77c 100644 --- a/elks/arch/i86/lib/Makefile +++ b/elks/arch/i86/lib/Makefile @@ -31,66 +31,47 @@ include $(BASEDIR)/Makefile-rules # Precompiled assembly -SRCS1= \ +SRCS1 = \ fmemcpyb.S fmemcpyw.S \ fmemcmpb.S fmemcmpw.S \ setupb.S setupw.S \ string.S \ - farlist.S seglist.S \ + seglist.S \ +# farlist.S \ # end of list -fmemcpyb.s:fmemcpyb.S -fmemcpyw.s:fmemcpyw.S -fmemcmpb.s:fmemcmpb.S -fmemcmpw.s:fmemcmpw.S -setupb.s:setupb.S -setupw.s:setupw.S -string.s:string.S -farlist.s:farlist.S -seglist.s:seglist.S +TMPS1 = $(SRCS1:.S=.s) -OBJS1=$(SRCS1:.S=.o) +OBJS1 = $(TMPS1:.s=.o) # Non-precompiled assembly -SRCS2= \ +SRCS2 = \ peekb.s peekw.s pokeb.s pokew.s \ fmemsetb.s fmemsetw.s \ border.s \ ldivmod.s \ + divmodsi3.s \ # end of list -OBJS2=$(SRCS2:.s=.o) +OBJS2 = $(SRCS2:.s=.o) # C sources -SRCS3= \ +SRCS3 = \ bitops.c \ # end of list -OBJS3=$(SRCS3:.c=.o) +OBJS3 = $(SRCS3:.c=.o) -ifeq ($(USEIA16), y) -OBJS = $(OBJS1) $(OBJS2) $(OBJS3) divmodsi3.o -else -OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(IOBJS) $(JOBJS) $(LLOBJS) -endif - -# compiler support for integer arithmetic - -IOBJS =idiv.o idivu.o imod.o imodu.o imul.o isl.o isr.o isru.o min.o ctypefn.o +OBJS = $(OBJS1) $(OBJS2) $(OBJS3) +#OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(JOBJS) # miscellaneous +# TODO: move them to the C library JOBJS = inport.o inportb.o outport.o outportb.o irqflag.o \ memcmp.o -# ntohl.o ntohs.o - -# compiler support for long arithmetic on little-endian (normal) longs - -LLOBJS =laddl.o landl.o lcmpl.o lcoml.o ldecl.o ldivl.o ldivul.o \ - leorl.o lincl.o lmodl.o lmodul.o lmull.o lnegl.o lorl.o \ - lsll.o lsrl.o lsrul.o lsubl.o ltstl.o ######################################################################### # Commands. @@ -98,7 +79,12 @@ LLOBJS =laddl.o landl.o lcmpl.o lcoml.o ldecl.o ldivl.o ldivul.o \ all: lib86.a lib86.a: $(OBJS) - ar rcs lib86.a $(OBJS) + $(AR) rcs lib86.a $(OBJS) + +$(TMPS1): $(SRCS1) +$(OBJS1): $(TMPS1) +$(OBJS2): $(SRCS2) +$(OBJS3): $(SRCS3) ######################################################################### # Standard commands. diff --git a/elks/arch/i86/lib/border.s b/elks/arch/i86/lib/border.s index 45d0aa6b2..a5afcd2ee 100644 --- a/elks/arch/i86/lib/border.s +++ b/elks/arch/i86/lib/border.s @@ -1,17 +1,18 @@ -! border.s +// border.s - .globl _ntohl - .globl _htonl - .text - .even + .code16 -_htonl: -_ntohl: - pop bx - pop dx - pop ax - sub sp,#4 - xchg ah,al - xchg dh,dl - jmp bx + .global ntohl + .global htonl + .text + .align 1 +htonl: +ntohl: + pop %bx + pop %dx + pop %ax + sub $4,%sp + xchg %al,%ah + xchg %dl,%dh + jmp *%bx diff --git a/elks/arch/i86/lib/ctypefn.s b/elks/arch/i86/lib/ctypefn.s deleted file mode 100644 index 3fc1d6c41..000000000 --- a/elks/arch/i86/lib/ctypefn.s +++ /dev/null @@ -1,29 +0,0 @@ - .text - .even -! char toupper(char c) { return(islower(c) ? (c ^ 0x20) : (c)); } - .globl _toupper -_toupper: - pop bx - pop ax ! c - cmpb al, #'a - jc .0 - cmpb al, #'z - ja .0 - j .1 - -! char tolower(char c) { return(isupper(c) ? (c ^ 0x20) : (c)); } - .globl _tolower -_tolower: - pop bx - pop ax ! c - cmpb al, #'A - jc .0 - cmpb al, #'Z - ja .0 -.1: - xor al,*$20 -.0: - xor ah, ah - dec sp - dec sp - jmp bx diff --git a/elks/arch/i86/lib/divmodsi3.s b/elks/arch/i86/lib/divmodsi3.s index 81918a356..95fb3fb99 100644 --- a/elks/arch/i86/lib/divmodsi3.s +++ b/elks/arch/i86/lib/divmodsi3.s @@ -1,90 +1,92 @@ + .code16 + .text .extern ldivmod .extern ludivmod - .globl ___divsi3 - .even + .global __divsi3 + .align 1 -___divsi3: - push bp - mov bp,sp - push bx - push cx - push di - mov ax,4[bp] - mov bx,6[bp] - mov cx,8[bp] - mov di,10[bp] +__divsi3: + push %bp + mov %sp,%bp + push %bx + push %cx + push %di + mov 4(%bp),%ax + mov 6(%bp),%bx + mov 8(%bp),%cx + mov 10(%bp),%di call ldivmod - mov dx,di - mov ax,cx - pop di - pop cx - pop bx - pop bp + mov %di,%dx + mov %cx,%ax + pop %di + pop %cx + pop %bx + pop %bp ret - .globl ___modsi3 - .even + .global __modsi3 + .align 1 -___modsi3: - push bp - mov bp,sp - push bx - push cx - push di - mov ax,4[bp] - mov bx,6[bp] - mov cx,8[bp] - mov di,10[bp] +__modsi3: + push %bp + mov %sp,%bp + push %bx + push %cx + push %di + mov 4(%bp),%ax + mov 6(%bp),%bx + mov 8(%bp),%cx + mov 10(%bp),%di call ldivmod - mov dx,bx - pop di - pop cx - pop bx - pop bp + mov %bx,%dx + pop %di + pop %cx + pop %bx + pop %bp ret - .globl ___udivsi3 - .even + .global __udivsi3 + .align 1 -___udivsi3: - push bp - mov bp,sp - push bx - push cx - push di - mov ax,4[bp] - mov bx,6[bp] - mov cx,8[bp] - mov di,10[bp] +__udivsi3: + push %bp + mov %sp,%bp + push %bx + push %cx + push %di + mov 4(%bp),%ax + mov 6(%bp),%bx + mov 8(%bp),%cx + mov 10(%bp),%di call ludivmod - mov dx,di - mov ax,cx - pop di - pop cx - pop bx - pop bp + mov %di,%dx + mov %cx,%ax + pop %di + pop %cx + pop %bx + pop %bp ret - .globl ___umodsi3 - .even + .global __umodsi3 + .align 1 -___umodsi3: - push bp - mov bp,sp - push bx - push cx - push di - mov ax,4[bp] - mov bx,6[bp] - mov cx,8[bp] - mov di,10[bp] +__umodsi3: + push %bp + mov %sp,%bp + push %bx + push %cx + push %di + mov 4(%bp),%ax + mov 6(%bp),%bx + mov 8(%bp),%cx + mov 10(%bp),%di call ludivmod - mov dx,bx - pop di - pop cx - pop bx - pop bp + mov %bx,%dx + pop %di + pop %cx + pop %bx + pop %bp ret diff --git a/elks/arch/i86/lib/fmemcmpb.S b/elks/arch/i86/lib/fmemcmpb.S index dbee2f5f5..f34fce0f8 100644 --- a/elks/arch/i86/lib/fmemcmpb.S +++ b/elks/arch/i86/lib/fmemcmpb.S @@ -1,39 +1,35 @@ -; int fmemcmpb (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) -; segment after offset to allow LDS & LES from the stack -; assume DS=ES=SS (not ES for GCC-IA16) +// int fmemcmpb (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) +// segment after offset to allow LDS & LES from the stack +// assume DS=SS (not ES for GCC-IA16) + + .code16 .text - .define _fmemcmpb + .global fmemcmpb -_fmemcmpb: -#ifdef USE_IA16 - mov bx,es -#endif - mov ax,si - mov dx,di - mov si,sp - mov cx,[si+10] ; arg4: byte count - les di,[si+2] ; arg0+1: far destination pointer - lds si,[si+6] ; arg2+3: far source pointer +fmemcmpb: + mov %es,%bx + mov %si,%ax + mov %di,%dx + mov %sp,%si + mov 10(%si),%cx // arg4: byte count + les 2(%si),%di // arg0+1: far destination pointer + lds 6(%si),%si // arg2+3: far source pointer cld repz cmpsb - mov si,ax - mov di,dx + mov %ax,%si + mov %dx,%di jz fmemcmpb_same - mov ax,#1 + mov $1,%ax jmp fmemcmpb_exit fmemcmpb_same: - xor ax,ax + xor %ax,%ax fmemcmpb_exit: - mov dx,ss - mov ds,dx -#ifdef USE_IA16 - mov es,bx -#else - mov es,dx -#endif + mov %ss,%dx + mov %dx,%ds + mov %bx,%es ret diff --git a/elks/arch/i86/lib/fmemcmpw.S b/elks/arch/i86/lib/fmemcmpw.S index bc5ed2d06..fe066c222 100644 --- a/elks/arch/i86/lib/fmemcmpw.S +++ b/elks/arch/i86/lib/fmemcmpw.S @@ -1,39 +1,41 @@ -; int fmemcmpw (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) -; segment after offset to allow LDS & LES from the stack -; assume DS=ES=SS (not ES for GCC-IA16) +// int fmemcmpw (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) +// segment after offset to allow LDS & LES from the stack +// assume DS=ES=SS (not ES for GCC-IA16) + + .code16 .text - .define _fmemcmpw + .global fmemcmpw -_fmemcmpw: +fmemcmpw: #ifdef USE_IA16 - mov bx,es + mov %es,%bx #endif - mov ax,si - mov dx,di - mov si,sp - mov cx,[si+10] ; arg4: byte count - les di,[si+2] ; arg0+1: far destination pointer - lds si,[si+6] ; arg2+3: far source pointer + mov %si,%ax + mov %di,%dx + mov %sp,%si + mov 10(%si),%cx //; arg4: byte count + les 2(%si),%di //; arg0+1: far destination pointer + lds 6(%si),%si //; arg2+3: far source pointer cld repz cmpsw - mov si,ax - mov di,dx + mov %ax,%si + mov %dx,%di jz fmemcmpw_same - mov ax,#1 + mov $1,%ax jmp fmemcmpw_exit fmemcmpw_same: - xor ax,ax + xor %ax,%ax fmemcmpw_exit: - mov dx,ss - mov ds,dx + mov %ss,%dx + mov %dx,%ds #ifdef USE_IA16 - mov es,bx + mov %bx,%es #else - mov es,dx + mov %dx,%es #endif ret diff --git a/elks/arch/i86/lib/fmemcpyb.S b/elks/arch/i86/lib/fmemcpyb.S index ac422891d..3057d42a9 100644 --- a/elks/arch/i86/lib/fmemcpyb.S +++ b/elks/arch/i86/lib/fmemcpyb.S @@ -1,31 +1,33 @@ -; void fmemcpyb (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) -; segment after offset to allow LDS & LES from the stack -; assume DS=ES=SS (not ES for GCC-IA16) +// void fmemcpyb (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) +// segment after offset to allow LDS & LES from the stack +// assume DS=ES=SS (not ES for GCC-IA16) + + .code16 .text - .define _fmemcpyb + .global fmemcpyb -_fmemcpyb: +fmemcpyb: #ifdef USE_IA16 - mov bx,es + mov %es,%bx #endif - mov ax,si - mov dx,di - mov si,sp - mov cx,[si+10] ; arg4: word count - les di,[si+2] ; arg0+1: far destination pointer - lds si,[si+6] ; arg2+3: far source pointer + mov %si,%ax + mov %di,%dx + mov %sp,%si + mov 10(%si),%cx // arg4: word count + les 2(%si),%di // arg0+1: far destination pointer + lds 6(%si),%si // arg2+3: far source pointer cld rep movsb - mov si,ax - mov di,dx - mov ax,ss - mov ds,ax + mov %ax,%si + mov %dx,%di + mov %ss,%ax + mov %ax,%ds #ifdef USE_IA16 - mov es,bx + mov %bx,%es #else - mov es,ax + mov %ax,%es #endif ret diff --git a/elks/arch/i86/lib/fmemcpyw.S b/elks/arch/i86/lib/fmemcpyw.S index f660e0922..879054750 100644 --- a/elks/arch/i86/lib/fmemcpyw.S +++ b/elks/arch/i86/lib/fmemcpyw.S @@ -1,32 +1,33 @@ -; void fmemcpyw (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) -; segment after offset to allow LDS & LES from the stack -; assume DS=ES=SS (not ES for GCC-IA16) +// void fmemcpyw (word_t dst_off, seg_t dst_seg, word_t src_off, seg_t src_seg, word_t count) +// segment after offset to allow LDS & LES from the stack +// assume DS=ES=SS (not ES for GCC-IA16) + + .code16 .text - .define _fmemcpyw + .global fmemcpyw -_fmemcpyw: +fmemcpyw: #ifdef USE_IA16 - mov bx,es + mov %es,%bx #endif - mov ax,si - mov dx,di - mov si,sp - mov cx,[si+10] ; arg4: word count - les di,[si+2] ; arg0+1: far destination pointer - lds si,[si+6] ; arg2+3: far source pointer + mov %si,%ax + mov %di,%dx + mov %sp,%si + mov 10(%si),%cx //; arg4: word count + les 2(%si),%di //; arg0+1: far destination pointer + lds 6(%si),%si //; arg2+3: far source pointer cld rep movsw - mov si,ax - mov di,dx - mov ax,ss - mov ds,ax + mov %ax,%si + mov %dx,%di + mov %ss,%ax + mov %ax,%ds #ifdef USE_IA16 - mov es,bx + mov %bx,%es #else - mov es,ax + mov %ax,%es #endif ret - diff --git a/elks/arch/i86/lib/fmemsetb.s b/elks/arch/i86/lib/fmemsetb.s index 9680f488e..af7125017 100644 --- a/elks/arch/i86/lib/fmemsetb.s +++ b/elks/arch/i86/lib/fmemsetb.s @@ -1,21 +1,23 @@ -; void fmemsetb (word_t off, seg_t seg, byte_t val, word_t count) -; segment after offset to allow LES from the stack -; compiler pushes byte_t as word_t +// void fmemsetb (word_t off, seg_t seg, byte_t val, word_t count) +// segment after offset to allow LES from the stack +// compiler pushes byte_t as word_t + + .code16 .text - .define _fmemsetb + .global fmemsetb -_fmemsetb: - mov bx,es - mov dx,di - mov di,sp - mov ax,[di+6] ; arg2: value - mov cx,[di+8] ; arg3: byte count - les di,[di+2] ; arg0+1: far pointer +fmemsetb: + mov %es,%bx + mov %di,%dx + mov %sp,%di + mov 6(%di),%ax // arg2: value + mov 8(%di),%cx // arg3: byte count + les 2(%di),%di // arg0+1: far pointer cld rep stosb - mov di,dx - mov es,bx + mov %dx,%di + mov %bx,%es ret diff --git a/elks/arch/i86/lib/fmemsetw.s b/elks/arch/i86/lib/fmemsetw.s index bd4f6c234..fe684c794 100644 --- a/elks/arch/i86/lib/fmemsetw.s +++ b/elks/arch/i86/lib/fmemsetw.s @@ -1,20 +1,22 @@ -; void fmemsetw (word_t off, seg_t seg, word_t val, word_t count) -; segment after offset to allow LES from the stack +// void fmemsetw (word_t off, seg_t seg, word_t val, word_t count) +// segment after offset to allow LES from the stack + + .code16 .text - .define _fmemsetw + .global fmemsetw -_fmemsetw: - mov bx,es - mov dx,di - mov di,sp - mov ax,[di+6] ; arg2: value - mov cx,[di+8] ; arg3: byte count - les di,[di+2] ; arg0+1: far pointer +fmemsetw: + mov %es,%bx + mov %di,%dx + mov %sp,%di + mov 6(%di),%ax // arg2: value + mov 8(%di),%cx // arg3: byte count + les 2(%di),%di // arg0+1: far pointer cld rep stosw - mov di,dx - mov es,bx + mov %dx,%di + mov %bx,%es ret diff --git a/elks/arch/i86/lib/idiv.s b/elks/arch/i86/lib/idiv.s deleted file mode 100644 index 1bb878723..000000000 --- a/elks/arch/i86/lib/idiv.s +++ /dev/null @@ -1,11 +0,0 @@ -! idiv.s -! idiv_ doesn't preserve dx (returns remainder in it) - - .globl idiv_ - .text - .even - -idiv_: - cwd - idiv bx - ret diff --git a/elks/arch/i86/lib/idivu.s b/elks/arch/i86/lib/idivu.s deleted file mode 100644 index cb45badb2..000000000 --- a/elks/arch/i86/lib/idivu.s +++ /dev/null @@ -1,11 +0,0 @@ -! idivu.s -! idiv_u doesn't preserve dx (returns remainder in it) - - .globl idiv_u - .text - .even - -idiv_u: - xor dx,dx - div bx - ret diff --git a/elks/arch/i86/lib/imod.s b/elks/arch/i86/lib/imod.s deleted file mode 100644 index 6b399ba53..000000000 --- a/elks/arch/i86/lib/imod.s +++ /dev/null @@ -1,12 +0,0 @@ -! imod.s -! imod doesn't preserve dx (returns quotient in it) - - .globl imod - .text - .even - -imod: - cwd - idiv bx ! Instruction queue full so xchg slower - mov ax,dx - ret diff --git a/elks/arch/i86/lib/imodu.s b/elks/arch/i86/lib/imodu.s deleted file mode 100644 index 127edce1f..000000000 --- a/elks/arch/i86/lib/imodu.s +++ /dev/null @@ -1,12 +0,0 @@ -! imodu.s -! imodu doesn't preserve dx (returns quotient in it) - - .globl imodu - .text - .even - -imodu: - xor dx,dx - div bx - mov ax,dx ! instruction queue full so xchg slower - ret diff --git a/elks/arch/i86/lib/imul.s b/elks/arch/i86/lib/imul.s deleted file mode 100644 index 7b5be69b9..000000000 --- a/elks/arch/i86/lib/imul.s +++ /dev/null @@ -1,13 +0,0 @@ -! imul.s -! imul_, imul_u don't preserve dx - - .globl imul_ - .globl imul_u - .text - .even - -imul_: - -imul_u: - imul bx - ret diff --git a/elks/arch/i86/lib/isl.s b/elks/arch/i86/lib/isl.s deleted file mode 100644 index 3acb09d2e..000000000 --- a/elks/arch/i86/lib/isl.s +++ /dev/null @@ -1,14 +0,0 @@ -! isl.s -! isl, islu don't preserve cl - - .globl isl - .globl islu - .text - .even - -isl: - -islu: - mov cl,bl - shl ax,cl - ret diff --git a/elks/arch/i86/lib/isr.s b/elks/arch/i86/lib/isr.s deleted file mode 100644 index b38511029..000000000 --- a/elks/arch/i86/lib/isr.s +++ /dev/null @@ -1,11 +0,0 @@ -! isr.s -! isr doesn't preserve cl - - .globl isr - .text - .even - -isr: - mov cl,bl - sar ax,cl - ret diff --git a/elks/arch/i86/lib/isru.s b/elks/arch/i86/lib/isru.s deleted file mode 100644 index d0281b99b..000000000 --- a/elks/arch/i86/lib/isru.s +++ /dev/null @@ -1,11 +0,0 @@ -! isru.s -! isru doesn't preserve cl - - .globl isru - .text - .even - -isru: - mov cl,bl - shr ax,cl - ret diff --git a/elks/arch/i86/lib/laddl.s b/elks/arch/i86/lib/laddl.s deleted file mode 100644 index aa8b35924..000000000 --- a/elks/arch/i86/lib/laddl.s +++ /dev/null @@ -1,13 +0,0 @@ -! laddl.s - - .globl laddl - .globl laddul - .text - .even - -laddl: - -laddul: - add ax,[di] - adc bx,2[di] - ret diff --git a/elks/arch/i86/lib/landl.s b/elks/arch/i86/lib/landl.s deleted file mode 100644 index 906f33269..000000000 --- a/elks/arch/i86/lib/landl.s +++ /dev/null @@ -1,13 +0,0 @@ -! landl.s - - .globl landl - .globl landul - .text - .even - -landl: - -landul: - and ax,[di] - and bx,2[di] - ret diff --git a/elks/arch/i86/lib/lcmpl.s b/elks/arch/i86/lib/lcmpl.s deleted file mode 100644 index 58381df91..000000000 --- a/elks/arch/i86/lib/lcmpl.s +++ /dev/null @@ -1,27 +0,0 @@ -! lcmpl.s -! lcmpl, lcmpul don't preserve bx - - .globl lcmpl - .globl lcmpul - .text - .even - -lcmpl: - -lcmpul: - sub bx,2[di] ! don't need to preserve bx - jne LCMP_EXIT - cmp ax,[di] - jb LCMP_B_AND_LT ! b (below) becomes lt (less than) as well - jge LCMP_EXIT ! ge and already ae - ! else make gt as well as a (above) - inc bx ! clear ov and mi, set ne for greater than - -LCMP_EXIT: - ret - - .even - -LCMP_B_AND_LT: - dec bx ! clear ov, set mi and ne for less than - ret diff --git a/elks/arch/i86/lib/lcoml.s b/elks/arch/i86/lib/lcoml.s deleted file mode 100644 index f606469fa..000000000 --- a/elks/arch/i86/lib/lcoml.s +++ /dev/null @@ -1,13 +0,0 @@ -! lcoml.s - - .globl lcoml - .globl lcomul - .text - .even - -lcoml: - -lcomul: - not ax - not bx - ret diff --git a/elks/arch/i86/lib/ldecl.s b/elks/arch/i86/lib/ldecl.s deleted file mode 100644 index d80c8b611..000000000 --- a/elks/arch/i86/lib/ldecl.s +++ /dev/null @@ -1,13 +0,0 @@ -! ldecl.s - - .globl ldecl - .globl ldecul - .text - .even - -ldecl: - -ldecul: - sub word ptr [bx],#1 - sbb word ptr 2[bx],#0 - ret diff --git a/elks/arch/i86/lib/ldivl.s b/elks/arch/i86/lib/ldivl.s deleted file mode 100644 index ba0ba36af..000000000 --- a/elks/arch/i86/lib/ldivl.s +++ /dev/null @@ -1,16 +0,0 @@ -! ldivl.s -! bx:ax / 2(di):(di), quotient bx:ax, remainder di:cx, dx not preserved - - .globl ldivl - .extern ldivmod - .text - .even - -ldivl: - mov cx,[di] - mov di,2[di] - call ldivmod ! bx:ax / di:cx, quot di:cx, rem bx:ax - xchg ax,cx - xchg bx,di - ret - diff --git a/elks/arch/i86/lib/ldivmod.s b/elks/arch/i86/lib/ldivmod.s index dbea17355..6ce386cd7 100644 --- a/elks/arch/i86/lib/ldivmod.s +++ b/elks/arch/i86/lib/ldivmod.s @@ -1,3 +1,4 @@ +/* ! ldivmod.s - 32 over 32 to 32 bit division and remainder for 8086 ! ldivmod( dividend bx:ax, divisor di:cx ) [ signed quot di:cx, rem bx:ax ] @@ -27,171 +28,173 @@ ! if the divisor is negative, the division is done by negating a and b, ! doing the division, then negating q and r +*/ + .code16 - .globl ldivmod + .global ldivmod .text - .even + .align 1 ldivmod: - mov dx,di ! sign byte of b in dh - mov dl,bh ! sign byte of a in dl - test di,di + mov %di,%dx // sign byte of b in dh + mov %bh,%dl // sign byte of a in dl + test %di,%di jns set_asign - neg di - neg cx - sbb di,*0 + neg %di + neg %cx + sbb $0,%di set_asign: - test bx,bx - jns got_signs ! leave r = a positive - neg bx - neg ax - sbb bx,*0 - j got_signs + test %bx,%bx + jns got_signs // leave r = a positive + neg %bx + neg %ax + sbb $0,%bx + jmp got_signs - .globl ludivmod - .even + .global ludivmod + .align 1 ludivmod: - xor dx,dx ! both sign bytes 0 + xor %dx,%dx // both sign bytes 0 got_signs: - push bp - push si - mov bp,sp - push di ! remember b - push cx + push %bp + push %si + mov %sp,%bp + push %di // remember b + push %cx b0 = -4 b16 = -2 - test di,di + test %di,%di jne divlarge - test cx,cx + test %cx,%cx je divzero - cmp bx,cx - jae divlarge ! would overflow - xchg dx,bx ! a in dx:ax, signs in bx - div cx - xchg cx,ax ! q in di:cx, junk in ax - xchg ax,bx ! signs in ax, junk in bx - xchg ax,dx ! r in ax, signs back in dx - mov bx,di ! r in bx:ax - j zdivu1 - -divzero: ! return q = 0 and r = a - test dl,dl + cmp %cx,%bx + jae divlarge // would overflow + xchg %bx,%dx // a in dx:ax, signs in bx + div %cx + xchg %ax,%cx // q in di:cx, junk in ax + xchg %bx,%ax // signs in ax, junk in bx + xchg %dx,%ax // r in ax, signs back in dx + mov %di,%bx // r in bx:ax + jmp zdivu1 + +divzero: // return q = 0 and r = a + test %dl,%dl jns return - j negr ! a initially minus, restore it + jmp negr // a initially minus, restore it divlarge: - push dx ! remember sign bytes - mov si,di ! w in si:dx, initially b from di:cx - mov dx,cx - xor cx,cx ! q in di:cx, initially 0 - mov di,cx + push %dx // remember sign bytes + mov %di,%si // w in si:dx, initially b from di:cx + mov %cx,%dx + xor %cx,%cx // q in di:cx, initially 0 + mov %cx,%di -! r in bx:ax, initially a -! use di:cx rather than dx:cx in order to -! have dx free for a byte pair later +// r in bx:ax, initially a +// use di:cx rather than dx:cx in order to +// have dx free for a byte pair later - cmp si,bx + cmp %bx,%si jb loop1 - ja zdivu ! finished if b > r - cmp dx,ax + ja zdivu // finished if b > r + cmp %ax,%dx ja zdivu -! rotate w (= b) to greatest dyadic multiple of b <= r +// rotate w (= b) to greatest dyadic multiple of b <= r loop1: - shl dx,*1 ! w = 2*w - rcl si,*1 - jc loop1_exit ! w was > r counting overflow (unsigned) - cmp si,bx ! while w <= r (unsigned) + shl $1,%dx // w = 2*w + rcl $1,%si + jc loop1_exit // w was > r counting overflow (unsigned) + cmp %bx,%si // while w <= r (unsigned) jb loop1 ja loop1_exit - cmp dx,ax - jbe loop1 ! else exit with carry clear for rcr + cmp %ax,%dx + jbe loop1 // else exit with carry clear for rcr loop1_exit: - rcr si,*1 - rcr dx,*1 + rcr $1,%si + rcr $1,%dx loop2: - shl cx,*1 ! q = 2*q - rcl di,*1 - cmp si,bx ! if w <= r + shl $1,%cx // q = 2*q + rcl $1,%di + cmp %bx,%si // if w <= r jb loop2_over ja loop2_test - cmp dx,ax + cmp %ax,%dx ja loop2_test loop2_over: - add cx,*1 ! q++ - adc di,*0 - sub ax,dx ! r = r-w - sbb bx,si + add $1,%cx // q++ + adc $0,%di + sub %dx,%ax // r = r-w + sbb %si,%bx loop2_test: - shr si,*1 ! w = w/2 - rcr dx,*1 - cmp si,b16[bp] ! while w >= b + shr $1,%si // w = w/2 + rcr $1,%dx + cmp b16(%bp),%si // while w >= b ja loop2 jb zdivu - cmp dx,b0[bp] + cmp b0(%bp),%dx jae loop2 zdivu: - pop dx ! sign bytes + pop %dx // sign bytes zdivu1: - test dh,dh + test %dh,%dh js zbminus - test dl,dl - jns return ! else a initially minus, b plus - mov dx,ax ! -a = b * q + r ==> a = b * (-q) + (-r) - or dx,bx - je negq ! use if r = 0 - sub ax,b0[bp] ! use a = b * (-1 - q) + (b - r) - sbb bx,b16[bp] - not cx ! q = -1 - q (same as complement) - not di + test %dl,%dl + jns return // else a initially minus, b plus + mov %ax,%dx // -a = b * q + r ==> a = b * (-q) + (-r) + or %bx,%dx + je negq // use if r = 0 + sub b0(%bp),%ax // use a = b * (-1 - q) + (b - r) + sbb b16(%bp),%bx + not %cx // q = -1 - q (same as complement) + not %di negr: - neg bx - neg ax - sbb bx,*0 + neg %bx + neg %ax + sbb $0,%bx return: - mov sp,bp - pop si - pop bp + mov %bp,%sp + pop %si + pop %bp ret - .even + .align 1 zbminus: - test dl,dl ! (-a) = (-b) * q + r ==> a = b * q + (-r) - js negr ! use if initial a was minus - mov dx,ax ! a = (-b) * q + r ==> a = b * (-q) + r - or dx,bx - je negq ! use if r = 0 - sub ax,b0[bp] ! use a = b * (-1 - q) + (b + r) (b is now -b) - sbb bx,b16[bp] - not cx - not di - mov sp,bp - pop si - pop bp + test %dl,%dl // (-a) = (-b) * q + r ==> a = b * q + (-r) + js negr // use if initial a was minus + mov %ax,%dx // a = (-b) * q + r ==> a = b * (-q) + r + or %bx,%dx + je negq // use if r = 0 + sub b0(%bp),%ax // use a = b * (-1 - q) + (b + r) (b is now -b) + sbb b16(%bp),%bx + not %cx + not %di + mov %bp,%sp + pop %si + pop %bp ret - .even + .align 1 negq: - neg di - neg cx - sbb di,*0 - mov sp,bp - pop si - pop bp + neg %di + neg %cx + sbb $0,%di + mov %bp,%sp + pop %si + pop %bp ret diff --git a/elks/arch/i86/lib/ldivul.s b/elks/arch/i86/lib/ldivul.s deleted file mode 100644 index 3563791c5..000000000 --- a/elks/arch/i86/lib/ldivul.s +++ /dev/null @@ -1,15 +0,0 @@ -! ldivul.s -! unsigned bx:ax / 2(di):(di), quotient bx:ax,remainder di:cx, dx not preserved - - .globl ldivul - .extern ludivmod - .text - .even - -ldivul: - mov cx,[di] - mov di,2[di] - call ludivmod ! unsigned bx:ax / di:cx, quot di:cx, rem bx:ax - xchg ax,cx - xchg bx,di - ret diff --git a/elks/arch/i86/lib/leorl.s b/elks/arch/i86/lib/leorl.s deleted file mode 100644 index db977f263..000000000 --- a/elks/arch/i86/lib/leorl.s +++ /dev/null @@ -1,13 +0,0 @@ -! leorl.s - - .globl leorl - .globl leorul - .text - .even - -leorl: - -leorul: - xor ax,[di] - xor bx,2[di] - ret diff --git a/elks/arch/i86/lib/lincl.s b/elks/arch/i86/lib/lincl.s deleted file mode 100644 index b2029d7a8..000000000 --- a/elks/arch/i86/lib/lincl.s +++ /dev/null @@ -1,16 +0,0 @@ -! lincl.s - - .globl lincl - .globl lincul - .text - .even - -lincl: - -lincul: - inc word ptr [bx] - jnz LINC_RET - inc word ptr 2[bx] - -LINC_RET: - ret diff --git a/elks/arch/i86/lib/lmodl.s b/elks/arch/i86/lib/lmodl.s deleted file mode 100644 index c68a6ef93..000000000 --- a/elks/arch/i86/lib/lmodl.s +++ /dev/null @@ -1,13 +0,0 @@ -! lmodl.s -! bx:ax % 2(di):(di), remainder bx:ax, quotient di:cx, dx not preserved - - .globl lmodl - .extern ldivmod - .text - .even - -lmodl: - mov cx,[di] - mov di,2[di] - call ldivmod - ret ! bx:ax / di:cx, quot di:cx, rem bx:ax diff --git a/elks/arch/i86/lib/lmodul.s b/elks/arch/i86/lib/lmodul.s deleted file mode 100644 index 9235069d1..000000000 --- a/elks/arch/i86/lib/lmodul.s +++ /dev/null @@ -1,13 +0,0 @@ -! lmodul.s -! unsigned bx:ax / 2(di):(di), remainder bx:ax,quotient di:cx, dx not preserved - - .globl lmodul - .extern ludivmod - .text - .even - -lmodul: - mov cx,[di] - mov di,2[di] - call ludivmod ! unsigned bx:ax / di:cx, quot di:cx, rem bx:ax - ret diff --git a/elks/arch/i86/lib/lmull.s b/elks/arch/i86/lib/lmull.s deleted file mode 100644 index 1e8dda600..000000000 --- a/elks/arch/i86/lib/lmull.s +++ /dev/null @@ -1,20 +0,0 @@ -! lmull.s -! lmull, lmulul don't preserve cx, dx - - .globl lmull - .globl lmulul - .text - .even - -lmull: - -lmulul: - mov cx,ax - mul word ptr 2[di] - xchg ax,bx - mul word ptr [di] - add bx,ax - mov ax,ptr [di] - mul cx - add bx,dx - ret diff --git a/elks/arch/i86/lib/lnegl.s b/elks/arch/i86/lib/lnegl.s deleted file mode 100644 index 4b7079f98..000000000 --- a/elks/arch/i86/lib/lnegl.s +++ /dev/null @@ -1,14 +0,0 @@ -! lnegl.s - - .globl lnegl - .globl lnegul - .text - .even - -lnegl: - -lnegul: - neg bx - neg ax - sbb bx,*0 - ret diff --git a/elks/arch/i86/lib/lorl.s b/elks/arch/i86/lib/lorl.s deleted file mode 100644 index 8f595d4ad..000000000 --- a/elks/arch/i86/lib/lorl.s +++ /dev/null @@ -1,13 +0,0 @@ -! lorl.s - - .globl lorl - .globl lorul - .text - .even - -lorl: - -lorul: - or ax,[di] - or bx,2[di] - ret diff --git a/elks/arch/i86/lib/lsll.s b/elks/arch/i86/lib/lsll.s deleted file mode 100644 index c50d9aab7..000000000 --- a/elks/arch/i86/lib/lsll.s +++ /dev/null @@ -1,30 +0,0 @@ -! lsll.s -! lsll, lslul don't preserve cx - - .globl lsll - .globl lslul - .text - .even - -lsll: - -lslul: - mov cx,di - jcxz LSL_EXIT - cmp cx,*32 - jae LSL_ZERO - -LSL_LOOP: - shl ax,*1 - rcl bx,*1 - loop LSL_LOOP - -LSL_EXIT: - ret - - .even - -LSL_ZERO: - xor ax,ax - mov bx,ax - ret diff --git a/elks/arch/i86/lib/lsrl.s b/elks/arch/i86/lib/lsrl.s deleted file mode 100644 index 570d4982f..000000000 --- a/elks/arch/i86/lib/lsrl.s +++ /dev/null @@ -1,22 +0,0 @@ -! lsrl.s -! lsrl doesn't preserve cx - - .globl lsrl - .text - .even - -lsrl: - mov cx,di - jcxz LSR_EXIT - cmp cx,*32 - jb LSR_LOOP - mov cx,*32 ! equivalent to +infinity in this context - -LSR_LOOP: - sar bx,*1 - rcr ax,*1 - loop LSR_LOOP - -LSR_EXIT: - ret - diff --git a/elks/arch/i86/lib/lsrul.s b/elks/arch/i86/lib/lsrul.s deleted file mode 100644 index 54e0cb1ef..000000000 --- a/elks/arch/i86/lib/lsrul.s +++ /dev/null @@ -1,27 +0,0 @@ -! lsrul.s -! lsrul doesn't preserve cx - - .globl lsrul - .text - .even - -lsrul: - mov cx,di - jcxz LSRU_EXIT - cmp cx,*32 - jae LSRU_ZERO - -LSRU_LOOP: - shr bx,*1 - rcr ax,*1 - loop LSRU_LOOP - -LSRU_EXIT: - ret - - .even - -LSRU_ZERO: - xor ax,ax - mov bx,ax - ret diff --git a/elks/arch/i86/lib/lsubl.s b/elks/arch/i86/lib/lsubl.s deleted file mode 100644 index 63743ee7d..000000000 --- a/elks/arch/i86/lib/lsubl.s +++ /dev/null @@ -1,13 +0,0 @@ -! lsubl.s - - .globl lsubl - .globl lsubul - .text - .even - -lsubl: - -lsubul: - sub ax,[di] - sbb bx,2[di] - ret diff --git a/elks/arch/i86/lib/ltstl.s b/elks/arch/i86/lib/ltstl.s deleted file mode 100644 index c63989ee6..000000000 --- a/elks/arch/i86/lib/ltstl.s +++ /dev/null @@ -1,17 +0,0 @@ -! ltstl.s -! ltstl, ltstul don't preserve bx - - .globl ltstl - .globl ltstul - .text - .even - -ltstl: -ltstul: - test bx,bx - jne LTSTL_RET - test ax,ax - jns LTSTL_RET - inc bx ! clear ov and mi, set ne for greater than -LTSTL_RET: - ret diff --git a/elks/arch/i86/lib/min.s b/elks/arch/i86/lib/min.s deleted file mode 100644 index 977248387..000000000 --- a/elks/arch/i86/lib/min.s +++ /dev/null @@ -1,16 +0,0 @@ -! __u16 min(__u16 x, __u16 y); - - .globl _min - .text - .even - -_min: - pop bx - pop ax ! x - pop dx ! y - cmp ax,dx - jbe .0 - mov ax,dx -.0: - sub sp,*4 - jmp bx diff --git a/elks/arch/i86/lib/peekb.s b/elks/arch/i86/lib/peekb.s index 8bb6d8980..04783dd5c 100644 --- a/elks/arch/i86/lib/peekb.s +++ b/elks/arch/i86/lib/peekb.s @@ -1,16 +1,18 @@ -; byte_t peekb (word_t off, seg_t seg) -; segment after offset to allow LDS from the stack -; returns the byte at the far pointer segment:offset +// byte_t peekb (word_t off, seg_t seg) +// segment after offset to allow LDS from the stack +// returns the byte at the far pointer segment:offset + + .code16 .text - .define _peekb + .global peekb -_peekb: - mov dx,ds - mov bx,sp - lds bx,[bx+2] ; arg0+1: far pointer - mov al,[bx] ; DS by default - xor ah,ah - mov ds,dx +peekb: + mov %ds,%dx + mov %sp,%bx + lds 2(%bx),%bx // arg0+1: far pointer + mov (%bx),%al // DS by default + xor %ah,%ah + mov %dx,%ds ret diff --git a/elks/arch/i86/lib/peekw.s b/elks/arch/i86/lib/peekw.s index ca6a6c270..e788b30cf 100644 --- a/elks/arch/i86/lib/peekw.s +++ b/elks/arch/i86/lib/peekw.s @@ -1,15 +1,17 @@ -; word_t peekw (word_t off, seg_t seg) -; segment after offset to allow LDS from the stack -; returns the word at the far pointer segment:offset +// word_t peekw (word_t off, seg_t seg) +// segment after offset to allow LDS from the stack +// returns the word at the far pointer segment:offset + + .code16 .text - .define _peekw + .global peekw -_peekw: - mov dx,ds - mov bx,sp - lds bx,[bx+2] ; arg0+1: far pointer - mov ax,[bx] ; DS by default - mov ds,dx +peekw: + mov %ds,%dx + mov %sp,%bx + lds 2(%bx),%bx // arg0+1: far pointer + mov (%bx),%ax // DS by default + mov %dx,%ds ret diff --git a/elks/arch/i86/lib/pokeb.s b/elks/arch/i86/lib/pokeb.s index aaeaed5bb..48259ebc0 100644 --- a/elks/arch/i86/lib/pokeb.s +++ b/elks/arch/i86/lib/pokeb.s @@ -1,17 +1,19 @@ -; void pokeb (word_t off, seg_t seg, byte__t val) -; segment after offset to allow LDS from the stack -; compiler pushes byte_t as word_t -; writes the byte at the far pointer segment:offset +// void pokeb (word_t off, seg_t seg, byte__t val) +// segment after offset to allow LDS from the stack +// compiler pushes byte_t as word_t +// writes the byte at the far pointer segment:offset + + .code16 .text - .define _pokeb + .global pokeb -_pokeb: - mov dx,ds - mov bx,sp - mov ax,[bx+6] ; arg2: value - lds bx,[bx+2] ; arg0+1: far pointer - mov [bx],al ; DS by default - mov ds,dx +pokeb: + mov %ds,%dx + mov %sp,%bx + mov 6(%bx),%ax // arg2: value + lds 2(%bx),%bx // arg0+1: far pointer + mov %al,(%bx) // DS by default + mov %dx,%ds ret diff --git a/elks/arch/i86/lib/pokew.s b/elks/arch/i86/lib/pokew.s index 7ee543c3a..c8af01a96 100644 --- a/elks/arch/i86/lib/pokew.s +++ b/elks/arch/i86/lib/pokew.s @@ -1,16 +1,18 @@ -; void pokew (word_t off, seg_t seg, word_t val) -; segment after offset to allow LDS from the stack -; writes the word at the far pointer segment:offset +// void pokew (word_t off, seg_t seg, word_t val) +// segment after offset to allow LDS from the stack +// writes the word at the far pointer segment:offset + + .code16 .text - .define _pokew + .global pokew -_pokew: - mov dx,ds - mov bx,sp - mov ax,[bx+6] ; arg2: value - lds bx,[bx+2] ; arg0+1: far pointer - mov [bx],ax ; DS by default - mov ds,dx +pokew: + mov %ds,%dx + mov %sp,%bx + mov 6(%bx),%ax // arg2: value + lds 2(%bx),%bx // arg0+1: far pointer + mov %ax,(%bx) // DS by default + mov %dx,%ds ret diff --git a/elks/arch/i86/lib/seglist.S b/elks/arch/i86/lib/seglist.S index 5d0747886..174d1e133 100644 --- a/elks/arch/i86/lib/seglist.S +++ b/elks/arch/i86/lib/seglist.S @@ -1,113 +1,117 @@ /* Double-linked list with segments */ + .code16 + + .text + /* void seglist_init (word_t root_off, seg_t root_seg); */ - .global _seglist_init + .global seglist_init -_seglist_init: - push bp - mov bp,sp - push ds - lds bx,[bp+4] /* node = root */ - mov [bx],ds /* node->prev = node */ - mov [bx+2],ds /* node->next = node */ - pop ds - pop bp +seglist_init: + push %bp + mov %sp,%bp + push %ds + lds 4(%bp),%bx /* node = root */ + mov %ds,(%bx) /* node->prev = node */ + mov %ds,2(%bx) /* node->next = node */ + pop %ds + pop %bp ret seglist_link: - mov ds,cx /* prev->next = node */ - mov [bx+2],ax - mov ds,dx /* next->prev = node */ - mov [bx],ax - mov ds,ax - mov [bx],cx /* node->prev = prev */ - mov [bx+2],dx /* node->next = next */ + mov %cx,%ds /* prev->next = node */ + mov %ax,2(%bx) + mov %dx,%ds /* next->prev = node */ + mov %ax,(%bx) + mov %ax,%ds + mov %cx,(%bx) /* node->prev = prev */ + mov %dx,2(%bx) /* node->next = next */ ret /* void seglist_insert_before (word_t node_off, seg_t next_seg, seg_t node_seg); */ - .global _seglist_insert_before + .global seglist_insert_before -_seglist_insert_before: - push bp - mov bp,sp - push ds - mov bx,[bp+4] /* ax:bx = node */ - mov ax,[bp+8] - mov dx,[bp+6] /* dx:bx = next */ - mov ds,dx /* prev = next->prev */ - mov cx,[bx] /* cx:bx = prev */ +seglist_insert_before: + push %bp + mov %sp,%bp + push %ds + mov 4(%bp),%bx /* ax:bx = node */ + mov 8(%bp),%ax + mov 6(%bp),%dx /* dx:bx = next */ + mov %dx,%ds /* prev = next->prev */ + mov (%bx),%cx /* cx:bx = prev */ call seglist_link - pop ds - pop bp + pop %ds + pop %bp ret /* void seglist_insert_after (word_t node_off, seg_t prev_seg, seg_t node_seg); */ - .global _seglist_insert_after + .global seglist_insert_after -_seglist_insert_after: - push bp - mov bp,sp - push ds - mov bx,[bp+4] /* ax:bx = node */ - mov ax,[bp+8] - mov cx,[bp+6] /* cx:bx = prev */ - mov ds,cx /* next = prev->next */ - mov dx,[bx+2] /* dx:bx = next */ +seglist_insert_after: + push %bp + mov %sp,%bp + push %ds + mov 4(%bp),%bx /* ax:bx = node */ + mov 8(%bp),%ax + mov 6(%bp),%cx /* cx:bx = prev */ + mov %cx,%ds /* next = prev->next */ + mov 2(%bx),%dx /* dx:bx = next */ call seglist_link - pop ds - pop bp + pop %ds + pop %bp ret /* void seglist_remove (word_t node_off, seg_t node_seg); */ - .global _seglist_remove + .global seglist_remove -_seglist_remove: - push bp - mov bp,sp - push ds - mov bx,[bp+4] /* ax:bx = node */ - mov ax,[bp+6] - mov ds,ax - mov cx,[bx] /* prev = cx:bx = node->prev */ - mov dx,[bx+2] /* next = dx:bx = node->next */ - mov ds,cx /* prev->next = next */ - mov [bx+2],dx - mov ds,dx /* next->prev = prev */ - mov [bx],cx - pop ds - pop bp +seglist_remove: + push %bp + mov %sp,%bp + push %ds + mov 4(%bp),%bx /* ax:bx = node */ + mov 6(%bp),%ax + mov %ax,%ds + mov (%bx),%cx /* prev = cx:bx = node->prev */ + mov 2(%bx),%dx /* next = dx:bx = node->next */ + mov %cx,%ds /* prev->next = next */ + mov %dx,2(%bx) + mov %dx,%ds /* next->prev = prev */ + mov %cx,(%bx) + pop %ds + pop %bp ret /* void seglist_prev (word_t node_off, seg_t node_seg, seg_t * prev_seg); */ - .global _seglist_prev + .global seglist_prev -_seglist_prev: - push bp - mov bp,sp - push ds - mov bx,[bp+4] /* ax:bx = node */ - mov ax,[bp+6] - mov ds,ax - mov cx,[bx] /* prev = cx:bx = node->prev */ - pop ds - mov bx,[bp+8] - mov [bx],cx - pop bp +seglist_prev: + push %bp + mov %sp,%bp + push %ds + mov 4(%bp),%bx /* ax:bx = node */ + mov 6(%bp),%ax + mov %ax,%ds + mov (%bx),%cx /* prev = cx:bx = node->prev */ + pop %ds + mov 8(%bp),%bx + mov %cx,(%bx) + pop %bp ret /* void seglist_next (word_t node_off, seg_t node_seg, seg_t * next_seg); */ - .global _seglist_next + .global seglist_next -_seglist_next: - push bp - mov bp,sp - push ds - mov bx,[bp+4] /* ax:bx = node */ - mov ax,[bp+6] - mov ds,ax - mov dx,[bx+2] /* next = dx:bx = node->next */ - pop ds - mov bx,[bp+8] - mov [bx],dx - pop bp +seglist_next: + push %bp + mov %sp,%bp + push %ds + mov 4(%bp),%bx /* ax:bx = node */ + mov 6(%bp),%ax + mov %ax,%ds + mov 2(%bx),%dx /* next = dx:bx = node->next */ + pop %ds + mov 8(%bp),%bx + mov %dx,(%bx) + pop %bp ret diff --git a/elks/arch/i86/lib/setupb.S b/elks/arch/i86/lib/setupb.S index 11ccd71aa..fde904411 100644 --- a/elks/arch/i86/lib/setupb.S +++ b/elks/arch/i86/lib/setupb.S @@ -1,20 +1,22 @@ -! int setupb(char *offset); -! returns the (unsigned) byte at the far pointer SETUP_DATA:offset +// int setupb(char *offset); +// returns the (unsigned) byte at the far pointer SETUP_DATA:offset + + .code16 #include - .define _setupb .text - .even -_setupb: - mov cx,ds - pop dx - mov ax,#SETUP_DATA - mov ds,ax - pop bx - sub sp,*2 - movb al,[bx] - subb ah,ah - mov ds,cx - jmp dx + .global setupb + +setupb: + mov %ds,%cx + pop %dx + mov $SETUP_DATA,%ax + mov %ax,%ds + pop %bx + sub $2,%sp + mov (%bx),%al + sub %ah,%ah + mov %cx,%ds + jmp %dx diff --git a/elks/arch/i86/lib/setupw.S b/elks/arch/i86/lib/setupw.S index 39c5aae1f..f29336d5a 100644 --- a/elks/arch/i86/lib/setupw.S +++ b/elks/arch/i86/lib/setupw.S @@ -1,19 +1,21 @@ -! int setupw( int *offset ); -! returns the word at the far pointer SETUP_DATA:offset +// int setupw( int *offset ); +// returns the word at the far pointer SETUP_DATA:offset #include - .define _setupw + .code16 + + .global setupw .text - .even + .align 1 -_setupw: - mov cx,ds - pop dx - mov ax,#SETUP_DATA - mov ds,ax - pop bx - sub sp,*2 - mov ax,[bx] - mov ds,cx - jmp dx +setupw: + mov %ds,%cx + pop %dx + mov $SETUP_DATA,%ax + mov %ax,%ds + pop %bx + sub $2,%sp + mov (%bx),%ax + mov %cx,%ds + jmp %dx diff --git a/elks/arch/i86/lib/string.S b/elks/arch/i86/lib/string.S index 77dd57c81..79ebf2238 100644 --- a/elks/arch/i86/lib/string.S +++ b/elks/arch/i86/lib/string.S @@ -1,131 +1,141 @@ -! string.s -! Contributed by Christoph Niemann +// string.s +// Contributed by Christoph Niemann + + .code16 .text - .define _strlen - .define _strcpy - .define _strcmp - .define _memset + .global strlen + .global strcpy + .global strcmp + .global memset +/* ! int strlen(char *str) ! ! returns the length of a string in ax ! +*/ -_strlen: ! needs more testing! +strlen: // needs more testing! #ifdef USE_IA16 - mov dx,es - mov es,_kernel_ds + mov %es,%dx + mov kernel_ds,%es #endif - mov bx,sp - push di - mov di,2[bx] - xor al,al - cld ! so di increments not decrements - mov cx,#-1 ! maximum loop count - repne ! while (cx) { - scasb ! cx--; if (al - [es:di++] == 0) break;} - mov ax,di - sub ax,2[bx] - dec ax - pop di + mov %sp,%bx + push %di + mov 2(%bx),%di + xor %al,%al + cld // so di increments not decrements + mov $-1,%cx // maximum loop count + repne // while (cx) { + scasb // cx--; if (al - [es:di++] == 0) break;} + mov %di,%ax + sub 2(%bx),%ax + dec %ax + pop %di #ifdef USE_IA16 - mov es,dx + mov %dx,%es #endif ret +/* ! ! char *strcpy(char *dest, char *source) ! ! copies the zero terminated string source to dest. ! +*/ -_strcpy: +strcpy: #ifdef USE_IA16 - mov dx,es - mov es,_kernel_ds + mov %es,%dx + mov kernel_ds,%es #endif - mov bx,sp - push di - push si - mov di,2[bx] ! address of the destination string - mov si,4[bx] ! address of the source string + mov %sp,%bx + push %di + push %si + mov 2(%bx),%di // address of the destination string + mov 4(%bx),%si // address of the source string cld -copyon: lodsb ! al = [ds:si++] - stosb ! [es:di++] = al - test al,al +copyon: lodsb // al = [ds:si++] + stosb // [es:di++] = al + test %al,%al jnz copyon - mov ax,2[bx] ! _strcpy returns a pointer to the destination string - pop si - pop di + mov 2(%bx),%ax // _strcpy returns a pointer to the destination string + pop %si + pop %di #ifdef USE_IA16 - mov es,dx + mov %dx,%es #endif ret +/* ! ! int strcmp(char *str1, char *str2) ! ! compares to zero terminated strings ! +*/ -_strcmp: +strcmp: #ifdef USE_IA16 - mov dx,es - mov es,_kernel_ds + mov %es,%dx + mov kernel_ds,%es #endif - mov bx,sp - push di - push si - mov si,2[bx] ! address of the string 1 - mov di,4[bx] ! address of the string 2 + mov %sp,%bx + push %di + push %si + mov 2(%bx),%si // address of the string 1 + mov 4(%bx),%di // address of the string 2 cld -cmpon: lodsb ! al = [ds:si++] - scasb ! al - [es:di++] +cmpon: lodsb // al = [ds:si++] + scasb // al - [es:di++] jne cmpend - testb al,al + test %al,%al jnz cmpon - xor ax,ax ! both strings are the same + xor %ax,%ax // both strings are the same jmp cmpret -cmpend: sbb ax,ax ! strings differ - or ax,#1 +cmpend: sbb %ax,%ax // strings differ + or $1,%ax -cmpret: pop si - pop di +cmpret: pop %si + pop %di #ifdef USE_IA16 - mov es,dx + mov %dx,%es #endif ret +/* ! ! char *memset(char *p, int value, size_t count) ! +*/ -_memset: +memset: #ifdef USE_IA16 - mov dx,es - mov es,_kernel_ds + mov %es,%dx + mov kernel_ds,%es #endif - mov bx,sp - push di - mov di,2[bx] ! address of the memory block - mov ax,4[bx] ! byte to write - mov cx,6[bx] ! loop count + mov %sp,%bx + push %di + mov 2(%bx),%di // address of the memory block + mov 4(%bx),%ax // byte to write + mov 6(%bx),%cx // loop count cld - rep ! while (cx) - stosb ! cx--, [es:di++] = al - mov ax,2[bx] ! return value = start addr of block - pop di + rep // while (cx) + stosb // cx--, [es:di++] = al + mov 2(%bx),%ax // return value = start addr of block + pop %di #ifdef USE_IA16 - mov es,dx + mov %dx,%es #endif ret #ifdef USE_IA16 .data - .extern _kernel_ds + .extern kernel_ds #endif diff --git a/elks/arch/i86/mm/Makefile b/elks/arch/i86/mm/Makefile index 35eb87d54..aa60ad353 100644 --- a/elks/arch/i86/mm/Makefile +++ b/elks/arch/i86/mm/Makefile @@ -40,7 +40,8 @@ OBJS = init.o malloc.o user.o segment.o ######################################################################### # Commands. -segment.o: segment.s +segment.s: segment.S +segment.o: segment.s all: mm.a diff --git a/elks/arch/i86/mm/segment.S b/elks/arch/i86/mm/segment.S index f61823f1f..4951423cb 100644 --- a/elks/arch/i86/mm/segment.S +++ b/elks/arch/i86/mm/segment.S @@ -4,55 +4,57 @@ #include + .code16 + .text /* void memcpy_fromfs(void *daddr, void *saddr, size_t len);*/ - .globl _memcpy_fromfs + .global memcpy_fromfs -_memcpy_fromfs: - mov ax,si - mov dx,di - mov bx,sp - mov di,2[bx] - mov si,4[bx] - mov cx,6[bx] - mov bx,_current - mov ds,TASK_USER_DS[bx] - mov bx,ss +memcpy_fromfs: + mov %si,%ax + mov %di,%dx + mov %sp,%bx + mov 2(%bx),%di + mov 4(%bx),%si + mov 6(%bx),%cx + mov current,%bx + mov TASK_USER_DS(%bx),%ds + mov %ss,%bx #ifdef USE_IA16 - push es - mov es,bx + push %es + mov %bx,%es #endif cld rep movsb #ifdef USE_IA16 - pop es + pop %es #endif - mov ds,bx - mov di,dx - mov si,ax + mov %bx,%ds + mov %dx,%di + mov %ax,%si ret /* void memcpy_tofs(void *daddr, void *saddr, size_t len);*/ - .globl _memcpy_tofs + .global memcpy_tofs -_memcpy_tofs: - mov ax,si - mov dx,di - mov bx,es - mov si,_current - mov es,TASK_USER_DS[si] - mov si,sp - mov di,2[si] - mov cx,6[si] - mov si,4[si] +memcpy_tofs: + mov %si,%ax + mov %di,%dx + mov %es,%bx + mov current,%si + mov TASK_USER_DS(%si),%es + mov %sp,%si + mov 2(%si),%di + mov 6(%si),%cx + mov 4(%si),%si cld rep movsb - mov es,bx - mov di,dx - mov si,ax + mov %bx,%es + mov %dx,%di + mov %ax,%si ret /* int strnlen_fromfs(void *saddr, size_t maxlen); */ @@ -60,29 +62,29 @@ _memcpy_tofs: /* scasb uses es:di, not ds:si, so it is not necessary * to save and restore ds */ - .globl _strnlen_fromfs + .global strnlen_fromfs -_strnlen_fromfs: - mov dx,di - mov di,_current - mov bx,sp - push es - mov es,TASK_USER_DS[di] - mov di,2[bx] - mov cx,4[bx] - xor al,al ! search for NULL byte +strnlen_fromfs: + mov %di,%dx + mov current,%di + mov %sp,%bx + push %es + mov TASK_USER_DS(%di),%es + mov 2(%bx),%di + mov 4(%bx),%cx + xor %al,%al // search for NULL byte cld repne scasb - pop es - mov ax,di ! calc len +1 - mov di,dx + pop %es + mov %di,%ax // calc len +1 + mov %dx,%di jnz strnln1 - dec ax + dec %ax strnln1: - sub ax,2[bx] + sub 2(%bx),%ax ret .data - .extern _current + .extern current diff --git a/elks/elks-small.ld b/elks/elks-small.ld new file mode 100644 index 000000000..e35b79e9f --- /dev/null +++ b/elks/elks-small.ld @@ -0,0 +1,24 @@ +OUTPUT_FORMAT(binary) + +SECTIONS { + .hdr : { + SHORT (0x0301); /* ELKS a.out magic */ + BYTE (0x30); /* flags : executable with separated I & D */ + BYTE (0x04); /* CPU : i8086 */ + BYTE (0x20); /* header length (32) */ + BYTE (0); /* unused */ + SHORT (0); /* version (unused) */ + LONG(SIZEOF (.text)); + LONG(SIZEOF (.data)); + LONG (SIZEOF (.bss)); + LONG (start); /* entry point */ + LONG (0); /* total memory allocated */ + LONG (0); /* symbol table size */ + } + _begintext = ALIGN(0x20); + .text 0 : AT(_begintext) { *(.text); . = ALIGN(0x10); } + _begindata = _begintext + .; + .data 0 : AT(_begindata) { *(.data) *(.rodata*) } + .bss : { *(.bss) *(COMMON) } + /DISCARD/ : { *(.comment) } +} diff --git a/elks/elks-tiny.ld b/elks/elks-tiny.ld new file mode 100644 index 000000000..248036336 --- /dev/null +++ b/elks/elks-tiny.ld @@ -0,0 +1,21 @@ +OUTPUT_FORMAT(binary) + +SECTIONS { + .hdr : { + SHORT (0x0301); /* ELKS a.out magic */ + BYTE (0x10); /* flags : executable with mixed I & D */ + BYTE (0x04); /* CPU : i8086 */ + BYTE (0x20); /* header length (32) */ + BYTE (0); /* unused */ + SHORT (0); /* version (unused) */ + LONG (SIZEOF (.text)); + LONG (0); /* .data section size */ + LONG (0); /* .bss section size */ + LONG (start); /* entry point */ + LONG (0); /* total memory allocated */ + LONG (0); /* symbol table size */ + } + _begintext = ALIGN(0x20); + .text 0 : AT(_begintext) { *(.text) *(.data) *(.rodata*) *(.bss) *(COMMON) } + /DISCARD/ : { *(.comment) } +} diff --git a/elks/fs/exec.c b/elks/fs/exec.c index 2e119536c..9b04d30ac 100644 --- a/elks/fs/exec.c +++ b/elks/fs/exec.c @@ -96,7 +96,7 @@ int sys_execve(char *filename, char *sptr, size_t slen) debug1("EXEC: Inode dev = 0x%x opened OK.\n", inode->i_dev); currentp->t_regs.ds = kernel_ds; - retval = filp->f_op->read(inode, filp, &mh, sizeof(mh)); + retval = filp->f_op->read(inode, filp, (char *) &mh, sizeof(mh)); /* Sanity check it. */ if (retval != (int)sizeof(mh) || @@ -114,7 +114,7 @@ int sys_execve(char *filename, char *sptr, size_t slen) #ifdef CONFIG_EXEC_ELKS if ((unsigned int) mh.hlen == 0x30) { /* BIG HEADER */ - retval = filp->f_op->read(inode, filp, &msuph, sizeof(msuph)); + retval = filp->f_op->read(inode, filp, (char *) &msuph, sizeof(msuph)); if (retval != (int)sizeof(msuph)) { debug1("EXEC: Bad secondary header, result %u\n", retval); goto error_exec3; diff --git a/elks/include/arch/segment.h b/elks/include/arch/segment.h index 8c9f7c4b9..fc545d342 100644 --- a/elks/include/arch/segment.h +++ b/elks/include/arch/segment.h @@ -5,9 +5,10 @@ extern __u16 kernel_cs, kernel_ds; -extern __u16 setupw(unsigned short int); +// Get data from setup segment -#define setupb(p) ((char)setupw(p)) +extern word_t setupw (word_t); +extern byte_t setupb (word_t); extern pid_t get_pid(void); diff --git a/elks/include/arch/system.h b/elks/include/arch/system.h index 592017e62..bb27a63d0 100644 --- a/elks/include/arch/system.h +++ b/elks/include/arch/system.h @@ -3,7 +3,7 @@ #include -extern int arch_cpu; +extern byte_t arch_cpu; // processor number (from setup data) extern void arch_setuptasks(void); extern void setup_arch(seg_t *,seg_t *); diff --git a/elks/net/Makefile b/elks/net/Makefile index ec50ef42c..b9f445708 100644 --- a/elks/net/Makefile +++ b/elks/net/Makefile @@ -43,7 +43,7 @@ OBJS = socket.o protocols.o ipv4/af_inet.o nano/af_nano.o unix/af_unix.o all: net.a net.a: $(OBJS) - ar rcs net.a $(OBJS) + $(AR) rcs net.a $(OBJS) ######################################################################### # Standard commands. diff --git a/elkscmd/Make.defs b/elkscmd/Make.defs index 2f180685d..cdc40a95c 100644 --- a/elkscmd/Make.defs +++ b/elkscmd/Make.defs @@ -74,20 +74,23 @@ ELKS_VSN=$(shell printf '%s.%s.%s-pre%s' $(E_V) | sed 's/-pre$$//') ifeq ($(PLATFORM),i86-ELKS) CC=bcc CFLBASE=-0 -O -ansi + LD=ld86 LDFLAGS=-s -ansi CHECK=gcc -c -o .null.o -Wall -pedantic + AS=as86 endif ifeq ($(PLATFORM),DEFAULT) CC=cc CFLBASE= + LD=ld LDFLAGS= CHECK=cc -c -o .null.o + AS=as endif CFLAGS=$(CFLBASE) $(LOCALFLAGS) $(INCLUDES) -D__ELKS__ -DELKS_VERSION=\"$(ELKS_VSN)\" -LD=ld86 ############################################################################### # diff --git a/elkscmd/config.in b/elkscmd/config.in index 80c70d366..1745c5301 100644 --- a/elkscmd/config.in +++ b/elkscmd/config.in @@ -71,16 +71,15 @@ mainmenu_option next_comment choice 'Filesystem' \ "MINIX CONFIG_IMG_MINIX \ FAT CONFIG_IMG_FAT \ + RAW CONFIG_IMG_RAW \ ROM CONFIG_IMG_ROM" MINIX - if [ "$CONFIG_IMG_FAT" != "y" ]; then + if [ "$CONFIG_IMG_MINIX" == "y" -o "$CONFIG_IMG_ROM" == "y" ]; then define_bool CONFIG_IMG_LINK y fi if [ "$CONFIG_IMG_ROM" != "y" ]; then - define_bool CONFIG_IMG_DEV y - choice 'Medium' \ "FD1680 CONFIG_IMG_FD1680 \ FD1440 CONFIG_IMG_FD1440 \ @@ -89,6 +88,10 @@ mainmenu_option next_comment FD360 CONFIG_IMG_FD360 \ HD CONFIG_IMG_HD" FD1440 + if [ "$CONFIG_IMG_MINIX" == "y" -o "$CONFIG_IMG_FAT" == "y" ]; then + define_bool CONFIG_IMG_DEV y + fi + if [ "$CONFIG_IMG_HD" == "y" ]; then int 'Blocks' CONFIG_IMG_BLOCKS 32768 fi diff --git a/elkscmd/sys_utils/Makefile b/elkscmd/sys_utils/Makefile index b4762954a..a68d231d3 100644 --- a/elkscmd/sys_utils/Makefile +++ b/elkscmd/sys_utils/Makefile @@ -42,7 +42,7 @@ meminfo: meminfo.c swapon: swapon.c $(CC) $(CFLAGS) $(LDFLAGS) swapon.c -o swapon -H 0x100 -init: init.c +init: init.c $(CC) $(CFLAGS) $(LDFLAGS) init.c -o init -H 0x8000 rdev: rdev.c diff --git a/tools/Makefile b/tools/Makefile index 3b5e314ed..6a63718fc 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,7 +1,10 @@ -# Select the cross compiler to build -# Default is to build BCC and GCC-IA16 -BUILD_BCC = 1 -BUILD_GCC_IA16 = 1 +# Makefile for cross tools + +ifndef TOPDIR +$(error TOPDIR is not defined) +endif + +include $(TOPDIR)/Make.defs .PHONY: all @@ -28,26 +31,15 @@ $(DISTDIR)/$(DEV86_DIST).zip: cd dev86 && make PREFIX=$(CROSSDIR) install touch .dev86.build -ifdef BUILD_BCC all:: .dev86.build -endif - -# ATT to AS86 conversion utility - -ifdef BUILD_GCC_IA16 -all:: $(CROSSDIR)/bin/att2as86 -endif - -$(CROSSDIR)/bin/att2as86: - make -C $(SRCDIR)/att2as86 all install # BINUTILS for IA16 -BINUTILS_VER=c045395ece435fcb3bf6225e9c4734b3ebcc874b +BINUTILS_VER=504e9ad8fbcc41117c004c42d97a645cc7eb306b BINUTILS_DIST=binutils-ia16-$(BINUTILS_VER) $(DISTDIR)/$(BINUTILS_DIST).zip: - cd $(DISTDIR) && wget https://github.com/crtc-demos/binutils-ia16/archive/$(BINUTILS_VER).zip -O $(BINUTILS_DIST).zip + cd $(DISTDIR) && wget https://github.com/tkchia/binutils-ia16/archive/$(BINUTILS_VER).zip -O $(BINUTILS_DIST).zip .binutils.src: $(DISTDIR)/$(BINUTILS_DIST).zip -rm -rf $(BINUTILS_DIST) @@ -64,17 +56,15 @@ $(DISTDIR)/$(BINUTILS_DIST).zip: make -C binutils-build install touch .binutils.build -ifdef BUILD_GCC_IA16 all:: .binutils.build -endif # GCC for IA16 -GCC_VER=5853ef6a8e9334fb1e6d4a86dd92179d2dba9d32 +GCC_VER=eb57e7ea98ebf30ff455fbde1af4c7279cc030bc GCC_DIST=gcc-ia16-$(GCC_VER) $(DISTDIR)/$(GCC_DIST).zip: - cd $(DISTDIR) && wget https://github.com/jbruchon/gcc-ia16/archive/$(GCC_VER).zip -O $(GCC_DIST).zip + cd $(DISTDIR) && wget https://github.com/tkchia/gcc-ia16/archive/$(GCC_VER).zip -O $(GCC_DIST).zip .gcc.src: $(DISTDIR)/$(GCC_DIST).zip -rm -rf $(GCC_DIST) @@ -91,6 +81,4 @@ $(DISTDIR)/$(GCC_DIST).zip: make -C gcc-build install touch .gcc.build -ifdef BUILD_GCC_IA16 all:: .gcc.build -endif diff --git a/tools/att2as86/Makefile b/tools/att2as86/Makefile deleted file mode 100644 index 93abb327c..000000000 --- a/tools/att2as86/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -.PHONY: all install - -# ATT to AS86 conversion utility - -CFLAGS=-O2 -ansi -Wpedantic -Wall -Wextra - -$(BUILDDIR)/att2as86.o: att2as86.c - mkdir -p $(BUILDDIR) - $(CC) -c $(CFLAGS) -o $@ $< - -all: $(BUILDDIR)/att2as86 - -install: $(BUILDDIR)/att2as86 - mkdir -p $(CROSSDIR)/bin - install $< $(CROSSDIR)/bin diff --git a/tools/att2as86/att2as86.c b/tools/att2as86/att2as86.c deleted file mode 100644 index 9804df992..000000000 --- a/tools/att2as86/att2as86.c +++ /dev/null @@ -1,570 +0,0 @@ -/* -Copyright (C) 2014 Juan Perez - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -/* gnu as to as86 source code converter */ - - -#include -#include -#include -#include - -#define MAX_LINE 4096 -#define MAX_OPERANDS 5 - -static char buffer[MAX_LINE]; -static char *operands[MAX_OPERANDS]; -static int sects[] = {'T', 'D', 'B', 'R',}; -static char *sectmsg[] = {".text", ".data", ".bss", ".rom", ".undef",}; - - -typedef struct { - char *att; - char *as86; - int type; -} instruction; -static int opcode = 0; -static int lineno = 1; -static char *imm_one = "#1"; - -static instruction mnemonics[] = { - {".align", ".align", 12}, - {".arch", ".", 0}, - {".ascii", ".ascii", 12}, - {".asciz", ".asciz", 12}, - {".att_syntax", ".", 0}, - {".byte", ".byte", 12}, - {".bss", ".bss", 12}, - {".code16", ".", 0}, - {".comm", ".comm", 9}, - {".data", ".data", 12}, - {".extern", ".globl", 12}, - {".global", "export", 12}, - {".hword", ".word", 12}, - {".ident", ".", 0}, - {".local", ".", 0,}, - {".long", ".long", 12,}, - {".p2align",".align", 7}, - {".section",".sect", 6}, - {".single", ".single", 12}, - {".size", ".", 0}, - {".skip", ".space", 8}, - {".string", ".asciz", 12}, - {".text", ".text", 1}, - {".type", ".", 0}, - {".word", ".word", 1}, - {"aaa", "aaa", 1}, - {"aad", "aad", 1}, - {"aam", "aam", 1}, - {"aas", "aas", 1}, - {"adcb", "adcb", 2}, - {"adcw", "adc", 2}, - {"addb", "addb", 2}, - {"addw", "add", 2}, - {"andb", "andb", 2}, - {"andw", "and", 2}, - {"call", "call", 5}, - {"cbtw", "cbw", 1}, - {"clc", "clc", 1}, - {"cld", "cld", 1}, - {"cli", "cli", 1}, - {"cmc", "cmc", 1}, - {"cmpb", "cmpb", 2}, - {"cmpsb", "cmpsb", 1}, - {"cmpsw", "cmpsw", 1}, - {"cmpw", "cmp", 2}, - {"cwtd", "cwd", 1}, - {"daa", "daa", 1}, - {"das", "das", 1}, - {"decb", "decb", 1}, - {"decw", "dec", 1}, - {"divb", "divb", 1}, - {"divw", "div", 1}, - {"fadd", "fadd", 1}, - {"faddp", "faddp", 1}, - {"faddps", "faddp", 1}, - {"fadds", "fadd", 1}, - {"fcom", "fcom", 1}, - {"fcomp", "fcomp", 1}, - {"fcomps", "fcomp", 1}, - {"fcoms", "fcom", 1}, - {"fdiv", "fdiv", 1}, - {"fdivp", "fdivp", 1}, - {"fdivr", "fdivr", 1}, - {"fdivrp", "fdivrp", 1}, - {"fdivrs", "fdivrs", 1}, - {"fildl", "fild", 1}, - {"fistl", "fist", 1}, - {"fistpl", "fistp", 1}, - {"fld", "fld", 1}, - {"fldcw", "fldcw", 1}, - {"fldenv", "fldenv", 1}, - {"flds", "fld", 1}, - {"fmul", "fmul", 1}, - {"fmulp", "fmulp", 1}, - {"fmulps", "fmulp", 1}, - {"fmuls", "fmul", 1}, - {"fnstcw", "fnstcw", 1}, - {"fnstenv", "fnstenv", 1}, - {"fnstsw", "fnstsw", 1}, - {"fstp", "fstp", 1}, - {"fstps", "fstp", 1}, - {"fsts", "fst", 1}, - {"fsub", "fsub", 1}, - {"fsubp", "fsubp", 1}, - {"fsubps", "fsubps", 1}, - {"fsubr", "fsubr", 1}, - {"fsubrp", "fsubrp", 1}, - {"fsubrs", "fsubrs", 1}, - {"fsubs", "fsubs", 1}, - {"fxch", "fxch", 1}, - {"hlt", "hlt", 1}, - {"idivb", "idivb", 1}, - {"idivw", "idiv", 1}, - {"imulb", "imulb", 3}, - {"imulw", "imul", 3}, - {"inb", "inb", 2}, - {"incb", "incb", 1}, - {"incw", "inc", 1}, - {"int", "int", 1}, - {"into", "into", 1}, - {"inw", "in", 2}, - {"iret", "iret", 1}, - {"ja", "bhi", 1}, /**/ - {"jae", "bhis", 1}, /**/ - {"jb", "blo", 1}, /**/ - {"jbe", "blos", 1}, /**/ - {"jc", "bcs", 1}, /**/ - {"jcxz", "jcxz", 1}, - {"je", "beq", 1}, /**/ - {"jg", "bgt", 1}, /**/ - {"jge", "bge", 1}, /**/ - {"jl", "blt", 1}, /**/ - {"jle", "ble", 1}, /**/ - {"jmp", "br", 5}, - {"jna", "blos", 1}, /**/ - {"jnae", "blo", 1}, /**/ - {"jnb", "bhis", 1}, /**/ - {"jnbe", "bhi", 1}, /**/ - {"jnc", "bcc", 1}, /**/ - {"jne", "bne", 1}, /**/ - {"jng", "ble", 1}, /**/ - {"jnge", "blt", 1}, /**/ - {"jnl", "bge", 1}, /**/ - {"jnle", "bgt", 1}, /**/ - {"jno", "bvc", 1}, /**/ - {"jnp", "bpc", 1}, /**/ - {"jns", "bpl", 1}, /**/ - {"jnz", "bne", 1}, /**/ - {"jo", "bvs", 1}, /**/ - {"jp", "bps", 1}, /**/ - {"jpe", "bps", 1}, /**/ - {"jpo", "bpc", 1}, /**/ - {"js", "bmi", 1}, /**/ - {"jz", "beq", 1}, /**/ - {"lahf", "lahf", 1}, - {"ldsw", "lds", 2}, - {"leaw", "lea", 2}, - {"lesw", "les", 2}, - {"lodsb", "lodsb", 1}, - {"lodsw", "lodsw", 1}, - {"loop", "loop", 1}, - {"loope", "loope", 1}, - {"loopne", "loopne", 1}, - {"loopnz", "loopnz", 1}, - {"loopz", "loopz", 1}, - {"movb", "movb", 2}, - {"movsb", "movsb", 1}, - {"movsw", "movsw", 1}, - {"movw", "mov", 2}, - {"mulb", "mulb", 1}, - {"mulw", "mul", 1}, - {"negb", "negb", 1}, - {"negw", "neg", 1}, - {"nop", "nop", 1}, - {"notb", "notb", 1}, - {"notw", "not", 1}, - {"orb", "orb", 2}, - {"orw", "or", 2}, - {"outb", "outb", 2}, - {"outw", "out", 2}, - {"popa", "popa", 1}, - {"popf", "popf", 1}, - {"popfw", "popf", 1}, - {"popw", "pop", 1}, - {"pusha", "pusha", 1}, - {"pushf", "pushf", 1}, - {"pushfw", "pushf", 1}, - {"pushw", "push", 1}, - {"rclb", "rclb", 4}, - {"rclw", "rcl", 4}, - {"rcrb", "rcrb", 4}, - {"rcrw", "rcr", 4}, - {"rep", "rep", 11}, - {"repe", "repe", 11}, - {"repne", "repne", 11}, - {"repnz", "repnz", 11}, - {"repz", "repz", 11}, - {"ret", "ret", 1}, - {"rolb", "rolb", 4}, - {"rolw", "rol", 4}, - {"rorb", "rorb", 4}, - {"rorw", "ror", 4}, - {"sahf", "sahf", 1}, - {"salb", "salb", 4}, - {"salw", "sal", 4}, - {"sarb", "sarb", 4}, - {"sarw", "sar", 4}, - {"sbbb", "sbbb", 2}, - {"sbbw", "sbb", 2}, - {"scasb", "scasb", 1}, - {"scasw", "scasw", 1}, - {"shlb", "shlb", 4}, - {"shlw", "shl", 4}, - {"shrb", "shrb", 4}, - {"shrw", "shr", 4}, - {"stc", "stc", 1}, - {"std", "std", 1}, - {"sti", "sti", 1}, - {"stosb", "stosb", 1}, - {"stosw", "stosw", 1}, - {"subb", "subb", 2}, - {"subw", "sub", 2}, - {"testb", "testb", 2}, - {"testw", "test", 2}, - {"xchgb", "xchgb", 1}, - {"xchgw", "xchg", 1}, - {"xlat", "xlatb", 11}, - {"xlatb", "xlatb", 11}, - {"xorb", "xorb", 2}, - {"xorw", "xor", 2}, -}; - -static int next(char *token) -{ - int chr; - char *buf; - - buf = token; -/*********** Skip whitespace and comments ***********/ - do { - chr = getchar(); - if((chr == EOF) || (chr == '\n')) - return chr; - if((chr == '#') || (chr == ';')) { - do { - chr = getchar(); - } while((chr != '\n') && (chr != EOF)); - return chr; - } - } while((chr <= ' ') || (chr > '~')); -/******************** Get number ********************/ - if(isdigit(chr)) { - do { - *token++ = chr; - chr = getchar(); - } while(isdigit(chr)); - *token = 0; - ungetc(chr, stdin); - return '0'; - } -/******* Get alphanumeric, labels and opcodes *******/ - if(chr == '.') { - chr = getchar(); - if(isalpha(chr) || (chr == '.') || (chr == '_')) { - *token++ = '.'; - } - else { - ungetc(chr, stdin); - return '.'; - } - } - if(isalpha(chr) || (chr == '.') || (chr == '_')) { - do { - *token++ = chr; - chr = getchar(); - } while(isalnum(chr) || (chr == '.') || (chr == '_')); - if(chr == ':') { - *token++ = chr; - *token = 0; - return 'L'; - } - *token = 0; - ungetc(chr, stdin); - for(opcode = 0; opcode < sizeof(mnemonics)/sizeof(instruction); opcode++) { - if (!strcasecmp(buf, mnemonics[opcode].att)) - break; - } - if(opcode >= sizeof(mnemonics)/sizeof(instruction)) - return 'A'; - return 'I'; - } -/**************** Get literal string ****************/ - else if(chr == '\"') { - *token++ = chr; - do { - chr = getchar(); - if((chr < ' ') && (chr > '~')) - continue; - *token++ = chr; - if(chr == '\\') { - chr = getchar(); - if((chr < ' ') && (chr > '~')) - continue; - *token++ = chr; - chr = '\\'; - } - } while((chr != '\"') && (chr != '\n') && (chr != EOF)); - *token = 0; - return 'S'; - } -/******************* Get register *******************/ - else if(chr == '%') { - chr = getchar(); - if(isalpha(chr)) { - do { - *token++ = chr; - chr = getchar(); - } while(isalnum(chr)); - *token = 0; - ungetc(chr, stdin); - return 'R'; - } - ungetc(chr, stdin); - return '%'; - } - return chr; -} - -static int flush_line(void) -{ - int chr; - - do { - chr = getchar(); - } while((chr != '\n') && (chr != EOF)); - return chr; -} - -static int flush_opr(void) -{ - int chr; - - do { - chr = getchar(); - } while((chr != '\n') && (chr != EOF) && (chr != ',')); - ungetc(chr, stdin); - return chr; -} - -static int mov_opr(char *ptr) -{ - int chr; - - do { - chr = getchar(); - *ptr++ = chr; - } while((chr != '\n') && (chr != EOF) && (chr != ',')); - *(ptr - 1) = 0; - ungetc(chr, stdin); - return 'A'; -} - -static int line(void) -{ - int nops, chr, i; - char *bufptr; - - bufptr = buffer; - - /* Discard empty lines */ - do { - chr = next(bufptr); - if(chr == '\n') - lineno++; - } while(chr == '\n'); - - if(chr == EOF) - return chr; - - /* Every label goes in its own line */ - if(chr == 'L') { - printf("%s\n", bufptr); - return chr; - } - i = opcode; -/*********** Process invalid instructions ***********/ - if((chr != 'I') || (mnemonics[opcode].type == 0)) { - if(chr != 'I') - fprintf(stderr, "!!ERROR: Line %d: Unknown %s\n", lineno, bufptr); - flush_line(); - lineno++; - return '\n'; - } - printf("\t%s\t", mnemonics[opcode].as86); -/************ Process .SECTION directive ************/ - if(mnemonics[opcode].type == 6) { - chr = next(bufptr); - for(nops = 0; nops < 4; nops++) - if(toupper((int)(*(bufptr + 1))) == sects[nops]) - break; - printf("%s\n", sectmsg[nops]); - flush_line(); - lineno++; - return '\n'; - } -/************ Process .P4ALIGN directive ************/ - if(mnemonics[opcode].type == 7) { - next(bufptr); - chr = atoi(bufptr); - printf("%d\n", (1 << chr)); - flush_line(); - lineno++; - return '\n'; - } - -/************* Process .SKIP directive **************/ - if(mnemonics[opcode].type == 8) { - next(bufptr); - printf("%s\n", bufptr); - flush_line(); - lineno++; - return '\n'; - } - -/************* Process .COMM directive **************/ - if(mnemonics[opcode].type == 9) { - next(bufptr); - printf("%s,", bufptr); - next(bufptr); next(bufptr); - printf(" %s\n", bufptr); - flush_line(); - lineno++; - return '\n'; - } -/********** Process indirect call and jmp ***********/ - if(mnemonics[opcode].type == 5) { - do { - chr = getchar(); - if((chr == EOF) || (chr == '\n')) - return chr; - if(chr == '*') - break; - } while((chr <= ' ') || (chr > '~')); - if(chr != '*') - ungetc(chr, stdin); - } - - nops = 0; - do { - operands[nops] = bufptr; - do { - chr = next(bufptr); - switch(chr) { - case 'R': - flush_opr(); - break; - case '$': - *bufptr = '#'; - chr = mov_opr(bufptr + 1); - break; - case '(': - *bufptr = '('; - chr = next(bufptr + 1); - if(chr == 'R') { - *bufptr = '['; - do { - bufptr = bufptr + (strlen(bufptr) + 1); - *(bufptr - 1) = ' '; - chr = next(bufptr); - if(chr != ')') { - *bufptr++ = '+'; - next(bufptr); - } - } while(chr != ')'); - chr = ']'; - } - else { - bufptr++; - } - default: - if(!isalnum(chr)) { - *bufptr = chr; - *(bufptr+1) = 0; - } - } - bufptr = bufptr + (strlen(bufptr) + 1); - *(bufptr - 1) = ' '; - } while((chr != '\n') && (chr != EOF) && (chr != ',')); - bufptr--; - *(bufptr - 1) = 0; - nops++; - } while((chr != '\n') && (chr != EOF)); - opcode = i; - switch(mnemonics[opcode].type) { - case 11: - nops = 0; - break; - case 4: - if(nops < 2) { - operands[1] = imm_one; - nops++; - break; - } - case 3: - if(nops >= 3) { - bufptr = operands[0]; - operands[0] = operands[2]; - operands[2] = bufptr; - break; - } - case 2: - if(nops >= 2) { - bufptr = operands[0]; - operands[0] = operands[1]; - operands[1] = bufptr; - } - case 1: - default: - break; - } - i = 0; - while(nops--) { - if(strlen(operands[i])) - printf("%s", operands[i]); - if(nops) - printf(","); - i++; - }; - printf("\n"); - lineno++; - return chr; -} - -int main (int argc, char **argv) -{ -/*char buffer[MAX_LINE]; -char *operands[MAX_OPERANDS];*/ - int chr; - - do { - chr = line(); - } while(chr != EOF); - return 0; -}