xref: /freebsd/sys/ddb/db_write_cmd.c (revision 1c6989fa7e54e08aa6c9e238298b3c511bf73660)
15b81b6b3SRodney W. Grimes /*
25b81b6b3SRodney W. Grimes  * Mach Operating System
35b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
45b81b6b3SRodney W. Grimes  * All Rights Reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
75b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
85b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
95b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
105b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
115b81b6b3SRodney W. Grimes  *
125b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
135b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
145b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
155b81b6b3SRodney W. Grimes  *
165b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
195b81b6b3SRodney W. Grimes  *  School of Computer Science
205b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
215b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
225b81b6b3SRodney W. Grimes  *
235b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
245b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
250edf66ecSRodney W. Grimes  *
261c6989faSPeter Wemm  *	$Id: db_write_cmd.c,v 1.11 1998/07/08 10:53:52 bde Exp $
275b81b6b3SRodney W. Grimes  */
280edf66ecSRodney W. Grimes 
295b81b6b3SRodney W. Grimes /*
305b81b6b3SRodney W. Grimes  *	Author: David B. Golub,  Carnegie Mellon University
315b81b6b3SRodney W. Grimes  *	Date:	7/90
325b81b6b3SRodney W. Grimes  */
335b81b6b3SRodney W. Grimes 
34f540b106SGarrett Wollman #include <sys/param.h>
355b81b6b3SRodney W. Grimes 
365ccbc3ccSBruce Evans #include <ddb/ddb.h>
375b81b6b3SRodney W. Grimes #include <ddb/db_access.h>
385b81b6b3SRodney W. Grimes #include <ddb/db_command.h>
395b81b6b3SRodney W. Grimes #include <ddb/db_sym.h>
405b81b6b3SRodney W. Grimes 
415b81b6b3SRodney W. Grimes /*
425b81b6b3SRodney W. Grimes  * Write to file.
435b81b6b3SRodney W. Grimes  */
445b81b6b3SRodney W. Grimes /*ARGSUSED*/
455b81b6b3SRodney W. Grimes void
465b81b6b3SRodney W. Grimes db_write_cmd(address, have_addr, count, modif)
475b81b6b3SRodney W. Grimes 	db_expr_t	address;
485b81b6b3SRodney W. Grimes 	boolean_t	have_addr;
495b81b6b3SRodney W. Grimes 	db_expr_t	count;
505b81b6b3SRodney W. Grimes 	char *		modif;
515b81b6b3SRodney W. Grimes {
525b81b6b3SRodney W. Grimes 	register
535b81b6b3SRodney W. Grimes 	db_addr_t	addr;
545b81b6b3SRodney W. Grimes 	register
555b81b6b3SRodney W. Grimes 	db_expr_t	old_value;
565b81b6b3SRodney W. Grimes 	db_expr_t	new_value;
575b81b6b3SRodney W. Grimes 	register int	size;
585b81b6b3SRodney W. Grimes 	boolean_t	wrote_one = FALSE;
595b81b6b3SRodney W. Grimes 
605b81b6b3SRodney W. Grimes 	addr = (db_addr_t) address;
615b81b6b3SRodney W. Grimes 
625b81b6b3SRodney W. Grimes 	switch (modif[0]) {
635b81b6b3SRodney W. Grimes 	    case 'b':
645b81b6b3SRodney W. Grimes 		size = 1;
655b81b6b3SRodney W. Grimes 		break;
665b81b6b3SRodney W. Grimes 	    case 'h':
675b81b6b3SRodney W. Grimes 		size = 2;
685b81b6b3SRodney W. Grimes 		break;
695b81b6b3SRodney W. Grimes 	    case 'l':
705b81b6b3SRodney W. Grimes 	    case '\0':
715b81b6b3SRodney W. Grimes 		size = 4;
725b81b6b3SRodney W. Grimes 		break;
735b81b6b3SRodney W. Grimes 	    default:
745b81b6b3SRodney W. Grimes 		db_error("Unknown size\n");
755b81b6b3SRodney W. Grimes 		return;
765b81b6b3SRodney W. Grimes 	}
775b81b6b3SRodney W. Grimes 
785b81b6b3SRodney W. Grimes 	while (db_expression(&new_value)) {
795b81b6b3SRodney W. Grimes 	    old_value = db_get_value(addr, size, FALSE);
805b81b6b3SRodney W. Grimes 	    db_printsym(addr, DB_STGY_ANY);
811c6989faSPeter Wemm 	    db_printf("\t\t%#8lr\t=\t%#8lr\n", (long)old_value,(long)new_value);
825b81b6b3SRodney W. Grimes 	    db_put_value(addr, size, new_value);
835b81b6b3SRodney W. Grimes 	    addr += size;
845b81b6b3SRodney W. Grimes 
855b81b6b3SRodney W. Grimes 	    wrote_one = TRUE;
865b81b6b3SRodney W. Grimes 	}
875b81b6b3SRodney W. Grimes 
885b81b6b3SRodney W. Grimes 	if (!wrote_one)
895b81b6b3SRodney W. Grimes 	    db_error("Nothing written.\n");
905b81b6b3SRodney W. Grimes 
915b81b6b3SRodney W. Grimes 	db_next = addr;
925b81b6b3SRodney W. Grimes 	db_prev = addr - size;
935b81b6b3SRodney W. Grimes 
945b81b6b3SRodney W. Grimes 	db_skip_to_eol();
955b81b6b3SRodney W. Grimes }
965b81b6b3SRodney W. Grimes 
97