2002-12-28 Yoshinori K. Okuji <okuji@enbug.org>

Use -mrtd and -mregparm=3 to reduce the generated code sizes.
	This means that any missing prototypes could be fatal. Also, you
	must take care when writing assembly code. See the comments at
	the beginning of startup.S, for more details.

	* kern/i386/pc/startup.S (pupa_halt): Modified for the new
	compilation mechanism.
	(pupa_chainloader_real_boot): Likewise.
	(pupa_biosdisk_rw_int13_extensions): Likewise.
	(pupa_biosdisk_rw_standard): Likewise.
	(pupa_biosdisk_check_int13_extensions): Likewise.
	(pupa_biosdisk_get_diskinfo_int13_extensions): Likewise.
	(pupa_biosdisk_get_diskinfo_standard): Likewise.
	(pupa_get_memsize): Likewise.
	(pupa_get_mmap_entry): Likewise.
	(pupa_console_putchar): Likewise.
	(pupa_console_setcursor): Likewise.
	(pupa_getrtsecs): Use pushl instead of push.

	* kern/i386/pc/init.c (pupa_machine_init): Use the scratch
	memory instead of the stack for a mmap entry, because some
	BIOSes may ignore the maximum size and overflow.

	* conf/i386-pc.rmk (COMMON_CFLAGS): Added -mrtd and -mregparm=3.

	* genmk.rb (PModule#rule): Compile automatically generated
	sources with module-specific CFLAGS as well as other sources.
This commit is contained in:
okuji 2002-12-28 07:16:30 +00:00
parent 9962ed9907
commit 62ddcc8f79
7 changed files with 141 additions and 111 deletions

View file

@ -1,3 +1,33 @@
2002-12-28 Yoshinori K. Okuji <okuji@enbug.org>
Use -mrtd and -mregparm=3 to reduce the generated code sizes.
This means that any missing prototypes could be fatal. Also, you
must take care when writing assembly code. See the comments at
the beginning of startup.S, for more details.
* kern/i386/pc/startup.S (pupa_halt): Modified for the new
compilation mechanism.
(pupa_chainloader_real_boot): Likewise.
(pupa_biosdisk_rw_int13_extensions): Likewise.
(pupa_biosdisk_rw_standard): Likewise.
(pupa_biosdisk_check_int13_extensions): Likewise.
(pupa_biosdisk_get_diskinfo_int13_extensions): Likewise.
(pupa_biosdisk_get_diskinfo_standard): Likewise.
(pupa_get_memsize): Likewise.
(pupa_get_mmap_entry): Likewise.
(pupa_console_putchar): Likewise.
(pupa_console_setcursor): Likewise.
(pupa_getrtsecs): Use pushl instead of push.
* kern/i386/pc/init.c (pupa_machine_init): Use the scratch
memory instead of the stack for a mmap entry, because some
BIOSes may ignore the maximum size and overflow.
* conf/i386-pc.rmk (COMMON_CFLAGS): Added -mrtd and -mregparm=3.
* genmk.rb (PModule#rule): Compile automatically generated
sources with module-specific CFLAGS as well as other sources.
2002-12-27 Yoshinori K. Okuji <okuji@enbug.org> 2002-12-27 Yoshinori K. Okuji <okuji@enbug.org>
* configure.ac: Check ld. * configure.ac: Check ld.

5
NEWS
View file

@ -2,6 +2,11 @@ New in 0.7:
* Problems in cross-compiling PUPA are fixed. * Problems in cross-compiling PUPA are fixed.
* Use -mrtd and -mregparm=3 to reduce the generated code sizes. This
means that any missing prototypes could be fatal. Also, you must take
care when writing assembly code. See the comments at the beginning of
startup.S, for more details.
New in 0.6 - 2002-12-27, Yoshinori K. Okuji: New in 0.6 - 2002-12-27, Yoshinori K. Okuji:
* The chainloader and the FAT filesystem are modularized. * The chainloader and the FAT filesystem are modularized.

View file

@ -1,7 +1,7 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin COMMON_ASFLAGS = -nostdinc -fno-builtin
COMMON_CFLAGS = -fno-builtin COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3
# Images. # Images.
pkgdata_IMAGES = boot.img diskboot.img kernel.img pkgdata_IMAGES = boot.img diskboot.img kernel.img
@ -312,7 +312,7 @@ pre-chain.o: chain_mod-loader_i386_pc_chainloader.o
$(LD) -r -o $@ $^ $(LD) -r -o $@ $^
mod-chain.o: mod-chain.c mod-chain.o: mod-chain.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CC) $(CPPFLAGS) $(CFLAGS) $(chain_mod_CFLAGS) -c -o $@ $<
mod-chain.c: moddep.lst genmodsrc.sh mod-chain.c: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh 'chain' $< > $@ || (rm -f $@; exit 1) sh $(srcdir)/genmodsrc.sh 'chain' $< > $@ || (rm -f $@; exit 1)
@ -351,7 +351,7 @@ pre-fat.o: fat_mod-fs_fat.o
$(LD) -r -o $@ $^ $(LD) -r -o $@ $^
mod-fat.o: mod-fat.c mod-fat.o: mod-fat.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CC) $(CPPFLAGS) $(CFLAGS) $(fat_mod_CFLAGS) -c -o $@ $<
mod-fat.c: moddep.lst genmodsrc.sh mod-fat.c: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh 'fat' $< > $@ || (rm -f $@; exit 1) sh $(srcdir)/genmodsrc.sh 'fat' $< > $@ || (rm -f $@; exit 1)

