From 57ac2e12864ebb180d4cae67d544d2f5d5c614c0 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Mon, 4 Apr 2011 18:23:55 +0000 Subject: [PATCH] Build boot2 with -mregparm=3, ie. pass upto 3 arguments via registers. This modifies CFLAGS and tweaks sio.S to use the new calling convention. The sio_init() and sio_putc() prototypes are modified so that other users of this code know the correct calling convention. This makes the code smaller when compiled with clang. Reviewed by: jhb Tested by: me and Freddie Cash --- sys/boot/i386/boot2/Makefile | 1 + sys/boot/i386/boot2/lib.h | 4 ++-- sys/boot/i386/boot2/sio.S | 17 +++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile index 6e8315ee1d6..d9b91dfeb56 100644 --- a/sys/boot/i386/boot2/Makefile +++ b/sys/boot/i386/boot2/Makefile @@ -31,6 +31,7 @@ CFLAGS= -Os \ -fno-unit-at-a-time \ -mno-align-long-strings \ -mrtd \ + -mregparm=3 \ -D${BOOT2_UFS} \ -DFLAGS=${BOOT_BOOT1_FLAGS} \ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ diff --git a/sys/boot/i386/boot2/lib.h b/sys/boot/i386/boot2/lib.h index 0459bc20e2f..3ae2b9d806f 100644 --- a/sys/boot/i386/boot2/lib.h +++ b/sys/boot/i386/boot2/lib.h @@ -17,8 +17,8 @@ * $FreeBSD$ */ -void sio_init(int); +void sio_init(int) __attribute__((regparm (3))); void sio_flush(void); -void sio_putc(int); +void sio_putc(int) __attribute__((regparm (3))); int sio_getc(void); int sio_ischar(void); diff --git a/sys/boot/i386/boot2/sio.S b/sys/boot/i386/boot2/sio.S index 7b8e9eb13b0..bbebb5955db 100644 --- a/sys/boot/i386/boot2/sio.S +++ b/sys/boot/i386/boot2/sio.S @@ -26,14 +26,14 @@ /* void sio_init(int div) */ -sio_init: movw $SIO_PRT+0x3,%dx # Data format reg +sio_init: pushl %eax + movw $SIO_PRT+0x3,%dx # Data format reg movb $SIO_FMT|0x80,%al # Set format outb %al,(%dx) # and DLAB - pushl %edx # Save subb $0x3,%dl # Divisor latch reg - movl 0x8(%esp),%eax # Set + popl %eax outw %ax,(%dx) # BPS - popl %edx # Restore + movw $SIO_PRT+0x3,%dx # Data format reg movb $SIO_FMT,%al # Clear outb %al,(%dx) # DLAB incl %edx # Modem control reg @@ -41,7 +41,7 @@ sio_init: movw $SIO_PRT+0x3,%dx # Data format reg outb %al,(%dx) # DTR incl %edx # Line status reg call sio_flush - ret $0x4 + ret /* void sio_flush(void) */ @@ -52,17 +52,18 @@ sio_flush: call sio_ischar # Check for character /* void sio_putc(int c) */ -sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg +sio_putc: pushl %eax + movw $SIO_PRT+0x5,%dx # Line status reg xor %ecx,%ecx # Timeout movb $0x40,%ch # counter sio_putc.1: inb (%dx),%al # Transmitter testb $0x20,%al # buffer empty? loopz sio_putc.1 # No jz sio_putc.2 # If timeout - movb 0x4(%esp,1),%al # Get character + popl %eax # Get the character subb $0x5,%dl # Transmitter hold reg outb %al,(%dx) # Write character -sio_putc.2: ret $0x4 # To caller +sio_putc.2: ret # To caller /* int sio_getc(void) */ -- 2.45.2