1// Copyright 2017 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7#include <arch/ops.h>
8#include <lib/code_patching.h>
9#include <lk/init.h>
10
11extern const CodePatchInfo __start_code_patch_table[];
12extern const CodePatchInfo __stop_code_patch_table[];
13
14static void apply_startup_code_patches(uint level) {
15    for (const CodePatchInfo* patch = __start_code_patch_table;
16         patch < __stop_code_patch_table; ++patch) {
17        patch->apply_func(patch);
18        arch_sync_cache_range((addr_t)patch->dest_addr, patch->dest_size);
19    }
20}
21
22LK_INIT_HOOK(code_patching, apply_startup_code_patches,
23             LK_INIT_LEVEL_ARCH_EARLY);
24