View file

@ -1,7 +1,7 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin COMMON_ASFLAGS = -nostdinc -fno-builtin
COMMON_CFLAGS = -fno-builtin COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3
# Images. # Images.
pkgdata_IMAGES = boot.img diskboot.img kernel.img pkgdata_IMAGES = boot.img diskboot.img kernel.img

View file

@ -125,7 +125,7 @@ UNDSYMFILES += #{undsym}
$(LD) -r -o $@ $^ $(LD) -r -o $@ $^
#{mod_obj}: #{mod_src} #{mod_obj}: #{mod_src}
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CC) $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
#{mod_src}: moddep.lst genmodsrc.sh #{mod_src}: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1) sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)

View file

@ -30,7 +30,8 @@ void
pupa_machine_init (void) pupa_machine_init (void)
{ {
pupa_uint32_t cont; pupa_uint32_t cont;
struct pupa_machine_mmap_entry entry; struct pupa_machine_mmap_entry *entry
= (struct pupa_machine_mmap_entry *) PUPA_MEMORY_MACHINE_SCRATCH_ADDR;
pupa_size_t lower_mem = (pupa_get_memsize (0) << 10); pupa_size_t lower_mem = (pupa_get_memsize (0) << 10);
pupa_addr_t end_addr = pupa_get_end_addr (); pupa_addr_t end_addr = pupa_get_end_addr ();
@ -53,31 +54,31 @@ pupa_machine_init (void)
PUPA_MEMORY_MACHINE_RESERVED_START - end_addr); PUPA_MEMORY_MACHINE_RESERVED_START - end_addr);
/* Check if pupa_get_mmap_entry works. */ /* Check if pupa_get_mmap_entry works. */
cont = pupa_get_mmap_entry (&entry, 0); cont = pupa_get_mmap_entry (entry, 0);
if (entry.size) if (entry->size)
do do
{ {
/* Avoid the lower memory. */ /* Avoid the lower memory. */
if (entry.addr < 0x100000) if (entry->addr < 0x100000)
{ {
if (entry.len <= 0x100000 - entry.addr) if (entry->len <= 0x100000 - entry->addr)
goto next; goto next;
entry.len -= 0x100000 - entry.addr; entry->len -= 0x100000 - entry->addr;
entry.addr = 0x100000; entry->addr = 0x100000;
} }
/* Ignore >4GB. */ /* Ignore >4GB. */
if (entry.addr <= 0xFFFFFFFF && entry.type == 1) if (entry->addr <= 0xFFFFFFFF && entry->type == 1)
{ {
pupa_addr_t addr; pupa_addr_t addr;
pupa_size_t len; pupa_size_t len;
addr = (pupa_addr_t) entry.addr; addr = (pupa_addr_t) entry->addr;
len = ((addr + entry.len > 0xFFFFFFFF) len = ((addr + entry->len > 0xFFFFFFFF)
? 0xFFFFFFFF - addr ? 0xFFFFFFFF - addr
: (pupa_size_t) entry.len); : (pupa_size_t) entry->len);
pupa_mm_init_region ((void *) addr, len); pupa_mm_init_region ((void *) addr, len);
} }
@ -85,9 +86,9 @@ pupa_machine_init (void)
if (! cont) if (! cont)
break; break;
cont = pupa_get_mmap_entry (&entry, cont); cont = pupa_get_mmap_entry (entry, cont);
} }
while (entry.size); while (entry->size);
else else
{ {
pupa_uint32_t eisa_mmap = pupa_get_eisa_mmap (); pupa_uint32_t eisa_mmap = pupa_get_eisa_mmap ();

View file

@ -35,6 +35,14 @@
{ 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
*/ */
/*
* Note: PUPA is compiled with the options -mrtd and -mregparm=3.
* So the first three arguments are passed in %eax, %edx, and %ecx,
* respectively, and if a function has a fixed number of arguments
* and the number if greater than three, the function must return
* with "ret $N" where N is ((the number of arguments) - 3) * 4.
*/
#include <config.h> #include <config.h>
#include <pupa/symbol.h> #include <pupa/symbol.h>
#include <pupa/boot.h> #include <pupa/boot.h>
@ -203,9 +211,6 @@ FUNCTION(pupa_reboot)
* APM even if it is available. * APM even if it is available.
*/ */
FUNCTION(pupa_halt) FUNCTION(pupa_halt)
/* get the argument */
movl 4(%esp), %eax
/* see if zero */ /* see if zero */
testl %eax, %eax testl %eax, %eax
jnz EXT_C(pupa_stop) jnz EXT_C(pupa_stop)
@ -256,16 +261,16 @@ FUNCTION(pupa_halt)
*/ */
FUNCTION(pupa_chainloader_real_boot) FUNCTION(pupa_chainloader_real_boot)
/* no need to save anything, just use %esp */ /* no need to save anything */
/* ESI must point to a partition table entry */ /* ESI must point to a partition table entry */
movl 8(%esp), %esi movl %edx, %esi
/* set up to pass boot drive */ /* set up to pass boot drive */
movl 4(%esp), %edx movl %eax, %edx
/* Turn off Gate A20 */ /* Turn off Gate A20 */
pushl $0 xorl %eax, %eax
call EXT_C(pupa_gate_a20) call EXT_C(pupa_gate_a20)
call prot_to_real call prot_to_real
@ -398,21 +403,15 @@ realcseg:
FUNCTION(pupa_biosdisk_rw_int13_extensions) FUNCTION(pupa_biosdisk_rw_int13_extensions)
pushl %ebp pushl %ebp
movl %esp, %ebp
pushl %esi pushl %esi
/* compute the address of disk_address_packet */ /* compute the address of disk_address_packet */
movl 0x10(%ebp), %eax movw %cx, %si
movw %ax, %si xorw %cx, %cx
xorw %ax, %ax shrl $4, %ecx /* save the segment to cx */
shrl $4, %eax
movw %ax, %cx /* save the segment to cx */
/* drive */
movb 0xc(%ebp), %dl
/* ah */ /* ah */
movb 0x8(%ebp), %dh movb %al, %dh
/* enter real mode */ /* enter real mode */
call prot_to_real call prot_to_real
@ -453,21 +452,24 @@ FUNCTION(pupa_biosdisk_rw_standard)
pushl %esi pushl %esi
/* set up CHS information */ /* set up CHS information */
movl 0x10(%ebp), %eax
movb %al, %ch /* set %ch to low eight bits of cylinder */
movb 0x18(%ebp), %al xchgb %cl, %ch
shlb $2, %al /* set bits 6-7 of %cl to high two bits of cylinder */
shrw $2, %ax shlb $6, %cl
movb %al, %cl /* set bits 0-5 of %cl to sector */
movb 0x14(%ebp), %dh addb 0xc(%ebp), %cl
/* drive */ /* set %dh to head */
movb 0xc(%ebp), %dl movb 0x8(%ebp), %dh
/* segment */ /* set %ah to AH */
movw 0x20(%ebp), %bx movb %al, %ah
/* save nsec and ah to %di */ /* set %al to NSEC */
movb 0x8(%ebp), %ah movb 0x10(%ebp), %al
movb 0x1c(%ebp), %al /* save %ax in %di */
movw %ax, %di movw %ax, %di
/* save SEGMENT in %bx */
movw 0x14(%ebp), %bx
/* enter real mode */ /* enter real mode */
call prot_to_real call prot_to_real
@ -503,7 +505,7 @@ FUNCTION(pupa_biosdisk_rw_standard)
popl %ebx popl %ebx
popl %ebp popl %ebp
ret ret $(4 * 4)
/* /*
@ -515,12 +517,10 @@ FUNCTION(pupa_biosdisk_rw_standard)
FUNCTION(pupa_biosdisk_check_int13_extensions) FUNCTION(pupa_biosdisk_check_int13_extensions)
pushl %ebp pushl %ebp
movl %esp, %ebp
pushl %ebx pushl %ebx
/* drive */ /* drive */
movb 0x8(%ebp), %dl movb %al, %dl
/* enter real mode */ /* enter real mode */
call prot_to_real call prot_to_real
@ -564,19 +564,16 @@ FUNCTION(pupa_biosdisk_check_int13_extensions)
FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions) FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions)
pushl %ebp pushl %ebp
movl %esp, %ebp
pushl %ebx pushl %ebx
pushl %esi pushl %esi
/* compute the address of drive parameters */ /* compute the address of drive parameters */
movl 0xc(%ebp), %eax movw %dx, %si
movw %ax, %si xorw %dx, %dx
xorw %ax, %ax shrl $4, %edx
shrl $4, %eax movw %dx, %bx /* save the segment into %bx */
movw %ax, %bx /* save the segment into %bx */
/* drive */ /* drive */
movb 0x8(%ebp), %dl movb %al, %dl
/* enter real mode */ /* enter real mode */
call prot_to_real call prot_to_real
@ -613,13 +610,17 @@ FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions)
FUNCTION(pupa_biosdisk_get_diskinfo_standard) FUNCTION(pupa_biosdisk_get_diskinfo_standard)
pushl %ebp pushl %ebp
movl %esp, %ebp
pushl %ebx pushl %ebx
pushl %edi pushl %edi
/* push CYLINDERS */
pushl %edx
/* push HEADS */
pushl %ecx
/* SECTORS is on the stack */
/* drive */ /* drive */
movb 0x8(%ebp), %dl movb %al, %dl
/* enter real mode */ /* enter real mode */
call prot_to_real call prot_to_real
@ -640,31 +641,26 @@ FUNCTION(pupa_biosdisk_get_diskinfo_standard)
DATA32 call real_to_prot DATA32 call real_to_prot
.code32 .code32
/* restore %ebp */ /* pop HEADS */
leal 0x8(%esp), %ebp popl %edi
/* heads */
movb %dh, %al movb %dh, %al
incl %eax /* the number of heads is counted from zero */ incl %eax /* the number of heads is counted from zero */
movl 0x10(%ebp), %edi
movl %eax, (%edi) movl %eax, (%edi)
/* sectors */ /* pop CYLINDERS */
xorl %eax, %eax popl %edi
movb %cl, %al
andb $0x3f, %al
movl 0x14(%ebp), %edi
movl %eax, (%edi)
/* cylinders */
shrb $6, %cl
movb %cl, %ah
movb %ch, %al movb %ch, %al
incl %eax /* the number of cylinders is movb %cl, %ah
counted from zero */ shrb $6, %ah /* the number of cylinders is counted from zero */
movl 0xc(%ebp), %edi incl %eax
movl %eax, (%edi) movl %eax, (%edi)
/* SECTORS */
movl 0x10(%esp), %edi
andb $0x3f, %cl
movzbl %cl, %eax
movl %eax, (%edi)
xorl %eax, %eax xorl %eax, %eax
movb %bl, %al /* return value in %eax */ movb %bl, %al /* return value in %eax */
@ -672,7 +668,7 @@ FUNCTION(pupa_biosdisk_get_diskinfo_standard)
popl %ebx popl %ebx
popl %ebp popl %ebp
ret ret $4
/* /*
@ -724,14 +720,13 @@ FUNCTION(pupa_biosdisk_get_num_floppies)
FUNCTION(pupa_get_memsize) FUNCTION(pupa_get_memsize)
pushl %ebp pushl %ebp
pushl %ebx
movl 0xc(%esp), %ebx movl %eax, %edx
call prot_to_real /* enter real mode */ call prot_to_real /* enter real mode */
.code16 .code16
testl %ebx, %ebx testl %edx, %edx
jnz xext jnz xext
int $0x12 int $0x12
@ -742,13 +737,13 @@ xext:
int $0x15 int $0x15
xdone: xdone:
movw %ax, %bx movw %ax, %dx
DATA32 call real_to_prot DATA32 call real_to_prot
.code32 .code32
movw %bx, %ax movw %dx, %ax
popl %ebx
popl %ebp popl %ebp
ret ret
@ -802,13 +797,12 @@ xnoteisa:
*/ */
FUNCTION(pupa_get_mmap_entry) FUNCTION(pupa_get_mmap_entry)
push %ebp pusha
push %ebx
push %edi
push %esi
/* push ADDR */
pushl %eax
/* place address (+4) in ES:DI */ /* place address (+4) in ES:DI */
movl 0x14(%esp), %eax
addl $4, %eax addl $4, %eax
movl %eax, %edi movl %eax, %edi
andl $0xf, %edi andl $0xf, %edi
@ -816,7 +810,7 @@ FUNCTION(pupa_get_mmap_entry)
movl %eax, %esi movl %eax, %esi
/* set continuation value */ /* set continuation value */
movl 0x18(%esp), %ebx movl %edx, %ebx
/* set default maximum buffer size */ /* set default maximum buffer size */
movl $0x14, %ecx movl $0x14, %ecx
@ -851,17 +845,14 @@ xsmap:
DATA32 call real_to_prot DATA32 call real_to_prot
.code32 .code32
/* write length of buffer (zero if error) into "addr" */ /* write length of buffer (zero if error) into ADDR */
movl 0x14(%esp), %eax popl %eax
movl %ecx, (%eax) movl %ecx, (%eax)
/* set return value to continuation */ /* set return value to continuation */
movl %ebx, %eax movl %ebx, %eax
pop %esi popa
pop %edi
pop %ebx
pop %ebp
ret ret
@ -937,7 +928,7 @@ gloop2ret:
* support setting a background attribute. * support setting a background attribute.
*/ */
FUNCTION(pupa_console_putchar) FUNCTION(pupa_console_putchar)
movl 0x4(%esp), %edx movl %eax, %edx
pusha pusha
movb EXT_C(pupa_console_cur_color), %bl movb EXT_C(pupa_console_cur_color), %bl
@ -1122,8 +1113,8 @@ FUNCTION(pupa_console_gotoxy)
pushl %ebp pushl %ebp
pushl %ebx /* save EBX */ pushl %ebx /* save EBX */
movb 0xc(%esp), %dl /* %dl = x */ movb %dl, %dh /* %dh = y */
movb 0x10(%esp), %dh /* %dh = y */ movb %al, %dl /* %dl = x */
call prot_to_real call prot_to_real
.code16 .code16
@ -1195,9 +1186,12 @@ console_cursor_shape:
.word 0 .word 0
FUNCTION(pupa_console_setcursor) FUNCTION(pupa_console_setcursor)
push %ebp pushl %ebp
push %ebx pushl %ebx
/* push ON */
pushl %eax
/* check if the standard cursor shape has already been saved */ /* check if the standard cursor shape has already been saved */
movw console_cursor_shape, %ax movw console_cursor_shape, %ax
testw %ax, %ax testw %ax, %ax
@ -1217,8 +1211,8 @@ FUNCTION(pupa_console_setcursor)
1: 1:
/* set %cx to the designated cursor shape */ /* set %cx to the designated cursor shape */
movw $0x2000, %cx movw $0x2000, %cx
movl 0xc(%esp), %ebx popl %eax
testl %ebx, %ebx testl %eax, %eax
jz 2f jz 2f
movw console_cursor_shape, %cx movw console_cursor_shape, %cx
2: 2:
@ -1254,7 +1248,7 @@ FUNCTION(pupa_console_setcursor)
* that it isn't running) * that it isn't running)
*/ */
FUNCTION(pupa_getrtsecs) FUNCTION(pupa_getrtsecs)
push %ebp pushl %ebp
call prot_to_real /* enter real mode */ call prot_to_real /* enter real mode */
.code16 .code16
@ -1272,7 +1266,7 @@ gottime:
movb %dh, %al movb %dh, %al
pop %ebp popl %ebp
ret ret