Add helper functions to handle the stack.
This commit is contained in:
@@ -11,9 +11,6 @@
|
||||
/// @brief The initial stack pointer.
|
||||
extern uintptr_t initial_esp;
|
||||
|
||||
/// @brief Push the `item` of a given `type` on the `stack`.
|
||||
#define PUSH_ARG(stack, type, item) (*((type *)((stack) -= sizeof(type))) = (item))
|
||||
|
||||
/// Kilobytes.
|
||||
#define K 1024
|
||||
/// Megabytes.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file stack_helper.h
|
||||
/// @brief Couple of macros that help accessing the stack.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
/// @brief Access the value of the pointer.
|
||||
#define __ACCESS_PTR(type, ptr) (*(type *)(ptr))
|
||||
/// @brief Moves the pointer down.
|
||||
#define __MOVE_PTR_DOWN(type, ptr) ((ptr) -= sizeof(type))
|
||||
/// @brief Moves the pointer up.
|
||||
#define __MOVE_PTR_UP(type, ptr) ((ptr) += sizeof(type))
|
||||
/// @brief First, it moves the pointer down, and then it pushes the value at that memory location.
|
||||
#define PUSH_VALUE_ON_STACK(ptr, value) (__ACCESS_PTR(typeof(value), __MOVE_PTR_DOWN(typeof(value), ptr)) = (value))
|
||||
/// @brief First, it access the value at the given memory location, and then it moves the pointer up.
|
||||
#define POP_VALUE_FROM_STACK(value, ptr) ({value = __ACCESS_PTR(typeof(value), ptr); __MOVE_PTR_UP(typeof(value), ptr); })
|
||||
Reference in New Issue
Block a user