From f56881c447481db3675f8b19b1e9a72eb61349a7 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 19 Oct 2015 19:56:23 +0200 Subject: [PATCH] Don't force alignment on platforms that don't need it. --- Kernel/cpu-msp430x/cpu.h | 6 ++++++ Kernel/include/kernel.h | 10 ++++++++++ Kernel/syscall_exec16.c | 4 ++-- Kernel/syscall_proc.c | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Kernel/cpu-msp430x/cpu.h b/Kernel/cpu-msp430x/cpu.h index 69886646..9a14e5a4 100644 --- a/Kernel/cpu-msp430x/cpu.h +++ b/Kernel/cpu-msp430x/cpu.h @@ -23,6 +23,12 @@ typedef uint16_t usize_t; /* Largest value passed by userspace */ typedef int16_t susize_t; typedef uint32_t clock_t; +/* The MSP430 requires aligned accesses. (Annoying, it doesn't trap if you + * get this wrong. It just reads to or writes from the wrong place.) */ + +#define ALIGNUP(v) alignup(v, 2) +#define ALIGNDOWN(v) aligndown(v, 2) + #define uputp uputw /* Copy user pointer type */ #define ugetp ugetw /* between user and kernel */ diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 4bb859da..81423b93 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -25,6 +25,16 @@ From UZI by Doug Braun and UZI280 by Stefan Nitschke. #define aligndown(v,a) (uint8_t*)((intptr_t)(v) & ~((a)-1)) #define alignup(v,a) (uint8_t*)((intptr_t)((v) + (a)-1) & ~((a)-1)) +/* By default, assume machines that don't need alignment. */ + +#ifndef ALIGNUP +#define ALIGNUP(v) (v) +#endif + +#ifndef ALIGNDOWN +#define ALIGNDOWN(v) (v) +#endif + #define CPM_EMULATOR_FILENAME "/usr/cpm/emulator" /* Maximum UFTSIZE can be is 16, then you need to alter the O_CLOEXEC code */ diff --git a/Kernel/syscall_exec16.c b/Kernel/syscall_exec16.c index cd976e71..40ff5e34 100644 --- a/Kernel/syscall_exec16.c +++ b/Kernel/syscall_exec16.c @@ -207,7 +207,7 @@ arg_t _execve(void) uzero((uint8_t *)progptr, bss); // Set initial break for program - udata.u_break = (int)alignup(progptr + bss, sizeof(void*)); + udata.u_break = (int)ALIGNUP(progptr + bss); /* Turn off caught signals */ memset(udata.u_sigvec, 0, sizeof(udata.u_sigvec)); @@ -295,7 +295,7 @@ char **wargs(char *ptr, struct s_argblk *argbuf, int *cnt) // ptr is in userspac sptr = argbuf->a_buf; /* Move them into the users address space, at the very top */ - ptr -= (arglen = (int)alignup(argbuf->a_arglen, 2)); + ptr -= (arglen = (int)ALIGNUP(argbuf->a_arglen)); if (arglen) { uput(sptr, ptr, arglen); diff --git a/Kernel/syscall_proc.c b/Kernel/syscall_proc.c index 76c7ac20..a48016c4 100644 --- a/Kernel/syscall_proc.c +++ b/Kernel/syscall_proc.c @@ -225,7 +225,7 @@ arg_t _brk(void) need to make this something like if (brk_valid(addr)) so we can keep it portable */ - uaddr_t aligned = (uaddr_t) alignup(addr, sizeof(uaddr_t)); + uaddr_t aligned = (uaddr_t) ALIGNUP(addr); if (aligned >= brk_limit()) { kprintf("%d: out of memory\n", udata.u_ptab->p_pid); udata.u_error = ENOMEM; -- 2.34.1