From 08ca05f500c97d607ca314c8f48295ce3da4e48d Mon Sep 17 00:00:00 2001 From: gord Date: Sat, 27 Mar 1999 23:35:37 +0000 Subject: [PATCH] Change bcopy, bzero to memmove, memset. --- ChangeLog | 6 ++++ shared_src/boot.c | 10 +++---- shared_src/char_io.c | 61 +++++++++++++++++++++------------------- shared_src/cmdline.c | 15 +++++----- shared_src/disk_io.c | 6 ++-- shared_src/fsys_ext2fs.c | 6 ++-- shared_src/fsys_ffs.c | 5 ++-- shared_src/gunzip.c | 6 ++-- shared_src/shared.h | 9 +++--- shared_src/smp-imps.c | 12 ++++---- shared_src/stage2.c | 20 ++++++------- 11 files changed, 84 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index a42f2d990..eeff8084f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 1999-03-27 Gordon Matzigkeit + * Change everything to use memset and memmove instead of bzero and + bcopy. GNB's Not BSD. + + * shared_src/shared.h (grub_memset): Adapted from grub_bzero. + (grub_memmove): Adapted from grub_bcopy. + * grub/asmstub.c (checkkey): Fix unterminated comment. * shared_src/char_io.c (grub_printf): Renamed from printf. diff --git a/shared_src/boot.c b/shared_src/boot.c index 4f3b60191..6bf6992dc 100644 --- a/shared_src/boot.c +++ b/shared_src/boot.c @@ -198,14 +198,14 @@ load_image (void) if (mbi.mem_lower >= 608) { - bcopy (buffer, (char *) LINUX_SETUP, data_len + SECTOR_SIZE); + memmove ((char *) LINUX_SETUP, buffer, data_len + SECTOR_SIZE); /* copy command-line plus memory hack to staging area */ { char *src = cur_cmdline; char *dest = (char *) (CL_MY_LOCATION + 4); - bcopy ("mem=", (char *) CL_MY_LOCATION, 4); + memmove ((char *) CL_MY_LOCATION, "mem=", 4); *((unsigned short *) CL_OFFSET) = CL_MY_LOCATION - CL_BASE_ADDR; *((unsigned short *) CL_MAGIC_ADDR) = CL_MAGIC; @@ -286,7 +286,7 @@ load_image (void) if (!errnum) { - bzero ((char *) cur_addr, bss_len); + memset ((char *) cur_addr, 0, bss_len); cur_addr += bss_len; printf (", bss=0x%x", bss_len); @@ -386,7 +386,7 @@ load_image (void) && grub_read ((char *) memaddr, filesiz) == filesiz) { if (memsiz > filesiz) - bzero ((char *) (memaddr + filesiz), memsiz - filesiz); + memset ((char *) (memaddr + filesiz), 0, memsiz - filesiz); } else break; @@ -454,7 +454,7 @@ load_initrd (void) return 0; moveto = ((mbi.mem_upper + 0x400) * 0x400 - len) & 0xfffff000; - bcopy ((void *) cur_addr, (void *) moveto, len); + memmove ((void *) moveto, (void *) cur_addr, len); printf (" [Linux-initrd @ 0x%x, 0x%x bytes]\n", moveto, len); diff --git a/shared_src/char_io.c b/shared_src/char_io.c index 226b7b93f..6bc1756f7 100644 --- a/shared_src/char_io.c +++ b/shared_src/char_io.c @@ -586,7 +586,7 @@ int memcheck (int start, int len) { #ifdef GRUB_UTIL - /* FIXME: cur_part_desc is the only global variable that we bcopy + /* FIXME: cur_part_desc is the only global variable that we memmove to. We should fix this so that we don't need a special case (i.e. so that it lives on the stack, or somewhere inside grub_scratch_mem). */ @@ -606,42 +606,45 @@ memcheck (int start, int len) } -int -grub_bcopy (char *from, char *to, int len) +char * +grub_memmove (char *to, char *from, int len) { - if (memcheck ((int) to, len)) - { - if ((to >= from + len) || (to <= from)) - { - while (len >= sizeof (unsigned long)) - { - len -= sizeof (unsigned long); - *(((unsigned long *) to)++) = *(((unsigned long *) from)++); - } - while (len-- > 0) - *(to++) = *(from++); - } - else - { - /* We have a region that overlaps, but would be overwritten - if we copied it forward. */ - while (len-- > 0) - to[len] = from[len]; - } - } + char *ret = to; + if (memcheck ((int) to, len)) + { + if ((to >= from + len) || (to <= from)) + { + while (len >= sizeof (unsigned long)) + { + len -= sizeof (unsigned long); + *(((unsigned long *) to)++) = *(((unsigned long *) from)++); + } + while (len-- > 0) + *(to++) = *(from++); + } + else + { + /* We have a region that overlaps, but would be overwritten + if we copied it forward. */ + while (len-- > 0) + to[len] = from[len]; + } + } - return (!errnum); + return errnum ? NULL : ret; } -int -grub_bzero (char *start, int len) +void * +grub_memset (void *start, int c, int len) { + char *p = start; + if (memcheck ((int) start, len)) { - while (len-- > 0) - *(start++) = 0; + while (len -- > 0) + *p ++ = c; } - return (!errnum); + return errnum ? NULL : start; } diff --git a/shared_src/cmdline.c b/shared_src/cmdline.c index 5c59cc57c..689ccd775 100644 --- a/shared_src/cmdline.c +++ b/shared_src/cmdline.c @@ -213,7 +213,7 @@ returnit: while (*(cur_entry++)); /* copy to work area */ - bcopy(old_entry, cur_heap, ((int)cur_entry) - ((int)old_entry)); + memmove (cur_heap, old_entry, ((int)cur_entry) - ((int)old_entry)); printf("%s\n", old_entry); } @@ -316,7 +316,8 @@ returnit: else if (substring("kernel", cur_heap) < 1) { /* make sure it's at the beginning of the boot heap area */ - bcopy(cur_heap, heap, cmd_len + (((int)cur_cmdline) - ((int)cur_heap))); + memmove (heap, cur_heap, + cmd_len + (((int)cur_cmdline) - ((int)cur_heap))); cur_cmdline = heap + (((int)cur_cmdline) - ((int)cur_heap)); cur_heap = heap; if ((type = load_image()) != 0) @@ -386,13 +387,13 @@ returnit: #endif /* copy possible DOS BPB, 59 bytes at byte offset 3 */ - bcopy(old_sect+BOOTSEC_BPB_OFFSET, buffer+BOOTSEC_BPB_OFFSET, - BOOTSEC_BPB_LENGTH); + memmove (buffer+BOOTSEC_BPB_OFFSET, old_sect+BOOTSEC_BPB_OFFSET, + BOOTSEC_BPB_LENGTH); /* if for a hard disk, copy possible MBR/extended part table */ if ((dest_drive & 0x80) && current_partition == 0xFFFFFF) - bcopy(old_sect+BOOTSEC_PART_OFFSET, buffer+BOOTSEC_PART_OFFSET, - BOOTSEC_PART_LENGTH); + memmove (buffer+BOOTSEC_PART_OFFSET, old_sect+BOOTSEC_PART_OFFSET, + BOOTSEC_PART_LENGTH); if (*((short *)(buffer+STAGE1_VER_MAJ_OFFS)) != COMPAT_VERSION || (*((unsigned short *) (buffer+BOOTSEC_SIG_OFFSET)) @@ -408,7 +409,7 @@ returnit: if (!new_drive) new_drive = current_drive; - bcopy(buffer, (char*)BOOTSEC_LOCATION, SECTOR_SIZE); + memmove ((char*)BOOTSEC_LOCATION, buffer, SECTOR_SIZE); *((unsigned char *)(BOOTSEC_LOCATION+STAGE1_FIRSTLIST)) = new_drive; diff --git a/shared_src/disk_io.c b/shared_src/disk_io.c index 1e49bd62f..b3a58a85e 100644 --- a/shared_src/disk_io.c +++ b/shared_src/disk_io.c @@ -177,7 +177,7 @@ rawread (int drive, int sector, int byte_offset, int byte_len, char *buf) if (size > ((num_sect * SECTOR_SIZE) - byte_offset)) size = (num_sect * SECTOR_SIZE) - byte_offset; - bcopy ((char *) bufaddr, buf, size); + memmove (buf, (char *) bufaddr, size); buf += size; byte_len -= size; @@ -451,7 +451,7 @@ real_open_partition (int flags) current_slice = PC_SLICE_TYPE (mbr_buf, i); part_start = part_offset + PC_SLICE_START (mbr_buf, i); part_length = PC_SLICE_LENGTH (mbr_buf, i); - bcopy (mbr_buf + PC_SLICE_OFFSET + (i << 4), cur_part_desc, 16); + memmove (cur_part_desc, mbr_buf + PC_SLICE_OFFSET + (i << 4), 16); /* * Is this PC partition entry valid? @@ -781,7 +781,7 @@ set_bootdev (int hdbias) /* * Set chainloader boot device. */ - bcopy (cur_part_desc, (char *) (BOOTSEC_LOCATION - 16), 16); + memmove ((char *) (BOOTSEC_LOCATION - 16), cur_part_desc, 16); /* * Set BSD boot device. diff --git a/shared_src/fsys_ext2fs.c b/shared_src/fsys_ext2fs.c index b0828e24d..c7c56b634 100644 --- a/shared_src/fsys_ext2fs.c +++ b/shared_src/fsys_ext2fs.c @@ -581,7 +581,7 @@ ext2fs_dir (char *dirname) #endif /* E2DEBUG */ /* copy inode to fixed location */ - bcopy ((void *) raw_inode, (void *) INODE, sizeof (struct ext2_inode)); + memmove ((void *) INODE, (void *) raw_inode, sizeof (struct ext2_inode)); #ifdef E2DEBUG printf ("first word=%x\n", *((int *) INODE)); @@ -614,7 +614,7 @@ ext2fs_dir (char *dirname) { /* Copy the remaining name to the end of the symlink data. Note that DIRNAME and LINKBUF may overlap! */ - bcopy (dirname, linkbuf + filemax, len); + memmove (linkbuf + filemax, dirname, len); } linkbuf[filemax + len] = '\0'; @@ -631,7 +631,7 @@ ext2fs_dir (char *dirname) { /* Copy the data directly from the inode. */ len = filemax; - bcopy ((char *) INODE->i_block, linkbuf, len); + memmove (linkbuf, (char *) INODE->i_block, len); } #if E2DEBUG diff --git a/shared_src/fsys_ffs.c b/shared_src/fsys_ffs.c index 5bcca5cb6..aaa8e40c4 100644 --- a/shared_src/fsys_ffs.c +++ b/shared_src/fsys_ffs.c @@ -173,8 +173,9 @@ loop: 0, SUPERBLOCK->fs_bsize, (char *) FSYS_BUF)) return 0; /* XXX what return value? */ - bcopy ((void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]), - (void *) INODE, sizeof (struct dinode)); + memmove ((void *) INODE, + (void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]), + sizeof (struct dinode)); /* if we have a real file (and we're not just printing possibilities), then this is where we want to exit */ diff --git a/shared_src/gunzip.c b/shared_src/gunzip.c index 26c0f01eb..ce30459ca 100644 --- a/shared_src/gunzip.c +++ b/shared_src/gunzip.c @@ -537,7 +537,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ unsigned z; /* number of entries in current table */ /* Generate counts for each bit length */ - bzero ((char *) c, sizeof (c)); + memset ((char *) c, 0, sizeof (c)); p = b; i = n; do @@ -795,7 +795,7 @@ inflate_codes_in_window (void) : e); if (w - d >= e) { - bcopy (slide + d, slide + w, e); + memmove (slide + w, slide + d, e); w += e; d += e; } @@ -1200,7 +1200,7 @@ gunzip_read (char *buf, int len) if (size > len) size = len; - bcopy (srcaddr, buf, size); + memmove (buf, srcaddr, size); buf += size; len -= size; diff --git a/shared_src/shared.h b/shared_src/shared.h index 9c9b45870..b4cad634b 100644 --- a/shared_src/shared.h +++ b/shared_src/shared.h @@ -204,8 +204,9 @@ extern char *grub_scratch_mem; /* Remap some libc-API-compatible function names so that we prevent circularararity. */ #ifndef WITHOUT_LIBC_STUBS -#define bcopy grub_bcopy -#define bzero grub_bzero +#define memmove grub_memmove +#define memcpy grub_memmove /* we don't need a separate memcpy */ +#define memset grub_memset #define isspace grub_isspace #define printf grub_printf #undef putchar @@ -452,8 +453,8 @@ void grub_printf (char *format,...); int grub_tolower (int c); int grub_isspace (int c); int grub_strncat (char *s1, char *s2, int n); -int grub_bcopy (char *from, char *to, int len); -int grub_bzero (char *start, int len); +char *grub_memmove (char *to, char *from, int len); +void *grub_memset (void *start, int c, int len); char *grub_strstr (char *s1, char *s2); int grub_strcmp (char *s1, char *s2); diff --git a/shared_src/smp-imps.c b/shared_src/smp-imps.c index 8ef3fb894..5d91525a9 100644 --- a/shared_src/smp-imps.c +++ b/shared_src/smp-imps.c @@ -233,7 +233,7 @@ boot_cpu (imps_processor * proc) /* %%%%% ESB */ extern char patch_code[]; bootaddr = 256 * 1024; - bcopy (patch_code, (char *) bootaddr, 32); + memmove ((char *) bootaddr, patch_code, 32); /* * Generic CPU startup sequence starts here. @@ -319,7 +319,7 @@ add_bus (imps_bus * bus) { char str[8]; - bcopy (bus->bus_type, str, 6); + memmove (str, bus->bus_type, 6); str[6] = 0; KERNEL_PRINT ((" Bus id %d is %s\n", bus->id, str)); @@ -488,9 +488,9 @@ imps_read_bios (imps_fps * fps_ptr) if (fps_ptr->cth_ptr) { char str1[16], str2[16]; - bcopy (local_cth_ptr->oem_id, str1, 8); + memcpy (str1, local_cth_ptr->oem_id, 8); str1[8] = 0; - bcopy (local_cth_ptr->prod_id, str2, 12); + memcpy (str2, local_cth_ptr->prod_id, 12); str2[12] = 0; KERNEL_PRINT ((" OEM id: %s Product id: %s\n", str1, str2)); cth_start = ((unsigned) local_cth_ptr) + sizeof (imps_cth); @@ -513,12 +513,12 @@ imps_read_bios (imps_fps * fps_ptr) if (fps_ptr->feature_info[0] == 1 || fps_ptr->feature_info[0] == 5) { - bcopy ("ISA ", defconfig.bus[0].bus_type, 6); + memcpy (defconfig.bus[0].bus_type, "ISA ", 6); } if (fps_ptr->feature_info[0] == 4 || fps_ptr->feature_info[0] == 7) { - bcopy ("MCA ", defconfig.bus[0].bus_type, 6); + memcpy (defconfig.bus[0].bus_type, "MCA ", 6); } if (fps_ptr->feature_info[0] > 4) { diff --git a/shared_src/stage2.c b/shared_src/stage2.c index a072b82e4..6fa3f1749 100644 --- a/shared_src/stage2.c +++ b/shared_src/stage2.c @@ -273,8 +273,8 @@ restart: if (c == 'O') { - bcopy(cur_entry, cur_entry+2, - ((int)heap) - ((int)cur_entry)); + memmove (cur_entry + 2, cur_entry, + ((int)heap) - ((int)cur_entry)); cur_entry[0] = ' '; cur_entry[1] = 0; @@ -287,7 +287,7 @@ restart: { char *ptr = get_entry(menu_entries, first_entry+entryno+1, 0); - bcopy(ptr, cur_entry, ((int)heap) - ((int)ptr)); + memmove (cur_entry, ptr, ((int)heap) - ((int)ptr)); heap -= (((int)ptr) - ((int)cur_entry)); num_entries--; @@ -325,7 +325,7 @@ restart: if (! strcmp (password, entered)) { char *new_file = config_file; - bzero (entered, sizeof (entered)); + memset (entered, 0, sizeof (entered)); while (isspace (*pptr)) pptr ++; while ((*(new_file ++) = *(pptr ++)) != 0); @@ -333,7 +333,7 @@ restart: } else { - bzero (entered, sizeof (entered)); + memset (entered, 0, sizeof (entered)); printf("Failed!\n Press any key to continue..."); getkey (); goto restart; @@ -401,11 +401,11 @@ restart: } /* align rest of commands properly */ - bcopy(cur_entry+i, cur_entry+j, - ((int)heap) - (((int)cur_entry) + i)); + memmove (cur_entry + j, cur_entry + i, + ((int)heap) - (((int)cur_entry) + i)); /* copy command to correct area */ - bcopy(new_heap, cur_entry, j); + memmove (cur_entry, new_heap, j); heap += (j - i); } @@ -596,8 +596,8 @@ cmain(void) menu_entries[menu_len++] = 0; config_entries[config_len++] = 0; - bcopy(menu_entries, config_entries+config_len, menu_len); - menu_entries = config_entries+config_len; + memmove (config_entries + config_len, menu_entries, menu_len); + menu_entries = config_entries + config_len; } /*